Page 1 of 1

Hierarchical COBOL file with Parent/Child relations

Posted: Thu Oct 01, 2015 6:39 pm
by ureddy
Hi All,

I am trying to read a COBOL File with CFF stage. The file has multiple record types (AB00,AB01,AB02 etc). Each record type will have different length. Sample data is below.

Header -> Abc.txt20150210
Parent -> 00000AB00XXXXXXXX99TTTT
Child 1 -> 00000AB01yy1234
child 2 -> 00000AB02pp123456789
Parent -> 00000AB00ppppppppp77TTTT
Child 1 -> 00000AB01pp2345
child 2 -> 00000AB02ab123456789
Trailer -> Count AB00 2 AB01 2 AB02 2


So I want to add 18,2 position (99 / 77 value) of parent record to the immediate child records. Sample outout as below.


Child 1 -> 9900000AB01yy1234
child 2 -> 9900000AB02pp123456789
Child 1 -> 7700000AB01pp2345
child 2 -> 7700000AB02ab123456789

I have the copybooks for each record types and could able to read the data each record type-wise but I am not able to match parent record value to child as there is no common field between parent and its child so I need to go by the order of parent and child records present in the file.

I tried to read the entire file as single field and dump to sequential file and then loop through the file based on the parent record to make the desired output but due to different field lengths could not able to read the file properly. The order and fields position of records are interchanging (COMP fields also present).

My record schema for CFF stage is below.
{record_format={type=implicit}, delim=none, quote=none, binary, ebcdic, native_endian, charset='ASCL_ISO8859-1', round=round_inf, nofix_zero}

Can any one please let me know how can I get the desired output?

Posted: Fri Oct 02, 2015 9:51 am
by FranklinE
Reddy,

You really need a Cobol developer to work with you there. I and others can only offer limited help to you here.

First, don't call them parent and child. What you have are sub-headers (parent) with details (child).

Cobol handles this with standard practice, checking the record type of the next record read to determine branching (details) or returning to the top of the logic (new sub-trailer or eof/trailer). A Cobol developer can explain how that works, and you can work on translating that to DataStage code.

Posted: Fri Oct 02, 2015 12:19 pm
by ureddy
Thanks FranklinE for the explanation.
How can we read the file sequentially as is using CFF stage because i have different record layouts with different lengths. If I read the file as is then i can dump it to sequential file and do the rest of processing.

I asked the Mainframe developer to add the parent record indicator value to its child record but they are not ready to change the file layout due to much effort involved from their end.

Posted: Fri Oct 02, 2015 12:43 pm
by FranklinE
You can use CFF as is with different lengths on each record type. I worked it out. Give it a try, and if you can't solve it in a few days post your errors and I should be able to help. Please note: I can't do your design for you.
ureddy wrote:I asked the Mainframe developer to add the parent record indicator value to its child record but they are not ready to change the file layout due to much effort involved from their end.
Do what you can to get them to do it, however long it takes. I do understand their answer -- I hear it all the time :D -- but Cobol file layouts should be standardized to a common record length just from best practice.

Posted: Fri Oct 02, 2015 4:48 pm
by ray.wurlod
Adding FILLER is neither difficult nor time consuming.

Posted: Mon Oct 05, 2015 9:04 am
by FranklinE
ray.wurlod wrote:Adding FILLER is neither difficult nor time consuming.
To those responsible for doing it, it is work, and they really have better things to do with their time.

:x

Posted: Sat Nov 10, 2018 9:42 pm
by ureddy
I know it is old post, but it may help others, so I am posting the work-around logic that worked well for me.

step 1. While reading the parent record in filter condition used RECORD_TYPE='AB00' Or RECORD_TYPE='AB01' Or RECORD_TYPE='AB02'.
So the output from the above step is: master record with 'AB00' record type and also Master record with record type 'AB01' value and 'AB02' value (3 records came).
In transformer use stage variables for numbering for these each record types and load to datasets.

step 2. Read the record type 'AB01' and 'AB02' separately to other datasets.

step 3. Join 1st step dataset with the second step datasets to get the required values from master to child records.