How to reformat the input in a cobol program



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

How to reformat the input in a cobol program

Postby anjali » Tue Jul 08, 2008 5:29 pm

Hi all,

I have an urgent requirement in my project to reformat the input data where the input data will be like:
Tag ID--> 2 bytes
Length--> 2 bytes
Data--> depending on the length

For example, I have the input data as "3802AB5501X2403MCC" where 38 is the tag id followed by length as 02 and data as "AB"; the next tag id is 55 and length is 01 and data is "X" and so on (it can have upto 60 bytes). I am reading the input file and storing it in a table. Here, I have to insert a new tag ID 50 with length as "02" and data as"XX" inside the input data and reformat the entire data in ascending sequence and write a reformatted output data in ascending order.

Can anyone please help me with some piece of sample COBOL code.

Thanks in advance,
Anjali
anjali
 
Posts: 5
Joined: Tue Jul 08, 2008 5:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to reformat the input in a cobol program

 

Re: How to reformat the input in a cobol program

Postby anjali » Tue Jul 08, 2008 5:30 pm

The ascending sequence should be based on the tag ID. I missed it there.
anjali
 
Posts: 5
Joined: Tue Jul 08, 2008 5:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to reformat the input in a cobol program

Postby dick scherrer » Tue Jul 08, 2008 9:35 pm

Hello,

Please post a better example of your input records (plural) and the output you want from the example input.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to reformat the input in a cobol program

Postby anjali » Wed Jul 09, 2008 9:52 am

The input records can look like:
Input Record:2001A6301B1801C7801D1201E
Output record should be 1201E1801C2001A5002XX6301B7801D

Similarly, there can be 'n' number of input records...

I need to rearrange the input and insert a new element, length and its data and finally after the end of the record is reached,the output should be in ascending sequence of tag ID.

Please let me know if anything more is needed.
anjali
 
Posts: 5
Joined: Tue Jul 08, 2008 5:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to reformat the input in a cobol program

Postby dick scherrer » Wed Jul 09, 2008 9:46 pm

Hello,

Please let me know if anything more is needed.
Yes, more is needed. . .

Why did the tiny bit of "input" change from your first post? You need to be more explicit about how the "rules" work. The example is all right, but the descripotion is not completely clear (at least to me ;) ). It will probably help if you "talk thru" the steps you need to use to "break apart" the input field by field as well as the steps to build the new output record.

Is it true that each input record will generate only 1 output record?

Keep in mind that your requirement is completely clear to you, but may not be to others who read it.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to reformat the input in a cobol program

Postby anjali » Thu Jul 10, 2008 10:38 am

Hi,
The sample inputs are difderent in the first and second post but the logic to reformat the output reamins the same. Let me explain the requirement in a bit more detailed manner.

The input record contains three parts in it which are sub tag id followed by the length of that sub tag id and the actual data depending on the length of that sub tag id and the total length of the input record is 60 bytes. Every single input record will have a single corresponding output record. My requiremnet is to insert a new sub tag id 50 with length as 2 bytes and 2-byte alpha numeric data before sub tag ids greater than 50. The final output record should be reformatted in ascending order based on the sub tag id.

The steps can be:
1. Read the input records and load them in an internal table of 60 bytes.
2. Check if the first byte of the table is less than 5 then set the index up by 'n' bytes.
3. If the first byte is eaual to or greater than 5 and second byte is greater than 0, then insert the new sub tag 50 with length and data before the sub tag greater than 50
4. Finally write the output after the entire record is read in ascending sequence based on the sub tag id. The output record should have the least sub tag id first followed by its length and data and then the next highest sub tag id with its length and data and so on.
5. Continue the same process for all the input records in the file

I have almost done with the coding but it will be helpful if others can pour in their thoughts on the same to code it in an effective manner.

Thanks,
Anjali
anjali
 
Posts: 5
Joined: Tue Jul 08, 2008 5:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to reformat the input in a cobol program

Postby dick scherrer » Fri Jul 11, 2008 1:31 am

Hello,

If you have the code that uses some array(s) working cool.

If i needed to write this code, i would use an internal sort to order the output and reference modificaton to parse the input.

Each "sort record" would contain:
01  sort-record.
    05 sort-rec-no  pic 9(5) (unless you have more than 99k records)
    05 sort-tag     pic xx.
    05 sort-lth     pic 99
    05 sort-data    pic x(  ) - however long the max data lth

I'd define a "record count" in ws and increment this each time a record was read.
As i parsed the input, i'd create and release a record to the sort for each "entry". On return from the sort, i'd control on the "record number" and build the output, inserting the 50 entry where appropriate in each output record.

For the sort, input/output procedure would be used - not using/giving.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to reformat the input in a cobol program

Postby anjali » Fri Jul 11, 2008 9:47 am

Thanks Dick for your help.
anjali
 
Posts: 5
Joined: Tue Jul 08, 2008 5:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to reformat the input in a cobol program

Postby dick scherrer » Fri Jul 11, 2008 10:11 pm

You're welcome :)

If there are questions/problems as you proceed, someone will be here.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to reformat the input in a cobol program

Postby jayind » Sat Jul 12, 2008 4:40 pm

Just a thought....

inserting the 50 entry where appropriate in each output record.


Since you are using sort, i dont think you need to track of the count or value of tag id. After parsing the input record into the array, even if you add the '50' and related data at the end of the array, on sort it will automatically come in the sorted order...

Is this making sense?

Regards,
Jayind
jayind
 
Posts: 62
Joined: Wed Apr 23, 2008 1:37 pm
Location: Chennai, India
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post