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

Populating Dynamic Tables

Former Member
0 Likes
995

Hi,

I have created a dynamic table using CALL METHOD cl_alv_table_create=>create_dynamic_table. However, I can't populate this with the source table. Below is my code:

FIELD-SYMBOLS:

<fs_dyn_table> TYPE STANDARD TABLE,

<fs_dyn_wa> TYPE ANY,

<fs_dyn_field> TYPE ANY.

DATA:

lv_dy_table TYPE REF TO data,

lv_dy_line TYPE REF TO data.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fieldcat

IMPORTING

ep_table = lv_dy_table.

ASSIGN lv_dy_table->* TO <fs_dyn_table>.

  • Create dynamic work area and assign to FS

CREATE DATA lv_dy_line LIKE LINE OF <fs_dyn_table>.

  • Get access to new work area using field symbol.

ASSIGN lv_dy_line->* TO <fs_dyn_wa>.

I have an internal table, it_XXXX. The data of the dynamic table will come from it_XXXX. Moving the fields correspondingly to <fs_dyn_table> from it_XXXX is my concern.

Thanks!

9 REPLIES 9
Read only

Former Member
0 Likes
953

If you want to do move multiple columns in one shot then MOVE CORRESPONDING is the only way.


LOOP AT IT_XXXX IN WA_XXXX.
 MOVE-CORRESPONDING WA_XXXX TO <fs_dyn_wa>.
 APPEND <fs_dyn_wa> TO <FS_DYN_TABLE>.
 CLEAR <fs_dyn_wa>.
ENDLOOP.

If you have to do it field by field.

ASSIGN COMPONENT 'FIELD1' OF <FS_DYN_WA> TO <FS_ANY>

<FS_ANY> = 'XXXX'.

Do this for each of the fields of the work area and then append the <fs_dyn_wa> to <fs_dyn_table>.

Regards,

Ravi

Note :Please mark all the helpful answers

Read only

0 Likes
953

Heloo,

I have already tried the looping code before but a syntax error saying "<FS_DYN_WA> is not a structure or internal table with header line." Why is this so?

Read only

0 Likes
953

Declare it like this

FIELD-SYMBOLS : <FS_DYN_WA> LIKE LINE OF TABLE <FS_DYN_TABLE>.

That should work .

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

0 Likes
953

Hi,

It still doesn't work. Thanks for you help, anyways. Points will be rewarded if solved.

Read only

0 Likes
953

What is the error message?

Also, take a look at this blogs, which talks about the dynamic internal tables in detail and also has example code

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards,

Ravi

Read only

0 Likes
953

Hi,

Below is a code which I tried to create but unfortunately due to lack of time I didn't finish it. But you might get some ideas from it.

REPORT zfr_forex_rev_acctg

NO STANDARD PAGE HEADING

LINE-COUNT 0

LINE-SIZE 100.

----


  • Data dictionary tables *

----


TABLES: bsis,

bsas,

tcurr,

t001.

FIELD-SYMBOLS: <fs_dyntable> TYPE STANDARD TABLE,

<fs_dynline> TYPE ANY,

<fs_fld> TYPE ANY,

<fs_data> TYPE REF TO data,

<fs_1> TYPE ANY,

<fs_2> TYPE ANY TABLE.

----


  • Selection screen *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_bukrs TYPE t001-bukrs,

p_asof TYPE bsis-budat,

p_year TYPE bsis-gjahr.

SELECT-OPTIONS: s_hkont FOR bsis-hkont NO INTERVALS.

SELECTION-SCREEN END OF BLOCK b1.

----


  • CLASS lcl_main DEFINITION

----


  • ........ *

----


CLASS lcl_main DEFINITION.

PUBLIC SECTION.

METHODS: build_table,

get_data,

combine_data,

display_header,

display_results.

PRIVATE SECTION.

  • data declarations for internal table

DATA: lt TYPE lvc_t_fcat,

ls TYPE lvc_s_fcat,

fldname(50) TYPE c,

it_ddfields TYPE TABLE OF ddfield,

wa_ddfields LIKE LINE OF it_ddfields.

ENDCLASS.

----


  • CLASS lcl_main IMPLEMENTATION

----


  • ........ *

----


CLASS lcl_main IMPLEMENTATION.

  • METHOD build_table

METHOD build_table.

DATA: lv_from TYPE bsis-gjahr,

lv_asof TYPE bsis-gjahr,

lv_check TYPE i,

lt_data TYPE REF TO data,

lt TYPE lvc_t_fcat,

v_counter TYPE i.

FIELD-SYMBOLS: <fs_year> TYPE gjahr.

ASSIGN lv_asof+0(4) TO <fs_year>.

lv_from = p_year.

lv_asof = p_asof+0(4).

ADD 1 TO v_counter.

DO.

IF lv_from = lv_asof.

EXIT.

ELSE.

ADD 1 TO: lv_from, v_counter.

ENDIF.

ENDDO.

  • YEAR_DUM

wa_ddfields-fieldname = 'YEAR_DUM'.

