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: 

Use of AT NEW statement

Former Member
0 Kudos

Hi,

In my program have written the code as

SORT gt_bsik BY lifnr belnr gjahr buzei.

DATA : gv_count TYPE i VALUE 0.

IF sy-subrc = 0.

LOOP AT gt_bsik.

AT NEW lifnr .

READ TABLE gt_lfb1 WITH KEY lifnr = gt_bsik-lifnr BINARY

SEARCH.

CLEAR lt_vendors.

lt_vendors-lifnr = gt_lfb1-lifnr.

ENDAT.

AT NEW belnr.

gv_new_invoice_ind = 'X'.

gt_bsik_copy-lifnr = gt_bsik-lifnr.

gt_bsik_copy-belnr = gt_bsik-belnr.

gt_bsik_copy-gjahr = gt_bsik-gjahr.

gt_bsik_copy-buzei = gt_bsik-buzei.

gv_count = gv_count + gt_bsik-buzei .

ENDAT.

the value of gt_bsik-buzei is coming as *** after passing tho AT NEW belnr stmt.Before that the value is correct only after passing tho it showing wrong value but the other fields are showing correct value .Whats the reason for this?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

This is a standard behavior. All the fields on the right hand side of the field that you mention in the AT event are converted to *.

What you need to use an auxilary work area and copy the contents in it before the AT event.


SORT gt_bsik BY lifnr belnr gjahr buzei.

DATA : gv_count TYPE i VALUE 0.

IF sy-subrc = 0.
LOOP AT gt_bsik.
wa_bsik = gt_bsik.
AT NEW lifnr .
READ TABLE gt_lfb1 WITH KEY lifnr = wa_bsik-lifnr BINARY
SEARCH.
CLEAR lt_vendors.
lt_vendors-lifnr = gt_lfb1-lifnr.
ENDAT.
AT NEW belnr.
gv_new_invoice_ind = 'X'.
gt_bsik_copy-lifnr = wa_bsik-lifnr.
gt_bsik_copy-belnr = wa_bsik-belnr.
gt_bsik_copy-gjahr = wa_bsik-gjahr.
gt_bsik_copy-buzei = wa_bsik-buzei.
gv_count = gv_count + wa_bsik-buzei .
ENDAT.
....

5 REPLIES 5

Former Member
0 Kudos

Hi,

This is a standard behavior. All the fields on the right hand side of the field that you mention in the AT event are converted to *.

What you need to use an auxilary work area and copy the contents in it before the AT event.


SORT gt_bsik BY lifnr belnr gjahr buzei.

DATA : gv_count TYPE i VALUE 0.

IF sy-subrc = 0.
LOOP AT gt_bsik.
wa_bsik = gt_bsik.
AT NEW lifnr .
READ TABLE gt_lfb1 WITH KEY lifnr = wa_bsik-lifnr BINARY
SEARCH.
CLEAR lt_vendors.
lt_vendors-lifnr = gt_lfb1-lifnr.
ENDAT.
AT NEW belnr.
gv_new_invoice_ind = 'X'.
gt_bsik_copy-lifnr = wa_bsik-lifnr.
gt_bsik_copy-belnr = wa_bsik-belnr.
gt_bsik_copy-gjahr = wa_bsik-gjahr.
gt_bsik_copy-buzei = wa_bsik-buzei.
gv_count = gv_count + wa_bsik-buzei .
ENDAT.
....

0 Kudos

How should i declare the work area wa_bsik.I have previously declared gt_bsik as an internal table.

Another one doubt is other values are getting populated correctly then y buzei value is alone populated ass ***.It would be so kind enough if you clear my doubts

0 Kudos

Hi

- How should i declare the work area wa_bsik.I have previously declared gt_bsik as an internal table.

Yes, u should.

It's better to use a workarea in you need to read all data of BSIK in the AT NEW statament

LOOP AT GT_BSIK.
   WA_BSIK = GT_BSIK.

   AT NEW LIFNR.
       IF WA_BSIK-BUZEI =...
   ENDAT.

- Another one doubt is other values are getting populated correctly then y buzei value is alone populated ass ***.It would be so kind enough if you clear my doubts

Other fields at the right of LIFNR will have **** as value, i.e. in AT NEW u can read only the value of the field on the left of LIFNR: so MANDT, BUKRS and LIFNR, of course.

Max

0 Kudos

HI,

Between AT NEW and endat statements you would have the field contents as **** after the field for which you have used in AT NEW statement. For example if you have used the 3rd field in AT NEW statement then between AT NEW and ENDAT statements you can access the first 3 fields contents only.If you want to access any field after 3rd field then you have to take a Back Up of those fields before you enter in to AT statement. In your case declare a WA_BSIK of type GT_BSIK.

Data : wa_bsik LIKE gt_bsik.

Before you enter in to AT NEW statement transfer contents of gt_bsik to wa_bsik.

WA_BSIK = GT_BSIK.

Between AT NEW and ENDAT use the field contents of wa_bsik and not gt_bsik.

AT NEW belnr.

gv_new_invoice_ind = 'X'.

wa_bsik_copy-lifnr = wa_bsik-lifnr.

wa_bsik_copy-belnr = wa_bsik-belnr.

wa_bsik_copy-gjahr = wa_bsik-gjahr.

wa_bsik_copy-buzei = wa_bsik-buzei.

gv_count = gv_count + wa_bsik-buzei .

ENDAT.

Former Member
0 Kudos

Alternatively, try ON CHANGE OF gt_bsik-belnr instead of AT NEW belnr

Regards,

Raman.