‎2009 Apr 01 12:58 PM
Hi experts I have written code as like follow:
CASE COMM_STRUCTURE-X.
WHEN '22'.
If COMM_STRUCTURE-wbs_elemt NE ' '.
READ TABLE i_wbs WITH TABLE KEY
co_area = COMM_STRUCTURE-co_area
wbs = COMM_STRUCTURE-wbs_elemt
objvers = 'A'.
RESULT = i_wbs-prfctr.
Else.
RESULT = COMM_STRUCTURE-profit_ctr.
Endif.
endcase.
Now my question is can we have if statement within WHEN, inside CASE ,ENDCASE.Is the above coding is correct?
If COMM_STRUCTURE-wbs_elemt NE ' ' is correct way or
If COMM_STRUCTURE-wbs_elemt NE Initial?
‎2009 Apr 01 1:02 PM
Hi,
If COMM_STRUCTURE-wbs_elemt NE ' ' is correct...or u can use like If COMM_STRUCTURE-wbs_elemt NE space.. but initial can be use like IF NOT itab[] IS INITIAL..
yes, we can write IF in CASE, and ur coding is correct..
Hope it helps!!
Regards,
Pavan
‎2009 Apr 01 1:02 PM
Hi,
If COMM_STRUCTURE-wbs_elemt NE ' ' is correct...or u can use like If COMM_STRUCTURE-wbs_elemt NE space.. but initial can be use like IF NOT itab[] IS INITIAL..
yes, we can write IF in CASE, and ur coding is correct..
Hope it helps!!
Regards,
Pavan
‎2009 Apr 01 1:05 PM
Hi,
and how about code is that correct:can we do coding or read table within IF....like follow
Case.
When.
IF.
Read table.
Endif.
Endcase.
‎2009 Apr 01 1:10 PM
Hi,
Have a look at the following Code hope will help you.
PARAMETERS: abc TYPE i.
CASE abc.
WHEN '1' OR '2'.
IF abc = 1.
WRITE: 'One'.
ELSE.
WRITE: 'Two'.
ENDIF.
WHEN '3' or '4'.
IF abc = 3.
WRITE: 'Three'.
ELSE.
WRITE: 'Four'.
ENDIF.
WHEN OTHERS.
WRITE: 'Number is not Between 1 to 4'.
ENDCASE.Best Regards,
Faisal
‎2009 Apr 01 1:10 PM
‎2009 Apr 01 1:17 PM
Hi, Pie
Test the following Sample Code to for more Clear idea about Case, if else and Read Table
PARAMETERS: abc TYPE i.
DATA: BEGIN OF it OCCURS 10,
no TYPE i,
cno(5),
END OF it.
it-no = 1. it-cno = 'One'. APPEND it.
it-no = 2. it-cno = 'Two'. APPEND it.
it-no = 3. it-cno = 'Three'. APPEND it.
it-no = 4. it-cno = 'Four'. APPEND it.
CASE abc.
WHEN '1' OR '2'.
IF abc = 1.
READ TABLE it WITH KEY no = abc.
IF sy-subrc EQ 0.
WRITE: it-cno.
ENDIF.
ELSE.
READ TABLE it WITH KEY no = abc.
IF sy-subrc EQ 0.
WRITE: it-cno.
ENDIF.
ENDIF.
WHEN '3' OR '4'.
IF abc = 3.
READ TABLE it WITH KEY no = abc.
IF sy-subrc EQ 0.
WRITE: it-cno.
ENDIF.
ELSE.
READ TABLE it WITH KEY no = abc.
IF sy-subrc EQ 0.
WRITE: it-cno.
ENDIF.
ENDIF.
WHEN OTHERS.
WRITE: 'Number is not Between 1 to 4'.
ENDCASE.Please Reply if any Issue,
Best Regards,
Faisal
‎2009 Apr 01 2:09 PM
Hi All,
Thank you so much for your support.
Your ans willbe rewarded.
‎2009 Apr 01 1:04 PM
There are different ways to write things based on the situations.
You are doing correct if the data types declared are appropriate with the CASE/IF conditions.
‎2009 Apr 01 1:09 PM
HI,
It would be better to use INITIAL instead of ' '. Because it works depending upon the datatype.
If Datatype is I initial value is 0.
Datatype is C initial value is space.
Datatype is N initial value is 0.
You can have the If statement in WHEN. What you have written is right.