Is it possible to process a file/records until a specific total is reached?
For example, I have a file that has 100 records but I need to stop processing when a specific total, e.g., $100, has been reached or exceeded. The next file could have 25 records but same requirement......need to stop processing after $100 has been reached or exceeded.
File layout:
DD000000000000000000010000000000011000075
DD000000000000000000020000000000089000075
DD000000000000000000030000000000100000075
In this case the total was reached after the first two records, so no need to continue processing.
Let me know.
Thanks!
Process file/records until a specific total is reached.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
What does this mean???
chillmo wrote:File layout:
DD000000000000000000010000000000011000075
DD000000000000000000020000000000089000075
DD000000000000000000030000000000100000075
Javas and Pythons come and go, but JCL and SORT stay forever.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
sergeyken wrote:What does this mean???chillmo wrote:File layout:
DD000000000000000000010000000000011000075
DD000000000000000000020000000000089000075
DD000000000000000000030000000000100000075
Hint:
What is presented here is (highly likely?) the "dump of input data"
The term "layout" means: description of field name/position/type/size/purpose for EACH field of the WHOLE record.
At least for the field(s) you are interested in.
The rest of records is completely irrelevant for your issue; it only adds unneeded mess to this topic.
When it is missing, the question cannot be answered.
Javas and Pythons come and go, but JCL and SORT stay forever.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
Since the issue of this topic is not very trivial for the Beginners Forum, I can give one of possible solutions not waiting for any response from the TS.
As usually, I use my own test "layout" only to demonstrate the approach, not to allow using it as copy-and-paste code, without a minor understanding how it works.
As usually, I use my own test "layout" only to demonstrate the approach, not to allow using it as copy-and-paste code, without a minor understanding how it works.
Code: Select all
// EXPORT SYMLIST=*
//*
// SET LIMIT=100
//*====================================================================
//SORTSUM EXEC PGM=SYNCTOOL
//*
//SSMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//SORTIN DD *
AAAAAAAA 1234567890 ZZZZZZZZ 9876543210 00000011 XXXXXXXX
QQQQQQQQ 2345678901 DDDDDDDD 8765432109 00000089 HHHHHHHH
CCCCCCCC 3456789012 NNNNNNNN 7654321098 00000100 KKKKKKKK
YYYYYYYY 4567890123 PPPPPPPP 6543210987 00000125 JJJJJJJJ
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*
//NUM1 DD SPACE=(TRK,(20,20))
//NUM2 DD SPACE=(TRK,(20,20))
//NUM12 DD SPACE=(TRK,(20,20))
//*
//SORTOUT DD SYSOUT=*
//*....................................................................
//TOOLIN DD *
COPY FROM(SORTIN) TO(NUM1) USING(SEQ1)
COPY FROM(SORTIN) TO(NUM2) USING(SEQ2)
SORT JKFROM TO(NUM12) USING(JOIN)
COPY JKFROM TO(SORTOUT) USING(DROP)
//*....................................................................
//SEQ1CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=1) record nums from 1
//*....................................................................
//SEQ2CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=2) record nums from 2
//*....................................................................
//JOINCNTL DD *
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED
JOINKEYS F2=NUM2,FIELDS=(81,8,A),SORTED
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80, full input record
F1:81,8, SEQNUM1
F2:41,8) prev record amount
* Calculate running SUM
INREC BUILD=(81,8, SEQNUM1
10:41,08,ZD,ADD,89,8,ZD,TO=ZDF,LENGTH=8)
SORT FIELDS=(1,8,CH,A) - make sure JOIN did not change the order
//*....................................................................
//DROPCNTL DD *,SYMBOLS=EXECSYS
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED numbered input
JOINKEYS F2=NUM12,FIELDS=(1,8,A),SORTED,
INCLUDE=(10,8,ZD,LE,&LIMIT) allowed SEQNUMs
REFORMAT FIELDS=(F1:1,80) = initial record
//*
//*====================================================================
Javas and Pythons come and go, but JCL and SORT stay forever.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
An improved version, to avoid double scan of the original dataset.
Code: Select all
// EXPORT SYMLIST=*
//*
// SET LIMIT=100
//*====================================================================
//SORTSUM EXEC PGM=SYNCTOOL
//*
//SSMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//SORTIN DD *
AAAAAAAA 1234567890 ZZZZZZZZ 9876543210 00000011 XXXXXXXX
QQQQQQQQ 2345678901 DDDDDDDD 8765432109 00000089 HHHHHHHH
CCCCCCCC 3456789012 NNNNNNNN 7654321098 00000100 KKKKKKKK
YYYYYYYY 4567890123 PPPPPPPP 6543210987 00000125 JJJJJJJJ
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*
//NUM1 DD SPACE=(TRK,(20,20))
//NUM2 DD SPACE=(TRK,(20,20))
//NUM12 DD SPACE=(TRK,(20,20))
//*
//SORTOUT DD SYSOUT=*
//*....................................................................
//TOOLIN DD *
COPY FROM(SORTIN) USING(SEQN)
SORT JKFROM TO(NUM12) USING(JOIN)
COPY JKFROM TO(SORTOUT) USING(DROP)
//*....................................................................
//SEQNCNTL DD *
OUTFIL FNAMES=NUM1,BUILD=(1,80,SEQNUM,8,ZD,START=1) renum from 1
OUTFIL FNAMES=NUM2,BUILD=(1,80,SEQNUM,8,ZD,START=2) renum from 2
//*....................................................................
//JOINCNTL DD *
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED
JOINKEYS F2=NUM2,FIELDS=(81,8,A),SORTED
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80, full input record
F1:81,8, SEQNUM1
F2:41,8) prev record amount
* Calculate running SUM
INREC BUILD=(81,8, SEQNUM1
10:41,08,ZD,ADD,89,8,ZD,TO=ZDF,LENGTH=8)
SORT FIELDS=(1,8,CH,A) - make sure JOIN did not change the order
//*....................................................................
//DROPCNTL DD *,SYMBOLS=EXECSYS
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED numbered input
JOINKEYS F2=NUM12,FIELDS=(1,8,A),SORTED,
INCLUDE=(10,8,ZD,LE,&LIMIT) allowed SEQNUMs
REFORMAT FIELDS=(F1:1,80) = initial record
//*
//*====================================================================
Javas and Pythons come and go, but JCL and SORT stay forever.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
As usually, after reviewing any code once again one can find new ways for its further improvement, and removing unneeded steps.
Code: Select all
// EXPORT SYMLIST=*
//*
// SET LIMIT=100 the desired limit for maximum total amount
//*====================================================================
//SORTSUM EXEC PGM=SYNCTOOL
//*
//SSMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//SORTIN DD *
AAAAAAAA 1234567890 ZZZZZZZZ 9876543210 00000011 XXXXXXXX
QQQQQQQQ 2345678901 DDDDDDDD 8765432109 00000089 HHHHHHHH
CCCCCCCC 3456789012 NNNNNNNN 7654321098 00000100 KKKKKKKK
YYYYYYYY 4567890123 PPPPPPPP 6543210987 00000125 JJJJJJJJ
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*
//NUM1 DD SPACE=(TRK,(20,20))
//NUM2 DD SPACE=(TRK,(20,20))
//NUM12 DD SPACE=(TRK,(20,20))
//*
//SORTOUT DD SYSOUT=*
//*....................................................................
//TOOLIN DD *
COPY FROM(SORTIN) USING(SEQN)
SORT JKFROM USING(JOIN)
//*....................................................................
//SEQNCNTL DD *
OUTFIL FNAMES=NUM1,BUILD=(1,80,SEQNUM,8,ZD,START=1) renum from 1
OUTFIL FNAMES=NUM2,BUILD=(1,80,SEQNUM,8,ZD,START=2) renum from 2
//*....................................................................
//JOINCNTL DD *,SYMBOLS=EXECSYS
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED
JOINKEYS F2=NUM2,FIELDS=(81,8,A),SORTED
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80, full input record
F1:81,8, SEQNUM1
F2:41,8) prev record amount
* Calculate running SUM
INREC OVERLAY=(89:41,8,ZD,ADD,89,8,ZD,TO=ZDF,LENGTH=8)
SORT FIELDS=(81,8,CH,A) - make sure the JOIN did not change the order
OUTFIL FNAMES=SORTOUT,
INCLUDE=(89,8,ZD,LE,&LIMIT), include until specified sum
BUILD=(1,80) truncate to original size
//*
//*====================================================================
Javas and Pythons come and go, but JCL and SORT stay forever.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
To be on safe side for ADD operation, it may be useful to clean-up the field in the non-matching first record
Code: Select all
. . . . . . . .
REFORMAT FIELDS=(F1:1,80, full input record
F1:81,8, SEQNUM1
F2:41,8), prev record amount
FILL=C'0' zero the unpaired first record prev. value
. . . . . . . . . . . . . . .
Javas and Pythons come and go, but JCL and SORT stay forever.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
During the weekend I've reviewed this topic once again, and I found my misunderstanding of the original issue.
That's why my previous solution would not produce the result really expected.
Please find here another approach to this task.
Sorry for misleading previous recommendations.
That's why my previous solution would not produce the result really expected.
Please find here another approach to this task.
Code: Select all
// EXPORT SYMLIST=*
//*
// SET LIMIT=100
//*====================================================================
//SORTSUM EXEC PGM=SYNCTOOL
//*
//TOOLMSG DD SYSOUT=*
//SSMSG DD SYSOUT=*
//SORTIN DD *
AAAAAAAA 1234567890 ZZZZZZZZ 9876543210 00000011 XXXXXXXX
QQQQQQQQ 2345678901 DDDDDDDD 8765432109 00000089 HHHHHHHH
CCCCCCCC 3456789012 NNNNNNNN 7654321098 00000100 KKKKKKKK
YYYYYYYY 4567890123 PPPPPPPP 6543210987 00000125 JJJJJJJJ
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*
//SUB1 DD SPACE=(TRK,(20,20))
//*
//SORTOUT DD SYSOUT=*
//*....................................................................
//TOOLIN DD *
COPY FROM(SORTIN) TO(SUB1) USING(SUBT)
COPY FROM(SUB1) TO(SORTOUT) USING(DROP)
//*....................................................................
//SUBTCNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD, renumber for unique id
89:8X) space for trailer
OUTFIL FNAMES=SUB1,
REMOVECC,NODETAIL,
SECTIONS=(81,8, unique num for each record
TRAILER3=(1,80, original record part
SUBTOTAL=(41,8,ZD,EDIT=(TTTTTTTT)))) running sum
//*....................................................................
//DROPCNTL DD *,SYMBOLS=EXECSYS
INREC IFTHEN=(WHEN=GROUP, detect the group of records needed
BEGIN=(81,8,ZD,EQ,41,8,ZD),
END=(81,8,ZD,GE,&LIMIT),
PUSH=(89:ID=4))
OUTFIL FNAMES=SORTOUT,
INCLUDE=(89,4,CH,NE,C' '), select records from the marked group
BUILD=(1,80) truncate to original LRECL
//*
//*====================================================================
Sorry for misleading previous recommendations.
Javas and Pythons come and go, but JCL and SORT stay forever.
Re: Process file/records until a specific total is reached.
Sergeyken,
Sorry for the late response but here's the breakdown of fields:
1st record:
Application code (2 bytes) - DD
Account number (20 bytes) - 00000000000000000001
Amount (15 bytes) - 000000000001100 ($11.00)
Source code (4 bytes) - 0075
2nd record:
Application code (2 bytes) - DD
Account number (20 bytes) - 00000000000000000002
Amount (15 bytes) - 000000000008900 ($89.00)
Source code (4 bytes) - 0075
3rd record:
Application code (2 bytes) - DD
Account number (20 bytes) - 00000000000000000003
Amount (15 bytes) - 000000000010000 ($100.00)
Source code (4 bytes) - 0075
Since the total of $100 was reached after the first two records, Sort should step processing and write out the two records.
If the next file has
The sort should stop processing and write out the first record.
Hope this helps!
Sorry for the late response but here's the breakdown of fields:
1st record:
Application code (2 bytes) - DD
Account number (20 bytes) - 00000000000000000001
Amount (15 bytes) - 000000000001100 ($11.00)
Source code (4 bytes) - 0075
2nd record:
Application code (2 bytes) - DD
Account number (20 bytes) - 00000000000000000002
Amount (15 bytes) - 000000000008900 ($89.00)
Source code (4 bytes) - 0075
3rd record:
Application code (2 bytes) - DD
Account number (20 bytes) - 00000000000000000003
Amount (15 bytes) - 000000000010000 ($100.00)
Source code (4 bytes) - 0075
Code: Select all
DD000000000000000000010000000000011000075
DD000000000000000000020000000000089000075
DD000000000000000000030000000000100000075
Since the total of $100 was reached after the first two records, Sort should step processing and write out the two records.
If the next file has
Code: Select all
DD000000000000000000030000000000100000075
DD000000000000000000010000000000111000075
DD000000000000000000020000000000089000075
The sort should stop processing and write out the first record.
Hope this helps!
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Process file/records until a specific total is reached.
I have provided you with the working approach to this task.
It is your responsibility to adjust this general solution to your own particular record layout.
It is your responsibility to adjust this general solution to your own particular record layout.
Javas and Pythons come and go, but JCL and SORT stay forever.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 3
- 6710
-
by sergeyken
View the latest post
Sun May 01, 2022 11:26 pm
-
-
Join parts of two records from same file
by Mickes » Thu Apr 27, 2023 3:47 am » in DFSORT/ICETOOL/ICEGENER - 3
- 1193
-
by sergeyken
View the latest post
Sat Apr 29, 2023 1:32 pm
-
-
-
File def'n-problem with different records layouts
by ralph » Tue Oct 26, 2021 10:47 pm » in IBM Cobol - 2
- 1509
-
by ralph
View the latest post
Wed Oct 27, 2021 1:42 am
-
-
-
Split file, SORT then append records.
by Esmayeelhusen » Fri Aug 04, 2023 6:37 pm » in DFSORT/ICETOOL/ICEGENER - 10
- 5041
-
by Esmayeelhusen
View the latest post
Wed Aug 09, 2023 7:39 am
-
-
-
Create multiple records based on one record within a file.
by chillmo » Thu Aug 11, 2022 3:54 am » in Syncsort/Synctool - 5
- 7672
-
by sergeyken
View the latest post
Fri Aug 12, 2022 2:23 am
-