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
 

 

Cobol match logic

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
venkatatcts

New User


Joined: 16 Mar 2009
Posts: 55
Location: India

PostPosted: Thu Jul 22, 2010 2:02 am    Post subject: Cobol match logic
Reply with quote

Hi,

Below are the two files. The key for both files are first seven digit and 3 digit field.

file 1 will have single occurence of the key where as the file 2 will multiple occurence. I need to compare the key first if it matches then i need to compare the third col between the files and if also matches then i need to move the four col from file1 to third column in file2.

Since it is a multi occurence.

I have used this logic ( both the files are in sorted order)

if no match found

perform read file 2 until key2 <= key1 and end of file = 'n'

peform update.

UPDATE.

READ READ FILE 1

EXIT.



INS LINE TRIGGER FILE

Code:
AZDGHFG XDR 100 200
AZDGHFT XDR 100 500
BGDXDRY XDR 100 600
GYTRTUV XDR 100 700


CEDED CLAIM CHAR UNLOAD FILE

Code:
AAAAAAA XDR 100
ABSSSSS XDR 100
AV11111 XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFT XDR 100
AZDGHFT XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
GYTRTUV XDR 100
GYTRTUV XDR 100


I guess below logic will update only single occurrence.

first method:

Code:
IF KEY2 = KEY 1
THEN
   READ FILE1
   READ FILE2
ELSE
  IF KEY2 < KEY 1
     READ FILE2
  ELSE
     READ FILE1
  END-IF
END-IF

second method:

Code:
IF KEY1 = KEY 2
THEN
   READ FILE1
   READ FILE2
ELSE
  IF KEY1 < KEY 2
     READ FILE1
  ELSE
     READ FILE2
  END-IF
END-IF
Back to top
View user's profile Send private message

dick scherrer

Site Director


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

PostPosted: Thu Jul 22, 2010 2:12 am    Post subject:
Reply with quote

Hello,

There is tested sample code to accomplish a 2-file match/merge posted as a "Sticky" at the top of the COBOL part of the forum.

Download this to your pc and then upload to your source library (use Right-Click, Save. . .).

Change this for your records/keys and implement the logic you need beyond the match/merge.
Back to top
View user's profile Send private message
venkatatcts

New User


Joined: 16 Mar 2009
Posts: 55
Location: India

PostPosted: Thu Jul 22, 2010 2:16 am    Post subject: Reply to: cobol match logic
Reply with quote

Hi,

Thanks. But I need to write for all the matching records whereas that logic will match single occurence and then it will read the other records of the next file which should not be. that's why i gave all the three logic and whether first one is correct or the second or the third.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Jul 22, 2010 2:32 am    Post subject:
Reply with quote

Hello,

The sample will properly handle a one-to-many match/merge. . .

Suggest you post the output you want from those 2 sets of input.

Your posts will be more effective when you use the "Code" tag. . .
Back to top
View user's profile Send private message
venkatatcts

New User


Joined: 16 Mar 2009
Posts: 55
Location: India

PostPosted: Thu Jul 22, 2010 2:35 am    Post subject: Reply to: cobol match logic
Reply with quote

Code:
INS LINE TRIGGER FILE

AZDGHFG XDR 100 200
AZDGHFT XDR 100 500
BGDXDRY XDR 100 600
GYTRTUV XDR 100 700

CEDED CLAIM CHAR UNLOAD FILE
AAAAAAA XDR 100
ABSSSSS XDR 100
AV11111 XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFT XDR 100
AZDGHFT XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
GYTRTUV XDR 100
GYTRTUV XDR 100

above two are my input files.

output files:

AAAAAAA XDR 100
ABSSSSS XDR 100
AV11111 XDR 100
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFT XDR 500
AZDGHFT XDR 500
BGDXDRY XDR 100
BGDXDRY XDR 600
BGDXDRY XDR 600
GYTRTUV XDR 700
GYTRTUV XDR 700


Code:
[img][/img]
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Jul 22, 2010 2:47 am    Post subject:
Reply with quote

Hello,

Suggest you look at this bit of the sample code:
Code:
       100-CAP-ELIG-MATCH.
      * these may change depending on how duplicates are handled.
      *    MOVE 'Y' TO NEED-CAP, NEED-ELG.
           MOVE 'Y' TO NEED-ELG.


If you change the code to only read the file with duplicates rather than automatically reading both files, it should do what you want. . . - once your custom code is added.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Jul 22, 2010 4:05 am    Post subject: Re: Reply to: cobol match logic
Reply with quote

venkatatcts wrote:
that's why i gave all the three logic and whether first one is correct or the second or the third.
What 'third'?

Hasn't anybody taught you how to design such a program?

Start with the middle where both files are in the middle of processing, do compares and process.
Then figure how to get the initial states set with opens and initial reads.
Then figure how to handle end-of-files from either and finish the writes and close.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Jul 22, 2010 6:16 am    Post subject: Reply to: cobol match logic
Reply with quote

Hi Bill,

The "third" is actually first and is sort of pseudo-code and text and i didn't "Code" it. . .

The reason i posted that Sticky so long ago is that many new people are not being shown this most basic process during training. . . icon_sad.gif

d
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


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