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

Problem In Case Statement

Former Member
0 Likes
2,281

HI ALL,

in the program,i need to display description based on condition type.

so we used CASE statement as below in LOOP. ITS not working .

could anyone please suggest if anything wrong in the following code.

LOOP AT gt_mat.

MOVE gt_mat-type TO gt_final-type.

  • Condition description

CASE gt_mat-type .

when 'N'.

move 'New' to gt_final-condes.

when 'B'.

move 'Block' to gt_final4-condes.

ENDCASE.

ENDLOOP.

please let me know whats the problem i above code and how to solve.

thanks in advance.

11 REPLIES 11
Read only

rainer_hbenthal
Active Contributor
0 Likes
1,679

Its not working is not an error message. If gt_final-codes is not filled, gt_mat-type does not contain 'N' or 'B'.

Read only

Former Member
0 Likes
1,679

Hi,

Your code is syntactically correct. Debug the code and check if gt_mat-type has the values 'N' or 'B'.

Regards,

Vikranth

Read only

0 Likes
1,679

we have the value in gt_mat-type as N.

It is not at all going inside the case statement.

CASE gt_mat-type .

when 'N'.

move 'New' to gt_final-condes.

when 'B'.

move 'Block' to gt_final4-condes.

ENDCASE.

Read only

0 Likes
1,679

Hi

check your data type for the filed :gt_mat-type is Character or not?

If not change that to Character.

Regards,

Sreeram

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,679

>

> we have the value in gt_mat-type as N.

> It is not at all going inside the case statement.

Hello,

I trust SAP on this. May be there is some "other" problem

Is the case stmt inside any loop control stmt (like AT NEW...ENDAT) ?

Suhas

Read only

0 Likes
1,679

>

> we have the value in gt_mat-type as N.

>

> It is not at all going inside the case statement.

>

> CASE gt_mat-type .

> when 'N'.

> move 'New' to gt_final-condes.

> when 'B'.

> move 'Block' to gt_final4-condes.

> ENDCASE.

Put WHEN OTHERS and see if it goes inside the CASE statement.

Also, as Venkat said, you need to put an APPEND gt_final or MODIFY gt_final to get the values as required.

Read only

abdul_hakim
Active Contributor
0 Likes
1,679

hi

plz check the values of gt_final-type field.

the value you specified in quote for eg 'N' is case sensitive(ie n NE N).

Cheers,

Hakim

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
1,679

Hi

MOVE gt_mat-type TO gt_final-type.

First check the value of gt_final-type.before using the CASE statement.

you are using MOVE gt_mat-type TO gt_final-type.check the datatypes of gt_mat-type and gt_final-type first.

Regards,

Sreeram

Read only

venkat_o
Active Contributor
0 Likes
1,679

Hi Sree, <li> Are you appending or modifying GT_FINAL and GT_FINAL4 tables after you passing text to field condes.

LOOP AT GT_MAT.
   MOVE GT_MAT-TYPE TO GT_FINAL-TYPE.
* Condition description
   CASE GT_MAT-TYPE .
     WHEN 'N'.
       MOVE 'New' TO GT_FINAL-CONDES.
       APPEND GT_FINAL.
       "or
       MODIFY GT_FINAL TRANSPORTING CONDES.
     WHEN 'B'.
       MOVE 'Block' TO GT_FINAL4-CONDES.
       APPEND GT_FINAL.
       "or 
       MODIFY GT_FINAL4 TRANSPORTING CONDES.
   ENDCASE.

 ENDLOOP.
Thanks Venkat.O

Read only

Former Member
0 Likes
1,679

Hi,

The only solution for this could be to debug the program and check if the coresponding values are populated and available. You could also try to replace the CASE statement with a simple IF statement and check if its working.


LOOP AT gt_mat.

MOVE gt_mat-type TO gt_final-type.
* Condition description
IF gt_mat-type = 'N'.
gt_final-condes = 'New'.
elseif gt_mat-type = 'B'.
gt_final-condes ='Block'.
append gt_final.
clear gt_final.
ENDIF.
ENDLOOP.

Also make sure the case of the value in gt_mat-type matches with the condition

Regards,

Vikranth

Read only

Former Member
0 Likes
1,679

Hi Shree,

The code provided by you looks good. It should work.

Please try condensing the gt_mat-type field using CONDENSE statement (before using it in case statement).

Also check the type of the field gt_mat-type. If it is not CHAR, then make it CHAR.

Hope it helps.

Regards,

Raveesh

Edited by: raveesh saurabh on Sep 14, 2009 12:47 PM