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

Table Field Reading in an ABAP program

tharu
Contributor
0 Likes
3,464

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,487

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

9 REPLIES 9
Read only

Former Member
0 Likes
2,487

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

Read only

naveen_inuganti2
Active Contributor
0 Likes
2,487

Use "ASSIGN COMPONENT"

Read only

Former Member
0 Likes
2,487

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

Read only

Former Member
0 Likes
2,488

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

Read only

0 Likes
2,487

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.

Read only

0 Likes
2,487

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

Read only

0 Likes
2,487

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

Read only

Former Member
0 Likes
2,487

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.

Read only

Former Member
0 Likes
2,487

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.