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: 

"Collect" in dynamic table.

Former Member
0 Kudos

COLLECT <dyn_wa> INTO <dyn_table> is not adding the numeric data field types.

Where am I wrong?

I have created the dynamic table as shown in the FORM routine:

I have declared the fields to be added as follows:

wa_it_fldcat-datatype = 'INT'.

Is this right?

FORM build_dyn_itab.

DATA: new_table TYPE REF TO data,

new_line TYPE REF TO data,

wa_it_fldcat TYPE lvc_s_fcat.

CLEAR wa_it_fldcat.

wa_it_fldcat-fieldname = 'VENDOR'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 10.

wa_it_fldcat-outputlen = 10.

APPEND wa_it_fldcat TO it_fldcat .

CLEAR wa_it_fldcat.

wa_it_fldcat-fieldname = 'USERID'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 10.

wa_it_fldcat-outputlen = 10.

APPEND wa_it_fldcat TO it_fldcat .

CLEAR wa_it_fldcat.

wa_it_fldcat-fieldname = 'CO_CODE'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 5.

wa_it_fldcat-outputlen = 5.

APPEND wa_it_fldcat TO it_fldcat .

SORT ispbup BY spbup ASCENDING.

LOOP AT ispbup.

CLEAR wa_it_fldcat.

ind = sy-tabix.

wa_it_fldcat-fieldname = ispbup-spbup.

  • concatenate 'PERIOD' ind into wa_it_fldcat-fieldname.

wa_it_fldcat-fieldname = ispbup-spbup.

CONDENSE wa_it_fldcat-fieldname NO-GAPS.

  • wa_it_fldcat-REPTEXT = ispbup-spbup.

wa_it_fldcat-datatype = 'INT'.

wa_it_fldcat-outputlen = 6.

wa_it_fldcat-intlen = 6.

APPEND wa_it_fldcat TO it_fldcat .

ENDLOOP.

CLEAR wa_it_fldcat.

wa_it_fldcat-fieldname = 'TOTAL'.

wa_it_fldcat-datatype = 'INT'.

wa_it_fldcat-outputlen = 7.

wa_it_fldcat-intlen = 7.

APPEND wa_it_fldcat TO it_fldcat .

  • 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. " build_dyn_itab

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Are you sure the type INT is defined?

The integer type should be INT1, INT2 and INT4:

So try to do these modification:

LOOP AT ispbup.
  ..............................
  wa_it_fldcat-datatype = 'INT4'. "<---------------
  .................................
  APPEND wa_it_fldcat TO it_fldcat .
ENDLOOP.

CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'TOTAL'.
wa_it_fldcat-datatype = 'INT4'. "<-----------------
wa_it_fldcat-outputlen = 7.
wa_it_fldcat-intlen = 7.
APPEND wa_it_fldcat TO it_fldcat.

INT4 should mean positive/negative integer numbers

Max

4 REPLIES 4

Former Member
0 Kudos

Hi

Are you sure the type INT is defined?

The integer type should be INT1, INT2 and INT4:

So try to do these modification:

LOOP AT ispbup.
  ..............................
  wa_it_fldcat-datatype = 'INT4'. "<---------------
  .................................
  APPEND wa_it_fldcat TO it_fldcat .
ENDLOOP.

CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'TOTAL'.
wa_it_fldcat-datatype = 'INT4'. "<-----------------
wa_it_fldcat-outputlen = 7.
wa_it_fldcat-intlen = 7.
APPEND wa_it_fldcat TO it_fldcat.

INT4 should mean positive/negative integer numbers

Max

0 Kudos

It works now. Thanks a lot!

Another quick question....

How do I sort the dynamic internal table? This is what I am doing but its not working (dynamic tablke do not have a header)

T_FIELD = 'VENDOR'.

APPEND T_FIELD.

clear t_field.

SORT <DYN_TABLE> BY (T_FIELD) .

0 Kudos

Hi

U can dynamically sort the table using some variable to store the field/s for the sorting (not an internal table):

*T_FIELD = 'VENDOR'.
*APPEND T_FIELD.

DATA: FIELD(30).

FIELD = 'VENDOR'.

SORT <DYN_TABLE> BY (FIELD) .

U can sort for several fields:

DATA: FIELD(30), FIELD1(30), FIELD2(30),....

FIELD = 'VENDOR'.

SORT <DYN_TABLE> BY (FIELD) (FIELD1) (FIELD2) ...(FIELDN) .[/code]

Max

Former Member
0 Kudos

another question for the same program