Application Development and Automation 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: 
Read only

Control break statements

Former Member
0 Likes
1,117

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?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,086

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

13 REPLIES 13
Read only

Former Member
0 Likes
1,086

loop at itab.

at new field1.

<b>read table itab index sy-tabix.</b>

endat.

endloop.

add the highlighted code.

Regards,

Ravi

Read only

0 Likes
1,086

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.

Read only

Former Member
0 Likes
1,086

hi,

use <b>read table</b> statement after that ..

Regards,

Santosh

Read only

Former Member
0 Likes
1,086

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.

Read only

Former Member
0 Likes
1,087

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

Read only

0 Likes
1,086

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.

Read only

0 Likes
1,086

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

Read only

0 Likes
1,086

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.

Read only

0 Likes
1,086

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.

Read only

Former Member
0 Likes
1,086

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)

Read only

Former Member
0 Likes
1,086

Hi,

Try this:

read table itab <b>into wa</b> index sy-tabix.

Thanks,

Kalpana

Read only

Former Member
0 Likes
1,086

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

Read only

Former Member
0 Likes
1,086

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