Application Development 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: 

Dynamic table - some fields of different rows in one column

Former Member
0 Kudos

Hey guys,

i have the following problem:

i habe a itab with some data like:

name | id | date | number

pete | 1 | 27.07 | 2

pete | 1 | 28.07 | 2

pete | 1 | 30.07 | 2

ann | 1 | 28.07 | 3

ann | 2 | 30.07 | 2

the user can define a period of time, e.g. 28-29.07

so my dynamic table will consist of the "hard" columns name and id and the dynamic added columns for every day:

name | id | 28.07 | 29.07

that's what i already have!

so my problem is, that i have to read the data from the itab into the new dynamic table (field-symbol) like:

name | id | 28.07 | 29.07

pete | 1 | 2 | 2

ann | 1 | 3 | -

i hope you can understand what i want! please give me code sample or a example report!

many thanks in adance!

best regards,

ludwig

1 ACCEPTED SOLUTION

franois_henrotte
Active Contributor
0 Kudos

you just have to create your dynamic table

the easiest way is to call function ALV_TABLE_CREATE : it will create an internal table based on a field catalog

10 REPLIES 10

franois_henrotte
Active Contributor
0 Kudos

you just have to create your dynamic table

the easiest way is to call function ALV_TABLE_CREATE : it will create an internal table based on a field catalog

0 Kudos

but i have already my itab... i have to match the fields from my itab to the the rows of my dynamic field symbol!

i hoped, the example would show this!

I already have my itab and my (empty) field-symbol with the output structure... so what i want is to transport some rows of my itab to one row of my field-symbol, like in my example above!

0 Kudos

Hi Ludwig,

Follow the below logic for your requirement

assume <gt_alv1_data> is your dynamic table created from users input and gt_alv1_data is your normal internal table.


  FIELD-SYMBOLS: <gt_alv_wa> type any,
                              <gt_alv_field> type any.

  CREATE DATA gref_alv_line LIKE LINE OF <gt_alv1_data>.
  ASSIGN gref_alv_line->* TO <gt_alv_wa>.

    ASSIGN COMPONENT '28.07'
                  OF STRUCTURE <gt_alv_wa>
                  TO <gt_alv_field>.

  MOVE GT_ALV1_DATA-NUMBER TO <gt_alv_field>.

In this way you can move value from normal internal table to dynamic internal table field

Cheers,

Kothand

0 Kudos

Hi

If you have already created the dynamic table with days.

Lets consider the table name is <fs_dyn_table> and work area is <fs_work_area>.

LOOP AT itab.

  ASSIGN COMPONENT 'NAME' OF STRUCTURE <fs_work_area> TO <fs_field>.  
  <fs_field> = itab-name.
  
  ASSIGN COMPONENT 'ID' OF STRUCTURE <fs_work_area> TO <fs_field>.
  <fs_field> = itab-id.
  
  ASSIGN COMPONENT itab-date OF STRUCTURE <fs_work_area> TO <fs_field>.
  <fs_field> = itab-number.
  
  COLLECT <fs_work_area> INTO <fs_dyn_table>.
  
ENDLOOP.

0 Kudos

hey Asik, you have understand what i want!

here is my table:

http://img181.imageshack.us/my.php?image=wh20080916113004ym8.png

after the loop, the 4 rows should be in my field-symbol only one row (no sum)!

but after the loop, there are to many rows! only one row is needed!

Look at the screenshot:

http://img185.imageshack.us/my.php?image=wh20080916113547wl0.png

So the second row at column "tag20080801" should be initial and with the next loop, the next day "tag20080730" should be filled with the number!


LOOP AT LT_OUT INTO LS_OUT.

  ASSIGN COMPONENT 'RESSOURCEN' OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = 'Ressource'.

  ASSIGN COMPONENT 'NAME' OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = LS_OUT-name.

  ASSIGN COMPONENT 'PROJEKT' OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = LS_OUT-PROJECTID.

  CONCATENATE 'DATE' LS_OUT-DATE INTO LF_DATE_COL.

  ASSIGN COMPONENT LF_DATE_COL OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = LS_OUT-COUNT.

  COLLECT <FS_LINE> INTO <FS_TABLE>.

ENDLOOP.

the right output data should look like this:

Ressourcen | Ludwig Heinz | 20080702LHZ | 4 | 4 | 4 | 1

0 Kudos

Hi Heinz,

Don't use COLLECT then. Do in the following way.

SORT LT_OUT BY NAME. " >> Change in Here <<

LOOP AT LT_OUT INTO LS_OUT.
 
  ASSIGN COMPONENT 'RESSOURCEN' OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = 'Ressource'.
 
  ASSIGN COMPONENT 'NAME' OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = LS_OUT-name.
 
  ASSIGN COMPONENT 'PROJEKT' OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = LS_OUT-PROJECTID.
 
  CONCATENATE 'DATE' LS_OUT-DATE INTO LF_DATE_COL.
 
  ASSIGN COMPONENT LF_DATE_COL OF STRUCTURE <FS_LINE> TO <fs_field>.
  <fs_field> = LS_OUT-COUNT.
    
  AT END OF NAME. " >> Change in Here <<
    APPEND <FS_LINE> TO <FS_TABLE>. " For every name one record will be created
  ENDAT.
 
ENDLOOP.

0 Kudos

Thats 90% of my problem...thanks!!!!!!

only one little thing:

http://img354.imageshack.us/my.php?image=wh20080916120757wx7.png

ludwig heinz has two projects... and the project 20080702LHZ has only one day day20080801 (and not as in the itab all days filled)!

have you any solution for this?

0 Kudos

Hi Heinz,

As per my understanding you are not clearing the work area <FS_LINE>.

Clear it once you append it.


AT END OF NAME.
  APPEND <FS_LINE> TO <FS_TABLE>. 
  CLEAR: <FS_LINE>.  " >> Change in Here <<
ENDAT.

0 Kudos

Great! You solved it! Many many thanks!

Former Member
0 Kudos

Hi ,

As you said you have the internal table say itab which already holds the records.

Just that you need to copy this data into a dynamic table .

You need to use field symbols,datareferences and RTTS(Runtime type services) to acheive this.

data: dbref TYPE REF TO data.

FIELD-SYMBOLS:<fs_itab> TYPE STANDARD TABLE, "This will refer to any table

<fs_field> TYPE ANY.

linetype ?= cl_abap_typedescr=>describe_by_name( itab ).

comp_tab = linetype->get_components( ).

tabtype = cl_abap_tabledescr=>create(

p_line_type = linetype ).

SELECT * from (itab) INTO TABLE <fs_itab>