2008 Jul 18 9:51 AM
hi
I want to fetch the value of a table's field-name into another variable, can you tell me how to do this..
Something like this
LOOP AT itab INTO wa_itab.
CASE ITAB-COL.
WHEN '0001'.
WA_RECORD-MANDT = ITAB-VALUE.
WHEN '0002'.
WA_RECORD-NAME2 = ITAB-VALUE.
ENDCASE.
AT END OF row.
APPEND wa TO itab_sflight.
w_col = 1.
ENDAT.
ENDLOOP.In the above code if COL value is 2 then I want to fetch the second fieldname from SFLIGHT table... so my answer should be CARRID..
2008 Jul 18 10:10 AM
I am not enough sure what is your exact requirement . What can I understand from the thread that you want to know the fieldnames of the itab. Then you check the fn module
DATA : IRSTRUCINFO LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = 'YOUR PROG NAME IN CAPS'
FIELDNAME = 'YOUR INT TABLE NAME IN CAPS'
TABLES
COMPONENTS = IRSTRUCINFO.
Hi,
i dont think you will be able to get the field from the Internal table like this. Internal table is a storage area which will simply take the data for the Type you have declared it for.
in your case. i would suggest you to use the first line to simply populate the Fields so that you can read them later at your will. read table index 1.
2008 Jul 18 9:55 AM
modify ur loop as below
LOOP AT itab INTO wa_itab.
CASE wa_ITAB-COL.
WHEN '0001'.
WA_RECORD-MANDT = wa_ITAB-VALUE.
WHEN '0002'.
WA_RECORD-NAME2 = wa_ITAB-VALUE.
ENDCASE.
AT END OF row.
APPEND wa_itab TO itab_sflight.
w_col = 1.
ENDAT.
ENDLOOP.
2008 Jul 18 9:59 AM
Hi
No problem with coding part.. I want to fetch the first field in SFLIGHT..
2008 Jul 18 10:02 AM
Hi,
i dont think you will be able to get the field from the Internal table like this. Internal table is a storage area which will simply take the data for the Type you have declared it for.
in your case. i would suggest you to use the first line to simply populate the Fields so that you can read them later at your will. read table index 1.
2008 Jul 18 11:01 AM
Hi,
you can try this:
DATA gt_sflight TYPE STANDARD TABLE OF sflight.
FIELD-SYMBOLS <gv_value> TYPE any.
FIELD-SYMBOLS <gs_sflight> type sflight.
LOOP AT gt_sflight ASSIGNING <gs_sfligt>.
ASSIGN COMPONENT 1 OF STRUCTURE <gs_sflight> TO <gv_value>.
* [...]
ENDLOOP.
[Assigning Components of Structures to a Field Symbol|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/frameset.htm]
Regards Rudi
2008 Jul 18 10:03 AM
LOOP AT itab INTO wa_itab.
first you need to find out column headers....
AT FIRST.
CASE wa_ITAB-COL.
WHEN '0001'.
move this value (wa_ITAB-VALUE) whrer ever u wnat.
WHEN '0002'.
move this value (wa_ITAB-VALUE) whrer ever u wnat ENDCASE.
APPEND wa_head TO i_head.
ENDAT.
CASE wa_ITAB-COL.
WHEN '0001'.
WA_RECORD-MANDT = wa_ITAB-VALUE.
WHEN '0002'.
WA_RECORD-NAME2 = wa_ITAB-VALUE.
ENDCASE.
AT END OF row.
APPEND wa TO itab_sflight.
w_col = 1.
ENDAT.
ENDLOOP.
Edited by: Raghu on Jul 18, 2008 11:05 AM
2008 Jul 18 10:07 AM
Hi,
if you only want do get the name of a field in a structure, you can read it from database table dd03l. Alternatively, you could use the class cl_abap_struct_descr.
In case that you want to have a pointer to field number x of a structure, use the command:
assign component x of structure y to <fs>.
Regards,
Thomas
2008 Jul 18 10:10 AM
I am not enough sure what is your exact requirement . What can I understand from the thread that you want to know the fieldnames of the itab. Then you check the fn module
DATA : IRSTRUCINFO LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = 'YOUR PROG NAME IN CAPS'
FIELDNAME = 'YOUR INT TABLE NAME IN CAPS'
TABLES
COMPONENTS = IRSTRUCINFO.
2008 Jul 18 1:56 PM
LOOP AT itab INTO wa_itab.
SELECT SINGLE fieldname FROM dd03l INTO w_fieldname
WHERE tabname = 'SFLIGHT'
AND position = w_col.
CONCATENATE 'WA_SFLIGHT' w_fieldname INTO string
SEPARATED BY '-'.
ASSIGN (string) TO <fname>.
<fname> = wa_itab-value.
w_col = w_col + 1.
AT END OF row.
APPEND wa_sflight TO itab_sflight.
w_col = '2'.
ENDAT.
ENDLOOP.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |