‎2009 Nov 20 3:56 PM
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
‎2009 Nov 20 4:25 PM
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
‎2009 Nov 20 4:12 PM
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
‎2009 Nov 20 4:23 PM
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=EKKOSo may be if you format you will get EKKO
BR,
Suhas
‎2009 Nov 20 4:25 PM
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
‎2009 Nov 20 4:40 PM