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: 

read

Former Member
0 Kudos

can any one tell something about read,modify,describe keywords

4 REPLIES 4

Former Member
0 Kudos

Hi

In SE38 program just write those words and press F1 you will

get help related to them

Read table doesn't allow ne operator.

It reads only one record...Either by index or key.

READ TABLE MY_TAB INDEX 1.

READ TABLE MY_TAB WITH KEY CODE = 'ATG'.

these are the results for SY-SUBRC checks after read table

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. For further detauls, refer to the COMPARING section of the additions

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.

Otherwise, SY-TABIX is undefined.

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.

Reading records with keys

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

Reading lines with Index

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3730358411d1829f0000e829fbfe/content.htm

MODIFY

... FROM { {wa} | {TABLE itab} }.

1. ... FROM wa

2. ... FROM TABLE itab

A wa data object that is not table-type or an itab internal table can be specified after FROM. On the one hand the content of the data objects determines whether the line(s) are inserted or changed, and on the other hand, which values are inserted or used for changes.

To insert or change several lines in a database table, use the following:

MODIFY <target> FROM TABLE <itab> .

Those lines of the internal table <itab> for which there is not already a line in the database table with the same primary key are inserted into the table. Those lines of the internal table <itab> for which there is already a line in the database table with the same primary key overwrite the existing line in the database table. The same rules apply to the line type of <itab> as to the work area <wa> described above.

SY-SUBRC is always set to 0. SY-DBCNT is set to the number of lines in the internal table

DESCRIBE table ITAB lines <v_l>

Describe is used to know the number of records in a Internal table

Reward points for useful Answers

Regards

Anji

Message was edited by:

Anji Reddy Vangala

Former Member
0 Kudos

Hi,

Read: READ : statement will read only single record at at time and not more than that.

Read statement will return Sy-subrc value.

if we want to compare 2 internal tables (itab1 & itab2) then we will loop one internal table and read another internal table.

ex: loop at itab1 into w_itab1.

read table itab2 into e_iatb2 with key f1 = w_itab1-f1.

If sy-subrc = 0.

....

....logic...

endif.

endloop.

Modify :Modify on database/ internal table:

- will insert a new record , if record doesnt exist with that primary key.

-will update the existing record , if record already exist with that primary key.

Describe:

1. If you want to know the no of records in an internal table and to know internal tabe type ,

we use

DESCRIBE TABLE ITAB LINES V_LINES

TYPE V_TYPE.

DATA : V_LINES TYPE I.

now you can use V_LINES to print total no of records in that table.

V_TYPE to know the table is standard or sorted or hashed table.

2. FOR a FIELD

DESCRIBE FIELD V_FIELD LENGH V_LENGTH IN CHARACTER MODE.

to know the length of the variable (while defining) it will come to V_LENGTH.

Thanks,

Anitha

varma_narayana
Active Contributor
0 Kudos

Hi

All these commands are used for operations on internal tables

1. Read: for reading a single row from internal table to a workarea

2. Modify : to modify the data in an internal table

3. Desribe : to find the attributes of an internal table (such as no of lines, length etc)

For syntax plz refer to F1 help.

regards.

Former Member
0 Kudos

Hi

Hope the below will be usefull....

Reading Table

Reading Single Lines:

READ TABLE <itab> [INTO <wa>] INDEX <idx>.

Reads the single line with index <idx> into <wa> (or into header line, if omitted). This is the fastest method.

• <idx> <= 0 : runtime error;

• <idx> > table size : SY-SUBRC = 4;

• <idx> found : SY-SUBRC = 0, SY-TABIX = <idx>.

READ TABLE <itab> [INTO <wa>] [BINARY SEARCH].

Reads the first line with a particular standard key, which should be placed in the table work area (works only for internal tables with header line).

• entry found : SY-SUBRC = 0, SY-TABIX = <idx>;

• entry not found : SY-SUBRC <> 0;.

READ TABLE <itab> [INTO <wa>] WITH KEY <key>[BINARY SEARCH].

Reads the first line with <key>.

• entry found : SY-SUBRC = 0, SY-TABIX = <idx>;

• entry not found : SY-SUBRC <> 0;.

Key definition for internal tables:

....WITH KEY <k1> = <f1> ... <kn> = <fn> ...

