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,
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.
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).
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.
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 ?
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.