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

SAP table field names

Former Member
0 Likes
3,337

in program i want to pass sap table name and get all the fields of this table name. how i can achieve this through abap program. table will be standard sap table and not internal table.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,281

Hi Santosh,

try with this FM DB_GET_TABLE_FIELDS

in program i want to pass sap table name and get all the fields of this table name. how i can achieve this through abap program. table will be standard sap table and not internal table.

6 REPLIES 6
Read only

Former Member
0 Likes
1,281

Hi,

You can achieve this by using the Table 'DD03L' to get the fieldnames for the corresponding table.

<REMOVED BY MODERATOR>

Regards

Rose

Edited by: Alvaro Tejada Galindo on Mar 19, 2008 6:39 PM

Read only

Former Member
0 Likes
1,281

Use This FM - /SAPDII/DWB_GET_TABLE_FIELDS

Pass the table as Import Parameter.

The Exporting table TABLE_FIELDS in which all the data corresponding to the field can be found.

Call this FM in your ABAP program and I/P the table name which is given in the selection to the FM.

Hope this solves your concern.

Regards

Vinayak

Read only

Former Member
0 Likes
1,281

hi ,

enter the table name and get the fields..

REPORT Z_DYNALV .

*Type pools declaration for ALV

TYPE-POOLS: SLIS. " ALV Global Types*data declaration for dynamic internal table and alv

DATA: L_STRUCTURE TYPE REF TO DATA,

L_TABLE TYPE REF TO DATA,

STRUC_DESC TYPE REF TO CL_ABAP_STRUCTDESCR,

LT_LAYOUT TYPE SLIS_LAYOUT_ALV,

LS_LVC_FIELDCATALOGUE TYPE LVC_S_FCAT,

LT_LVC_FIELDCATALOGUE TYPE LVC_T_FCAT,

LS_FIELDCATALOGUE TYPE SLIS_FIELDCAT_ALV,

LT_FIELDCATALOGUE TYPE SLIS_T_FIELDCAT_ALV.

*field symbols declaration

FIELD-SYMBOLS :

<IT_TABLE> TYPE STANDARD TABLE,

<DYN_STR> TYPE ANY,

<STR_COMP> TYPE ABAP_COMPDESCR.

*declarations for grid title

DATA : T1(30),

T2(10),

T3(50).

*selection screen declaration for table input

PARAMETERS : P_TABLE LIKE DD02L-TABNAME.

*initialization event

INITIALIZATION.

*start of selection event

START-OF-SELECTION.

*texts for grid title

T1 = 'Dynamic ALV display for table'.

T2 = P_TABLE. CONCATENATE T1 T2 INTO T3 SEPARATED BY SPACE.

  • Dynamic creation of a structure

CREATE DATA L_STRUCTURE TYPE (P_TABLE).

ASSIGN L_STRUCTURE->* TO <DYN_STR>.

  • Fields Structure

STRUC_DESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <DYN_STR> ).

LOOP AT STRUC_DESC->COMPONENTS ASSIGNING <STR_COMP>.

  • Build Fieldcatalog

LS_LVC_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_LVC_FIELDCATALOGUE-REF_TABLE = P_TABLE.

APPEND LS_LVC_FIELDCATALOGUE TO LT_LVC_FIELDCATALOGUE.

  • Build Fieldcatalog

LS_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_FIELDCATALOGUE-REF_TABNAME = P_TABLE.

APPEND LS_FIELDCATALOGUE TO LT_FIELDCATALOGUE.

ENDLOOP.

  • Create internal table dynamic

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVC_FIELDCATALOGUE

IMPORTING

EP_TABLE = L_TABLE.

ASSIGN L_TABLE->* TO <IT_TABLE>.

  • Read data from the table selected.

SELECT * FROM (P_TABLE)

INTO CORRESPONDING FIELDS OF TABLE <IT_TABLE>.

  • ALV Layout

LT_LAYOUT-ZEBRA = 'X'.

LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LT_LAYOUT-WINDOW_TITLEBAR = T3.

*ALV output

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IS_LAYOUT = LT_LAYOUT

IT_FIELDCAT = LT_FIELDCATALOGUE

TABLES

T_OUTTAB = <IT_TABLE>

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

regards,

venkat.

Read only

Former Member
0 Likes
1,282

Hi Santosh,

try with this FM DB_GET_TABLE_FIELDS

Read only

Former Member
0 Likes
1,281

Hi,

Use this Table- DD03L . Give the table name and u will get all the fields.

Regards

Sandipan

Read only

Former Member
0 Likes
1,281

Hi,

Please refer below:


data : gt_table LIKE dntab OCCURS 0 WITH HEADER LINE,

  CALL FUNCTION 'NAMETAB_GET'
   EXPORTING
     langu                     = sy-langu
     only                      = ' '
     tabname                   = ' ' "Pass the table or strcuture here
* IMPORTING
*   HEADER                    =
*   RC                        =
    TABLES
      nametab                   = gt_table
   EXCEPTIONS
     internal_error            = 1
     table_has_no_fields       = 2
     table_not_activ           = 3
     no_texts_found            = 4
     OTHERS                    = 5          .

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Now you will have field, description, domain and data element everything is gt_table.

Thanks.

Sriram Ponna.