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

Arithmetic Operation


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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 11, 2012 7:48 pm
Reply with quote

I have 3 input files,
1) First file:
Total1
---------
05
2)Second file:
Total1
---------
20

output file should be.

Percentage
--------------
25

Now, I have one more file which contains total percentage,

3)Third file:
Percentage
-------------
90

Here, I have to check if 25>90 then set the return code of the step to 8 else set the return code to 4.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Apr 11, 2012 7:53 pm
Reply with quote

Well, we'd need the full shebang,

Recfms/lrecls of all files. Start/length of all fields relevant. Sample data for all three input files, in the Code tags please.

Are the RC values fixed in stone?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 11, 2012 7:57 pm
Reply with quote

I have 3 input files,
1) First file:
Code:
Total1
---------
05

2)Second file:
Code:
Total1
---------
20


output file should be.

Code:
Percentage
--------------
25


Now, I have one more file which contains total percentage,

3)Third file:
Code:
Percentage
-------------
90


Here, I have to check if 25>90 then set the return code of the step to 8 else set the return code to 4.

Its FB file and LRECL=20 for all of the files.
Please treat the values provided as the sample data.I mean all the time these 3 input files will be containing only one record.
Yes the RC values are fixed in all the time.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 11, 2012 8:11 pm
Reply with quote

Code:
total
-----
20


Please ignore this reply alone.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Apr 11, 2012 8:15 pm
Reply with quote

You are showing three records on each input file. Do you mean one data record plus two heading records?

Isn't this a bit of "overkill"?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 11, 2012 8:28 pm
Reply with quote

Sorry for getting you misunderstood on this,
Just the numbers are the actual data present in al off these files, please idnore all the headers and '---'.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 11, 2012 9:14 pm
Reply with quote

Hello Bill,
Please consider it as a only data records, no headers and '-----'.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Wed Apr 11, 2012 9:45 pm
Reply with quote

The time between your first and last posting is 1h26m. Wasn't that enough to code a simple COBOL, PL/I or REXX program to do what's needed?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Apr 11, 2012 10:38 pm
Reply with quote

prino wrote:
The time between your first and last posting is 1h26m. Wasn't that enough to code a simple COBOL, PL/I or REXX program to do what's needed?

Wrote, compiled, linked, and tested a PL/I program in 00:33. My mainframe is running hella slow due to storage issues just now, else I probably could have knocked ten minutes off that time.
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: Wed Apr 11, 2012 10:43 pm
Reply with quote

Quote:
Here, I have to check if 25>90 then set the return code of the step to 8 else set the return code to 4.


Passing back RC=4 or RC=8 with DFSORT is not straightforward. Passing back RC=0 or RC=4 would be.

As others have said, DFSORT is probably NOT the ideal program for this kind of thing. We could probably cobble something together to do it but a simple program in PL/I, REXX, COBOL, etc would probably be a better choice.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Apr 12, 2012 1:46 pm
Reply with quote

Akatsukami, Prino:
Yes, you all are right, but I don't have a requirement to include any COBOL, REXX,PL/I modules, otherwise I would not have posted this here.
Moreover, I am trying to do this with the help of SAS (Client is ok with it)parallely, but any help related to DFSORT would be appriciated.

Quote:
Passing back RC=4 or RC=8 with DFSORT is not straightforward. Passing back RC=0 or RC=4 would be.


I am ok with these RC (i.e. 0 and 4)
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Apr 12, 2012 1:51 pm
Reply with quote

Rohit Umarjikar wrote:
[...]

I am ok with these RC (i.e. 0 and 4)


Funny. I thought I asked about that yesterday. Maybe I was misunderstood.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Apr 12, 2012 2:38 pm
Reply with quote

Here's the cobble requested:

Since there are only a total of three input records, and their order can be guaranteed if you get the concatenation correct, this uses two GROUPs to pass data from one record to another and then calculate on that another record.

If you bust your warning percentage, no record is written to file F1 OUTFIL, and the NULLOFL=RC4 gets you your 4. If not busted, a record of inconsequential content is written and you get the 0 because there is data on the file.

Don't gouge yourself on the nails. An expert cobbler could make a better job of it, I'm sure.

Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOFF1 DD DUMMY this is to get the RC0/RC4, but content is not relevant
//SORTIN   DD your amout used dataset
//         DD your maximum amount dataset
//         DD your warning percentage dataset
//SORTOUT  DD your calculated percentage output dataset
//SYSIN    DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,RECORDS=3,PUSH=(21:1,2,SEQ=1)),
        IFTHEN=(WHEN=(23,1,CH,EQ,C'2'),
               OVERLAY=(5:21,2,ZD,MUL,+100,
                                  DIV,1,2,ZD,
                                  TO=ZD,LENGTH=2))
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(23,1,CH,EQ,C'2'),PUSH=(30:5,2)),
         IFTHEN=(WHEN=(23,1,CH,EQ,C'3',
                  AND,30,2,CH,GT,1,2,CH),
               OVERLAY=(5:C'X'))
  OUTFIL INCLUDE=(23,1,CH,EQ,C'2'),BUILD=(5,2,80:X)
  OUTFIL FILES=F1,INCLUDE=(5,1,CH,NE,C'X',
                      AND,23,1,CH,EQ,C'3'),BUILD=(1,80),
                      NULLOFL=RC4
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Apr 12, 2012 4:53 pm
Reply with quote

Thanks Bill,
I would try this one.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Apr 12, 2012 9:43 pm
Reply with quote

Rohit Umarjikar,

The condition to set the RC is
Code:

IF (file1 value + file2 value ) = File3 Value
    SET RC=0
