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

Dynamic IF statement

matteo_montalto
Contributor
0 Likes
1,356

Hi all @SAPForums,

I need to manage an IF statement whose conditional expression depends on certain parameters. I wonder if there's an easy way to do as follows:

IF parameter 1 is not set (EQ SPACE), then the condition must be: IF it_po_items-delete_ind <> 'L'.

IF parameter 2 is not set (EQ SPACE), then the condition must be: IF it_po_items-delete_ind <> 'S'.

IF both parameters are not set, the condition must be the concatenation of the two above:

IF it_po_items-delete_ind <> 'L' AND it_po_items-delete_ind <> 'S'.

IF both params are set (EQ 'X', they are flags), then there's no condition at all. (IF true?).

Sounds like a thing I could manage using dynamic conditional statements, I did once time ago on a WHERE clause in a SELECT statement, but I'm not able to redo it in this case... maybe because isn't possible in an IF statement?

Thanks for any help you would give me

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,160

hi

you can use case statement

if p1 is initial.

IF it_po_items-delete_ind = 'L'.

endif.

elseif p2 is initial.

IF it_po_items-delete_ind = 'S'.

endif.

elseif p1 is initial  and p2 is initial.

IF it_po_items-delete_ind eq 'L' AND it_po_items-delete_ind eq 'S'.

endif.

endif.

regards

sarves

4 REPLIES 4
Read only

ThomasZloch
Active Contributor
0 Likes
1,160

Maybe you can work around by using a range based on delete_ind.

> DATA: r_delind TYPE RANGE OF ...

You can fill it according to your parameters and then apply it as IF condition.

Thomas

Read only

0 Likes
1,160

hi thomas and thanks for your help.

Sound like a good solution.... Can you provide an example is code / pseudocode in order to evaluate how to apply this solution in my report? Thanks again.

Read only

Former Member
0 Likes
1,160

Hi,

You can use ranges...for this..

Ex..

DATA: r_range TYPE RANGE OF loekz,
          s_range LIKE LINE OF r_range.

s_range-sign = 'I'.
s_range-option = 'EQ'.

*IF parameter 1 is not set (EQ SPACE), then the condition must be: IF it_po_items-delete_ind 'L'.
IF parameter1 = SPACE.
  s_range-low = 'L'.
  APPEND s_range TO r_range.
ENDIF.

*IF parameter 2 is not set (EQ SPACE), then the condition must be: IF it_po_items-delete_ind 'S'.
IF parameter2 = SPACE.
  s_range-low = 'S'.
  APPEND s_range TO r_range.
ENDIF.

IF it_po_items-delete_ind IN r_range. " Only one IF condition should be enough..
**Condition satisfied.  
ENDIF.

Hope this is clear.

Thanks

Naren

Read only

Former Member
0 Likes
1,161

hi

you can use case statement

if p1 is initial.

IF it_po_items-delete_ind = 'L'.

endif.

elseif p2 is initial.

IF it_po_items-delete_ind = 'S'.

endif.

elseif p1 is initial  and p2 is initial.

IF it_po_items-delete_ind eq 'L' AND it_po_items-delete_ind eq 'S'.

endif.

endif.

regards

sarves