Application Development 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: 

If...elseif statement...

Former Member
0 Kudos

Hi,

I am selecting the data to an itab gi_output.I have 3 checkboxes in my selection screen(p_wgt and p_wgt and p_dimen).so according to the checkboxes selected the data should be deleted from gi_output.

if p_wgt = 'X'.

delete gi_output where tarag NE '0.000' and magew NE '0.000'

and ntgew NE '0.000' and brgew NE '0.000'.

elseif p_ippc = 'X'.

delete gi_output where vegr1 NE ' '.

elseif p_dimen = 'X'.

delete gi_output where laeng NE '0.000'

and breit NE '0.000'

and hoehe NE '0.000'.

elseif p_wgt = 'X' and P_ippc = 'X'.

delete gi_output where tarag NE '0.000' and magew NE '0.000'

and ntgew NE '0.000' and brgew NE '0.000'

or vegr1 NE ' '.

when 1 checkbox is selected..my coding is working fine..but when 2 checkboxes are selected (suppose p_wgt and P_ippc),the control is checking 1st if statement(P_wgt = 'X')than after that it is coming out of if statement block....any idea..

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

You need to write all possible combination for check boxes.

if p_wgt = 'X' AND p_ippc = 'X' AND p_dimen = 'X'.

<your deletion code>

endif.

if p_wgt = 'X' AND p_ippc = 'X' .

<your deletion code>

endif.

if p_ippc = 'X' AND p_dimen = 'X'.

<your deletion code>

endif.

if p_wgt = 'X' AND p_dimen = 'X'.

<your deletion code>

endif.

if p_wgt = 'X' .

<your deletion code>

endif.

if p_ippc = 'X' .

<your deletion code>

endif.

if p_dimen = 'X'.

<your deletion code>

endif.

Regards

Arindam

8 REPLIES 8

former_member1245113
Active Contributor
0 Kudos

Hi Priya,

Please understand the key words properly.

IF statements executes for the first logical expression where it satisfied the condions mentiond and skips other else conditions.

this is the NATURE of IF statement.

if you want all the three to be checked.

you need to write combinations.

if f_chek is 'X' AND

S_CHEK IS 'X' AND

T_CHEK IS 'X'.

ELSEIF

ELSEIF.

or use anyother logic.

for further help please go throught the key word documentaion.

regards

Ramchander Rao.K

0 Kudos

so,

what can i use for multiple checkbox selection.?

0 Kudos

hi

use case endcase .

Former Member
0 Kudos

Hello,

You need to write all possible combination for check boxes.

if p_wgt = 'X' AND p_ippc = 'X' AND p_dimen = 'X'.

<your deletion code>

endif.

if p_wgt = 'X' AND p_ippc = 'X' .

<your deletion code>

endif.

if p_ippc = 'X' AND p_dimen = 'X'.

<your deletion code>

endif.

if p_wgt = 'X' AND p_dimen = 'X'.

<your deletion code>

endif.

if p_wgt = 'X' .

<your deletion code>

endif.

if p_ippc = 'X' .

<your deletion code>

endif.

if p_dimen = 'X'.

<your deletion code>

endif.

Regards

Arindam

kesavadas_thekkillath
Active Contributor
0 Kudos

easy to work it out...HMmmm

if p_wgt = 'X'.

delete gi_output where tarag NE '0.000' and magew NE '0.000'

and ntgew NE '0.000' and brgew NE '0.000'.

endif.

if p_ippc = 'X'.

delete gi_output where vegr1 NE ' '.

endif.

if p_dimen = 'X'.

delete gi_output where laeng NE '0.000'

and breit NE '0.000'

and hoehe NE '0.000'.

endif.

if p_wgt = 'X' and P_ippc = 'X'.

delete gi_output where tarag NE '0.000' and magew NE '0.000'

and ntgew NE '0.000' and brgew NE '0.000'

or vegr1 NE ' '.

endif.

this will work

0 Kudos

Kheshu's right ... simplest and most effective

if p_wgt = 'X'.

*logic when checkbox1 is selected

endif.

if p_ippc = 'X'.

*logic when checkbox1 is selected

endif.

if p_dimen = 'X'.

*logic when checkbox1 is selected

endif.

and use combinations if different logic for various combinations of checkboxes is required.

Sougata
Active Contributor
0 Kudos

Hi Priya,

For this specific scenario i.e. if you do not have any other requirements as far as logic behind these 3 checkboxes are concerned, you could write it like this:


IF p_wgt = 'X' AND p_ippc = 'X'.
* your logic
ELSEIF p_ippc = 'X'.
* your logic
ELSEIF p_dimen = 'X'.
* your logic
ELSE.
 delete gi_output where tarag NE '0.000' and magew NE '0.000' 
 and ntgew NE '0.000' and brgew NE '0.000'.
ENDIF.

Hope this solves the issue.

Cheers,

Sougata.

Former Member
0 Kudos

Hi Priya,

Check boxes are viable to select more than one among hence you need to handle it for each check box selected. The best way to handle check boxes are to have independent IF...ENDIF condition for each.

IF..ELSEIF...statement is more suitable for 'Radiobuttons' as you will always select one among the group. So have indepedent IF...ENDIF condition for each check box.

If you will still wants to do only with IF...ELSEIF statements then you need to take care of coding for cominational conditions. Always have most feasible conidtion on TOP.

Check the below code.

if p_wgt = 'X' and P_ippc = 'X'.

delete gi_output where tarag NE '0.000' and magew NE '0.000'

and ntgew NE '0.000' and brgew NE '0.000'

or vegr1 NE ' '.

elesif p_wgt = 'X'.

delete gi_output where tarag NE '0.000' and magew NE '0.000'

and ntgew NE '0.000' and brgew NE '0.000'.

elseif p_ippc = 'X'.

delete gi_output where vegr1 NE ' '.

elseif p_dimen = 'X'.

delete gi_output where laeng NE '0.000'

and breit NE '0.000'

and hoehe NE '0.000'.

endif.

Thanks,

Vinay