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

Dynamic Internal table

Former Member
0 Likes
605

Hi Technical Consultants,

I am working on SD Module.I have to display ALV grid for Revenue report.Please guide me in using dynamic internal table,as the number of columns for the report is not fixed.Also I need to take the sub total of each row into the last column.

Please help me with issue.

Thanks.

6 REPLIES 6
Read only

Former Member
0 Likes
578

Hi,

Please refer the following link:

Regards

Bhupal Reddy

Read only

Former Member
0 Likes
578

hi Sneha,

try out this simpler dynamic internal tables

REPORT ZSAMPLEPRG.

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.

*In this added the column needed

line = ' CITYFROM CITYTO AIRPTO'.

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

Try putting break point in the loop u can see it

    • Reward points if it is useful

Read only

Former Member
0 Likes
578

Hi,

check this test program for dynamic table

REPORT zgaurav_create_data_dynamic .

TYPE-POOLS: slis.

DATA: it_fcat TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table TYPE REF TO data.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

  • Build fieldcat

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SYST'

CHANGING

ct_fieldcat = it_fcat[].

LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.

MOVE-CORRESPONDING is_fcat TO is_fieldcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

ENDLOOP.

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

  • Create a new Line with the same structure of the table.

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

  • Test it...

DO 30 TIMES.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

<l_field> = sy-index.

INSERT <l_line> INTO TABLE <l_table>.

ENDDO.

LOOP AT <l_table> ASSIGNING <l_line>.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

WRITE <l_field>.

ENDLOOP.

Read only

Former Member
0 Likes
578

hi

hope this code helps you...


TYPE-POOLS: slis.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
              <dyn_wa>.
DATA: alv_fldcat TYPE slis_t_fieldcat_alv,
      it_fldcat TYPE lvc_t_fcat.

DATA: lv_monate TYPE f,
      lv_months TYPE i,
      lv_date TYPE sy-datum.

lv_date = sy-datum + 360.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_check TYPE c.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
    EXPORTING
      i_datum_bis   = lv_date
      i_datum_von   = sy-datum
      i_kz_incl_bis = ' '
    IMPORTING
      e_monate      = lv_monate.

  lv_months = lv_monate.

  PERFORM build_dyn_itab.
  PERFORM build_report.
  LOOP AT <dyn_table> INTO <dyn_wa>.
    WRITE:/ <dyn_wa>.
  ENDLOOP.
*************************************************************************
FORM build_dyn_itab.
  DATA: index(3) TYPE c.
  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 = 'AUFNR'.
  wa_it_fldcat-datatype = 'CHAR'.
  wa_it_fldcat-intlen = 12.
  APPEND wa_it_fldcat TO it_fldcat .
  CLEAR wa_it_fldcat.
  wa_it_fldcat-fieldname = 'POSNR'.
  wa_it_fldcat-datatype = 'CHAR'.
  wa_it_fldcat-intlen = 6.
  APPEND wa_it_fldcat TO it_fldcat .
* Create fields
  CLEAR index.
  DO 2 TIMES.
    index = sy-index.
    CLEAR wa_it_fldcat.
    CONCATENATE 'Field' index INTO
    wa_it_fldcat-fieldname .
    CONDENSE wa_it_fldcat-fieldname NO-GAPS.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    APPEND wa_it_fldcat TO it_fldcat .
  ENDDO.
* 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


**********************************************************************
FORM build_report.
  DATA: fieldname(20) TYPE c.
  DATA: fieldvalue(5) TYPE c.
  DATA: index(3) TYPE c.
  FIELD-SYMBOLS: <fs1>.
  ASSIGN COMPONENT 'AUFNR' OF STRUCTURE <dyn_wa> TO <fs1>.
  <fs1> = '123456789'.
  ASSIGN COMPONENT 'POSNR' OF STRUCTURE <dyn_wa> TO <fs1>.
  <fs1> = '000001'.
  DO 2 TIMES.
    index = sy-index.
* Set up fieldname
    CONCATENATE 'FIELD' index INTO fieldname .
    CONDENSE fieldname NO-GAPS.
* Set up fieldvalue
    CONCATENATE 'FLD' index INTO fieldvalue.
    CONDENSE fieldvalue NO-GAPS.
    ASSIGN COMPONENT fieldname OF STRUCTURE <dyn_wa> TO <fs1>.
    <fs1> = fieldvalue.
  ENDDO.
* Append to the dynamic internal table
  APPEND <dyn_wa> TO <dyn_table>.
ENDFORM.                    "build_report

thx

pavan

Read only

Former Member
0 Likes
578

Hi Sneha,

First u need to create the fieldcatalog for the structure [ internal table structure]. That is done using the FM 'REUSE_ALV_FIELDCATALOG_MERGE'. After that u need to pass this fieldcatalog to a method 'CREATE_DYNAMIC_TABLE' of class 'CL_ALV_TABLE_CREATE' to create dynamic table.

*********

Data : it_fcat type slis_t_fieldcat_alv,

is_fcat like line of it_fcat,

it_fieldcat type lvc_t_fcat,

is_fieldcat like line of it_fieldcat.

Data :new_table type ref to data.

field-symbols : <l_table> type standard table.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = l_segname " [<b>Structure Name</b>]

CHANGING

ct_fieldcat = it_fcat[].

loop at it_fcat into is_fcat.

Move-corresponding is_fcat to is_fieldcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-ref_field.

is_fieldcat-ref_table = is_fcat-ref_table.

append is_fieldcat to it_fieldcat.

endloop.

****Create new table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

if sy-subrc eq 0.

assign new_table->* to <l_table>.

endif.

-Satya Priya

Read only

Former Member
0 Likes
578

Thanks to all Techincal consultants.The steps were really helpful & I implemented the same in my program.