View previous topic :: View next topic
|
Author |
Message |
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Vinu,
you code looks super to me. What problem are you having? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
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 |
|
|
|