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 ALV construct with dynamic table

Former Member
0 Likes
562

Hi experts !

I want to display a dynamic alv with the result of a first alv grid.

I explain with an exemple :

my first alv contains these rows :

pers. nbr. / data1 /... / Wage Type / ... / amount / - > (fieldcat header)

01........... /........../..../ 101 / / 1u20AC /

01........... /........../..../ 560 / / 2u20AC /

01........... /........../..../ 1000 / / 3u20AC /

01........... /........../..../ 1001 / / 4u20AC /

02........... /........../..../ 101 / / 5u20AC /

02........... /........../..../ 560 / / 6u20AC /

02........... /........../..../ 1000 / / 7u20AC /

02........... /........../..../ 1001 / / 8u20AC /

An i want this result :

pers. nbr. / data1 / data2 / ... /101 /560/1000/1001 - > (fieldcat header)

01 / / / / 1u20AC / 2u20AC /3u20AC / 4u20AC

02 / / / / 5u20AC / 6u20AC /7u20AC / 8u20AC

for the moment with help of fields symbols and "cl_alv_table_create=>create_dynamic_table" fonction, i've got only this result :

pers. nbr. / data1 / data2 / ... /101 /560/1000/1001 - > (fieldcat header)

01 / / / / ? / ? / ? / ?

02 / / / / ? / ? / ? / ?

i don't know how to put the corresponding values on the correponding column because my table is dynamic and i don't know the fiels number or name.

here is my code :


* creation of dynamic internal table
  ASSIGN lt_data TO <fs_data>.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = lv_fieldcat3
    IMPORTING
      ep_table                  = <fs_data>
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
  IF sy-subrc <> 0.
  ENDIF.

* So  now points to our dynamic internal table.
  ASSIGN <fs_data>->* TO <fs_1>.
* Next step is to create a work area for our dynamic internal table.
  CREATE DATA new_line LIKE LINE OF <fs_1>.
* A field-symbol to access that work area
  ASSIGN new_line->*  TO <fs_2>.


 LOOP AT lt_datatable +(my first table)+ ASSIGNING <ls_data4>.
    ASSIGN COMPONENT column
    OF STRUCTURE <ls_data4> TO <fs_2>+[where ????]+.
    AT NEW pernr.
      MOVE-CORRESPONDING <ls_data4> TO <fs_2>.
      APPEND <fs_2> TO <fs_1>.
    ENDAT.
 ENDLOOP.

I hope i'm understanding with my poor english !

Thanks all...

Edited by: ronando on Mar 12, 2009 4:06 PM

Edited by: ronando on Mar 12, 2009 4:30 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
530

You don't know the names of your columns? hmm you do, because before you created dynamic table you had to create field catalog, so the structure and column names of newly (dynamically) created table will be the same like defined in the field catalog.

The last loop also does not look good, in my opinion should be something like:

LOOP AT lt_datatable +(my first table)+ ASSIGNING <ls_data4>.
    AT NEW pernr.
      APPEND initial line to <fs_1> assigning <fs_2>.
      <fs_2>-pernr = <ls_data4>-pernr.
      ....
    ENDAT.
    ASSIGN COMPONENT <ls_data4>-wage_type OF STRUCTURE <fs_2> TO <fs_5>.
    <fs_5> = <ls_data4>-amount.
 ENDLOOP.

also keep in mind that number of calls of method cl_alv_table_create=>create_dynamic_table is limited to 36 (?) calls within one program session because it uses dynamic subroutine pool behind so you will have short dump if you will execute that 37 times.

4 REPLIES 4
Read only

Former Member
0 Likes
530

sorry, I accidentally pressed publish, my full post below.

Edited by: Marcin.Podkowinski on Mar 12, 2009 4:46 PM

Read only

former_member376453
Contributor
0 Likes
530

Try this link :http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html

Kuntal

Read only

Former Member
0 Likes
531

You don't know the names of your columns? hmm you do, because before you created dynamic table you had to create field catalog, so the structure and column names of newly (dynamically) created table will be the same like defined in the field catalog.

The last loop also does not look good, in my opinion should be something like:

LOOP AT lt_datatable +(my first table)+ ASSIGNING <ls_data4>.
    AT NEW pernr.
      APPEND initial line to <fs_1> assigning <fs_2>.
      <fs_2>-pernr = <ls_data4>-pernr.
      ....
    ENDAT.
    ASSIGN COMPONENT <ls_data4>-wage_type OF STRUCTURE <fs_2> TO <fs_5>.
    <fs_5> = <ls_data4>-amount.
 ENDLOOP.

also keep in mind that number of calls of method cl_alv_table_create=>create_dynamic_table is limited to 36 (?) calls within one program session because it uses dynamic subroutine pool behind so you will have short dump if you will execute that 37 times.

Read only

0 Likes
530

Thank your for reactivity,

OK Now it's work !!!

i don't really understand why <fs5> it's needed but it's OK.

Here is the final code :

LOOP AT lt_datatable ASSIGNING <ls_data4>.
     AT NEW pernr.
      APPEND INITIAL LINE TO <fs_1> ASSIGNING <fs_2>.
      MOVE-CORRESPONDING <ls_data4> TO <fs_2>.
    ENDAT.
    REPLACE '/' WITH '' INTO <ls_data4>-LGART.
    ASSIGN COMPONENT <ls_data4>-LGART OF STRUCTURE <fs_2> TO <fs_5>.
    <fs_5> = <ls_data4>-BETRG.
 ENDLOOP.

Thanks you very much !

Edited by: ronando on Mar 12, 2009 6:23 PM