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

Reg : Read statement

Former Member
0 Likes
924

Hi all ,

i am using a select query which is below .but the requirement is to use a read statement .read statement on a database table any sample code .thanks in advance.

SELECT werks mtart matnr exclude INTO TABLE

itab_exclude FROM zwm_tbl_mat_alog WHERE werks IN s_werks

AND exclude EQ 'X'.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
892

Try-

Fetch all records from database table into one internal table and use 'read with key' on this internal table.

Regards,

Aparna Gaikwad

8 REPLIES 8
Read only

Former Member
0 Likes
892

i am using a select query which is below .but the requirement is to use a read statement .read statement on a database table any sample code .thanks in advance

am afraid to say we cannot use read command with select.

Amit.

Read only

Former Member
0 Likes
892

hiii

you can not use READ statement on database table..take data in one internal table and then use READ statement on that data.

Before we were able to use it but in new version it is obsolute..syntax was like below

READ TABLE dbtab [WITH KEY key] 
                 [SEARCH {FKEQ|FKGE|GKEQ|GKGE}] 
                 [VERSION vers].

instead of using READ on Database table you can use SELECT SINGLE statement..it will give a same result with dbtab.

regards

twinkal

Read only

Former Member
0 Likes
893

Try-

Fetch all records from database table into one internal table and use 'read with key' on this internal table.

Regards,

Aparna Gaikwad

Read only

JozsefSzikszai
Active Contributor
0 Likes
892

this is OK what you've done...

SELECT ==> DB table

READ TABLE ==> internal table

no other way possible, whatever the requirement is

Read only

Former Member
0 Likes
892

hi,

Read is only used with Internal Table.

Put All Data in an internal table and Use READ command.

Regards

Sumit Agarwal

Read only

Former Member
0 Likes
892

SELECT werks mtart matnr exclude INTO TABLE

itab_exclude FROM zwm_tbl_mat_alog WHERE werks IN s_werks

AND exclude EQ 'X'.

read table itab_exclude with index 1 .

Read only

Former Member
0 Likes
892

Hi

READ TABLE dbtab [WITH KEY key]

[SEARCH {FKEQ|FKGE|GKEQ|GKGE}]

[VERSION vers].

Effect

This variant of the statement READ (not allowed in classes) reads a row from the database table dbtab and assigns the content to the respective table work area. For dbtab, you must specify the name of a database table that begins with "T" and is not longer than five characters. The table work area must have been declared with statement TABLES for database table dbtab. If a database table is specified that does not begin with "T", then the first letter is implicitly replaced by "T".

Without the addition WITH KEY, the row to be read is determined by the content of the components of the table work area that correspond to the primary key fields of database table dbtab.

System Fields

sy-subrc Relevance

0 A table entry was read.

4 No table entry was found under the specified search key.

8 The table work area is too short.

12 The database table was not found.

Addition 1

... WITH KEY key

Effect

With the addition WITH KEY, the key is determined through the content of data object key for which a flat character-type data type is expected.

The content of the table work area resp. of the data object key is taken from the database table as search key (left-aligned with the length of the key components); then a matching entry is searched in the database.

Addition 2

... SEARCH {FKEQ|FKGE|GKEQ|GKGE}

Effect

The addition SEARCH determines how the row is searched:

Without the addition SEARCH and with SEARCH FKEQ, the first row in the database table is searched that matches the withdrawn search key.

With SEARCH GKEQ, you search generically for the first row of the database table that matches the withdrawn search key. The search key treats blanks as if they match all values.

With SEARCH FKGE, the first row of the database table is searched that is larger or equal to the withdrawn search key.

With SEARCH GKGE, you search generically for the first row of the database table that is larger or equal to the withdrawn search key. The search key treats blanks as if they match all values.

Addition 3

... VERSION vers

Effect

If the addition VERSION is specified, then not the database table dbtab is read, but the table whose name is composed of "T" and the content of vers. For vers, you have to specify a data object of the type c with a maximum length of four characters. If the database table is not available, sy-subrc is set to 12.

The content of the rows is still assigned to table work area dbtab, on whose type it is also cast onto. If table work area is too short, then sy-subrc is set to 8.

The statement is not executed if the database table does not exist or does not comply with the naming conventions stated above.

Example

Reading of a row from the database table T100 or another database table that starts with "T".

TABLES t100.

PARAMETERS p TYPE c LENGTH 4 DEFAULT '100T'.

t100-sprsl = 'E'.

t100-arbgb = 'BC'.

t100-msgnr = '010'.

READ TABLE t100 SEARCH FKEQ VERSION p.

IF sy-subrc = 0.

...

ENDIF.

The Open-SQL-syntax to be used instead reads:

PARAMETERS p TYPE c LENGTH 5 DEFAULT 'T100T'.

DATA dref TYPE REF TO data.

FIELD-SYMBOLS <fs> TYPE ANY.

CREATE DATA dref TYPE (p).

ASSIGN dref->* TO <fs>.

SELECT SINGLE *

FROM (p)

INTO <fs>

WHERE sprsl = 'E' AND

arbgb = 'BC' AND

msgnr = '010'.

IF sy-subrc = 0.

...

ENDIF.

Regards

Aditya

Read only

Former Member
0 Likes
892

First of all you cant use READ for a database table

If you want to use READ, do it on you internal table itab_exclude

Use READ as

READ TABLE itab { table_key

| free_key

| index } result.

Hope this helps!