‎2013 Apr 03 1:19 PM
HI ABAP gurus,
I need to determine the category field based on these conditions. can anyone suggest the code for the same ?
category = C1 if EKPO-PSTYP is equal to 1 and EKPO-KONNR is not equal to NULL.
category = c2 if EKPO-PSTYP is equal to 1 and EKPO-KONNR is qual to NULL.
category = C3 if EKPO-PSTYP is not equal to 1 and EKPO-KONNR is equal to NULL
Category = C4 if EKPO-PSTYP is not equal to 1 and EKPO-KONNR is not qual to NULL and
category = C5 if EBAN-ESTKZ = R.
All these C1 to C5 will be populated in a single field based on the above conditions. I need to write a code for this category field.
I dont know how to handle the if and endif and else if in a single statement.
I can try, please correct it gurus.
if EKPO-PSTYP is equal to 1 and EKPO-KONNR is not equal to NULL then category = C1
else if
if EKPO-PSTYP is equal to 1 and EKPO-KONNR is qual to NULL then category = C2
else if
if EKPO-PSTYP is not equal to 1 and EKPO-KONNR is equal to NULL then category = C3
else if
if EKPO-PSTYP is not equal to 1 and EKPO-KONNR is not qual to NULL then category = C4
else if
EBAN-ESTKZ = R then category = C5.
endif.
endif.
endif.
endif.
I am not sure about these if and endif concept. Please correct my code and suggest the original code in ABAP please. I appreciate it.
thank You,
DR
‎2013 Apr 03 1:25 PM
Hi,
There will be only only if and endif rest everything will be in elseif.
if EKPO-PSTYP eq 1 and EKPO-KONNR is not initial.
category = c1.
elseif EKPO-PSTYP eq 1 and EKPO-KONNR is initial.
category = C2.
elseif EKPO-PSTYP ne 1 and EKPO-KONNR is initial.
category = C3.
elseif EKPO-PSTYP ne 1 and EKPO-KONNR is not initial.
category = C4.
elseif EBAN-ESTKZ = R.
category = C5.
endif.
‎2013 Apr 03 1:41 PM
Thank You so much Ramesh. I appreciate it. You are the best. I wanna add you and post my ABAP queries to you. You can suggest if you are free. Is that OK
Cheers,
DR
‎2013 Apr 04 6:32 AM
thanks for the compliment..you can ask me if you have any questions regarding ABAP queries...Incase if i am not available in SDN you can send me mail @rameshkrishnamani@gmail.com.
Regards,
Ramesh.
‎2013 Apr 03 1:32 PM
HI,
IF EKPO-PSTYP EQ 1 and EKPO-KONNR is not equal to NULL .
category = C1 .
elseif EKPO-KONNR is equal to NULL .
category = C2 .
endif.
IF EKPO-PSTYP ne 1 and EKPO-KONNR is equal to NULL .
category = C3.
elseif EKPO-KONNR is not equal to NULL .
category = C4 .
elseif EBAN-ESTKZ = R.
category = C5
endif..
‎2013 Apr 03 1:43 PM
Oh my god another smart answer. You guys are too fast. I wanna learn ABAP....and I am trying. ...but its tough for a new bee guys.....so just a question....can i use either of the code's or any suggestions....just a question.....do i need to put skip or exit after the first endif.....so that it wont check for c3,c4,c5 when one of the first condition is met or not needed.
thanks,
DR
‎2013 Apr 03 2:28 PM
Hi Daniel,
IF ekpo-pstyp EQ 1.
IF ekpo-konnr IS NOT INITIAL.
category = c1.
ELSEIF ekpo-konnr IS NOT INITIAL.
category = c2.
ENDIF.
ELSEIF ekpo-pstyp NE 1.
IF ekpo-konnr IS NOT INITIAL.
category = c3.
ELSEIF ekpo-konnr IS NOT INITIAL.
category = c4.
ENDIF.
ENDIF.
Regards,
Jyoti.
‎2013 Apr 04 1:42 AM
‎2013 Apr 04 10:20 AM
oh looks like missed some...sorry for that.
for C5 you have to add another elseif statement. Here the example code
IF ekpo-pstyp EQ 1.
IF ekpo-konnr IS NOT INITIAL.
category = c1.
ELSEIF ekpo-konnr IS NOT INITIAL.
category = c2.
ENDIF.
ELSEIF ekpo-pstyp NE 1.
IF ekpo-konnr IS NOT INITIAL.
category = c3.
ELSEIF ekpo-konnr IS NOT INITIAL.
category = c4.
ENDIF.
ELSEIF eban-esktz IS NOT INITIAL.
category = c5.
ENDIF.
Regards,
Jyoti.
‎2013 Apr 03 3:05 PM
Hi Daniel,
Please find sample code.
Loop at it_mara into wa_mara.
if wa_mara-material = 'XYX'.
do something.
else.
do something
endif.
endloop.
‎2013 Apr 04 8:20 AM
Hey Daniel,
I guess there are many ways to write If and endif but as a Standard Coding Practice they'll always suggest you to modularise things.
If EKPO-PSTYP = 1.
If EKPO-KONNR = null.
category = c2
Else.
category = C1
endif.
Elseif EKPO-PSTYP <> 1.
If EKPO-KONNR = null.
category = c3
Else.
category = C4
Endif.
Elseif EBAN-ESTKZ = R.
category = C5.
endif.