The self-defined key consists of the table components <k1>...<kn>. If the data type of <fi> is not compatible to the data type of <ki>, then <fi> is converted to the type of <ki>. You can specify an offset and length for any component you use in the key. You can set key fields at runtime by replacing <ki> with (<ni>). The key field is the contents of the field <ni>. If <ni> is blank at runtime, the system ignores this key field. If <ni> contains an invalid component name, a runtime error occurs.

....WITH KEY = <value> ...

Defines entire line as key (will be converted if necessary).

....WITH KEY <value> ...

The system compares the (left-justified) beginning of a line with <value>. <value> cannot contain an internal table or a structure containing an internal table. In contrast to the above two options, the comparison is processed using the data type of <value>.

Additions:

• BINARY SEARCH - performs a binary search instead of the standard sequential search (much faster). Table must be sorted.

o SY-SUBRC = 0 : entry found, SY-TABIX = index of the found entry;

o SY-SUBRC = 4 : entry not found, SY-TABIX = index of the next largest entry, output area remains unchanged;

o SY-SUBRC = 8 : entry not found, the key is greater than last table entry, SY-TABIX = (number of all entries + 1), output area remains unchanged.

• TRANSPORTING {<f1> ... <fn>|NO FIELDS} - only transports selected fields to the target area.

• COMPARING {<f1> ... <fn>|ALL FIELDS} - reads single line with key or index into the target area. After reading the line, the components specified in fields list are compared to the corresponding components of the target area:

o SY-SUBRC = 0 : line is read and the contents of the compared fields are the same;

o SY-SUBRC = 2 : line is read, but the contents of the compared fields are not the same;

o SY-SUBRC = 4 : no line was read.

Modifying Table

MODIFY <itab> [FROM <wa>] [INDEX <idx>] [TRANSPORTING <f1> ... <fn> [WHERE <condition>]].

Modifies the line in the table. For tables with a header line the source area can be omitted. With INDEX option, will be modified the line which has the index <idx>. In this case: SY-SUBRC = 4 if no line with <idx> exists; SY-SUBRC = 0 - success.

Use MODIFY without the INDEX option is allowed only within a LOOP - ENDLOOP loop by modifying the current line (i.e. the line which has the index returned by SY-TABIX).

With the TRANSPORTING option, the system transports only the components <f1> ... <fn> from the work area into the internal table. Strongly recommended suppress unnecessary transports of fields which are internal tables itself. You can specify a component dynamically by writing (<name>). In this case, the system reads the name of the component from field <name> at runtime. An invalid component name leads to a runtime error.

WHERE <condition> with the TRANSPORTING option determines all the lines of the table into which the components <f1> ... <fn> are to be transported. First operand should be a component of the internal table's line structure. WHERE cannot be used together with the INDEX option.

WRITE <f>[<o1>][(<l1>)] TO <itab>[<o2>][(<l2>)] INDEX <idx>.

Variant of WRITE TO. Overwrites the section of the line of the <itab> that has index <idx>. Does not affect header line. Does not recognize the structure of table lines. Return codes: SY-SUBRC = 4 - no line with <idx> exists; SY-SUBRC = 0 - success. If <idx> <= 0 - runtime error.

Deleting lines:

DELETE <itab>.

Deletes current line in LOOP - ENDLOOP (that is line which have index SY-TABIX). After the first line has been deleted, the current line and its assignment to the contents of SY-TABIX can be undefined. To process further lines within this loop, use only statements with the INDEX option.

DELETE <itab> INDEX <idx>.

Deletes line with the index <idx>. Return codes: SY-SUBRC = 4 - no line with <idx> exists; SY-SUBRC = 0 - success.

DELETE ADJACENT DUPLICATES FROM <itab> [COMPARING {<f1> ... <f1>|ALL FIELDS}].

Deletes adjacent duplicates entries. Return codes: SY-SUBRC = 0 - at least one entry was deleted; SY-SUBRC = 4 - otherwise. Without the COMPARING option, the contents of the standard key fields must be the same.

DELETE <itab> [FROM <n1>] [TO <n2>] [WHERE <condition>].

Deletes selected entries. At least one of three criteria should be used. First operand in WHERE should be a component of the internal table's line structure. Return codes: SY-SUBRC = 0 - at least one entry was deleted; SY-SUBRC = 4 - otherwise.

Regards,

Ramya.R