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

Issue with determing table name runtime

Former Member
0 Likes
525

Hi All,

I have a problem in determing the table name during runtime

TABLES : ekko.

DATA : test TYPE REF TO lcl_test.
DATA : itab TYPE STANDARD TABLE OF ekko.

IF test IS INITIAL.
    CREATE OBJECT test.
  ENDIF.
test->cmeth( EXPORTING itab1 = itab ).

CLASS lcl_test DEFINITION.

  PUBLIC SECTION.

    METHODS : cmeth IMPORTING itab1 TYPE STANDARD TABLE.

ENDCLASS.                    


*----------------------------------------------------------------------*
*       CLASS lcl_test IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test IMPLEMENTATION.

METHOD test.

*Here i have to know the table name of the importing internal data itab1 (In this particular case its EKKO)

*In general it can be any table 

*Is there a way to determine a table name (as EKKO) in this method

*My problem is i need to find out the field of that internal table

*to find out the fields of the  table i'm using 

CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'I need to pass header of the internal table something like wa_ekko'
TABLES
components = icomp.


** so i have to find out the table name and declare a work area and then pass that to Get_component_list FM*


OR 


I CAN USE BELOW CODE AS WELL

data:
    wa_ref        type ref to data,
    desc_table    type ref to cl_abap_tabledescr,
    desc_struc    type ref to cl_abap_structdescr.
  field-symbols:
    <p_data>      type any,
    <p_field>     type any,
    <p_component> type abap_compdescr.




** The probelm  here is it_data has s tructure defined in class unlike mine  with is type standard table*
create data wa_ref like line of it_data.
  assign wa_ref->* to <p_data>.
 desc_table ?= cl_abap_tabledescr=>describe_by_data( it_data ).
  desc_struc ?= desc_table->get_table_line_type( ).


loop at it_data assigning <p_data>.
    loop at desc_struc->components assigning <p_component>.
 
        assign component <p_component>-name of structure <p_data> to <p_field>.
    endloop.
  endloop.

endmethod.

Hope i'm clear

Thanks

David

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
498

Hi

Perhaps something like this can help you:

TABLES : EKKO.


DATA : ITAB TYPE STANDARD TABLE OF EKKO.
*
CLASS LCL_TEST DEFINITION.

  PUBLIC SECTION.

    METHODS : CMETH IMPORTING ITAB1 TYPE STANDARD TABLE.

ENDCLASS.                    "lcl_test DEFINITION
*
CLASS LCL_TEST IMPLEMENTATION.

  METHOD CMETH.
    DATA: MY_WA       TYPE REF TO DATA.
    DATA: DESC_TABLE    TYPE REF TO CL_ABAP_TABLEDESCR,
          DESC_STRUC    TYPE REF TO CL_ABAP_STRUCTDESCR.
    FIELD-SYMBOLS:
         <P_DATA>      TYPE ANY,
         <P_FIELD>     TYPE ANY,
         <P_COMPONENT> TYPE ABAP_COMPDESCR.


    CREATE DATA MY_WA LIKE LINE OF ITAB1.
    ASSIGN MY_WA->* TO <P_DATA>.

    DESC_STRUC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <P_DATA> ).

    LOOP AT DESC_STRUC->COMPONENTS ASSIGNING <P_COMPONENT>.
      WRITE: / <P_COMPONENT>-NAME.
    ENDLOOP.
  ENDMETHOD.                    "test
ENDCLASS.                    "lcl_test IMPLEMENTATION


DATA : TEST TYPE REF TO LCL_TEST.

START-OF-SELECTION.

  IF TEST IS INITIAL.
    CREATE OBJECT TEST.
  ENDIF.

  TEST->CMETH( EXPORTING ITAB1 = ITAB ).

Max

4 REPLIES 4
Read only

former_member191735
Active Contributor
0 Likes
498
    • so i have to find out the table name and declare a work area and then pass that to Get_component_list FM*

Why not field symbol instead of work area. Field symbol type any

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
498

Hello,

Does the attribute ABSOLUTE_NAME of class CL_ABAP_STRUCTDESCR / CL_ABAP_TABLEDESCR be of any help?

I added this line to Max's code & works (but you need a lil' formatting):

WRITE: desc_struc->absolute_name.

Output:

\TYPE=EKKO

So may be if you format you will get EKKO

BR,

Suhas

Read only

Former Member
0 Likes
499

Hi

Perhaps something like this can help you:

TABLES : EKKO.


DATA : ITAB TYPE STANDARD TABLE OF EKKO.
*
CLASS LCL_TEST DEFINITION.

  PUBLIC SECTION.

    METHODS : CMETH IMPORTING ITAB1 TYPE STANDARD TABLE.

ENDCLASS.                    "lcl_test DEFINITION
*
CLASS LCL_TEST IMPLEMENTATION.

  METHOD CMETH.
    DATA: MY_WA       TYPE REF TO DATA.
    DATA: DESC_TABLE    TYPE REF TO CL_ABAP_TABLEDESCR,
          DESC_STRUC    TYPE REF TO CL_ABAP_STRUCTDESCR.
    FIELD-SYMBOLS:
         <P_DATA>      TYPE ANY,
         <P_FIELD>     TYPE ANY,
         <P_COMPONENT> TYPE ABAP_COMPDESCR.


    CREATE DATA MY_WA LIKE LINE OF ITAB1.
    ASSIGN MY_WA->* TO <P_DATA>.

    DESC_STRUC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <P_DATA> ).

    LOOP AT DESC_STRUC->COMPONENTS ASSIGNING <P_COMPONENT>.
      WRITE: / <P_COMPONENT>-NAME.
    ENDLOOP.
  ENDMETHOD.                    "test
ENDCLASS.                    "lcl_test IMPLEMENTATION


DATA : TEST TYPE REF TO LCL_TEST.

START-OF-SELECTION.

  IF TEST IS INITIAL.
    CREATE OBJECT TEST.
  ENDIF.

  TEST->CMETH( EXPORTING ITAB1 = ITAB ).

Max

Read only

0 Likes
498

Thank you all for your help