Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref                 Calculate and rounding up value using dfsort Goto page 1, 2  Next
Author Message
useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Tue Apr 24, 2012 5:50 pm    Post subject: Calculate and rounding up value using dfsort hi,
i have requirement which i want to achieve it through dfsort.

(input lrecl=54,key-1-23)

 Code: 01  DETAIL.                                        03 KEY.                                          05 STORE              PIC 9(5).                05 PRODA             PIC 9(9).                05 PRODB             PIC 9(9).              03 DATA.                                        05 STocK         PIC S9(9) COMP-3.        05 QTY1          PIC S9(9) COMP-3.        05 QTY2          PIC S9(9) COMP-3.        05 IND           PIC X.                    05 SIZE          PIC 9(5)V99.              05 WEIGHT        PIC X.                    05 WGT           PIC 9(5)V99.

my input file is as below.
 Code: ----------------------------------------------------------------------------------------------------  (1-5)  (6-14)     (15-23)    (24-28)  (29-33)     (34-38)     (39-39)  (40-46)   (47-47) (48-54)       00010   050009698  008774500  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774600  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774700  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009700  008777500  +100    +222222222   +111111111    N      00005.00   I      00008.00 00010   050009700  008777600  +200    +222222222   +111111111    N      00006.10   I      00008.00 00010   050009700  008777700  +300    +222222222   +111111111    N      00007.20   I      00008.00 00010   050009700  008777800  +400    +222222222   +111111111    N      00008.00   I      00008.00 ------------------------------------------------------------------------------------------------------

WHEN PRODA has multiple PRODB in STORE (when ALL PRODB has same size ):

then calculate the stock as 100+100+100=300

WHEN PRODA has multiple PRODB in STORE (when ALL PRODB has different size ):

then recalculate stock=100+(200*00006.10)/00005.00+(300*000007.20)/00005.00+(400*00008.00)/00005.00

=100+240+420+640=1400

 Code: ---------------------------------------------------------------------------------------------------- 00010   050009698  008774500  +300    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774600  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774700  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009700  008777500  +100    +222222222   +111111111    N      00005.00   I      00008.00 00010   050009700  008777600  +240    +222222222   +111111111    N      00006.10   I      00008.00 00010   050009700  008777700  +420    +222222222   +111111111    N      00007.20   I      00008.00 00010   050009700  008777800  +640    +222222222   +111111111    N      00008.00   I      00008.00 --------------------------------------------------------------------------------------------------

step2:

bunch all the stock under that PRODA . and assign it to first PRODB.

and my final output should be
 Code: ---------------------------------------------------------------------------------------------------- 00010   050009698  008774500  +300    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774600  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774700  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009700  008777500  +1400   +222222222   +111111111    N      00005.00   I      00008.00 00010   050009700  008777600  +240    +222222222   +111111111    N      00006.10   I      00008.00 00010   050009700  008777700  +420    +222222222   +111111111    N      00007.20   I      00008.00 00010   050009700  008777800  +640    +222222222   +111111111    N      00008.00   I      00008.00 --------------------------------------------------------------------------------------------------

REGDS,
USEIT useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Tue Apr 24, 2012 5:51 pm    Post subject: i ran the below jcl . but it failed with rc=6. please correct me in case if anything wrong.

 Code: //STEP0100 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //INA DD DSN=MY INPUT FILE,DISP=SHR //INB DD DSN=SAME INPUT FILE,DISP=SHR //SORTOUT DD SYSOUT=* //SYSIN DD * OPTION COPY JOINKEYS F1=INA,FIELDS=(1,14,A),SORTED,NOSEQCK JOINKEYS F2=INB,FIELDS=(1,14,A) REFORMAT FIELDS=(F1:1,54,55,2,F2:57,4) INREC IFOUTLEN=54, IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(24:57,4)) //* //JNF1CNTL DD * INREC IFTHEN=(WHEN=INIT,OVERLAY=(57:24,4)), IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2)), IFTHEN=(WHEN=(55,2,ZD,GT,1), OVERLAY=(57:(57,4,PD,MUL,40,7,ZD),DIV,+5,EDIT=(TT),X, (57,4,PD,MUL,40,7,ZD),MOD,+5,EDIT=(TT)),HIT=NEXT), IFTHEN=(WHEN=(61,2,ZD,GT,0),OVERLAY=(24:57,4,PD,ADD,+1,EDIT=(TT))) //* //JNF2CNTL DD * INREC IFTHEN=(WHEN=INIT,OVERLAY=(57:24,4)), IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2)), IFTHEN=(WHEN=(55,2,ZD,GT,1), OVERLAY=(57:(57,4,PD,MUL,40,7,ZD),DIV,+5,EDIT=(TT),X, (57,4,PD,MUL,40,7,ZD),MOD,+5,EDIT=(TT)),HIT=NEXT), IFTHEN=(WHEN=(61,2,ZD,GT,0),OVERLAY=(24:57,4,PD,ADD,+1,EDIT=(TT))) SUM FIELDS=(57,4,PD) //*

