1. A logical database provides optimized access to related database tables in an ABAP program. It handles the database queries and returns the results to the calling program.
2. When a logical database is used, a selection screen is automatically displayed to filter the returned data. The program only needs to define data processing using GET events.
3. GET events are executed in tree-like order to retrieve related records from different tables, matching the relationships defined in the logical database structure. This simplifies programming multi-table reports.
Sample problem Go through example above explaining solution in terms of the relationship between the two tables.
Solution 1 - Nested Select Statement What if you wanted to print details of each flight (departure/destination)? >> a third select statement would be used using the carrid and connid number to look up another table storing dept & dest cities. Use of nested selects is complex and requires a good knowledge of the table structures involved as well as correct syntax involved with the “where” clause.
Solution 2 - Using a Logical Database Using a logical database is another method for reading data from a database table. A logical database is actually a separate program, usually written by SAP, that provides access to a group of related tables to an ABAP/4 program. The R/3 system contains about 150 logical databases covering most of the business processes (financials, purchasing, stock movements). When you run a program that calls a logical database , the program behind the logical database runs as well. The logical database issues the SELECT commands and returns the data to the calling program. Where is the logical database specified? >> In the program attributes screen. How does the program know what data to retrieve i.e. flights after 01/09/2006? >> Selection screen automatically appears. How do you know a program uses a logical database? >> If it contains the GET statement and NODE statement .
A logical database supplies your program with entries from tables. This means that you only need to program the data processing statements. Each logical database has a structure containing a hierarchy of those tables that can be read. You can attach exactly one logical database to each type 1 program. The logical database then supplies your program with entries from tables. This means that you only need to program the data processing statements.
Assigning a Logical Database All Logical Databases have a name which must be entered in the Logical database field of the attributes screen. Only one logical database can be used per program.
Selection screen of a Logical Database The logical database has its own selection screen with typical criteria from which the user can select. When the program is started, the system displays the selection screen defined by the logical database. Selections displayed depend on the NODES statement. The NODES statement determines how detailed the selection screen is : The selection screen that has been defined in the logical database should contain only those key information input fields that the program needs. The NODES statement allows you to ensure only information from relevant tables is available to the logical database. Once the user has input some selection criteria, the logical database can issue the appropriate SELECT command with the proper where clause to retrieve the data. What would happen if the user did not type in any input to the selection screen? >> Booking information would be displayed for all flights for all airlines.
Using the GET event GET isn’t a command like SELECT or WRITE. It’s an event. A code block associated with an event ends with the next event statement, such as another GET. Using events to access data in a logical database can be confusing at first, so a simple example will be used. A logical database is composed of several tables that form a hierarchy (as well as a program that accesses those tables). The logical database makes data from the hierarchy available to your ABAP program. Looking at the program from the traditional top-down approach, you would expect a list of all the rows from the spfli table followed by all the rows from the sflight table. But events don’t execute in a top-down fashion - they execute when appropriate. Each event is like a separated subroutine that’s executed when the systems detects a certain condition. REFER to NEXT Slide's NOTES
Using the GET event What would happen if I switched the 2 GET statements around? >> Nothing, because they are events, they would still be triggered in the order determined by the hierarchy of the tables in the logical database. What would happen if I deleted the GET spfli event? >> A list of flight dates without the corresponding flight details A simple GET statement may in fact access more than one table if the GET specifies a table at the bottom of the logical database hierarchy. The overhead of reading from all those tables isn’t obvious from looking at a single statement. A program using a SELECT statement may give you better performance.