0

I want to aggregate some specific data in a RFC module. The module takes several parameters like timestamps but also dimensions that specify the kind of aggregation.

For example I want to aggregate all contracts in a specific timerange for the several sales orgs in my system.

For this I use the GROUP BY functionality for internal tables like here:

LOOP AT ls_output-merged_data INTO ls_tmp
          GROUP BY (  sales_org = ls_tmp-sales_org
                      group_quantity = GROUP SIZE )

           ASCENDING ASSIGNING FIELD-SYMBOL(<fs_tmp_2>).

          lt_tmp_dim1 = VALUE #( BASE lt_tmp_dim1 (
                              sales_org = <fs_tmp_2>-sales_org
                              group_quantity  = <fs_tmp_2>-group_quantity
                              ) ). 
ENDLOOP.

The group-field may change for different cases also it should be possible to use two group-fields in order to e.g. aggregate all sales-orgs and the material they sold.

My question know is, how could I do the GROUP-BY dynamically without the need to programm every combination of group-fields manually?

Thank you very much in advance

Andi D.
  • 63
  • 1
  • 11

1 Answers1

0

Please check: Loop at group by dynamic group condition

I implemented a dynamic 'group by' clause by referring above link. It may also can be answer your question.

LOOP AT t_actual_data INTO DATA(actual) 
      GROUP BY cond string( when i_prodh_based eq abap_true THEN
                            |{ actual-prodh } { actual-vkorg } { actual-hl_kunnr } { actual-period }|
                            else
                            |{ actual-matnr } { actual-vkorg } { actual-hl_kunnr } { actual-period }| )
                            ASSIGNING FIELD-SYMBOL(<group>).

    "following assignment does not give any result. So I did a loop to get group conditions
    "ASSIGN COMPONENT 'PRODH' of STRUCTURE <group> to <prodh>. "no result

    "get group condition values
    LOOP AT GROUP <group> ASSIGNING FIELD-SYMBOL(<line_data>).
              ASSIGN COMPONENT 'PRODH' of STRUCTURE <line_data> to <prodh>.
              ASSIGN COMPONENT 'VKORG' of STRUCTURE <line_data> to <vkorg>.
              ASSIGN COMPONENT 'MATNR' of STRUCTURE <line_data> to <matnr>.
              ASSIGN COMPONENT 'HL_KUNNR' of STRUCTURE <line_data> to <tl_kunnr>.
              ASSIGN COMPONENT 'PERIOD' of STRUCTURE <line_data> to <period>.
              EXIT.
    ENDLOOP.

ENDLOOP.
ozkancinar
  • 53
  • 1
  • 5
  • this looks like it would work for me as well, however I want to implement this in a RFC function module and I am getting weird errors like "the statement FUNCTION is missing". Did you experience something similiar? – Andi D. Aug 14 '20 at 13:04