DIVISION in Sort



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

DIVISION in Sort

Postby rskmfguy » Wed Dec 04, 2013 11:38 pm

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
rskmfguy
 
Posts: 10
Joined: Mon Oct 22, 2012 11:07 pm
Has thanked: 8 times
Been thanked: 0 time

Re: DIVISION in Sort

 

Re: DIVISION in Sort

Postby Akatsukami » Thu Dec 05, 2013 12:09 am

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).
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day

These users thanked the author Akatsukami for the post:
rskmfguy (Thu Dec 05, 2013 5:57 am)
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: DIVISION in Sort

Postby BillyBoyo » Thu Dec 05, 2013 2:13 am

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.

These users thanked the author BillyBoyo for the post:
rskmfguy (Thu Dec 05, 2013 5:58 am)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post