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 stmt

0 Likes
958

Hi,

Can any one suggest me how to place the below select statement in a subroutine currently which was executing in a loop .

select single kappl objky kschl into wa_otype

from nast

where kappl = wa_vbrk-kappl

and objky = wa_vbrk-objky.

wa_vbrk-kschl = wa_otype-kschl.

we can get wa_... from the loop.

instead of writing multiple time the same code i want to move this to subroutine.

Regards,

Cheritha

7 REPLIES 7
Read only

former_member188827
Active Contributor
0 Likes
939

loop at itab into wa.

perform selection using wa.

endloop.

when u double click on the perform statement, it 'll create a form.

between form and endform statements copy ur code of select.

plz reward points if it helps

Message was edited by:

abapuser

Read only

varma_narayana
Active Contributor
0 Likes
939

Hi ..

from Performance point of view It is better to Write this select statement directly in the LOOP instead of calling a subroutine.

so no need to change ur code..

<b>Reward if Helpful</b>

Read only

Former Member
0 Likes
939

Hi,

there is no need of writing the code in the way u are expecting.the way u have written is the efficient one...

<b>reward if helpful</b>

rgds,

bharat.

Read only

dev_parbutteea
Active Contributor
0 Likes
939

Hi,

it think that it wud be better for performance if u do the select before the loop by using select for all entries.

then in loop, you just do a read statement.

Regards

Read only

Former Member
0 Likes
939

• Values can be passed through PERFORM to FORM.

• Giving the flexibility to use the same subroutine multiple number of times.

Syntax1: PERFORM <XXXX> using <YYY>

changing <MMM>

FORM <XXXX> using <YYY> like <ZZZ>

changing <MMM> like <NNN> - Pass by reference

OR

FORM <XXXX> using value (YYY) like <ZZZ> - Pass by value, creates another copy of the variable.

Example1:

PERFORM date-invert using in-date

Changing out-date

FORM date-invert using in-date like datum

Syntax2: PERFORM function-name(program) IF FOUND.

Example2: PERFORM HEADER(FORMPOOL) IF FOUND.

Read only

Former Member
0 Likes
939

Hello Cheritha,

Writing Select statement in a loop is not suggestable... it will kill performance.

-


use SELECT... FOR ALL ENTRIES IN itab. It will fetch all the related data for itab. Don't use loop...

any way i'm giving procedure for that also.

loop at ....

perform routine.

endloop.

form routine.

select single kappl objky kschl into wa_otype

from nast

where kappl = wa_vbrk-kappl

and objky = wa_vbrk-objky.

wa_vbrk-kschl = wa_otype-kschl.

we can get wa_... from the loop.

endform.

Reward If Helpful.

Regards

--

Sasidhar Reddy Matli.

Read only

Former Member
0 Likes
939

Hi Cheritha,

Try the below code.

Loop At t_vbrk into wa_vbrk.

Perform sub_select using wa_vbrk

changing wa_otype.

Endloop.

Form sub_select p_wa_vbrk type ty_vbrk

p_wa_otype type ty_otype.

select single kappl objky kschl into p_wa_otype

from nast

where kappl =p_ wa_vbrk-kappl

and objky = p_wa_vbrk-objky.

wa_vbrk-kschl = p_wa_otype-kschl.

EndFORM.

The p_wa_otype will be replicate as wa_otype inthe loop.

Thanks.