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

Modify Read Describe

Former Member
0 Likes
857

Hi all,

Could anyone please give me syntax for

MODIFY

READ

DESCRIBE on hashed table and standard table.

Thank you

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
723

Pavan,

See the SAP Help...

MODIFY - Change a database table

Variants:

1. MODIFY dbtab. or

MODIFY *dbtab. or

MODIFY (dbtabname) ... ..

2. MODIFY dbtab FROM TABLE itab. or

MODIFY (dbtabname) FROM TABLE itab.

3. MODIFY dbtab VERSION vers. or

MODIFY *dbtab VERSION vers.

Effect

Inserts new lines or updates existing lines in a database table (s. relational database). If a line with the specified primary key already exists, an UPDATE is executed. Otherwise, an INSERT is performed. You can specify the name of the database table either in the program itself in the form MODIFY dbtab ... or at runtime as the contents of the field dbtabname in the form MODIFY (dbtabname) ... . In both cases, the database table must be defined in the ABAP Dictionary. Normally, records are inserted or updated only in the current client. Data can only be inserted or updated using a view, if the view refers to a single table and was created in the ABAP Dictionary with the maintenance status "No restriction".

MODIFY belongs to the Open SQL command set.

When the statement has been executed, the system field SY-DBCNT contains the number of edited lines.

The return code is set as follows:

SY-SUBRC = 0:

All lines were successfully inserted or updated.

SY-SUBRC = 4:

One or more lines could not be inserted or updated.

Notes

You cannot modify a line if there is already a line in the table with identical key field values in a UNIQUE index.

Automatic definition of INSERT and UPDATE is expensive. You should therefore use MODIFY only if you cannot define the INSERT and UPDATE cases yourself in the program.

Since the MODIFY statement does not perform authority checks, you have to program them yourself.

Adding or changing lines with the MODIFY command is only completed after a database commit (see LUW) has been performed. Before the database commit has been performed, any database changes can be reversed with a database rollback (see Programming transactions).

Synchronization of simultanous accesses by several users to the same set of data cannot be guaranteed exclusively with the lock mechanism of the database system. In several cases, you are recommended to use the SAP lock mechanism.

Variant 1

MODIFY dbtab. or

MODIFY *dbtab. or

MODIFY (dbtabname) ... .

Additions:

1. ... FROM wa

2. ... CLIENT SPECIFIED

See Short forms not allowed and * work areas not allowed.

Effect

Inserts a new line or updates an existing line in a database table. If you specify the name of the database table yourself, the primary key for identifying the line to be inserted or updated and the relevant values are taken from the table work area dbtab or *dbtab (see TABLES). If you specify the name of the database table directly, the program must contain a corresponding TABLES statement. If the name of the database table is not determined until runtime, you need to use the addition ... FROM wa.

Example

Insert or change data of the customer Robinson in the current client:

TABLES SCUSTOM.

SCUSTOM-ID = '12400177'.

SCUSTOM-NAME = 'Robinson'.

SCUSTOM-POSTCODE = '69542'.

SCUSTOM-CITY = 'Heidelberg'.

SCUSTOM-CUSTTYPE = 'P'.

SCUSTOM-DISCOUNT = '003'.

SCUSTOM-TELEPHONE = '06201/44889'.

MODIFY SCUSTOM.

Addition 1

... FROM wa

Effect

The values for the line to be inserted or updated are not taken from the table work area dbtab, but from the explicitly specified work area wa. When doing this, the data is read from left to right according to the structure of the table work area dbtab (see TABLES). Since the structure of wa is not taken into account, the work area wa must be at least as wide (see DATA) as the table work area dbtab and the alignment of the work area wa must correspond to the alignment of the table work area. Otherwise, a runtime error occurs.

Note

If a work area is not explicitly specified, the values for the line to be inserted or updated are also taken from the table work area dbtab if the statement is in a FORM or FUNCTION where the table work area is stored in a formal parameter or local variable of the same name.

Addition 2

... CLIENT SPECIFIED

Effect

Switches off automatic client handling. This allows you to edit data across all clients even when dealing with client-specific tables. The client field is treated like a normal table field that can be programmed to accept values in the table work area dbtab or *dbtab where the line to be edited occurs.

