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: 6968
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: 8121
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: 8121
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: 8121
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: 6968
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 BI,TO=ZD Changing Values Tyler Dunbar DFSORT/ICETOOL 4 Tue Jul 25, 2017 12:12 am
No new posts Changeman get multiple "Browse C... elixir1986 Compuware & Other Tools 4 Fri Jul 14, 2017 1:48 am
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm


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