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

Using Group By in an Internal Table

Former Member
0 Likes
580

Hi all,

Apparently, I have an internal table with the following structure:

<u>itab_cust</u>

Customer No

Customer Name

Country

Sales Organization

Total_sold

However, if I want to generate a report, using the above table, to summarize total customer and total sales amount group by sales organization and country, how can I achieve the above? Please note that internal table itab_cust has bundled with all the data.

Appreciate your advise.

Best regards,

Patrick

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
549

Hi patrick,

1. We will have to follow the following steps.

2.<b> first collecting the summary sales org and country wise</b>

a) make new internal table say, sumtab

which has only the followng fields

sales org (keep same field name)

country (keep same field name)

cust_count <b>(for customer count)</b>

total_sold (keep same field name)

b) LOOP AT ITAB_CUST

MOVE-CORRESPONDING ITAB_CUST TO SUMTAB.

SUMTAB-CUST_COUNT = 1.

COLLECT SUMTAB.

ENDLOOP.

3. Then u can just print out this summary data.

4. Thats all !

regards,

amit m.

Hi all,

Apparently, I have an internal table with the following structure:

<u>itab_cust</u>

Customer No

Customer Name

Country

Sales Organization

Total_sold

However, if I want to generate a report, using the above table, to summarize total customer and total sales amount group by sales organization and country, how can I achieve the above? Please note that internal table itab_cust has bundled with all the data.

Appreciate your advise.

Best regards,

Patrick

3 REPLIES 3
Read only

Former Member
0 Likes
549

You can simply develop a ALV Grid report using the user can go the totals / sub totals by themselves. They can do the subtotals by specific columns.

Regards,

Ravi

note : Please mark all the helpful answers

Read only

Former Member
0 Likes
550

Hi patrick,

1. We will have to follow the following steps.

2.<b> first collecting the summary sales org and country wise</b>

a) make new internal table say, sumtab

which has only the followng fields

sales org (keep same field name)

country (keep same field name)

cust_count <b>(for customer count)</b>

total_sold (keep same field name)

b) LOOP AT ITAB_CUST

MOVE-CORRESPONDING ITAB_CUST TO SUMTAB.

SUMTAB-CUST_COUNT = 1.

COLLECT SUMTAB.

ENDLOOP.

3. Then u can just print out this summary data.

4. Thats all !

regards,

amit m.

Read only

andreas_mann3
Active Contributor
0 Likes
549

hi Patrick,

that's the advantage of an alv-grid /list. that the user can design his own layouts with totals, subtotals , groups,...

you just need to fill that:

x_save = 'X'.
  gs_variant-report     = sy-repid.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            I_STRUCTURE_NAME = c_tabname
            IS_VARIANT       = gs_variant
            IS_layout        = lay
            I_SAVE           = x_save
       TABLES
            T_OUTTAB         = gridtab
       EXCEPTIONS
            OTHERS           = 1.

Andreas

Message was edited by: Andreas Mann