ELSE
    SET RC=4
END-IF


Use the following DFSORT JCL which will give you the desired results. Just concatenate file1 and file2 and treat it as single file and sum the values.
Code:

//STEP0100 EXEC PGM=SORT                         
//SYSOUT   DD SYSOUT=*                           
//INA      DD DSN=Your input Lrecl 20 File1,DISP=SHR                 
//         DD DSN=Your input Lrecl 20 File2,DISP=SHR
//*           
//INB      DD Your input Lrecl 20 File3,DISP=SHR
//SORTOUT  DD SYSOUT=*                           
//SYSIN    DD *                                 
  JOINKEYS F1=INA,FIELDS=(21,1,A)               
  JOINKEYS F2=INB,FIELDS=(21,1,A),SORTED,NOSEQCK
  REFORMAT FIELDS=(F1:1,3,F2:1,3)               
  INCLUDE COND=(1,3,ZD,EQ,4,3,ZD)               
  OPTION COPY,NULLOUT=RC4       
//*               
//JNF1CNTL DD *                                 
  INREC BUILD=(C'0',1,2,21:C'1')                 
  SUM FIELDS=(1,3,ZD)                           
//*                                             
//JNF2CNTL DD *                                 
  OPTION STOPAFT=1                               
  INREC BUILD=(C'0',1,2,21:C'1')                 
//*
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Apr 13, 2012 7:19 pm
Reply with quote

Kolusu,

Thanks for the update.

But I don't see the % is getting calculated based on the file1 and file 2. I actually would like to get % done by the use of file1 and file2 record and then check that % value with % value present in the file3.

Hope I am keeping my words same.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 13, 2012 7:48 pm
Reply with quote

and the posts go on and on and on and on...
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Apr 13, 2012 8:02 pm
Reply with quote

Sometimes....icon_smile.gif
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Apr 13, 2012 8:44 pm
Reply with quote

Rohit Umarjikar wrote:
Kolusu,

Thanks for the update.

But I don't see the % is getting calculated based on the file1 and file 2. I actually would like to get % done by the use of file1 and file2 record and then check that % value with % value present in the file3.

Hope I am keeping my words same.


Ok My mistake about not calculating the % but how did you arrive at the percentage?

5 = (20 * X)/100 and now I need to calculate the X?

in the above case X would result in 25.

What happens if File1 value is greater than file 2 value? or it exceeds 100?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Mon Apr 16, 2012 7:50 pm
Reply with quote

Quote:
Ok My mistake about not calculating the % but how did you arrive at the percentage?

5 = (20 * X)/100 and now I need to calculate the X?

in the above case X would result in 25.

What happens if File1 value is greater than file 2 value? or it exceeds 100?


Yes, you are right the 25 value should be the %.
And file1 value will be at max equals to file 2 value so it will be max of 100%.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Mon Apr 16, 2012 9:50 pm
Reply with quote

Rohit Umarjikar wrote:
Yes, you are right the 25 value should be the %.
And file1 value will be at max equals to file 2 value so it will be max of 100%.


Rohit Umarjikar,

You only show 2 digit values and when you calculate the percentage it might result in 3 digits (100%) and you want to compare this to a 2 digit number. Is the data just 2 bytes? or 3 bytes? There are no checks to see if the numbers you pass are valid numbers. what happens if the input has negative numbers or spaces or zeroes?

Assuming that each of the input file has just 1 record and the first 2 bytes have the data,
here is a job which would set the return code to 4 if the calculated percentage is NOT equal to the percentage value in file 3.


Code:

//STEP0100 EXEC PGM=SORT                                     
//SYSOUT   DD SYSOUT=* 
//INA      DD DSN=Your input Lrecl 20 File1,DISP=SHR                 
//         DD DSN=Your input Lrecl 20 File2,DISP=SHR
//*           
//INB      DD Your input Lrecl 20 File3,DISP=SHR
//SORTOUT  DD SYSOUT=*                                       
//SYSIN    DD *                                             
  OPTION COPY                                               
  JOINKEYS F1=INA,FIELDS=(21,1,A),SORTED,NOSEQCK             
  JOINKEYS F2=INB,FIELDS=(21,1,A),SORTED,NOSEQCK             
  REFORMAT FIELDS=(F1:1,8,F2:1,3)               
             
  INREC OVERLAY=(15:(5,3,ZD,MUL,+100),DIV,1,3,ZD,EDIT=(TTT))
  OUTFIL NULLOFL=RC4,INCLUDE=(9,3,ZD,EQ,15,3,ZD)             
//*                                                         
//JNF1CNTL DD *                                             
  OPTION STOPAFT=2                                           
  INREC IFTHEN=(WHEN=INIT,BUILD=(C'0',1,2,21:SEQNUM,1,ZD)), 
  IFTHEN=(WHEN=GROUP,RECORDS=3,PUSH=(5:1,3))                 
//*                                                         
//JNF2CNTL DD *                                             
  OPTION STOPAFT=1                                           
  INREC BUILD=(C'0',1,2,21:C'2')                             
//* 
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Tue Apr 17, 2012 7:05 pm
Reply with quote

Thanks Skolusu...
Great help
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 Arithmetic division using Syncsort SYNCSORT 6
No new posts Help this REXX Rookie-Bad arithmetic ... CLIST & REXX 7
No new posts An write operation error - ABENDED S0... COBOL Programming 3
No new posts Bad arithmetic conversion when assign... CLIST & REXX 4
No new posts HEADER1 with Date arithmetic DFSORT/ICETOOL 4
Search our Forums:

Back to Top