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: 

"AT END OF " statement not working

Former Member

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

1 ACCEPTED SOLUTION

Former Member

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

6 REPLIES 6

Former Member

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

former_member386202
Active Contributor

Hi,

KUNNR should be the first field in internal table.

Regards,

Prashant

Former Member
0 Kudos

Thanks a lot guys...problem solved.

Former Member
0 Kudos

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.