IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Performing arithmetic on input field


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Thu Jan 05, 2017 8:31 pm
Reply with quote

Hi, Happy New Year to you all. I am back to the task.

Code:
//SORTIN   DD *                         
518791041070069                         
//SORTOUT  DD SYSOUT=*                 
//SYSIN    DD *                         
  OPTION COPY                           
  INREC IFTHEN=(WHEN=INIT,             
        BUILD=(1,1,UFF,MUL,+2,EDIT(TT),
               2,1,UFF,MUL,+1,EDIT(TT),
               3,1,UFF,MUL,+2,EDIT(TT),
               4,1,UFF,MUL,+1,EDIT(TT),
               5,1,UFF,MUL,+2,EDIT(TT),
               6,1,UFF,MUL,+1,EDIT(TT),
               7,1,UFF,MUL,+2,EDIT(TT),
               8,1,UFF,MUL,+1,EDIT(TT),
               9,1,UFF,MUL,+2,EDIT(TT),
              10,1,UFF,MUL,+1,EDIT(TT),
              11,1,UFF,MUL,+2,EDIT(TT),
              12,1,UFF,MUL,+1,EDIT(TT),
              13,1,UFF,MUL,+2,EDIT(TT),
              14,1,UFF,MUL,+1,EDIT(TT),
              15,1,UFF,MUL,+2,EDIT(TT)))
  OUTREC BUILD=(1,1,ZD,ADD,             
               2,1,ZD,ADD, 
               3,1,ZD,ADD, 
               4,1,ZD,ADD, 
               5,1,ZD,ADD, 
               6,1,ZD,ADD, 
               7,1,ZD,ADD, 
               8,1,ZD,ADD, 
               9,1,ZD,ADD, 
              10,1,ZD,ADD, 
              11,1,ZD,ADD, 
              12,1,ZD,ADD, 
              13,1,ZD,ADD, 
              14,1,ZD,ADD, 
              15,1,ZD,ADD, 
              16,1,ZD,ADD, 
              17,1,ZD,ADD, 
              18,1,ZD,ADD, 
              19,1,ZD,ADD, 
              20,1,ZD,ADD, 
              21,1,ZD,ADD, 
              22,1,ZD,ADD, 
              23,1,ZD,ADD, 
              24,1,ZD,ADD,   
              25,1,ZD,ADD,   
              26,1,ZD,ADD,   
              27,1,ZD,ADD,   
              28,1,ZD,ADD,   
              29,1,ZD,ADD,   
              30,1,ZD,MUL,+9)
//SYSOUT   DD SYSOUT=*       
//SYSUDUMP DD SYSOUT=*       

output is 116, it should have been 468 (52 x 9). I have checked, calculation is right up to 52. Something has gone wrong when MULT with 9. Is the length of 52 causing MULT with work differently?

Thanks.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Jan 06, 2017 2:25 am
Reply with quote

Try enclosing all your ADDs in a separate () parenthesis
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Fri Jan 06, 2017 3:57 am
Reply with quote

Definitely: MUL has priority over ADD.

With all ADDs enclosed in () the result is correct.

Edited to remove spurious content
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Fri Jan 06, 2017 2:13 pm
Reply with quote

Thanks Arun.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Fri Jan 06, 2017 3:29 pm
Reply with quote

Hi Arun,

Thanks for your help so far. One last query. Is there a way I can do this calculation in INREC using multiple BUILD as I want to use the OUTREC to present data differently.

Currennt output is 468.

I want to stick right most digit (8 in this case) to original input value. In this case, my final output should be:
5187910410700698

This algorithm will be used on an input file to calculate check digit (Luhn algorithm).

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jan 06, 2017 4:55 pm
Reply with quote

Yes, there is no need for the OUTREC, you could put the second BUILD on another WHEN=INIT on INREC.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Fri Jan 06, 2017 7:50 pm
Reply with quote

Thanks Bill. It worked with two BUILDs with WHEN=INIT.

