03-12-2013 4:10 PM
Hi Experts,
I have dynamically creaeted a internal table and it's work area.
My requirement is I want field names from the dynamically created work area.
And enter data into the particular field selected field.
Can anyone explain me how can I achieve it?.
Thanks in advance.
03-13-2013 8:12 AM
HI Kish,
You have to use one more field symbol to hold field name then,
you can dynamically assign field name from work area to new field symbol.
The code will be something like..
1. ASSIGN COMPONENT fieldname/field_position OF STRUCTURE <dynamic_work_area> TO <new_work_area>. " Get field name
2. <new_work_area> = field_value. " Assign value to field
" repeat step 1 and 2 for all the fields and at last.
APPEND <dynamic_work_area> TO <dynamic_internal_table>.
03-12-2013 5:23 PM
Hi Kish,
Try to user LVC_FIELDCATALOG_MERGE:
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = itab
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF sy-subrc IS INITIAL.
LOOP at lt_fieldcat INTO wa_fieldcat.
WRITE: / wa_fieldcat-fieldname.
ENLOOP.
ENDIF.
Regards,
Edgar
03-12-2013 11:03 PM
Hi,
Use Class: cl_abap_typedescr
Here's some examples:
http://jumpifzero.wordpress.com/2011/08/25/dynamically-determining-the-fields-of-an-abap-structure/
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3145358411d1829f0000e829fbfe/content.htm
Or
if you already know the fieldnames you can use field symbols you can use syntax "ASSIGN COMPONENT.. "
http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm
Br,
Andrei
03-13-2013 4:32 AM
Hi Kish
*Data declaration
DATA: lo_abap_structdescr TYPE REF TO cl_abap_structdescr,
lo_abap_typedescr TYPE REF TO cl_abap_typedescr.
DATA : lv_excel_field(500) TYPE c,
*** declare constant containing structure information and structure name local delcared
lc_excel_op_structure
lc_excel_structure - local structure like ls_**** holding the data
*** Get the Structure Description
lo_abap_typedescr = cl_abap_structdescr=>describe_by_name( lc_excel_op_structure ).
*** Get the structure field
lo_abap_structdescr ?= lo_abap_typedescr.
lo_abap_structdescr will contain all the fields of the structure
READ TABLE lo_abap_structdescr->components INTO ls_components
WITH KEY name = (structure field you want)
IF sy-subrc = 0 AND ls_components-name IS NOT INITIAL.
UNASSIGN <ls_excel_field_value>.
CONCATENATE lc_excel_structure ls_components-name INTO lv_excel_field.
CONDENSE lv_excel_field NO-GAPS.
TRANSLATE lv_excel_field TO UPPER CASE.
ASSIGN (lv_excel_field) TO <ls_excel_field_value>.
IF <ls_excel_field_value> IS ASSIGNED.
<ls_excel_field_value> = ( value which you want to populate )
endif.
endif.
Thanks & Regards
Parin
03-13-2013 4:46 AM
Its easy, please do a search on cl_abap_typedescr. you will get it..!!!
03-13-2013 8:12 AM
HI Kish,
You have to use one more field symbol to hold field name then,
you can dynamically assign field name from work area to new field symbol.
The code will be something like..
1. ASSIGN COMPONENT fieldname/field_position OF STRUCTURE <dynamic_work_area> TO <new_work_area>. " Get field name
2. <new_work_area> = field_value. " Assign value to field
" repeat step 1 and 2 for all the fields and at last.
APPEND <dynamic_work_area> TO <dynamic_internal_table>.