IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Dividing in SORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Jenifer Lewis

New User


Joined: 14 Sep 2009
Posts: 28
Location: Maine

PostPosted: Fri Feb 26, 2010 4:08 am
Reply with quote

I would like to divide a number in a file by another number in the same file and include the result in the sort output, but I am not getting the results I want.

For example, dividing "026392" by "000997" yields " 26" with several blanks before the 26.

I've coded it this way: (15,6,ZD,DIV,38,6,ZD)

I suspect all those leading blanks are trying to tell me something, and I tried using masks (e.g. M2) but I got a syntax error.

I'm clearly missing something fairly basic.

Originally I was trying to divide the numbers the other way round to get a percentage, and with the results all to the right of the decimal point the output field was just zeros.

I'd appreciate any thoughts, ideas, or manual pages you can provide.

Thanks!
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Feb 26, 2010 4:12 am
Reply with quote

What do you want the output value to look like for your example?

Show a better example of input values and expected output values.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Fri Feb 26, 2010 4:26 am
Reply with quote

Hi,

Quote:
I suspect all those leading blanks are trying to tell me something,

The result of an arithmetic operation is a 15 digit ZD value that can be converted to a different numeric format.

Gerry
Back to top
View user's profile Send private message
Jenifer Lewis

New User


Joined: 14 Sep 2009
Posts: 28
Location: Maine

PostPosted: Fri Feb 26, 2010 4:27 am
Reply with quote

Forget my earlier example, as it's just one of several feeble attempts.

I want a percentage of the number of customer calls within a group of billed accounts. In the following example, of the 26,392 accounts which billed a couple of weeks ago, 997 of the customers called within a 14-day period.

Here is an input record, and yes, the fields are labeled:

TOTAL BILL = 026392 BILL & CALL = 000997 % OF BILLED =

The result of dividing the smaller by the larger is .037776598 which I would like to see as 3.78 or something similar.

Thanks!
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Feb 26, 2010 5:25 am
Reply with quote

What do you want the output to look like exactly?

Please show the output you expect for each of the following input records:

TOTAL BILL = 026392 BILL & CALL = 000997 % OF BILLED =
TOTAL BILL = 026392 BILL & CALL = 026392 % OF BILLED =
TOTAL BILL = 026392 BILL & CALL = 009999 % OF BILLED =

I'm trying to find out exactly what format you want the output in.

Also, what is the RECFM and LRECL of the input file and expected output file?

If the first field 14,6,ZD or something else (what)?
Is the second field 35,6,ZD or something else (what)?

What is the starting position, length and format of the output % field?
Back to top
View user's profile Send private message
Jenifer Lewis

New User


Joined: 14 Sep 2009
Posts: 28
Location: Maine

PostPosted: Fri Feb 26, 2010 4:34 pm
Reply with quote

For these two i/p records:

TOTAL BILL = 026392 BILL & CALL = 000997
TOTAL BILL = 026392 BILL & ADJ = 000227

I'd like to see this o/p record:

TOTAL BILL = 026392 BILL & CALL = 000997 % OF BILLED = 3.78
TOTAL BILL = 026392 BILL & ADJ = 000227 % OF BILLED = 0.86

My routine formats the o/p as the first 40 bytes of the i/p record, a third label in position 42 ("% of billed") and a percentage calculated by dividing i/p field (35,6,ZD) by i/p field (14,6,ZD).

LRECL=80, RECFM=FB

