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

query

Former Member
0 Likes
673

What do 'MODIFY' 'READ TABLE' AND 'UPDATE' Statement does.

Please give example of each.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
647

Hi,

<b>MODIFY statement can be used for modifying database table or internal table..</b>

Ex..

  • database table

MODIFY ZTABLE.

  • Internal table.

MODIFY ITAB FROM WA INDEX 1.

<b>READ TABLE is used for reading a single record from the internal table.</b>

Ex..

READ TABLE ITAB INTO WA INDEX 1.

UPDATE statement is used for updating database table.

Ex..

<b>UPDATE ZTABLE SET FIELD = 'ABC' WHERE FIELD1 = 'TEST'.</b>

Thanks,

Naren

4 REPLIES 4
Read only

Former Member
0 Likes
648

Hi,

<b>MODIFY statement can be used for modifying database table or internal table..</b>

Ex..

  • database table

MODIFY ZTABLE.

  • Internal table.

MODIFY ITAB FROM WA INDEX 1.

<b>READ TABLE is used for reading a single record from the internal table.</b>

Ex..

READ TABLE ITAB INTO WA INDEX 1.

UPDATE statement is used for updating database table.

Ex..

<b>UPDATE ZTABLE SET FIELD = 'ABC' WHERE FIELD1 = 'TEST'.</b>

Thanks,

Naren

Read only

Former Member
0 Likes
647

hi Abhay

<b>UPDATE:-</b>

The Open SQL statement for changing data in a database table is:

<b>UPDATE <target> <lines>.</b>

It allows you to change one or more lines in the database table <target>. You can only change lines in an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table <target> either statically or dynamically.

<b>MODIFY:-</b>

To insert lines into a database table regardless of whether there is already a line in the table with the same primary key, use the following:

<b>MODIFY <target> <lines>.</b>

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added.

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

<b>MODIFY <target> FROM TABLE <itab> .</b>

<b>READ</b> is used to read the internal table at a particular index or whole of the tabel

<b>Read table itab index <index no></b>

Regards

ravish

<b>reward points if helpful</b>

Read only

Former Member
0 Likes
647

Hi,

<b>MODIFY:</b>

Modify statment will work both insert and Update..

Modify <ztable> from table <int_table>.

if you are changing non primary key,then it works like update..

if you are creating new record then it works like insert command.

Check the Demo Program <b>DEMO_LIST_MODIFY_FIELD_FORMAT</b> for Example.

<b>READ TABLE:</b>

Read table will get the first record that saitisfies the condition specified in the with key statement into the header.

if an itab contains the following data:

field1 field2

1 one

2 two

3 three

4 four

5 five

And if you read the itab like this:

read table itab into WA with key field1 = '3'.

if sy-subrc = 0.

write:/ wa.

endif.

The output will be

3 three.

<b>UPDATE:</b>

Update command is used to Update a DB record ......../ records .......

If u want to update records which meets certain criteria then use the following command ...

<b>UPDATE</b> <DB Table Name> SET <Fieldname> = <value u want to pass>

WHERE <field 1> = <retrict value 1>

AND <field 2> = <retrict value 2>

<b>Example:</b>

TABLES SPFLI.

DATA WA TYPE SPFLI.

MOVE 'AA' TO WA-CARRID.

MOVE '0064' TO WA-CONNID.

MOVE 'WASHINGTON' TO WA-CITYFROM.

...

UPDATE SPFLI FROM WA.

MOVE 'LH' TO SPFLI-CARRID.

MOVE '0017' TO SPFLI-CONNID.

MOVE 'BERLIN' TO SPFLI-CITYFROM.

...

UPDATE SPFLI.

Regards,

Padmam.

Read only

Former Member
0 Likes
647

You can take printout and go throught it has with syntax ...


1.
MODIFY for Database Tables

Inserts or changes lines in database tables.

Syntax

MODIFY <dbtab> FROM <wa>.

MODIFY <dbtab> FROM TABLE <itab>.

Works like INSERT for database tables, if there is not yet a line in the table with the same primary key. Works like UPDATE if a line already exists with the same primary key. 

MODIFY for any Internal Table

Changes the content of lines in internal tables of any type.

Syntax

MODIFY TABLE <itab> FROM <wa> [TRANSPORTING <f1> <f 2>...] 
                              [ASSIGNING <FS> | REFERENCE INTO <dref>].

