Page 1 of 1

SORT card for addition.

Posted: Wed Jun 10, 2015 2:06 pm
by Deepak Mahant
Hi,

In a COBOL program I have this calculation:

Code: Select all

NBR-A = TRUNC((variable-x / variable-y) + 0.5 )


The question is, can I do this using SORT? Please suggest on this.

I tried the following:

Code: Select all

OUTREC BUILD=(1:1,22,((17,3,ZD,DIV,20,3,ZD),ADD,+0.5))


And

Code: Select all

OUTREC BUILD=(1:1,22,((17,3,ZD,DIV,20,3,ZD),ADD,(+50,DIV,+100)))
but not getting the desired result.

I want to divide to interger column and add 0.5 to get the output field.

Please suggest.

regards

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 2:42 pm
by enrico-sorichetti
sort does not handle decimal digits ...
You will have to do it on Your own.

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 3:32 pm
by enrico-sorichetti
a working snippet to show some division and rounding

Code: Select all

 ****** ***************************** Top of Data ******************************
 000001 //ENRICO1  JOB NOTIFY=&SYSUID,
 000002 //             MSGLEVEL=(1,1),CLASS=A,MSGCLASS=X
 000003 //*
 000004 //S1      EXEC PGM=SORT
 000005 //SYSPRINT  DD SYSOUT=*
 000006 //SYSOUT    DD SYSOUT=*
 000007 //TOOLMSG   DD SYSOUT=*
 000008 //DFSMSG    DD SYSOUT=*
 000009 //SORTIN    DD *
 000010  5.12      2.34
 000011  5         2
 000012  102       2
 000013  7         2
 000014  6         3
 000015 //SORTOUT   DD SYSOUT=*
 000016 //SYSIN     DD *
 000017   OPTION COPY
 000018   INREC  IFTHEN=(WHEN=NONE,
 000019          OVERLAY=(22:02,09,UFF,M11,LENGTH=07,C'00',
 000020                   32:12,09,UFF,M11,LENGTH=09,
 000021                   42:(22,09,ZD,DIV,32,09,ZD),ZD,LENGTH=09,
 000022                   52:(42,09,ZD,ADD,+50),ZD,LENGTH=09,
 000023                   62:(52,07,ZD),ZD,LENGTH=09))
 ****** **************************** Bottom of Data ****************************
the result

Code: Select all

********************************* TOP OF DATA **********************************
 5.12      2.34      000051200 000000234 000000218 000000268 000000002
 5         2         000000500 000000002 000000250 000000300 000000003
 102       2         000010200 000000002 000005100 000005150 000000051
 7         2         000000700 000000002 000000350 000000400 000000004
 6         3         000000600 000000003 000000200 000000250 000000002
******************************** BOTTOM OF DATA ********************************

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 5:19 pm
by William Collins
Deepak Mahant,

The code you show is not COBOL.

Without seeing your data, expected result and achieved result, we can't do more than make useless guesses about what is wrong with the SORT cards you have shown.

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 5:31 pm
by enrico-sorichetti
My idea is that any IT practitioner with the usual number of active neurons should be able to take a snippet
and adapt it to any similar logic ,

in my snippet there are FIVE stages

1 and 2 convert from free form to zoned decimal extending the first operand with 2 decimal digits of zeroes
3 carries on the division
4 rounds UP
5 drops the decimals

does not look too difficult to follow :mrgreen:

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 9:53 pm
by William Collins
I agree, enrico. I wasn't talking about your code, but the TS/OP's code. Clarified now.

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 11:07 pm
by enrico-sorichetti
hello William,
I was just considering Your comment
we can't do more than make useless guesses about what is wrong
I really hate wen we are asked to spoon feed the TS down to the last bit

and..
in general I wonder about the lack of logic reasoning shown in too many questions asked
and when I ask a TS where the problem is - in the logic or the coding -
I am really surprised that in too many cases the problem is in devising the logic.

Re: SORT card for addition.

Posted: Wed Jun 10, 2015 11:16 pm
by William Collins
Agreed again, enrico.

However my actual comment was specific:
we can't do more than make useless guesses about what is wrong with the SORT cards you have shown
Turns out I was wrong on that anyway. Still, no point in fixing without seeing the data, as equally don't know what to fix :-)

Re: SORT card for addition.

Posted: Sat Jun 13, 2015 5:33 pm
by Deepak Mahant
The original equation is from the "requirement document" but that can be done in cobol program, at least that what is assumed. But we thought to do it in sort as well. So William that's not a Cobol code but I needed some direction to achieve it in sort.

Re: SORT card for addition.

Posted: Sat Jun 13, 2015 6:10 pm
by William Collins
And what do you think enrico's effort is other than giving you the direction you want? It is also well documented.

SORT only does integer operations, so you have to do the scaling yourself, and does not do rounding, so you have to do that yourself.