What is an open sql in sap abap?What is its function?

Open SQL contains set of ABAP statements that performs the operations in the central database of the current AS ABAP. It helps in accessing the database tables present in ABAP dictionary. Data manipulation language functionality is the specific feature that maps the Open SQL statements in ABAP that supports database systems.
The open SQL interface converts SQL statements to database specific of the database interface which are then transferred to the database system and executed. The central database of AS ABAP accessed automatically and also accessing other databases is also possible by connecting secondary databases.
To know whether the set of these statements used in an ABAP program, is executed successfully or not, you need to check it first. If proper insertion of a record into a database table does not take place, then proper action has to be taken in the program which is mandatory. This can be rectified by using system field known as SY-SUBRC which is used already. This field checks whether the statement is executed successfully or not, by providing the value 0. Thus the user can further continue with the program.
DATA statement is the statement used to declare a work area. Let the name be given as 'wa_customers1'. With the use of LIKE statement you can declare the data type fields in a table.

INSERT Statement

With the LIKE statement the wa_customers1 work area is declared as ZCUSTOMERS1 table. This work area can only store one record. Once the declaration is complete, then with the help of INSERT statement insert the work area which holds the record into the table. Here the code is read as 'INSERT ZCUSTOMERS1 FROM wa_customers1'.

Some data should be filled in the work area. Take the field names from the ZCUSTOMERS1 table by forward navigation. Double click the table name in the code using the transaction SE11. This indicates that the fields of the table are copied and pasted into the ABAP editor.
Following is the code snippet −
Next CHECK statement is used as follows. If the record is inserted correctly, the system will show as the value as below. Or else it will display SY-SUBRC code which will not equal zero.
Following is the code snippet −
Once the insertion is completed check the program, save, activate the code, and then test it. The output window will appear as 'Record Inserted Successfully'.

CLEAR Statement

CLEAR statement helps to clear the field or variable and allows to insert new data, so that the fields or variables which already exist can be reused. CLEAR statement is generally used in programs.
In the previous code snippet, validation check is performed only after the insertion of the new record into the table. Here we can use CLEAR statement to insert a new record and also you can reuse the data many times as per your wish.

UPDATE Statement

UPDATE statement is used to update one or multiple existing records in a table at the same time. It has the same features as the INSERT statement; it follows the same procedure that is declaring the work area, new data is then filled and insert into a record before the program is executed. The existing records which have created using the insert statement will get updated here with the UPDATE STATEMENT. You need to edit the text included in the NAME and TITLE fields. Using Update statement the same structure produces as shown below −

As soon as the UPDATE statement gets executed, to verify that the record has been updated successfully, by using the Data Browser in the ABAP Dictionary you can confirm.

MODIFY Statement

It is very clear that MODIFY statement relates to make changes in the record. How does INSERT and UPDATE statements are used, in the same way Update statement is used. So it is considered as the combination of both INSERT and UPDATE statements. It helps in either inserting a new record or modifying an existing record. Same syntax is followed by the UPDATE statement as the previous two statements have.
When this statement is executed, first it will check whether the key fields match with those in the table. If records with these key field values already exist, it will get updated. Otherwise, new record will get created.
following is the code snippet for creating a new record −
In this example, you can see with the CLEAR statement new entry can be created into the work area, and then add customer (number) 100007. As this is a new unique key field value, insertion of new record takes place. Further validation check has been done.
When this is executed and viewed in the Data Browser, a new record will have been created for the customer number 100007 (RALPH).
The above code produces the following output (table contents) −


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status