regds,
useit Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8505
Location: Dubuque, Iowa, USA Posted: Tue Apr 24, 2012 5:57 pm    Post subject: Quote: i ran the below jcl . but it failed with rc=6. please correct me in case if anything wrong.
Why not post the actual output, instead of making everyone guess as to what the error message is? useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Tue Apr 24, 2012 6:34 pm    Post subject: my final output should be.

 Code: ---------------------------------------------------------------------------------------------------- 00010 050009698 008774500 +300 +222222222 +111111111 N 00006.00 I 00008.00 00010 050009698 008774600 +100 +222222222 +111111111 N 00006.00 I 00008.00 00010 050009698 008774700 +100 +222222222 +111111111 N 00006.00 I 00008.00 00010 050009700 008777500 +1400 +222222222 +111111111 N 00005.00 I 00008.00 00010 050009700 008777600 +240 +222222222 +111111111 N 00006.10 I 00008.00 00010 050009700 008777700 +420 +222222222 +111111111 N 00007.20 I 00008.00 00010 050009700 008777800 +640 +222222222 +111111111 N 00008.00 I 00008.00 --------------------------------------------------------------------------------------------------

Regds,
useit. Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7312 Posted: Tue Apr 24, 2012 6:36 pm    Post subject: Reply to: calculate and rounding up value using dfsort I suspect the EDIT=(TT) is a problem. In the original solution, you had a two-byte zoned-decimal, which is what the EDIT=(TT) would give you. Here, you have four-byte packed-decimal, according to your coding. TO=PD,LENGTH=4 would give you a four-byte packed-decimal answer. There may be other problems... Since you have the same code (except for the SUM) under both the JNFnCNTLs, I'd get it working on one first, and then copy it once it is working. If you post again, please use the Code tags and post the output from the step as well. useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Tue Apr 24, 2012 7:05 pm    Post subject: i tried removing EDIT class but it did not work for me:(. also i just dont want to hard code DIV,+5...i want to populate it dynamically..since that value can change for the next key.

say for example

 Code: 00010 050009700 008777700 +50 +222222222 +111111111 N 00002.00 I 00008.00 00010 050009700 008777800 +100 +222222222 +111111111 N 00003.00 I 00008.00

then i should recalulate it as

50+(100*3)/2=50+150=200

so my output will be

 Code: 00010 050009700 008777700 +200 +222222222 +111111111 N 00002.00 I 00008.00 00010 050009700 008777800 +150 +222222222 +111111111 N 00003.00 I 00008.00 Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7312 Posted: Tue Apr 24, 2012 7:36 pm    Post subject: Reply to: calculate and rounding up value using dfsort When attempting the Code tags, try the Preview button, it allows you to see what the Post looks like before you Submit it, so you can make changes if necessary.

From you earlier record-layout, it seems that STOCK is 24 for a length of 5, PD, not 4.