The addition CLIENT SPECIFIED must be specified immediately after the name of the database table.

Variant 2

MODIFY dbtab FROM TABLE itab.or MODIFY (dbtabname) FROM TABLE itab.

Addition:

... CLIENT SPECIFIED

Effect

Mass modify: Inserts new lines or updates existing lines of a database table. The primary keys for identifying the lines to be inserted or updated and the relevant values are taken from the internal table itab. The lines of the internal table itab must satisfy the same conditions as the work area wa in addition 1 to variant 1.

Note

If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.

Addition

... CLIENT SPECIFIED

Effect

As for variant 1.

Variant 3

MODIFY dbtab VERSION vers. or MODIFY *dbtab VERSION vers.

This variant is not allowed in an ABAP Objects context. See VERSION addition not allowed.

Note

This variant is obsolete.

Effect

Inserts a new line or updates an existing line in a database table, the name of which is taken from the field vers at runtime. If no line exists with the specified primary key, an INSERT is executed. Otherwise, an UPDATE is performed. The database table must be defined in the ABAP/4 Dictionary and its name must conform to the naming conventions for R/2 ATAB tables. These stipulate that the name must begin with 'T' and may contain up to four further characters. The field vers must contain the table name without the leading 'T'. Only lines in the current client are inserted or updated. The line to be inserted is taken from the statically specified table work area dbtab or *dbtab.

SY-SUBRC is set to 0 if the line is successfully inserted or updated. SY-SUBRC <> 0 is not possible since any other result causes a runtime error.

READ::::

Read statement will be only for Internal tables.

READ - Reading an Internal Table

Variants:

1. READ TABLE itab FROM wa [additions].

2. READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn

[ additions].

3. READ TABLE itab WITH KEY k1 = v1 ... kn = vn

[BINARY SEARCH] [ additions].

4. READ TABLE itab INDEX i [additions].

Obsolete Variants

In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See Short forms of line operations not allowed.

Effect

Reads an entry from an DS:ABEN.ITAB>internal table, using either its key or its index. The return code SY-SUBRC specifies whether an entry could be read. If you specify a non-unique key (the table must have a NON-UNIQUE key for this to be valid) , the system returns the entry with the lowest index from the set of entries that meet the condition.

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 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.

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

Variant 1

READ TABLE itab FROM wa [ additions].

Variant 2

READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn [additions].

Effect

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. The way in which the system looks for table entries depends on the table type:

STANDARD TABLE:

The system searches from the start of the table. The response time is in linear relation to the number of table entries.

SORTED TABLE:

The response time is in logarithmic relation to the number of table entries.

HASHED TABLE:

The response time is constant.

Notes

When you specify the table key using k1 = v1 ... kn = vn you must specify values for all of the key fields. If the type of a value is not compatible with the type of the corresponding key field,the system uses MOVE logic to convert it to the type of the key field before reading from the table.

If you do not know the name of a component until runtime, you can use the expression WITH TABLE KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni. If ni is empty at runtime, the key specification is ignored.

If the line type of the internal table contains object reference variables as components, or the entire line type is a reference variable, you can use the attirbutes of the objects to which the reference is pointing in a particular line as key values (see Attributes of Objects as the Key of an Internal Table).

If a table has a non-structured line type, you can use the pseudocomponent TABLE_LINE to address the entire line as the table key (see also Pseudocomponent TABLE_LINE in Internal Tables).

If you specify the key implicitly using FROM wa, the values for the table key are taken from the corresponding components of the (structured) field wa. wa must be compatible with the line type of itab. In this way, you can access a table using READ without having to know the table key statically. If the table key is empty, the system reads the first line.

Variant 3

READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH] [additions].

Effect

The system uses the specified key to identify the correct line. If the type of a value is not compatible with the type of the corresponding key field, the system uses MOVE logic to convert the value into the type of the component before reading the table. This is an asymmetric comparison logic, in which the component type takes precedence over the value type.

The way in which the system looks for an entry in the table depends on its table type:

STANDARD TABLE:

