Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Performing arithmetic on input field
Goto page Previous  1, 2
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 101
Location: UK

PostPosted: Thu Dec 08, 2016 8:58 pm    Post subject:
Reply with quote

My input:
Code:
518791041070069


I read more about having multiple IFTHEN and improved code to:
Code:
OPTION COPY                                       
INREC IFTHEN=(WHEN=INIT,                           
      BUILD=(1,1,UFF,MUL,+2,EDIT(IT),             
             2,1,UFF,MUL,+1,EDIT(T),               
             3,1,UFF,MUL,+2,EDIT(IT),             
             4,1,UFF,MUL,+1,EDIT(T),               
             5,1,UFF,MUL,+2,EDIT(IT),             
             6,1,UFF,MUL,+1,EDIT(T),               
             7,1,UFF,MUL,+2,EDIT(IT),             
             8,1,UFF,MUL,+1,EDIT(T),               
             9,1,UFF,MUL,+2,EDIT(IT),             
            10,1,UFF,MUL,+1,EDIT(T),               
            11,1,UFF,MUL,+2,EDIT(IT),             
            12,1,UFF,MUL,+1,EDIT(T),               
            13,1,UFF,MUL,+2,EDIT(IT),             
            14,1,UFF,MUL,+1,EDIT(T),               
            15,1,UFF,MUL,+2,EDIT(IT))),           
      IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C' ',C'')))


Result is:
Code:
10116718104201400618


number of digits in Result will vary based on input. How do I tell SORT to pick all the digits when adding them?

P.S. - I was amazed to know every IFTHEN picks up amendments done by previous IFTHEN. I didn't know that.

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

Arun Raj

Moderator


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

PostPosted: Thu Dec 08, 2016 10:07 pm    Post subject:
Reply with quote

I think you got confused. Forget the FINDREP suggestion. You don't need FINDREP. I will repeat what was suggested already if that makes any clearer.

1 - In the first IFTHEN , multiply only the digits at odd positions(pos-1,3,5,..etc), which in the input are in ZD format (you don't need to multiply others by 1) and OVERLAY at the end of the record (say pos-81,83,85..etc), here either keep it edited as 'TT', or 'IT' so you can read them as ZD or UFF in the second IFTHEN.
To avoid confusion I'd recommend using TT, so you see ZEROes instead of blanks.

2 - In the second IFTHEN, ADD all the individual digits from the results above(pos-81,82,83,...etc) and the digits at even positions from your original input which is still available at pos-2,4,6,..etc. And include the MUL by 9 in the same calculation, edit the final result to format it as per your requirement.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Thu Dec 08, 2016 10:40 pm    Post subject: Reply to: Performing arithmetic on input field
Reply with quote

zh_lad wrote:
I was amazed to know every IFTHEN picks up amendments done by previous IFTHEN


It is not the IFTHEN, it is the BUILD. Each BUILD that is executed creates a "new version" of the current record, from the previous version.

OVERLAY does not create a new version of the current records, but operates on the existing version.

Code:

BUILD=(21,20,1,20)
OVERLAY=(21,20,1,20)


Try those, the output will be different, because of the way BUILD and OVERLAY operate.

If you need to "rearrange" data, BUILD is more convenient. If you need to update data where it is, OVERLAY is 1) clearer and 2) performs better.

Other differences are that although you can specify columns in BUILD, you can only define fields in "ascending" order (the columns will just get space-padded if needed), whereas with OVERLAY you can specify the columns in any order, and even do multiple transformations to the same field in one OVERLAY, by specifying the same column multiple times.

Anyway, I'm assuming that was the confusion (how BUILD works), because it is entirely normal to expect something that has been changed to be available to the next line of code.

Note also that with IFTHEN=(WHEN=(logicalexpression), when one is true, no further IFTHEN=(WHEN=(logicalexpression) are processed for that "record", unless you ask for it, by using HIT=NEXT, and that includes if you want to use WHEN=ANY.

So one or more IFTHEN=(WHEN=(logicalexpression) are like a "case/select" statement (EVALUATE in COBOL).
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 101
Location: UK

PostPosted: Fri Dec 09, 2016 8:34 pm    Post subject: Reply to: Performing arithmetic on input field
Reply with quote

Sorry I couldn't pursue this as I was busy in work. I am on holiday for next week. I will resume when I am back from holiday.

Wish you all Merry Xmas and a Happy New Year.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Fri Dec 09, 2016 8:36 pm    Post subject:
Reply with quote

Thanks and Wish you the same!
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 101
Location: UK

PostPosted: Thu Jan 05, 2017 8:31 pm    Post subject:
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: 2285
Location: @my desk

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

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

Active User


Joined: 29 Apr 2008
Posts: 214
Location: Maryland

PostPosted: Fri Jan 06, 2017 3:57 am    Post subject:
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: 101
Location: UK

PostPosted: Fri Jan 06, 2017 2:13 pm    Post subject: Reply to: Performing arithmetic on input field
Reply with quote

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

Active User


Joined: 06 Jun 2009
Posts: 101
Location: UK

PostPosted: Fri Jan 06, 2017 3:29 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Fri Jan 06, 2017 4:55 pm    Post subject: Reply to: Performing arithmetic on input field
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: 101
Location: UK

PostPosted: Fri Jan 06, 2017 7:50 pm    Post subject:
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: 101
Location: UK

PostPosted: Wed Feb 08, 2017 7:31 pm    Post subject: Reply to: Performing arithmetic on input field
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: 101
Location: UK

PostPosted: Wed Feb 08, 2017 8:35 pm    Post subject:
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: 2285
Location: @my desk

PostPosted: Wed Feb 08, 2017 10:55 pm    Post subject:
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: 101
Location: UK

PostPosted: Thu Feb 09, 2017 10:49 pm    Post subject:
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: 2285
Location: @my desk

PostPosted: Fri Feb 10, 2017 3:26 am    Post subject:
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: 101
Location: UK

PostPosted: Fri Feb 10, 2017 3:28 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JOINKEYS Paired and Unpaired Sort on ... MFwhiz DFSORT/ICETOOL 7 Tue Nov 07, 2017 2:46 am
No new posts Copy selected columns from 2 input fi... Poha Eater DFSORT/ICETOOL 3 Thu Nov 02, 2017 3:43 pm
This topic is locked: you cannot edit posts or make replies. Incrementing current time field by 30... arunsoods DFSORT/ICETOOL 11 Thu Oct 26, 2017 3:22 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us