‎2006 Dec 13 9:04 AM
Hello friends,
In regard to control level processing of Internal tables ,with in at and enaat the if defaukt key fields will give '*' and numeric fields will give 0 in output.
can any body give example code for this?
‎2006 Dec 13 9:14 AM
Here is an example code ..
LOOP AT it_detail.
AT NEW OWN_NO.
READ TABLE IT_DETAIL INDEX SY-TABIX.
IT_DETAIL-FIELD1 = '001'.
MODIFY IT_DETAIL TRANSPORTING FIELD1.
OWNER_COUNT = OWNER_COUNT + 1.
ENDAT.
ENDLOOP.
Regards,
Santosh
‎2006 Dec 13 9:07 AM
loop at itab.
at new field1.
<b>read table itab index sy-tabix.</b>
endat.
endloop.
add the highlighted code.
Regards,
Ravi
‎2006 Dec 13 9:11 AM
thanks.but i wnt the small examole code ..i wnt to see when * and 0 will come in the output.when we use write stmt between at and endat.
‎2006 Dec 13 9:08 AM
hi,
use <b>read table</b> statement after that ..
Regards,
Santosh
‎2006 Dec 13 9:11 AM
try to use
on change of
or take your internal table value to some variable in the loop but before using at endat.
i.e.
loop at itab.
v_data = itab-data.
at new data.
write v_data.
endat.
endloop.
regards
shiba dutta.
‎2006 Dec 13 9:14 AM
Here is an example code ..
LOOP AT it_detail.
AT NEW OWN_NO.
READ TABLE IT_DETAIL INDEX SY-TABIX.
IT_DETAIL-FIELD1 = '001'.
MODIFY IT_DETAIL TRANSPORTING FIELD1.
OWNER_COUNT = OWNER_COUNT + 1.
ENDAT.
ENDLOOP.
Regards,
Santosh
‎2006 Dec 13 10:13 AM
Hi ,see this code.
tables: vbap.
select-options: s_posnr for vbap-posnr.
*parameters: p_matnr like vbap-matnr.
data: itab like vbap occurs 0 with header line.
data: wa like itab.
select * from vbap into table itab up to 10 rows where posnr in s_posnr
.
if not itab[] is initial.
loop at itab into wa.
at new matnr.
read table itab index sy-tabix.
write:/ wa-zmeng, wa-matkl, 'At new'.
endat.
endloop.
After exicuting the above code i am getting 0000 for zmeng and **** fro matkl.
How to over come this?
endif.
‎2006 Dec 13 10:17 AM
Hi ,
Here is the code
tables: vbap.
select-options: s_posnr for vbap-posnr.
*parameters: p_matnr like vbap-matnr.
data: itab like vbap occurs 0 with header line.
data: wa like itab,
wa1 like itab . " new varaible declared
select * from vbap into table itab up to 10 rows where posnr in s_posnr
.
if not itab[] is initial.
loop at itab into wa.
wa1 = wa. " additional statement
at new matnr.
read table itab index sy-tabix. " You dont need this
*write:/ wa-zmeng, wa-matkl, 'At new'. " Statement Commented
write:/ wa1-zmeng, wa1-matkl, 'At new'. " statement added
endat.
endloop.
endif.Regards
Arun
Message was edited by:
Arun Ramachandran
‎2006 Dec 13 10:18 AM
if not itab[] is initial.
SORT ITAB BY MATNR
loop at itab .
ON CHANGE OF ITAB-MATNR
write:/ ITAB-zmeng, ITAB-matkl, 'At new'.
ENDON.
endloop.
‎2006 Dec 13 10:20 AM
hi,
give like this...
data: itab like vbap occurs 0 with header line.
data: wa like itab.
select * from vbap into table itab up to 10 rows where posnr in s_posnr.
if not itab[] is initial.
loop at itab into wa.
at new matnr.
<b>read table itab into wa index sy-tabix.</b>
write:/ wa-zmeng, wa-matkl, 'At new'.
endat.
endloop.
endif.
regards,
priya.
‎2006 Dec 13 9:24 AM
Hi,
Make it more performant, more elegant and much easier in this way (just an entire example).
REPORT ztestdb_002 .
TYPES: BEGIN OF t_itab,
col1(3),
col2(3),
col3 TYPE n,
END OF t_itab.
DATA: itab TYPE TABLE OF t_itab,
wa TYPE t_itab.
FIELD-SYMBOLS: <fs> TYPE t_itab.
START-OF-SELECTION.
REFRESH itab.
CLEAR wa.
wa-col1 = 'A'.
wa-col2 = 'a'.
wa-col3 = 1.
APPEND wa TO itab.
CLEAR wa.
wa-col1 = 'A'.
wa-col2 = 'b'.
wa-col3 = 2.
APPEND wa TO itab.
CLEAR wa.
wa-col1 = 'A'.
wa-col2 = 'c'.
wa-col3 = 3.
APPEND wa TO itab.
CLEAR wa.
wa-col1 = 'B'.
wa-col2 = 'a'.
wa-col3 = 1.
APPEND wa TO itab.
SORT itab.
LOOP AT itab ASSIGNING <fs>.
AT NEW col1.
WRITE <fs>.
ENDAT.
ENDLOOP.
END-OF-SELECTION.
If you asked about the way it works, then:
- in order to work properly AT events within a loop, you must sort the itab!
- within AT event, in the working area of the loop are kept only fields, from left to right, up to the one which appear in AT event, and the others are filled with * or initial null value for numeric fields - exception: AT FIRST and AT LAST
- the only way to have all fields available within AT is using field-symbols (see my example)
‎2006 Dec 13 10:16 AM
Hi,
Try this:
read table itab <b>into wa</b> index sy-tabix.
Thanks,
Kalpana
‎2006 Dec 13 10:18 AM
hi,
take one temporary work area
tables: vbap.
select-options: s_posnr for vbap-posnr.
*parameters: p_matnr like vbap-matnr.
data: itab like vbap occurs 0 with header line.
data: wa like itab.
select * from vbap into table itab up to 10 rows where posnr in s_posnr
.
if not itab[] is initial.
loop at itab.
wa = itab. "bcoz itab is already declared with header line
at new matnr.
write:/ wa-zmeng, wa-matkl, 'At new'.
endat.
endloop.
try with this code it will work
‎2006 Dec 13 10:23 AM
Hey ,
Just a question what is the purpose of the statement
<b>read table itab index sy-tabix.</b>
inside the loop on itab.
You will get the output without this statement also.
Regards
Arun