Page 1 of 1

DIVISION in Sort

PostPosted: Wed Dec 04, 2013 11:38 pm
by rskmfguy
Hi All,

I'm trying to do Division in DFSORT

//STEP1    EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD *
52
//SYSIN  DD *
 OUTREC BUILD=(1,1,ZD,DIV,2,1,ZD)
 OPTION COPY
/*

I got the answer as 2. I was expecting to get 2.5

Then I changed the sort card as below

OUTREC BUILD =((1,1,ZD,DIV,2,1,ZD),EDIT=(TT.TT))

This time I got 00.02.

Can someone please help me to know what I'm missing?

Thank you in advance!

Regards,
rskmfguy

Re: DIVISION in Sort

PostPosted: Thu Dec 05, 2013 12:09 am
by Akatsukami
rskmfguy wrote:Hi All,

I'm trying to do Division in DFSORT

//STEP1    EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD *
52
//SYSIN  DD *
 OUTREC BUILD=(1,1,ZD,DIV,2,1,ZD)
 OPTION COPY
/*

I got the answer as 2. I was expecting to get 2.5


As it says in the fine manual,

The intermediate or final result of a DIV operation is rounded down to the nearest integer.


(Search on arexp.)

Then I changed the sort card as below

OUTREC BUILD =((1,1,ZD,DIV,2,1,ZD),EDIT=(TT.TT))

This time I got 00.02.


Unlike in COBOL, a decimal point in DFSORT does not have aligning power (this is not stated explicitly, but is shown in several examples; search on edit mask).

Re: DIVISION in Sort

PostPosted: Thu Dec 05, 2013 2:13 am
by BillyBoyo
If you want decimals from a DIV you have to arrange it yourself. MUL by 100 first. Note that if you want "rounding" other than "down to nearest integer" (aka "truncation") you'll have to code that yourself as well.