If you use the ... BINARY SEARCH addition, the system uses a binary search. Otherwise, the search is sequential. This assumes that the internal table is sorted in ascending order in the sequence of the specified key fields.

SORTED TABLE:

If the specified key fields form a left-justified extract of the table key, the search is binary, otherwise sequential.

HASHED TABLE:

Sequential search.

Notes

The system reads the first entry in which the specified components k1 ... kn correspond with the values of v1 ... vn. If the type of a value and the type of the corresponding key are incompatible, the system uses MOVE logic to convert the value into the type of the component before reading the table.

If your table has a non-structured line type, you can use the pseudocomponent TABLE_LINE to address the entire line as the key (see also Pseudocomponent TABLE_LINE with Internal Tables).

If you do not know the name of a component until runtime, you can use the expression WITH KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni. If ni is empty at runtime, the system ignores the component. If ni contains an invalid component name, a runtime error occurs. If ni contains an empty name, the system ignores the key specification.

If the line type of the internal table contains object reference variables as componetns or the entire line type is a reference variable, you can use the attributes of the object to which the reference is pointing in a particular line as key values (see Attributes of Objects as the Key of an Internal Tables).

If you specify a completely empty key, the system reads the first entry from the table.

You restrict your specification using offset and length. This is valid for both the static and dynamic variant.

Variant 4

READ TABLE itab INDEX i [additions].

Effect

Accessing the table entry with the index i.

Notes

Performance:

The quickest way to access a single line of an internal table is direct access using an index, because the response time is then not linked to the size of the table, and is restricted more or less to the transport costs for a single line.

For hashed tables, the response time is constant. Accessing a table using the hash administration makes the response time around 3 times slower than using index access.

If you use the key to access a table, the response time increase as the number of table entries and the size of the search key increase. Searching using a binary search is considerably quicker than using a linear search. Therefore, in many cases it can be quicker to sort the table and then use the BINARY SEARCH addition.

The runtime required to read a line from a table with 100 entries using the index is around ca. 7 msn (standard microseconds), to read a line using a key of 30 bytes using a binary search, around 25 msn, and without binary search, around 100 msn.

Using statements that use an explicit work area for internal tables with a header line can avoid unnecessary value assignments. Zuweisungen vermieden werden.

Note

Runtime errors:

ITAB_EMPTY_KEY: Key missing when reading a table using READ ... WITH TABLE KEY.

ITAB_ILLEGAL_BINARY_SEARCH: When you read a SORTERD TABLE using the BINARY SEARCH addition, the specified key fields must make up a left-justified extract of the key.

ITAB_KEY_COMPONENT_MISSING: Key specification missing.

ITAB_KEY_ILLEGAL_COMPONENT: Invalid key specification when accessing a key table.

Additional help

Reading Table Lines

Reading Table Lines Using the Index

Describe::DESCRIBE - Finding Out the Attributes of an Internal Table

Basic form

DESCRIBE TABLE itab.

Effect

Gets the attributes of the internal table itab.

You must use at least one of the additions listed below.

Note

You cannot use the DESCRIBE statement for all ABAP types. In conjunction with ABAP Objects, SAP has introduced an RTTI system, based on global classes, that you can use to return type attributes at runtime. This system applies to all ABAP types, and so includes all of the functions available in the DESCRIBE TABLE statement.

Additions:

1. ... LINES n

2. ... OCCURS n

3. ... KIND k

Addition 1

... LINES n

Effect

Places the numebr of filled lines of the table itab into the field n. The value returned to n has type I.

Example

DATA: N TYPE I,

ITAB TYPE TABLE OF I.

...

CLEAR ITAB.

APPEND 36 TO ITAB.

DESCRIBE TABLE ITAB LINES N.

Result: N contains the value 1.

Addition 2

... OCCURS n

Effect

Places the value of the OCCURS or INITIAL SIZE parameter from the definition of itab (DATA) into the variable n. The value returned to n has the type I.

Example

DATA: N1 TYPE I,

N2 TYPE I,

ITAB1 TYPE TABLE OF I INITIAL SIZE 10,

ITAB2 TYPE I OCCURS 5.

