Posted: Wed Dec 15, 2021 11:57 am Post subject: Counting & adding the amounts on the basis of sign bit.
Hi Team,
I have one requirement, we have one input file (FB, LRECL-200) where we have amounts with signed bytes defined as PIC S9(11)V9(2), sign is stored in the last bit. In the file we can see them from position 4 till 16 in the detailed record.
In the below input file first record is header starting with '1' and records starting with '2' are detailed records and record starting with '3' is trailer:
We want to create two output files on the basis of last record at position 20. If it is 'A' than write it in output FILE1 else if 'B' write in output FILE2.
But with this we need to write the header and trailers as well in both the files. Header will be same but in trailer we need to have in below layout:
Code:
First byte is '3'
12 bytes - Counts of positive amounts
12 bytes - Counts of negative amounts
15 bytes - sum of positive amounts - S9(13)V9(02)
15 bytes - sum of negative amounts -S9(13)V9(02)
15 bytes - Total amount (sum of positive and negative amts) -S9(13)V9(02)
How can we achieve this. To identify the positive and negative records, do we need to first change it to ZD or we simply have a way in DFSORT to identify the positive and negative records from last byte.
Now coming to the requirement , it is quite easy. Essentially your amount is ZD format which has the sign over punched. This is the representation of the ZD numbers . The number on top represents the sign overpunch and the lower number represents the readable decimal number
Hex C0 thru C9 are positive numbers and D0 thru D9 are negative numbers. So -5 would look as 000000000000N
Since your input field already had the sign overpunched we simply can check if it is a positive or not by checking > 0 for positive numbers and < 0 for negative numbers.
Here is an untested JCL which will give you the desired results
Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=your.input.fb200.file
//FILEA DD SYSOUT=*
//FILEB DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(01,1,CH,EQ,C'1',OR, $ HEADER
20,1,SS,EQ,C'A,B') $ A OR B RECORDS
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(201:C'0', $ INIT POSITIVE COUNT
202:C'0', $ INIT NEGATIVE COUNT
204:+0,TO=ZD,LENGTH=13, $ INIT POSITIVE TOTAL
220:+0,TO=ZD,LENGTH=13, $ INIT NEGATIVE TOTAL
235:+0,TO=ZD,LENGTH=13)), $ INIT FULL TOTAL
IFTHEN=(WHEN=(04,13,ZD,GT,0,AND, $ IF VALUE > 0
20,1,SS,EQ,C'A,B'), $ AND HAS A OR B
OVERLAY=(201:C'1', $ 1 FOR POSITIVE COUNT
204:04,13, $ POSITIVE TOTAL
235:04,13)), $ FULL TOTAL
IFTHEN=(WHEN=(04,13,ZD,LT,0,AND, $ IF VALUE < 0
20,1,SS,EQ,C'A,B'), $ AND HAS A OR B
OVERLAY=(202:C'1', $ 1 FOR NEGATIVE COUNT
220:04,13, $ NEGATIVE TOTAL
235:04,13)) $ FULL TOTAL
OUTFIL FNAMES=FILEA,REMOVECC, $ OUTFILE A
BUILD=(1,200), $ ORIGINAL LRECL
INCLUDE=(01,1,CH,EQ,C'1',OR, $ HEADER OR
20,1,CH,EQ,C'A'), $ TYPE A RECORD
TRAILER1=('3', $ TRAILER ID
TOT=(201,01,ZD,M11,LENGTH=12), $ TOTAL POSITIVE COUNT
TOT=(202,01,ZD,M11,LENGTH=12), $ TOTAL NEGATIVE COUNT
TOT=(204,13,ZD,ZDC,LENGTH=15), $ TOTAL POSITIVE AMOUNT
TOT=(220,13,ZD,ZDC,LENGTH=15), $ TOTAL POSITIVE AMOUNT
TOT=(235,13,ZD,ZDC,LENGTH=15)) $ TOTAL AMOUNT
OUTFIL FNAMES=FILEB,REMOVECC, $ OUTFILE B
BUILD=(1,200), $ ORIGINAL LRECL
INCLUDE=(01,1,CH,EQ,C'1',OR, $ HEADER OR
20,1,CH,EQ,C'B'), $ TYPE B RECORD
TRAILER1=('3', $ TRAILER ID
TOT=(201,01,ZD,M11,LENGTH=12), $ TOTAL POSITIVE COUNT
TOT=(202,01,ZD,M11,LENGTH=12), $ TOTAL NEGATIVE COUNT
TOT=(204,13,ZD,ZDC,LENGTH=15), $ TOTAL POSITIVE AMOUNT
TOT=(220,13,ZD,ZDC,LENGTH=15), $ TOTAL POSITIVE AMOUNT
TOT=(235,13,ZD,ZDC,LENGTH=15)) $ TOTAL AMOUNT
/*
Adding to my previous query. Could you please help me by suggesting that in case in my File A there is no record(empty file created) than no record should be written into the file. As of now Trailer record is getting printed. I want my file to be blank in case no record selected.
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
Posted: Thu Nov 17, 2022 1:48 pm Post subject:
Srishti Rawat wrote:
Hi Kolusu,
Adding to my previous query. Could you please help me by suggesting that in case in my File A there is no record(empty file created) than no record should be written into the file. As of now Trailer record is getting printed. I want my file to be blank in case no record selected.
Srishti Rawat,
You can add a step to check if the file is empty and then skip the actual step that is creating the totals.
Code:
//EMPTCHK EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DISP=SHR,DSN=your.input.fb200.file
//TOOLIN DD *
COUNT FROM(IN) EMPTY RC4 USING(CTL1)
/*
//CTL1CNTL DD *
INCLUDE COND=(01,1,CH,EQ,C'1',OR, $ HEADER
20,1,SS,EQ,C'A,B') $ A OR B RECORDS
/*
//STEP0100 EXEC PGM=SORT,COND=(4,EQ,EMPTCHK)
..
or
Code:
//EMPTCHK EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=your.input.fb200.file
//SORTOUT DD DUMMY
//SYSIN DD *
OPTION COPY,NULLOUT=RC4
INCLUDE COND=(01,1,CH,EQ,C'1',OR, $ HEADER
20,1,SS,EQ,C'A,B') $ A OR B RECORDS
/*
//STEP0100 EXEC PGM=SORT,COND=(4,EQ,EMPTCHK)
But I need if at 20th position we have 'A' than do not right anything, create an empty file. Whereas, File B is fine, trailer should be written to it for the given condition even if we dont have matching records.
Is it possible to do with the same sortcard rather than having additional steps in PROC?
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
Posted: Thu Nov 17, 2022 6:47 pm Post subject:
Srishti Rawat wrote:
Hi Kolusu,
Thanks for your reply.
But I need if at 20th position we have 'A' than do not right anything, create an empty file. Whereas, File B is fine, trailer should be written to it for the given condition even if we dont have matching records.
Srishti Rawat,
You are better off having the EMPTY file check after you have created the Summary files A and B.
Srishti Rawat wrote:
Is it possible to do with the same sortcard rather than having additional steps in PROC?
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