You are on page 1of 37

Programming ABAP Reports

Standard SAP Reports

Reporting Tool

- SAP Query

Retrieving Data

- Logical Database: global data retrieval programs. They provide database access, selection screen, and
perform authorization checks.

- Modularization Units

Reporting Tools (Query Tools)

Can be used to create reports (without to write ABAP programs).

Restricted to specific applications.

Available Tools (reporting solutions): purpose/advantages/limitations

1. SAP Query

2. InfoSet Query

3. Quick Viewer

- Custom development

SAP Business Warehouse (SAP BW)

A reporting system, into which data is extracted from one or mre transactional systems. Non ABAP
written queries are used to create reports withing SAP BW system using a variety of specific tools.

Logical Databases

Global data retrieval programs.

They provide a selection screen and perform authorization checks

If you choose custom development (of reports) as your solution, check if you can use a logical database
to retrieve the data you need.

Standard Reports
Purpose: Provides solutions for the most common reporting requirements

Advantages:

1. Immediately usable

2. No development effort

Limitations:

1. Limited flexibility

2. No flexibility with regard to the output fields

InfoSet Query

Purpose:

1. Easy to use general SAP reporting tool for creating your own reports

2. Allows the creation of evaluations for all areas of human resources

Advantages:

1. Simple user interfaces

2. Is easy to operate

3. No programming

4. Integrated with SAP Query - InfoSet

5. Queries can be edited in SAP Query if necessary

6. User access to InfoSet Query is integrated in roles

Limitations:

1. You first need to define InfoSets and user groups in SAP Query

2. Cannot display list entries with multiple rows

SAP Query

Purpose:

1. General SAP reporting tool for creating your own reports

2. Individual definition of user groups, InfoSets, and Queries

Advantages:

1. Flexible
2. No programming

3. Allows you to place queries in the SAP Easy Access menu

4. Provides extensive options to calculations, and graphics

5. Allows you to display list entries with multiple rows

6. Allows you to define a basic list and multiple statistics and ranked lists for each query

Limitations:

1. Restricted to data from the SAP system

2. Requires a higher training investment than other report creation tools

Your own ABAP programs (Reporting Solutions)

Purpose:

- Ultimate flexibility to implement customer requirements

Advantages:

1. Makes the entire scope of the ABAP language avaliable

2. Provides an easy-to-use development environment

Limitations:

1. Provides a solution with total freedom

2. Involves the risk of programming issues, such as poor runtime, incorrect data retrieval, or incorrect
data interpretation.

Output formats for displaying report results (implement customer-defined interactive functions):

ALV: an output format to display mass data as a table or tree. It provides a range of standard functions,
making it a better alternative to the classic list. You can choose from two programming models:

- The ALV Grid Control

- The ALV Object Model

Classic ABAP List: allows you to create lists with interactive functions. Does not meet accessibility
requirements.

Accessibility: the availability of information and the suitability of software for people with disabilities.
Include Programs:

Can be nested.

Naming convention:

- Top Include: <main_program_name>_TOP

- PBO modules: <main_program_name>_O01 (from 0 to 99)

- PAI modules: <main_program_name>_I01 (from 0 to 99)

- Subroutines: <main_program_name>_F01 (from 0 to 99)

- ABAP events: <main_program_name>_E01 (from 0 to 99)

List Generation

The first WRITE statement triggers list generation.

The output is sent to a list buffer.

The system generates the screen and displays the list.

The system generates two header lines (the standard header).

Additions to the WRITE statement:

- Formatting the output.

- Positioning the output.

Selection Screens

Speical screens, which are generated by the system based on ABAP statements.

Serve as an interface between the program and the user.

Use the decalrative statements PARAMETERS AND SELECT-OPTIONS to generate a standard selection
screen (screen 1000) with input fields.

Create additional selection screen using:

SELECTION-SCREEN BEGIN OF SCREEN.

Call a selection screen using: CALL SELECTION-SCREEN.

Create variants to save selection screen values that you use frequently. If a report with a selection
screen runs in the background, a variant is always required.
Additions to the PARAMETER statement

DEFAULT addition: set a default value

MEMORY ID addition: retrieve the current value from SAP Memory.

OBLIGATORY addition: declare mandatory fields, which users cannot proceed without entering values in
these fields.

LOWER CASE addition

AS CHECKBOX addition

VALUE CHECK addition

RADIOBUTTON GROUP addition

MODIF ID addition: assign the name of a modification group.

SAP Memory

A user-specific memory area in which simple data values are stored for SET/GET parameters.

The data values are stored for the duaration of a user session.

SET/GET parameters

Identified by a name, which can be maximum 20 characters long.

Can be assigned to a data element. Fields based on this data element can then use the SAP Memory
mechanism.

SELECT-OPTIONS

Declarative language element

Restricted to eight characters

Allows the use of a value range and complex selections instead of single input field.

Generate an internal table (the selection table) with a stadnard structure and a header line.

- Sign (Includes: I or Exludes: E)

- Option (EQ, NE, LE, LT, GE, GT, BT, NB,CP, NP)

- Low
- High

The system automatically fills the internal table if a user enters data.

FOR addition is used to specify the type of the field.

The selection set

If no values are entered into the SELECT-OPTION, the system returns all rows from the database.

Additions to SELECT-OPTIONS (other than PARAMETERS additions):

- NO-EXTENSION

- NO INTERVALS

NODES statement

INTIALIZATION Event Block

Only processed once, before the selection screen is displayed for the first time

Appropriate for a dynamic preassignment of the input fields. You can assign default values for the
selection screen fields of a report or a logical database during this event.

AT SELECTION-SCREEN OUTPUT Event Block

Occurs before the selection screen is displayed.

You can provide values for the selection screen in this event. However, this event may be processed
multiple times.

