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

Delete modify in table

Former Member
0 Likes
1,682

hi,

how can we insert delete and modify in database table using an internal table in programming codes .

if the internal table is same like as table s225 in database.

thanks jayant.

6 REPLIES 6
Read only

sachin_mathapati
Contributor
0 Likes
1,303

Hi Jayant,

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.

Insert :

INSERT dbtab [CLIENT SPECIFIED] FROM TABLE itab. or INSERT (dbtabname) [CLIENT SPECIFIED] FROM TABLE itab.

Addition: ... ACCEPTING DUPLICATE KEYS

Effect

Mass insert: Inserts all lines of table itab in a single operation. The lines of itab must satisfy the same condition as the work area wa in variant 1.

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

The return code is set as follows:

SY-SUBRC = 0:

All lines inserted successfully. Any other situation causes a runtime error.

Note

If the internal table itab is empty, SY-SUBRC and SY-DBCNT are both 0 after the call.

Delete :

DELETE dbtab FROM TABLE itab.

DELETE (dbtabname) FROM TABLE itab.

Addition:

... CLIENT SPECIFIED

Effect

Mass deletion: Deletes all database table lines for which the internal table itab contains values for the primary key fields. The lines of the internal table itab must satisfy the same condition as the work area wa in addition 1 to variant 2.

The system field SY-DBCNT contains the number of deleted lines, i.e. the number of lines of the internal table itab for whose key values there were lines in the database table dbtab.

The return code is set as follows:

SY-SUBRC = 0:

All lines from itab could be used to delete lines from dbtab.

SY-SUBRC = 4:

For at least one line of the internal table in the database table, there was no line with the same primary key. All found lines are deleted.

Note

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

Regards,

Sachin M M

Read only

naveen_inuganti2
Active Contributor
0 Likes
1,303

Hi....

To delete the database table use this code.....

> parameter: p_f1 like <db-f1>.

>

> SELECT * FROM <.dbtable> INTO TABLE ITAB WHERE <db-f1> IN p_f1.

> DELETE FROM <dbtable> WHERE WHERE <db-f1> IN p_f1.

And to modify the database table use this code.....

..

> select * from <.dbtable> into table itab.

> LOOP AT Itab.

> itab-f1 = 'N'.

> MODIFY <.dbtable> FROM itab.

> ENDLOOP.

Thanks,

Naveen.I

Edited by: Naveen Inuganti on Jun 30, 2008 6:13 PM

Read only

Former Member
Read only

GauthamV
Active Contributor
0 Likes
1,303

hi,

check this sample code.

TABLES : zgm_table.

data : it_data type standard table of zgm_table,

wa_data type zgm_table.

select-options : s_name for zgm_table-name,

s_city for zgm_table-city,

s_role for zgm_table-role.

*wa_data-name = 'ABC'.

*wa_data-city = 'JAPAN'.

*wa_data-role = 'ASSOCIATE'.

*wa_data-salary = 26000.

*

*append wa_data to it_data.

*insert zgm_table from table it_data.

*

*IF sy-subrc = 0.

*

  • MESSAGE 'records created succesfully' TYPE 'S'.

*

*ENDIF.

*modify zgm_table from table it_data.

*

*IF sy-subrc = 0.

*

  • MESSAGE 'records created succesfully' TYPE 'S'.

*

*ENDIF.

*

*

*DELETE FROM zgm_table WHERE name in s_name.

*

*IF sy-subrc = 0.

*

  • MESSAGE 'records deleted succesfully' TYPE 'S'.

*

*ENDIF.

wa_data-name = 'ABC'.

wa_data-city = 'JAPAN'.

wa_data-role = 'ASSOCIATE'.

wa_data-salary = 38000.

append wa_data to it_data.

update zgm_table from table it_data.

use these statements depending on ur requirement.

Read only

Former Member
0 Likes
1,303

Hi,

Lets take

DATA: it_s225 TYPE TABLE OF s225.

DATA: wa_s225 LIKE LINE OF it_s225.

First we fetch the data from s225.

SELECT * FROM s225 INTO TABLE it_s225 WHERE ssour = <some_value>.

Now down the line in the program you need to delete records corresponding to specific value of sptag.

DELETE it_s225 WHERE sptag = <some_date>.

To delete the records from database table, you use

DELETE s225 FROM TABLE it_s225.

Suppose you need to set the value of the field WERKS to 'w001' for all records.

LOOP AT it_s225 INTO wa_s225.

wa_s225-werks = 'w001'.

MODIFY it_s225 FROM wa_s225 TRANSPORTING werks.

ENDLOOP.

CLEAR wa_s225.

To change the value of werks in database table use

MODIFY s225 FROM TABLE it_s225.

Please reward if helpful.

Regards,

Prosenjit.

Read only

Subhankar
Active Contributor
0 Likes
1,303

Hi,

Please try it,

To delete record

*lock the table before updating

if it successful , delete the record

DELETE zhtm_intf_log FROM wa_zhtm_intf_log.

IF sy-subrc = 0.

COMMIT WORK.

ENDIF.

ENDIF.

To modify.

MODIFY zhtm_intf_log from wa_zhtm_intf_log.

IF sy-subrc = 0.

COMMIT WORK.

ENDIF.

  • Unlock the table