Skip to Content
-2
Jul 07, 2019 at 12:39 PM

Help to create dynamic table from internal table

113 Views

Hi,

I have the bellow code which is working fine, the final internal table is i_final

my requirement is to create a dynamic table from the i_final internal table
(they dynamic table columns will be the material numbers of i_final rows and the content
of the dynamic table for each column will be the row of the internal table i_final)

i have limited knowledge in RTTS, if anyone can help me it will great since it is customer requirement

TYPE-POOLS : slis.
TABLES:vbrp, vbrk, kna1, konv,VBAP,VBUK, TVKBT .

TYPES : BEGIN OF tty_i_final,
      MATNR    TYPE VBRP-MATNR,
      ARKTX    TYPE VBRP-ARKTX,
      fkimg    TYPE vbrp-fkimg,
      netwr   TYPE vbrp-netwr,
      WAVWR    TYPE VBRP-WAVWR,
END OF tty_i_final.

TYPES : BEGIN OF tty_itab1,
      fkart TYPE vbrk-fkart ,
      KUNAG    TYPE vbrk-KUNAG,
      fkimg    TYPE vbrp-fkimg,
      netwr   TYPE vbrp-netwr,
      WAVWR    TYPE VBRP-WAVWR,
      MATNR    TYPE VBRP-MATNR,
      ARKTX    TYPE VBRP-ARKTX,

END OF tty_itab1.

TYPES : BEGIN OF tty_itab2,
      fkimg    TYPE vbrp-fkimg,
      netwr   TYPE vbrp-netwr,
      WAVWR    TYPE VBRP-WAVWR,
      MATNR    TYPE VBRP-MATNR,
      ARKTX    TYPE VBRP-ARKTX,
      Cost1 TYPE P,
      Cost2 TYPE P,
      Cost3 TYPE P,
      Cost4 TYPE P,

END OF tty_itab2.


TYPES : BEGIN OF tty_itab3,
      fkimg    TYPE vbrp-fkimg,
      netwr   TYPE vbrp-netwr,
      WAVWR    TYPE VBRP-WAVWR,
      MATNR    TYPE VBRP-MATNR,
      ARKTX    TYPE VBRP-ARKTX,
      Cost1 TYPE P,
      Cost2 TYPE P,
      Cost3 TYPE P,
      Cost4 TYPE P,
END OF tty_itab3.

DATA : i_final TYPE TABLE OF tty_i_final. "internal table
DATA  itab1 TYPE TABLE OF  tty_itab1 .
DATA  itab2 TYPE TABLE OF  tty_itab2.
DATA  itab3 TYPE TABLE OF  tty_itab3.
"DATA  i_dynamic TYPE TABLE OF  tty_dynamic.

DATA  wa_i_final LIKE LINE OF i_final.
DATA  wa_i_final2 LIKE LINE OF i_final.

DATA: wa_itab1 TYPE tty_itab1 .
DATA: wa_itab2 TYPE tty_itab2 .
DATA: wa_itab3 TYPE tty_itab3 .


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE A1TITLE.

SELECT-OPTIONS :

                 s_KUNAG FOR vbrk-KUNAG OBLIGATORY NO INTERVALS NO-EXTENSION ,
                 s_fkdat FOR vbrk-fkdat OBLIGATORY.                      "BILLING DATE
                           "Sold-to party
                 "s_MATNR FOR VBRP-MATNR ,                                 " Material Code
                 "s_SPART    FOR VBRK-SPART,                              "Devision
                 "S_MATKL FOR VBRP-MATKL.                                "Mat Group


SELECTION-SCREEN END OF BLOCK b1.


START-OF-SELECTION.


perform fill_table.


"cl_demo_output=>display( i_final ).

FORM fill_table.

SELECT   vbrk~fkart vbrk~KUNAG  SUM( vbrp~fkimg ) AS fkimg SUM( vbrp~netwr ) AS netwr SUM( VBRP~WAVWR ) AS WAVWR vbrp~MATNR VBRP~ARKTX
         INTO CORRESPONDING FIELDS OF TABLE itab1
         FROM vbrk
         JOIN vbrp ON vbrp~vbeln = vbrk~vbeln
         WHERE vbrk~fkdat IN s_fkdat
         AND   vbrk~KUNAG IN s_KUNAG
         AND vgtyp IN ('C', 'c', 'h', 'H')
         GROUP BY vbrk~KUNAG vbrp~MATNR VBRP~ARKTX vbrk~fkart .



  LOOP AT itab1 INTO wa_itab1 WHERE ( fkart(1) EQ 'S' OR fkart EQ 'IVS' OR fkart EQ 'RE' OR fkart EQ 'PB' )
                    AND fkart NE 'S2'.
   wa_itab1-netwr  = wa_itab1-netwr * ( -1 ).
   wa_itab1-FKIMG = wa_itab1-FKIMG * ( -1 ).
   wa_itab1-WAVWR = wa_itab1-WAVWR * ( -1 ).
    MODIFY itab1 from wa_itab1.
  ENDLOOP.


loop at itab1 into wa_itab1.
  move-corresponding wa_itab1 to wa_itab2.
  append wa_itab2 to itab2.
endloop.


LOOP AT itab2 INTO wa_itab2.
  COLLECT wa_itab2 INTO itab3.


ENDLOOP.


loop at itab3 into wa_itab3.
  move-corresponding wa_itab3 to wa_i_final.
  append wa_i_final to i_final.
endloop.

ENDFORM.                    "FILL_TABLE