Skip to Content
author's profile photo Former Member
Former Member

Interactive reports subtotals

Hi Experts,

I Need to do subtotals and grandtotals in interactive reports using control break events and i have done according to that and below is

code

*&---------------------------------------------------------------------*

*& Report Z80INTERACTIVE_SUBTOTAL

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT Z80INTERACTIVE_SUBTOTAL.

TYPES: BEGIN OF typ_cust,

customerno(15) TYPE c,

customername(15) TYPE c,

quantity(15) TYPE c,

amount(15) TYPE c,

ws_total TYPE c,

wg_total TYPE c,

ws_totals TYPE c,

wg_totals TYPE c,

END OF typ_cust.

DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno

customername quantity amount .

DATA : wa_cust TYPE typ_cust,

wa_temp TYPE typ_cust,

ws_total TYPE typ_cust,

wg_total TYPE typ_cust,

ws_totals TYPE typ_cust,

wg_totals TYPE typ_cust.

DEFINE fill.

wa_cust-customerno = &1.

wa_cust-customername = &2.

wa_cust-quantity = &3.

wa_cust-amount = &4.

append wa_cust to it_cust.

END-OF-DEFINITION.

fill '1000' 'C1' '10' '35'.

fill '1000' 'C1' '11' '45'.

fill '1000' 'C1' '12' '55'.

fill '1000' 'C1' '13' '65'.

fill '1000' 'C1' '14' '75'.

fill '1000' 'C1' '15' '85'.

fill '1000' 'C1' '16' '95'.

fill '1001' 'C2' '17' '25'.

fill '1001' 'C2' '18' '55'.

fill '1001' 'C2' '19' '65'.

LOOP AT it_cust INTO wa_cust.

wa_temp = wa_cust.

AT FIRST.

WRITE:/ 'Customer Details'.

ENDAT.

AT NEW customername.

WRITE:/ wa_temp-customerno,wa_temp-customername.

ENDAT.

WRITE:/33 wa_temp-quantity,40 wa_temp-amount.

SKIP 1.

ws_total = ws_total + wa_temp-quantity.

ws_totals = ws_totals + wa_temp-amount.

AT END OF customerno.

* SUM.

ULINE 43(16).

WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.

CLEAR ws_total.

* wa_temp-quantity,30 wa_temp-amount.

ENDAT.

wg_total = wg_total + wa_temp-quantity.

wg_totals = wg_totals + wa_temp-amount.

AT LAST .

SKIP 2.

WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.

CLEAR: wg_total,wg_totals.

ENDAT.

ENDLOOP.