SELECTION-SCREEN

Design the structure of the selection screen.

BEGIN OF BLOCK addition: group logically related screen elements and WITH FRAME to frame them. You
can nest frames up to five levels.

BEGIN OF LINE addition: display multiple parameters and comments in the same output line.

The COMMENT addition: inclue text in the line. Comment texts must always have a format (position and
output length).

SKIP addition: define empty lines.


BIBS Trasnaction: Screen Design

Additional Selection Screens:

The standard selection screen always has the number 1000. Additional selection screens should have a
number higher than 1000.

Define other selection screen sing SELECTION-SCREEN BEGIN OF SCREEN.

Use CALL SELECTION-SCREEN to call the selection screen.

If the user performs any action on the called selection screen, the AT SELECTION-SCREEN event is
processed. In this event, the sy-dynnr system field contains the number of the called selection screen.

To call selection screens as a modal dialog box:

CALL SELECTION-SCREEN <nnn> STARTING AT <left_col> <upper_row> ENDING AT <right_col>


<lower_row>

- <left_col> and <upper_row> are the coordinates of the top-left corner of the screen

- <right_col> and <lower_row> are the coordinates of the bottom-right corner.

Tabstrips:

Define selection screens as subscreens, and then include them on other screens as tabs.

The definiton of a selection screen as a subscreen using the AS SUBSCREEN addition

The definition of a subscreen area for a tabstrip on a selection screen begins with: SELECTION-SCREEN
BEGIN OF TABBED BLOCK

Define a single tab as SELECTION-SCREEN TAB

A structure is automatically created for every tabstrip block, which has the same name as the tabstrip
block. It contains the prog, dynnr, and activetab fileds.

AT SELECTION-SCREEN event

AT SELECTION-SCREEN OUTPUT event

AT SELECTION-SCREEN Event Block

Evaluation of the user's selection screen.

The ON addition: refer to specific selections. If an error occurs, only these fields become ready for input
again (ON <f>, ON <seltab>, ON RADIOBUTTON GROUP <grp>, ON BLOCK <block>).
F1 help (field help): AT SELECTION-SCREEN ON HELP-REQUEST FOR

F4 help (input help): AT SELECTION-SCREEN ON VALUE-REQUEST FOR

Variants:

Variants are uniquely assigned to one program, and are not available in other programs. A user can
create any number of selection screen variants for a program.

If the program uses several selection screens, a variant can be created for all selection screens, or
individually for each selection screen.

Creating variants is useful when you:

- Frequently start a program with the same selections

- Run the program in the background.

The naming convention for variants:

- SAP&xxx are supplied with the SAP system.

- CUS&xxx are created by the customer.

The Variant Catalog

Scope of varaint attributes

Buttons on a Selection Screen

SELECTION-SCREEN PUSHBUTTON statement

By default, the button is not positioned in a new line.

You need to specify a name and a user command for the button.

You need to maintain the text that is to appear on the button separately during INITIALIZATION.

You can also use the ICON_CREATE function module to generate a text and an icon.

If the user chooses the button, the system triggers the user command assigned to it and places the user
command in the sscrfields-ucomm field at the begining of the AT SELECTION-SCREEN event. You need to
include the TABLES sscrfields statement in your program to be able to access this field.

For standard screen programming, the process logic can be implemented at the following event for each
screen:

Process Before Output (PBO): Immediately before the screen is displayed. For selection screens is
equivalent to AT SELECTION-SCREEN OUTPUT
Process After Input (PAI): Immediately after the screen has been displayed. For selection screens is
equivalent to AT SELECTION-SCREEN.

SCREEN System Table

Each field of the selection screen has an entry in the table.

You can change the contents of this table at runtime.

You control the fields using the name of the field or the group name.

To hide selection fields: assign the value 0 to the SCREEN-ACTIVE attribute.

To change whether a field is ready for input: assign 0 or 1 to the SCREEN-INPUT field.

Dynamic Changes to Selection Screen Fields

You can address these screen fields in LOOP AT SCREEN....ENDLOOP using their names.

Must be performed in the AT SELECTION- SCREEN OUTPUT event block.

To ensure that you do not need to address each field individually, you can combine selections into
modification groups.

ALV

The ALV Object Model (ALV OM)

Layout of ALV Container:

- Toolbar

- List Header

- Data Area

Lead and non-lead columns

Selecting cells, rows, and columns

Line selection column

Sorting column (small red triangle)

Summed column (sigma sign)

Standard functions in application toolbar


Services of the Runtime System: the application program communicates with the screen at runtime
using these services:

ABAP processor

DYNPRO (screen) processor

SAP GUI Services: manage windows and their dialog box levels, data transfer, and so on.

Controls:

Additional screen elements other than provided in the Screen Painter.

Standalone binary software components that are reusable.

You can integrate on or more controls into your user dialogs and use the functions they make available.

An area is reserved on the screen to display a control. A container control is placed in this area. The ALV
Grid is then linked to the container and is displayed in the reserved screen area (Control Area ⬅️
Container Control ⬅️SAP Control).

Screen Flow Logic

You cannot program ABAP directly in the flow logic. Instead, you encapsulate ABAP commands in
modules.

Modules called during PBO are defined by the MODULE <module_name> OUTPUT statement.

Modules called during PAI are defined using the MODULE <module_name> INPUT statement.

GUI Status

Made of:

- Menu bar

- Standard toolbar

- Application toolbar

- Function key settings

SET PF-STATUS statement: define status name.

Status types:

- Normal screen
- Dialog box

- Context menu

As a minimum, the Back, Cancel, and Exit functions should be activated.

GUI Title

LEAVE TO SCREEN 0 command: return to the point where the screen was called.

LEAVE PROGRAM command: leave the program.

