- •Introduction to the abap Workbench
- •15 Introduction to the abap Workbench
- •49 Exercise 3: Creating Transactions
- •Case pa_op.
- •When ’/’.
- •In debugging mode.
- •127 Exercise 7: Working with Internal Tables
- •Loop at it_spfli into wa_spfli.
- •Into (field_1, ... , field_n)
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •Insert wa_flight into table it_flight.
- •Wa_flight-percentage, ’%’.
- •Id ’actvt’ field ’02’.
- •Id ’actvt’ field actvt_display.
- •Into corresponding fields of wa_flight
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •195 Exercise 11: Subroutines
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •Clear wa_flight. At line-selection.
- •Wa_flight-fldate.
- •Wa_sbook-cancelled.
- •Wa_sbook-loccurkey.
- •Id ’actvt’ field actvt_display. If sy-subrc ne 0.
- •Into corresponding fields of wa_flight
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •At line-selection. Call screen 100.
- •Wa_sbook-bookid.
- •Id ’carrid’ field wa_sbook-carrid
- •Id ’actvt’ field actvt_change.
- •When ’back’.
- •303 Exercise 17: Creating an Interface
- •When ’rw’.
- •Importing
- •If container_r is initial.
Loop at it_spfli into wa_spfli.
WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom, wa_spfli-cityto, wa_spfli-deptime, wa_spfli-arrtime.
ENDLOOP. ENDIF.
Lesson Summary
You should now be able to:
• Define internal tables
• Use basic ABAP statements with internal tables
• Analyze internal tables in debugging mode
Unit Summary
You should now be able to:
• Define elementary data objects (simple variables)
• Use basic ABAP statements with elementary data objects
• Execute and analyze programs in debugging mode
• Define structured data objects (structure variables)
• Use basic ABAP statements for structured data objects
• Analyze structured data objects in debugging mode
• Define internal tables
• Use basic ABAP statements with internal tables
• Analyze internal tables in debugging mode
Related Information
... Refer to the online documentation for the relevant ABAP statement.
Unit 5
133 Data Retrieval
See the introductory instructors’ notes in the lessons
Unit Overview
Refer to the individual lesson objectives for an overview of this unit.
Unit Objectives
After completing this unit, you will be able to:
• List different methods for searching relevant database tables
• Program read access to specific columns and rows within a particular database table
• List different methods for read accesses to several database tables
• Explain the SAP authorization concept
• Implement authorization checks
Unit Contents
Lesson: Reading Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146
Exercise 8: Data Retrieval Using a SELECT Loop . . . . . . . . . . . . . . . . . . . .163
Exercise 9: Data Retrieval and Buffering in an Internal Table . . . . . . . .169
Lesson: Authorization Check. ... ... ... .. ... ... .. ... ... ... .. ... ... ... .. ... ... ..174
Exercise 10: Authorization Check . . ... ... .. ... ... ... .. ... ... ... .. ... ... ..181
Lesson:
134
Reading Database Tables
Lesson Duration: 110 Minutes
Lesson Overview
In this lesson you will learn how to retrieve information on database tables and how to read data from them. An overview of techniques that allow you to access multiple database tables will also be covered.
This lesson concludes with a note about database table accesses that initiate changes.
Lesson Objectives
After completing this lesson, you will be able to:
• List different methods for searching relevant database tables
• Program read access to specific columns and rows within a particular database table
• List different methods for read accesses to several database tables
Business Example
You need to evaluate data from database tables.
Data Retrieval
Figure 86: Database Access (Architecture)
SQL is the abbreviation of Structured Query Language, a language that enables define, change, and read access to database tables.
Every relational database system has a native SQL, which is unfortunately database-specific. Hence, an ABAP program with native SQL statements cannot be used without restrictions in all SAP systems (due to the different database systems of different SAP systems).
In contrast Open SQL is an SAP-defined, database-independent SQL standard for the ABAP language. The Open SQL statements are dynamically converted to the corresponding native SQL statements of the currently used database system and are thus independent of the database. They allow the ABAP programmer uniform access to data, regardless of the database system installed.
The above graphic illustrates the options for searching for the required database tables.
Of course, you can also execute a free search via the Repository Information
System.
Figure 88: Database Read Access (Overview)
You use the Open SQL statement SELECT to program database read access. The
SELECT statement contains a series of clauses, each of which has a different task:
• Amongst other things, the SELECT clause describes which fields of the table are to be read.
• The FROM clause names the source (database table or view) from which the data is to be selected.
• The INTO clause determines the target variable into which the selected data is to be placed.
• The WHERE clause specifies the columns of the table that are to be selected.
For information about other clauses, please refer to the keyword documentation for the SELECT statement.
Figure 89: Reading Single Records
The SELECT SINGLE statement allows you to read a single record from the database table. To ensure a unique access, all key fields must be filled in the WHERE clause. The client field is an exception: If it is not specified the current client is assumed. (Please note that a client can only be specified in the SELECT select statement in combination with the CLIENT SPECIFIED addition. More details on this are provided in the course of this lesson.)
You use the asterisk * to specify that all fields of the table row to be selected are to be read. If you only want a specific selection of columns, you can list the required fields instead of the *. The next graphic illustrates this.
You use the INTO clause to specify the target variable to which the data record is to be copied. Left-justified, the target area must be structured like the table row or the specified required fields of the row.
If the system finds a suitable record, the return value SY-SUBRC equals 0.
Figure 90: Suitable Target Structure for the Field List
If you want only a certain selection of fields from the table row to be read, these can be specified as a field list within the SELECT statement (as described in the above graphic). In the INTO clause, you must then name a target structure variable that has the same structure as the field list (at least in the beginning), that is, it contains the fields of the field list in the same order. Only the corresponding field types have to match. The names of the target structure fields are not taken into account.
An alternative to specifying the target structure is to list the corresponding target fields in the INTO clause.