Copies the work area <wa> into the line of the internal table with the same table key as <wa>. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the modified line or the relevant data reference is stored in <dref> after the statement. You can use the TRANSPORTING addition to specify the exact components that you want to change. 

MODIFY <itab> FROM <wa> TRANSPORTING <f1> <f 2>... WHERE <logexp>.

Copies the work area <wa> into the line of the internal table for which the logical expression is true. In each comparison of the logical expression, the first operand must be a component of the line structure. 

MODIFY for Index Tables

Changes the content of lines in index tables.

Syntax

MODIFY <itab> FROM <wa> [INDEX <idx>] [TRANSPORTING <f1> <f 2>...] 
                        [ASSIGNING <FS> | REFERENCE INTO <dref>].

Copies the work area <wa> into the line of the internal table with the index <idx>. If you omit the INDEX addition, you can only use the statement within a LOOP. In this case, you change the current loop line If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the modified line or the relevant data reference is stored in <dref> after the statement.

<b>MODIFY for Lists</b>

Changes a list line.

Syntax

MODIFY LINE <n> [INDEX <idx>] [OF CURRENT PAGE|OF PAGE <p>]
      |CURRENT LINE
      LINE FORMAT <option1> <option2>... 
      FIELD VALUE <f1> [FROM <g1>] <f2> [FROM <g2>]... 
      FIELD FORMAT <f1> <options1> <f2> <options2>.

Changes either line <n> on the current or specified list (or page), or the last line to be chosen. The exact nature of the change is specified in the additions

MODIFY SCREEN

Changes the SCREEN table.

Syntax

MODIFY SCREEN...

Like changing an internal table. The system table SCREEN contains the names and attributes of all of the fields on the current screen. 

2.
READ for any Internal Table

Reads a line of an internal table.

Syntax

READ TABLE <itab>  FROM <wa>
                  |WITH TABLE KEY <k1> = <f1>... <kn> = <fn> 
                  |WITH KEY = <f>
                  |WITH KEY <k1> = <f1>... <kn> = <fn> 
      INTO <wa> [COMPARING <f1> <f2>... |ALL FIELDS]
                [TRANSPORTING <f1> <f2>... |ALL FIELDS|NO FIELDS]
     |ASSIGNING <FS>
     |REFERENCE INTO <dref>.

This statement reads either the line of the internal table with the same key as specified in the work area <wa>, the line with the key specified in the TABLE KEY addition, the line that corresponds fully to <f>, or the one corresponding to the freely-defined key in the KEY addition. The contents of the line are either written to the work area <wa>, or the line is assigned to the field symbol <FS>. If you assign the line to a work area, you can compare field contents and specify the fields that you want to transport.

READ for Index Tables

Reads a line of an internal table.

Syntax

READ TABLE <itab> INDEX <idx>   INTO <wa>... 
                              | ASSIGNING <FS>
                              | REFERENCE INTO <dref>.

The line with index 7 is read. The result is specified as with any internal table. 

<b>READ for Lists</b>

Reads the contents of a line from a list. 

Syntax

READ LINE  <n> [INDEX <idx>] [OF CURRENT PAGE|OF PAGE <p>]
          |CURRENT LINE
          [FIELD VALUE <f1> [INTO <g1>]... <fn> [INTO <gn>]].

Reads either the line <n> on the current or specified list or page, or the last line to have been selected by the user. The addition specifies the fields that you want to read, and the target fields into which they should be placed. The entire line is always placed in the system field SY-LISEL, and the HIDE area is filled for the line. 

3.UPDATE

Changes entries in database tables.

Syntax

UPDATE <dbtab> SET  <si> = <f> 
                   |<si> = <s i> + <f> 
                   |<si> = <s i> - <f> [WHERE <cond>].

The value in the column <si> is set to the value <f>, increases it by <f>, or decreases it by <f> for all lines selected. The WHERE clause specifies the lines that are changed. If you omit the WHERE clause, all lines are changed. 

Syntax

UPDATE <dbtab> FROM <wa>.

UPDATE <dbtab> FROM TABLE <itab>.

This deletes the line that has the same primary key as the work area <wa>, or deletes all the lines in the database that have the same primary key as a line in the internal table <itab>. The work area <wa> or the lines of the internal table <itab> must have at least the same length and alignment as the lines of the database table.

Rewar points if it is usefull ..

Girish