Posted: Sun Dec 05, 2010 4:37 am Post subject: DFSORT - SORT/COPY fields based on another field
Hello,
I have a sort jcl that extracts certain fields from a sequential file and creates an extract file. Now I have a change to add one more field from the input file to the output extract file.
Lets say the additional field is called 'payment amount' in my input file. Actually this field is in an OCCURS clause of OCCURS 3 times. Also, there is another field in the input layout called 'payment amount occurs flag'.
I need to copy the payment amount to the extract file based on the 'payment amount occurs flag'. For example: if the flag is havign value '2', then I need to copy data from 2nd occurs for the payment amount.
Assuming payment-amt1 is at position 10, payment-amt2 is at positon 22, payment-amt3 is at position 31. Now, if payment-occurs-flag is '1' then I need to copy amount value from position 10, else if the occurs-flag is '2' then I need to copy amount value from position 22 , else if the occurs-flag is '3' then I need to copy amount value from 31.
Can anyone please share a sample SORT JCL for this ? As I mentioned I already have a sort jcl that does the simple sort copy and outrec build.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Sun Dec 05, 2010 3:29 pm Post subject:
kumar26fl,
The following DFSORT JCL will give you the desired results. I assumed your input is FB and the contents you want to pick are from pos 50 for 30 bytes.
Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
1 PAYMENT1 SOME DATA TO PICK-1
2 PAYMENT1 PAYMENT2 SOME DATA TO PICK-2
3 PAYMENT1 PAYMENT2 PAYMENT3 SOME DATA TO PICK-3
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'1'),BUILD=(50,30,10,8)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'2'),BUILD=(50,30,22,8)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'3'),BUILD=(50,30,31,8))
//*
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum