2007 Feb 15 8:07 AM
Hello ABAP Experts,
I like to get the structure name of an reference variable during the runtime, which is assign to a DDIC Table.
e.g.
<i>DATA: ref_tab TYPE REF TO data.
FIELD-SYMBOLS: <fs_sflight> type any.
create data ref_tab type table of sflight.
assign ref_tab to <fs_sflight></i>
How can I get now the name of the structure ('SFLIGHT') from 'ref_tab'. The reason is I like to call the ALV-GRID method 'SET_TABLE_FOR_FIRST_DISPLAY' to display the sflight data in field-symbol <fs_sflight>. Therefore I need a structure name.
Thank you very much for your answers.
Kind regards
Axel
Thank
Hello ABAP Experts,
I like to get the structure name of an reference variable during the runtime, which is assign to a DDIC Table.
e.g.
<i>DATA: ref_tab TYPE REF TO data.
FIELD-SYMBOLS: <fs_sflight> type any.
create data ref_tab type table of sflight.
assign ref_tab to <fs_sflight></i>
How can I get now the name of the structure ('SFLIGHT') from 'ref_tab'. The reason is I like to call the ALV-GRID method 'SET_TABLE_FOR_FIRST_DISPLAY' to display the sflight data in field-symbol <fs_sflight>. Therefore I need a structure name.
Thank you very much for your answers.
Kind regards
Axel
Thank
2007 Feb 15 8:39 AM
Hi
DATA: ref_tab TYPE REF TO data.
FIELD-SYMBOLS: <fs_sflight> type any.
create data ref_tab type table of sflight.
Ref_data = 'SFLIGHT'.
assign (ref_tab) to <fs_sflight>.Regards
Sudheer
2007 Feb 15 8:53 AM
Hi Sudheer,
Thank you for you answer, but my description was mybe not correct. I have a method which returns the content of a certain table e.g. Sflight but maybe the content of another structure.
The Method call looks like this:
Get the refernce variable (e.g. Sflight)
<i>gs_objects-object->get_details( IMPORTING et_details = lr_dtl ).
ASSIGN lr_dtl->* TO <fs_details>.
CALL METHOD go_alv_grid_dtl->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
i_structure_name = <b>"Here I need a structure name"</b>
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
it_outtab = <fs_details>
IT_FIELDCATALOG =
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
.</i>
Hopefully it makes it now more clear.
regards
Axel
2007 Feb 15 1:09 PM
Hello,
I have solved the issue like following. If somebody has a better solution don´t hesitate to post it here.
Regards
Axel
+DATA: lr_dtl TYPE REF TO data,
lo_typdesc TYPE REF TO cl_abap_typedescr,
lo_tabdesc TYPE REF TO cl_abap_tabledescr,
lo_strdesc TYPE REF TO cl_abap_structdescr,
lt_ddfield TYPE ddfields,
ls_ddfield TYPE LINE OF ddfields.
FIELD-SYMBOLS: TYPE ANY TABLE.+
get reference variable
gs_objects-object->get_details( IMPORTING et_details = lr_dtl ).
assign reference variable to field symbol
ASSIGN lr_dtl->* TO <fs_details>.
Object typ determine and create instance
+CALL METHOD cl_abap_typedescr=>describe_by_data_ref
EXPORTING
p_data_ref = lr_dtl
RECEIVING
p_descr_ref = lo_typdesc
EXCEPTIONS
reference_is_initial = 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.+
Widening Cast
cl_abap_tabledescr = cl_abap_typedescr
lo_tabdesc ?= lo_typdesc.
structure typ determination und create instance
+CALL METHOD lo_tabdesc->get_table_line_type
RECEIVING
p_descr_ref = lo_typdesc.+
Widening Cast
cl_abap_structdescr = cl_abap_typedescr
lo_strdesc ?= lo_typdesc.
get list of DDIC description and components
+ lt_ddfield = lo_strdesc->get_ddic_field_list( ).+
get DDIC-Structure name (Field: TABNAME)
READ TABLE lt_ddfield INTO ls_ddfield INDEX 1.
display ALV-GRID
+IF 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.+
2007 Feb 15 8:40 PM
Hello Axel,
first of all you need to get a Descriptor Object, maybe like that:
data:
rtti_Handle type ref to Cl_Abap_DataDesr.
rtti_Handle = cl_Abap_TypeDesc=>describe_By_Data_Ref( your_Ref ).
If this is already the structure handle go on. If this is a handle of the internal table some pre or follow up operations are necessary.
But assume this is the Handle for the Structure. Next you need to check if this is a DDic Type by calling method is_DDic_Type( ). Only in case this condition is true you may pass the type name to ALV. Non DDIC Type are not usable for this purpose!
You can get the type name now. Maybe there is a need to Remove the global type prefix (something like '\TYPE=TADIR') by splitting at the = sign.
Voila
Klaus
2007 Feb 16 8:42 AM
Hello Klaus,
thanks you for you answer. The Referenz Variable (LR_DTL) is pointing to an Internal Table, therefore I got as description object the type CL_ABAP_TABLEDESCR back. With this typ the methods "IS_DDIC_TYPE()" or "GET_RELATIVE_NAME" or not working. I did another widening cast with the method "GET_TABLE_LINE_TYPE()" and get the object of class CL_ABAP_STRUTDESC back. This object allows me to call the method "GET_RELATIVE_NAME", which gives me the correct DDIC-Structure name.
Please see coding below.
Regards
Axel
This statement gives me a Instance of Class CL_ABAP_TABLEDESCR back.
Widening Cast
lo_tabdesc ?= cl_abap_typedescr=>describe_by_data_ref( lr_dtl ).
This statement gives me a Instance of Class CL_ABAP_STRUCTDESCR back.
Widening Cast
lo_strdesc ?= lo_tabdesc->get_table_line_type( ).
Now I get the required DDIC Structure name
lv_tabname = lo_strdesc->get_relative_name( ).
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |