View previous topic :: View next topic
|
Author |
Message |
blpraveen123 Currently Banned New User
Joined: 26 Apr 2007 Posts: 12 Location: Mysore
|
|
|
|
Hi,
Is it possible to exit the evaluate when the XYZ(D) = ABC(D) and avoid performing the loop until LIMIT.
Code: |
PROGRAM
EVALUATE x
WHEN 1
PERFORM D VARIYING FROM 1 BY 1 UNTIL D > LIMIT
IF XYZ(D) = ABC(D)
MOVE 'Y' TO WS-VAR
END-IF
WHEN OTHER
MOVE 'N' TO WS-VAR
END-EVALUATE
GOBACK.
|
CONTINUE and NEXT SENTENCE will not work as i am moving values within IF statement. If I insert EXIT command it wiil go to infinite Loop. I am working on COBOL II version.Is there anyway i can exit the perform without using the Flag as below.
Code: |
PERFORM D VARIYING FROM 1 BY 1 UNTIL D > LIMIT or FLAG
IF XYZ(D) = ABC(D)
MOVE 'Y' TO WS-VAR
MOVE 'YES' TO FLAG
END-IF
|
|
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Praveen,
After MOVE statement, why dont you recalculate the var 'D' (say LIMIT+1). |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Praveen,
In addition to my prev post,
.......... when you dont need variable 'D' (original) value down the program. |
|
Back to top |
|
|
saptagiri kintali
New User
Joined: 21 Sep 2007 Posts: 20 Location: chennai
|
|
|
|
and u can move '0' to limit if D contains only positive values, by this way also u can make exit |
|
Back to top |
|
|
saptagiri kintali
New User
Joined: 21 Sep 2007 Posts: 20 Location: chennai
|
|
|
|
........and the best way is move low values to limit. |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
Please check with the following code for your requirement. It is using WS-VAR to exit from the EVALUATE when the XYZ(D) = ABC(D) and avoid performing the loop until LIMIT.
Code: |
EVALUATE X
WHEN 1
PERFORM VARIYING D FROM 1 BY 1 UNTIL D > LIMIT OR WS-VAR = 'Y'
IF XYZ(D) = ABC(D)
MOVE 'Y' TO WS-VAR
END-IF
WHEN OTHER
MOVE 'N' TO WS-VAR
END-EVALUATE
GOBACK. |
|
|
Back to top |
|
|
blpraveen123 Currently Banned New User
Joined: 26 Apr 2007 Posts: 12 Location: Mysore
|
|
|
|
Hi,
I thank you all for approaching the question to answer, But i put the code in the wrong way
please see the code below.
Code: |
working_Storage section
01 list
05 filler pic x(10) value 'A AAAAAAAA'
05 filler pic x(10) value 'B BBBBBBBB'
....
....
05 filler pic x(10) value 'Z ZZZZZZZZ'
01 Group-rec redfines list
05 xyx occures 26 times
10 letter pic x.
10 filler pic x.
10 ENV pic x(8).
EVALUATE X
WHEN 1
PERFORM VARIYING D FROM 1 BY 1 UNTIL D > LIMIT
IF XYZ(D) = ABC(D)
MOVE XYZ(D) (1:1) TO WS-VAR
END-IF
WHEN OTHER
MOVE 'N' TO WS-VAR
END-EVALUATE
GOBACK.
|
|
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Would not something like this work?
Code: |
EVALUATE X
WHEN 1
PERFORM VARYING D FROM 1 BY 1 UNTIL D > LIMIT
or XYZ(D) = ABC(D)
end-perform
WHEN OTHER
MOVE 'N' TO WS-VAR
END-EVALUATE
IF XYZ(D) = ABC(D)
MOVE XYZ(D) (1:1) TO WS-VAR
END-IF
GOBACK.
|
|
|
Back to top |
|
|
blpraveen123 Currently Banned New User
Joined: 26 Apr 2007 Posts: 12 Location: Mysore
|
|
|
|
Hi,
Thanks
I want to know why it give Compilation error when i inserted NEXT statement after move wthin in the If para. Is that the NEXT statement to be used to indicate perform nothing when IF condition is TRUE.
Code: |
EVALUATE X
WHEN 1
PERFORM VARIYING D FROM 1 BY 1 UNTIL D > LIMIT
IF XYZ(D) = ABC(D)
MOVE XYZ(D) (1:1) TO WS-VAR
NEXT SENTENCE
END-IF
WHEN OTHER
|
|
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Praveen,
Please post spool messages (compiliation messages). |
|
Back to top |
|
|
shrivatsa Warnings : 1 Active User
Joined: 17 Mar 2006 Posts: 174 Location: Bangalore
|
|
|
|
I think NEXT SENTENCE
Should be used as a single statement.
If <Condition> then
{Statement-1
Next Sentence}
Else
{Statement-2
Next Sentence}
end-if
That's why you are getting compile error.
Correct me if i am wrong |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
blpraveen123 wrote: |
I want to know why it give Compilation error |
I don't know, since you have not provided the error....
But I can tell that your coding style sucks...for example, why turn a simple IF into such a mess and where is the END-PERFORM?
Quote: |
Code: |
EVALUATE X
WHEN 1
PERFORM VARIYING D FROM 1 BY 1 UNTIL D > LIMIT
IF XYZ(D) = ABC(D)
MOVE XYZ(D) (1:1) TO WS-VAR
NEXT SENTENCE
END-IF
WHEN OTHER
|
|
|
|
Back to top |
|
|
|