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: 

Summurization with a dynamic table

philippe_gauthier
Participant
0 Kudos

hello all,

I use a dynamic table. I populate it with my data. before to do the summurization, i transpose one table into my dynamic table like this

BUKRS KUNNR PERBL VVP01

1010 1 2006001 10000

1010 1 2006002 5000

so when i fill my dynamic table, i obtain this:

BUKRS KUNNR VVP01_200601 VVP01_2006002

1010 1 10000

1010 1 5000

Now i do not find the way to aggregate my key figures to obtain some thing like this:

BUKRS KUNNR VVP01_200601 VVP01_2006002

1010 1 10000 5000

When i use collect and sum i obtain an error. So how can i do it ?

Thanks for your help,

Philippe

1 REPLY 1

philippe_gauthier
Participant
0 Kudos

I solve my self the trouble.

this is the code that permitted to do the summurization.


FORM agregation_dyntab.
  FIELD-SYMBOLS <fs> TYPE ANY.
  FIELD-SYMBOLS <f90> TYPE ANY.
  FIELD-SYMBOLS <f91> LIKE LINE OF it_fldcat.

  DATA: BEGIN OF t_dd03l OCCURS 0.
          INCLUDE STRUCTURE dd03l.
  DATA: END OF t_dd03l.
  DATA: BEGIN OF t_dd04v OCCURS 0.
          INCLUDE STRUCTURE dd04v.
  DATA: END OF t_dd04v.


  DATA: BEGIN OF t_var OCCURS 0,
          vari(8) TYPE c,
          tri TYPE n,
          st(1) TYPE c,
   END OF t_var.
  DATA: p_st TYPE string,
        p_max TYPE string,
        p_num TYPE string,
        p_fld LIKE dd03l-fieldname,
        p_fld1 TYPE string,
        p_len TYPE n,
        p_tot TYPE i.
  DATA: l_sort TYPE string,
        p_bc(1) TYPE c VALUE ' '.
  LOOP AT it_fldcat0.
    IF it_fldcat0-fieldname(1)  NE 'V'.
      SELECT SINGLE * FROM dd03l
      WHERE fieldname = it_fldcat0-fieldname
      AND tabname = it_fldcat0-ref_table.

      IF sy-subrc <> 0.
        p_num = p_num + it_fldcat0-outputlen.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ELSE.
        p_num = p_num + dd03l-intlen.
      ENDIF.
    ELSE.
      EXIT.
    ENDIF.
  ENDLOOP.

  LOOP AT <dyn_table> ASSIGNING <dyn_wa2>.
    IF sy-tabix NE '1'.


      IF <dyn_wa2>(p_num) NE <dyn_wa>(p_num).
        p_tot = 1.
      ELSE.
        p_tot = 0.
      ENDIF.




      IF p_tot EQ 0.
        LOOP AT it_fldcat0.
          IF it_fldcat0-fieldname(1)  EQ 'V'.
            p_fld = it_fldcat0-fieldname.
*            CONCATENATE '<dyn_wa>-' p_fld INTO p_fld1.
            ASSIGN COMPONENT sy-tabix OF STRUCTURE <dyn_wa> TO <fs>.
*            ASSIGN (p_fld) TO <fs>.
*            CONCATENATE '<dyn_wa2>-' p_fld INTO p_fld1.
            ASSIGN COMPONENT sy-tabix OF STRUCTURE <dyn_wa2> TO <f90>.
*            ASSIGN (p_fld1) TO <f90>.
*            p_num = <fs> + <f90>.


*           assign component p_fld of structure <dyn_wa> to <fs>.
            <fs> = <f90> + <fs>.
          ENDIF.
        ENDLOOP.

      ENDIF.

    ELSE.
      <dyn_wa> = <dyn_wa2>.

    ENDIF.


* si ligne en ecart,
* je stock le résultat obtenu dans la table dynamique 2
    IF p_tot EQ 1.
      APPEND <dyn_wa> TO <dyn_table2>.
      CLEAR <dyn_wa>.
* je remets la ligne courante de la table
* dynamique dyn_table dans dyn_wa
      <dyn_wa> = <dyn_wa2>.
* je reinitialise la variable du total
      p_tot = 0.
    ENDIF.

  ENDLOOP.


ENDFORM.                    "agregation_dyntab

Bonne journée

Thanks for your help