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

Building dynamic internal tables

Former Member
0 Likes
834

Hi all-

Need to know how I can dynamically create an internal table-

The data I have in one internal table is as follows:

VBELN DATE NUMBER

123 5/2/05 3

123 5/7/05 4

123 5/8/05 6

456 5/1/05 1

456 5/2/05 3

.....

From the data in this internal table

I want to create a new internal table that has the following entries:

Entry 1:

BEDID DATE1 Num DATE2 Num DATE3 Num

123 5/2/05 3 5/7/05 4 5/8/05 6

Entry 2:

BEDID DATE1 Num DATE2 Num

456 5/1/05 1 5/2/05 3

so basically building one entry per BEDID for all of the dates and number.

But the number of date entries per BEDID is dynamic.

Thanks for ideas on how to accomplish this efficiently!

1 ACCEPTED SOLUTION
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
743

Hi C K

Check out the class "<b>CL_ALV_TABLE_CREATE</b>". Try its method called "<b>CREATE_DYNAMIC_TABLE</b>". It is some easy just prepare a field catalog and call the method to give reference of dynamically created table.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Hi C K

Check out the class "<b>CL_ALV_TABLE_CREATE</b>". Try its method called "<b>CREATE_DYNAMIC_TABLE</b>". It is some easy just prepare a field catalog and call the method to give reference of dynamically created table.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

4 REPLIES 4
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
744

Hi C K

Check out the class "<b>CL_ALV_TABLE_CREATE</b>". Try its method called "<b>CREATE_DYNAMIC_TABLE</b>". It is some easy just prepare a field catalog and call the method to give reference of dynamically created table.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

0 Likes
743

Thank you Serder! Please clarify where I would find this information?

Read only

0 Likes
743

Here is a quick and dirty sample program.

This should get you started.



report zrich_0001.

type-pools: slis.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.

selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.

start-of-selection.

* build the dynamic internal table
  perform build_dyn_itab.

* write 5 records to the alv grid
  do 5 times.
    perform build_report.
  enddo.

* call the alv grid.
  perform call_alv.


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

  data: new_table type ref to data,
        new_line  type ref to data,
        wa_it_fldcat type lvc_s_fcat.

* Create fields .
  do p_flds times.
    clear wa_it_fldcat.
    wa_it_fldcat-fieldname = sy-index.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
  enddo.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = it_fldcat
               importing
                  ep_table        = new_table.

  assign new_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data new_line like line of <dyn_table>.
  assign new_line->* to <dyn_wa>.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: <fs1>.

  do p_flds times.

    index = sy-index.

* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.

    assign component  index  of structure <dyn_wa> to <fs1>.
    <fs1> =  fieldvalue.

  enddo.

* Append to the dynamic internal table
  append <dyn_wa> to <dyn_table>.


endform.

************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.

  data: wa_cat like line of alv_fldcat.

  do p_flds times.
    clear wa_cat.
    wa_cat-fieldname = sy-index.
    wa_cat-seltext_s = sy-index.
    wa_cat-outputlen = '5'.
    append wa_cat to alv_fldcat.
  enddo.


* Call ABAP List Viewer (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat = alv_fldcat
       tables
            t_outtab    = <dyn_table>.

endform.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
743

Thanks you!