cancel
Showing results for 
Search instead for 
Did you mean: 

how to combine/simplify these multiple IF Statements?

sh4il3sh
Participant
0 Kudos

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.

 

 

View Entire Topic
NISHANT_R
Explorer
0 Kudos

Hi ,

I combined multiple if's to single if using else if . Try it.

Refer the screenshot for the code.

 

 

sajid-khan
Explorer
0 Kudos
@NISHANT_R your code is logically different than the code posted by the author.
NISHANT_R
Explorer
0 Kudos
@sajid-khan I think that the logic is same but the code construct is different
sajid-khan
Explorer
0 Kudos
@NISHANT_R Nope, your code will produce different result than the code posted by the author.
Tomas_Buryanek
Active Contributor
0 Kudos
You are using ELSEIF which is not used in OPs code.
sh4il3sh
Participant
0 Kudos

.

sh4il3sh
Participant
0 Kudos
Agreed with others, this would give me another solution.