2011 Jul 19 12:25 PM
Dear All Gurus,
This is my requirement..
I need to read the field name (not the value of the field) in an Internal Table loop.
Ex : If internal table is currently reading 'LIFNR' ,need to read this field name into a variable, because I need to cross check this with a mapping table created for this development (BADI for ME52N).
How to I do this ?
Need your help..
Thanks
Jam123
2011 Jul 19 1:43 PM
Hi Jam123
You may do like this:-
TYPE-POOLS: sydes.
DATA: BEGIN OF t_marc OCCURS 0,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
PSTAT TYPE marc-PSTAT,
END OF t_marc.
DATA: td TYPE sydes_desc.
DESCRIBE FIELD t_marc into td.
Now "td-names" will have all the fields names of internal Table
Regards,
Manish
Dear All Gurus,
This is my requirement..
I need to read the field name (not the value of the field) in an Internal Table loop.
Ex : If internal table is currently reading 'LIFNR' ,need to read this field name into a variable, because I need to cross check this with a mapping table created for this development (BADI for ME52N).
How to I do this ?
Need your help..
Thanks
Jam123
2011 Jul 19 12:30 PM
Hi,
you can get the field names of a table using FM DD_GET_NAMETAB.
And in the loop it should be possible to use the index to get the current field name then.
Best regards,
Oliver
2011 Jul 19 12:34 PM
2011 Jul 19 12:40 PM
Hi,
You can try backwards like below.
i.e. suppose in the range S1 all the field names are there and LIFNR is there. Then get the value of the field LIFNR through below code.
ASSIGN COMPONENT 'LIFNR' OF STRUCTURE S1 TO <fs>.
This will give you the value of field LIFNR in internal table.
Hope this is useful.
let me know if it did not solve the problem.
Thanks,
Venkatesh
2011 Jul 19 1:43 PM
Hi Jam123
You may do like this:-
TYPE-POOLS: sydes.
DATA: BEGIN OF t_marc OCCURS 0,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
PSTAT TYPE marc-PSTAT,
END OF t_marc.
DATA: td TYPE sydes_desc.
DESCRIBE FIELD t_marc into td.
Now "td-names" will have all the fields names of internal Table
Regards,
Manish
2011 Jul 20 10:52 AM
Thank you for the reply. Im now able to get field names of my internal table to "td".
How do we loop this TD line by line to output field name?
Ex : write : td-"<fieldname>"
I'm bit stucked with this cos this is not like looping normal internal table/structure.
2011 Jul 21 5:48 AM
HI,
Do like that,
DATA: td TYPE sydes_desc.
FIELD-SYMBOLS <FS> TYPE any.
DESCRIBE FIELD t_marc into td.
LOOP AT td-names ASSIGNING <FS>.
WRITE : / <FS>.
ENDLOOP.
Hope this can solve your problem.
Regards,
Manish
2011 Jul 21 8:53 AM
Jam123,
Use FM GET_COMPONENT_LIST.
data: lt_comp TYPE TABLE OF rstrucinfo .
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'ITAB'
tables
components = lt_comp
lt_comp-COMPNAME will five you Field names.
BR,
Diwakar
2011 Jul 21 9:23 AM
Hi,
Check below code. It will useful.
TYPE-POOLS: sydes.
TABLES: dd01t, dd03l.
DATA: BEGIN OF t_marc OCCURS 0,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
pstat TYPE marc-pstat,
END OF t_marc.
DATA: it_dd03l TYPE STANDARD TABLE OF dd03l,
it_dd01t TYPE STANDARD TABLE OF dd01t.
DATA: td TYPE sydes_desc.
DATA: lv_domain TYPE dd03l-domname,
lv_field_desc TYPE string,
lv_tabname TYPE string,
lv_field_name TYPE string.
FIELD-SYMBOLS :<fs> TYPE ANY.
DESCRIBE FIELD t_marc INTO td.
*APPEND td TO tt.
*CLEAR td.
SELECT * FROM dd03l INTO TABLE it_dd03l WHERE tabname = 'MARC'.
*IF it_dd03l IS NOT INITIAL.
SELECT * FROM dd01t INTO TABLE it_dd01t
FOR ALL ENTRIES IN it_dd03l WHERE domname = it_dd03l-domname.
*ENDIF.
lv_tabname = 'MARC'.
WRITE:/ 'Field Description:'.
SHIFT lv_tabname LEFT DELETING LEADING space.
LOOP AT td-names ASSIGNING <fs>.
SHIFT <fs> LEFT DELETING LEADING space.
lv_field_name = <fs>.
SELECT SINGLE * FROM dd03l WHERE tabname = lv_tabname AND fieldname = lv_field_name AND languflag = sy-langu.
READ TABLE it_dd03l INTO dd03l WITH KEY tabname = lv_tabname fieldname = lv_field_name.
IF dd03l-domname IS NOT INITIAL.
SELECT SINGLE ddtext INTO lv_field_desc FROM dd01t WHERE domname = dd03l-domname AND ddlanguage = sy-langu.
READ TABLE it_dd01t INTO dd01t WITH KEY domname = dd03l-domname.
WRITE:/ lv_field_desc.
ENDIF.
CLEAR: <fs>, dd03l, dd01t, lv_field_desc, lv_field_name.
ENDLOOP.
Ram.
2011 Jul 21 11:32 AM
Hi,
I was discussing the same with one of my colleagues and he advised to use the statement.
ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <structure name > TO <fs>.
You might want to declare your field symbol of type ANY.
THanks,
Guru.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |