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

Read statement in internal table.

Former Member
0 Likes
2,631

PLease help me to figure out what a read statement does???

Please show me through examples how a read statements selects data from a table ,,,puts into internal table & finally we are able to read it through work area????

thanx... <REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Mar 10, 2008 7:27 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,257

Hi,

READ statement is mainly used to read a single line of any table.

READ TABLE <itab> <key> <result>.

Useful Link to know about READ statement :

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

<REMOVED BY MODERATOR>

Regards

Rose

Edited by: Alvaro Tejada Galindo on Mar 10, 2008 7:27 PM

8 REPLIES 8
Read only

Former Member
0 Likes
2,257

Reads records from an internal table ... we cannot get data directly

from a table using read statement.

data : it_pa0001 like pa0001 occurs 0 with header line.

select * from Pa0001 into table it_pa0001.

if sy-subrc = 0.

read table it_pa0001 index 1. <-- now it_pa0001 will have the first line

in the header.

endif.

Read only

0 Likes
2,257

Reads an entry from an internal table, using either its key or its index. The return code SY-SUBRC specifies whether an entry could be read. The system uses the specified table key values to locate the correct line. If there is more than one entry with the same key, the system returns the first.

SY-SUBRC = 0:

An entry was read.

SY-TABIX is set to the index of the entry.

SY-SUBRC = 2:

An entry was read.

SY-TABIX is set to the index of the entry. This return code can only occur when you use the COMPARING addition

SY-SUBRC = 4:

No entry was read.

The value of SY-TABIX depends on the table type and whether the BINARY SEARCH addition was specified.

If the table is a SORTED TABLE or a table sorted in ascending order of the type STANDARD TABLE with the BINARY SEARCH addition, SY-TABIX refers to the next-highest index.

SY-SUBRC = 8:

No entry was read.

This return code only occurs with a SORTED TABLE or a STANDARD TABLE with the BINARY SEARCH addition. SY-TABIX is set to the number of all entries plus 1.

The READ TABLE statement also fills the system fields SY-TFILL and SY-TLENG.

go through this link this might be helping you

http://help.sap.com/saphelp_470/helpdata/EN/fc/eb35f8358411d1829f0000e829fbfe/frameset.htm

Read only

Former Member
0 Likes
2,257

Hi,

To read a single line of any table read state ment is used

check this link

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/frameset.htm

Regards

Read only

Former Member
0 Likes
2,257

Hi

Effect

This statement reads a row from internal table itab. You have to specify the row by either naming values table_key for the table key, a free condition free_key or an index index. The latter choice is possible only for index tables. The output result result determines when and where the row contents are read.

If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.

Syntax

READ TABLE itab { table_key

| free_key

| index } result.

Example:

DATA: spfli_tab TYPE SORTED TABLE OF spfli

WITH UNIQUE KEY carrid connid,

spfli_key LIKE LINE OF spfli_tab.

FIELD-SYMBOLS <spfli> TYPE spfli.

...

SELECT *

FROM spfli

INTO TABLE spfli_tab

WHERE carrid = 'LH'.

...

spfli_key-carrid = 'LH'.

spfli_key-connid = '0400'.

READ TABLE spfli_tab FROM spfli_key ASSIGNING <spfli>.

IF sy-subrc = 0.

...

ENDIF.

...

READ TABLE spfli_tab

WITH TABLE KEY carrid = 'LH' connid = '2402'

ASSIGNING <spfli>.

IF sy-subrc = 0.

...

ENDIF.

Regards,

Venkat

Read only

Former Member
0 Likes
2,258

Hi,

READ statement is mainly used to read a single line of any table.

READ TABLE <itab> <key> <result>.

Useful Link to know about READ statement :

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

<REMOVED BY MODERATOR>

Regards

Rose

Edited by: Alvaro Tejada Galindo on Mar 10, 2008 7:27 PM

Read only

Former Member
0 Likes
2,257

Thanx srinivas,,,just wanted to confim that whenever we use read statement, then it should always needed for us to select all the data to internal table??

Can u please explain me with the help of a small query,,then it would be great...

Like please take a field & select some data& show me when u put the read statement which all data moves to the header of internal table & how u then retrieve the data one by one...

U use loop statements,or anything but please show me this...

thanx ..

thanx..

Read only

0 Likes
2,257

If we want to read an internal table .. it should have some data..

for ex :

data : begin of itab occurs 0,

field1(10),

field2(10),

end of itab.

itab-field1 = 'First'.

itab-field2 = 'Value'.

append itab.

clear itab.

itab-field1 = 'Second'.

itab-field2 = 'Value'.

append itab.

clear itab.

Now itab has two entries ..

read table itab index 1. <---

now itab-field1 has 'First'

and itab-field2 has 'Value' ...

U can also use Loop ... endloop ..<-- there is no need to read

loop at itab.

write 😕 itab-field1 , itab-field2.

endloop.

Read only

Former Member
0 Likes
2,257

Hey saswat ,

just wanted to give a simplified example of ur query , if not understood please ask

REPORT Z_PRGM_TRY_READ NO STANDARD PAGE HEADING.

TABLES : MARA , MARD.

SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.

TYPES : BEGIN OF LT_MARA ,

MATNR LIKE MARA-MATNR ,

ERSDA LIKE MARA-ERSDA ,

MBRSH LIKE MARA-MBRSH ,

END OF LT_MARA .

DATA : TT_MARA TYPE STANDARD TABLE OF LT_MARA INITIAL SIZE 0 ,

WA_MARA TYPE LT_MARA .

TYPES : BEGIN OF LT_MARD ,

MATNR LIKE MARD-MATNR ,

WERKS LIKE MARD-WERKS ,

LGORT LIKE MARD-LGORT ,

PSTAT LIKE MARD-PSTAT ,

END OF LT_MARD.

DATA : TT_MARD TYPE STANDARD TABLE OF LT_MARD INITIAL SIZE 0 ,

WA_MARD TYPE LT_MARD.

TYPES : BEGIN OF LT_FINAL ,

MATNR LIKE MARA-MATNR ,

ERSDA LIKE MARA-ERSDA ,

MBRSH LIKE MARA-MBRSH ,

WERKS LIKE MARD-WERKS ,

LGORT LIKE MARD-LGORT ,

PSTAT LIKE MARD-PSTAT ,

END OF LT_FINAL .

DATA : TT_FINAL TYPE STANDARD TABLE OF LT_FINAL INITIAL SIZE 0 ,

WA_FINAL TYPE LT_FINAL .

SELECT MARA~MATNR

ERSDA

MBRSH

INTO CORRESPONDING FIELDS OF TABLE TT_MARA FROM MARA WHERE MARA~MATNR IN S_MATNR .

SELECT MARD~MATNR

WERKS

LGORT

PSTAT

INTO CORRESPONDING FIELDS OF TABLE TT_MARD FROM MARD

FOR ALL ENTRIES IN TT_MARA

WHERE MATNR = TT_MARA-MATNR.

LOOP AT TT_MARA INTO WA_MARA.

READ TABLE TT_MARD INTO WA_MARD WITH KEY MATNR = WA_MARA-MATNR .

IF SY-SUBRC = 0.

WA_FINAL-MATNR = WA_MARA-MATNR .

WA_FINAL-ERSDA = WA_MARA-ERSDA.

WA_FINAL-MBRSH = WA_MARA-MBRSH.

WA_FINAL-WERKS = WA_MARD-WERKS.

WA_FINAL-LGORT = WA_MARD-LGORT.

WA_FINAL-PSTAT = WA_MARD-PSTAT.

APPEND WA_FINAL TO TT_FINAL.

CLEAR WA_FINAL.

ENDIF.

ENDLOOP.

LOOP AT TT_FINAL INTO WA_FINAL.

WRITE : / WA_FINAL-MATNR , WA_FINAL-ERSDA , WA_FINAL-MBRSH , WA_FINAL-WERKS ,

WA_FINAL-LGORT , WA_FINAL-PSTAT.

ENDLOOP.