View previous topic :: View next topic
|
Author |
Message |
shivakr
New User
Joined: 09 Jan 2006 Posts: 8
|
|
|
|
Hi all ,
Can any onw tell me the efficient cobol coding for comparing two transaction files with one master file .
Siva . |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Hi shivakr,
What is the purpose of the compare? What do you want to do if you find the transaction key on the master, what if there is no transaction for a master, and what if there is no master for the transaction?
Can the two transaction files be combined into a single combined transaction file?
Here is some simple compare pseudo logic making these assumptions. 1 ? the two transaction files have been combined into a single sorted transaction file the same as the master file, ascending 2 ? nothing will be done if there is no transaction for a master, 3 ? the master will be updated with the transaction data if the keys are equal. 4 ? There can be more than one transaction for each master 5 ? error reporting if there is no master file for the transaction.
Code: |
INITIALIZATION.
PERFORM READ-TRANSACTION-FILE.
PERFORM READ-MASTER-FILE.
PERFORM COMPARE THRU COMPARE-EXIT
UNTIL TRANSACTION-FILE-EOF.
PERFORM END-OF-JOB.
GOBACK.
COMPARE.
IF TRANSACTION-KEY = MASTER-KEY
THEN
PERFORM MASTER-RECORD-UPDATE
PERFORM READ-TRANSACTION-FILE
ELSE
IF TRANSACTION-KEY < MASTER-KEY
THEN
PERFORM TRANSACTION-ERROR-REPORTING
PERFORM READ-TRANSACTION-FILE
ELSE
PERFORM READ-MASTER-FILE
END-IF.
COMPARE-EXIT.
EXIT.
|
Hope this helps |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Siva,
I'll assume you want to do something when the keys of the 3 files are equal. I won't write the code for you - takes too much of my time (and why should I have all the fun? ), but I will give you some insights.
Sort all 3 files on the same key.
Then, in your COBOL pgm, do a first read on all 3 files. Then in a loop to EOF on all 3 files you:
determine the hi-key.
test each file's key against that
when less than, read a rec for that file
when greater than or equal, do nothing
also test if all 3 keys are equal (not sure where this goes)
if equal do your thing then read all 3 files
Well, that's the basis of it, but as they say, the devil's in the details.
You're best doing READ INTO and setting the key to hi-vals at EOF for each file and don't forget to by-pass the read if the file is already at EOF.
The logic I provided should make this unneccessary, but if you have to change it, keep the point in mind.
HTH |
|
Back to top |
|
|
shivakr
New User
Joined: 09 Jan 2006 Posts: 8
|
|
|
|
Thanx all , I got it .
Siva |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Siva,
What did you get? Tellus how you solved the prob. Share your code w/others here as they have shared w/you. |
|
Back to top |
|
|
shivakr
New User
Joined: 09 Jan 2006 Posts: 8
|
|
|
|
Hi MMwife ,
My program has to read three ADABAS files and to create three output files for next days trade calculation , i was sure about comparing two sorted files and creating one out file after editing . PSB the code for the same.
034300 MAIN-020.
034400 PERFORM S300-FD.
034500 IF END-FLG2 = 'E'
034600 MOVE SPACE TO END-FLG2
034700 GO TO MAIN-030
034800 ELSE
034900 GO TO MAIN-020.
035000*
035100 MAIN-030.
035200 PERFORM S400-LK.
035300 PERFORM S410-SR.
035400 PERFORM S500-LK.
035500 PERFORM S510-SR.
035600 PERFORM S800-LK. T2KS0010
035700 PERFORM S810-SR. T2KS0010
035800*
035900 MAIN-040.
036000 IF KEY-1 NOT = KEY-2
036100 GO TO MAIN-050.
036200 IF KEY-2 NOT = KEY-3 T2KS0010
036300 GO TO MAIN-045. T2KS0010
036400 IF KEY-1 = HIGH-VALUE
036500 GO TO MAIN-010.
036600*** PERFORM S520-EDIT. T2KS0010
036700 MOVE ADA-DATA4 TO WK-DATA. T2KS0010
036800 MOVE '1' TO IX110-CH. T2KS0010
036900 MOVE WK-DATA TO ADA-DATA4. T2KS0010
037000 PERFORM S820-EDIT. T2KS0010
037100 PERFORM S510-SR.
037200 PERFORM S410-SR.
037300 PERFORM S810-SR. T2KS0010
037400 GO TO MAIN-040.
037500 MAIN-045. T2KS0010
037600 IF KEY-2 < KEY-3 T2KS0010
037700 GO TO MAIN-047. T2KS0010
037800 PERFORM S820-EDIT. T2KS0010
037900 PERFORM S810-SR. T2KS0010
038000 GO TO MAIN-040. T2KS0010
038100 MAIN-047. T2KS0010
038200 PERFORM S520-EDIT. T2KS0010
038300 PERFORM S510-SR. T2KS0010
038400 PERFORM S410-SR. T2KS0010
038500 GO TO MAIN-040. T2KS0010
038600*
038700 MAIN-050.
038800 IF KEY-1 < KEY-2
038900 GO TO MAIN-060.
039000 IF KEY-2 > KEY-3 T2KS0010
039100 GO TO MAIN-055. T2KS0010
039200 PERFORM S520-EDIT.
039300 PERFORM S510-SR.
039400 GO TO MAIN-040.
039500 MAIN-055. T2KS0010
039600 PERFORM S820-EDIT. T2KS0010
039700 PERFORM S810-SR. T2KS0010
039800 GO TO MAIN-040. T2KS0010
039900 MAIN-060.
040000 IF KEY-1 NOT = KEY-3 T2KS0010
040100 GO TO MAIN-065. T2KS0010
040200 MOVE ADA-DATA4 TO WK-DATA. T2KS0010
040300 IF IX110-CH = SPACE T2KS0010
040400 PERFORM S820-EDIT T2KS0010
040500 END-IF. T2KS0010
040600 PERFORM S410-SR. T2KS0010
040700 PERFORM S810-SR. T2KS0010
040800 GO TO MAIN-040. T2KS0010
040900 MAIN-065. T2KS0010
041000 IF KEY-1 > KEY-3 T2KS0010
041100 GO TO MAIN-067. T2KS0010
041200 PERFORM S420-EDIT.
041300 PERFORM S410-SR.
041400 GO TO MAIN-040.
041500 MAIN-067. T2KS0010
041600 PERFORM S820-EDIT. T2KS0010
041700 PERFORM S810-SR. T2KS0010
041800 GO TO MAIN-040. T2KS0010
041900 MAIN-070.
042000 PERFORM S600-END.
042100 STOP RUN. |
|
Back to top |
|
|
Bitneuker
CICS Moderator
Joined: 07 Nov 2005 Posts: 1104 Location: The Netherlands at Hole 19
|
|
|
|
Here a solution which is a standard in our country. It's without goto's and the only comparison for < is to determine the smaller key. We're used to call it BALANCE_LINE. I used some pseudo-code just as an example
01 MASTER_STAMP
03 MASTER_EOF INIT('0')
03 MASTER_KEY
01 TRAN1_STAMP
03 TRAN1_EOF INIT('0')
03 TRAN1_KEY
01 TRAN2_STAMP
03 TRAN2_EOF INIT('0')
03 TRAN2_KEY
01 SMALLEST_STAMP
03 SMALL_EOF INIT('0')
03 SMALL_KEY
MASTER:
READ MASTERFILE AND FILL MASTER_KEY, ENDFILE -> MASTER_EOF = '1'
TRAN1
READ TRAN1FILE AND FILL TRAN1_KEY, ENDFILE -> TRAN1_EOF = '1'
TRAN2
READ TRAN2FILE AND FILL TRAN2_KEY, ENDFILE -> TRAN2_EOF = '1'
SMALLEST
SMALLEST_STAMP = MASTER_STAMP.
IF TRAN1_STAMP < SMALLEST_STAMP OVERWRITE WITH TRAN1_STAMP.
IF TRAN2_STAMP < SMALLEST_STAMP OVERWRITE WITH TRAN2_STAMP.
PROCESS UNTIL SMALLEST_EOF
IF SMALLEST_STAMP = MASTER_STAMP PROCESS MASTER IN OUTAREA, READ NEXT MASTER AND FILL MASTER_STAMP.
IF SMALLEST_STAMP = TRAN1_STAMP PROCESS TRAN1 IN OUTAREA, READ NEXT TRAN1 AND FILL TRAN1_STAMP.
IF SMALLEST_STAMP = TRAN2_STAMP PROCESS TRAN2 IN OUTAREA, READ NEXT TRAN2 AND FILL TRAN2_STAMP.
PROCESS OUTAREA BY WRITING TO NEW MASTER.
DETERMINE SMALLEST
END_UNTIL |
|
Back to top |
|
|
|