Some software products marketed by SAP AG and its distributors contain .. 1 Unit 1: Flow of an ABAP Program BC Lesson: System Architecture and ABAP . Register Login. Tutorials Forum PDF Books Interview Question Courses & Institutes Sample Resume Articles SAP Career Guidence. Logo ☰. Some software products marketed by SAP AG and its distributors contain SAP AG. BC ABAP Workbench Tutorial. April 3. Icons. Icon.
|Language:||English, Spanish, German|
|ePub File Size:||25.53 MB|
|PDF File Size:||17.45 MB|
|Distribution:||Free* [*Sign up for free]|
An SAP Compass course - use it to learn, reference it for work. SAP NetWeaver .. following packages BC, BC, BC and DNW7AW. The following. BC ABAP Workbench Concepts and Tools in the ABAP Dictionary, see the SAP. This book is not affiliated with, sponsored by, or approved by SAP AG. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate.
SAP BC What the User Sees Program Start Executing a Program Object list
Only the header is copied. The actual table content is copied. Working with Internal Tables Exercise 7: Working with Internal Tables Exercise Objectives After completing this exercise, you will be able to: Define internal table 1. You should therefore define an internal table with a line type that is compatible with the line structure of SPFLI.
Define an internal table name suggestion: Define a suitable work area for the internal table name suggestion: Fill the internal table and display contents 1. Display the buffered data in a list. Use the LOOP statement to do this. Working with Internal Tables Solution 7: Working with Internal Tables Task 1: Refer to the online documentation for the relevant ABAP statement. Reading Database Tables Data Retrieval and Buffering in an Internal Table Authorization Check Data Retrieval BC Lesson: Reading Database Tables Lesson Overview In this lesson, you will learn how to get information about database tables.
An overview of techniques that allow you to access multiple database tables will also be provided. This lesson concludes with a note about database table accesses that initiate changes. They allow the ABAP programmer uniform access to data, regardless of the database system installed. Data Retrieval BC Figure Searching for Database Tables You have different options for searching for database tables: Using the application hierarchy or the Repository Information System.
If you have the name of a program that accesses the database table you are searching for: This is often a structure field. Double-click the data element and then use the where-used list function to search for transparent tables with the field type.
Reading Database Tables Figure It therefore specifies the rows to be selected from the table. If you only wish a specific selection of columns, you can list the required fields instead.
In the INTO clause, enter the destination to where the database interface is to copy the data. The target area should have a structure identical to the columns of the database table being read and be left-justified. The system only fills those components that have identical names to columns in the database table. If you do not use this addition, the system fills the target area left-justified, irrespective of its structure.
The database can then terminate the search as soon as it has found the appropriate record. In this example, the field list determines the columns whose data is to be read from the database.
The name of the database table that is accessed is found in the FROM clause. The database delivers the data to the database interface in packages. The ABAP runtime system copies the data records to the target area row by row using a loop. This is called an array fetch. INTO Clause: Target Structure Suitable for Field List The program must contain a data object with a suitable type for each column that is requested from a database table.
To make the program easier to maintain, you should use the corresponding global types ABAP Dictionary to assign types to the data objects. The INTO clause specifies into which data object the data from the database table is placed. There are two possibilities: In this case, you can enter the name of the structure in the INTO clause. The contents are copied left-justified without gaps. The field names within the structure component names are disregarded.
If you select data from client-specific tables, the system always reads the data records of the current client, unless otherwise specified. Since this special case is not relevant for this course, the client field is generally omitted from the graphics. Performance Aspect: Secondary Index As soon as you navigate to the definition of a database table in the ABAP Dictionary, you will see information about all the technical attributes of that database table.
The following information is of interest for improving the performance of database accesses: Key fields If the rows requested from the database are being retrieved according to key fields, the Database Optimizer can perform access using a primary index. Secondary index If the rows requested from the database are retrieved according to fields in a secondary index, the Database Optimizer can perform access using this secondary index.
These are displayed in a dialog box whenever you choose the Indexes pushbutton. You can choose an index from the dialog box by simply double-clicking it.
The system then displays a screen with additional information about that index. In the case of client-specific tables, it is standard that the client field is included in the index. Reading Database Tables Outlook: Reading Linkable Database Tables If you want to read data from two databases that are logically connected, you can access both database tables using one database query.
To do so, you must enter the following information: In this condition, columns from both database tables are linked. A record is placed in a common row in the results table if all the field values of the linked columns match. If a column appears in both database tables, you must specify the table from which this column is to be read. It is known as a view. There are different kinds of views. You can implement a dynamic link using ABAP statements. It is known as an ABAP join.
At runtime, the system generates an appropriate database query in the database interface. Reuse Components for Data Retrieval If reusable components that encapsulate complex data retrieval are available, you must use them. There are four possible techniques: Logical databases are data retrieval programs that return logically connected data in a hierarchical sequence. Information about the first three techniques is available in the relevant units. For detailed information on how to include logical databases, refer to the SAP library: Possible database accesses that initiate changes in the database should not be used unless the user understands the SAP transaction concept.
For further information, refer to the relevant keyword documentation. Reading Database Tables Exercise 8: The list should also include the occupancy, in percent, of each flight. Reading several rows using a loop 1. Change the work area type name suggestion: Find out information about the subfields of this structure. Define an input parameter for the airline abbreviation. Select only those fields that have a target field in the work area. Does the database interface still use the primary index?
Data Retrieval BC Task 2: Calculating the percentage 1. Within the loop statement, calculate the percentage occupancy for each flight.
Extend your list output to include the percentage occupancy. Reading Database Tables Solution 8: Data Retrieval BC 5. Despite this fact, the database interface can use the primary index in this case for selecting the data records. When the ABAP runtime system accesses client-specific tables, it assumes that data should only be taken into account if it belongs to the client under which the user is logged on.
Reading Database Tables 2. Reading Database Tables Exercise 9: For this purpose, append the data records for the selected airline to an internal table. Data retrieval and filling an internal table 1.
Define an internal table name proposal: Remove the statements for list output. You can still use the source code later. Sorting and outputting the internal table 1. Sort the internal table according to occupancy. Use a LOOP to display the contents of the internal table in a list. Reading Database Tables Solution 9: Authorization Check Lesson Overview In this lesson, you will learn why an authorization check is useful and how to include it in your programs. Authorization Checks Figure Authorization Check Critical data and parts of the functional scope of the SAP system must be protected from unauthorized access so that the user can only access those areas for which he has explicit authorization.
You should therefore carry out an authorization check before accessing the database. The system administrator assigns user authorizations when maintaining user master data. If it is 0, this means that the user has the required authorization and the program can be continued. However, if the value is not 0, the user does not possess the required authorization.
In this case, you could display a message, for example. Later in this course, you will learn how to make fields on the selection screen ready for input again if you perform the authorization check right after the selection screen and output a message if the user does not have the required authorization.
Apart from this type of authorization check within your program, there is generally no other security check. There are other concepts, such as applying an authorization check to a transaction code, but these are merely extras and not replacements.
Data Retrieval BC When assigning authorizations, you should specify exactly which data users are allowed to access and what kind of access should be allowed.
For example, you might want to allow users to display data for all airlines, but only allow them to change data for certain selected ones. This object must then be addressed both for the authorization assignment within user maintenance and for the authorization check in the program. Therefore, authorization objects simply define the combination of fields that need to be addressed simultaneously and serve as templates for the authorizations and the authorization checks.
The authorization objects are organized into object classes in order to make it easier to find and manage them; one or more classes may be assigned to each application. Authorization Check For authorization checks in programs, you specify the object and values the user needs in an authorization to be able to access the object in question.
This return code enables you to specify the consequences of a missing authorization yourself for example, program terminates or merely skips some output lines. If you do not want to carry out a check for a particular field, enter DUMMY after the authorization field.
When calling a transaction to change flight data, you want to check whether the user is authorized to change the entries for at least one airline carrier: Therefore, the check could not be executed successfully. Authorization Check Exercise Authorization Check Exercise Objectives After completing this exercise, you will be able to: Check for display authorization for airlines 1.
Search for the correct abbreviation of the activity to be checked. Use this constant in the authorization check. Only execute the database access if the user has display authorization for the selected airline. If this is not the case, display an appropriate error message on the list. Execute your programs; select the airline abbreviations AA and UA.
Check for display authorization for airlines II 1. Proceed as you did in the previous exercise. Authorization Check Solution Authorization Check Task 1: CASE sy-subrc.
Source code excerpt: Subroutines Lesson Overview In this lesson, you will learn how to use subroutines and why there is an interface for subroutines. You will also learn the different transfer types of a main program to the interface of a subroutine: Internal Program Modularization with Subroutines Figure Subroutines A subroutine is a program-internal modularization unit.
You move parts of a program to a subroutine to make the program easier to read and allow you to use these code segments more than once. You can pass data to the subroutine and back using its interface. This allows you to call the same functions for different data objects. The above example shows a subroutine that calculates a percentage. This subroutine is called several times, even though different data objects are passed to the interface in each case.
Using subroutines makes your program more function-oriented: This generally makes programs easier to maintain. This usually makes it easier to find the source of the error.
Ways of Passing Interface Parameters You specify how the data is passed from the main program actual parameters to the subroutine formal parameters in the interface. There are three ways of doing this: This means that value assignments to the formal parameter have absolutely no effect on the actual parameter. Call-by-reference The dereferenced address of the actual parameter is passed to the subroutine.
This means that value assignments to the formal parameter affect the actual parameter directly. The value of the actual parameter is physically changed by the subroutine through the address. Call-by-value-and-result A local copy of the actual parameter is passed to the subroutine and a value is passed back to the main program.
This means that value assignments to the formal parameter only affect the actual parameter after leaving the subroutine. You should choose this option if you want to be sure that the actual parameter will not be changed, should the subroutine be terminated prematurely.
Passing Interface Parameters: Syntax In the interface definition, you list the formal parameters of the different kinds and assign a type to each one. The sequence is syntactically fixed: Thus within the subroutine, you address the data that has been passed using the formal parameters.
You specify the way in which the parameters are to be passed in the interface definition: However, if you change a parameter listed after USING in the subroutine, you receive a warning in the extended program check.
Interface Parameters: Internal Program Modularization BC The data objects passed to a subroutine that is, the actual parameters can be of any type. If you use elementary types, you can decide whether or not you want to specify the type of the formal parameters. By specifying the type of the formal parameters, you ensure that only actual parameters of that type can be passed to the subroutine.
This makes your program more stable, since the syntax check will find any type conflicts. For compatibility reasons, you can also omit this addition. Then, if the statements in the subroutine are not suited to the inherited type, a runtime error may occur. If you want to specify a type completely, you must use a user-defined type. Conversely, the data types I, F, D, and T are fully typed.
Specifying Types for Structures and Internal Tables If you use structures or internal tables as formal parameters, you must type them fully. This allows you to access these formal parameters as normal within the subroutine. Subroutines The components of structures are known in the subroutine, as a result of the assigned type, so that you can address these components with the usual syntax. If you use internal tables, the assigned type allows you to address the formal parameter as an internal table with the usual syntax.
Note on runtime requirements: If you use internal tables as parameters, you should generally pass them using call-by-reference. Otherwise, the system can use considerable resources simply copying them to the subroutine. Both the formal parameters and the local data objects are only active at the runtime of the subroutine.
This means that memory is only allocated when the subroutine is called and is released as soon as the subroutine has been executed. Thus these parameters and data objects can only be addressed from within the subroutine. The global data objects from the main program can also be addressed from the subroutine. However, you should avoid doing this wherever possible.
Otherwise, you are bypassing the interface, which makes the program more error-prone. Internal Program Modularization BC If a local data object or formal parameter has the same name as a global data object, the ABAP runtime system addresses the local data object in the subroutine and the global one outside it.
They are then known as locally obscured objects. Passing an Internal Table The above example shows a main program calling a subroutine, which specifies the number of lines of an internal table needed to fulfill a specific criterion. To loop through the internal table, you need a work area with a compatible line type, which you define locally in the subroutine, by making a reference to the formal parameter.
Subroutines Figure When the subroutine is called, parameters are passed to it in strict sequence. For this reason, you should define the subroutine first and then call it. The Object Navigator supports you in this respect: This prevents you from mixing up or forgetting any parameters. However, you must remember to replace the formal parameters with actual parameters.
Subroutines in Debugging Mode In debugging mode, you can make a subroutine run without stopping. The execution of the main program does not stop until after the subroutine has been executed. Alternatively, you can execute the subroutine statement-by-statement using Single Step. If the current statement is located in a subroutine, you can execute the rest of the subroutine without it stopping by choosing Return.
Subroutines Exercise Subroutines Exercise Objectives After completing this exercise, you will be able to: Create a subroutine with internal table transfer 1.
Encapsulate the display of data in a list in a subroutine. To do so, define the subroutine and specify types for the interface parameter name proposal: Display the data from the subroutine using a LOOP. To do this, create the required table work area as a local data object in the subroutine name proposal: Call subroutine 1. Pass the internal table containing the data that has been read using the interface. Execute your program to test the result.
Subroutines Task 1: Subroutines DATA: Subroutines Lesson Summary You should now be able to: Event Blocks Event Blocks Figure A processing block consists of passive source code sections that are processed sequentially when called. Processing blocks are the smallest units in ABAP. They cannot be split, which also means that they cannot be nested. Such events can be initiated by the ABAP runtime system itself or by the user.
These are only required for screen processing. When a program is started, all the global data objects of the program are created in the working memory first. However, for the sake of clarity, you should place all declarative statements together at the beginning of the source code, with the exception of local declarations within subroutines. ABAP Program with Several Event Blocks and a Selection Screen In all of the programs that we have seen so far in this course, only one event block has been programmed in addition to the declarative statements.
In this case, there is no need to declare the event block explicitly. However, in more complex programs, we will require several different event blocks. The example given here contains a selection screen with an input field for a date. The date of the same weekday in the previous week should appear as the default value. However, a calculation is required in order to preset the date. Introduction to Event Blocks BC that the data object is filled with a default value.
To be able to change variables at runtime, you must therefore program a processing block. This should be processed before the standard selection screen is transmitted. Event Blocks Event blocks are called in a fixed sequence designed for list processing: Afterwards, the systems sends the selection screen with this new value to the presentation server. The user has the option of changing the value.
Then the selection screen is sent to the presentation server. Both events presented here are initiated by the ABAP runtime system exactly once each time a program is executed. Event Block Characteristics An event block is introduced with an event keyword. It ends implicitly when the next processing block starts.
Event blocks are called by the ABAP runtime system. Therefore, the sequence in which the event blocks are written in the program is not important. This event block allows you to set default values that can only be determined at runtime, for example. However, it is available for executable programs only.
It is called by the ABAP runtime system as soon as you have left the standard selection screen. It is also only available for executable programs.
In executable programs, there are further event blocks available for different tasks that are designed for creating lists. A complete list is available in the ABAP documentation: Event Blocks Lesson Summary You should now be able to: User Dialogs: User dialogs BC Lesson: Selection Screen Creating a Screen Screens and Data Transport Specifying the Next Screen Dynamically User interface Creating an Interface List Lesson: You will also create a detail list using an ABAP event.
Features of Lists The main purpose of a list is to display data for the minimum amount of programming. Lists also take the special requirements of business data into account: Texts and headers appear in the logon language whenever a translation is available. The following options are available to the user outputting a list: You can add colors and icons. The system automatically converts to HTML.
List Figure Standard List Functions The standard list interface offers the user several navigation features: Sends the list in e-mail form You can use the Menu Painter to adapt the default list interface to your own needs. User dialogs BC Figure List Headers in the Default Page Header Each list can have a list header and up to four lines of column headers.
There are two different ways to do this: From the list: Save the program, activate it, and then by generate the list by choosing Execute for the program. The main advantage of using this method is that the list is still displayed on the screen. This makes it easier to position column headers.
The next time you start the program, the new headers will appear in the list automatically. If there is no header text entered, the program title is inserted in the header.
You can translate all text elements into other languages. The logon language setting on the logon screen specifies the language in which text elements will be displayed. Text symbols are another kind of text element. Text symbols are text literals that can be translated and are assigned to the program.
They are frequently used to make lists independent of a specific language. You can write text symbols into your program in either of the following ways: Lists in Executable Programs In executable programs, lists are automatically displayed after their corresponding event blocks have been processed.
Event blocks are called in a sequence designed for list processing: All output from the event blocks that create the lists and from the modularization units processed before a list is sent, is temporarily stored in the list buffer. The ABAP runtime system ensures that the following take place: If you are using a default status, this happens automatically every time you choose an icon, the menu function Choose, or the function key F2.
Navigation in Detail Lists The lists in the example program should function as follows: Simple Detail List You program a detail list as follows: Example of a Detail List in an Application We will now write a program using both basic lists and detail lists: The basic list in your program should contain flight data, such as carrier ID and flight numbers, departure city and airport, destination city and airport, as well as departure and arrival times.
The user should be able to access information about any particular flight by double-clicking its carrier ID and flight number. Flight date and occupancy should be displayed. The following graphics demonstrate how this is done. A detail list, however, often needs data selected within the basic list itself. It would be good if you could store row-specifc data from the row you have selected and then automatically insert it in the corresponding data objects.
You can implement this using the HIDE area. You can predetermine which row-specific information should be stored when you are creating a basic list. The runtime system automatically records the name and contents of the data object in relation to its line position in the list currently being created. First the values for this line buffered in the HIDE area are inserted back into the corresponding global data objects. Then the system processes the relevant event block in the ABAP program.
The key fields of the airline will be displayed in the example program. Note that the line-specific information on the airline is only available by double-clicking in the data objects if the relevant data objects have been placed in the HIDE area when the basic list was created.
List Exercise Lists Exercise Objectives After completing this exercise, you will be able to: Once the user has selected a flight on the basic list dou- ble-click or F2 on the relevant row in the list , display a detail list containing all of the bookings for the selected flight. Prepare the detail list 1. Make sure that the key fields of the database table SFLIGHT are available to you for creating the detail list when the user selects a flight from the basic list double-click or F2 on the corresponding row in the list.
Create the detail list 1. In the first line of the detail list, display key information from the selected flight. Under this line, display a horizontal line and a blank line. Make sure that you only read fields from the database table that you want to display in the list. User dialogs BC 3. List Solution Lists Task 1: Result Model solution without optional exercises: WHEN 0.
Model solution with optional exercises: List SKIP. Selection Screen Lesson: Selection Screen Lesson Overview In this lesson, you will learn about the benefits of using the dialog form known as the selection screen. Purpose of Selection Screens Selection screens allow users to enter selection criteria required by the program for it to continue. For example, if you create a list containing data from a very large database table, you can use a selection screen to restrict the amount of that data that is selected.
At runtime, the user can select intervals for one of the key fields, and only data that corresponds to this selection is read from the database and displayed in the list.
This considerably reduces the load on the network. Selection Screen Figure Selection Screen Attributes Selection screens are input masks for value sets that restrict the amount of data read from the database.
The user has the following options: The system performs a type check: If you enter a value with an incorrect type, the system displays an error message and makes the field ready for new input. Entering Value Sets Selection screens allow you to define selection options for complex entries as well as simple input fields.
ABAP Dictionary Reading Multiple Database Tables Available Reuse Techniques Event Blocks Flow Chart Encapsulating Output in a Subroutine Calling the Subroutine Reference Parameters Subroutine with Interface Reference Parameters A Simple Detail List Detail lists Selection Screens Creating a Screen Screen Attributes The Attribute Window Displaying Data Example Program with Data Transport Defining Pushbuttons Functions in Screens Setting a Status before Displaying a Screen Key Settings Gain a detailed knowledge of the fundamental concepts of ABAP and learn how to comfortably and efficiently work with the ABAP Workbench tools in order to undertake custom developments with confidence.
Enhance your team's effectiveness and boost productivity with this course, delivered privately to your organization or to any preferred location or online.
Thank You! We have received your request and will contact you soon. For immediate assistance, please call First Name: Last Name: Company Name: