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

Convert Dynamic internal table to internal table

Former Member
0 Likes
7,545

Hi All,

   

        I have created a Dynamic internal table using field symbols.  Now i need to conver that dynamic itab to another normal internal table . Can anybody tell me how can i convert that dyn_itab to another itab.

Code which i used for create dynamic table:

   CALL METHOD cl_alv_table_create=>create_dynamic_table

     EXPORTING

       i_style_table             = 'X'

       it_fieldcatalog           = it_fcat1

     IMPORTING

       ep_table                  = gt_dyn_table

     EXCEPTIONS

       generate_subpool_dir_full = 1

       OTHERS                    = 2.

   ASSIGN gt_dyn_table->* TO <l_table>.

   CREATE DATA new_line LIKE LINE OF <l_table>.

   ASSIGN new_line->* TO <l_line>.

Hi All,

   

        I have created a Dynamic internal table using field symbols.  Now i need to conver that dynamic itab to another normal internal table . Can anybody tell me how can i convert that dyn_itab to another itab.

Code which i used for create dynamic table:

   CALL METHOD cl_alv_table_create=>create_dynamic_table

     EXPORTING

       i_style_table             = 'X'

       it_fieldcatalog           = it_fcat1

     IMPORTING

       ep_table                  = gt_dyn_table

     EXCEPTIONS

       generate_subpool_dir_full = 1

       OTHERS                    = 2.

   ASSIGN gt_dyn_table->* TO <l_table>.

   CREATE DATA new_line LIKE LINE OF <l_table>.

   ASSIGN new_line->* TO <l_line>.

9 REPLIES 9
Read only

Former Member
0 Likes
3,724

Hi Swapnil,

There is already dynamic Internal Table.

If you wish to have normal internal table then declare it and populate it via dynamic internal table.

What is the problem you are facing?

Read only

0 Likes
3,724

Thanks for your reply,

But i want to convert gt_dyn_table  dynamic table which is created  from field catalog  into Normal internal table. Because I want to apply loop on that table without field symbol .

Read only

0 Likes
3,724

You cannot convert since it's dynamic but you can create another static internal table and populate the data using dynamic internal table data.

Read only

0 Likes
3,724

We don't understand your problem very well,

you have a dynamic table, and you want to change it to static, to loop without <FS>.

so if you sure, which table ,

you can define structure ls_any_str   type  Sflight, ( EX)

loop at <lt_data> into ls_any_str.

ls_any_str-carrid..

endloop.

if you want to ask loop .. where ..... carrid =   ( Static )

so change dynamic to static,

lt_stat_tab = lt_dyna_table.

this is waht I understood, ,

so if it doesnt help you, so could you please explain more

thnx

Read only

0 Likes
3,724

i don't have any structure for that dynamic table . that dynamic table is created run time  with the help of that field catalog , And field catalogs columns is also not fix which  are getting added at run time dynamically. 

below code for that :

FIELD-SYMBOLS: <l_table> TYPE TABLE,

                <l_line>  TYPE ANY,

                <l_field> TYPE ANY.

DATA gt_dyn_table TYPE REF TO data,

         gw_line      TYPE REF TO data.

(Code to append field catalog)

   count = count + 1.

   wa_fcat1-col_pos = count.

   wa_fcat1-coltext = 'FR SALVAGE CUM %'.

   wa_fcat1-fieldname = 'CFSAL_PERC'.

   APPEND wa_fcat1 TO it_fcat1.

   CLEAR : wa_fcat1.

(Code to add dynamic columns to internal table of field catalog using another internal table ( it_proc1 ) entries )

   LOOP AT it_proc1 INTO wa_proc1.

     LOOP AT it_proc INTO wa_proc WHERE frr_def_no = wa_proc1-frr_def_no.

       count2 = count2 + 1.

     ENDLOOP.

     CONDENSE count3.

     CONCATENATE col count3 INTO count5.

     count  = count + 1.

     count3 = count3 + 1.

     wa_fcat1-col_pos = count.

     wa_fcat1-coltext = wa_proc1-frr_def.

     wa_fcat1-fieldname = count5.

     APPEND wa_fcat1 TO it_fcat1.

     CLEAR : wa_fcat1,count2.

   ENDLOOP .

   CALL METHOD cl_alv_table_create=>create_dynamic_table

     EXPORTING

       i_style_table             = 'X'

       it_fieldcatalog           = it_fcat1

     IMPORTING

       ep_table                  = gt_dyn_table

     EXCEPTIONS

       generate_subpool_dir_full = 1

       OTHERS                    = 2.

Now my requirement is i want static internal table of gt_dyn_table dynamic table.

Read only

Pavan_Golesar
Active Participant
0 Likes
3,724

This message was moderated.

Read only

former_member186741
Active Contributor
0 Likes
3,724

you could possibly create some dynamic abap to define the variable but this is awfully complicated and may not work. Why do you want to avoid using field-symbols? there should not be a problem accessing the dynamic table via them. Please explain your need for a static table.

Read only

matt
Active Contributor
0 Likes
3,724

You've got a dynamic table. You have to access in dynamically. There's no way around that. The whole idea of converting a dynamic table to a static table makes little sense. It's almost akin to asking for a supplier for four-sided triangles.

You are not stating your requirement, you are stating your preferred solution to your requirement. If you stated clearly your requirement you might get some help.

Handling dynamic tables is a FAQ and well covered and not that difficult. Hence I am locking this discussion.

Read only

mustafacengizde62
Participant
0 Likes
3,724

Hi,

I had a same situation, while i wanted to send my dynamic table as an Excel file. You can use your fieldcatalog and your dynamic table. You will have a table i_attachment (TYPE STANDARD TABLE OF solisti1.) Then you have all the lines of the internal table, that you want to have. But how to generate a new internal table, especially in runtime, is really a big issue. Maybe that helps you.

Best regards.

DATA : g_sent_to_all TYPE sonv-flag,
g_tab_lines TYPE i.

DATA : i_document_data TYPE STANDARD TABLE OF sodocchgi1,
i_packing_list TYPE STANDARD TABLE OF sopcklsti1,
i_attachment TYPE STANDARD TABLE OF solisti1,
i_body_msg TYPE STANDARD TABLE OF solisti1,
i_receivers TYPE STANDARD TABLE OF somlreci1.

DATA : w_document_data LIKE LINE OF i_document_data,
w_packing_list LIKE LINE OF i_packing_list,
w_attachment LIKE LINE OF i_attachment,
w_body_msg LIKE LINE OF i_body_msg,
w_receivers LIKE LINE OF i_receivers.

CLASS cl_abap_char_utilities DEFINITION LOAD.

CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

LOOP AT gt_fcat INTO gs_fcat.

CONCATENATE w_attachment gs_fcat-fieldname INTO w_attachment
SEPARATED BY con_tab.

ENDLOOP.

CONCATENATE con_cret w_attachment INTO w_attachment.
APPEND w_attachment TO i_attachment.
CLEAR: w_attachment, gs_fcat, <st_tab>.


LOOP AT <t_tab> INTO <st_tab>.

LOOP AT gt_fcat INTO gs_fcat.

ASSIGN COMPONENT gs_fcat-fieldname OF STRUCTURE <st_tab> TO <fs_val_2>.

IF NOT <fs_val_2> IS INITIAL .
CONCATENATE w_attachment <fs_val_2> INTO w_attachment SEPARATED BY con_tab.
ELSE.
CONCATENATE w_attachment ' ' INTO w_attachment SEPARATED BY con_tab.
ENDIF.

ENDLOOP.

CONCATENATE con_cret w_attachment INTO w_attachment.

APPEND w_attachment TO i_attachment.
CLEAR: w_attachment, <fs_val_2>.

ENDLOOP.

-------> ''i_attachment'' has the shape of the internal table that you want, line by line.