Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Subtract two amounts though in input they appear as positive

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
ayushT

New User


Joined: 01 Oct 2007
Posts: 23
Location: india

PostPosted: Sat Sep 27, 2008 3:23 am    Post subject: Subtract two amounts though in input they appear as positive
Reply with quote

Input

KEY AMOUNT1 AMOUNT2 SUBKEY
----------------------------------------
ABC 100.00 200.00 BEFORE
BCD 100.00 200.00 BEFORE
ABC 100.00 200.00 AFTER
DEF 100.00 200.00 AFTER

The amounts are displayed with a decimal point

Output

KEY AMOUNT1 AMOUNT2 SUBKEY
----------------------------------------
ABC 0.00 200.00
BCD 100.00 200.00 BEFORE
DEF 100.00 200.00 AFTER



Two records exist (Subkey = BEFORE & AFTER). The AFTER amountS are subtracted from BEFORE amountS.

Conditions to be written out to output with the computed amount -

1. If it equals out to zero, SUBKEY in output will be blank
2. If Before amounts > AFTER amounts , SUBKEY in output will be BEFORE
3. If Before amounts < AFTER amounts , SUBKEY in output will be AFTER

Could you help me on this?




If I have two records(subkey = BEFORE & AFTER) with the same KEY=ABC, then I need to do as shown below
Back to top
View user's profile Send private message

Frank Yaeger

DFSORT Moderator


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

PostPosted: Sat Sep 27, 2008 3:54 am    Post subject:
Reply with quote

It's not clear what you want to do. You say "The AFTER amountS are subtracted from BEFORE amountS". But for your two ABC records, the BEFORE and AFTER values for both fields are the same, but you show 0.00 (subtract) for the first field and 200.00 (no subtract) for the second field. Why?

Also you say "If Before amounts > AFTER amounts , SUBKEY in output will be BEFORE'. I have no idea what you mean by this. What are the "Before amounts"? What are the "AFTER amounts"?

You need to show a better example of input and expected output records with all of the possible variations, and explain clearly the "rules" for getting from input to output.

Also, give the RECFM and LRECL of the your input file, and the starting position and length of each input field.
Back to top
View user's profile Send private message
ayushT

New User


Joined: 01 Oct 2007
Posts: 23
Location: india

PostPosted: Tue Sep 30, 2008 2:29 am    Post subject:
Reply with quote

Input file is FB with LRECL=30.

The fields in the input file are

KEY X (4)
AMOUNT1 X(6)
Filler X (1)
AMOUNT2 X(6)
Filler X(1)
INDICATOR X(6)
FILLER X(6)

Sample input file

AAA 50.00 50.00 BEFORE
AXE 50.00 50.00 BEFORE
SAM 100.00 200.00 BEFORE
RAM 100.00 200.00 BEFORE
AXE 100.00 200.00 AFTER
BBB 100.00 200.00 AFTER
SAM 100.00 200.00 AFTER
RAM 50.00 50.00 AFTER


1.
Key='AXE' has two input records. One record has indicator BEFORE and the 2nd one has indicator AFTER. AMOUNT1 of indicator AFTER is subtracted from AMOUNT1 of indicator BEFORE.Since AMOUNT1 of indicator AFTER is greater than AMOUNT1 of indicator BEFORE, Indicator AFTER and AMOUNT2 of indicator AFTER are copied to output.

2.
Key='SAM' has two input records. One record has indicator BEFORE and the 2nd one has indicator AFTER. AMOUNT1 of indicator AFTER is subtracted from AMOUNT1 of indicator BEFORE.Since AMOUNT1 of indicator AFTER is equal to AMOUNT1 of indicator BEFORE, Indicator AFTER and AMOUNT2 of indicator BEFORE are copied to output.

3.
Key='RAM' has two input records. One record has indicator BEFORE and the 2nd one has indicator AFTER. AMOUNT1 of indicator AFTER is subtracted from AMOUNT1 of indicator BEFORE.Since AMOUNT1 of indicator AFTER is less than AMOUNT1 of indicator BEFORE, Indicator BEFORE and AMOUNT2 of indicator BEFORE are copied to output.

4.
If you see, Key='AAA' has one input record with indicator BEFORE.This record is copied to output as it is.

5.
If you see, Key='BBB' has one input record with indicator AFTER.This record is copied to output as it is.

This is how my output file will look like
Output file (sorted in ascending order of KEY)
AAA 50.00 50.00 BEFORE
AXE 50.00 200.00 AFTER
BBB 100.00 200.00 AFTER
RAM 50.00 200.00 BEFORE
SAM 0.00 200.00 BEFORE


Note : Amount1 Amount2 are in decimal format. I guess AMOUNT1 needs to be converted to ZD using SFF before subtraction could be applied.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Tue Sep 30, 2008 3:16 am    Post subject:
Reply with quote

I'm still trying to make sense of this and work out coding rules.

It appears that in the cases where you have a BEFORE and AFTER pair, you want the AMOUNT1 output value to be the absolute value of (AFTER AMOUNT1- BEFORE AMOUNT1) like this:

AXE -> 100.00 - 50.00 = 50.00
SAM -> 100.00 - 100.00 = 0.00
RAM -> 50.00 - 100.00 = -50.00 -> 50.00

Is that correct?

The other rules for each BEFORE and AFTER pair appear to be:

If AFTER AMOUNT1 > BEFORE AMOUNT1, use AFTER AMOUNT2 and AFTER indicator.

If AFTER AMOUNT1 < BEFORE AMOUNT1, use BEFORE AMOUNT2 and BEFORE indicator.

Is that correct?

If AFTER AMOUNT1 = BEFORE AMOUNT1, use BEFORE AMOUNT2 and AFTER indicator. I question this one, though. To be consistent, wouldn't you want the AFTER AMOUNT2?. For example, if you had:

QQQ 50.00 100.00 BEFORE
QQQ 50.00 200.00 AFTER

what would you expect for output?
Back to top
View user's profile Send private message
ayushT

New User


Joined: 01 Oct 2007
Posts: 23
Location: india

PostPosted: Tue Sep 30, 2008 10:04 pm    Post subject:
Reply with quote

the example

QQQ 50.00 100.00 BEFORE
QQQ 50.00 200.00 AFTER

Output would be

QQQ 0.00 100.00 BEFORE

The purpose of indicators in the o/p is to tell one which record has the greater AMOUNT1 (the record with indicator BEFORE or the record with indicator AFTER)

So in the case where AFTER AMOUNT1=BEFORE AMOUNT1 , there is no hard and fast rule that in the output the indicator should be BEFORE.
Back to top
View user's profile Send private message
ayushT

New User


Joined: 01 Oct 2007
Posts: 23
Location: india

PostPosted: Tue Sep 30, 2008 10:07 pm    Post subject:
Reply with quote

case where AFTER AMOUNT1=BEFORE AMOUNT1 , there is no hard and fast rule that in the output the indicator should be BEFORE and amount2 should be BEFORE AMOUNT2.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Wed Oct 01, 2008 2:17 am    Post subject:
Reply with quote

Based on what I think you've said you want, here's a DFSORT job that will do it:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file (FB/30)
//SORTOUT DD DSN=...  output file (FB/30)
//SYSIN    DD    *
  INREC IFTHEN=(WHEN=INIT,
          OVERLAY=(31:C'1',38:6C'0',44:6C'0')),
        IFTHEN=(WHEN=(19,1,CH,EQ,C'B'),
          OVERLAY=(32:5,6,UFF,MUL,-1,TO=ZD,LENGTH=6,
          38:12,6,UFF,TO=ZD,LENGTH=6)),
        IFTHEN=(WHEN=(19,1,CH,EQ,C'A'),
          OVERLAY=(32:5,6,UFF,TO=ZD,LENGTH=6,
          44:12,6,UFF,TO=ZD,LENGTH=6))
  SORT FIELDS=(1,3,CH,A)
  SUM FIELDS=(31,1,ZD,32,6,ZD,38,6,ZD,44,6,ZD)
  OUTREC IFOUTLEN=30,
   IFTHEN=(WHEN=(31,1,ZD,EQ,2,AND,32,6,ZD,GT,0),
     BUILD=(1,4,5:32,6,ZD,EDIT=(IIT.TT),X,
       44,6,ZD,EDIT=(IIT.TT),X,C'AFTER')),
   IFTHEN=(WHEN=(31,1,ZD,EQ,2,AND,32,6,ZD,LE,0),
     BUILD=(1,4,5:32,6,ZD,EDIT=(IIT.TT),X,
       38,6,ZD,EDIT=(IIT.TT),X,C'BEFORE'))
/*


If SORTIN had these records:

Code:

AAA  50.00  50.00 BEFORE       
AXE  50.00  50.00 BEFORE       
SAM 100.00 200.00 BEFORE       
RAM 100.00 200.00 BEFORE       
QQQ  50.00 100.00 BEFORE       
QQQ  50.00 200.00 AFTER       
AXE 100.00 200.00 AFTER       
BBB 100.00 200.00 AFTER       
SAM 100.00 200.00 AFTER       
RAM  50.00  50.00 AFTER       


SORTOUT would have these records:

Code:

AAA  50.00  50.00 BEFORE   
AXE  50.00 200.00 AFTER     
BBB 100.00 200.00 AFTER     
QQQ   0.00 100.00 BEFORE   
RAM  50.00 200.00 BEFORE   
SAM   0.00 200.00 BEFORE   
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Formating the Input file sreekusr DFSORT/ICETOOL 3 Fri Feb 17, 2017 10:40 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 37 Tue Dec 06, 2016 8:04 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 15 Thu Dec 01, 2016 8:28 pm
This topic is locked: you cannot edit posts or make replies. How to use 2 input files in control c... Gunapala CN DFSORT/ICETOOL 23 Thu Oct 13, 2016 3:42 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us