## Arithmetic operations using syncsort

Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL

### Arithmetic operations using syncsort

Hi All,

Here is my requirement. I would basically like to evaluate the percentage of two fields in a file and write it to an output file.

Input file is a follows:-

col1;            col2;            col3;
A;           22.32;           11.32;
B;        11111.99;        10920.35;
C;         3567.23;           38.60;
D;          760.25;          575.57;

It should basically be calculating the difference between col2 and col 3 ( Res1=col2-col3) and divide by col3 ( (res1/col3)*100) to get the percentage.

Output file is as follows :-

col1;            col2;            col3;              col4;
A;           22.32;           11.32;0.9717314487632509
B;        11111.99;        10920.35;0.0175488880850888
C;         3567.23;           38.60;91.41528497409326
D;          760.25;          575.57;0.3208645342877495

Can some one help me in achieving it.

P.S. I tried doing it in phase by phase but unable to achieve it.
ibmmf4u

Posts: 65
Joined: Wed Dec 14, 2011 10:26 pm
Has thanked: 0 time
Been thanked: 1 time

### Re: Arithmetic operations using syncsort

Hello,

Suggest you post the code you tried and explain what did not work.

Posting it didn't work is the biggest waste of time in the forum . . . You need to show what didn't work - diagnostic message, failed run, not the desired results, etc.
Hope this helps,
d.sch.

dick scherrer
Global moderator

Posts: 6284
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

### Re: Arithmetic operations using syncsort

Hi Dick,

Pasted below is the piece of code which i tried running in Phases.

The resultant filed in first which phase which the difference between (col2-col3) is a 16 byte field of which the last two positions are reserved for the decimal places i have done it with the help of EDIT ( as i couldn't able to obtain it automatically).

//STEP010  EXEC PGM=SORT
//SORTIN   DD DSN=INPUT.FILE,DISP=SHR
//SORTOUT  DD DSN=TEMP.FILE,
//            DISP=(NEW,CATLG,DELETE),
//            SPACE=(CYL,(10,20),RLSE),
//            DCB=(RECFM=FB,LRECL=250)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
SORT  FIELDS=COPY -
OUTREC FIELDS=(1,40,4X,
(6,16,UFF,SUB,23,16,UFF),EDIT=(TTTTTTTTTTTTT.TT))
//*

Output:-

A;           22.32;           11.32;     0000000000011.00
B;        11111.99;        10920.35;     0000000000191.64
C;         3567.23;           38.60;     0000000003528.63
D;          760.25;          575.57;     0000000000184.68

And later tried to divide the resultant value with the col3 but couldn't able to get the exact results ( missing the decimal points am not sure if its beacuse of UFF)

//STEP040  EXEC PGM=SORT
//SORTIN   DD DSN=TEMP.FILE,DISP=SHR
//SORTOUT  DD DSN=OUTPUT.FILE,
//            DISP=(NEW,CATLG,DELETE),
//            SPACE=(CYL,(10,20),RLSE),
//            DCB=(RECFM=FB,LRECL=250)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
SORT  FIELDS=COPY -
OUTREC FIELDS=(1,64,X,
(45,16,UFF,DIV,23,16,UFF))

Output:-

A;           22.32;           11.32;     0000000000011.00              0
B;        11111.99;        10920.35;     0000000000191.64              0
C;         3567.23;           38.60;     0000000003528.63             91
D;          760.25;          575.57;     0000000000184.68              0

Request you to kindly help me out

ibmmf4u

Posts: 65
Joined: Wed Dec 14, 2011 10:26 pm
Has thanked: 0 time
Been thanked: 1 time

### Re: Arithmetic operations using syncsort

Hi All,

Can someone let me know , if there is a way in achieving it ?

ibmmf4u

Posts: 65
Joined: Wed Dec 14, 2011 10:26 pm
Has thanked: 0 time
Been thanked: 1 time

### Re: Arithmetic operations using syncsort

Hello ibmmf4u,

Here is an example that may be helpful to you:
//SORT1 EXEC PGM=SORT
//SYSOUT  DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN  DD *
A       22.32    11.32
B    11111.99 10920.35
C     3567.23    38.60
D      760.25   575.57
//SYSIN   DD *
SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=INIT,
BUILD=(1,5,(((6,8,UFF,SUB,15,8,UFF),MUL,+10000),DIV,15,8,UFF))),
IFTHEN=(WHEN=(16,1,CH,EQ,C' '),
OVERLAY=(16:17,4,ZD,EDIT=(TT.TT))),
IFTHEN=(WHEN=(16,1,CH,NE,C' '),
OVERLAY=(14:14,7,ZD,DIV,+100,EDIT=(TT.TT)))
/*

This is the output produced by the step above:
A              97.17
B              01.75
C            91.4152
D              32.08

It may need to be tweaked to get the exact formatting of the output you desire, but its a good starting point.

Regards,
Alissa Margulies
Syncsort Mainframe Product Services
201-930-8260
zos_tech@syncsort.com
Alissa Margulies
Global moderator

Posts: 369
Joined: Tue Feb 26, 2008 11:15 pm
Location: USA
Has thanked: 1 time
Been thanked: 2 times