Reason why this is interesting is because it first requires to uniquely identify the 'Code' which are mapped to a certain 'Type'; once done, it again requires to GROUP all such 'Code' which were earlier tagged - this is where the task actually becomes a challenge, i.e. how do we uniquely group the records with the ones that were earlier tagged. If this is figured out, then rest of the code is a breeze.
In a real-world situation, the TYPE values can be multiple/varying.
Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
Posted: Wed May 31, 2017 10:38 am Post subject: Re: Conditional data selection
Aki88 wrote:
Hello,
This post is taken from another forum.
It poses an interesting challenge; posting here to expand the DFSORT expert solution base.
Requirement: If first 5 bytes (1,5) of Type is 30000, then for the corresponding code all types should be written to the output file.
Aki88,
Unless I am mistaken, it is a quite simple task. Use the trick of matching the file to it self but for the JNF2 subtask we will only pull the 30000 records. something like this
As always, hats off to the simplicity of your solution.
I won't lie, EVERYTHING other than JOINKEYS had crossed my mind
And I think it might be because I was working on multiple things that used IFTHEN constructs so JOINKEYS didn't even strike me once, not even close.
The premise being, add an identifier using the primary key values such that secondary values - if SORTed - become the first character in 'Their' particular GROUP chain.
Then SORT them such that they are GROUPed together.
Now that this is achieved, then it is another GROUP operation with PUSH to uniquely identify them all.
But this is where I lose control over it! Unsure how to drop the remaining records. To my best guess, I think another IFTHEN operation is required in INREC so that I can use an OMIT in OUTFIL.
After which I can work on retaining the original order of records.
Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
Posted: Tue Jun 13, 2017 10:59 am Post subject:
Aki88,
You are complicating the request too much. It is actually quite simple. Here is a version to give you un-ordered records. ie. 30000 records becomes the first record.
Code:
//***************************************************************
//* USE ALTSEQ CODE TO TRANSLATE '30000' TO SPACES SO WHEN **
//* SORTED IT WILL BE THE FIRST RECORD. **
//* **
//* '0' = X'F0' | '3' = X'F3' | SPACE = X'40' **
//* **
//* REPLACING X'F3' AND X'F0' WITH X'40' WILL MAKE **
//* '30000' AS ' ' **
//***************************************************************
//*
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30000 00000 <<< FIRST RECORD
*****
10000 11111
11000 11111
20000 11111
30000 11111 <<< LAST RECORD
AAAAA *****
10000 12345
11000 12345
30000 12345 <<< 3RD RECORD
20000 12345
BBBBB *****
11000 45624
25000 45624
CCCCC *****
34000 33669
30000 33669 <<< LAST RECORD
//SORTOUT DD SYSOUT=*
//SYSIN DD *
ALTSEQ CODE=(F340,F040)
30000 00000 <<< FIRST RECORD
30000 11111 <<< LAST RECORD
10000 11111
11000 11111
20000 11111
30000 12345 <<< 3RD RECORD
10000 12345
11000 12345
20000 12345
30000 33669 <<< LAST RECORD
34000 33669
If you want the records in the order they came in then you need to use the following control cards
30000 00000 <<< FIRST RECORD
10000 11111
11000 11111
20000 11111
30000 11111 <<< LAST RECORD
10000 12345
11000 12345
30000 12345 <<< 3RD RECORD
20000 12345
34000 33669
30000 33669 <<< LAST RECORD
ALTSEQ was a nifty one! I agree, it saves the whole shebang of configuring a way to bring the record on top.
Aside, on looking at your SORT card, I realized I was missing an OUTREC ; if I had to go by my original thought, then this is how the card looks now (have retained the extra bytes of data for testing):
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