I'm not going to go through checking everything for you. You need to do that. I've hacked about your Cobol layout into SYMNAMES and produced the SYMNOUT from that.

 Code: ------- ORIGINAL STATEMENTS FROM SYMNAMES ------- STORE,1,5,CH                                      PRODA,*,9,CH                                      PRODB,*,9,CH                                      STOCK,*,5,PD                                      QTY1,*,5,PD                                      QTY2,*,5,PD                                      IND,*,1,CH                                        SIZE,*,7,ZD                                      WEIGHT,*,1,CH                                    WGT,*,7,ZD                                                                                          ------------------ SYMBOL TABLE ----------------- STORE,1,5,CH                                      PRODA,6,9,CH                                      PRODB,15,9,CH                                    STOCK,24,5,PD                                    QTY1,29,5,PD                                      QTY2,34,5,PD                                      IND,39,1,CH                                      SIZE,40,7,ZD                                      WEIGHT,47,1,CH                                    WGT,48,7,ZD

You can either use the symbols in your code, or at least use the definitions. enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10637
Location: italy Posted: Tue Apr 24, 2012 8:06 pm    Post subject: Reply to: calculate and rounding up value using dfsort Your unreadable posts have been edited to use the code tags! we moderators would appreciate if You started doing so Yourself it' s a nuisance to have to waste time editing the posts of inconsiderate posters but it' something that must be done to show respect and consideration for the people spending time to help You ! use the preview button to check that Your posts look the way they should! sqlcode1

Active Member

Joined: 08 Apr 2010
Posts: 578
Location: USA Posted: Tue Apr 24, 2012 9:11 pm    Post subject: useit,

What should be the expected output for input records like below? This is where you have multiple PRODB records under PRODA but with the same values(00006.00) . Is it even possible?
 Code: 00010   050009698  008774500  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774500  +100    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009698  008774500  +100    +222222222   +111111111    N      00006.00   I      00008.00

Thanks, Skolusu

Senior Member

Joined: 07 Dec 2007
Posts: 2205
Location: San Jose Posted: Wed Apr 25, 2012 3:38 am    Post subject: Re: calculate and rounding up value using dfsort useit wrote: hi, i have requirement which i want to achieve it through dfsort. WHEN PRODA has multiple PRODB in STORE (when ALL PRODB has same size ): then calculate the stock as 100+100+100=300 WHEN PRODA has multiple PRODB in STORE (when ALL PRODB has different size ): then recalculate stock=100+(200*00006.10)/00005.00+(300*000007.20)/00005.00+(400*00008.00)/00005.00 =100+240+420+640=1400

useit,

You truly live up to your nickname USEit. I always wonder as to why people post imaginary requirements when they have trouble adapting the proposed solution to the real requirements. Are you under the assumption that we cannot comprehend the requirement as you do? You already have a topic about rounding and summing up the values and you cannot adopt that solution to the actual requirement here because there are many other factors to consider. As Bill pointed out, PD field you used in calculation is 5 bytes and you are calculating using just 4 bytes.
 useit wrote: i ran the below jcl . but it failed with rc=6.

RC=6? DFSORT does not issue an return code of 6. well I guess you are hungry and ate the 10 or you simply rounded it ? How hard is to post the complete sysout? I guess the mods did a good job adding the code tags to your post.

Anyway despite all the above the requirement isn't clear.

200*00006.10)/00005.00 = 244 but you had 240. So are you rounding the size field (value 6.10) to 6 and performing the math or you taking the entire 200*00006.10)/00005.00 = 244 and then round it to 240?

Which value are you rounding? And how is the rounding done? if it is size then any value greater than 49 in the decimal field will be rounded to next integer . ie 6.50, 6.99 becomes 7 and 6.01, 6.49 becomes 6.

Or if you are rounding after calculating the entire value , then how do you plan to round?

241,242,243,244 becomes 240 ??

245,246,247,248,249 becomes 250?? useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Wed Apr 25, 2012 9:12 am    Post subject: skolusu,
extremely sorry.

WHEN PRODA has multiple PRODB in STORE (when ALL PRODB has different size ):

then recalculate stock=100+(200*00006.10)/00005.00+(300*000007.20)/00005.00+(400*00008.00)/00005.00

=100+244+432+640=1416.

