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

Dynamic programming using cl_abap_typedescr

IanStubbings
Active Participant
0 Likes
414

I have created a field catalog for an ALV grid dynamically using cl_alv_table_create=>create_dynamic_table (I am on 46B and cannot use the new version). How do I create the structure and therefore internal table to pass into the it_outtab parameter of the ALV grid set_table_for_first_display

method? I can create a blank table with the correct dynamic columns but now wish to populate it without much success! I am retrieving the type using cl_abap_typedescr=>describe_by_data and can cycle through the key but how do I just obtain the structure?

Cheers

Ian

cl_abap_typedescr to retrieve the column names of a dynamic table I have created for using with an ALV grid

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
369

Hi,

Use ASSIGN r_dyn_table->* TO <t_dyn_table> to get access to the dynamic table. To append rows to it, you should use ASSIGN COMPONENT idx/name OF STRUCTURE struc TO <fs>.

Example:

data: tab_fields like table of wa_fields,

r_dyn_table TYPE REF TO data,

r_wa_dyn_table TYPE REF TO data,

f_int type i.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = F_TAB_FCAT

IMPORTING

ep_table = r_dyn_table

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

ASSIGN r_dyn_table->* TO <t_dyn_table>.

CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.

ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.

DESCRIBE TABLE tab_fields lines f_int.

do f_int times.

READ TABLE tab_fields INDEX sy-index into wa_fields.

ASSIGN wa_fields-field TO <w_field1>.

check1 = sy-subrc.

ASSIGN COMPONENT sy-index

OF STRUCTURE <wa_dyn_table> TO <w_field2>.

check2 = sy-subrc.

if check1 = 0 and check2 = 0.

<w_field2> = <w_field1>.

endif.

enddo.

Svetlin

2 REPLIES 2
Read only

Former Member
0 Likes
370

Hi,

Use ASSIGN r_dyn_table->* TO <t_dyn_table> to get access to the dynamic table. To append rows to it, you should use ASSIGN COMPONENT idx/name OF STRUCTURE struc TO <fs>.

Example:

data: tab_fields like table of wa_fields,

r_dyn_table TYPE REF TO data,

r_wa_dyn_table TYPE REF TO data,

f_int type i.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = F_TAB_FCAT

IMPORTING

ep_table = r_dyn_table

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

ASSIGN r_dyn_table->* TO <t_dyn_table>.

CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.

ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.

DESCRIBE TABLE tab_fields lines f_int.

do f_int times.

READ TABLE tab_fields INDEX sy-index into wa_fields.

ASSIGN wa_fields-field TO <w_field1>.

check1 = sy-subrc.

ASSIGN COMPONENT sy-index

OF STRUCTURE <wa_dyn_table> TO <w_field2>.

check2 = sy-subrc.

if check1 = 0 and check2 = 0.

<w_field2> = <w_field1>.

endif.

enddo.

Svetlin

Read only

0 Likes
369

Thanks Svetlin, I had got down to the Assign component on my own but that gave me the final nudge.

Cheers

Ian