wa_ddfields-position = '0001'.

wa_ddfields-datatype = 'NUMC'.

wa_ddfields-leng = '000004'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • ZUONR

wa_ddfields-fieldname = 'ZUONR'.

wa_ddfields-position = '0002'.

wa_ddfields-datatype = 'CHAR'.

wa_ddfields-leng = '000018'.

wa_ddfields-decimals = '00000'.

APPEND wa_ddfields TO it_ddfields.

  • GJAHR

wa_ddfields-fieldname = 'GJAHR'.

wa_ddfields-position = '0003'.

wa_ddfields-datatype = 'NUMC'.

wa_ddfields-leng = '000004'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • BELNR

wa_ddfields-fieldname = 'BELNR'.

wa_ddfields-position = '0004'.

wa_ddfields-datatype = 'CHAR'.

wa_ddfields-leng = '000010'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • BLDAT

wa_ddfields-fieldname = 'BLDAT'.

wa_ddfields-position = '0005'.

wa_ddfields-datatype = 'DATS'.

wa_ddfields-leng = '00008'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • WAERS

wa_ddfields-fieldname = 'WAERS'.

wa_ddfields-position = '0006'.

wa_ddfields-datatype = 'CUKY'.

wa_ddfields-leng = '000005'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • BLART

wa_ddfields-fieldname = 'BLART'.

wa_ddfields-position = '0007'.

wa_ddfields-datatype = 'CHAR'.

wa_ddfields-leng = '000002'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • DMBTR

wa_ddfields-fieldname = 'DMBTR'.

wa_ddfields-position = '0008'.

wa_ddfields-datatype = 'CURR'.

wa_ddfields-leng = '000013'.

wa_ddfields-decimals = '000002'.

APPEND wa_ddfields TO it_ddfields.

  • WRBTR

wa_ddfields-fieldname = 'WRBTR'.

wa_ddfields-position = '0009'.

wa_ddfields-datatype = 'CURR'.

wa_ddfields-leng = '000013'.

wa_ddfields-decimals = '000002'.

APPEND wa_ddfields TO it_ddfields.

  • HKONT

wa_ddfields-fieldname = 'HKONT'.

wa_ddfields-position = '0010'.

wa_ddfields-datatype = 'CHAR'.

wa_ddfields-leng = '000010'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

  • AMOUNT

wa_ddfields-fieldname = 'AMOUNT'.

wa_ddfields-position = '0011'.

wa_ddfields-datatype = 'CURR'.

wa_ddfields-leng = '000010'.

wa_ddfields-decimals = '000002'.

APPEND wa_ddfields TO it_ddfields.

DATA: lv_position TYPE i.

lv_position = 0012.

  • Additional fields for the years

WHILE lv_check < v_counter.

wa_ddfields-fieldname = <fs_year>.

wa_ddfields-position = lv_position.

wa_ddfields-datatype = 'NUMC'.

wa_ddfields-leng = '000004'.

wa_ddfields-decimals = '000000'.

APPEND wa_ddfields TO it_ddfields.

lv_asof = lv_asof - 1.

ADD 1 TO: lv_check, lv_position.

ENDWHILE.

CLEAR lv_position.

lv_position = 1.

LOOP AT it_ddfields INTO wa_ddfields.

CASE wa_ddfields-fieldname.

WHEN 'BLDAT'.

ls-col_pos = lv_position.

ls-row_pos = lv_position.

ls-fieldname = wa_ddfields-fieldname.

ls-inttype = 'D'.

ls-ref_table = 'BSIS'.

ls-ref_field = 'BLDAT'.

WHEN 'WAERS'.

ls-col_pos = lv_position.

ls-row_pos = lv_position.

ls-fieldname = wa_ddfields-fieldname.

ls-ref_table = 'BSIS'.

ls-ref_field = 'WAERS'.

WHEN 'DMBTR'.

ls-col_pos = lv_position.

ls-row_pos = lv_position.

ls-fieldname = wa_ddfields-fieldname.

ls-decimals = '2'.

ls-ref_table = 'BSIS'.

ls-ref_field = 'DMBTR'.

WHEN 'WRBTR'.

ls-col_pos = lv_position.

ls-row_pos = lv_position.

ls-fieldname = wa_ddfields-fieldname.

ls-decimals = '2'.

ls-ref_table = 'BSIS'.

ls-ref_field = 'WRBTR'.

WHEN 'HKONT'.

ls-col_pos = lv_position.

ls-row_pos = lv_position.

ls-fieldname = wa_ddfields-fieldname.

ls-ref_table = 'BSIS'.

ls-ref_field = 'HKONT'.

WHEN OTHERS.

ls-col_pos = lv_position.

ls-row_pos = lv_position.

ls-fieldname = wa_ddfields-fieldname.

ENDCASE.

APPEND ls TO lt.

ADD 1 TO lv_position.

ENDLOOP.

CLEAR lv_position.

ASSIGN lt_data TO <fs_data>.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt

