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

"AT END OF " statement not working

Dear All,

I have the code as below ,where i need to display the report customer wise and at the end of each customer wants the total of the qty for that customer.

But the AT END OF KUNNR is not working as expected.

SORT ITAB_RESULT BY KUNNR.

FORMAT RESET.

LOOP AT itab_result.

WRITE: /1(18) itab_result-matnr,

20(4) itab_result-spart,

25(15) itab_result-description,

42(8) itab_result-cr_date,

52(12) itab_result-kunnr,

65(8) itab_result-req_qty,

75(8) itab_result-sug_qty,

85(8) itab_result-ersda,

95(8) itab_result-fob,

105(8) itab_result-po_qty,

115(8) itab_result-atp_stock,

125(8) itab_result-po_receive_qty,

135(8) itab_result-po_sn_qty,

145(8) itab_result-bo_qty,

155(15) itab_result-netcbm LEFT-JUSTIFIED,

170(15) itab_result-grocbm LEFT-JUSTIFIED,

185(8) itab_result-mm01,

195(8) itab_result-mm02,

205(8) itab_result-mm03,

215(8) itab_result-mm04,

225(8) itab_result-mm05,

235(8) itab_result-mm06,

245(8) itab_result-mm07,

255(8) itab_result-mm08,

265(8) itab_result-mm09,

275(8) itab_result-mm10,

285(8) itab_result-mm11,

295(8) itab_result-mm12.

AT END OF kunnr.

FORMAT INTENSIFIED ON.

SKIP 1.

WRITE: /1 sy-uline.

SUM.

WRITE: /50 'CUSTOMER Total : ',

65(8) itab_result-req_qty DECIMALS 0,

75(8) itab_result-sug_qty DECIMALS 0.

WRITE: /1 sy-uline.

SKIP 1.

ENDAT.

AT LAST.

SKIP 1.

WRITE: /1 sy-uline.

SUM.

WRITE: /50 'Final Total : ',

65(8) itab_result-req_qty DECIMALS 0,

75(8) itab_result-sug_qty DECIMALS 0.

ENDAT.

ENDLOOP.

The result report displays the total after each record even the two records are for the same customer.

Please suggest what's worng in the coding.

Thanks in advance,

Swati

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 13, 2009 at 06:10 AM

    Hi,

    AT END OF statement will consider the end of all the previous fields in the internal table also.

    In your case, it will take end of combination of matnr, spart, description, cr_date and kunnr.

    So, have kunnr as the first field in the internal table and try it.

    Thanks and regards,

    Venkat

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 13, 2009 at 06:13 AM

    Hi,

    KUNNR should be the first field in internal table.

    Regards,

    Prashant

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 13, 2009 at 06:11 AM

    Hi,

    Use the statement AT NEW kunnr and then display the data.

    then use the AT END OF kunnr to display the total for that customer.

    Hope it helps.

    Regards,

    Rajesh Kumar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 13, 2009 at 06:13 AM

    Hi,

    AT End of statement will be working for each of your customer,

    you can try using *AT New Customer * inside the loop and populate

    another internal table for the required data for that customer and do ENDAT.

    Then inside that loop only use AT End of the new internal table populated customer

    and do your processing.

    Hope it helps

    Regards

    Mansi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 13, 2009 at 06:21 AM

    Thanks a lot guys...problem solved.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 13, 2009 at 06:24 AM

    Hi,

    check out the field position of Kunnr in your internal table,

    these statements work on key basis,

    suppose your internal table(it_final) structure is

    *---internal table for holding final data
    DATA: BEGIN OF IT_FINAL OCCURS 0,
          HKONT   LIKE BSIS-HKONT,   "GL Account
          MONAT   LIKE BSIS-MONAT,   "Period
          KUNNR   LIKE KNA1-KUNNR,   "Customer
          SEGMENT LIKE BSIS-SEGMENT, "segment
    END OF IT_FINAL.
    
    *---filling internal table for ALV1 from it_final
      SORT IT_FINAL BY HKONT MONAT KUNNR SEGMENT.
      LOOP AT IT_FINAL.
    
    AT NEW SEGMENT.
          SUM.
          IF IT_FINAL-SEGMENT = 'S00'.
    *----segment0
            IT_ALV1-SEGMENT0 = IT_FINAL-DMBTR.
          ENDIF.
    
          IF IT_FINAL-SEGMENT = 'S01'.
    *----segment1
            IT_ALV1-SEGMENT1 = IT_FINAL-DMBTR.
          ENDIF.
    ENDAT.   "at new segment.
    
    
        AT END OF KUNNR.
    *----total of all segments
          IT_ALV1-TOTAL = IT_ALV1-SEGMENT0 + IT_ALV1-SEGMENT1  + IT_ALV1-SEGMENT2
                        + IT_ALV1-SEGMENT3 + IT_ALV1-SEGMENT4.
    
          APPEND IT_ALV1.
          CLEAR IT_ALV1.
        ENDAT.    "AT END OF KUNNR
    endloop.    "  LOOP AT IT_FINAL.
    
    

    Hope this example will make you understand the concept.

    Thanks ,

    Krishna.

    Add a comment
    10|10000 characters needed characters exceeded

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.