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

using read statement

Former Member
0 Likes
1,401

Hi experts

how should i modify this statement

'select single parnr from ihpa into g_parnr' inorder to improve the performance.

can i use 'read' if yes can u plz give me the code for that

regards

siri

1 ACCEPTED SOLUTION
Read only

rahulkavuri
Active Contributor
0 Likes
1,371

LOOP AT IHPA.

READ TABLE DTABLE WITH KEY PARNR = IHPA-PARNR.

IF SY-SUBRC = 0.

g_parnr = IHPA-PARNR.

ENDIF.

ENDLOOP.

Message was edited by: Rahul Kavuri

14 REPLIES 14
Read only

rahulkavuri
Active Contributor
0 Likes
1,372

LOOP AT IHPA.

READ TABLE DTABLE WITH KEY PARNR = IHPA-PARNR.

IF SY-SUBRC = 0.

g_parnr = IHPA-PARNR.

ENDIF.

ENDLOOP.

Message was edited by: Rahul Kavuri

Read only

0 Likes
1,371

hi thank u

do we need to declare what is dtable in the code bcoz the code u gave is showing syntax error

regards

siri

Read only

0 Likes
1,371

Hi Sireesha,

yes you need to declare it and then you need to select it before loop it self. check the above code.

Regards

vijay

Read only

0 Likes
1,371

hi vijay

for suppose i want to select the data from IHPA data base table

how should i declare at begining

and how i should use the select statement.

regards

siri

Read only

0 Likes
1,371

Hi,

it should be like this..

data: it_ihpa like ihpa occurs 0 with header line.

select * from ihpa into table it_ihpa.

then proceed...

Regards

vijay

Read only

Former Member
0 Likes
1,371

Hi sireesha,

1. READ statement is for reading from

internal table (and not database table)

2. Your select statement is perfectly fine,

3. we can use where condition for this table ihpa,

for fields

OBJNR

PARVW

COUNTER

to improve the performance.

(bcos they are primary key fields of this table)

4. Other wise, there is no scope for improvement

for this simple select statement.

regards,

amit m.

Read only

Former Member
0 Likes
1,371

YOu cannot use a read statemkent to fetch records from database.

change your select single statement to this(Use the key fields in the where clause)

select single parnr from ihpa into g_parnr where OBJNR = p_OBJNR and PARVW = p_PARVW and COUNTER = p_COUNTER.

REgards,

Ravi

Read only

Former Member
0 Likes
1,371

Hii

use identical select statements.

Therefore, SORT the table and use READ TABLE WITH KEY BINARY SEARCH.

USE THE FOLLOWING

sort IT_VBAP BY MATNR .

LOOP AT IT_VBAP.

<b>READ TABLE IT_MAKT KEY MATNR = IT_VBAP-MATNR

TRANSPORTING MAKTX binary search .</b>

IF SY-SUBRC NE 0.

<b>SELECT MATNR MAKTX FROM MAKT

APPENDING TABLE IT_MAKT-MAKTX

WHERE MATNR EQ IT_VBAP-MATNR.</b>

ENDIF.

MOVE: IT_MAKT TO IT_VBAP-MAKTX.

ENDLOOP.

<b>Instead of: </b>

LOOP AT IT_VBAP.

SELECT SINGLE MAKTX INTO IT_VBAP-MAKTX

FROM MAKT

WHERE MATNR EQ IT_VBAP-MATNR.

ENDLOOP.

reward points if helpful .

Regards

Naresh

Read only

Former Member
0 Likes
1,371

Hi,

Using read :

read t_internal_tab with key matnr = wa_mara-matnr binar search....

but it's applicable to internal table only and not reading database table

Plz reward points and close the thread

regards

gunjan

Read only

Former Member
0 Likes
1,371

HI

GOOD

THERE IS NO MISTAKE IN YOUR SELECT STATEMENT AND I DONT THINK IT WILL GIVE YOU A BAD PERFORMANCE.

THANKS

MRUTYUN

Read only

Former Member
0 Likes
1,371

Hi,

Your select single statement seems to be fine because it scans the table only for a single record which satisfies the condition. you can also use select upto 1 rows.

Regards,

Aswin

Read only

Former Member
0 Likes
1,371

if you are using the <b>select single</b> in side<b> loop</b>, then you can use <b>for all entries</b> and then use <b>Read</b> in side loop as suggested by Rahul.

Regards

vijay

Read only

abdul_hakim
Active Contributor
0 Likes
1,371

hi,

READ is for reading from internal table.

you cannot use READ for reading from the database table.

Suppose if you want to fetch more than one record from a table then don't use select single instead use select field1 field2 from table1 into table itab variant this will improve your performance...

Cheers,

Abdul Hakim

Mark all useful answers

Read only

Former Member
0 Likes
1,371

Hi ,

First select all ur PARNR into on internale table , then use READ where ever u want

SELET PARNR FROM IHPA INTO TABLE IT_PARNR.

then u can use this table whereever u want

SORT IT_PARNR by PARNR.
eg : LOOP AT IT_FINAL.
         READ TABLE IT_PARNR WITH KEY PARNR = IT_FINAL-PARNR BINARY SEARCH.
 ENDLOOP.