DESCRIBE TABLE ITAB1 OCCURS N1.

DESCRIBE TABLE ITAB2 OCCURS N2.

Result: n1 has the value 10, N2 has the value 5.

Addition 3

... KIND k

Effect

Places the table type of itab into the field k. The value returned to k has the type C. The return value is one of the constants SYDES_KIND-STANDARD, SYDES_KIND-SORTED, or SYDES_KIND-HASHED from the type group SYDES.

Example

Generic FORM routine for any table type:

TYPE-POOLS: SYDES.

...

FORM GENERIC_FORM USING ITAB TYPE ANY TABLE.

DATA: K TYPE C.

DESCRIBE TABLE ITAB KIND K.

CASE K.

WHEN SYDES_KIND-STANDARD.

...

WHEN SYDES_KIND-SORTED.

...

WHEN SYDES_KIND-HASHED.

...

ENDCASE.

ENDFORM.

Notes

Performance: The runtime for the DESCRIBE TABLE statement is around 4 msn (standard microseconds).

The DESCRIBE TABLE statement also fills the system fields SY-TFILL, SY-TLENG, and SY-TOCCU.

Additional help

Retrieving Attributes ofInternal Tables

2 REPLIES 2
Read only

former_member156446
Active Contributor
0 Likes
723

Hi Pavan

MODIFY

Change a database table

- MODIFY dbtab.

MODIFY *dbtab.

MODIFY (dbtabname) ... .

- MODIFY dbtab FROM TABLE itab.

MODIFY (dbtabname) FROM TABLE itab.

- MODIFY dbtab VERSION vers.

MODIFY *dbtab VERSION vers.

Change an internal table

- MODIFY itab [FROM wa] [INDEX idx].

Change a list line

- MODIFY LINE n.

- MODIFY LINE n OF CURRENT PAGE.

- MODIFY LINE n OF PAGE m.

- MODIFY CURRENT LINE.

Change the attributes of a screen field

- MODIFY SCREEN.

-


READ

Read an internal table

- READ TABLE itab. / READ TABLE itab INTO wa.

Read a list line

- READ LINE lin.

- READ LINE lin OF CURRENT PAGE.

- READ LINE lin OF PAGE pag.

- READ CURRENT LINE.

Read a program

- READ REPORT prog INTO itab.

Read text elements

- READ TEXTPOOL prog ...INTO itab ...LANGUAGE lg.

Read a file

- READ DATASET dsn INTO f.

Read a database table

- READ TABLE dbtab.

Determine calendar information

- In R/2: READ CALENDAR.

-


Return attributes of a field

- DESCRIBE FIELD f.

Return attributes of an internal table

- DESCRIBE TABLE itab.

Determine distance between two fields

- DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3.

Return attributes of a list

- DESCRIBE LIST NUMBER OF LINES lin.

- DESCRIBE LIST NUMBER OF PAGES n.

- DESCRIBE LIST LINE lin PAGE pag.

- DESCRIBE LIST PAGE pag.

DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3

Effect

Returns the distance between the fields f1 and f2 in f3.

Example

TABLES LFA1.

DATA DIS TYPE P.

DESCRIBE DISTANCE BETWEEN LFA1-LAND1

AND LFA1-NAME1

INTO DIS.

Result: DIS contains the value 14, since exactly two fields lie between LAND1 and NAME1, namely LNRZA (10 bytes) and LOEVM (1 byte); additionally, the sub-field LAND1 is 3 bytes long. Therefore, the start of the sub-field LAND1 is exactly 14 bytes from the start of the sub-field NAME1.

DESCRIBE - Supply attributes of a field

Basic form

DESCRIBE FIELD f.

Effect

Supplies the attributes of the field f . You must specify at least one of the additions:

Additions

1. ... LENGTH len

2. ... TYPE typ

3. ... TYPE typ COMPONENTS n

4. ... OUTPUT-LENGTH len

5. ... DECIMALS n

6. ... EDIT MASK mask

Addition 1

... LENGTH len

Effect

Returns the length of the field f in the field

len .

Example

DATA: FLD(8),

LEN TYPE P.