I was asked to come up with something quick (isn't it always the way?) and rather than write a COBOL program on the fly which I knew darn well would change once they began seeing the results, I used DATACOM queries to derive the data, ICETOOL to match and splice, and for the last piece I thought I'd try the above.

I've never used any SORT calculation except SUM, and looking through the manuals has given me lots of ideas and parameters, but I'm stuck here. If you could steer me in the right direction for finding a good resource for figuring this stuff out, I'd be grateful.

I appreciate your help, Frank!
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Feb 26, 2010 9:53 pm
Reply with quote

Since DFSORT only does integer arithmetic, it's a matter of scaling and rounding to get what you want. Here's a DFSORT job that will do it:

Code:

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
TOTAL BILL = 026392 BILL & CALL = 000997
TOTAL BILL = 026392 BILL & ADJ  = 000227
TOTAL BILL = 026392 BILL & ADJ  = 026392
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  INREC OVERLAY=(42:C'% OF BILLED = ',
    (((35,6,ZD,MUL,+100000),DIV,14,6,ZD),ADD,+5),DIV,+10,
        EDIT=(IIT.TT))
/*


SORTOUT would have:

Code:

TOTAL BILL = 026392 BILL & CALL = 000997 % OF BILLED =   3.78
TOTAL BILL = 026392 BILL & ADJ  = 000227 % OF BILLED =   0.86
TOTAL BILL = 026392 BILL & ADJ  = 026392 % OF BILLED = 100.00
Back to top
View user's profile Send private message
Jenifer Lewis

New User


Joined: 14 Sep 2009
Posts: 28
Location: Maine

PostPosted: Fri Feb 26, 2010 11:20 pm
Reply with quote

Thank you, Frank -- that worked like a charm.

The OVERLAY command is nifty -- haven't had the need to try that before but it was just what the doctor ordered.

I'm looking at your code and I think I understand everything except one part. What does the bolded part of this do?

(((35,6,ZD,MUL,+100000),DIV,14,6,ZD),ADD,+5),DIV,+10,

Is it allowing for decimal places?
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Feb 26, 2010 11:34 pm
Reply with quote

(x+5)/10 is used to round the last decimal place. Without it, you would get 3.77 instead of 3.78.
Back to top
View user's profile Send private message
Jenifer Lewis

New User


Joined: 14 Sep 2009
Posts: 28
Location: Maine

PostPosted: Fri Feb 26, 2010 11:39 pm
Reply with quote

Clear as mud. ;-)

As soon as we come out of storm mode (I work for a power company in Maine and we have about 130K outages right now) and things settle down to a dull roar I'll try to spend some time with Mr. Overlay and learn more about all those instructions.

Thanks again!
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Sat Feb 27, 2010 12:06 am
Reply with quote

Quote:
Clear as mud. ;-)


Ok, let me try to make it clearer (and hopefully the light will come on in Maine) icon_smile.gif

(((35,6,ZD,MUL,+100000),DIV,14,6,ZD),ADD,+5),DIV,+10,
EDIT=(IIT.TT))

Let's take your 997 and 26392 values as an example and work through the arithmetic one term at a time.

997*100000 = 99700000

99700000/26392 = 3777 (DFSORT only keeps the integer part)

We could edit that to 3.777, but you want 3.78 so we have to round 3777 to 378 (0-4 -> 0 or 5-9 -> 10 so 7-> 10).

3777+5 = 3782

3782/10 = 378

We use EDIT=(IIT.TT) to edit that to bb3.78

The key here is to figure out what integer value we want to edit and then work out the integer arithmetic to get that integer value.
Back to top
View user's profile Send private message
Jenifer Lewis

New User


Joined: 14 Sep 2009
Posts: 28
Location: Maine

PostPosted: Sat Feb 27, 2010 12:42 am
Reply with quote

Yep, I see it now.

For all I know the client will want to see 4% so as not to be troubled with all those pesky decimal places, but better to err on the side of too much precision than too little.

Your explanation has been quite, um, illuminating.

And now, my shift in the storm rotation is coming to an end and I will be going home soon. Oh, how I do hope they decide to take us out of "storm mode" before my next turn in the five-person rotation comes around at midnight on Sunday morning!

Thank you for all your help and explanations. Between this and ICETOOL I'm doing all kinds of neat stuff with flat files. Who says you can't teach an old dinosaur new tricks? icon_cool.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Feb 27, 2010 12:45 am
Reply with quote

Quote:
Who says you can't teach an old dinosaur new tricks?
Been a while since i've seen a young dinosaur. . . icon_wink.gif

d
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Sat Feb 27, 2010 1:47 am
Reply with quote

Jenifer,

Glad I could help.

Dick,

But, of course, there were young dinosaurs when there were dinosaurs. I wonder how much a baby Tyrannosaurus weighed? (I know, I could look it up but I'm feeling lazy today.) icon_smile.gif
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sat Feb 27, 2010 2:02 am
Reply with quote

Frank Yaeger wrote:
I wonder how much a baby Tyrannosaurus weighed?


I don't think you would have wanted to hold in your lap and rock it to sleep.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Sat Feb 27, 2010 2:04 am
Reply with quote

I suppose it would have been a bit bigger than one of my pet rats. icon_wink.gif

(I guess it's off-topic Friday.)
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

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top