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

The program dont respect my IF statement.

Former Member
0 Likes
733

I need to pass this code if the statement is true:

But the program dont respect the statement.

Thanks for the help.


IF T_ITAB-BSTAT1 NE 'S' OR T_ITAB-BSTAT1 NE 'V'
   OR T_ITAB-BSTAT1 NE 'W' OR T_ITAB-BSTAT1 NE 'Z'
   OR T_ITAB-BSTAT1 NE 'D'.


    wa_msgdetails-company       = t_itab-bukrs.
    wa_msgdetails-account       = t_itab-hkont.
    wa_msgdetails-center        = t_itab-prctr .
    wa_msgdetails-posting_date  = t_itab-cpudt .
    wa_msgdetails-efective_date = t_itab-budat .
    wa_msgdetails-source_code   = t_itab-sgtxt.
    wa_msgdetails-description1  = t_itab-sgtxt.
    wa_msgdetails-description2  = t_itab-zuonr .
    wa_msgdetails-description3  = t_itab-ltext .
    wa_msgdetails-amount        = t_itab-wrbtr.
    wa_msgdetails-sign          = t_itab-shkzg.
    msghead-posting_date        = sy-datum.
    msghead-effective_date      = sy-datum.
    msghead-counter_rec         = t_acum.

endif.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
715

Hi Carlos

Your code respect your control, because you're using OR statament so you're checking if a variable isn't equal to value OR other value and this control is always true.

Infact: A = 2.

IF A <> 1 or A <> 2.

This control is true because A <> 1.

A = 1.

IF A <> 1 or A <> 2.

This control is true because A <> 2.

You have to use AND statament, if you want the data isn't equal to several values at the same time.

A = 1.

IF A <> 1 AND A <> 2.

This control is false, because A isn't equal 2 but it's 1.

So your code have to be:

IF T_ITAB-BSTAT1 NE 'S' AND T_ITAB-BSTAT1 NE 'V'

AND T_ITAB-BSTAT1 NE 'W' AND T_ITAB-BSTAT1 NE 'Z'

AND T_ITAB-BSTAT1 NE 'D'.

wa_msgdetails-company = t_itab-bukrs.

wa_msgdetails-account = t_itab-hkont.

wa_msgdetails-center = t_itab-prctr .

wa_msgdetails-posting_date = t_itab-cpudt .

wa_msgdetails-efective_date = t_itab-budat .

wa_msgdetails-source_code = t_itab-sgtxt.

wa_msgdetails-description1 = t_itab-sgtxt.

wa_msgdetails-description2 = t_itab-zuonr .

wa_msgdetails-description3 = t_itab-ltext .

wa_msgdetails-amount = t_itab-wrbtr.

wa_msgdetails-sign = t_itab-shkzg.

msghead-posting_date = sy-datum.

msghead-effective_date = sy-datum.

msghead-counter_rec = t_acum.

endif.

Max

I need to pass this code if the statement is true:

But the program dont respect the statement.

Thanks for the help.


IF T_ITAB-BSTAT1 NE 'S' OR T_ITAB-BSTAT1 NE 'V'
   OR T_ITAB-BSTAT1 NE 'W' OR T_ITAB-BSTAT1 NE 'Z'
   OR T_ITAB-BSTAT1 NE 'D'.


    wa_msgdetails-company       = t_itab-bukrs.
    wa_msgdetails-account       = t_itab-hkont.
    wa_msgdetails-center        = t_itab-prctr .
    wa_msgdetails-posting_date  = t_itab-cpudt .
    wa_msgdetails-efective_date = t_itab-budat .
    wa_msgdetails-source_code   = t_itab-sgtxt.
    wa_msgdetails-description1  = t_itab-sgtxt.
    wa_msgdetails-description2  = t_itab-zuonr .
    wa_msgdetails-description3  = t_itab-ltext .
    wa_msgdetails-amount        = t_itab-wrbtr.
    wa_msgdetails-sign          = t_itab-shkzg.
    msghead-posting_date        = sy-datum.
    msghead-effective_date      = sy-datum.
    msghead-counter_rec         = t_acum.

endif.

5 REPLIES 5
Read only

Former Member
0 Likes
715

Try changing all your ORs to ANDs.

Rob

Read only

Former Member
0 Likes
716

Hi Carlos

Your code respect your control, because you're using OR statament so you're checking if a variable isn't equal to value OR other value and this control is always true.

Infact: A = 2.

IF A <> 1 or A <> 2.

This control is true because A <> 1.

A = 1.

IF A <> 1 or A <> 2.

This control is true because A <> 2.

You have to use AND statament, if you want the data isn't equal to several values at the same time.

A = 1.

IF A <> 1 AND A <> 2.

This control is false, because A isn't equal 2 but it's 1.

So your code have to be:

IF T_ITAB-BSTAT1 NE 'S' AND T_ITAB-BSTAT1 NE 'V'

AND T_ITAB-BSTAT1 NE 'W' AND T_ITAB-BSTAT1 NE 'Z'

AND T_ITAB-BSTAT1 NE 'D'.

wa_msgdetails-company = t_itab-bukrs.

wa_msgdetails-account = t_itab-hkont.

wa_msgdetails-center = t_itab-prctr .

wa_msgdetails-posting_date = t_itab-cpudt .

wa_msgdetails-efective_date = t_itab-budat .

wa_msgdetails-source_code = t_itab-sgtxt.

wa_msgdetails-description1 = t_itab-sgtxt.

wa_msgdetails-description2 = t_itab-zuonr .

wa_msgdetails-description3 = t_itab-ltext .

wa_msgdetails-amount = t_itab-wrbtr.

wa_msgdetails-sign = t_itab-shkzg.

msghead-posting_date = sy-datum.

msghead-effective_date = sy-datum.

msghead-counter_rec = t_acum.

endif.

Max

Read only

former_member184495
Active Contributor
0 Likes
715

hi ,

as per your code,

say if the value of T_ITAB-BSTAT1 is 'V',

it will satisfy your first condition in if,

i.e

if T_ITAB-BSTAT1 NE 'S'

and the loop would not go for the 'OR' condition, so here your purpose is lost.

hence you could do one thing ,

use 'AND' instead of 'OR'.

hope it was helpful.

cheers,

Aditya.

Read only

hymavathi_oruganti
Active Contributor
0 Likes
715

AS IT IS A NEGATION STATEMENT,

CHANGE ALL UR ORs to AND s

because

A OR B = NOT A and NOT B

I HOPE U UNDERSTOOD.

regs

hyma

Read only

Former Member
0 Likes
715

Hi Carlos,

When you use conditions for equalling to a certain value then you have to use OR & when you go for non-quality to values then you have to go for AND .Furthermore as you have so many conditions to be checked use simple braces too.

Thanx

Rk