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

COBOL - Logic to check multiple values


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

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Dec 03, 2009 2:41 am
Reply with quote

Hi all,

I have 2 flat files and should write the data to third flat file on matching criteria. I am loading the similar Account number data located in the second flat file to a COBOL internal table and comparing it with first file contents (using loop).

Code:
PERFORM VARYING I FROM 1 BY 1 UNTIL WS-FLAG = 'Y' OR I > 50     
  IF ACCT-ID-1   = WS-ACCT-ID-2(I)   AND
      ITEM-CD-1   = WS-ITM-CD-2(I)   AND
      SYS-EFFDT   > WS-SYS-EFFDT(I)   AND           
      SYS-EXPDT  < WS-SYS-EXPDT(I)
      MOVE WS-GROUP-CODE-2(I) TO GROUP-CD-1
      MOVE 'Y' TO WS-FLAG
 END-IF                                             
END-PERFORM 


Assume that the Item code value of first file (ITEM-CD-1) is having value 5. So for this match to happen, the Item code value of second file ie., WS-ITM-ID-2 should have value '5'.

My requirement here is that, if the ITEM-CD-1 = '5'', then if the Item code of second file WS-ITM-CD-2(I) contains '5' or '10', then also the match should happen.
Can anyone please help me in having the logic for this requirement.

Thanks
Vinu
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Dec 03, 2009 3:53 am
Reply with quote

Vinu,

you code looks super to me. What problem are you having?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Dec 03, 2009 4:06 am
Reply with quote

Is your condition only true for '5' or is there more you haven't told us yet? For example, if ITEM-CD-1 = '6' then it matches WS-ITM-CD-2 (I) only if WS-ITM-CD-2 (I) is '6' as well. Are there any other valid matches?

As your problem was stated, you could simply add another clause to your IF test as the line immediately after the line starting IF:
Code:
(ITEM-CD-1 = '5' AND (WS-ITM-CD-2 (I) = '5' OR '10')) AND
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Dec 03, 2009 4:34 am
Reply with quote

Hi Dick and Robert,

Thanks for the response.
The ITEM-CD-1 can have any values but, if it has the value 5, and if WS-ITM-CD-2 has values 5 or 10, then match should happen.

Similarly if the ITEM-CD-1 has value '10', and if WS-ITM-CD-2 has values 5 or 10, then match should happen.

I am getting stuck how to implement this in my existing IF loop.

Note: I am getting ITEM-CD-1 from flat file and WS-ITEM-CD-2 is already loaded to COBOL internal table.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Dec 03, 2009 4:43 am
Reply with quote

You're not addressing the question I asked: is the match condition only for the value '5' (and '10', apparently), or is it a general condition? If it is a general condition, what are the specific rules for matching (e.g., would '6' match '6' or '12')?
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Dec 03, 2009 9:50 pm
Reply with quote

Hi Robert,

Sorry about that.
This is only a specific matching condition when '5' or '10' comes.
When other values comes, it should match with the respective values.

Eg:
The match should happen when the following value comes

Code:
ITEM-CD-1      WS-ITM-CD-2
5                    5 or 10
10                    5 or 10
6                    6
7                    7
8                    8 
1                    1
Anyvalue         corresponding value

Thanks
Vinu
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Dec 03, 2009 10:03 pm
Reply with quote

Code:
PERFORM VARYING I FROM 1 BY 1 UNTIL WS-FLAG = 'Y' OR I > 50     
  IF  ACCT-ID-1   = WS-ACCT-ID-2(I)   AND
       ITEM-CD-1   = WS-ITM-CD-2(I)   AND
      ((ITEM-CD-1 = '5' OR '10') AND (WS-ITM-CD-2 (I) = '5' OR '10')) AND
      SYS-EFFDT   > WS-SYS-EFFDT(I)   AND           
      SYS-EXPDT  < WS-SYS-EXPDT(I)
      MOVE WS-GROUP-CODE-2(I) TO GROUP-CD-1
      MOVE 'Y' TO WS-FLAG
 END-IF                                             
END-PERFORM 
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Dec 03, 2009 10:11 pm
Reply with quote

Hi Robert,

Thanks for the code. A small clarification.

For each record, the ITEM-CD-1 will have either 5, 10 or any other value.
The exception conditon is only if 5 or 10 comes.

As per your code, if any other value (like 2,3,6,7,8 etc..) comes for ITEM-CD-1, the match won't happen since the code expects ITEM-CD-1 to have either 5 or 10.

Exception condition:
If 5 or 10 comes in ITM-CD-1, and WS-ITM-CD-2 has 5 or 10, match should happen

Normal condition: - If any value comes in ITEM-CD-1, and WS-ITM-CD-2 has corresponding same value, match should happen else match should not happen.

Thanks
Vinu
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Dec 03, 2009 10:11 pm
Reply with quote

Code:

        (
         ITEM-CD-1   = WS-ITM-CD-2(I)   OR
      ((ITEM-CD-1 = '5' OR '10') AND (WS-ITM-CD-2 (I) = '5' OR '10'))
         ) AND


??
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Dec 04, 2009 10:40 pm
Reply with quote

Thanks Dick and Robert,

The code is working when I put the OR condition as stated in Dick's reply.
I had implemented this in the logic stated by Robert.

Thanks
Vinu
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 COBOL 6.4 - User Defined Function nee... COBOL Programming 6
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top