IMPORTING

ep_table = <fs_data>

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

ASSIGN <fs_data>->* TO <fs_1>.

ASSIGN <fs_1> TO <fs_2>.

ASSIGN <fs_1> TO <fs_dyntable>.

ENDMETHOD.

  • METHOD get_data

METHOD get_data.

*get records from BSIS

SELECT zuonr gjahr belnr bldat waers blart dmbtr wrbtr hkont

FROM bsis

INTO CORRESPONDING FIELDS OF TABLE <fs_dyntable>

WHERE bukrs = p_bukrs

AND hkont IN s_hkont

AND budat <= p_asof.

*get records from BSAS

SELECT zuonr gjahr belnr bldat waers blart dmbtr wrbtr hkont

FROM bsas

APPENDING CORRESPONDING FIELDS OF TABLE <fs_dyntable>

WHERE bukrs = p_bukrs

AND hkont IN s_hkont

AND budat <= p_asof

AND augdt > p_asof.

ENDMETHOD.

  • METHOD combine_data

METHOD combine_data.

FIELD-SYMBOLS: <wa_dyntable> TYPE ANY,

<fs> TYPE ANY.

DATA: new_line TYPE REF TO data.

CREATE DATA new_line LIKE LINE OF <fs_dyntable>.

ASSIGN new_line->* TO <wa_dyntable>.

ASSIGN new_line->* TO <fs>.

DATA: lv_date(10) TYPE c,

lv_year TYPE bsis-gjahr,

lv_bldat(10) TYPE c,

t_rate_type TYPE bapi1093_1-rate_type,

t_from_curr TYPE bapi1093_1-from_curr,

t_to_curr TYPE bapi1093_1-to_currncy,

t_date TYPE bapi1093_2-trans_date,

t_exch_rate TYPE bapi1093_0,

t_message TYPE bapireturn1.

t_rate_type = 'ME'.

t_to_curr = 'USD'.

LOOP AT <fs_dyntable> ASSIGNING <wa_dyntable>.

NEW-LINE.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <wa_dyntable> TO <fs>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

ENDMETHOD.

  • METHOD display_header

METHOD display_header.

DATA: text1 TYPE string,

text2 TYPE string,

lv_asof TYPE bsis-budat,

lv_pageno TYPE n.

SELECT SINGLE butxt FROM t001

INTO t001-butxt

WHERE bukrs = p_bukrs.

WRITE: / t001-butxt,

/ sy-title.

CONCATENATE: s_hkont '/' p_bukrs

INTO text1.

CONCATENATE: 'Account:' text1

INTO text2

SEPARATED BY space.

WRITE: / text2.

CLEAR: text1, text2.

CONCATENATE: 'As of' p_asof

INTO text1

SEPARATED BY space.

CLEAR text1.

lv_asof = p_asof+0(4).

CONCATENATE: 'Year:' p_year 'to' lv_asof

INTO text1

SEPARATED BY space.

WRITE: / text1.

CLEAR text1.

lv_pageno = sy-pagno.

CONCATENATE: 'Page No:' lv_pageno

INTO text1

SEPARATED BY space.

WRITE: / text1.

CLEAR text1.

ENDMETHOD.

  • METHOD display_results

METHOD display_results.

DATA: lv_color TYPE i VALUE 1.

FORMAT COLOR COL_HEADING.

WRITE: / sy-uline(sy-linsz),

sy-vline,

(02) 'DT' CENTERED,

(10) 'Doc. No.' CENTERED,

(10) 'Doc. Date' CENTERED,

(05) 'Cur.' CENTERED,

(20) 'Transaction Curr.' CENTERED,

(20) 'Local Curr. (PHP)' CENTERED,

sy-vline,

sy-uline(sy-linsz).

FORMAT COLOR OFF.

ENDMETHOD.

ENDCLASS.

TOP-OF-PAGE.

DATA: top TYPE REF TO lcl_main.

CREATE OBJECT top.

CALL METHOD top->display_header.

START-OF-SELECTION.

DATA: main TYPE REF TO lcl_main.

CREATE OBJECT main.

CALL METHOD main->build_table.

CALL METHOD main->get_data.

CALL METHOD main->combine_data.

CALL METHOD main->display_results.

The difference with this is that I use my dynamic table in my select statements so no need to move from one 'normal' table to a dynamic table.

Hope this helps...

P.S. Please award points for useful answers.

Read only

0 Likes
953

Thanks for this. I don't know why we can't use move-corresponding to the field-symbol. Do you see some wrong declarations in my data/field symbol?

Read only

0 Likes
953

Hi,

the declaration that you gave is not accepted. The examples that you've are different from my scenario. My scenario is that I have an internal table wherein its data come from different table. But, I don't need to include all in the exported file. So, I made a dynamic table. Now, my goal is to fill the dynamic table.

Thanks!

Read only

aris_hidalgo
Contributor
0 Likes
953

Hi,

What you can do is to assign each field in your dynamic table to a field-symbol then loop through your 'standard table' and move it.