so my output should be.

 Code: 00010 050009698 008774500 +300 +222222222 +111111111 N 00006.00 I 00008.00 00010 050009698 008774600 +100 +222222222 +111111111 N 00006.00 I 00008.00 00010 050009698 008774700 +100 +222222222 +111111111 N 00006.00 I 00008.00 00010 050009700 008777500 +1416 +222222222 +111111111 N 00005.00 I 00008.00 00010 050009700 008777600 +244 +222222222 +111111111 N 00006.10 I 00008.00 00010 050009700 008777700 +432 +222222222 +111111111 N 00007.20 I 00008.00 00010 050009700 008777800 +640 +222222222 +111111111 N 00008.00 I 00008.00

sorry for the typo.return code which am getting is 16:(

Regds,
useit. useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Wed Apr 25, 2012 11:07 am    Post subject: HI ,
i ran the below jcl but i did not get the correct output.please correct me the jcl whic i have coded.

 Code: //STEP0100 EXEC PGM=SORT                                //SYSOUT   DD SYSOUT=*                                  //INA      DD DSN=INPUT FILE,DISP=SHR          //INB      DD DSN=SAME INPUT FILE,DISP=SHR            //SORTOUT  DD DSN=OUTPUT FILE,DISP=SHR      //SYSIN    DD *                                            OPTION COPY                                              JOINKEYS F1=INA,FIELDS=(1,23,A),SORTED,NOSEQCK          JOINKEYS F2=INB,FIELDS=(1,23,A)                          REFORMAT FIELDS=(F1:1,54,55,2,F2:57,5)                  INREC IFOUTLEN=54,                                      IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(24:57,5))        //*                                                      //JNF1CNTL DD *                                                            INREC IFTHEN=(WHEN=INIT,OVERLAY=(57:24,5)),                              IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,23),PUSH=(55:SEQ=2)),                    IFTHEN=(WHEN=(55,2,ZD,GT,1),                                            OVERLAY=(57:(57,5,PD,MUL,40,7,ZD),DIV,+5,PD,LENGTH=5,X,                              (57,5,PD,MUL,40,7,ZD),MOD,+5,PD,LENGTH=5),HIT=NEXT),        IFTHEN=(WHEN=(61,2,ZD,GT,0),OVERLAY=(24:57,5,PD,ADD,+1,PD,LENGTH=5))  //*                                                                      //JNF2CNTL DD *                                                            INREC IFTHEN=(WHEN=INIT,OVERLAY=(57:24,5)),                              IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,23),PUSH=(55:SEQ=2)),                    IFTHEN=(WHEN=(55,2,ZD,GT,1),                                            OVERLAY=(57:(57,5,PD,MUL,40,7,ZD),DIV,+5,PD,LENGTH=5,X,                              (57,5,PD,MUL,40,7,ZD),MOD,+5,PD,LENGTH=5),HIT=NEXT),        IFTHEN=(WHEN=(61,2,ZD,GT,0),OVERLAY=(24:57,5,PD,ADD,+1,PD,LENGTH=5))    SUM FIELDS=(57,5,PD)                                                  //* enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10637
Location: italy Posted: Wed Apr 25, 2012 11:22 am    Post subject: Reply to: calculate and rounding up value using dfsort the preview button... the fkng preview button edited again Your last two posts to put the code tags in the proper place useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Wed Apr 25, 2012 12:17 pm    Post subject: Hi,

when i give 40,7,ZD Calculated value was wrong.when i give 40,5,ZD VALUE is populated correctly. what should be the lcorrect length of
FOR PIC 9(5)V99??

 Code: OVERLAY=(57:(57,5,PD,MUL,40,5,ZD),DIV,+5,PD,LENGTH=5,X,                           (57,5,PD,MUL,40,5,ZD),MOD,+5,PD,LENGTH=5),HIT=NEXT),

Regds,
useit

edited again  useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Wed Apr 25, 2012 12:19 pm    Post subject: Code: OVERLAY=(57:(57,5,PD,MUL,40,7,ZD),DIV,+5,PD,LENGTH=5,X, (57,5,PD,MUL,40,7,ZD),MOD,+5,PD,LENGTH=5),HIT=NEXT),

