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 statement

Former Member
0 Likes
821

Hi,

I am getting error in following select statement

data: begin of tt_data,

kunnr like kna1-kunnr,

name1 like kna1-name1,

vbeln like vbak-vbeln,

posnr like vbap-posnr,

kwmeng like vbap-kwmeng,

end of tt_data.

data: gt_data like table of tt_data,

gs_data like line of gt_data.

loop at gt_data into gs_data.

select single posnr kwmeng into (gs_data-posnr, gs_data-kwmeng)

from vbap where vbeln = p_vbeln.

endloop.

Pls concentrate on only select statement. I am getting error in only select statement.

6 REPLIES 6
Read only

Former Member
0 Likes
786

Hi Neha,

Please use the following corrected code.

data: begin of tt_data,
kunnr like kna1-kunnr,
name1 like kna1-name1,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
kwmeng like vbap-kwmeng,
end of tt_data.

data: gt_data like table of tt_data,
gs_data like line of gt_data.

loop at gt_data into gs_data.
select single posnr kwmeng into ( gs_data-posnr,gs_data-kwmeng ) 
from vbap where vbeln = p_vbeln.
endloop.

Before brackets you need to give space. Please sap help example.

Instead of select statement in loop. plz use select ... for all entries statement.

Regards

Bhupal Reddy

Read only

0 Likes
786

Space is needed before using brackets as follows in ur select statements -

select single posnr kwmeng into ( gs_data-posnr,gs_data-kwmeng )

from vbap where vbeln = p_vbeln.

also instead of using the select statement in a loop ,u can use for all entries in the select statement to fetch the dat at one shot..it will enhance the performance of ur code..

amit

Read only

Clemenss
Active Contributor
0 Likes
786

Hi,

for me it looks fine, even the missing spaces some guys want to see. HELP says:

SELECT ... INTO (<f1>, <f 2>, ...). ...

You must specify as many individual fields <f i > as are specified in the field list of the SELECT clause. The fields in the SELECT clause are assigned, from left to right, to the fields in the list in the INTO clause.

So where is the space afetr the bracket? Spaces are required for functional evaluations like aggregate functions (MAX, MIN, ...).

But: where vbeln = p_vbeln looks suspicious because p_vbeln is not defined visibly - it may be mistaken for gs_data-vbeln.

You could use INTO CORRESPONDING FIELDS OF gs_data. It does not affect performance although repeatedly otherwise stated.

The SELECT SINGLE within the LOOP is POISON for performance. And it will always read only one item of the vbeln document regardless of how many items are present.

Better define a second table for the item data, read them all together and then transfer values to gt_data.

data:
  gt_itemdta like sorted table of tt_data with unique key vbeln posnr.

select vbeln posnr kwmeng 
  into corresponding fields of table gt_itemdta
  from vbap
  for all entries in gt_data
  where vbeln = gt_data-vbeln.

loop at gt_data into gs_data.
* Because gt_itemdta is sorted table with defined keys, loop is fast
  loop at gt_itemdta into tt_data
    where vbeln = gs_data-vbeln.
    add tt_data-kwmeng to gs_data-kwmeng.
    gs_data-posnr = tt_data-posnr."??? What about mulitiple items ??
  endloop.
modify gt_data from gs_data
endloop.

And using field-symbols will speed it up again...

Regards,

Clemens

Read only

0 Likes
786

You also need a space after the comma.



select single posnr kwmeng into ( gs_data-posnr, gs_data-kwmeng ) 
from vbap where vbeln = p_vbeln.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
786

select single posnr kwmeng into (gs_data-posnr, gs_data-kwmeng)

from vbap where vbeln = p_vbeln.

I DIDNT SEE P_VBELN IF IT IS PARAMETER THEN IT IS OK BUT FOR SELECT-OPTION YOU HAVE TO GIVE IN INSTEAD OF =. AND SPACE AFTER COMMA.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
786

Hi Neha ,

I executed the statement and it worked for me .

Could you please tell what exaclty is the error you are getting.

Regards

Arun