Now I am working on OUTREC to stick right most digit to original input. Thanks for your help. Cheers!
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Wed Feb 08, 2017 7:31 pm
Reply with quote

I have managed to calculate check digit using:

Code:
//SORTIN   DD *                             
518791041070069                             
518621031103021                             
518621031103022                             
518621031103023                             
494000111111111                             
456215111111112                             
420376111111113                             
457150111111114                             
446272111111115                             
431940111111116                             
//SORTOUT  DD SYSOUT=*                     
//SYSIN    DD *                             
  OPTION COPY                               
  INREC IFTHEN=(WHEN=INIT,                 
        BUILD=(1,15,1,1,UFF,MUL,+2,EDIT(TT),
                    2,1,UFF,MUL,+1,EDIT(TT),
                    3,1,UFF,MUL,+2,EDIT(TT),
                    4,1,UFF,MUL,+1,EDIT(TT),
                    5,1,UFF,MUL,+2,EDIT(TT),
                    6,1,UFF,MUL,+1,EDIT(TT),   
                    7,1,UFF,MUL,+2,EDIT(TT),   
                    8,1,UFF,MUL,+1,EDIT(TT),   
                    9,1,UFF,MUL,+2,EDIT(TT),   
                   10,1,UFF,MUL,+1,EDIT(TT),   
                   11,1,UFF,MUL,+2,EDIT(TT),   
                   12,1,UFF,MUL,+1,EDIT(TT),   
                   13,1,UFF,MUL,+2,EDIT(TT),   
                   14,1,UFF,MUL,+1,EDIT(TT),   
                   15,1,UFF,MUL,+2,EDIT(TT))), 
        IFTHEN=(WHEN=INIT,                     
        BUILD=(1,15,(16,1,ZD,ADD,               
                     17,1,ZD,ADD,               
                     18,1,ZD,ADD,               
                     19,1,ZD,ADD,               
                     20,1,ZD,ADD,               
                     21,1,ZD,ADD,               
                     22,1,ZD,ADD,               
                     23,1,ZD,ADD,               
                     24,1,ZD,ADD,               
                     25,1,ZD,ADD,               
                     26,1,ZD,ADD,               
                     27,1,ZD,ADD,     
                     28,1,ZD,ADD,     
                     29,1,ZD,ADD,     
                     30,1,ZD,ADD,     
                     31,1,ZD,ADD,     
                     32,1,ZD,ADD,     
                     33,1,ZD,ADD,     
                     34,1,ZD,ADD,     
                     35,1,ZD,ADD,     
                     36,1,ZD,ADD,     
                     37,1,ZD,ADD,     
                     38,1,ZD,ADD,     
                     39,1,ZD,ADD,     
                     40,1,ZD,ADD,     
                     41,1,ZD,ADD,     
                     42,1,ZD,ADD,     
                     43,1,ZD,ADD,     
                     44,1,ZD,ADD,     
                     45,1,ZD,ADD,     
                     46,1,ZD),MUL,+9))
   OUTREC FIELDS=(1,15,30,1)
//SYSOUT   DD SYSOUT=*       
//SYSUDUMP DD SYSOUT=*       


Code:
Output:
5187910410700698
5186210311030217
5186210311030225
5186210311030233
4940001111111111
4562151111111129
4203761111111138
4571501111111140
4462721111111153
4319401111111165


Is there any better way to write above code? Thanks.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Wed Feb 08, 2017 8:35 pm
Reply with quote

I am doing this when I am free. If I wanted to do then I too could have written a cobol program in an hour.
SORT gives me flexibility to re use code for different files and layout.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Feb 08, 2017 10:55 pm
Reply with quote

