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

Create dynamic structure

Former Member
0 Likes
446

Is there any way to create a dynamic work-area, similar to cl_alv_table_create=>create_dynamic_table????

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
400

try the one in bold

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcatalog

IMPORTING

ep_table = new_table

EXCEPTIONS

generate_subpool_dir_full = 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.

<b>ASSIGN new_table->* TO <it_final>.

********CREATE WORK AREA***************************

CREATE DATA new_line LIKE LINE OF <it_final>.

ASSIGN new_line->* TO <wa_final>.</b>

2 REPLIES 2
Read only

Former Member
0 Likes
401

try the one in bold

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcatalog

IMPORTING

ep_table = new_table

EXCEPTIONS

generate_subpool_dir_full = 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.

<b>ASSIGN new_table->* TO <it_final>.

********CREATE WORK AREA***************************

CREATE DATA new_line LIKE LINE OF <it_final>.

ASSIGN new_line->* TO <wa_final>.</b>

Read only

Former Member
0 Likes
400

hi jose

You can try to do something like this:

DATA: BEGIN OF itab_in OCCURS 0,

field1,

field2,

field3,

fieldn,

END OF itab_in.

DATA: index(3) TYPE n.

DATA: t_lvc TYPE lvc_t_fcat,

w_lvc TYPE lvc_s_fcat.

FIELD-SYMBOLS: <new_itab> TYPE table,

<wa_itab> TYPE table.

DATA: new_tab TYPE REF TO data,

wa_tab TYPE REF TO data.

FIELD-SYMBOLS: <wa_out>, <wa_in>.

DATA: field_idx TYPE i.

START-OF-SELECTION.

  • Create the structure of new table

LOOP AT itab_in.

MOVE sy-tabix TO index.

CONCATENATE 'WC' index INTO w_lvc-fieldname.

.....................

APPEND w_lvc TO t_lvc.

ENDLOOP.

  • Create new table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_lvc

IMPORTING

ep_table = new_tab.

ASSIGN new_tab->* TO <new_itab>.

  • Create workarea

CREATE DATA wa_tab LIKE LINE OF <new_itab>.

ASSIGN wa_tab->* TO <wa_itab>.

  • Transfer data: n = Number of fields of ITAB_IN

DATA: n TYPE i.

do n times.

field_idx = field_idx + 1.

LOOP AT itab_in.

ASSIGN COMPONENT sy-tabix OF STRUCTURE <wa_itab> TO <wa_out>.

ASSIGN COMPONENT field_idx OF STRUCTURE itab_in TO <wa_in>.

ENDLOOP.

IF sy-subrc = 0.

APPEND <wa_itab> TO <new_itab>.

ENDIF.

ENDDO.

Regards

navjot

reward if helpfull