|
View previous topic :: View next topic
|
| Author |
Message |
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Hello all,
I have one requirement where could some one of you help me in this regard.
I have a file with card number and values as below with order sequence (card/value),
| Code: |
111111 123456
111111 123457
111111 999999
111111 999999
222222 999999
333333 456789
333333 999999
...
|
My requirement is for each card, when it has value 999999, then I should check if previous record has same card number with good value, if so, I have to take the previous value and increase it by 1 and store it current record. If the previous record doesn't have same card number, then set the current record value as 000000. Like as below,
| Code: |
111111 123456
111111 123457
111111 123458
111111 123459
222222 000000
333333 456789
333333 456790
...
|
I planned to do that via COBOL, but I feel it can done via ICETOOL / SYNCSORT. Thanks for your response. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
See if your SyncSort has KEYBEGIN in WHEN=GROUP.
Where there are existing number (not nines) are they guaranteed to be correct?
| Code: |
111111 123456
111111 123457
111111 999999
111111 999999 |
So 12357 (and any like it) will always be correct? |
|
| Back to top |
|
 |
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Hi Bill,
I will check SYNCSORT function. Yes, the numbers other than 999999 will always be correct. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Use WHEN=INIT to set up a SEQNUM with a START of zero and a RESTART pointing to the key. Make it long enough to cover the maximum number you can have within a key.
Use WHEN=GROUP with BEGIN for zero in the sequence number, PUSH the key after the sequence number.
Then another WHEN=INIT which "calculates" by adding the sequence to the PUSHed value.
Finally WHEN=(logicalexpression to test for nines and set to zero (OVERLAY) if there are.
Use IFOUTLEN (fixed-length records) or BUILD (variable-length records) to get rid of the extended data.
Edited for clarity :-) |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Assuming that the valid values (except 999999) in column 8 to 13 will always be in sequence, you can try the below job:
| Code: |
//STEP01 EXEC PGM=SORT
//SORTIN DD *
----+----1----+----2----+----3----+----4----+----5----+----6----+
111111 123456
111111 123457
111111 999999
111111 999999
222222 999999
333333 456789
333333 999999
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(21:SEQNUM,1,ZD,START=0,RESTART=(1,6))),
IFTHEN=(WHEN=GROUP,BEGIN=(21,1,CH,EQ,C'0'),
PUSH=(31:8,6))
OUTREC IFOUTLEN=20,
IFTHEN=(WHEN=INIT,
OVERLAY=(8:31,6,ZD,ADD,
21,1,ZD,EDIT=(TTTTTT))),
IFTHEN=(WHEN=(8,6,CH,EQ,C'999999'),
OVERLAY=(8:C'000000')) |
Output
| Code: |
111111 123456
111111 123457
111111 123458
111111 123459
222222 000000
333333 456789
333333 456790 |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(21:SEQNUM,1,ZD,START=0,RESTART=(1,6))),
IFTHEN=(WHEN=GROUP,BEGIN=(21,1,CH,EQ,C'0'),
PUSH=(31:8,6)),
IFTHEN=(WHEN=INIT,
OVERLAY=(8:31,6,ZD,ADD,
21,1,ZD,EDIT=(TTTTTT))),
IFTHEN=(WHEN=(8,6,CH,EQ,C'999999'),
OVERLAY=(8:C'000000')),
IFOUTLEN=20 |
A slight rearrangement. Largely to highlight that WHEN=INIT can also appear after WHEN=GROUP and to show that the location of IFOUTLEN is not significant.
For developing, it is convenient to leave "gaps" when extending records, but they should the gaps need to be removed if the data is to be sorted (not here, where it wouldn't matter much). |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Thanks Bill.
| Quote: |
| I planned to do that via COBOL, but I feel it can done via ICETOOL / SYNCSORT. |
@dudenithy: Please note that I have tested this job in Syncsort V1.4 and not in DFSORT. But hopefully it should work in DFSORT as well. |
|
| Back to top |
|
 |
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Hi Bill and Mistah,
I have just started analysing the options today (No access to host from home). I found the complete piece of coding here from you all. I believe completely that it willwork . Thanks a lot for your time.  |
|
| Back to top |
|
 |
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Hi Bill,
I just have one question. My input file is a VB file (maximum rec length, say 100 bytes). So is it good to keep the extended data at the last after the real data, or to have these extended data at the beginning of the real data? If as in above example (extended data after the real data), I'm not sure how to give the reference position. Could you kindly help ? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
For a VB, you should extend at the beginning of the record.
I'd put in another INIT as the first one with BUILD=(1,4,7X,5) to make space for the extension.
Then change the first OVERLAY, 5: for the sequence number, and 6: for the key in the PUSH, and change the other locations as necessary.
To get rid of the extension, you can no longer use IFOUTLEN.
To keep it simple, because of the IFTHEN=(WHEN=logical expression), I'd use a simple OUTREC with BUILD=(1,4,12). This will ignore the 7 bytes from position five. |
|
| Back to top |
|
 |
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
| Yes Bill, Even I thought that should be the easiest and simple. Thanks four confirmation. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|