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 problem

Former Member
0 Kudos
100

Hi Experts ...

hope you will help me out...

I have use AT End of , expecting that will solve my problem.....

but since iam new to control break stmt....iam struggling abit to fix it off...

As per my code....

The same value gets repeated for WA_FINAL-GROSS and WA_FINAL-NET

its not refreshing , and same value gets repeated...

can you please help me out correctin my AT End of code

CODE

sort it_bseg by belnr.

loop at it_bseg into wa_bseg .

wa_final-kunnr = wa_bseg-kunnr.

read table it_amount into wa_amount with key belnr = wa_bseg-belnr.

At end of belnr.

if wa_bseg-hkont = '0000500100'.

if sy-subrc = 0.

wa_final-gross = wa_amount-dmbtr.

endif.

endif.

if wa_bseg-koart = 'D'.

if sy-subrc = 0.

wa_final-net = wa_amount-dmbtr.

Endif.

Endif.

*at end of belnr.

*Endif.

read table it_bkpf into wa_bkpf with key belnr = wa_bseg-belnr.

if sy-subrc = 0.

wa_final-xblnr = wa_bkpf-xblnr.

wa_final-bldat = wa_bkpf-bldat.

endif.

*At end of belnr.

append wa_final to it_final.

Endat.

clear wa_amount.

clear wa_final.

endloop.

6 REPLIES 6

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
70

Hello Rachel,

A typical problem faced with LOOP control stmts. Declare another work area WA_BSEG1 and use it for processing:

SORT it_bseg BY belnr.

DATA: wa_bseg1 LIKE wa_bseg.

LOOP AT it_bseg INTO wa_bseg.

  wa_bseg1 = wa_bseg.

  wa_final-kunnr = wa_bseg1-kunnr.

  READ TABLE it_amount INTO wa_amount WITH KEY belnr = wa_bseg1-belnr.

  AT END OF belnr.
    IF wa_bseg1-hkont = '0000500100'.
      IF sy-subrc = 0.
        wa_final-gross = wa_amount-dmbtr.
      ENDIF.
    ENDIF.

    IF wa_bseg1-koart = 'D'.
      IF sy-subrc = 0.
        wa_final-net = wa_amount-dmbtr.
      ENDIF.
    ENDIF.

    READ TABLE it_bkpf INTO wa_bkpf WITH KEY belnr = wa_bseg1-belnr.

    IF sy-subrc = 0.

      wa_final-xblnr = wa_bkpf-xblnr.
      wa_final-bldat = wa_bkpf-bldat.

    ENDIF.

*At end of belnr.

    APPEND wa_final TO it_final.
  ENDAT.
  CLEAR wa_amount.
  CLEAR wa_final.
ENDLOOP.

Hope this helps.

BR,

Suhas

Former Member
0 Kudos
70

Thanx for helping me out...

I tried the way u said...but still doesnt reflect any changes........

Former Member
0 Kudos
70

At end of triggers for every end of the unique combination of the fields left to the BELNR in your case.

You need not to write if sy-subrc inside, ex if wa_bseg-hkont = '0000500100'.

if sy-subrc = 0. In this case Sy-subrc is not required. the above check is enough.

If you understand the concept of At end of it will be easy.

0 Kudos
70

Use statement clear wa_bseg at the end of each loop ..

Regards

Nishit .

former_member242255
Active Contributor
0 Kudos
70

i think the 1st At end of belnr statement should be before the READ staement.

regards,

sravan

Former Member
0 Kudos
70

Check the codes:

DATA:W_index type i,

w_index1 type i.

sort it_bseg by belnr.

loop at it_bseg into wa_bseg .

add 1 to w_index.

wa_final-kunnr = wa_bseg-kunnr.

read table it_amount into wa_amount with key belnr = wa_bseg-belnr.

At end of belnr.

w_index1 = w_index.

Endat.

IF w_index1 = w_index.

if wa_bseg-hkont = '0000500100'.

if sy-subrc = 0.

wa_final-gross = wa_amount-dmbtr.

endif.

endif.

if wa_bseg-koart = 'D'.

if sy-subrc = 0.

wa_final-net = wa_amount-dmbtr.

Endif.

Endif.

*at end of belnr.

*Endif.

read table it_bkpf into wa_bkpf with key belnr = wa_bseg-belnr.

if sy-subrc = 0.

wa_final-xblnr = wa_bkpf-xblnr.

wa_final-bldat = wa_bkpf-bldat.

endif.

*At end of belnr.

append wa_final to it_final.

ENDIF.

clear wa_amount.

clear wa_final.

endloop.

Regards,

Gurpreet