and the issue is i dont want to use another workarea.So please help me in this issue.


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2014 at 11:44 AM

    Hi Vinod,

    Try Below Code.

    REPORT ZTEMP_SAMPLE_IT_ALV.

    "REPORT Z80INTERACTIVE_SUBTOTAL.

    TYPES: BEGIN OF typ_cust,

    customerno(15) TYPE c,

    customername(15) TYPE c,

    quantity(15) TYPE c,

    amount(15) TYPE c,

    ws_total TYPE c,

    wg_total TYPE c,

    ws_totals TYPE c,

    wg_totals TYPE c,

    END OF typ_cust.

    DATA: cust(15) TYPE c.

    DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno

    customername quantity amount .

    DATA : wa_cust TYPE typ_cust,

    wa_temp TYPE typ_cust,

    ws_total TYPE typ_cust,

    wg_total TYPE typ_cust,

    ws_totals TYPE typ_cust,

    wg_totals TYPE typ_cust.

    DEFINE fill.

    wa_cust-customerno = &1.

    wa_cust-customername = &2.

    wa_cust-quantity = &3.

    wa_cust-amount = &4.

    append wa_cust to it_cust.

    END-OF-DEFINITION.

    fill '1000' 'C1' '10' '35'.

    fill '1000' 'C1' '11' '45'.

    fill '1000' 'C1' '12' '55'.

    fill '1000' 'C1' '13' '65'.

    fill '1000' 'C1' '14' '75'.

    fill '1000' 'C1' '15' '85'.

    fill '1000' 'C1' '16' '95'.

    fill '1001' 'C2' '17' '25'.

    fill '1001' 'C2' '18' '55'.

    fill '1001' 'C2' '19' '65'.

    LOOP AT it_cust INTO wa_cust.

    "wa_temp = wa_cust.

    AT FIRST.

    WRITE:/ 'Customer Details'.

    ENDAT.

    if cust ne wa_cust-customername.

    "AT NEW customername.

    WRITE:/ wa_cust-customerno,wa_cust-customername.

    endif.

    cust = wa_cust-customername.

    "ENDAT.

    WRITE:/33 wa_cust-quantity,40 wa_cust-amount.

    SKIP 1.

    ws_total = ws_total + wa_cust-quantity.

    ws_totals = ws_totals + wa_cust-amount.

    AT END OF customerno.

    * SUM.

    ULINE 43(16).

    WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.

    CLEAR ws_total.

    * wa_temp-quantity,30 wa_temp-amount.

    ENDAT.

    wg_total = wg_total + wa_cust-quantity.

    wg_totals = wg_totals + wa_cust-amount.

    AT LAST .

    SKIP 2.

    WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.

    CLEAR: wg_total,wg_totals.

    ENDAT.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2014 at 11:58 AM

    Hi vinod,

    The main reason For the ******* value when you code with SUM is that you have declared the amount and quantity in c .. change it to i..

    and do the following code It will give you result.

    TYPES: BEGIN OF typ_cust,

    customerno(15) TYPE c,

    customername(15) TYPE c,

    quantity TYPE i,

    amount TYPE i,

    ws_total TYPE i,

    wg_total TYPE i,

    ws_totals TYPE i,

    wg_totals TYPE i,

    END OF typ_cust.

    DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno

    customername quantity amount .

    DATA : wa_cust TYPE typ_cust,

    wa_temp TYPE typ_cust,

    ws_total TYPE typ_cust,

    wg_total TYPE typ_cust,

    ws_totals TYPE typ_cust,

    wg_totals TYPE typ_cust.

    DEFINE fill.

    wa_cust-customerno = &1.

    wa_cust-customername = &2.

    wa_cust-quantity = &3.

    wa_cust-amount = &4.

    append wa_cust to it_cust.

    END-OF-DEFINITION.

    fill '1000' 'C1' '10' '35'.

    fill '1000' 'C1' '11' '45'.

    fill '1000' 'C1' '12' '55'.

    fill '1000' 'C1' '13' '65'.

    fill '1000' 'C1' '14' '75'.

    fill '1000' 'C1' '15' '85'.

    fill '1000' 'C1' '16' '95'.

    fill '1001' 'C2' '17' '25'.

    fill '1001' 'C2' '18' '55'.

    fill '1001' 'C2' '19' '65'.

    LOOP AT it_cust INTO wa_cust.

    AT FIRST.

    WRITE:/ 'Customer Details'.

    ULINE.

    ENDAT.

    AT NEW customername.

    * READ TABLE ITAB INDEX SY-TABIX.

    FORMAT INTENSIFIED OFF COLOR COL_HEADING.

    WRITE:/ wa_cust-customerno,wa_cust-customername.

    FORMAT RESET.

    ENDAT.

    WRITE:/50 wa_cust-quantity, wa_cust-amount.

    AT END OF customername.

    SUM.

    FORMAT INTENSIFIED ON COLOR COL_TOTAL.

    WRITE:/ 'Sub Total: ',60 wa_cust-quantity, wa_cust-amount.

    FORMAT RESET.

    ENDAT.

    AT LAST.

    SUM.

    FORMAT INTENSIFIED ON COLOR COL_GROUP.

    WRITE:/ 'Total: ',60 wa_cust-quantity, wa_cust-amount.

    FORMAT RESET.

    ENDAT.

    ENDLOOP.



    Regards,

    sivaganesh

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 08, 2014 at 11:08 AM

    hi,

    if you use ' wa_cust instead of wa_temp' .What error you are getting?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2014 at 11:27 AM

    If i am using with single workarea then it is showing me ***** instead of values,so please correct me in this.

    Add a comment
    10|10000 characters needed characters exceeded

    • hi,

      Actually at new statement allow single varible only i.e. wa_temp-customerno.

      if want more than one we have to pass those fields to another variable use those variables then you get it.

      AT NEW customername.

      WRITE:/ wa_temp-customerno,wa_temp-customername.

      ENDAT.


      try with this code..


      TYPES: BEGIN OF typ_cust,

      customerno(15) TYPE c,

      customername(15) TYPE c,

      quantity(15) TYPE c,

      amount(15) TYPE c,

      ws_total TYPE c,

      wg_total TYPE c,

      ws_totals TYPE c,

      wg_totals TYPE c,

      END OF typ_cust.

      DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno

      customername quantity amount .

      DATA : wa_cust TYPE typ_cust,

      wa_temp TYPE typ_cust,

      ws_total TYPE typ_cust,

      wg_total TYPE typ_cust,

      ws_totals TYPE typ_cust,

      wg_totals TYPE typ_cust.

      DEFINE fill.

      wa_cust-customerno = &1.

      wa_cust-customername = &2.

      wa_cust-quantity = &3.

      wa_cust-amount = &4.

      append wa_cust to it_cust.

      END-OF-DEFINITION.

      fill '1000' 'C1' '10' '35'.

      fill '1000' 'C1' '11' '45'.

      fill '1000' 'C1' '12' '55'.

      fill '1000' 'C1' '13' '65'.

      fill '1000' 'C1' '14' '75'.

      fill '1000' 'C1' '15' '85'.

      fill '1000' 'C1' '16' '95'.

      fill '1001' 'C2' '17' '25'.

      fill '1001' 'C2' '18' '55'.

      fill '1001' 'C2' '19' '65'.

      data x(15) type c.

      LOOP AT it_cust INTO wa_cust.

      wa_temp = wa_cust.

      x = wa_cust-customername.

      AT FIRST.

      WRITE:/ 'Customer Details'.

      ENDAT.

      AT NEW customername.

      WRITE:/ wa_cust-customerno,x."wa_cust-customername.

      ENDAT.

      WRITE:/33 wa_cust-quantity,40 wa_cust-amount.

      SKIP 1.

      ws_total = ws_total + wa_cust-quantity.

      ws_totals = ws_totals + wa_cust-amount.

      AT END OF customerno.

      * SUM.

      ULINE 43(16).

      WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.

      CLEAR ws_total.

      * wa_temp-quantity,30 wa_temp-amount.

      ENDAT.

      wg_total = wg_total + wa_cust-quantity.

      wg_totals = wg_totals + wa_cust-amount.

      AT LAST .

      SKIP 2.

      WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.

      CLEAR: wg_total,wg_totals.

      ENDAT.

      ENDLOOP.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.