Maybe you can remove the calculations that are not required and also directly overlay the final 'result digit', like this:
Code:
//SYSIN    DD *                             
   OPTION COPY                               
   INREC IFOUTLEN=16,IFTHEN=(WHEN=INIT,     
         OVERLAY=(16:1,1,UFF,MUL,+2,EDIT(TT),
                     3,1,UFF,MUL,+2,EDIT(TT),
                     5,1,UFF,MUL,+2,EDIT(TT),
                     7,1,UFF,MUL,+2,EDIT(TT),
                     9,1,UFF,MUL,+2,EDIT(TT),
                    11,1,UFF,MUL,+2,EDIT(TT),
                    13,1,UFF,MUL,+2,EDIT(TT),
                    15,1,UFF,MUL,+2,EDIT(TT),
                  16:(16,1,ZD,ADD,
                      17,1,ZD,ADD,
                      18,1,ZD,ADD,
                      19,1,ZD,ADD,
                      20,1,ZD,ADD,
                      21,1,ZD,ADD,
                      22,1,ZD,ADD,
                      23,1,ZD,ADD,
                      24,1,ZD,ADD,
                      25,1,ZD,ADD,
                      26,1,ZD,ADD,
                      27,1,ZD,ADD,
                      28,1,ZD,ADD,
                      29,1,ZD,ADD,
                      30,1,ZD,ADD,
                      31,1,ZD,ADD,
                      02,1,ZD,ADD,
                      04,1,ZD,ADD,
                      06,1,ZD,ADD,
                      08,1,ZD,ADD,
                      10,1,ZD,ADD,               
                      12,1,ZD,ADD,               
                      14,1,ZD),MUL,+9,EDIT=(T)))
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Thu Feb 09, 2017 10:49 pm
Reply with quote

Thanks Arun. Looks brilliant.

I am getting slightly incorrect result with this code.

Code:
//SORTIN   DD *                               
518791041070069                               
//SYSIN    DD *                               
    OPTION COPY                               
    INREC IFOUTLEN=16,IFTHEN=(WHEN=INIT,     
          OVERLAY=(16:1,1,UFF,MUL,+2,EDIT(TT),
                      3,1,UFF,MUL,+2,EDIT(TT),
                      5,1,UFF,MUL,+2,EDIT(TT),
                      7,1,UFF,MUL,+2,EDIT(TT),
                      9,1,UFF,MUL,+2,EDIT(TT),
                     11,1,UFF,MUL,+2,EDIT(TT),
                     13,1,UFF,MUL,+2,EDIT(TT),
                     15,1,UFF,MUL,+2,EDIT(TT),
                   16:(16,1,ZD,ADD,           
                       17,1,ZD,ADD,           
                       18,1,ZD,ADD,           
                       19,1,ZD,ADD,           
                       20,1,ZD,ADD,           
                       21,1,ZD,ADD,           
                       22,1,ZD,ADD,           
                       23,1,ZD,ADD,           
                       24,1,ZD,ADD,           
                      25,1,ZD,ADD,             
                      27,1,ZD,ADD,             
                      28,1,ZD,ADD,             
                      29,1,ZD,ADD,             
                      30,1,ZD,ADD,             
                      31,1,ZD,ADD,             
                      32,1,ZD,ADD,             
                      02,1,ZD,ADD,             
                      04,1,ZD,ADD,             
                      06,1,ZD,ADD,             
                      08,1,ZD,ADD,             
                      10,1,ZD,ADD,             
                      12,1,ZD,ADD,             
                      14,1,ZD),MUL,+9,EDIT=(T)))


output is:
Code:
5187910410700699


Check digit should be '8'. Addition is resulting 51, should have been 52.
51 x 9 = 459 ==> resulting CH as '9'.
52 x 9 = 468 ==> results CH as '8'.

Thanks.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Feb 10, 2017 3:26 am
Reply with quote

You missed the '26,1,ZD,ADD' and you have an extra line instead - '32,1,ZD,ADD'
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 115
Location: UK

PostPosted: Fri Feb 10, 2017 3:28 pm
Reply with quote

Sorted. Thanks.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL Goto page Previous  1, 2

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts force tablespace using LISTDEF input DB2 1
No new posts Two input files & writing counter... DFSORT/ICETOOL 12
Search our Forums:

Back to Top