DESCRIBE FIELD FLD LENGTH LEN.

Result: LEN contains the value 8.

Addition 2

... TYPE typ

Effect

Returns the data type of f in the field typ

Example

DATA: FLD(8) TYPE N,

F_TYPE.

DESCRIBE FIELD FLD TYPE F_TYPE.

Result: F_TYPE contains the value 'N' .

Note

Along with the elementary data types you can specify under

DATA (C, N, etc.), several other data types are created either

with reference to Dictionary fields or during generation. These data

types, which are also returned by DESCRIBE , have the following

type IDs:

h Internal table s 2-byte integer with leading sign b 1-byte integer without leading sign u Structure without internal table v Structure containing at least one internal table

For compatibility reasons, ... TYPE typ returns C rather than u or v with structures.

Addition 3

... TYPE typ COMPONENTS n

Effect

Similar to ... TYPE typ except that, with structures in typ , u or v are returned and in the number of structure components is set in n . If f is not a structure, n is set to 0.

Example

Recursive processing of the pages of an ABAP/4 data structure:

FORM TEST USING F.

DATA: TYP(1) TYPE C, N TYPE I.

FIELD-SYMBOLS: <F>.

DO.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE F TO <F>.

IF SY-SUBRC <> 0. EXIT. ENDIF.

DESCRIBE FIELD <F> TYPE TYP COMPONENTS N.

IF N > 0. " Equivalent is TYP = 'u' OR TYP = 'v'

PERFORM TEST USING <F>.

ELSE.

PERFORM DO_SOMETHING USING <F>.

ENDIF.

ENDDO.

ENDFORM.

Addition 4

... OUTPUT-LENGTH len

Effect

Enters the output length of the field f in the variable len .

Example

DATA: FLD(4) TYPE P,

O_LEN TYPE P.

DESCRIBE FIELD FLD OUTPUT-LENGTH O_LEN.

Result: O_LEN contains the value 8.

Addition 5

... DECIMALS n

Effect

Enters the number of decimal places for the field f (defined in addition ... DECIMALS of the DATA statement or in the ABAP/4 Dictionary ) in the variable n .

Example

DATA: FLD(8) TYPE P DECIMALS 2,

DEC TYPE P.

DESCRIBE FIELD FLD DECIMALS DEC.

Resultat: DEC contains the value 2.

Addition 6

... EDIT MASK mask

Effect

If the field f has a conversion routine in the ABAP/4 Dictionary , this is placed in the field mask in the form " ==conv ". " conv " stands for the name of the conversion routine, e.g. " ==ALPHA " in the conversion routine " ALPHA ". In this form, mask can then be used in the addition USING EDIT MASK mask of the WRITE statement.

Example

Check whether there is a conversion routine for the field "customer number" in the table SBOOK :

TABLES SBOOK.

DATA: CONV_EXIT(10).

DESCRIBE FIELD SBOOK-CUSTOMID EDIT MASK CONV_EXIT.

IF CONV_EXIT <> SPACE. ... ENDIF.

Result: CONV_EXIT contains the value " ==ALPHA ".

Award points if helpful

Read only

Former Member
0 Likes
724

Pavan,

See the SAP Help...

MODIFY - Change a database table

Variants:

1. MODIFY dbtab. or

MODIFY *dbtab. or

MODIFY (dbtabname) ... ..

2. MODIFY dbtab FROM TABLE itab. or

MODIFY (dbtabname) FROM TABLE itab.

3. MODIFY dbtab VERSION vers. or

MODIFY *dbtab VERSION vers.

Effect

Inserts new lines or updates existing lines in a database table (s. relational database). If a line with the specified primary key already exists, an UPDATE is executed. Otherwise, an INSERT is performed. You can specify the name of the database table either in the program itself in the form MODIFY dbtab ... or at runtime as the contents of the field dbtabname in the form MODIFY (dbtabname) ... . In both cases, the database table must be defined in the ABAP Dictionary. Normally, records are inserted or updated only in the current client. Data can only be inserted or updated using a view, if the view refers to a single table and was created in the ABAP Dictionary with the maintenance status "No restriction".

MODIFY belongs to the Open SQL command set.

