Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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

New User


Joined: 06 Jun 2009
Posts: 95
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: 2177
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: 7251

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

New User


Joined: 06 Jun 2009
Posts: 95
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: 2177
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

New User


Joined: 06 Jun 2009
Posts: 95
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: 2177
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

New User


Joined: 29 Apr 2008
Posts: 41
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

New User


Joined: 06 Jun 2009
Posts: 95
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

New User


Joined: 06 Jun 2009
Posts: 95
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: 7251

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

New User


Joined: 06 Jun 2009
Posts: 95
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
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 INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 15 Thu Dec 01, 2016 8:28 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us