Data retrieval: is in the START-OF-SELECTION event block.

Global Classes: created with the Class Builder

Creating Instances

CREAT OBJECT statement: create an instance of the class for which the object reference variable has
been assigned a type.

CONSTRUCTOR method of a class:

- If a class has a method with the name CONSTRUCTOR, it is automatically executed when the instance
is created.

- Can only have IMPORTING parameters and EXCEPTIONS as a signature.

CL_GUI_CUSTOM_CONTAINER

Container control class

IMPORTING parameter container_name of the CONSTRUCTOR method: transfer the name of the area
reserved for the control on the screen.

Avoidance of multiple generation of contrrols: ensure that an instance is generated only the first time
the dynpro is called. You can stop unwanted instances from being created by checking that the
container reference is initial, before creating the object.

ALV Grid
Creating an instance of the ALV Grid after the container control instance is created and before the SAP
GUI windows is sent to the presentation server.

An ALV Grid instance: reference to class CL_GUI_ALV_GRID

- IMPORTING parameter i_parent_parameter of the CONSTRUCTOR method: assigning a reference to


the previously created container control instance. To display the ALV Grid in full screen mode, assign the
value cl_gui_custom_container=>screen0 (0 for pop-up level) to this parameter.

- SET_TABLE_FOR_FIRST_DISPLAY method: used to pass the list data, field catalog, and other
additional information.

- it_outtab parameter (obligatory): used to pass the list data that you want to display.

- i_structure _name parameter: used to pass the name of a global structure type from the ABAP
Dictionary. The representative instance automatically generates the corresponding field catalog.

- is_variants and i_save parameters: set the configuration options of the layout variants for the user.

- i_default parameter: set an existing layout variant as the initial variant. When saving a layout
variant, you can define it as the default variant if this parameter has the value X (the default value).

- is_layout and is_print parameters: pass default settings for the appearance of the ALV and print list
output

- it_special_groups parameter: pass the names of field groups defined in the field catalog.

- it_toolbar_excluding parameter: pass the names of the standard functions of the toolbar that are to
be hidden (deactivated).

- it_fieldcatalog parameter: pass a corresponding internal table to change the automatically created
field catalog or create it yourself.

- it_filter and it_sort parameters: pass default settings for filtering and sorting the data to be
displayed.

- REFRESH_TABLE_DISPLAY method: prompt the representative instance to send the list data and the
additional information to the instance on the presentation server again.

- i_soft_refresh parameter: specify if the current filter and sort criteria are kept and applied (assign
the value " ") or the current filter and sort criteria are kept but not applied (assign the value X).

- is_stable parameter: pass the corresponding filled structure to specify the condition that scroll
positions for rows or columns are retained when refreshing (row and col fields of a structure of the
lvc_s_stbl).

- SET_USER_COMMAND method: allow you to replace the standard functions of the ALV grid control
with your functions.

- GET_CURRENT_CELL method: returns the coordinates of and value of the current cell (current
position).
- GET_SELECTED_CELLS method: returns the coordinates of and values of the selected cells.

- GET_SELECTED_COLUMNS method: returns the name of the selected columns.

- GET_SELECTED_ROWS method: returns the row numbers of the selected rows.

- GET_SUBTOTALS method: get current subtotals of the ALV Grid Control

- SET_TOOLBAR_INTERACTIVE method: triggers the TOOLBAR event

Releasing of Instances

FREE <object_name> instance method: explicitly release the resources. Every control wrapper has this
free method (inherited from CL_GUI_OBJECT).

CLEAR and FREE statements: releasing the object references, ensuring that the resources for ABAP
objects instance created in the program are released in memory the next time the garbage collector
runs.

AT LINE-SELECTION Event Block

Triggered if a user double-clicks a line in a classic list.

Creating a Simple ALV Grid Control in a Dialog Box

Representative Instance of the CL_GUI_ALV_GRID class

Additional Information

Global data objects defined in the calling program that can be filled with additional information and
then passed to the representative instance.

Layout Info:

- Data area (display) => LVC_S_LAYO

- Standard Functions => UI_FUNCTIONS

- Print list => LVC_S_PRNT

Data Info:

- Sort => LVC_T_SORT

- Filter => LVC_T_FILT


- Field groups => LVC_T_SGRP

Normally, you do not create the filter and sort criteria in the program, because the user can change the
criteria interactively.

Options for Variant Management:

Using the is_variant and i_save parameters of SET_TABLE_FOR_FIRST_DISPLAY method.

Modes of layout variant:

- Change (default)

is_variant = space

i_save = space

- Change and select existing

is_variant = <st_name: structure of type disvariant>

i_save = space

- Change, save, and select existing

is_variant = <st_name>

i_save = 'U', 'X', or 'A'

You can transport only the standard layout variants.

To create or change standard layouts or to set them as the default setting, users require an
authorization for the authorization object S_ALV_LAYO with ACTVT value 23.]

Rules of namespaces of the variants:

- Global variants (standard variants) of the customer strart with a /.

- Global varaints of SAP start with a digit.

- User-specific varaints start with a letter.

disvariant structure

<disvariant>-report: name of the report

<disvariant>-variant: the name of the layout variant

Changing the Layout of the ALV Grid


Selecting title

Creating a striped (zebra) pattern for the lines

Optimize column width

Steps:

1. Create a structure with the type LVC_S_LAYO

2. Fill in the relevant fields of the structure

3. Pass the structure to the is_layout parameter of the SET_TABLE_FOR_FIRST_DISPLAY method.

Fields of the layout structure:

- grid_title

- zebra

- cwidth_opt

- sel_mode

- excp_fname

- excp_led

Sort Criteria

Fill an internal table of LVC_T_SORT type

- You can insert the fields in the required sequence in the internal table of sort criteria.

