0% found this document useful (0 votes)
26 views

Reading Data Using Opensql - 2

The SELECT statement is used to read data from a database table. It specifies the columns and rows to select, the target area to store the results, and the source table. Optional clauses can filter the rows selected using conditions. The code uses SELECT * to read all columns and rows from the ZEMPLOYEE table into the GWA_EMPLOYEE work area. It then loops through each record returned, writing the field values to the output. Variables like SY-SUBRC and SYDBCNT provide information about the number of records selected.

Uploaded by

Vikram Bigamudre
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Reading Data Using Opensql - 2

The SELECT statement is used to read data from a database table. It specifies the columns and rows to select, the target area to store the results, and the source table. Optional clauses can filter the rows selected using conditions. The code uses SELECT * to read all columns and rows from the ZEMPLOYEE table into the GWA_EMPLOYEE work area. It then loops through each record returned, writing the field values to the output. Variables like SY-SUBRC and SYDBCNT provide information about the number of records selected.

Uploaded by

Vikram Bigamudre
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

SELECT is the open SQL statement to read the data from the database.

The general syntax for SELECT statement is as follows. SELECT <result> INTO <target> FROM <source> [WHERE <condition>] Clause SELECT <result> Description Specifies which columns you want to read, whether one line or many lines needs to selected, and whether duplicate entries are allowed INTO <target> Determines the target area into which the selected data is to be placed FROM <source> Specifies the database table from which the data is to be selected WHERE <condition> specifies which lines are to be read by specifying conditions for the selection
DATA: gwa_employee TYPE zemployee. WRITE:/1 'Emp ID' color 5,9 'Name' color 5,17 'Place' color 5, 27 'Phone' color 5,39 'Dept' color 5. SELECT * FROM zemployee INTO gwa_employee. WRITE:/1 gwa_employee-id,9 gwa_employee-name, 17 gwa_employee-place,27 gwa_employee-phone, 39 gwa_employee-dept_id. ENDSELECT.

In the above code,


GWA_EMPLOYEE is the work area to hold one record of table ZEMPLOYEE at a time. SELECT * specifies all the rows and columns are read from the database. SELECT ENDSELECT works in a loop, so the code between SELECT and ENDSELECT will be executed for each record found in the database table. WRITE statements are used to output the values in the list. If the SELECT statement returns any record then the value of the system variable SY-SUBRC is set to zero else a non zero value will be set. After the SELECT statement is executed, the value of the system variable SYDBCNT contains the number of records read from the database. The value of SYDBCNT is zero if no records are read from the database.

Table ZEMPLOYEE Entries

Report Output

You might also like