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

move data from static to dynamic itab

Former Member
0 Likes
470

Hi,

I was able to create a structure for dynamic internal table for the specific requirement below.

How ever. I am finding it hard to move data to this new dynamic table.

Any expert suggestions would be greatlt appreciated.

OP QUAN DATE

1 2 10/10/2009

2 3 10/10/2009

3 2 11/10/2009

4 1 12/10/2009

Output table should look like this ( there are 3 different dates in above input and my output should have 3 additional columns and quan should fall under date)

OP 10/10/2009 11/10/2009 12/10/2009

1 2

2 3

3 2

4 1

I was able to move the OP field as this is common across 2 tables. But unable to find a logic to send QUAN field under specific date in the 2 nd table.

Thanks,

Bill

3 REPLIES 3
Read only

Former Member
0 Likes
415

Sorry the tab delimitation in second table is out of sync in my previous post.

Here is how the 2 nd table data should look like

OP 10/10/2009 11/10/2009 12/10/2009

1 2 - -

2 3 - -

3 - 2 -

4 - - 1

quan field value should follow under respective dates

Read only

0 Likes
415

Hi,

try the following logic. I could not verify it in the system, so I hope my syntax is okay...


DATA: dates_itab TYPE [same type as source_itab],
      source_tab_iterator LIKE LINE OF source_itab,
      target_tab_line LIKE LINE OF target_tab,
      col_index TYPE i.

FIELD-SYMBOLS: <target_col> LIKE source_tab-quan.
                " ^ I assume the dynamic columns of the target itab
                "   have this data type...

* Get all the distinct dates of the source itab into table dates_itab
dates_itab = source_itab.
SORT dates_itab BY date.
DELETE ADJACENT DUPLICATES FROM dates_itab COMPARING date.

* Now iterate over the source itab and populate the target table
LOOP AT source_itab INTO source_tab_iterator.
  CLEAR target_tab_line.
  target_tab_line-op = source_tab_iterator-op.
  READ TABLE dates_itab TRANSPORTING NO FIELDS
        WITH KEY date = source_tab_iterator-date
        BINARY SEARCH.
  col_index = sy-index + 1.    "first date is column 2, second is colum 3, etc.
  ASSIGN COMPONENT col_index OF STRUCTURE target_tab_line TO <target_col>.
  <target_col> = source_tab_iterator-quan.
  APPEND target_tab_line TO target_itab.
ENDLOOP.

Regards,

David

Read only

0 Likes
415

Hi billbala,

I think this can be done creating a dynamic table using RTTS runtime type services cl_abap_typedesc and others.The column (field) names can't be like 10/10/2009, but D_20091010 would be possible. In ALV grid you could set the column header as 10/10/2009.

But I can't get your logic because everything is posted unformatted. Select with mouse, push above <_> code button and use preview to check.

Why 41 becomes 4--1?

Regards,

Clemens