When the statement has been executed, the system field SY-DBCNT contains the number of edited lines.

The return code is set as follows:

SY-SUBRC = 0:

All lines were successfully inserted or updated.

SY-SUBRC = 4:

One or more lines could not be inserted or updated.

Notes

You cannot modify a line if there is already a line in the table with identical key field values in a UNIQUE index.

Automatic definition of INSERT and UPDATE is expensive. You should therefore use MODIFY only if you cannot define the INSERT and UPDATE cases yourself in the program.

Since the MODIFY statement does not perform authority checks, you have to program them yourself.

Adding or changing lines with the MODIFY command is only completed after a database commit (see LUW) has been performed. Before the database commit has been performed, any database changes can be reversed with a database rollback (see Programming transactions).

Synchronization of simultanous accesses by several users to the same set of data cannot be guaranteed exclusively with the lock mechanism of the database system. In several cases, you are recommended to use the SAP lock mechanism.

Variant 1

MODIFY dbtab. or

MODIFY *dbtab. or

MODIFY (dbtabname) ... .

Additions:

1. ... FROM wa

2. ... CLIENT SPECIFIED

See Short forms not allowed and * work areas not allowed.

Effect

Inserts a new line or updates an existing line in a database table. If you specify the name of the database table yourself, the primary key for identifying the line to be inserted or updated and the relevant values are taken from the table work area dbtab or *dbtab (see TABLES). If you specify the name of the database table directly, the program must contain a corresponding TABLES statement. If the name of the database table is not determined until runtime, you need to use the addition ... FROM wa.

Example

Insert or change data of the customer Robinson in the current client:

TABLES SCUSTOM.

SCUSTOM-ID = '12400177'.

SCUSTOM-NAME = 'Robinson'.

SCUSTOM-POSTCODE = '69542'.

SCUSTOM-CITY = 'Heidelberg'.

SCUSTOM-CUSTTYPE = 'P'.

SCUSTOM-DISCOUNT = '003'.

SCUSTOM-TELEPHONE = '06201/44889'.

MODIFY SCUSTOM.

Addition 1

... FROM wa

Effect

The values for the line to be inserted or updated are not taken from the table work area dbtab, but from the explicitly specified work area wa. When doing this, the data is read from left to right according to the structure of the table work area dbtab (see TABLES). Since the structure of wa is not taken into account, the work area wa must be at least as wide (see DATA) as the table work area dbtab and the alignment of the work area wa must correspond to the alignment of the table work area. Otherwise, a runtime error occurs.

Note

If a work area is not explicitly specified, the values for the line to be inserted or updated are also taken from the table work area dbtab if the statement is in a FORM or FUNCTION where the table work area is stored in a formal parameter or local variable of the same name.

Addition 2

... CLIENT SPECIFIED

Effect

Switches off automatic client handling. This allows you to edit data across all clients even when dealing with client-specific tables. The client field is treated like a normal table field that can be programmed to accept values in the table work area dbtab or *dbtab where the line to be edited occurs.

The addition CLIENT SPECIFIED must be specified immediately after the name of the database table.

Variant 2

MODIFY dbtab FROM TABLE itab.or MODIFY (dbtabname) FROM TABLE itab.

Addition:

... CLIENT SPECIFIED

Effect

Mass modify: Inserts new lines or updates existing lines of a database table. The primary keys for identifying the lines to be inserted or updated and the relevant values are taken from the internal table itab. The lines of the internal table itab must satisfy the same conditions as the work area wa in addition 1 to variant 1.

Note

If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.

Addition

... CLIENT SPECIFIED

Effect

As for variant 1.

Variant 3

MODIFY dbtab VERSION vers. or MODIFY *dbtab VERSION vers.

This variant is not allowed in an ABAP Objects context. See VERSION addition not allowed.

Note

This variant is obsolete.

Effect

Inserts a new line or updates an existing line in a database table, the name of which is taken from the field vers at runtime. If no line exists with the specified primary key, an INSERT is executed. Otherwise, an UPDATE is performed. The database table must be defined in the ABAP/4 Dictionary and its name must conform to the naming conventions for R/2 ATAB tables. These stipulate that the name must begin with 'T' and may contain up to four further characters. The field vers must contain the table name without the leading 'T'. Only lines in the current client are inserted or updated. The line to be inserted is taken from the statically specified table work area dbtab or *dbtab.

