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

Assign fields

Former Member
0 Likes
1,066

Hello everybody.

First of all, sorry for my English, I am from Catalonian and I know my english is very poor.

Ok, I am developping in Abap since 6 months, more or less, and know I have a little problem.

I hace defined an internal table where there are 12 fields like these: quantity01, quantity02, ... quantity12. Every field is defined for every month (January, february, ... , december).

My idea is assign the values depending of a date contained in other field of the table (field period).

Is something like this:

LOOP gt_report into gs_report.

  IF gs_report-period = '01'.

    gs_report-quantity01 = gs_report-quant.

  ENDIF.

.......

  IF gs_report-period = '02'.

    gs_report-quantity02 = gs_report-quant.

  ENDIF.

ENDLOOP.

I don't want to work with 12 IF's, because I have to do other operations.

I supose this is very easy for most of you, but I have searched a lot and I didn't find anything. I heart something like fieldsymbols but I don't know if these is really the solution.

Can anyone help me, please?

Thank you in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,036

Hi Marius Conchillo,

I am not having much expertise in the abap so i think my reply may help you.

I understood that your code should not write more if....endif statements.

Instead of writing multiple if...endif statements, we can assign the values to a data object and write a case statement.

using case..... endcase we can exclude multiple if statements.

I think this helped you.

8 REPLIES 8
Read only

Former Member
0 Likes
1,037

Hi Marius Conchillo,

I am not having much expertise in the abap so i think my reply may help you.

I understood that your code should not write more if....endif statements.

Instead of writing multiple if...endif statements, we can assign the values to a data object and write a case statement.

using case..... endcase we can exclude multiple if statements.

I think this helped you.

Read only

0 Likes
1,036

Thank you for your answer Harsha.

Ok, I can use case/endcase, but by this way is more or less the same. Finally, I have to write 12 portions of code (1 for every month).

The idea is write only one.

Thank you Harsha.

Read only

0 Likes
1,036

Hello Conchilo,

You can try like this.

DATA : V_PERIO(40) TYPE C,

             v_fs type any.

LOOP at gt_report into gs_report.

concatenate 'GS_REPORT-QUANTITY'  GS_REPORT-PERIOD INTO V_PERIO.

ASSIGN (V_PERIO) TO V_FS.

V_FS = GS_REPORT-QUANTITY.

ENDLOOP.

Regards

Gourav.

Read only

0 Likes
1,036

Hi,

This will not work

here is how it should be

You can try like this.

DATA : V_PERIO(40) TYPE C.

FIELD-SYMBOLS <fs> TYPE ANY

            

LOOP at gt_report into gs_report.

concatenate 'GS_REPORT-QUANTITY'  GS_REPORT-PERIOD INTO V_PERIO.

ASSIGN (V_PERIO) TO <FS>.

IF <FS> is assigned.

<FS> = GS_REPORT-QUANTITY.

ENDIF.

ENDLOOP.

Regards

Gourav.

Read only

0 Likes
1,036

Hi Yakub,

By mistake I wrote that line.

<fs> type any within data,Yes it will under field-symbol.

GOURAV.

Read only

0 Likes
1,036

Thank you everybody for your answers.

Now, it's working fine.

Read only

Former Member
0 Likes
1,036

Hi Marius,

Other similar way to solve the  problem is:

DATA: lv_name TYPE string.
FIELD-SYMBOLS: <lv_content> TYPE ANY.

LOOP AT gt_report INTO gs_report.
 
CONCATENATE 'QUANTITY' gs_report-period INTO lv_name.
 
ASSIGN COMPONENT lv_name OF STRUCTURE gs_report TO <lv_content>.

 
IF <lv_content> IS ASSIGNED.
      <lv_content>
= gs_report-quant.
 
ENDIF.

 
CLEAR: lv_name.
  UNASSIGN
: <lv_content>.
ENDLOOP.

Hope it helps. Cheers!

Read only

Former Member
0 Likes
1,036

Hi Marius,

I hope your post is relevant to the below document, it clearly explain you how to use Field Symbols

http://scn.sap.com/docs/DOC-42525

Regard's,.

Shashi Kanth.