edited again  Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7312 Posted: Wed Apr 25, 2012 1:39 pm    Post subject: useit wrote:
Hi,

when i give 40,7,ZD Calculated value was wrong.when i give 40,5,ZD VALUE is populated correctly. what should be the lcorrect length of
FOR PIC 9(5)V99??

 Code: OVERLAY=(57:(57,5,PD,MUL,40,5,ZD),DIV,+5,PD,LENGTH=5,X,                           (57,5,PD,MUL,40,5,ZD),MOD,+5,PD,LENGTH=5),HIT=NEXT),

Regds,
useit

edited again The correct length of 9(5)V99 is seven bytes. Note there is no way to define a decimal decimal place, 40,7,ZD could be 9(5)99 or 9(7) or V9(7) or anything which is seven digits with or without a decimal place. So you have to deal with any decimal places in your calculation. Is that what went "wrong"? useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Wed Apr 25, 2012 2:02 pm    Post subject: bill, yes.it is giving some huge namber after calculation Regds, useit. Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7312 Posted: Wed Apr 25, 2012 2:06 pm    Post subject: Reply to: calculate and rounding up value using dfsort So for every part with decimal places, you need to keep things is check as you progress through the calculation. One way is divide by +100 for each two decimal places (divide by +10 for each decimal place). useit

Active User

Joined: 05 Oct 2006
Posts: 150 Posted: Wed Apr 25, 2012 2:30 pm    Post subject: thanks a lot bill.it is working fine.
one more doubt is in the below statement i have hardcodeddiv, +5 which i want to populate it dynamically.

 Code: OVERLAY=(57:(57,5,PD,MUL,40,5,ZD),DIV,+5,PD,LENGTH=5,X,                           (57,5,PD,MUL,40,5,ZD),MOD,+5,PD,LENGTH=5),HIT=NEXT),

how can we use the push command to populate the value?

FOR EXAMLE.

 Code: 00010   050009700  008777500  +100    +222222222   +111111111    N      00005.00   I      00008.00 00010   050009700  008777600  +240    +222222222   +111111111    N      00006.00   I      00008.00 00010   050009700  008777700  +420    +222222222   +111111111    N      00007.00   I      00008.00 00010   050009999  008777500  +100    +222222222   +111111111    N      00001.00   I      00008.00 00010   050009999  008777600  +240    +222222222   +111111111    N      00002.00   I      00008.00 00010   050009999  008777700  +420    +222222222   +111111111    N      00003.00   I      00008.00

in this case for the first key i will recalculate the stock as

100+(240*00006.00)/00005.00+(420*00006.00)/00005.00

for the second key

100+(240*00002.00)/00001.00+(420*00003.00)/00001.00

so i cant simply divide by some value. i need to mention the proper position.

REGDS,
USEIT. Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7312 Posted: Wed Apr 25, 2012 2:40 pm    Post subject: Reply to: calculate and rounding up value using dfsort Code: IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,23),PUSH=(55:SEQ=2)),

This is where you identify the first record which makes up your group of records.

If that record contains the "divisor" that you want to use "dynamically", extend the PUSH so that it includes, at a location you are not already using, a copy of the divisor which can be used for all the records. Remember you have decimal places in that as well, it seems. All times are GMT + 6 HoursGoto page 1, 2  Next
 Page 1 of 2

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics RegEx Support in DFSORT (z/OS 2.4) Joerg.Findeisen DFSORT/ICETOOL 3 Thu Nov 14, 2019 7:44 am calculate the record count and based ... naveensrimf DFSORT/ICETOOL 1 Tue Jan 08, 2019 11:20 pm Need advise in calling DFSORT from REXX ajithajt CLIST & REXX 9 Thu Nov 29, 2018 10:50 am How to handle different file length b... javen777 DFSORT/ICETOOL 15 Mon Nov 26, 2018 12:13 pm How to count the number of times key ... vnktrrd DFSORT/ICETOOL 14 Thu Nov 15, 2018 9:19 pm © 2003-2017 IBM MAINFRAME Software Support Division Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us