cancel
Showing results for 
Search instead for 
Did you mean: 

How to create dynamic internal table?

Former Member
0 Kudos

Hi All,

I am working on an ALV report which consist of several section. Each section(layout) is different internal table. But if user want to display two section at the same time, the result layout should be the combination of two layout. Let me explain by one example.

Section 1: itab1 ( if user want only section 1)

itab1

- field1

- field2

- field3

- field4

Section 2: itab2 ( if user want only section 2)

-field1

-field2

-field5

-field6

So, now if user want to display both section 1 and 2, i have to dynamically create an internal table in the program such at

Final layout: itab3 ( user want both section )

- field1

- field2

- field3

- field4

- field5

- field6

Is there any way to dynamically create an internal table based on two or more tables. What is the best way to do this ( i have maximum of 6 section )?

If anybody has any idea, please let me know.

Thanks,

Pratik

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi ,

Instead of creating dynamic internal table; you can create an internal table with the maximum fields possible for any combination.

Set the field catalog of the internal table has per your requirement.In the ALV grid only those field will be shown for which field catlog is maintained. you can even give dynamic field name ( on alv grid). aplly the logic and prepair single internal table as per the selection criteria

Code to do that (reference)

TYPES : BEGIN OF ty_summay_tab,

f01 TYPE char30,

f02 TYPE char30,

f03 TYPE char30,

f04 TYPE char30,

f05 TYPE char30,

f06 TYPE char30,

f07 TYPE char30,

f08 TYPE char30,

f09 TYPE char30,

f10 TYPE char30,

f11 TYPE char30,

f12 TYPE char30,

END OF ty_summay_tab.

&----


  • Data for the feilds for the column

----


  • -->xv_value : Value for the field of type any

  • <->xys_summay : Structure of the Summary Tab

  • <->xyv_column : Column Number of the structure

----


FORM f9100_summry_row_data USING xv_value TYPE any

CHANGING xys_summay TYPE ty_summay_tab

xyv_column TYPE i.

CLEAR wa_fcat .

CASE xyv_column.

WHEN 1.

xys_summay-f01 = xv_value.

wa_fcat-fieldname = 'F01'.

wa_fcat-coltext = xv_value.

WHEN 2.

xys_summay-f02 = xv_value.

wa_fcat-fieldname = 'F02'.

wa_fcat-coltext = xv_value.

WHEN 3.

xys_summay-f03 = xv_value.

wa_fcat-fieldname = 'F03'.

wa_fcat-coltext = xv_value.

WHEN 4.

xys_summay-f04 = xv_value.

wa_fcat-fieldname = 'F04'.

wa_fcat-coltext = xv_value.

WHEN 5.

xys_summay-f05 = xv_value.

wa_fcat-fieldname = 'F05'.

wa_fcat-coltext = xv_value.

WHEN 6.

xys_summay-f06 = xv_value.

wa_fcat-fieldname = 'F06'.

wa_fcat-coltext = xv_value.

WHEN 7.

xys_summay-f07 = xv_value.

wa_fcat-fieldname = 'F07'.

wa_fcat-coltext = xv_value.

WHEN 8.

xys_summay-f08 = xv_value.

wa_fcat-fieldname = 'F08'.

wa_fcat-coltext = xv_value.

WHEN 9.

xys_summay-f09 = xv_value.

wa_fcat-fieldname = 'F09'.

wa_fcat-coltext = xv_value.

WHEN 10.

xys_summay-f10 = xv_value.

wa_fcat-fieldname = 'F10'.

wa_fcat-coltext = xv_value.

WHEN 11.

xys_summay-f11 = xv_value.

wa_fcat-fieldname = 'F11'.

wa_fcat-coltext = xv_value.

WHEN 12.

xys_summay-f12 = xv_value.

wa_fcat-fieldname = 'F12'.

wa_fcat-coltext = xv_value.

ENDCASE.

xyv_column = xyv_column + 1.

IF gv_header IS INITIAL.

APPEND wa_fcat TO lit_fcat_summary .

ENDIF.

ENDFORM. " f9100_summry_row_data

LOOP AT xt_status_text INTO wa_status_text.

*---Status Description ( Selected )

PERFORM f9100_summry_row_data USING wa_status_text-statustext

CHANGING wa_summay_tab lv_column.

ENDLOOP.

Former Member
0 Kudos

Use ABAP Objects:

DATA: gp_table TYPE REF TO data.

FIELD-SYMBOLS: <GT_TABLE> TYPE TABLE.

  • Where gt_fieldcat is the field catalog for the table.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = gt_fieldcat

IMPORTING ep_table = gp_table.

ASSIGN gp_table->* TO <gt_table>.

vinod_gunaware2
Active Contributor
0 Kudos

How to create a Dynamic Internal Table or Array?

REPORT ZCLUST1 .

  • Example: how to create a dynamic internal table

  • The dynamic internal table stucture

DATA: BEGIN OF STRUCT OCCURS 10,

FILDNAME(8) TYPE C,

ABPTYPE TYPE C,

LENGTH TYPE I,

END OF STRUCT.

  • The dynamic program source table

DATA: BEGIN OF INCTABL OCCURS 10,

LINE(72),

END OF INCTABL.

DATA: LNG TYPE I, TYPESRTING(6).

  • Sample dynamic internal table stucture

STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.

APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.

APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.

APPEND STRUCT. CLEAR STRUCT.

  • Create the dynamic internal table definition in the dyn. program

INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.

INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.

LOOP AT STRUCT.

INCTABL-LINE = STRUCT-FILDNAME.

LNG = STRLEN( STRUCT-FILDNAME ).

IF NOT STRUCT-LENGTH IS INITIAL .

TYPESRTING(1) = '('.

TYPESRTING+1 = STRUCT-LENGTH.

TYPESRTING+5 = ')'.

CONDENSE TYPESRTING NO-GAPS.

INCTABL-LINE+LNG = TYPESRTING.

ENDIF.

INCTABL-LINE+15 = 'type '.

INCTABL-LINE+21 = STRUCT-ABPTYPE.

INCTABL-LINE+22 = ','.

APPEND INCTABL.

ENDLOOP.

INCTABL-LINE = 'end of dyntab. '.

APPEND INCTABL.

  • Create the code processes the dynamic internal table

INCTABL-LINE = ' '. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.

INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.

INCTABL-LINE = ' '. APPEND INCTABL.

INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.

INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.

INCTABL-LINE = 'endloop.'. APPEND INCTABL.

  • Create and run the dynamic program

INSERT REPORT 'zdynpro'(001) FROM INCTABL.

SUBMIT ZDYNPRO.

-


or Just try out this simpler dynamic internal tables

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

START-OF-SELECTION.

*line = ' CITYFROM CITYTO '.

line = ' AIRPTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

  • WRITE: / wa-cityfrom, wa-cityto.

WRITE 😕 wa-airpto.

ENDLOOP.

ENDIF.

regards

vinod

former_member188685
Active Contributor
0 Kudos

Hi,

Check this Blog..

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

Regards

Vijay

andreas_mann3
Active Contributor
0 Kudos

hi,

have a look here:

Andreas