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

logic required for file read and sum on amount filed?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Tue Jan 19, 2010 6:23 pm
Reply with quote

I have a input file and it is having 4 fields (Branch,User,Amount and Bin).Each branch may have different users and bins.My requirement is calculate the sum of the amount of each bramch,user,bin fields.please provide me the logic.

Input file Data :-

Branch User Amount Bin
B1 U1 200 1
B1 U2 100 1
B1 U3 300 1
B2 U1 200 2
B2 U2 100 2
B2 U3 300 2
B3 U1 200 3
B3 U2 200 3
B3 U3 200 3
B4 U1 100 1
B4 U2 100 1
B4 U3 100 1
B5 U1 200 2
B5 U2 200 2
B5 U3 200 2
B1 U1 200 1
B1 U2 100 1
B1 U3 300 1
B2 U1 200 2
B2 U2 100 2
B2 U3 300 2
B3 U1 200 3
B3 U2 200 3
B3 U3 200 3
B4 U1 100 1
B4 U2 100 1
B4 U3 100 1
B5 U1 200 2
B5 U2 200 2
B5 U3 200 2
B1 U1 200 1
B1 U2 100 1
B1 U3 300 1
B2 U1 200 2
B2 U2 100 2
B2 U3 300 2
B3 U1 200 3
B3 U2 200 3
B3 U3 200 3
B4 U1 100 1
B4 U2 100 1
B4 U3 100 1
B5 U1 200 2
B5 U2 200 2
B5 U3 200 2


Output file should be like this,Here amount is sum of each branch,user and Bin fields.

Branch User Amount Bin
B1 U1 600 1
B1 U2 300 1
B1 U3 900 1
B2 U1 600 2
B2 U2 300 2
B2 U3 900 2
B3 U1 600 3
B3 U2 600 3
B3 U3 600 3
B4 U1 300 1
B4 U2 300 1
B4 U3 300 1
B5 U1 600 2
B5 U2 600 2
B5 U3 600 2
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Jan 19, 2010 6:35 pm
Reply with quote

this is a help forum, not a do it for me ( You should know better after 80 posts)
show what You have done, and from there on You might get some help
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jan 19, 2010 6:35 pm
Reply with quote

This is a HELP forum, not a DO-YOUR-JOB-FOR-YOU forum. Most of the people who respond are paid for their professional work product (such as program code). If you're willing to pay their rate (which can exceed 1000 USD per day or fraction thereof), I'm sure you will get your code quickly. Otherwise, you need to write the code, not us.

What have you tried so far and what is not working for you?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Jan 19, 2010 6:50 pm
Reply with quote

Hi Robert!
we just experienced a forum collision icon_biggrin.gif we posted at the same time,
looking at the topic my post comes first but from the forum index I am the last poster

in a real time stock exchange application it might cause panic all over

too bad that this post will destroy the proof
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jan 19, 2010 6:59 pm
Reply with quote

LOL enrico -- these things happen. As long as no bruising is involved, I'm okay with it. ;)
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: Tue Jan 19, 2010 9:25 pm
Reply with quote

Hello,

Quote:
Output file should be like this,Here amount is sum of each branch,user and Bin fields.
So, what have you done so far?

Why would you believe it appropriate to ask the forum to provide code/logic for something that is less complex than a student exercise?

Possibly this is a class assignment. . .

Possibly, you would be better served in the student/fresher forum:
ibmmainframeforum.com/
Back to top
View user's profile Send private message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Wed Jan 20, 2010 7:08 pm
Reply with quote

Hi all,

i am reading input file(sorted order file) and move the the first record into working storage variables and comapre this first record with second read record,if match with the previous record then sum the amount field,if not match write the working storage field in to output file.

but i am facing problem with working storage variables are not keep the previoiu record.

PERFORM UNTIL END-OF-FILE
READ GAD-DETAIL-TRAN-FILE INTO WS-GAD-FILE-RECORD

EVALUATE TRUE

WHEN FILE-IN-STATUS EQUAL TO ZEROS
MOVE SSTACB TO WS-SSTACB
MOVE SSCPWS TO WS-SSCPWS
MOVE SSBIN TO WS-SSBIN
ADD 1 TO WS-DETL-MATCH-CNT
IF SSTACB = WS-SSTACB
AND SSCPWS =WS-SSCPWS
AND SSCPWS =WS-SSCPWS
MOVE SSCAM1 TO WS-SSCAM1
MOVE SSCHAM TO WS-SSCHAM
COMPUTE WS-AMT = WS-SSCAM1 + WS-SSCHAM
ELSE
PERFORM 2070-WRITE-RDC-BC-CONSOL-FILE
END-IF

please correct my code?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jan 20, 2010 7:25 pm
Reply with quote

You need to learn to use BBcode. If you have a record, and the hold fields in working storage match the fields you just read, accumulate. Otherwise, you need to output the record, THEN update the working storage fields from the record with the new data. You need an amount accumulator for branch and another for user -- you only have one so far, so you're short. And you're not resetting it each time you find a new branch or user. Note: this is not tested code, it is merely a rewrite of what you've posted so far.

Code:
PERFORM UNTIL END-OF-FILE
READ GAD-DETAIL-TRAN-FILE INTO WS-GAD-FILE-RECORD

IF  FILE-IN-STATUS EQUAL TO ZEROS
    IF  SSTACB = WS-SSTACB
    AND SSCPWS =WS-SSCPWS
        MOVE SSCAM1 TO WS-SSCAM1
        MOVE SSCHAM TO WS-SSCHAM
        COMPUTE WS-AMT = WS-SSCAM1 + WS-SSCHAM
    ELSE
        PERFORM 2070-WRITE-RDC-BC-CONSOL-FILE
        MOVE SSTACB TO WS-SSTACB
        MOVE SSCPWS TO WS-SSCPWS
        MOVE SSBIN TO WS-SSBIN
        ADD 1 TO WS-DETL-MATCH-CNT
    END-IF
END-IF
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 8
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top