HOW TO GET REQUIRED FIELDS INTO O/P FILE



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby Mann_B » Wed Mar 09, 2011 12:35 pm

HI..
we have an i/p file of the format
trans-id item1 f11 f12 f13 f14 ....f1n item2 f21 f22 f23 ...f2n item3...........
itemn fn1 fn2...fnn

We have the record spanned to 2-3 rows and indicator at the begining mentions the number of span out of number of rows it
spanned
eg:if the record spanned to 2 rows,we have an indicator like
12(in first row)
22(in second row)

now we need to get the fields requested ,in the o/p files from this kind of input file and the number of fields reuested
in the o/p file may vary in future

We thought of having another i/p file with the requested details.
like
item pos.of-the-field-(in the item) length-of-field
AB 10 10
CD 250 20
....
In the program we will process each item and write the whole item into a record(with item layout ..internal).From that we can
get the required field in the o/p.
But here the number of i.p fields required varies,which should be added at the bottom.But for every record the input file
must be read till end of file . And giving just the pos may have problems.So do we have any other option to achive this.
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

 

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby BillyBoyo » Wed Mar 09, 2011 12:59 pm

Good morning Mann_B,

That is a curious input file. I don't suppose there is any way as part of your task to make it a bit more normal, with only one "item" per physical record? It would make using it easier.

I think first if I do a bit of re-stating, you can tell me whether I got it, or where I went wrong.

You want to supply a file of requested fields to extract from your file. The request file is to indicate the item reference, the position of the field within the item, and the length of the field.

Since you don't mention trans-id, either all the trans-id are the same or item reference can appear in any trans id. It is not yet clear whether item reference always appears in the same places on the input record (ie all item reference data is the same length). If not, you'll need a method to "find" items.

Having found the item, you want to extract a field based on position (relative to start of item) and length. This is unusual, but it is your requirement. One problem you have is how to ensure the input data for the request is correct, otherwise you will end up with rubbish and, if you are unlucky, rubbish which looks OK,

Finally for now, you want to avoid reading the whole request file multiple times.

How many requests are you likely to process at once, as a maximum? If not too many, you can read your request file at one go, storing the data into a table in the cobol program. Then, process that table with each input record of your main file to find the data that you need. Your output file might not have the order you want, but it gives you a chance to put good information onto it and to sort it afterwards so that reading your output file is not such a huge job as extracting the data for it.

If you could "rationalise" your input file, you'll make your life much easier each time you use it.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby Mann_B » Wed Mar 09, 2011 1:23 pm

Hi
thanks for ur reply.
Storing the data from the input file to an array option would be fine but is it best way to give the Pos and length of the filed in the Item which is like hard coding.
And all the items will not be having same length and each record(transaction) may not get same items .I mean if one transaction has Ab,CD ,Ef and another may have AB,CD , GH ,IJ like this...
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby BillyBoyo » Wed Mar 09, 2011 1:37 pm

I am amazed by your input file. Is it really some sort of home-grown database, with a key file/data map somewhere?

So, all the records are variable in length and content of data (could be any number of "items" with their associated fields).

The items contain no information within themselves as to how long their data is? How are you going to tell where one item ends and the next starts?

Please try an answer to all the questions, otherwise I have to ask again, I think the answers are needed.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby Mann_B » Wed Mar 09, 2011 1:52 pm

In the input file we have 4bytes at the begining indictaing the length of the record n before each item 2 bytes will indicate the length of the Item ..If we traverse the i.p file with that length exacty after that length another Item would start..that is the check to see if the ITEM is truly an item r some text for some value.And each item has layout defined fo it.While travesing the i.p file we will chk for the length from the current pos..if it is correct then we will copy that to the Item-record till the length .
I have an idea on how to get the required fields from the required ITEM,but now my doubt is how to indicate the required fields in another i.p file that tooo I want to make the pgm Generic ...not specific to my requirement,
and if in future if another person wants few fields written into another file,Can we jsut add an o/p file in the pgm n again we need to differentiate the fields in the file like which and all fields to be written to which o/p file/
I myself feel it gng to b more confusing and complex...
Not sure this is just my approach and searching for better way.......
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby Zio69 » Wed Mar 09, 2011 2:02 pm

That reminds me of MERVA's journal files. Except, MERVA had "item" and "field" delimiters, so processing was quite painless. Have you considered the option of adding delimiters?
Zio69
 
Posts: 31
Joined: Wed Feb 16, 2011 7:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby BillyBoyo » Wed Mar 09, 2011 2:10 pm

OK, you want to extract the whole item when it satisfies the request. So your output record probably has to have the entire request record at the front, followed by the selected item, because you will need to know the field requested (from length, displacement, although perhaps field-number is another option? It would automatically work if the size of the field changed).

So, firstly and seperately, sort you request file and remove duplicates (if more than one person requests the same, you don't have to do the work twice).

Read your request file, storing it all in a table (set some reasonable limits, do some check to not overwrite if limits busted).

"Step along" each record on main file getting the item type. Create your output of request (from table now in program) and the current item. Continue untile end of input file. You can ignore the spanning (ie treat all records the same) as you are not associating item to transaction in any way. Apart from where to start the search for that spanned record....
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby enrico-sorichetti » Wed Mar 09, 2011 2:11 pm

to make things easier for people trying to help You,
why instead of giving Your interpretation/descriptions, quite approximate I dare to say,
don' t You get hold of the application documentation and post the relevant info from there ???
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby BillyBoyo » Wed Mar 09, 2011 2:18 pm

Enrico is right. If you gave the infomation up front, you'd have the answer by now. But, we're getting there.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: HOW TO GET REQUIRED FIELDS INTO O/P FILE

Postby Mann_B » Wed Mar 09, 2011 3:00 pm

Thanks all for ur replies ..but I do not have any application doc as of now.
We already have the process of processing the spanned i/p record,now our requirement is to get the requested fields in the o/p.
Thanks you soo much for your quick responses
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post