- To sort data using sort criteria, enter the column name in the fieldname field.

- Enter X in the up field if you wish to sort the entries in ascending order.

- If you want to sort the entries in descending order, enter X in the down field.

Pass the internal table to the it_sort parameter of the SET_TABLE_FOR_FIRST_DISPLAY method.

Line Colors

Steps:

1. Add an extra field to your data table that contains a code representing the color of the line. This is a
character field with length 4.

2. Add the field at the end of the line type of your internal table.
3. In the info_fname field, enter the component name of your color column for a strucutre of the
LVC_S_LAYO global type.

4. Pass the strucutr to the is_layout parameter of the SET_TABLE_FOR_FIRST_DISPLAY method.

Components of the color field value:

- Letter 'C'

- Number of one of the eight colors (color constants)

- intensified display: 1 or 0

- Invers: 1 or 0

Changing of the Cell Colors

A cell color has a higher priority that a row color.

Steps:

1. Add an internal table of LVC_T_SCOL type to the line type of the output data table.

2. Fill the fileds fname (name of the field to be colored) and color (structure made of the col, int, and
inv components) of the internal table.

3. Loop through the internal table and write the work area back into the internal data table using the
MODIFY command.

4. Assign the name of the field color table to the field ctab_name of the layout structure.

INCLUDE TYPE statement: used to include Dictionary types, ABAP types, and self-defined types, directly.

INCLUDE STRUCTURE statement: still supported for compitability reasons.

FORMAT Command

Function Codes

The possible function codes are defined as constants of the CL_GUI_ALV_GRID class.

- MC_FC prefix constant (The constants for function codes have this constant)

- MC_MB prefix constant (represents an entire menu in the toolbar)

- MC_FC_EXCL_ALL constant (deactivate all functions on the application toolbar)

- MC_FC_PRINT_BACK
- MC_FC_DETAIL

- FC_MB_SUM

Hiding of Standard Functions

You can display only a subset of the standard functions or hide the entire toolbar.

To hide individual functions, define an internal table with the ui_function line type. Fill the internal table
with the name of the functions that you need to keep inactive (not displayed).

To hide the entire toolbar, set the no_toolbar parameter of the layout structure to X.

Field Catalog

A format description of the display area for data.

Rules concerning how the data should be displayed.

You can pass the display information to the representative instance using an additional internal table.
This additional table is called the field catalog. The global data type of this internal table is LVC_T_FCAT.
The corresponding structure type (for the work area) is called LVC_S_FCAT.

The field catalog must contain a row for every column of the data table that differs from an underlying
ABAP Dictionary structure or a row for every column that is not in the ABAP Dictionary structure at all.
This row must contain the technical properties and other formatting information for the column.

Situations when a field catalog is required include the following:

- All fields of a global structure exist in the data table with the same names, however, adjustments are
to be made to the specifications from the ABAP Dictionary, additional columns are to be output, or both.
In this case, create rows in the field catalog for the columns to be changed or added.

- The row type of the data table does not contain any reference to the ABAP Dictionary, individual
global structure fields, or data elements. In this case, you need to create the field catalog completely in
the calling program.

There is a situation when a field catalog may not be required; when all fields of a global structure type
exist in the data table with the same names. These fields should also be the output. In this case, you can
have the field catalog generated automatically by the representative instance. You only need to pass the
name of the global structure type to the parameter i_structure_name of method
SET_TABLE_FOR_FIRST_DISPLAY. Columns of the data table that are defined in the global structure type
are displayed.

Every column of the data table that you want to format must have a corresponding row in the field
catalog.

To create a field catalog in the calling program:


- Define an internal table for the field catalog based on the LVC_T_FCAT global table type and a
compatible structure as the work area (LVC_S_FCAT structure type).

- Assign the name of a column from the data table to the fieldname field. This field assigns a row in the
field catalog to a column of the data table.

- Fill the fields of the work area for each affected column of your data table and add it to the internal
table for the field catalog.

Performing a consistency check: press the SHIFT key and double-click with the right mouse button in an
area of the ALV grid that contains no data

Semi-automatic field description

Control Framework (CFW)

Used for the communication for all control in the same way.

Uses special services in the SAP GUI and the runtime system on the application server. These services
are the automation controller on the presentation server and the CFW service on the application server.

GUI Controls

Every GUI control that communicates with an application program represents an object, which is an
instance of a class, on the presentation server. The communication with the instances uses the method
calls and events of the objects.

There are representative classes (proxy classes) for all GUI controls in the class library. These are
referred to as control wrappers.

Use of a GUI control in an ABAP program involves the following objects:

- Instance in the ABAP program

- Instance of the control at the presentation server

The communication between the ABAP program and a GUI control is performed as follows:

- The ABAP program communicates with the representative object only (method calls, operations on
the attributes). The representative object performs the associated operations on the presentation server
instances using the CFW.

- Actions performed on the presentation server control are forwarded to the representative object,
using the CFW. The representative object then communicates with the ABAP program.

To pass an event to a presentation server control, the following partner levels are involved:
- SAP GUI/Automation Controller: receives the event triggered by the presentation server control and
forwards the information about the event to the basis services

- Basis Services: forward the information to the representative object in the ABAP program.

- Representative Object: triggers an ABAP Objects event, informing the instances registered for the
event. These instances then handle the event with an appropriate method also known as a handler
method.

Processing of ABAP Objects Event

An Object

- Change of its state.

- Does not know the event handler.

- Can trigger identified events (provided by the associated class for representative objects of the
control).

Basis Services

- Register handler methods.

- Ensure the registered methods are executed.

Hander Methods (exectued)

ALV Grid Events:

The ALV grid control has more than 25 events.

The Most Important Events of the ALV Grid:

