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

select and endselect

Former Member
0 Likes
889

hello friends,

following is my scenario.

it seems little tricky and complex. can some one help me with this.

i never used select and endselect.

can we transfer data beteween different itabs and also get data from ztable at a time inside select and endselect

loop at itab1

select ztable3 where field4 = itab1-field4.

move itab1-field1 to itab2-field1.

move ztable3-field3 to itab2-field3.

itab2-field5 = ztable3-field7 * itab1-field6 * itab1-field5

endselect.

endloop

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
864

Hi Saritha,

The select .. endselect works as a loop fetching single record for every loop pause..

as you kept a select inside a loop .. you have 2 loops.. going to the database unnecessarily so many times is not a good idea...

instead you can write

select * from ztable3 for all entries in itab1 where field4 = itab1-field4.

then ...

loop at itab1.

read table ztable3 with key field4 = itab1-field4.

..move your fields...

append itab2.

endloop.

Regards,

Vidya.

8 REPLIES 8
Read only

Former Member
0 Likes
864

Yes it is possible.

SELECT...ENDSELECT is like a LOOP only.

SELECT * INTO ITAB1

FROM TAB.

LOOP AT ITAB1.

ITAB2-FIELD = ITAB1-FIELD1 * X.

APPEND ITAB2.

ENDLOOP.

is same as

SELECT * FROM TAB.

ITAB2-FIELD = TAB-FIELD1 * X.

ENDSELECT.

Read only

Former Member
0 Likes
865

Hi Saritha,

The select .. endselect works as a loop fetching single record for every loop pause..

as you kept a select inside a loop .. you have 2 loops.. going to the database unnecessarily so many times is not a good idea...

instead you can write

select * from ztable3 for all entries in itab1 where field4 = itab1-field4.

then ...

loop at itab1.

read table ztable3 with key field4 = itab1-field4.

..move your fields...

append itab2.

endloop.

Regards,

Vidya.

Read only

Former Member
0 Likes
864

Hello Saritha,

Do not use select endselect and it gives more performance issue

loop at itab1

select * from ztable3 into table itab2

where field4 = itab1-field4.

loop at itab2.

move itab1-field1 to itab2-field1.

move ztable3-field3 to itab2-field3.

itab2-field5 = ztable3-field7 * itab1-field6 * itab1-field5

endloop.

endloop

Reward Points if it is helpful

Thanks

Seshu

Read only

srinivas_akiri
Active Participant
0 Likes
864

Hi saritha,

we can write any no.of selects or select.. endselect( also another form of loop) statements within the loop. but it leads to poor performance since you are trying to access the same database table many times in the loop.

use for all entries clause to improve the performance.

Thanks

Srinivas

Read only

Former Member
0 Likes
864

hi darshil

thanks for response,

here i just want to know how to handle a situation where in data transfers and calculations happen between two itabs and a ztable

Read only

0 Likes
864

What exactly is the scenario? You want to move data to itab2 or you want to get data from itab1, itab2 and ztable3?

If you move data to itab2 or you want to get data from itab1, itab2 and ztable3:

loop at itab1

select ztable3 where field4 = itab1-field4.

*Use a read statement:

<b>READ TABLE ITAB2 WITH KEY ...

(or you can use LOOP AT ITAB2 in case of multiple records)</b>

move itab1-field1 to itab2-field1.

move ztable3-field3 to itab2-field3.

itab2-field5 = ztable3-field7 * itab1-field6 * itab1-field5

endselect.

endloop

If ITAB2 is your destination table then:

loop at itab1

select ztable3 where field4 = itab1-field4.

move itab1-field1 to itab2-field1.

move ztable3-field3 to itab2-field3.

itab2-field5 = ztable3-field7 * itab1-field6 * itab1-field5

<b>APPEND ITAB2.</b>

endselect.

endloop

Read only

Former Member
0 Likes
864

thanks friends,

can we use read on ztable.

Read only

Former Member
0 Likes
864

Saritha,

we cannot use a read on a database table directly.

we need to make a select from the ztable into an internal table and then read on that internal table.

Regards,

Vidya.