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: 113
Location: UK

PostPosted: Tue Dec 06, 2016 8:04 pm
Reply with quote

Hi,

I like to apply arithmetic to input data.

Code:
987654321

My Input record

Code:
9 (2) + 8 + 7(2) + 6 + 5(2) + 4 + 3(2) + 1   
Multiplying every alternate digit with 2, starting from left.
Code:
18 + 8 + 14 + 6 + 10 + 4 + 6 + 1


Code:
67 * 9
Multiplying final sum with 9
Code:
603
Expected output record.

Can someone please suggest what reformatting functions I should use to get expected output. I don't think EDIT allows to apply arithmetic operation.

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

Moderator Emeritus


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

PostPosted: Tue Dec 06, 2016 8:41 pm
Reply with quote

I opened a DFSORT Application Programming Guide (I used 2.1) PDF and used the PDF-reader to search for 'mul,' (quotes not needed for the search) and readily located several examples of the use of multiple arithmetic operands.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 3:27 pm
Reply with quote

Thanks Bill. I was expecting this reply.
I have 2012 version of DFSORT Application Programming Guide, I can't see any example for multiplication there.

I did a small test.
Code:
//STEP001  EXEC PGM=SORT   
//SORTIN   DD *             
123                         
//SORTOUT  DD SYSOUT=*     
//SYSIN    DD *             
  OPTION COPY               
  OUTREC FIELDS=(3,MUL,1,3)
//SYSOUT   DD SYSOUT=*     
//SYSUDUMP DD SYSOUT=*     


3 x 123 = 369
and it gives error:

Code:

ICE000I 1 - CONTROL STATEMENTS FOR 5650-ZOS, Z/OS DFSORT V2R1  - 09:47 ON WED DEC 07, 2016 -
            OPTION COPY                                                           00130000 
            OUTREC FIELDS=(3,MUL,1,3)                                                       
                             £                                                             
ICE007A E SYNTAX ERROR                                                                     


Do I need to use Mn, EDIT, or EDxy parameter always with MUL?

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

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 3:39 pm
Reply with quote

fine I tried this.

Code:
//STEP001  EXEC PGM=SORT       
//SORTIN   DD *               
123                           
//SORTOUT  DD SYSOUT=*         
//SYSIN    DD *               
  OPTION COPY                 
  OUTREC FIELDS=(1,3,ZD,MUL,+3)
//SYSOUT   DD SYSOUT=*         
//SYSUDUMP DD SYSOUT=*         


and output is:
Code:
---+----1----+-
***************
            369


Can you please explain why do I need '+3' not 3, and why is output 11 bytes long?

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

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 4:03 pm
Reply with quote

Fine I used EDIT to supress trailing spaces.

Code:
//STEP001  EXEC PGM=SORT                 
//SORTIN   DD *                         
3456                                     
//SORTOUT  DD SYSOUT=*                   
//SYSIN    DD *                         
  OPTION COPY                           
  OUTREC FIELDS=(1,1,ZD,MUL,+1,EDIT(T), 
                 2,1,ZD,MUL,+2,EDIT(IT),
                 3,1,ZD,MUL,+1,EDIT(T), 
                 4,1,ZD,MUL,+2,EDIT(IT))


I am doing 3(1)+4(2)+5(1)+6(2). I will add them once I know what multiplication is producing.

It create:
Code:
---+--
******
3 8512


How do I display only one digit when result of multiplication is only one digit? Bear in mind, I need to SUM them later.
4 x 2 is coming out as b8.

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

Global Moderator


Joined: 21 Sep 2010
Posts: 2588
Location: NYC,USA

PostPosted: Wed Dec 07, 2016 8:31 pm
Reply with quote

Code:
OPTION COPY                             
INREC BUILD=(1,1,ZD,MUL,+1,EDIT(T),     
               2,1,ZD,MUL,+2,EDIT(IT),
               3,1,ZD,MUL,+1,EDIT(T),   
               4,1,ZD,MUL,+2,EDIT(IT)) 
OUTREC FINDREP=(INOUT=(C' ',C''))
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Wed Dec 07, 2016 8:38 pm
Reply with quote

If you don't specify a length (with LENGTH or an explicit EDIT mask) you get a default length. If you don't provide an explicit EDIT, you get a default mask.

"I" in an EDIT means "a blank if there is no significant digit encountered yet", so leading zeros you ask to be blank.

You need a + (or -) because that is how DFSORT will tell if you are specifying a numeric literal, or the (incomplete) start of a field definition.

