‎2008 Jun 30 1:37 PM
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.
‎2008 Jun 30 1:42 PM
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
‎2008 Jun 30 1:42 PM
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
‎2008 Jun 30 1:44 PM
Hi,
Check out the following Links which are helpful....
http://help.sap.com/saphelp_nw04/helpdata/en/79/c5547fb3dc11d5993800508b6b8b11/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/a4/35ff395ef548e5add909b73ca12878/frameset.htm
Regards.
‎2008 Jun 30 1:47 PM
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.
‎2008 Jun 30 1:47 PM
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.
‎2008 Jun 30 1:50 PM
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