‎2007 May 04 12:34 PM
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.
‎2007 May 04 12:42 PM
Hi,
Try using
wa_ekko = wa_ekkofld.
or move wa_ekkofld to wa_ekko.
Asha
‎2007 May 04 1:03 PM
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.
‎2007 May 04 1:07 PM
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.
‎2007 May 04 1:12 PM
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.
‎2007 May 04 1:22 PM
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?
‎2007 May 04 4:05 PM
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!
‎2007 May 04 1:17 PM
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
‎2007 May 04 4:12 PM
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