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 and AT New Commands

Former Member
0 Kudos

Hi...

While using AT END command i am facing one problem...

I have all the data present in the internal table l_i_item_temp with BELNR as a first field.

After the loop statement the l_wa_item_temp contains the actual values.

However after triggering of AT END of event, the fields values after BELNR are becoming garbage values in the work area l_wa_item_temp.

IF l_i_item_temp IS NOT INITIAL.

SORT l_i_item_temp BY belnr.

LOOP AT l_i_item_temp INTO l_wa_item_temp.

AT END OF belnr.

l_wa_item_data_temp-belnr = l_wa_item_temp-belnr.

l_wa_item_data_temp-augbl = l_wa_item_temp-augbl.

l_wa_item_data_temp-bldat = l_wa_item_temp-bldat.

l_wa_item_data_temp-xblnr = l_wa_item_temp-xblnr.

l_wa_item_data_temp-shkzg = l_wa_item_temp-shkzg.

l_wa_item_data_temp-dmbtr = l_v_dmbtr1.

l_wa_item_data_temp-zfbdt = l_wa_item_temp-zfbdt.

l_wa_item_data_temp-zbd1t = l_wa_item_temp-zbd1t.

l_wa_item_data_temp-zbd2t = l_wa_item_temp-zbd2t.

l_wa_item_data_temp-zbd3t = l_wa_item_temp-zbd3t.

l_wa_item_data_temp-rebzg = l_wa_item_temp-rebzg.

Also if we try the same with field symbols the actual values are getting filled in the field symbol.

So i just wanted to generally we use work area in looping before using the AT END command even if it givein the garbage values.

And why there is a different behavoiur with the work area and the field symbols in case of AT END events.

Thanks in advance for your help.

Regards,

Anuja

11 REPLIES 11

Former Member
0 Kudos

Hi,

To solve this...

Declare a variable

data flag type c.

IF l_i_item_temp IS NOT INITIAL.

SORT l_i_item_temp BY belnr.

LOOP AT l_i_item_temp INTO l_wa_item_temp.

clear flag.

AT END OF belnr.

flag = 'X'.

endat.

if flag = 'X'.

l_wa_item_data_temp-belnr = l_wa_item_temp-belnr.

l_wa_item_data_temp-augbl = l_wa_item_temp-augbl.

l_wa_item_data_temp-bldat = l_wa_item_temp-bldat.

l_wa_item_data_temp-xblnr = l_wa_item_temp-xblnr.

l_wa_item_data_temp-shkzg = l_wa_item_temp-shkzg.

l_wa_item_data_temp-dmbtr = l_v_dmbtr1.

l_wa_item_data_temp-zfbdt = l_wa_item_temp-zfbdt.

l_wa_item_data_temp-zbd1t = l_wa_item_temp-zbd1t.

l_wa_item_data_temp-zbd2t = l_wa_item_temp-zbd2t.

l_wa_item_data_temp-zbd3t = l_wa_item_temp-zbd3t.

l_wa_item_data_temp-rebzg = l_wa_item_temp-rebzg.

endif.

endloop.

Former Member
0 Kudos

Hi Anuja,

Case 1. AT Command using Work Area:

In this case system creates a new memory area which is assigned to your work area l_wa_item_temp.

When the at command is used all the non-numeric fields are set to * (this not any garbage value) and the numeric values are set to initial ( this will happen only in the work area not in the table ). You will come to know the strength of AT command when you use commands like 'SUM' within AT.

Case 2: AT Command Using Field Symbols:

You should be aware that FS is a pointer so system does not make any memmory allocation for the same. Rather the FS points to the corresponding row of the internal table directly. So here you will not find any * or your garbage values :-).

I hope it clears your doubt.

Regards,

Prakash Pandey

Former Member
0 Kudos

HI,

HI,

Instead of Loop at itab into wa.....

Try this way...

data: g_wa like l_i_item_temp .

IF l_i_item_temp IS NOT INITIAL.

SORT l_i_item_temp BY belnr.

LOOP AT l_i_item_temp INTO l_wa_item_temp.

move l_i_item_temp to g_wa .

AT END OF belnr.

l_wa_item_data_temp-belnr = lg_wa -belnr.

l_wa_item_data_temp-augbl = g_wa -augbl.

l_wa_item_data_temp-bldat = g_wa -bldat.

l_wa_item_data_temp-xblnr = lg_wa -xblnr.

l_wa_item_data_temp-shkzg = g_wa -shkzg.

l_wa_item_data_temp-dmbtr = l_v_dmbtr1.

l_wa_item_data_temp-zfbdt = g_wa -zfbdt.

l_wa_item_data_temp-zbd1t =g_wa -zbd1t.

l_wa_item_data_temp-zbd2t = g_wa -zbd2t.

l_wa_item_data_temp-zbd3t =g_wa -zbd3t.

l_wa_item_data_temp-rebzg = g_wa -rebzg.

former_member1245113
Active Contributor
0 Kudos

Hi,

Wheneve we use AT key word the right hand side char type fields becomes *** this is architecture provided by SAP.

Please go through the KEY word documentaion of AT for further info.

Regards

ramchander Rao.K

Former Member
0 Kudos

Declare one more work area with the same structure and move the contents to this new WA. You can use the values of this wa inside your AT END statement.

Former Member
0 Kudos

Hi Anuja,

you need to declare one more work area same as l_wa_item_temp.For example see the below code.

data: l_wa_item_temp1 like line of l_i_item_temp.

loop at l_i_item_temp to l_wa_item_temp.

move-corresponding l_wa_item_temp to l_wa_item_temp1.

at end of belnr.

move-corresponding l_wa_item_temp1 to l_wa_item_data_temp.

endat.

endloop.

I already tested the above code. It is working fine.....check it once.

Thanks,

Kiran.

Former Member
0 Kudos

Hi...

Many thanks for your replies.

However i am actually interested to know, why we do not go for field symbols when using control events inside a loop. The concerns here is while using the control events the work area get initialized( Numric values are set to 0 and Non numeric fields to *) and this does not happen with the field symbol.

But the field symbol also holds the data. So why it is preffered to go with the work area rather than a field symbol.

Looking forward for your reply.

Regards,

Anuja

0 Kudos

Hi Anuja

If you are not getting * with Field symbols you can use field symbols as a work area.

I don`t see any issue their.

Regards

Neha

Former Member
0 Kudos

Hi Neha,

Many thanks for your quick reply.

Ok it is fine. However it is a practice to use the work areas genrally instead of field symbols and copy that work area into another work area of same type.

So , i just want to confirm will it be a problem ot erratic condition if we use the field symbols.

Looking forward for your reply.

Regards,

Anuja

0 Kudos

Hi Anuja,

I don't find any difficulties in using field symbol with control break statements.

Try the below code.

REPORT  ztest.

DATA: gt_itab TYPE TABLE OF makt.

FIELD-SYMBOLS: <gwa_itab> TYPE makt.

SELECT * FROM makt INTO TABLE gt_itab UP TO 30 ROWS.

LOOP AT gt_itab ASSIGNING <gwa_itab>.

  AT NEW matnr.

    WRITE:/ sy-tabix, ':',  <gwa_itab>-matnr.

  ENDAT.

ENDLOOP.

Former Member
0 Kudos

This message was moderated.