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 - Logic to check multiple values

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

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Thu Dec 03, 2009 2:41 am    Post subject: COBOL - Logic to check multiple values
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: 6967
Location: porcelain throne

PostPosted: Thu Dec 03, 2009 3:53 am    Post subject:
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Thu Dec 03, 2009 4:06 am    Post subject:
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: 151
Location: India

PostPosted: Thu Dec 03, 2009 4:34 am    Post subject:
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Thu Dec 03, 2009 4:43 am    Post subject:
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: 151
Location: India

PostPosted: Thu Dec 03, 2009 9:50 pm    Post subject:
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Thu Dec 03, 2009 10:03 pm    Post subject:
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: 151
Location: India

PostPosted: Thu Dec 03, 2009 10:11 pm    Post subject:
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: 6967
Location: porcelain throne

PostPosted: Thu Dec 03, 2009 10:11 pm    Post subject:
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: 151
Location: India

PostPosted: Fri Dec 04, 2009 10:40 pm    Post subject:
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    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 Sorting of hex values Saurabh_mi DFSORT/ICETOOL 11 Thu May 25, 2017 3:49 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm


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