2 weeks ago - last edited 2 weeks ago
I have below multiple IF statements which I want to see combined,
I tried using ELSEIF and CASE but its not applicable here because the comparison operator is <> instead of =
Below is the code:
IF <ls_load>-atnam <> 'AA'.
IF VALUE #( lt_num[ charact = 'AA' ]-value_from OPTIONAL ) IS INITIAL.
DELETE lt_num WHERE charact = 'AA'.
ENDIF.
ENDIF.
IF <ls_load>-atnam <> 'BB'.
IF VALUE #( lt_num[ charact = 'BB' ]-value_from OPTIONAL ) IS INITIAL.
DELETE lt_num WHERE charact = 'BB'.
ENDIF.
ENDIF.
IF <ls_load>-atnam <> 'CC'.
IF VALUE #( lt_num[ charact = 'CC' ]-value_from OPTIONAL ) IS INITIAL.
DELETE lt_num WHERE charact = 'CC'.
ENDIF.
ENDIF.
Hello, consider creating a method in this case. All three conditions looks same, just parameter 'AA'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If your aim is to eliminate code repetition by combining IF's, you can use a simple LOOP:
LOOP AT VALUE TT_ACTION_CODES( ( 'AA' ) ( 'BB' ) ( 'CC' ) ) ASSIGNING FIELD-SYMBOL(<value>).
IF <ls_load>-atnam <> <value>.
IF VALUE #( lt_num[ charact = <value> ]-value_from OPTIONAL ) IS INITIAL.
DELETE lt_num WHERE charact = <value>.
ENDIF.
ENDIF.
ENDLOOP.
Regards,
Sajid Khan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.