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

if condition

Former Member
0 Likes
1,027

Hi all there,

I am using if condition like this

IF JTAB-AUART = 'ZODO' OR JTAB-AUART = 'ZNET' OR

JTAB-AUART = 'ZOID' OR JTAB-AUART = 'ZDRO' OR

JTAB-AUART = 'ZNFO' OR JTAB-AUART = 'ZNIP' OR

JTAB-AUART = 'ZPDO' OR JTAB-AUART = 'ZPFO'.

is there any options to make it short

Regards

Shashikant

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
984

Hi,

Its highly recommended that you make use of brackets. If your code requires these conditions then its unavoidable. It cant be made short.

Thanks

Nayan

8 REPLIES 8
Read only

Former Member
0 Likes
985

Hi,

Its highly recommended that you make use of brackets. If your code requires these conditions then its unavoidable. It cant be made short.

Thanks

Nayan

Read only

Former Member
0 Likes
984

Shashikant,

I think if you want to go only with IF than no way to do a short.but either you can you CASE statement instead if IF.It will look better also in coding.

Amit.

Read only

Former Member
0 Likes
984

Instead you can write:

CASE JTAB-AUART.

WHEN 'ZODO' or 'ZNET' or 'ZOID' or.....

ENDCASE.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
984

case JTAB-AUART.

when 'ZODO' or 'ZNET' or 'ZOID' or 'ZDRO' or 'ZNFO'

or 'ZNIP' or 'ZPDO' or 'ZPFO'.

-


endcase.

Read only

Former Member
0 Likes
984

either use case statement but that wil not make your code shorter but if you want use if statement like this , please use braces .

Read only

Former Member
0 Likes
984

i see in your if statement is checked 8 values beginning with 'Z***'.

you can make code shorter, if jtab-auart has maximum accepted values equals

to, for example, 9 (9 value is 'Z123'). Then you will write:

if not jtab-auart = 'Z123'.

*----


your logic

endif.

Read only

Former Member
0 Likes
984

You can make it short by using Ranges.

Example:

ranges: r_range for vbak-auart.

data: w_auart type auart.

r_range-low = '1234'.

r_range-option = 'EQ'.

r_range-low = 'I'.

append r_range.

r_range-low = '5678'.

r_range-option = 'EQ'.

r_range-low = 'I'.

append r_range.

r_range-low = '9101'.

r_range-option = 'EQ'.

r_range-low = 'I'.

append r_range.

IF w_auart in r_range.

write 'hi'.

endif.

If the same condition need to be evaluated in multiple places, then you can build a range and use it in the IF statement.

Regards,

Lakshmi.

Read only

Former Member
0 Likes
984

You can very well use in Operator to make this short and effective.

if JTAB-AUART in ( 'VAL1', 'VAL2', 'VAL3'... )

endif.