- DOUBLE_CLICK: triggered after a double-click with the mouse. If a column has been identified as a
hotspot, and the user presses the mouse button in the hotspot column of the data area, the
HOTSPOT_CLICK event is triggered in the calling program.

- PRINT_TOP_OF_LIST, PRINT_TOP_OF_PAGE, PRINT_END_OF_PAGE, PRINT_END_OF_LIST: triggered


at various points during output of the print list.

- TOOLBAR: triggered when the ALV grid control is created (during the SET_TABLE_FOR_FIRST_DISPLAY
method) or refreshed (during the REFRESH_TABLE_DISPLAY method), but can also be triggered explicitly
with the SET_TOOLAR_INTERACTIVE method. It allows you to change the composition of the toolbar.

- USER_COMMAND: triggered when user-defined function codes are chosen.

Every event has an implicit parameter, called sender, which you can also receive by listing it in the
IMPORTING addition. This parameter allows handlers of instance events to access the instance that
triggered the event.
Handler Methods

A handler method can be a static method or an instance method of an object.

To create a handler method for an event, first define a local class. The local class requires a public
method that is defined as a handler method for a particular event of a certain class.

The names of event handler methods should be structured as on_<event_name>.

The signature of an event handler method can only contain IMPORTING parameters. These parameters
are defined within the corresponding event.

The event handler method does not need to import all the parameters passed in the RAISE EVENT
statement.

The syntax for defining a handler method:

on_<event_name> FOR EVENT <event_name> OF <class_name>

IMPORTING <parameters>

Syntax of registering the handler method:

SET HANDLER <local_class_name>=><handler_method_name> FOR <object_name>

=> for static methods

-> for instance methods

The SET HANDLER statement links handler methods with the event triggers.

By default, an event hanlder is not processed when an event occurs. The event hanlder is only called if
you register the event at runtime.

Simple Syntax for Selecting Set of Columns of a Database Table and Storing the Results into
Corresponding Fields:

SELECT SINGLE <column1> <column2> <column3>

FROM <table_name>

INTO (variable1, variable2, variable3).

The TOOLBAR Event

The toolbar event has a pointer to an instance of the class CL_ALV_EVENT_TOOLBAR_SET as an


exporting parameter.
The instance of a toolbar contains the public attribute an internal table mt_toolbar. You fill this internal
table in the handler method to add further buttons or other elements.

The line type of mt_toolbar internal table is STB_BUTTON

If the user chooses an element of the menu button or menu type, the representative instance triggers
the MENU_BUTTON event. This has a parameter E_OBJECT with type REF TO CL_CTMENU. To add a
menu to the toolbar, you must also implement a handler method in which you create the menu in the
same way as a context menu.

If the user chooses a function element that has been added to the standard toolbar, the representative
instance triggers the USER_COMMAND event. This event contains the function code as its E_UCOMM
export parameter.

Display a Field in the ALV Grid as Button:

Define an internal table with type LVC_T_STYL

For each field to be displayed as button, create an entry in the internal table, in which you assign the
name of the field to the fieldname component and the constant
CL_GUI_ALV_GIRD=>MC_STYLE_BUTTON to the style component.

The name of the internal table that contains the information about the buttons is specified in the
stylefname component of the layout strucuture.

BUTTON_CLICK Event

Triggered when a user chooses a button in a cell.

The event returns the number of the row and name of the column in which the button was clicked.

Print List Events

By using print list events you can implement the same logical process steps as used in the classic ABAP
list layout.

You can use the SUBTOTAL_TEXT event to define additional texts for subtotals across columns whose
output has been suppressed.

You must set an indicator in the print structure to ensure that the user can format the control level
change in the print list. This print structure is controlled by the GRPCHGEDIT field of the IS_PRINT
transfer parameter, which is the LVC_S_PRNT structure type.

Replacing the Standard Function


BEFORE_USER_COMMAND Event: triggered before a user command (standard command or custom
command) is processed.

Define a handler method (ON_BEFORE_USER_COMMAND) and check the function code.

Context Menus

A context menu is displayed if a user presses the right mouse button (or Shift + F10) and the mouse
pointer is positioned over a GUI control.

When a user presses the right mouse button, the ALV grid control triggers the
CONTEXT_MENU_REQUEST event.

If the user selects a function from the context menu, the ALV grid control triggers the USER_COMMAND
event.

By default, the ALV grid control has a context menu that you can replace or extend.

Creating a context menu in the object list of the Object Navigator:

- Create a new GUI status with type context menu.

- Enter the required function codes and their texts in the Menu Painter.

- To create a submenu, enter text but no code for a line in the Menu Painter (maximum of three
levels).

- To load the GUI status into the context menu, use the static method LOAD_GUI_STATUS (parameters:
program, status, disable, menu) of class CL_CTMENU.

- You can extend the context menu that you loaded, using the ADD_FUNCTION method of the
CL_CTMENU class.

-----------------

Retrieving Data

-----------------

Logical Databases

A logical database is an ABAP program that reads data from the database and passes it to other
programs.

The use of a logical database provides an alternative to programming your own database access.

Logical databases also provide a security advantage because they perform all the authorization checks in
the logical database program instead of in the report.
There are more than 250 logical databases in SAP ERP systems.

Most logical databases names consist of three characters.

Using a logical database:

- Enter the name of the logical database in the program attributes.

- Use the NODES <nodes> statement (recommended more than TABLES keyword) to specify the nodes
of the logical database that you want to use, it creates a structure corresponding to the node type.

- When the logical database reads the data records, it uses the PUT <node> keywod that triggers the
GET <node> event in the report program.

Nodes

Node names can contain up to 14 characters.

The structure determines the hierarchy and the read sequence of the data records (the sequence in
which the GET events are processed).

Nodes types:

1. Table (T type): table or strucutre from the ABAP Dictionary. Name must be identical to the node
name.

2. ABAP Dictionary (DDIC) (S type): table or structure. Name can be different from the node name;
deep structures are possible.

3. Complex types from Type Groups (C type): type that has been defined in a type group.

4. Dynamic nodes (A type): type is specified in program.

Logical Database Events

START-OF-SELECTION: triggered when an executable program is run before control is transferred to the
read routine of the logical database.

END-OF-SELECTION: triggered after all GET events are processed (after all data records are read and
processed).

GET <node>: triggered when the logical database supplies data for this node. Each GET event block can
be processed several times, depending on how many records are supplied by the logical database.

GET <node> LATE: triggered when all subordinate nodes of the current node have been processed,
before the data is read for the next node (when a hierarchy level is completed).

Termination Keywords Used in a GET Event Block:


CHECK keyword: If the specified condition is false, the current processing block is terminated.

STOP keyword: terminates the program processing. The END-OF-SELECTION processing block is
executed first, if it exists.

EXIT statement: exits the program immediately, without executing the END-OF-SELECTION event. The
list that has been generated so far is displayed.

REJECT statement: this data record is not processed further. When reading the next data record,
processing continues at the same hierarchy level.

Logical Database Selection Screens:

Logical database programs have the DB<name>SEL include program, in which the selection screen of the
logical database is defined.

The FOR NODE addition (to PARAMETERS and SELECT-OPTIONS statements): assigns selections to
individual nodes.

If the SELECTION-SCREEN FIELD SELECTION FOR TABLE <node> statement: field selection is possible for
these nodes. This means that the application program can use the GET <node> FIELD <field list>
statement to restrict the amount of data retrieved.

Some logical databases provide dynamic selections for certain nodes using the DYNAMIC SELECTIONS
FOR <node> addition. If this is the case, the Dynamic Selections button appears on the selection screen
of your report to restrict the data retrieval further. You can determine the selection fields to be
displayed by using a Selection View.

Some large logical databases have multiple selection screen versions. You specify the selection screen
that you need to display by entering the version number of the selection screen in the program
attributes.

Selection Views

Determines which fields are displayed on the selection screen for nodes with dynamic selections.

Provided by SAP (of type SAP), or can be defined by the customer (type CUS).

Defining a selection view:

- Define field groups.

- Assign the individual fields of a node to a field group by assigning the number of the relevant field
group to the field. You can also define whether these fields need to be immediately available when the
users want to work with dynamic selections.

Logical database programs


Logical database programs are named SAPDB <ldbname>, where <ldbname>is the name of the logical
database.

Consist of subroutines. Each subroutine is executed at a particular event.

There are other subroutines that are processed at the Process Before Output (PBO) and Process After
Input (PAI) events of the selection screen. Checks are performed during the PAI event.

The database accesses are programmed in the put_<node> subroutines. This subroutines can be
processed several times.

The interaction between a logical database and a program occurs as follows:

When a program which uses a logical database is started, control is initially passed to the database
program of the logical database. Each event has a corresponding subroutine in the database program,
for example, init subroutine in a logical database for the INITIALIZATION event.

During the interaction between the logical database and the associated report, first the subroutine is
processed and then the corresponding event block in the report (if it has been coded).

Logical database programs read data from the database according to the structure declared in the
logical database.

The logical database reads the data in the put_<node> subroutines. During the PUT event, control is
passed from the database program to the GET event of the associated report.

Data is made available in the corresponding work areas in the report. The processing block defined for
the GET event is executed.

Control then returns to the logical database. The next relevant subroutine will then be processed.

Data that is to be output in a list or ALV can be read from the database using:

Open SQL: a platform-independent SQL variant used in ABAP. Open SQL statements are translated into
the relevant Native SQL by the database interface.

Native SQL statements: for portability reasons, it is best to avoid Native SQL restrictions or
requirements.

Open SQL

Open SQL is not database-specific and ensures that your program is independent of the database
engine.
Open SQL allows portability between different RDBMS systems and allows your the change to a different
database system, without the need to change the code.

ABAP Open SQL is completely integrated into the ABAP Workbench, which has integrated syntax checks
for Open SQL syntax.

ABAP Open SQL also makes it possible to use the SAP table buffers, where buffering has been activated
for a particular table.

Native SQL

The syntax for native SQL statements:

EXEC SQL [PEFORMING <form>]

<Native SQL statements>

ENDEXEC.

Native SQL must not be used to change data in the SAP database.

If you need to use Native SQL, put the code in an INCLUDE so that it can be modified easily if your
RDBMS changes and restrict your Native SQL to Standard SQL.

The General Rules to Ensure Optimal Database Performance:

Keep results sets samll.

Keep data transfer between the database server and the application server to a minimum.

Reduce the number of database queries.

Reduce search area.

Minimize unnecessary database server load.

Reading Data from Multiple Database Table

Views

Inner Join

Outer Join

FOR ALL ENTRIES

Nested SELECT statements


Joins

Join conditions are not limited to key fields. They can be declared using any fields for which a foreign key
relationship is defined, or in certain cases, between fields that have the same domain.

Use a LEFT OUTER JOIN statement when data from the table on the left is needed even if there are no
corresponding entries in the table on the right.

FOR ALL ENTRIES

Initially, data is fetched from the first database table and collected in an internal table. You must then
evaluate the value of SY-SUBRC, to check whether the initial SELECT returned any data. If data was
retrieved, the SELECT...FOR ALL ENTRIES can then be used to retrieve data from a second database
table, based on the entries in the first internal table.

It is recommended that you use the FOR ALL ENTRIES addition when the first set of data is not being
read from the database and is already available in the program, for example, if the user has input the
data. Otherwise, a join is recommended.

