|
View previous topic :: View next topic
|
| Author |
Message |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
i have input file. the layout is as below. (LRECL=54)
| Code: |
01 DETAIL.
03 KEY.
05 CENTER PIC 9(5).
05 PRODUCT PIC 9(9).
05 PRODUCT ID PIC 9(9).
03 DATA.
05 QTY1 PIC S9(9) COMP-3.
05 QTY2 PIC S9(9) COMP-3.
05 QTY3 PIC S9(9) COMP-3.
05 IND PIC X.
05 SIZE PIC 9(5)V99.
05 WEGHT PIC X.
05 UNIT PIC 9(5)V99. |
and the input file is as below.
| Code: |
PRODUCT PRODUCT QTY1 QTY2 QTY3 IND SIZE WEGHT UNIT
Z(9) (6-14) Z(9) (15-23) PS(9) (24-28) PS(9) (29-33) PS(9) (34-38) C(1) Z(5,2) (40-46) C(1) (47-47) Z(5,2) (48-54)
----------- ------------ ------------- ------------- ------------- ---- -------------- ------------ --------------
****************************** TOP OF DATA *********************************************** *********************************
050009698 008774500 +154 +9 +9 N 00003.00 I 00008.00
050009698 000011512 +10 +9 +1 N 00006.00 I 00002.13
050009698 008373548 +6 +9 +9 N 00009.00 I 00008.40 |
in this case i want to re calculate the QTY1 as = 154+(10*6)/3+(6*9)/3=
then sum up all the quantities and assign it to first QTY1 field. i,e =154+20+18=192
i ran the below jcl and got the correct output.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD DSN=infile1,DISP=SHR
//INB DD DSN=infile1,DISP=SHR
//SORTOUT DD DSN=outfile,DISP=SHR
//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,57,5,F2:62,5)
INREC IFOUTLEN=54,
IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(24:62,5))
//*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(62:24,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,5)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(62:(62,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,X,
(62,5,PD,MUL,40,5,ZD),MOD,57,5,ZD,PD,LENGTH=5),HIT=NEXT)
//*
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(62:24,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,5)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(62:(62,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,X,
(62,5,PD,MUL,40,5,ZD),MOD,57,5,ZD,PD,LENGTH=5),HIT=NEXT)
SUM FIELDS=(62,5,PD)
//* |
so my outpu file will be as below.
| Code: |
PRODUCT PRODUCT QTY1 QTY2 QTY3 IND SIZE WEGHT UNIT
Z(9) (6-14) Z(9) (15-23) PS(9) (24-28) PS(9) (29-33) PS(9) (34-38) C(1) Z(5,2) (40-46) C(1) (47-47) Z(5,2) (48-54)
----------- ------------ ------------- ------------- ------------- ---- -------------- ------------ --------------
****************************** TOP OF DATA *********************************************** *********************************
050009698 008774500 +192 +9 +9 N 00003.00 I 00008.00
050009698 000011512 +10 +9 +1 N 00006.00 I 00002.13
050009698 008373548 +6 +9 +9 N 00009.00 I 00008.40 |
similarly i have to recalculate QTY2 field. if i do it in two seperate steps it is working fine. but when i tried to do it in single step. i am getting some huge numbers. getting wrong result.what could be the reaason for this? is there any syntax problem in the below code
below is the jcl.
| Code: |
//INA DD DSN=input file1,DISP=SHR
//INB DD DSN=input file1,DISP=SHR
//SORTOUT DD DSN=output file,DISP=SHR
//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,57,5,F2:62,5,67,5)
INREC IFOUTLEN=54,
IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(24:62,5,29:67,5))
//*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(62:24,5,67:29,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,5)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(62:(62,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,X,
(62,5,PD,MUL,40,5,ZD),MOD,57,5,ZD,PD,LENGTH=5),HIT=NEXT),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(67:(67,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,X,
(67,5,PD,MUL,40,5,ZD),MOD,57,5,ZD,PD,LENGTH=5),HIT=NEXT)
//*
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(62:24,5,67:29,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,5)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(62:(62,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,X,
(62,5,PD,MUL,40,5,ZD),MOD,57,5,ZD,PD,LENGTH=5),HIT=NEXT),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(67:(67,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,X,
(67,5,PD,MUL,40,5,ZD),MOD,57,5,ZD,PD,LENGTH=5),HIT=NEXT)
SUM FIELDS=(62,5,PD,67,5,PD)
//* |
and am getting the output as
| Code: |
PRODUCT PRODUCT QTY1 QTY2 QTY3 IND
Z(9) (6-14) Z(9) (15-23) PS(9) (24-28) PS(9) (29-33) PS(9) (34-38) C(1)
----------- ------------ ------------- ------------- ------------- ----
******************************* TOP OF DATA *********************************
050009698 008774500 +174 +800000009 +9 N
050009698 008774500 +18 +200000000 +9 N
050009698 000011512 +10 +9 +1 N |
please help me in this regard.
regds,
useit |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, you have several problems with varying impacts.
You are ignoring decimal places, but doesn't cause the problem.
You have a "spare" HIT=NEXT not followed by WHEN=logicalexpression, but doesn't cause the problem.
You have no need to repeat the test, both calculations can be done under the same IFTHEN, but doesn't cause the problem...
You need to look at and understand exactly what your existing OVERLAY is doing and the field positionS(!) which ARE occupied. Then review the starting position for your "second" field. This is your actual problem.
When taking a solution given to you, it is a really good idea to thoroughly understand it before using it seriously. If you had done that, I don't thing any of the above would have been coded. |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
useit,
I have no idea as to why you have a MOD operation. Please don't use solutions from different topics and get confused. You say you want to divide with a constant of +3 but your control cards are using a field to divide. How about you come up with the actual requirement telling us the rules instead of correcting your logic? |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
skolosu,
in the above example if there are multiple product-id under tyhe same product field then i have to recalculate QTY1,QTY2 and QTY2 field.
in the above case i have to recalculate the
QTY1 =154+ (10*00006.00)/00003.00+(6*00009.00)/00003.00
QTY1=qty1+(second record QTY1*size of second record)/size of first record+(third record QTY1*size of third record)/size of first
i,e=154+20+18
bunch up recalculated value and assign it to first record qty1 field.
similarly for QTY2 field.
QTY2=9+(9*00006.00)/00003.00+(9*00009.00)/00003.00
=9+18+27=54
so my output file should be
| Code: |
PRODUCT PRODUCT QTY1 QTY2 QTY3 IND SIZE WEGHT UNIT
Z(9) (6-14) Z(9) (15-23) PS(9) (24-28) PS(9) (29-33) PS(9) (34-38) C(1) Z(5,2) (40-46) C(1) (47-47) Z(5,2) (48-54)
----------- ------------ ------------- ------------- ------------- ---- -------------- ------------ --------------
****************************** TOP OF DATA *********************************************** *********************************
050009698 008774500 +192 +54 +9 N 00003.00 I 00008.00
050009698 000011512 +10 +9 +1 N 00006.00 I 00002.13
050009698 008373548 +6 +9 +9 N 00009.00 I 00008.40 |
|
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
i ran the below jcl and it worked fine for me. please find the below jcl
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD DSN=infile,DISP=SHR
//INB DD DSN=infile,DISP=SHR
//SORTOUT DD DSN=outfile,DISP=SHR
//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,57,5,F2:62,5,67,5,72,5)
INREC IFOUTLEN=54,
IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(24:62,5,29:67,5,34:72,5))
//*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(62:24,5,67:29,5,72:34,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,5)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(62:(62,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,
67:(67,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,
72:(72,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5),HIT=NEXT)
//*
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(62:24,5,67:29,5,72:34,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,5)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(62:(62,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,
67:(67,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5,
72:(72,5,PD,MUL,40,5,ZD),DIV,57,5,ZD,PD,LENGTH=5),HIT=NEXT)
SUM FIELDS=(62,5,PD,67,5,PD,72,5,PD)
//* |
Regds,
useit |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
In your earlier topic which was very similar you needed the MOD because you wanted "rounded up" values. Was that a different thing?
You still don't need the HIT=NEXTs that you have, |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
bill,
in the above jcl i have considered only the integer part while dividing.i tried calculating even considering decimal part. it worked fine. but jcl will always round down.how to round up the value? do we need MOD functionality to round up?
Regds,
useit |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
below jcl is giving the desired result.but its rounding down.
| Code: |
//INA DD DSN=infile1,DISP=SHR
//INB DD DSN=infile1,DISP=SHR
//SORTOUT DD DSN=outfile,DISP=SHR
//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,57,7,F2:64,5,69,5,74,5)
INREC IFOUTLEN=54,
IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(24:64,5,29:69,5,34:74,5))
//*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(64:24,5,69:29,5,74:34,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,7)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(64:(64,5,PD,MUL,40,7,ZD),DIV,57,7,ZD,PD,LENGTH=5,
69:(69,5,PD,MUL,40,7,ZD),DIV,57,7,ZD,PD,LENGTH=5,
74:(74,5,PD,MUL,40,7,ZD),DIV,57,7,ZD,PD,LENGTH=5),HIT=NEXT)
//*
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(64:24,5,69:29,5,74:34,5)),
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2,57:40,7)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(64:(64,5,PD,MUL,40,7,ZD),DIV,57,7,ZD,PD,LENGTH=5,
69:(69,5,PD,MUL,40,7,ZD),DIV,57,7,ZD,PD,LENGTH=5,
74:(74,5,PD,MUL,40,7,ZD),DIV,57,7,ZD,PD,LENGTH=5),HIT=NEXT)
SUM FIELDS=(64,5,PD,69,5,PD,74,5,PD)
//* |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The MOD you had previously was used as a way of knowing if you number was exactly divisible by the "pack size" or whatever it was. If not exactly divisible, then you'd "round up" to the nearest "pack size".
If you can set out exactly what it is you are trying to achieve, it will help.
If you are trying to use "variables" it is best not to only show examples with literal values. |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
bill,
say for example. from the below file
| Code: |
PRODUCT PRODUCT QTY1 QTY2 QTY3 IND SIZE WEGHT UNIT
Z(9) (6-14) Z(9) (15-23) PS(9) (24-28) PS(9) (29-33) PS(9) (34-38) C(1) Z(5,2) (40-46) C(1) (47-47) Z(5,2) (48-54)
----------- ------------ ------------- ------------- ------------- ---- -------------- ------------ --------------
****************************** TOP OF DATA *********************************************** *********************************
050009698 008774500 +154 +54 +9 N 00003.00 I 00008.00
050009698 000011512 +10 +9 +1 N 00006.00 I 00002.13
050009698 008373548 +6 +9 +9 N 00009.80 I 00008.40 |
if you calculate the qty1field
QTY1 Will be,=154+(10*00006.00)/00003.00+(6*0000*9.80)/00003.00
=154+20+19.6=193.6=(193->jcl will round down)
but i want the output as 194.(even if it is 193.1 or 193.2........193.9)
Regds,
useit |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Consult the manual and find out what MOD does. That should allow you to understand why it was suggested to you originally for the "rounding up". If you remove the code for the MOD, you won't get the "rounding up".
Note, this is not something specifically to do with MOD, it is logic you apply to the result of MOD to achieve your aim. |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| Please note: JCL does not do rounding of ANY kind. in fact, by the time your job runs the machine has finished processing your JCL. Please get your terminology right. |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
useit,
I am not even sure as to how you can say you got the desired results. You show the division by a constant of +3 or +300 as examples but your control cards are picking up a value division from the input file. The value 3 or 300 doesn't even exist in your input. I pointed out this earlier too and you just ignore it and continue with your own imaginary calculations.
You don't need to calculate the values on JNF1CNTL also as it serves no purpose. You only have 1 file and you want to update the values adding up the values for each key. If you use sum function you would end up with 1 record. So that is the reason as to why we use the same input file twice and JNF2CNTL will sum up the results into a single record and then you can use the join function to update the values on to the first record.
So understand the solutions before you implement them. Do not use code that you don't understand. Take a moment to understand the solution and use it. Refer the manuals and understand each keyword.
There are many ways to skin a cat. Since you want to round to next integer In simple math terms
(6*0000*9.80) = 58.8
58.8/3 = 19.6 ie (19 * 3 = 57 + remainder 1.8)
Now to make it 20 you can check if the remainder > 0 and add 1 to 19 making 20
or you can divide the remainder by remainder itself and add it to 19.
(58.8 /3 ) + mod(58.8/3) /mod(58.8/3) = 19+1 = 20
In case of evenly divisible values it would be 0. DFSORT puts 0/0 as 0
ex:
(10*6)/3 = 60/3 = 20 and remainder is 0
(60/3) + mod(60/3) / mod(60/3) = 20
Use this JCL which will give you the desired results. I calculated QTY1, QTY2, and also QTY3
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD DSN=infile1,DISP=SHR
//INB DD DSN=infile1,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,F2:57,15)
INREC IFOUTLEN=54,
IFTHEN=(WHEN=INIT,OVERLAY=(70:SEQNUM,2,ZD,RESTART=(1,14))),
IFTHEN=(WHEN=(70,2,ZD,EQ,1),OVERLAY=(24:55,15))
//*
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,14),PUSH=(55:SEQ=2)),
IFTHEN=(WHEN=(55,2,ZD,EQ,1),OVERLAY=(57:24,15)),
IFTHEN=(WHEN=(55,2,ZD,GT,1),
OVERLAY=(57:((24,5,PD,MUL,40,7,ZD),DIV,+300),ADD,
((24,5,PD,MUL,40,7,ZD),MOD,+300),DIV,
((24,5,PD,MUL,40,7,ZD),MOD,+300),PD,LENGTH=5,
((29,5,PD,MUL,40,7,ZD),DIV,+300),ADD,
((29,5,PD,MUL,40,7,ZD),MOD,+300),DIV,
((29,5,PD,MUL,40,7,ZD),MOD,+300),PD,LENGTH=5,
((34,5,PD,MUL,40,7,ZD),DIV,+300),ADD,
((34,5,PD,MUL,40,7,ZD),MOD,+300),DIV,
((34,5,PD,MUL,40,7,ZD),MOD,+300),PD,LENGTH=5))
SUM FIELDS=(57,5,PD,62,5,PD,67,5,PD)
//* |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
useit,
You have, again, wasted time by continuing to show literal values when you want data values from your records.
You did this in your previous topic with similar "rounding" and you did it twice here despite Kolusu's question and my suggestion.
Please avoid doing this in the future, as people spend time on what you provide, since we are not mind-readers.
You have a solution. Run it as is until you understand exactly how everything is workin and what is different from your previous topic. You can "take it apart" to run small elements at a time to see the effects.
Read the manual specifically for the functions used. Use the functions and review their effects. Return to the manual to ensure that you are clear about how each function works.
This sort of method can help you get there on your own in countless different situations.
Of course, when you've got everything you should be able to make the changes yourself to use the data from the file. I'd suggest a SYMNAME or two to save typing of repeated values. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|