OPEN SQL in ABAP

 

OPEN SQL commands that are used on database tables are

  1. SELECT
  2. INSERT
  3. UPDATE
  4. MODIFY
  5. DELETE
  6. COMMIT WORK

SELECT is used for getting records from dbtable.

  • SELECT....

ENDSELECT.

  • SELECT....  FROM TABLE INTO ITAB.

INSERT is for adding new records to dbtable.

  • INSERT DBTAB FROM WA.
  • INSERT INTO DBTAB VALUES WA.

workarea records  will be transferred to dbtable.

  • INSERT DBTAB FROM TABLE ITAB.

after the execution of this

SY-DBCNT contains no.  of records added

SY-SUBRC is 0 if operation is successful

is 4 if operation is failed

UPDATE is for changing the contents of existing records.

  • UPDATE DBTAB SET FLDI = VAL1 FLD 2 = VAL2....

all records field values will be modified.

Use where clause to process few records.

Ex.  UPDATE SPFLI SET CARRID = 'AN'WHERE CARRID = 'AP'.

UPDATE DBTAB FROM WA.

the record which is matched with workarea record according to its PRIMARY KEY fields will be modified

  • UPDATE DBTAB FROM TABLE ITAB.

SY-DBCNT & SY-SUBRC will be set accordingly

sy-subrc is 0 if atleast one record is updated.

MODIFY is the combination of INSERT and UPDATE commands

  • MODIFY DBTAB FROM WA.
  • MODIFY DBTAB FROM TABLE ITAB.

if the record is already existed it will be UPDATED.

if the record is not there it will be INSERTED

SY-DBCNT & SY-SUBRC will be set accordingly.

COMMIT WORK is used to make above operations permanent.

ROLLBACK WORK is used to cancel the above operations.

These are used in module pool programming.

Do not modify the records of standard tables of database server through simple programs.

They must always be updated by standard transactions only.

Comments

Popular posts from this blog

Domains and Data Elements

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

OPEN SQL EXAMPLES IN ABAP – PART 2