MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to perform a formula calculation
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Fri Nov 18, 2016 9:34 am    Post subject: How to perform a formula calculation Reply with quote

Hello,
I have a rather simple task to attain, but I wasn't able to complete everything I wanted.
I have a simple file in input and have to create a new output creating some new fields according to some criteria I will (try) describe below.

This is how my sort looks right now:
Code:

//SORT01    EXEC PGM=SORT               
//SORTLIB   DD DSN=SYS1.SORTLIB,DISP=SHR
//SYSOUT    DD SYSOUT=*                 
//SORTIN    DD DISP=SHR,DSN=INPUT     
//SORTOUT   DD DSN=OUTPUT,             
//            DISP=(,CATLG),                             
//            UNIT=SYSDA,SPACE=(CYL,(1,1),RLSE),         
//            DCB=(*.SORTIN)                             
//SORTWK01  DD UNIT=SYSDA,SPACE=(CYL,10)
//SYSIN     DD *
SORT FIELDS=COPY
OUTREC BUILD=(4,8,C';',39,1,CHANGE=(9,C'D',C'REDUCED  ',             
     C'N',C'NEW      '),NOMATCH=(39,1),C';', 33,6,C';',12,2,C';',   
(15,18,ZD,MUL,+1),EDIT(IIIIIIIIIITTTTTTTT),C';',                     
(40,18,ZD,MUL,+1),EDIT(SIII.III.III.III.TTT,TTT),SIGNS=(,-),C';',   
(58,17,ZD,DIV,+100),EDIT(SII.III.III.III.III.TTT,TT),SIGNS=(,-),C';',
(75,17,ZD,DIV,+100),EDIT(SII.III.III.III.III.TTT,TT),SIGNS=(,-),C';')
/*                                                                   


As you can desume from SORT, INPUT has 3 signed numerical fields, starting from position 40 with these pictures:
field 1 cols 40,18 PIC S9(15)V9(3)
field 2 cols 58,17 PIC S9(15)V9(2)
field 3 cols 75,17 PIC S9(15)V9(2)

I wanted to report these fields in OUTPUT as they are in input, with the same pictures. I know I've messed a bit with EDIT, but result right now is acceptable.
As you can see from SYSIN for some fields I need a simple multiply by 100 (always with sign), but I also would need to write in OUTPUT another field that must be calculated according the following formula:

IF "REDUCED" (or column 9 of INPUT = 'D') (((field 1 * 0,01187)/100)/12)*11)
ELSE (field 3 /12)*11)

This new OUTPUT field must be written as PIC S9(15)V9(3)

Is it possible to do it in sort?

Thanks in advance for any help you could provide.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Fri Nov 18, 2016 10:44 am    Post subject: Reply with quote

Fab,

It can be done but we need a bit more details.

Lets you have a "D" at position 39.

Code:

IF REC(39:1) = 'D'                                   
   OUTVAL    = (((FIELD-1 * 0.01187)/ 100)/ 12)* 11)
ELSE                                                 
   OUTVAL    = (FIELD-3 / 12) * 11                   
END-IF                                               


Assume

Code:

FIELD-1 = 12.345  AND FIELD-3 = 67.89

Code:

OUTVAL = (FIELD-1 * 0.01187) = 12.345 * 0.01187 = 0.14653515
         ((FIELD-1 * 0.01187)/ 100)  = (0.14653515 / 100) = 0.001465352
         ((FIELD-1 * 0.01187)/ 100)/ 12)  = (0.001465352 / 12) = 0.0001221126
         (((FIELD-1 * 0.01187)/ 100)/ 12)* 11)   = 0.0001221126 * 11 = 0.001343239


Now if you output definition has only 3 decimal digits you are going to end up with zeros. Is that what you want?

Also it would be helpful if you can paste some sample data for Field-1/2/3 and the expected result from the formulas.

Btw there is no formula related to Field-2 ? do you just need to copy it to output?
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Mon Nov 21, 2016 3:17 am    Post subject: Reply with quote

Thanks for your attention and answer Kolusu,
I will try to clarify everything answering your questions in order.

1. I don't want to end up with zeroes, but my new output calculated field should have (if possible) 3 decimal digits.
2. Field 1 is usually a big value, and is the value I have calculated in my above sort ((40,18,ZD,MUL,+1),EDIT(SIII.III.III.III.TTT,TTT),SIGNS=(,-)). Field 3 is not a big value and must be the value I calculated in my above sort ((75,17,ZD,DIV,+100),EDIT(SII.III.III.III.III.TTT,TT),SIGNS=(,-)).
These are some real values I have, both cases:

If 39:1 = 'D' (Field 1 is the calculated value (40,18,ZD,MUL,+1),EDIT(SIII.III.III.III.TTT,TTT),SIGNS=(,-))
Field 1 = 46.481,11 Then (46481,11*0,01187/100/12*11 = 5,058)
Field 1 = 77.468,53 Then (77468,53*0,01187/100/12*11 = 8,429)
Field 1 = 108.455,95 Then (108455,95*0,01187/100/12*11 = 11,801)
Field 1 = 4.620.000,00 Then (4620000*0,01187/100/12*11 = 502,695)

If 39:1 = 'N' (Field 3 is the calculated value (75,17,ZD,DIV,+100),EDIT(SII.III.III.III.III.TTT,TT),SIGNS=(,-))
Field 3 = 51,88 Then (51,88/12*11 = 47,557)
Field 3 = 43,23 Then (43,23/12*11 = 39,628)
Field 3 = 37,95 Then (37,95/12*11 = 34,788)
Field 3 = 17,86 Then (17,86/12*11 = 16,372)

This new calculated field must be reported in output after the last field I am actualy reporting, so after 75,17 position (so probably 91,18), with picture PIC S9(15)V9(3), preferably.

3. Field 2 is indeed not affected from any formula, and must be reported in output just multiplied by +100

I see I have forgotten to mention a thing. In my previous examples I always mentioned the constant 11, but that is not a constant. I run this JCL once every three months (4 times a year), and that value must be decremented accordingly the related quarter, so it will be 11, 8, 5, and 2.
I did not mention it before because in the input file there is nothing that can be used to identify the quarter I am running, so I simply guessed that I will have to edit the jcl every time. But if that can be avoided I will be even more grateful, you know Smile

I did my best to clarify things, but, please let me know if you need to know anything else.
Thanks again for your attention.
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Mon Nov 21, 2016 4:49 am    Post subject: Reply with quote

Sorry for some typos and inaccuracies I just saw:
Quote:
This new calculated field must be reported in output after the last field I am actualy reporting, so after 75,17 position (so probably 91,18), with picture PIC S9(15)V9(3), preferably.

I just verified that this new field should be placed between Field 2 and Field 3, sorry.

Quote:
3. Field 2 is indeed not affected from any formula, and must be reported in output just multiplied by +100

It is divided by +100, sorry
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Mon Nov 21, 2016 12:07 pm    Post subject: Reply with quote

Fab wrote:

If 39:1 = 'D' (Field 1 is the calculated value (40,18,ZD,MUL,+1),EDIT(SIII.III.III.III.TTT,TTT),SIGNS=(,-))
Field 1 = 46.481,11 Then (46481,11*0,01187/100/12*11 = 5,058)


Fab,

You seem to have rounded up the values. DFSORT deals with integers only and I end up with the final result as 5.049 as we only consider 3 decimal places. If you do need to round up then we have to increase the precision.

when you divide a number by another number and want to retain the decimal value then first multiply by the no: of digits and then use divide.
Code:

 ex: 21/100  = 0 since fractional part is lost                     
 ex: (21* 100)/100 with edit mask (tt.tt)  = 00.21                 

In your case we needed 3 decimals, so we multiply with +10000 and then later on divide to get 3 decimals.

Fab wrote:
I see I have forgotten to mention a thing. In my previous examples I always mentioned the constant 11, but that is not a constant. I run this JCL once every three months (4 times a year), and that value must be decremented accordingly the related quarter, so it will be 11, 8, 5, and 2.
I did not mention it before because in the input file there is nothing that can be used to identify the quarter I am running, so I simply guessed that I will have to edit the jcl every time. But if that can be avoided I will be even more grateful, you know


It is quite easy to determine the quarter you are running in. DFSORT has LASTDAYQ which lets you determine the last day of the quarter. So we determine the lastday of the quarter using the current date when the job ran.

Fab wrote:
This new calculated field must be reported in output after the last field I am actualy reporting, so after 75,17 position (so probably 91,18), with picture PIC S9(15)V9(3), preferably.


well you are expanding the final output with delimiters and hence the calculated field will not be at position 91. It will be at position 104.

Use the following DFSORT control cards which will give you the desired results
Code:

//SYSIN    DD *               
  OPTION COPY                 
  OUTREC IFOUTLEN=128,                                                   
         IFTHEN=(WHEN=INIT,                                             
                BUILD=(04,08,                                $ FIELD-1   
                       C';',                                 $ DELMTR   
                       39,01,CHANGE=(9,C'D',C'REDUCED',                 
                                       C'N',C'NEW'),                     
                            NOMATCH=(39,1),                             
                       C';',                                 $ DELMTR   
                       33,06,                                $ FILED-3   
                       C';',                                 $ DELMTR   
                       12,02,                                $ FILED-4   
                       C';',                                 $ DELMTR   
                       15,18,SFF,EDIT=(IIIIIIIIIITTTTTTTT),  $ AMT-1     
                       C';',                                 $ DELMTR   
                       40,18,SFF,                            $ AMT-2     
                       EDIT=(SII.III.III.TTT,TT),                       
                       SIGNS=(,-),                                       
                       C';',                                 $ DELMTR   
                       58,17,SFF,DIV,+100,                   $ AMT-3     
                       EDIT=(SI.III.III.TTT,TT),                         
                       SIGNS=(,-),                                       
                       C';',                                 $ DELMTR   
                       75,17,SFF,DIV,+100,                   $ AMT-4     
                       EDIT=(SI.III.III.TTT,TT),                         
                       SIGNS=(,-),                                       
                       C';',                                 $ DELMTR   
                       128:C';',                             $ DELMTR   
                       130:DATE1)),                                     

         IFTHEN=(WHEN=INIT,                                           
        OVERLAY=(140:130,8,Y4T,LASTDAYQ,TOGREG=Y4T,       $ QTR DATE   
                 150:144,2,CHANGE=(2,C'03',C'02',         $ 1QTR = 02 
                                     C'06',C'05',         $ 2QTR = 05 
                                     C'09',C'08',         $ 3QTR = 08 
                                     C'12',C'11'))),      $ 4QTR = 11 
                                                                       
         IFTHEN=(WHEN=(10,9,CH,EQ,C'REDUCED'),                         
        OVERLAY=(104:((((49,18,SFF,MUL,+10000),                       
                                   MUL,+1187),                         
                                   DIV,+120000000000),                 
                                   MUL,150,2,ZD),                     
                             EDIT=(SIII.III.III.III.TTT,TTT),         
                             SIGNS=(,-))),                             
                                                                       
         IFTHEN=(WHEN=(10,9,CH,EQ,C'NEW'),                             
        OVERLAY=(104:(((86,18,SFF,MUL,+1000),                         
                                  DIV,+1200),                         
                                  MUL,150,2,ZD),                       
                             EDIT=(SIII.III.III.III.TTT,TTT),         
                             SIGNS=(,-)))                             
//*

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Tue Nov 22, 2016 3:36 am    Post subject: Reply with quote

Thanks so much Kolusu,
I just tried your code and it works perfectly, but I see something that must be refined by me.

Values of my yesterday post was calculated/taken from EXCEL, probably they were automatically rounded there depending on how may dec I have specified in cell format.

Quote:
DFSORT deals with integers only and I end up with the final result as 5.049 as we only consider 3 decimal places

understood, so what I need to do to increase precision? increase the number of decimals? because I see that I would need more precision expecially on the calculated numbers.

data from my old sort was like this:
2100363000;
87.152,10;
006,27; <-- acceptable precision, but if I can increase it would be better
012,55; <-- acceptable precision, but if I can increase it would be better

with your new code I have:
2100363000; <-- this is just as input, no calculated so it's ok
87.152,10; <-- this is 40,18, it's ok
000,62; <-- not enough precision
001,25; <-- not enough precision
001,724; <-- this is the new introduced field calculated by formula, this one needs the more precision I can get (previously it was calculated every time by hand in EXCEL appllying the formula I posted here, my goal was to understand if the process ca be completely automated in host)

Kind Regards
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Tue Nov 22, 2016 5:03 am    Post subject: Reply with quote

I have another question,

why with (58,17,ZD,DIV,+100),EDIT(SII.III.III.III.III.TTT,TT),SIGNS=(,-)
I have 6,27

while with 58,17,SFF,DIV,+100, EDIT=(SI.III.III.TTT,TT), SIGNS=(,-),
I have 000,62?

To have the same value in output as before I have to divide by 10 instead that by 100, is this because of the different EDIT mask or because of the SFF?

Thanks in advance
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Tue Nov 22, 2016 9:20 am    Post subject: Reply with quote

Kolusu,
don't quant to bother you, but I have another question to be sure I understand all your code.
Quote:

OVERLAY=(140:130,8,Y4T,LASTDAYQ,TOGREG=Y4T,
150:144,2,CHANGE=(2,C'03',C'11',
C'06',C'08',
C'09',C'05',
C'12',C'02'))),

I changed this piece of code to accomodate my "quarter" needs (month 03 means 1st quarter, so c'11' is appropriate). I see that these fields reside outside maximum 128 width. So I understand these are just there to permit the identification of the right quarter and so the right numerical coefficient. But I would like to understand these two value:
Quote:

140:130
150:144


does that meant that the 1st field begin at position 130 til 140, and the other one from 144 to 150?
Not so clear how it works.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Tue Nov 22, 2016 11:56 am    Post subject: Reply with quote

Fab wrote:
understood, so what I need to do to increase precision? increase the number of decimals? because I see that I would need more precision expecially on the calculated numbers.


You can increase the precision by multiplying with the number of decimal digits you want.

for ex: Field 1 = 46.481,11 Then (46481,11*0,01187/100/12*11 = 5,058)

The below will produce 5.057,525;

Code:

         IFTHEN=(WHEN=(10,9,CH,EQ,C'REDUCED'),                 
        OVERLAY=(104:((((49,18,SFF,MUL,+10000000),             
                                   MUL,+1187),                 
                                   DIV,+120000000000),         
                                   MUL,150,2,ZD),               
                             EDIT=(SIII.III.III.III.TTT,TTT),   
                             SIGNS=(,-))),                     
                                                               



Now if we simply divide that number by 1000, you will end up with 5,057 where as you wanted it as 5,058.

ie.
Code:

          IFTHEN=(WHEN=(10,9,CH,EQ,C'REDUCED'),                             
         OVERLAY=(104:((((49,18,SFF,MUL,+10000000),                         
                                    MUL,+1187),                             
                                    DIV,+120000000000),                     
                                    MUL,150,2,ZD),                         
                              ZD,LENGTH=18,                                 
                  104:104,18,ZD,DIV,+1000,                                 
                              EDIT=(SIII.III.III.III.TTT,TTT),             
                              SIGNS=(,-))),                                 
                                                                           


So if you really want to have rounded based on the decimals, then you need another IFTHEN to check decimals and round it

we have 5.057,525.

I check the the byte 3rd byte from right i.e 5 in 525 at the end. So if it is Greater than or equal to 5, I add +1000 to it and then it would be become 5.058,525. Now all you have to do it simply divide it by 1000 to have 5,058

use the following control cards.

Code:

          IFTHEN=(WHEN=(10,9,CH,EQ,C'REDUCED'),                     
         OVERLAY=(104:((((49,18,SFF,MUL,+10000000),                 
                                    MUL,+1187),                     
                                    DIV,+120000000000),             
                                    MUL,150,2,ZD),                 
                          ZD,LENGTH=24),HIT=NEXT),                 
                                                                   
          IFTHEN=(WHEN=(010,9,CH,EQ,C'REDUCED',AND,                 
                        125,1,ZD,GE,5),                             
         OVERLAY=(104:(104,24,ZD,ADD,+1000),DIV,+1000,             
                      EDIT=(SIII.III.III.III.TTT,TTT),             
                              SIGNS=(,-))),                         
                                                                   


Fab wrote:
To have the same value in output as before I have to divide by 10 instead that by 100, is this because of the different EDIT mask or because of the SFF?


It is because of the edit mask. So you need to determine what kind of edit mask you want.

Fab wrote:
I changed this piece of code to accomodate my "quarter" needs (month 03 means 1st quarter, so c'11' is appropriate). I see that these fields reside outside maximum 128 width. So I understand these are just there to permit the identification of the right quarter and so the right numerical coefficient. But I would like to understand these two value


Since I used IFOUTLEN=128, anything beyond that will not show up in your output. Basically I created 3 temp fields

    1. At position 130 I put the Current date as CCYYMMDD.
    2. Now using that current date at position 130 , I calculated the lastday of the quarter using LASTDAYQ function and put that value in position 140 which will be of the format CCYYMMDD
    3. Now I validate month (MM) field of the last day function at 140. The month(MM) is at position 144. Using a Change command I add in the desired constant and put that value at 150.

We have all the information we needed and we perform our mathematical formula using the value at position 150. And IFOUTLEN=128 gets rid off the temp fields.

If you really want to understand how the job works, change the Value of IFOUTLEN=160. This will create an output file of 160 bytes in length.

Once you understand the job, you can put back the original output length.
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Wed Nov 23, 2016 3:45 am    Post subject: Reply with quote

I understood everything you told me, many thanks for detailed explanation.

you say:
Quote:
It is because of the edit mask. So you need to determine what kind of edit mask you want.


I'm not perfectly conviced about that, look:
I ran the job first time, just changing SFF with ZD, nothing else like this:
Code:

*--SFF        58,17,SFF,DIV,+100,EDIT=(SI.III.III.TTT,TT),
              58,17,ZD,DIV,+100,EDIT=(SI.III.III.TTT,TT),
                    SIGNS=(,-),C';',                     
*--SFF        75,17,SFF,DIV,+100,EDIT=(SI.III.III.TTT,TT),
              75,17,ZD,DIV,+100,EDIT=(SI.III.III.TTT,TT),
                    SIGNS=(,-),C';',128:C';',130:DATE1)),
And I have this in output:
Code:

003,34;
006,69;


Then ran again changing again like this:
Code:

              58,17,SFF,DIV,+100,EDIT=(SI.III.III.TTT,TT),
*--ZD         58,17,ZD,DIV,+100,EDIT=(SI.III.III.TTT,TT),
                    SIGNS=(,-),C';',                     
              75,17,SFF,DIV,+100,EDIT=(SI.III.III.TTT,TT),
*--ZD         75,17,ZD,DIV,+100,EDIT=(SI.III.III.TTT,TT),
                    SIGNS=(,-),C';',128:C';',130:DATE1)),


And I got this:
Code:

000,33;
000,66;


Input fields (both cases)
Code:

3348I
hex: F3 F3 F4 F8 C9
6697I
hex F6 F6 F9 F7 C9


At first sight it doesn't seems to me an EDIT mask problem to me.
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Wed Nov 23, 2016 3:57 am    Post subject: Reply with quote

Unless I do something like this (as you suggested before):
Code:

58,17,SFF,MUL,+1000,DIV,+100,               
                   EDIT=(SI.III.III.TTT,TTT),


This way I have this:
Code:
033,480;


I wanted to see the last digit (8), so I multiplied by +1000, as you said me before.
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Wed Nov 23, 2016 4:50 am    Post subject: Reply with quote

After few tests I see there is something that I loose and this is not so good to me:

My sort output should match a report that is created reading the same input that I read in sort. In the example of my previous post on that report I have:
Code:

334,89
669,79


I know that these fields must be written with 2 dec, so now, as you suggested me in your last post, I will have to apply the 2nd ifthen to round values. This way I will have:
Code:

3,35
6,70


which I suppose is the most correct value I can give. Many thanks again for your suggestions.
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Wed Nov 23, 2016 8:25 am    Post subject: Reply with quote

Hello Kolusu,
have two more questions.
First question, it seems your code to round up do not behave always fine, look:

Old code (no rounded numbers) produces something like this:
Code:

000,918;
001,532;
002,144;
091,398;
001,148;
000,918;
002,298;
001,378;
006,130;
001,838;
001,992;
001,838;


Modified code produces
Code:

                 000,920;
                 001,533;
                 002,146;
000000000000000091399000;
000000000000000001149438;
                 000,920;
                 002,299;
000000000000000001379326;
000000000000000006130342;
000000000000000001839102;
000000000000000001992360;
000000000000000001839102;


I have sobstituted this code
Code:

IFTHEN=(WHEN=(10,9,CH,EQ,C'DECURTATE'),           
  OVERLAY=(104:((((49,18,SFF,MUL,+10000),         
                             MUL,+1187),           
                             DIV,+120000000000),   
                             MUL,150,2,ZD),       
                   EDIT=(SIII.III.III.III.TTT,TTT),
                   SIGNS=(,-))),                   


with this new code
Code:

IFTHEN=(WHEN=(10,9,CH,EQ,C'DECURTATE'),         
   OVERLAY=(104:((((49,18,SFF,MUL,+10000000),   
                              MUL,+1187),       
                              DIV,+120000000000),
                              MUL,150,2,ZD),     
                    ZD,LENGTH=24),HIT=NEXT),     
                                                 
IFTHEN=(WHEN=(010,9,CH,EQ,C'DECURTATE',AND,     
                  125,1,ZD,GE,5),               
   OVERLAY=(104:(104,24,ZD,ADD,+1000),DIV,+1000,
                EDIT=(SIII.III.III.III.TTT,TTT),
                        SIGNS=(,-))),           

I reduced MUL,+10000000 to MUL,+10000, because I had too big numbers, ie:
919,550
91.399,000
and so on, while now I have (with "old" code, not the one you suggested to round up numbers):
000,918
091,398
which I think are more realistic (for these numbers I have any report evidence to compare to, so I can just desume and try to calculate with EXCEL to make a comparison.

Second question is, how can I insert your code to round up numbers after these two calculation? (you can see I commented the ZD to use again SFF, but I can find it working only in this way)
Code:

*--ZD         58,17,ZD,DIV,+100,EDIT=(SI.III.III.TT,TTT),       
              58,17,SFF,MUL,+100,DIV,+100,EDIT=(SI.III.TTT,TTT),
                    SIGNS=(,-),C';',                           
*--ZD         75,17,ZD,DIV,+100,EDIT=(SI.III.III.TT,TTT),       
              75,17,SFF,MUL,+100,DIV,+100,EDIT=(SI.III.TTT,TTT),


I tried, but always do something wrong, always get sort abends. Most probably I am still not completely confident with your code to modify it independently. Thanks in advance.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Wed Nov 23, 2016 10:25 am    Post subject: Reply with quote

Fab,

The reason you had some of the number without an edit mask is because that the decimals are not greater than 5 and hence it is left as is.

these values

Code:

000000000000000091399000;
000000000000000001149438
..


Here you have 000 and 438 and since 0 and 4 are less than 5 we did not apply the edit mask and hence it is left as is.

You need another IFTHEN to have the edit mask on for the condition when the rounding is NOT needed.

Also I apologize for the over sight of handling negative input values. If your input is a negative value and during rounding if you are adding +1000 it will produce incorrect results.

Code:

-46.481,11 Then (-46481,11*0,01187/100/12*11 = -5.057,525 add +1000 = -5.056


-5.056 is an incorrect value. So you need another IFTHEN to handle subtract 1000 instead of adding to get the right value.

Code:

        IFTHEN=(WHEN=(10,9,CH,EQ,C'REDUCED'),                       
       OVERLAY=(104:((((49,18,SFF,MUL,+10000000),                   
                                  MUL,+1187),                       
                                  DIV,+120000000000),               
                                  MUL,150,2,ZD),                   
                        ZD,LENGTH=24),HIT=NEXT),                   
                                                                   
        IFTHEN=(WHEN=(010,9,CH,EQ,C'REDUCED',AND,                   
                      125,1,ZD,LT,5),                               
        OVERLAY=(104:104,24,ZD,                                     
                     EDIT=(SIII.III.III.III.TTT,TTT),               
                           SIGNS=(,-))),                           
                                                                   
        IFTHEN=(WHEN=(010,9,CH,EQ,C'REDUCED',AND,                   
                      125,1,ZD,GE,5,AND,104,24,ZD,GE,+0),           
        OVERLAY=(104:(104,24,ZD,ADD,+1000),DIV,+1000,               
                    EDIT=(SIII.III.III.III.TTT,TTT),               
                            SIGNS=(,-)),HIT=NEXT),                 
                                                                   
        IFTHEN=(WHEN=(010,9,CH,EQ,C'REDUCED',AND,                   
                      125,1,ZD,GE,5,AND,104,24,ZD,LT,+0),           
        OVERLAY=(104:(104,24,ZD,SUB,+1000),DIV,+1000,               
                      EDIT=(SIII.III.III.III.TTT,TTT),             
                            SIGNS=(,-)),HIT=NEXT),                 
                                                                   
                                                                     


This will produce -5,058

That handles the possible values for formula for FIELD-1 and I guess you need similar IFTHEN statements for your Field-3 formula

fab wrote:
Second question is, how can I insert your code to round up numbers after these two calculation? (you can see I commented the ZD to use again SFF, but I can find it working only in this way)


I am not sure as to whether you want to divide by 10/100/1000. Either way it depends on how many decimal digits you want and whether you want to perform the rounding or it.

I am guessing that you need to perform the same level of rounding for FIELD-3 calculation too. So just repeat the same something like this

I assumed that you wanted to delete by +100.

Code:

         IFTHEN=(WHEN=(10,9,CH,EQ,C'NEW'),                     
         OVERLAY=(104:(((86,18,SFF,MUL,+1000),                 
                                  DIV,+1200),                   
                                  MUL,150,2,ZD),               
                         ZD,LENGTH=24),HIT=NEXT),               
                                                               
         IFTHEN=(WHEN=(10,9,CH,EQ,C'NEW',AND,                   
                       125,1,ZD,LT,5),                         
         OVERLAY=(104:104,24,ZD,                               
                      EDIT=(SIII.III.III.III.TTT,TTT),         
                      SIGNS=(,-))),                             
                                                               
         IFTHEN=(WHEN=(10,9,CH,EQ,C'NEW',AND,                   
                       125,1,ZD,GE,5,AND,104,24,ZD,GE,+0),     
         OVERLAY=(104:(104,24,ZD,ADD,+1000),DIV,+1000,         
                     EDIT=(SIII.III.III.III.TTT,TTT),           
                             SIGNS=(,-)),HIT=NEXT),             
                                                               
         IFTHEN=(WHEN=(10,9,CH,EQ,C'NEW',AND,                   
                       125,1,ZD,GE,5,AND,104,24,ZD,LT,+0),     
         OVERLAY=(104:(104,24,ZD,SUB,+1000),DIV,+1000,         
                       EDIT=(SIII.III.III.III.TTT,TTT),         
                             SIGNS=(,-)))                       
                                                               

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Wed Nov 23, 2016 10:54 am    Post subject: Reply with quote

Fab,

On second thoughts I have decided to eliminate all the Repetitive IFTHEN statements and perform with a single IFTHEN.

Basically we have 2 formula's to calculate and then apply the edit mask based on the indicator.

So we by default calculate the 2 formula values and store as temp variables and then checking the indicator we overlay one of the temp variable with the other. By doing so we have 1 temp variable that we need to apply the edit mask.

Right after we determine the quarter constant, we also calculate the formula values.

At position 160 I calculate the Field-1 formula and save it as 24 byte zd field. (indicator = reduced)

At position 190 I calculate the Field-3 formula and save it as 24 byte zd field. ( indicator = new or something else)

Now I have a IFTHEN statement to Check if it Not equal to Reduced and then simply overlay the contents at 190 onto position 160.

By doing this we have single value that we need to validate to apply the rounding and apply the edit mask.

Now the decimals are at position 181 that will validate and round it and apply the edit mask.

Code:

  OUTREC IFOUTLEN=128,                                                   
         IFTHEN=(WHEN=INIT,                                               
                BUILD=(04,08,                                $ FIELD-1   
                       C';',                                 $ DELMTR     
                       39,01,CHANGE=(9,C'D',C'REDUCED',                   
                                       C'N',C'NEW'),                     
                            NOMATCH=(39,1),                               
                       C';',                                 $ DELMTR     
                       33,06,                                $ FILED-3   
                       C';',                                 $ DELMTR     
                       12,02,                                $ FILED-4   
                       C';',                                 $ DELMTR     
                       15,18,SFF,EDIT=(IIIIIIIIIITTTTTTTT),  $ AMT-1     
                       C';',                                 $ DELMTR     
                       40,18,SFF,                            $ AMT-2     
                       EDIT=(SII.III.III.TTT,TT),                         
                       SIGNS=(,-),                                       
                       C';',                                 $ DELMTR     
                       58,17,SFF,DIV,+100,                   $ AMT-3     
                       EDIT=(SI.III.III.TTT,TT),                         
                       SIGNS=(,-),                                       
                       C';',                                 $ DELMTR     
                       75,17,SFF,DIV,+100,                   $ AMT-4     
                       EDIT=(SI.III.III.TTT,TT),                         
                       SIGNS=(,-),                                       
                       C';',                                 $ DELMTR     
                       128:C';',                             $ DELMTR     
                       130:DATE1)),                                       
                                                                         
         IFTHEN=(WHEN=INIT,                                           
        OVERLAY=(140:130,8,Y4T,LASTDAYQ,TOGREG=Y4T,       $ QTR DATE 
                 150:144,2,CHANGE=(2,C'03',C'02',         $ 1QTR = 11
                                     C'06',C'05',         $ 2QTR = 08
                                     C'09',C'08',         $ 3QTR = 05
                                     C'12',C'11'),        $ 4QTR = 02
                 160:((((49,18,SFF,MUL,+10000000),                   
                                   MUL,+1187),                       
                                   DIV,+120000000000),               
                                   MUL,150,2,ZD),                     
                         ZD,LENGTH=24,                               
                                                                     
                 190:(((86,18,SFF,MUL,+1000),                         
                                  DIV,+1200),                         
                                  MUL,150,2,ZD),                     
                         ZD,LENGTH=24)),                             
                                                                     
         IFTHEN=(WHEN=(10,9,CH,NE,C'REDUCED'),                       
         OVERLAY=(160:190,24),HIT=NEXT),                             
                                                                     
         IFTHEN=(WHEN=(181,1,ZD,LT,5),                               
         OVERLAY=(104:160,24,ZD,                                     
                      EDIT=(SIII.III.III.III.TTT,TTT),               
                      SIGNS=(,-))),                                   
                                                                     
         IFTHEN=(WHEN=(181,1,ZD,GE,5,AND,160,24,ZD,GE,+0),           
         OVERLAY=(104:(160,24,ZD,ADD,+1000),DIV,+1000,               
                     EDIT=(SIII.III.III.III.TTT,TTT),                 
                             SIGNS=(,-))),                           
                                                                     
         IFTHEN=(WHEN=(181,1,ZD,GE,5,AND,160,24,ZD,LT,+0),           
         OVERLAY=(104:(160,24,ZD,SUB,+1000),DIV,+1000,               
                       EDIT=(SIII.III.III.III.TTT,TTT),               
                             SIGNS=(,-)))                             
//*                                                                   

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group