Application Development 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: 

Storing field value into variable using select query

0 Kudos
 DATA var TYPE c LENGTH 20.
 SELECT SINGLE lokkt FROM bseg INTO var WHERE hkont = value.
 

Hey gurus, I'm trying to store a field value from table directly into a variable using this query.. I'm guessing there is a logical error or the query itself could be wrong.. if so then please help me understand how could i achieve this or fix it?

8 REPLIES 8

GK817
Active Contributor
SELECT SINGLE lokkt FROM bseg INTO  @DATA(lv_lokkt) where hkont =  @value.

GK817
Active Contributor
0 Kudos

Are you getting any error?

0 Kudos

The program is going into infinite loop.. since this is the only change i made i'm guessing this query broke something else in the code

p244500
Active Contributor

Sandra_Rossi
Active Contributor

Infinite loop or just very very very long? BSEG used to be a cluster table, so maybe it's your case, and HKONT is not part of the primary key, consequently, a huge number of lines will have to be read from BSEG table until one line satisfies the condition.

What did you change?

GK817
Active Contributor
0 Kudos

No loop there.

Please try UPTO 1 ROWS or may be 100 ROWS and see if you get the results. If yes, then may be it's the huge data as suggested by Sandra.

former_member1716
Active Contributor
0 Kudos

Prasad Supare,

The data type of the field used in the select Query is different from the variable, you need to correct that. You data declaration and code must be as below:

DATA var TYPE ALTKT_SKB1.
SELECT SINGLE lokkt 
FROM bseg 
INTO @var 
WHERE hkont = @value.

Or

You can use the code suggested by Gaurav Above.

Regards!

michael_koehler2
Participant
0 Kudos

Hi Prasad,

In the old days FiDoc item table BSEG used to be a cluster table w/ only BELNR / POSNR as the primary key. The way to go was to look for a secondary index either on BKPF (FiDoc Header) or one of the secondary index tabs (BSID... etc). Check if HKONT is an index on BKPF or another table that contains the BELNR, then join w/BSEG on BELNR. That should give you acceptable performance... at least used to in ECC. S/4 HANA; no clue, but worth a try!

A remark on the other answers: IMHO they 'only' address the 'formally unclean' code, but not the performance... (except, of course, Sandra's comment...)

All the best,
Mike