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

Passing Fields dynamically to Structure

Former Member
0 Likes
2,408

Hi,

Can any one help me out on this scenario.

I have the selected fields(table fields from EKKO) in my internal table say for example "ZIT_EKKOFLD". And my internal table has the value also for the corresponding fields.

Now i am in Loop

Loop at ZIT_EKKOFLD into work area(wa_ekkofld)

I have another structure say for example wa_ekko, now

i need to assign the new value to wa_ekko from wa_ekkofld work area.

i.e., WA_EKKO - (WA_EKKOFLD-FIELDNAME) = WA_EKKOFLD-VALUE.

endloop.

Can any one tell me how can i do this dynamically ? I know the structure name only thing is i need to pass the field name dynamically inside the loop.

8 REPLIES 8
Read only

Former Member
0 Likes
1,464

Hi,

Try using

wa_ekko = wa_ekkofld.

or move wa_ekkofld to wa_ekko.

Asha

Read only

0 Likes
1,464

Hi,

The one which you are saying to move the value, but my question is fields for the structure will be dynamic.

ie., wa_ekko-(xxxxxx) this xxxxxx fields will be in my looping table.

Let me know is this clear to you or not.

Read only

0 Likes
1,464

Hi,

Could you please elaborate about the structure of wa_ekko as to the fields.

Since it is a structure and must be having some fields.

Read only

0 Likes
1,464

You should use field-symbols:


field-symbols: <field> TYPE any.

ASSIGN component xxx OF STRUCTURE wa_ekkoofld TO <field>.
<field> = wa_ekko-value.

xxx can be the fieldname or the number of the field in the structure.

Read only

0 Likes
1,464

Hi,

I am explaning you in detail.

My Internal table for example : ZIT_FIELDS (Fieldname, Value)

consider this values in ZIT_FIELDS :

fieldname value

-


-


BUKRS 9999

BSART ZTY

ERNAM kumar

ERDAT 20070404

Now i am in loop, say

loop at zit_fields into work area(wa_fields)

I have data in another structure say LS_EKKO will have my zit_fields as well, now i need to change the

respective fields as well as value from zit_fields.

i.e., LS_EKKO-BUKRS, LS_EKKO-BSART, LS_EKKO-ERNAM....

since these field names are in my internal table, how can i pass those field

names to my structure LS_EKKO dyanamically?

endloop.

I hope this is clear to you?

Read only

0 Likes
1,464

That's what I tried to explain earlier: Use Field-symbols!

Should work like this:

field-symbols: <field> TYPE any.
DATA: wa_fields  LIKE ZIT_FIELDS. 
 
SELECT * FROM ZIT_FIELDS INTO wa_fields.

ASSIGN COMPONENT wa_fields-fieldname
OF STRUCTURE wa_ekko TO <field>.
IF sy-subrc = 0.
<field> = wa_fields-value.
ENDIF.

ENDSELECT.

This will try to assign the value from ZIT into the fieldname from ZIT of structure ls_ekko if this structure contains such fieldname.

Of course, bad values for the destination datatype will cause an conversion dump!

Read only

Former Member
0 Likes
1,464

Hi,

If the structures WA_EKKO and WA_EKKOFLD have same fields u can use

Move-corresponding WA_EKKOFLD to WA_EKKO.

Regards,

Kasi S

Read only

Former Member
0 Likes
1,464

Hi Sivanarul,

Refer this code for crating dynamic internal table..

DATA: wa_fldcat TYPE LVC_S_FCAT.

DATA: it_fldcat TYPE LVC_T_FCAT.

DATA: it TYPE REF TO DATA.

FIELD-SYMBOLS: <fs_table> TYPE TABLE.

FIELD-SYMBOLS: <fs_temp> TYPE ANY.

START-OF-SELECTION.

*BUILDING FIELD CATALOG.

wa_fldcat-fieldname = 'matnr'.

wa_fldcat-tabname = 'it'.

wa_fldcat-datatype = 'matnr'.

append wa_fldcat to it_fldcat.

*CREATE THE DYNAMIC INTERNAL TABLE

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fldcat

IMPORTING

EP_TABLE = it.

  • Assign the pointer <fs_table> to the dynamically created internal table "it"

ASSIGN it->* TO <fs_table>.

  • populate the internal table (through field symbols)

select matnr

INTO TABLE <fs_table>

from mara

where mtart = 'ABF'.

  • write the data

loop at <fs_table> ASSIGNING <fs_temp>.

write:/ <fs_temp>.

endloop.

Reward points if helpful.

Regards,

Hemant