DELETE ADJACENT DUPLICATES: remove duplicate entries from the internal table.

DESCRIBE TABLE <internal_table> <property_name> <variable_name> statement: this statement


captures several properties of a field and assigns them to the specified variables.

SELECT statement

SELECT <fields>

FROM <source>

INTO <target>

[WHERE <condition>]

[GROUP BY <fields>]

[HAVING <grouping_condition>]

[ORDER BY <sort_key>]

Aggregate Functions

MAX: returns the maximum value of the column

MIN: returns the minimum value of the column


AVG: returns the average value of the column

SUM: returns the sum of the column

COUNT: counts values or rows as follows:

COUNT (DISTINCT s ): returns the number of different values in column s.

COUNT( * ): returns the total number of rows in the resulting set.

DISTINCT addition: prevents values from occurring more than once in the result set.

GROUP BY

Combines rows that have the same value combinations for the columns specified, into a single row in
the result set.

Columns with the STRING and RAWSTRING data types cannot be used in the GROUP BY clause.

You cannot use the GROUP BY clause when selecting from a pool or cluster table.

Data types of the returned value from aggregate functions (ensure the target variable has an
appropriate type):

- MAX, MIN, and SUM: the data type of the corresponding colun in the ABAP Dictionary.

- AVG: type F (floating point).

- COUNT: type I (4-type integer).

When any aggregate expression is used, the GROUP BY clause must include all other columns that are
selected, except for those in the aggregate expression.

HAVING Addition

Restricts the number of groups of combined results in the result set by using a logical expression for
these rows.

May only contain columns that also occur in the GROUP BY clause.

The condition of HAVING clause may contain aggregate functions for any columns of the database table
listed in the column list after SELECT.

ORDER BY

Sorts the result set on the basis of the contents of the entered columns.
For all columns not listed after ORDER BY, the order in the result set is undefined, and can be different if
the same SELECT statement is executed more than once.

ORDER BY PRIMARY KEY addition: the result set can be sorted by primary key in ascending order.

The result set can be sorted by any combination of selected columns. The column can be entered
direclty using the column indicators or using the alternative column name. The alternative column
names are necessary, if you want to sort by columns that are specified as aggregate expressions.

The system sorts in ascending order as default, if niether of ASCENDING and DESCENDING additions is
specified.

The priority of of the sorting follows the order in which the columns are specified.

The SELECT statement baypasss the SAP buffer in all cases except for ORDER BY PRIMARY KEY.

For performance reasons, only perform a sort in the database system if the sorting is supported by an
index.

---------------------------------------------------

The Call of Other Programs from ABAP Reports

---------------------------------------------------

You can call an ABAP program from another running ABAP program in the following ways:

Interrupt the current program to run the new program: The called program is executed, and processing
then returns to the calling program.

End the current program and start the new program.

Synchronous Calling

Complete ABAP programs in a single user session can only run sequentially.

CALL FUNCTION <function_name> STARTING NEW TASK <task_name>

SUBMIT Statement

VIA SELECTION-SCREEN addition: the system displays the standard selection screen of the program (if
one has been defined).

AND RETURN addition: the system resumes processing at the first statement after the SUBMIT
statement, as soon as the called program is complete.

WITH addition: assign values to a field on a standard selection screen.


LEAVE TO TRANSACTION <trasnaction_code> statement: the system terminates the current program
and starts the transaction. The statement has the same effect as entering /n<t_code> in the command
field.

CALL TRANSACTION <transaction_code>

Allows you to insert an ABAP program with a transaction code into the call chain.

USING <gt_bdcdata> addition: execute the transaction using values from the internal table in the screen
fields. The internal table must have line type BDCDATA and it must be filled in the program before the
CALL TRANSACTION statement.

MODE addition: specify the frequency of displaying the screen contents:

- Always (A - default setting)

- If an error occurs (E)

- Never displayed (N)

MESSAGES INTO <gt_messages> addition: specify an internal table in which all system messages are
written. The internal table must have line type BDCMSGCOLL.

LEAVE PROGRAM statement: terminates an ABAP program. If the statement occurs in a program that
you called using CALL TRANSACTION or SUBMIT <program_name> AND RETURN, the system resumes
processing at the next statement after the call in the calling program.

AND SKIP FIRST SCREEN addtion to the CALL TRANSACTION statement or LEAVE TO TRANSACTION
statement: prevent the system from displaying the contents of the first transaction screen. The system
still processes the flow logic.

UPDATE addition: specify the update technique that the program should use, if you start a transaction
with CALL TRANSACTION that uses update techniques. This technique can be asynchronous (default),
synchronous, or local.

Calling of Other Programs: Memory Management

The external sessions have the following characteristics:

- An external session is an SAP GUI window.

- External sessions are divided into internal sessions.


Each program that you start runs in an internal session. Data for the program is only visible in an internal
session.

CALL TRANSACTION <t_code> or SUBMIT <program> AND RETURN opens a new internal session that
creates a new program context. The internal sessions of an external session create a memory stack. The
new session is placed at the top of the stack.

At the end of the execution of a program, the internal session that is at the top of the stack is removed,
and the system continues processing the calling program (same for explicit LEAVE PROGRAM
statement).

LEAVE TO TRANSACTION removes all internal sessions from the stack, and opens a new internal session
that contains the program context of the calling program. After the program call, the ABAP memory is
reset. All the data in the ABAP memory is removed after the call.

SUBMIT <program> replaces the internal session of the program. This program performs the call with
the internal session of the program that the system calls. This action is according to the program code
written by the programmer. The new internal session contains the program context of the called
program.

The function group needs to be loaded in every internal session used. If a new internal session calls a
function, the called function group needs to be loaded in the new internal session

Ways to pass data to programs that run in separate internal sessions, which are as follows:

Interface of the called program (a standard selection screen)

ABAP memory

SAP memory

Shared memory/shared buffer

Database tables

Local files on your presentation server

GUI_UPLOAD Function Module

GUI_DOWNLOAD Function Module

CL_GUI_FRONTEND_SERVICES

Passing of Data Using the Program Interface


Function modules have an interface that the calling program and function module use to exchange data.
Subroutines use a similar technique. There are restrictions when using the interface of a remote-enabled
function module.

If you call an ABAP program with a standard selection screen, you can pass data for the input fields in
the call:

- Specify a variant for the selection screen in the program call.

- Specify values for the input fields in the program call.

To pass multiple selections to a selection option:

Create an internal table with the columns SIGN, OPTION, LOW, and HIGH using: DATA <data_object>
TYPE | LIKE RANGE OF.

Fill the table with the multiple selections and pass it to the executable program using the WITH
<sel_opt> IN <data_object> statement.

SAP Memory

A user-specific memory area for storing field values that relate to parameter IDs.

It is only suitable for passing data between internal sessions to a limited extent.

Values in SAP memory are retained for the duration of a user session.

The SAP memory can be used between different sessions of the same user session.

You can use the contents of the SAP memory as default values for screen fields

All external sessions can work with the SAP memory.

Defining memory areas or parameters in the SAP Memory:

- Add the MEMORY ID <par_id> option to the statements PARAMETERS or SELECT-OPTIONS.

- Create input/output fields with reference to the ABAP Dictionary.

- Directly fill the memory area using the SET PARAMETER ID '<par_id>' FIELD <var> statement and read
from the memory using the GET PARAMETER ID '<par_id>' FIELD <var> statement.

ABAP Memory

User-specific.

There is local ABAP memory for each external session.


You can use the local ABAP memory to exchange any ABAP variable between the internal sessions of an
external session.

The system cannot share the ABAP memory with other external sessions.

If the user ends an external session, the associated ABAP memory is automatically released.

EXPORT Statement

EXPORT <parameters_list> TO MEMORY ID <id>

Create a data cluster in ABAP memory.

The data cluster stores ABAP variables with their current values in ABAP memory.

The ID <id> addition enables you to identify different data clusters.

Another EXPORT… TO MEMORY statement for the same data cluster overwrites the old cluster.

IMPORT Statement

IMPORT <parameters_list> FROM MEMORY ID <id>:

Copy data from the ABAP memory to the corresponding fields of your ABAP program.

FREE MEMORY ID <id>: release a data cluster.

---------------------------

Backgrounds Processing

---------------------------

Backgrounds Processing

Background execution takes place without user dialogs in special background work processes. This
allows parallel processing and ensures that dialog work processes remain free for foreground
processing.

Some reasons to run a report in the background:

1. When a program processes large datasets, the program may have a long runtime.

2. Running a report in the background allows evaluations to be run periodically.

3. Some evaluations must be carried out based on events.


BTCH & BTC2: function groups (job scheduling)

Job

Background Job Creation (Job Definition)

Job Wizard

Job Status

Job Class (priority)

Job Step

Job Start Condition

Job Selection

Job Log

Spool

Variants

Container Object: doesn't work in the background. If you try to instantiate a container control in the
nackground, an exception occurs. When an ALV is called in the background, a print list (Classic ALV) is
generated.

SY-BATCH System Field

Checked to ensure that you do not exectue the CREATE OBJECT statement in case of instantiating a
container control in the background.

Will have the value 'X' if a program is run in the background, and space if not.

--------------------------

ALV Object Model (OM)

--------------------------

Calling Methods

Functional writing style

Classic CALL METHOD


ALV OM

When working with the ALV object model, you must, first. generate an instance of the class
CL_SALV_TABLE.

Each of the ALV properties or subobjects is itself represented by another ABAP class.

All of the class names start CL_SALV_*. If the name is plural, it refers to the properties of a group of ALV
Elements. If the name is singular, it relates to the properties of a single element.

CL_SALV_TABLE

The main class of the ALV Object Model.

Has GET methods for each property of ALV, which can be used to fetch the appropriate object.

FACTORY method

A static method.

Instantiates an object of the ALV main class. It returns an ALV instance and is used instead of CREATE
OBJECT.

You then use this instance for all other method calls relating to the ALV.

You must pass the internal table containing the data to be displayed. The display type is also passed
using a parameter of this method.

Important parameters:

- R_SALV_TABLE: reference to the created ALV

- T_TABLE: name of the internal table that contains the display data.

- LIST_DISPLAY: if the value is X the ALV is displayed as a classic list. To display the ALV in full screen
mode assign the value a space to its value.

DISPLAY method

Used to display the data.

Refreshing the ALV output

If there is changes in the data table, the changes need to be repeated in the ALV output.
REFRESH method of CL_SALV_TABLE is used to refresh the display.

- Refresh ALV output without deleting filter and sorting settings.

- Refresh ALV ouput by deleting filter and sorting settings.

SET_DATA method of CL_SALV_TABLE:

Assign a new strucutre and new content to the ALV.

Pass a new internal table using the T_TABLE parameter.

All objects, such as sorting objects that are related to the previous strucutre, are deleted.

SAP_BOOL

CX_ROOT: the superclass of all exception classes.

Downcast operator ?=

IS BOUND: checks whether a reference variable contains a valid reference.

If a reference to the CL_SALV_TABLE class is running in a container, it is possible to add functions


dynamically (using the instance method ADD_FUNCTION of class CL_SALV_FUNCTIONS)

Standard User Interface Status:

Program Name: SAPLKKBL

GUI Status: STANDARD


SAP BC_TRAVEL Flight Data Model

F1S Logical: Database of Flight Data Model

You might also like