‎2020 Jan 01 1:59 PM
Hello Experts,
I have a requirement for creating nested dynamic table.
Example -
create dynamic table(<TAB1>)
using above created dynamic table create a nested dynamic table (<TAB2>).
i tried with below code but unable to create nested dynamic table.
let me know if there is any other process to create nested dynamic table.
Thanks in advance.
DATA:
lt_comptab TYPE cl_abap_structdescr=>component_table,
ls_comp LIKE LINE OF lt_comptab,
lt_comptab2 TYPE cl_abap_structdescr=>component_table,
ls_comp2 LIKE LINE OF lt_comptab,
lref_newstr TYPE REF TO cl_abap_structdescr,
lref_tab_type TYPE REF TO cl_abap_tabledescr,
lt_fcat TYPE lvc_t_fcat,
ls_fcat TYPE lvc_s_fcat,
ls_dd03p TYPE dd03p,
lt_data type ref to data,
lt_data2 type ref to data.
field-symbols: <fs_table> type standard table.
field-symbols: <fs_table2> type standard table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SCARR'
CHANGING
ct_fieldcat = lt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_fcat INTO ls_fcat.
IF ls_fcat-ref_table IS NOT INITIAL.
CLEAR ls_dd03p.
CALL FUNCTION 'BUS_DDFIELD_GET'
EXPORTING
i_tabnm = ls_fcat-ref_table
i_fldnm = ls_fcat-fieldname
IMPORTING
e_dd03p = ls_dd03p
EXCEPTIONS
field_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
ls_comp-name = ls_fcat-fieldname.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_dd03p-rollname ).
APPEND ls_comp TO lt_comptab.
CLEAR ls_comp.
ENDIF.
ELSE.
ls_comp-name = ls_fcat-fieldname.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_fcat-rollname ).
APPEND ls_comp TO lt_comptab.
CLEAR ls_comp.
ENDIF.
ENDLOOP.
CLEAR ls_fcat.
lref_newstr = cl_abap_structdescr=>create( lt_comptab ).
lref_tab_type = cl_abap_tabledescr=>create( lref_newstr ).
create data lt_data type handle lref_tab_type.
assign lt_data->* to <fs_table>.
ls_fcat-fieldname = 'NESTED_TABLE'.
*ls_fcat-inttype = 'CHAR'.
*ls_fcat-intlen = 000006.
ls_fcat-rollname = <fs_table>. "For SFLIGHT
APPEND ls_fcat TO lt_fcat.
ls_comp2-name = ls_fcat-fieldname.
ls_comp2-type ?= cl_abap_datadescr=>describe_by_name( ls_fcat-rollname ).
APPEND ls_comp2 to lt_comptab2.
DATA(lref_newstr2) = cl_abap_structdescr=>create( lt_comptab ).
DATA(lref_tab_type2) = cl_abap_tabledescr=>create( lref_newstr2 ).
create data lt_data2 type handle lref_tab_type2.
assign lt_data2->* to <fs_table2>.
‎2020 Jan 01 4:03 PM
I'm not sure to understand what type you want to obtain (I see SCARR fields, NESTED_TABLE, SFLIGHT fields), and what is the issue you are facing, so it's difficult to answer precisely. Can you show roughly what type you want to obtain with TYPES statements?
‎2020 Jan 02 6:25 AM
Hi Sandra Rossi,
Thanks for responding to my query.
Below is detailed explanation of my requirement.
with fields from SCARR structure i have created dynamic internal table <FS_TABLE>.
now I want to created deep dynamic table<FS_TABLE2> using dynamic table <FS_TABLE>.
below is structure of dynamic deep table.
Nested_table <FS_TABLE> 1 table dataThanks in advance
‎2020 Jan 02 8:05 AM
Please don't "answer", instead use the "Comment" button.
You should only submit an answer when you are proposing a solution to the poster's problem.
‎2020 Jan 02 8:11 AM
Sorry, I still REALLY don't understand. Why did you mention SFLIGHT in the comments of your initial code? Please provide the type you want with TYPES.
Let me help you, please update this code as you wish:
TYPES: BEGIN OF ts_deep,
nested_table TYPE STANDARD TABLE OF scarr WITH EMPTY KEY,
END OF ts_deep,
tt_deep TYPE STANDARD TABLE OF ts_deep WITH EMPTY KEY.
‎2020 Jan 03 3:36 AM
Hi Sandra Rossi,
Below is types structure.
TYPES: BEGIN OF ts_str,
CARRID type S_CARR_ID,
CARRNAME type S_CARRNAME,
CURRCODE type S_CURRCODE,
URL type S_CARRURL,
nested_table TYPE STANDARD TABLE OF scarr WITH EMPTY KEY,
END OF ts_str,
tt_str type standard table of ts_scarr,
begin of ts_deep,
nested_str type char30,
tab type standard table of ts_str,
end of ts_deep,
tt_deep TYPE STANDARD TABLE OF ts_deep WITH EMPTY KEY.
in above types TT_STR i want to create dynamically in run time.
and using TT_STR want to create dynamic deep structure TT_DEEP.
Thanks in advance.
‎2020 Jan 03 8:03 AM
Thank you, I will answer in a moment.
NB: please use Comment, don't use "Answer"/button "Submit the answer", as SAP says:
You should only submit an answer when you are proposing a solution to the poster's problem
‎2020 Jan 03 9:00 AM
If you want to obtain dynamically the type TT_DEEP and all types used by it, so that it's equivalent to this static code (I used DEFAULT instead of EMPTY so that to shorten my answer):
TYPES: BEGIN OF ts_str,
CARRID type S_CARR_ID,
CARRNAME type S_CARRNAME,
CURRCODE type S_CURRCODE,
URL type S_CARRURL,
nested_table TYPE STANDARD TABLE OF scarr WITH DEFAULT KEY,
END OF ts_str,
tt_str type standard table of ts_scarr WITH DEFAULT KEY,
begin of ts_deep,
nested_str type char30,
tab type tt_str,
end of ts_deep,
tt_deep TYPE STANDARD TABLE OF ts_deep WITH DEFAULT KEY.It corresponds to this pseudo code:
data(rtts_tt_scarr) = CL_ABAP_TABLEDESCR=>get( p_line_type
= cast #( cl_abap_typedescr=>describe_by_name( 'SCARR' ) ) ).
data(rtts_ts_str) = CL_ABAP_STRUCTDESCR=>get( value #(
( name = 'CARRID' type = cast #( cl_abap_typedescr=>describe_by_name( 'SCARR-CARRID' ) ) )
" ...
( name = 'NESTED_TABLE' type = rtts_tt_scarr ) ) ).
data(rtts_tt_str) = CL_ABAP_TABLEDESCR=>get( p_line_type = rtts_ts_str ).
data(rtts_ts_deep) = CL_ABAP_STRUCTDESCR=>get( value #(
( name = 'NESTED_STR' type = cast #( cl_abap_typedescr=>describe_by_name( 'CHAR30' ) ) )
( name = 'TAB' type = rtts_tt_str ) ) ).
data(rtts_tt_deep) = CL_ABAP_TABLEDESCR=>get( p_line_type = rtts_ts_deep ).