I'm pretty sure the examples for 2.1 are the same as for 2.2, for instance, p136 in both documents:

Quote:
arexp,edit or (arexp),edit
specifies that the edited result of an arithmetic expression is to appear in the reformatted input record. The arithmetic expression can consist of input fields, decimal constants, operators and parentheses. An arithmetic expression produces a signed, 31-digit zoned decimal (ZD) result to be edited as specified.
See arexp,edit under OUTFIL OUTREC for details.

Code:
Sample Syntax:
INREC FIELDS=(C’**’,27,2,FI,MIN,
83,4,PD,EDIT=(STTTTTTT),SIGNS=(+,-),
15:(((15,5,ZD,ADD,+1),MUL,+100),DIV,62,2,PD),M25,LENGTH=10)


Note the use of FIELDS instead of BUILD, which likely indicates that this example has been around for more than 10 years.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Wed Dec 07, 2016 8:44 pm
Reply with quote

zh_lad,

I would suggest keeping all the intermediate multiplication results in 2 bytes, so you don't have to figure out later which result has 2 digits and which one has 1 digit. Because you need to sum all of them later. It might add more work and confusion if you get rid of the blanks, and then try to figure out where each intermediate result starts.

So you can use TT...edits and read them as ZD in further computations or keep the IT...edits and read them as UFF, whichever works for you.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Wed Dec 07, 2016 9:26 pm
Reply with quote

And multiple arithmetic operations can be carried out without having to define anything for intermediate results. The next operation is on "the current result" for as long as necessary without having to be concerned about it.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 10:06 pm
Reply with quote

Thanks Rohit, it worked.

Rohit Umarjikar wrote:
Code:
OPTION COPY                             
INREC BUILD=(1,1,ZD,MUL,+1,EDIT(T),     
               2,1,ZD,MUL,+2,EDIT(IT),
               3,1,ZD,MUL,+1,EDIT(T),   
               4,1,ZD,MUL,+2,EDIT(IT)) 
OUTREC FINDREP=(INOUT=(C' ',C''))
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 10:18 pm
Reply with quote

Thanks Bill.

1. I learnt it later when I read about Mask.
2. I am aware of use of 'I' in EDIT
3. I didn't know, I was using arithmetic first the first in SORT - Thanks
4. Yes PDF has examples but always problem is discussed on different page. Ideally it should have link to go directly to the problem description by one click. It difficult to absorb example (sample) if problem is discussed on a different page.

Thanks for your comments. They helped to use PDF better.

Bill Woodger wrote:
If you don't specify a length (with LENGTH or an explicit EDIT mask) you get a default length. If you don't provide an explicit EDIT, you get a default mask.

"I" in an EDIT means "a blank if there is no significant digit encountered yet", so leading zeros you ask to be blank.

You need a + (or -) because that is how DFSORT will tell if you are specifying a numeric literal, or the (incomplete) start of a field definition.

I'm pretty sure the examples for 2.1 are the same as for 2.2, for instance, p136 in both documents:

Quote:
arexp,edit or (arexp),edit
specifies that the edited result of an arithmetic expression is to appear in the reformatted input record. The arithmetic expression can consist of input fields, decimal constants, operators and parentheses. An arithmetic expression produces a signed, 31-digit zoned decimal (ZD) result to be edited as specified.
See arexp,edit under OUTFIL OUTREC for details.

Code:
Sample Syntax:
INREC FIELDS=(C’**’,27,2,FI,MIN,
83,4,PD,EDIT=(STTTTTTT),SIGNS=(+,-),
15:(((15,5,ZD,ADD,+1),MUL,+100),DIV,62,2,PD),M25,LENGTH=10)


Note the use of FIELDS instead of BUILD, which likely indicates that this example has been around for more than 10 years.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Wed Dec 07, 2016 10:25 pm
Reply with quote

Quote:
Thanks Rohit, it worked
But I am afraid that is not what you were trying to achieve. Like Bill mentioned above, you can have multiple computations, just use braces to have meaningful results and then edit the final result as needed.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 10:37 pm
Reply with quote

Thanks Arun. Yes, I need to edit my original post to:

Code:
1+8 + 8 + 1+4 + 6 + 1+0 + 4 + 6 + 1
= 40 * 9
= 360

I want to sum the digits of all the results of multiplication. I think I would need intermediate result to find all the digits to do sum later.

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

Moderator


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

PostPosted: Wed Dec 07, 2016 11:08 pm
Reply with quote

Quote:
Code:
987654321

My Input record

Code:
9 (2) + 8 + 7(2) + 6 + 5(2) + 4 + 3(2) + 1   
Multiplying every alternate digit with 2, starting from left.

From your original post, if it is every alternate digit, should it not be like this?

9 (2) + 8 + 7(2) + 6 + 5(2) + 4 + 3(2) + 2 + 1(2) = 70 * 9 = 630

You don't need to worry about the format of intermediate results because, as suggested you can do multiple computations one after the other, like this and edit only the final result.
Code:
//SORTIN  DD *                                     
987654321                                         
//SYSIN   DD *                                     
  OPTION COPY                                     
  OUTREC BUILD=((1,1,ZD,MUL,+2,ADD,               
                 2,1,ZD,ADD,                       
                 3,1,ZD,MUL,+2,ADD,               
                 4,1,ZD,ADD,                       
                 5,1,ZD,MUL,+2,ADD,               
                 6,1,ZD,ADD,                       
                 7,1,ZD,MUL,+2,ADD,               
                 8,1,ZD,ADD,                       
                 9,1,ZD,MUL,+2),MUL,+9,EDIT=(TTTT))
SORTOUT
Code:
 0630
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Wed Dec 07, 2016 11:22 pm
Reply with quote

Thanks Arun. Please check my previous post where I said I need to add up all the digits e.g.
9 (2) + 8 + 7 (2 ) + 6 + 5 (2) + 4 + 3 (2) + 1
18 + 8 + 14 + 6 + 10 + 4 + 6 + 1
1+8+8+1+4+6+1+0+4+6+1
= 40 × 9
= 360.

I couldn't edit my original post. Thanks

>>Still "2" is missing
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu Dec 08, 2016 12:29 am
Reply with quote

IFTHEN=(WHEN=INIT for an OVERLAY to give you the several multiply-by-two results (they are not "intermediate results" in the sense normally used), then another WHEN=INIT with the BUILD to ADD all the digits that you need (odd-number from original location, even-numbered from the location OVERLAYed to) and then multiply that by +9.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Thu Dec 08, 2016 4:21 am
Reply with quote

Thanks Bill. I will apply these suggestions. I was about to fix missing '2' but it was locked. Cheers
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu Dec 08, 2016 4:24 am
Reply with quote

No-one locked anything, and that last comment wasn't mine :-)

Posts can only be edited by non-moderators for 10 minutes after they have been entered. If you can post (or PM) me a correction I can apply it and tidy up a bit.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Thu Dec 08, 2016 7:46 pm
Reply with quote

Hi Bill,

How will I deal with space when result of multiplication is only 1 digit.

Code:
1,1,UFF,MUL,+2,EDIT(IT)


How will I ignore space to pick up digits to sum in OUTREC (second IFTHEN).

Rohit was using FIND and REPLACE
Code:
OUTREC FINDREP=(INOUT=(C' ',C'')) 



Thanks.

Bill Woodger wrote:
IFTHEN=(WHEN=INIT for an OVERLAY to give you the several multiply-by-two results (they are not "intermediate results" in the sense normally used), then another WHEN=INIT with the BUILD to ADD all the digits that you need (odd-number from original location, even-numbered from the location OVERLAYed to) and then multiply that by +9.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Thu Dec 08, 2016 7:55 pm
Reply with quote

zh_lad wrote:
How will I ignore space to pick up digits to sum in OUTREC (second IFTHEN).
This is already suggested above. Keep the results in 2-bytes and read as ZD or UFF (2 bytes)
Quote:
you can use TT...edits and read them as ZD in further computations or keep the IT...edits and read them as UFF, whichever works for you.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Thu Dec 08, 2016 8:58 pm
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: 2481
Location: @my desk

PostPosted: Thu Dec 08, 2016 10:07 pm
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

Moderator Emeritus


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

PostPosted: Thu Dec 08, 2016 10:40 pm
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: 113
Location: UK

PostPosted: Fri Dec 09, 2016 8:34 pm
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: 2481
Location: @my desk

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

Thanks and Wish you the same!
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 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Using sort on VB records based on off... DFSORT/ICETOOL 6
This topic is locked: you cannot edit posts or make replies. Passing a field name to COBOL program COBOL Programming 10
No new posts JOINKEYS to match two input files on ... DFSORT/ICETOOL 3
No new posts BMS map length field greater than zero CICS 3
No new posts Break a record into fields, each fiel... SYNCSORT 2
Search our Forums:

Back to Top