Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Obscure CASE statement.

Former Member
0 Likes
647

Hello,

Can CASE be used in the following manner:

case true.

when expression1.

when expression2.

...

endcase.

Aside from functional methods can it be used for logical expressions? e.g.

case 1.

when a > b.

when a < b.

when a = b.

endcase.

Thanks,

John

6 REPLIES 6
Read only

Former Member
0 Likes
617

I guess we can use for logical expressions also

Read only

Former Member
0 Likes
617

Hi,

U cant use logical expressions in the when statement.

The CASE Control Structure

This control structure is introduced with the CASE statement. The CASE control structure allows you to control which statement blocks are processed based on the contents of a data object.

CASE <f>.

WHEN <f11> [OR <f 12> OR ...].

<Statement block>

WHEN <f21>.[OR <f 22> OR ...]

<Statement block>

WHEN <f31> [OR <f 32> OR ...].

<statement block>

WHEN ...

......

WHEN OTHERS.

<statement block>

ENDCASE.

The statement block following a WHEN statement is executed if the contents of <f> are the same as those of one of the fields <f ij >. Afterwards, the program carries on processing after the ENDCASE statement. The statement block after the optional WHEN OTHERS statement is executed if the contents of <f> does not equal any of the <f ij > contents. The last statement block must be concluded with ENDCASE.

The CASE control structure is a shortened form of the following IF structure:

IF <f> = <f11> OR <f> = <f 12> OR <f> = ...

<Statement block>

ELSEIF <f> = <f21> OR <f> = <f 22> OR <f> =...

<Statement block>

ELSEIF <f> = <f21> OR <f> = <f 22> OR <f> =...

<statement block>

ELSEIF <f> = ...

...

ELSE.

<statement block>

ENDIF.

You can nest CASE control structures and also combine them with IF structures. However, they must always end with an ENDCASE statement within the current processing block.

regards,

keerthi.

Read only

abdul_hakim
Active Contributor
0 Likes
617

hi

yes u can use..

Cheers,

Abdul Hakim

Read only

anversha_s
Active Contributor
0 Likes
617

hi,

sure u can write like that.

rgds

anver

Read only

Former Member
0 Likes
617

Hi,

No, CASE statement can not be used like that. WHEN statment can not have logical expression.

Regards,

Rahul

Read only

Bema
Active Participant
0 Likes
617

hi,

No, you can not use logical expression with WHEN.