Professional Documents
Culture Documents
Open SQL
Open SQL
Sap R/3 is independent of database being used, i.e. sap can use any database to store the data.
Whenever we want to store the data into database, we need to use the respective database language
statements.
It is an interface which is given by standard SAP software which is used to convert the abap language
statements into respective database statements and vice versa.
The statement which is converted by R/3 interface layer from abap to respective database statement
and viceversa are called open sql statements.
These statements directly communicate with the database without interacting with R3 interface layer
are called native sql statements.
SYNTAX OF OPEN SQL STATEMENTS
2. Always work with internal tables rather than work areas to insert /update/modify data in database
table
SYSTEM VARIABLES: There are two system variables which are updated automatically for every open sql
operation.
1) SY-SUBRC
operation. If SY-SUBRC = 0.
If SY-SUBRC NE 0.
2) SY-DBCNT
INSERT: It is used to insert single record or multiple records from internal table to database table.
SY-SUBRC NE 0 ,means only few records are inserted or no records are inserted.
Suppose if there are any duplicate records in the internal table it will throw an run time error.
This statement does not insert any duplicate records, but it avoids runtime error.
UPDATE
This statement will update the record which is available in database table.
Or
<f2>= <val>
Where <condition>.
DELETE: this statement is used to delete either a single record or multiple records from database tables.
EXAMPLES ON INSERT,MODIFY,UPDATE,DELETE
BUSINESS REQUIREMENT:
INSERT
WA_T001W-WERKS = ‘HYD’.
WA_T001W-WERKS = ‘HYD1’.
IF SY-SUBRC EQ 0.
ENDIF.
UPDATE:
WA_T001W-WERKS = ‘HYD’.
WA_T001W-WERKS = ‘HYD1’.
IF SY-SUBRC = 0
ENDIF.
(OR)
IF SY-SUBRC = 0
ENDIF.
MODIFY:
WA_T001W-WERKS = ‘HYD3’.
WA_T001W-WERKS = ‘HYD4’.
IF SY-SUBRC = 0
ENDIF.
DELETE:
WA_T001W-WERKS = ‘HYD3’.
WA_T001W-WERKS = ‘HYD4’.
IF SY-SUBRC = 0
ENDIF.