SY-SUBRC is set to 0 if the line is successfully inserted or updated. SY-SUBRC <> 0 is not possible since any other result causes a runtime error.

READ::::

Read statement will be only for Internal tables.

READ - Reading an Internal Table

Variants:

1. READ TABLE itab FROM wa [additions].

2. READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn

[ additions].

3. READ TABLE itab WITH KEY k1 = v1 ... kn = vn

[BINARY SEARCH] [ additions].

4. READ TABLE itab INDEX i [additions].

Obsolete Variants

In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See Short forms of line operations not allowed.

Effect

Reads an entry from an DS:ABEN.ITAB>internal table, using either its key or its index. The return code SY-SUBRC specifies whether an entry could be read. If you specify a non-unique key (the table must have a NON-UNIQUE key for this to be valid) , the system returns the entry with the lowest index from the set of entries that meet the condition.

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 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.

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

Variant 1

READ TABLE itab FROM wa [ additions].

Variant 2

READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn [additions].

Effect

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. The way in which the system looks for table entries depends on the table type:

STANDARD TABLE:

The system searches from the start of the table. The response time is in linear relation to the number of table entries.

SORTED TABLE:

The response time is in logarithmic relation to the number of table entries.

HASHED TABLE:

The response time is constant.

Notes

When you specify the table key using k1 = v1 ... kn = vn you must specify values for all of the key fields. If the type of a value is not compatible with the type of the corresponding key field,the system uses MOVE logic to convert it to the type of the key field before reading from the table.

If you do not know the name of a component until runtime, you can use the expression WITH TABLE KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni. If ni is empty at runtime, the key specification is ignored.

If the line type of the internal table contains object reference variables as components, or the entire line type is a reference variable, you can use the attirbutes of the objects to which the reference is pointing in a particular line as key values (see Attributes of Objects as the Key of an Internal Table).

If a table has a non-structured line type, you can use the pseudocomponent TABLE_LINE to address the entire line as the table key (see also Pseudocomponent TABLE_LINE in Internal Tables).

If you specify the key implicitly using FROM wa, the values for the table key are taken from the corresponding components of the (structured) field wa. wa must be compatible with the line type of itab. In this way, you can access a table using READ without having to know the table key statically. If the table key is empty, the system reads the first line.

Variant 3

READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH] [additions].

Effect

The system uses the specified key to identify the correct line. If the type of a value is not compatible with the type of the corresponding key field, the system uses MOVE logic to convert the value into the type of the component before reading the table. This is an asymmetric comparison logic, in which the component type takes precedence over the value type.

The way in which the system looks for an entry in the table depends on its table type:

STANDARD TABLE:

If you use the ... BINARY SEARCH addition, the system uses a binary search. Otherwise, the search is sequential. This assumes that the internal table is sorted in ascending order in the sequence of the specified key fields.

SORTED TABLE:

If the specified key fields form a left-justified extract of the table key, the search is binary, otherwise sequential.

HASHED TABLE:

Sequential search.

Notes

The system reads the first entry in which the specified components k1 ... kn correspond with the values of v1 ... vn. If the type of a value and the type of the corresponding key are incompatible, the system uses MOVE logic to convert the value into the type of the component before reading the table.

If your table has a non-structured line type, you can use the pseudocomponent TABLE_LINE to address the entire line as the key (see also Pseudocomponent TABLE_LINE with Internal Tables).

If you do not know the name of a component until runtime, you can use the expression WITH KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni. If ni is empty at runtime, the system ignores the component. If ni contains an invalid component name, a runtime error occurs. If ni contains an empty name, the system ignores the key specification.

If the line type of the internal table contains object reference variables as componetns or the entire line type is a reference variable, you can use the attributes of the object to which the reference is pointing in a particular line as key values (see Attributes of Objects as the Key of an Internal Tables).

