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

Simple ABAP Conditions

Former Member
0 Likes
764

Dear All,

Please I need your help. This is quite confusing. My condition is quite simple, but I just don't know why it still gets through even though it did not satisfy the parameters. Below is the sample condition.

IF p0001-btrtl = '1000' OR p0001-btrtl BETWEEN '2000' AND '2999'.

IF p0001-kostl in p_rccode.

MOVE p0001-kostl TO stab-kostl.

move: 1 to ok1.

ENDIF.

ELSEIF p0001-btrtl in p_btrtl.

move: 1 to ok1.

concatenate '0000000' p0001-btrtl into stab-kostl.

condense stab-kostl.

ENDIF.

The problem here is that p0001-btrtl's value is '210', but still the program gets through the 1st condition. Please, can anyone explain why this is happening. Hope you could help me with my dilemma. Thank you so much.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
727

HI Anna,

In alphabetic sequence 210 falls in between 2000 ans 3000.

You can use a numeric field to get the required result.

<b>data: v_numc(4) type n.

v_numc = p0001-btrtl.</b>

IF p0001-btrtl = '1000' OR <b>v_numc</b> BETWEEN '2000' AND '2999'.

IF p0001-kostl in p_rccode.

MOVE p0001-kostl TO stab-kostl.

move: 1 to ok1.

ENDIF.

ELSEIF p0001-btrtl in p_btrtl.

move: 1 to ok1.

concatenate '0000000' p0001-btrtl into stab-kostl.

condense stab-kostl.

ENDIF.

Regards,

ravi

P.S: check this sample program to demonstrate the same

data: v_char(4) type n value '210'.

if v_char between '2000' and '3000'.

Write:/ 'Lies'.

else.

write:/ 'Doesnt fall'.

endif.

output: 'Doesnt fall'

Dear All,

Please I need your help. This is quite confusing. My condition is quite simple, but I just don't know why it still gets through even though it did not satisfy the parameters. Below is the sample condition.

IF p0001-btrtl = '1000' OR p0001-btrtl BETWEEN '2000' AND '2999'.

IF p0001-kostl in p_rccode.

MOVE p0001-kostl TO stab-kostl.

move: 1 to ok1.

ENDIF.

ELSEIF p0001-btrtl in p_btrtl.

move: 1 to ok1.

concatenate '0000000' p0001-btrtl into stab-kostl.

condense stab-kostl.

ENDIF.

The problem here is that p0001-btrtl's value is '210', but still the program gets through the 1st condition. Please, can anyone explain why this is happening. Hope you could help me with my dilemma. Thank you so much.

3 REPLIES 3
Read only

Former Member
0 Likes
727

Hi,

Change your code in a way

IF ( p0001-btrtl = '1000' ) OR ( p0001-btrtl BETWEEN '2000' AND '2999' ).

IF p0001-kostl in p_rccode.

MOVE p0001-kostl TO stab-kostl.

move: 1 to ok1.

ENDIF.

ELSEIF p0001-btrtl in p_btrtl.

move: 1 to ok1.

concatenate '0000000' p0001-btrtl into stab-kostl.

condense stab-kostl.

ENDIF.

Reward if it is helpful

Regards,

Sangeetha.A

Read only

Former Member
0 Likes
728

HI Anna,

In alphabetic sequence 210 falls in between 2000 ans 3000.

You can use a numeric field to get the required result.

<b>data: v_numc(4) type n.

v_numc = p0001-btrtl.</b>

IF p0001-btrtl = '1000' OR <b>v_numc</b> BETWEEN '2000' AND '2999'.

IF p0001-kostl in p_rccode.

MOVE p0001-kostl TO stab-kostl.

move: 1 to ok1.

ENDIF.

ELSEIF p0001-btrtl in p_btrtl.

move: 1 to ok1.

concatenate '0000000' p0001-btrtl into stab-kostl.

condense stab-kostl.

ENDIF.

Regards,

ravi

P.S: check this sample program to demonstrate the same

data: v_char(4) type n value '210'.

if v_char between '2000' and '3000'.

Write:/ 'Lies'.

else.

write:/ 'Doesnt fall'.

endif.

output: 'Doesnt fall'

Read only

Former Member
0 Likes
727

Hi,

p0001-btrtl is a char4 element so,

if the value in p0001-btrtl is '210_' , where '_' is a space is normal that abap

consider this string inside '2000' and '2999', because you are not comparing

numbers, but characters.

If the value in p0001-btrtl is '_210' then ...i don't know !!!

Best Regards,