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

read (or) loop statements

Former Member
0 Likes
703

hai abapers,

iam selecting some data base tables.

create some internal tables with their batabase tables.

all tables select quires completed by using for all entries condition.

problem is ?

some tables contains multiple records and some tables contains single records. so in this case

move into final table , i can take multiple records tables by using loop stament and single record tables

by using read stament.

but single record table fields repeted by same value along with multiple fields table.

how can i rectify this problem ?

my requirement is single field value only comes once , but not repeated.

6 REPLIES 6
Read only

Former Member
0 Likes
667

Hi,

use delete adjacent duplicates comparing the fields which you want to show only once in the repor

Regards

Lalit

Read only

Former Member
0 Likes
667

Hi,

Trt to select the data based on key fields from the table.

Thanks.

Read only

Former Member
0 Likes
667

Hi Raja,

if you donot want this happen,

do it like this.

***note : if you want this internal table data for further processing move the whole data into another similar internal table

itab2[] = itab1[].

take care of sy-tabix as it changes once after the loop statement and once per the read statement.

loop at itab.

read table itab1 with key f1 = itab-f1.

if sy-subrc is initial.

move-corresponding itab1 to i_final.

****now you delete the record from the itab1

delete itab1 index sy-tabix.

endif.

hope this will meet your purpose.

regards

Ramchander Rao.Krishnamraju

endloop.

or you can try this.

you can use the control break statements as follows.

in this case you dont need the delete the record of the internal table

please note here all the character fields become stars from right of the key field.

only numeric fields are available.

sort itab by f1.

loop at itab.

at new itab-f1.

read table itab1 with key f1 = itab-f1.

if sy-subrc is initial.

endif.

endat.

endloop.

Edited by: ramchander krishnamraju on Nov 12, 2008 6:13 AM

Edited by: ramchander krishnamraju on Nov 12, 2008 6:18 AM

Read only

Former Member
0 Likes
667

Jus try this...If u hv 2 internal tables, one wid multiple records and the other wid single records, then use 'loop' for single records table and 'read' for multiple records table....

Read only

0 Likes
667

hi,

if you loop the single record internal table you might end up in not processing the entire records.

as the case like this.

loop at i_vbak.

read table i_vbap.

endloop.

normally vbap contains more line items for a record in vbak.

then loop runs only single time.

regards

Ramchander Rao.K

Read only

Former Member
0 Likes
667

In ur final internal table if some data is rapeating , jst sort the internal table based upon the comparing fields and use delete adjacent dupilcate comparing <fields> .