If you specify a completely empty key, the system reads the first entry from the table.

You restrict your specification using offset and length. This is valid for both the static and dynamic variant.

Variant 4

READ TABLE itab INDEX i [additions].

Effect

Accessing the table entry with the index i.

Notes

Performance:

The quickest way to access a single line of an internal table is direct access using an index, because the response time is then not linked to the size of the table, and is restricted more or less to the transport costs for a single line.

For hashed tables, the response time is constant. Accessing a table using the hash administration makes the response time around 3 times slower than using index access.

If you use the key to access a table, the response time increase as the number of table entries and the size of the search key increase. Searching using a binary search is considerably quicker than using a linear search. Therefore, in many cases it can be quicker to sort the table and then use the BINARY SEARCH addition.

The runtime required to read a line from a table with 100 entries using the index is around ca. 7 msn (standard microseconds), to read a line using a key of 30 bytes using a binary search, around 25 msn, and without binary search, around 100 msn.

Using statements that use an explicit work area for internal tables with a header line can avoid unnecessary value assignments. Zuweisungen vermieden werden.

Note

Runtime errors:

ITAB_EMPTY_KEY: Key missing when reading a table using READ ... WITH TABLE KEY.

ITAB_ILLEGAL_BINARY_SEARCH: When you read a SORTERD TABLE using the BINARY SEARCH addition, the specified key fields must make up a left-justified extract of the key.

ITAB_KEY_COMPONENT_MISSING: Key specification missing.

ITAB_KEY_ILLEGAL_COMPONENT: Invalid key specification when accessing a key table.

Additional help

Reading Table Lines

Reading Table Lines Using the Index

Describe::DESCRIBE - Finding Out the Attributes of an Internal Table

Basic form

DESCRIBE TABLE itab.

Effect

Gets the attributes of the internal table itab.

You must use at least one of the additions listed below.

Note

You cannot use the DESCRIBE statement for all ABAP types. In conjunction with ABAP Objects, SAP has introduced an RTTI system, based on global classes, that you can use to return type attributes at runtime. This system applies to all ABAP types, and so includes all of the functions available in the DESCRIBE TABLE statement.

Additions:

1. ... LINES n

2. ... OCCURS n

3. ... KIND k

Addition 1

... LINES n

Effect

Places the numebr of filled lines of the table itab into the field n. The value returned to n has type I.

Example

DATA: N TYPE I,

ITAB TYPE TABLE OF I.

...

CLEAR ITAB.

APPEND 36 TO ITAB.

DESCRIBE TABLE ITAB LINES N.

Result: N contains the value 1.

Addition 2

... OCCURS n

Effect

Places the value of the OCCURS or INITIAL SIZE parameter from the definition of itab (DATA) into the variable n. The value returned to n has the type I.

Example

DATA: N1 TYPE I,

N2 TYPE I,

ITAB1 TYPE TABLE OF I INITIAL SIZE 10,

ITAB2 TYPE I OCCURS 5.

DESCRIBE TABLE ITAB1 OCCURS N1.

DESCRIBE TABLE ITAB2 OCCURS N2.

Result: n1 has the value 10, N2 has the value 5.

Addition 3

... KIND k

Effect

Places the table type of itab into the field k. The value returned to k has the type C. The return value is one of the constants SYDES_KIND-STANDARD, SYDES_KIND-SORTED, or SYDES_KIND-HASHED from the type group SYDES.

Example

Generic FORM routine for any table type:

TYPE-POOLS: SYDES.

...

FORM GENERIC_FORM USING ITAB TYPE ANY TABLE.

DATA: K TYPE C.

DESCRIBE TABLE ITAB KIND K.

CASE K.

WHEN SYDES_KIND-STANDARD.

...

WHEN SYDES_KIND-SORTED.

...

WHEN SYDES_KIND-HASHED.

...

ENDCASE.

ENDFORM.

Notes

Performance: The runtime for the DESCRIBE TABLE statement is around 4 msn (standard microseconds).

The DESCRIBE TABLE statement also fills the system fields SY-TFILL, SY-TLENG, and SY-TOCCU.

Additional help

Retrieving Attributes ofInternal Tables