Page 1
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 1/134
Software systems use fixed-length bit sequences for internal character representation. This length specifies the
number of characters that can be displayed in total and a Character Set Table is used to match the assignment
between characters and bit sequence. For example, the ASCII character set, which has 8 bits in length, consists of
256 characters.
If you were using the ASCII Character Set and you wanted other characters to be processed, you would need to
load a different character set table.
Extra work is therefore involved when different users use different character sets and parallel text-based
processing is required. Exchanging data between these is also not so easy.
The Unicode Character Set Table has been defined for this purpose and it is large enough to contain all the
current character sets. It has a 16-bit sequence length, which results in 65,536 possible codes. SAP supports the
Unicode Character Set since SAP Web Application Server 6.10.
Page 2
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 2/134
Predefined data types in Unicode programs include the character-type: C, N, D, T and STRING. Structure types
that contain components of these types would also form a part of the character-type.
In non-Unicode systems, a character of this type is one byte.
Page 3
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 3/134
In Unicode systems, it is as long as a character on the respective platform. X and XSTRING-type variables are
described as byte-type. Earlier everything was treated as character type but from SAP Web Application server
6.10, there is a distinction made between character type and byte type arguments.
For compatibility, character string commands in their standard form always expect character-type arguments.
The statements are then converted by the system, character by character. The corresponding variants of these
statements for byte sequence processing are recognizable by the IN BYTE MODE addition. With this addition, the
statements expect byte-type arguments and are converted byte by byte.
The STRLEN function always expects character-type variables and returns their length in characters. With type Cvariables, only the occupied length is relevant and trailing blanks are not counted.
The XSTRLEN function returns the length of byte sequences. It always expects byte-type variables and returns the
current length for type XSTRING and the defined length in bytes for type X..
The image on your screen shows sample code for both these functions..
Apart from the comparison operators shown on the left of the image, you will notice six new operators that have
been defined and which are identified by the prefix BYTE. Usage of this is also shown in the sample code on the
screen..
Page 4
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 4/134
Depending on the platform, some data types require a specific alignment to be met. For example, there may be arequirement to begin at a specific memory address. Within a structure, during runtime, “alignment” bytes would
be inserted by the system either before or after the component with details of the alignment.
The system first creates a Unicode fragment view to check whether such conversion is possible. The view groups
together adjacent components and alignment gaps.
This view can be seen in the classic debugger. A sample is shown on your screen for reference.
If the fragments of the source and target structures match the type and length as the length of the shorter
structure, conversion is allowed. Else an error occurs in the Unicode check.
If the target structure is longer than the source structure, the character-type components of the remainder are
filled with space characters. All other components in the remainder are filled with the type-specific initial values.
Alignment gaps are filled with null bytes. Components from other types like P, F, String and XString are not
considered but treated individually.
Page 5
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 5/134
Continuing with the rules for conversion, we will now look at some rules for conversion from structures toelementary data objects.
If a structure is contains only character-type data, the same is like a type C data object during conversion
If the structure is not completely character type, the single field must be type C and the structure must
begin with a character-type fragment that is at least as long as the single field.
If the target field is a structure, the remaining character-type fragments are filled with space characters
and all other components with the type-specific initial value.
Page 6
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 6/134
From our earlier learning in this course, you will remember that for character-type variables, offset and length areinterpreted character by character and types X and XSTRING, the values for offset and length are interpreted byte
by byte.
For structures the offset and length accesses are only permitted in Unicode programs if the structure is flat and
the offset and length specifications only contain character-type fields starting from the beginning of the structure.
Page 7
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 7/134
ABAP allows for Unicode character sets since SAP Web Application Server 6.10. However, you must be careful toensure that information about the internal length of your characters does not spill over to your program.
While the ABAP Workbench supports you when working with existing code, you may have to make certain
adjustments. The syntax check has been extended to include Unicode compatibility also.
To execute the relevant syntax checks, you must set the indicator Unicode Checks Active in the program (or class)
attributes. This is the standard setting in Unicode systems.
If the Unicode indicator is set for a program (or a class), the syntax check and program are executed in accordance
with the rules described in the Unicode online help. (This is irrespective of whether the system is a Unicode or a
non-Unicode system).
If the Unicode indicator is not set, the program can only be executed in a non-Unicode system. For such
programs, Unicode-specific changes of syntax and semantics do not apply. However, you can use all the language
enhancements introduced in connection with the conversion to Unicode.
The abap/unicode_check parameter controls the execution of Unicode checks during the syntax check and at
ABAP program runtime in a non-Unicode system.
The parameter can take on the following values:
On: The Unicode checks are performed for each ABAP program. The system behaves as though the programattribute Unicode Checks Active were set for all ABAP programs. This option is normally used for preparing a
conversion to Unicode.
Off: Unicode checks are only performed in those programs for which the program attribute Unicode Checks Active
has been set.
As of SAP Web Application Server 6.10, you can use the transaction UCCHECK to check several Repository objects
for Unicode compatibility at the same time. The transaction always checks the active program version. You can
also use it to apply the Unicode Checks Active attribute to several programs (which must be original programs in
the system). However, you should only do this with programs that are actually Unicode-enabled, otherwise the
program terminates when it is executed.
Page 8
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 8/134
Page 9
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 9/134
Predefined ABAP Types
Compleat
Imcompleat
Page 10
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 10/134
Let us now look at the predefined ABAP type.
Predefined data types can be categorized as complete data types and incomplete data types. The complete types
can be used to type a data object directly while the incomplete types must be supplemented with a length
specification to create a complete type.
Each predefined data type has a characteristic initial value. This type-specific initial value plays an important role
in instantiating the data objects and executing the CLEAR statement.
The image on your screen shows you the description for each data type, the initial value it would take on
instantiation, its static length, and its attributes. You will notice that for the variable length, the length begins with
zero and is adjusted dynamically during runtime.
Page 11
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 11/134
The runtime environment of ABAP provides predefined generic types in addition to the predefined ABAP types.
Unlike the ABAP data type, the generic data type cannot be used to define a data object. They are used
exclusively to type formal parameters and field symbols. The third column in the image on your screen shows you
the compatibility of the generic data type with one or more predefined data types. For example, the generic data
type ‘numeric’ is only compatible with the ABAP data types i, f and p.
Page 12
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 12/134
ABAP has a separate data type for Date and Time fields. They are character like data types and contain 8 numeric
characters for the date and 6 numeric characters for the time.
On the screen you can see that the 8 character field for the data type date can be represented as the date formator as an integer when the date type is converted to an integer for arithmetic purposes.
The internal format of YYYYMMDD can also be defined to a more user friendly format. This specified format can
be used for input and output. The sample code on your screen shows you how date1 has a formatted output and
date2 is as per the system format.
Date fields can be used in arithmetic expressions. The data object of type date will be represented as an integer
and its value is calculated as the number of days from 1st January 0001.
If the data object with type time is used in arithmetic expressions, then it takes a value as the number of seconds
from midnight.
Page 13
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 13/134
If different types of ABAP data objects are used in an operation, the types are converted automatically. Automatic
type conversion is user friendly. However, conversions use up runtime and it is advisable to keep conversion
during runtime to a minimum.
Page 14
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 14/134
Data types are descriptions in ABAP and are not linked to an address inside memory. Data objects are instances of
a data type and therefore occupy memory.
The image on your screen shows you the syntax to define a data object. The statement ‘DATA’ defines the data
and the keyword TYPE links the type to the data object. The link is static and cannot be changed at runtime.
Predefined data types are available in the ABAP runtime environment where you may have complete and
incomplete data types.
Global data types are defined in the Dictionary.
The local data type is defined using the TYPES statement within the ABAP program.
The structure of data objects can contain Elementary fields, Structures or Internal tables.
Structures and internal tables can be mutually nested to nearly any depth. If a structure contains an internal table
or other component with a variable length (components with type string and xstring), it is called a deep structure.
If the component has a fixed length, it is termed as a flat structure. A structure can contain other structures as its
components. Such objects are called nested structures.
Page 15
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 15/134
A literal is defined in the source text of the program. There are three types of literals:
The numeric literal which is defined as a sequence of digits, the text-field literal which is defined as a sequence of
characters using the inverted commas to enclose the characters, and the string literal which is defined using the
character string defined within back quotes. The string literal is only available from SAP Web Application Server
6.10 and later.
Page 16
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 16/134
As ABAP developers, you are familiar with the concept of encapsulating data. The extent to which data objects are
visible depends on the context. The following rules apply to data objects that are defined using the DATA
statement:
A global data object is visible to the entire program.
Inside a subroutine, if the data appears between FORM and ENDFORM, it is a local data object to the subroutine.
If it appears between FUNCTION and ENDFUNCTION, then it defines a local data object of a function module.
Page 17
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 17/134
Data objects that are created in the declaration part of a class are called attributes.
Using these attributes you can decide on the visibility areas using Private, Protected or Public attributes.
The image on your screen shows you different options for specifying visibility.
Page 18
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 18/134
The lifetime of a data object depends on their visibility.
Global data objects are valid as long as the program is in memory.
Local data objects are valid within the subroutine or function module which creates it. These data objects are lost
once the runtime of the modularization unit is completed.
If you use the STATICS statement instead of DATA when you declare local data objects, their lifetime is extended
to the overall program lifetime. Therefore, such data objects have the same lifetime as global data objects, but
their visibility is still limited to the respective modularization unit.
Page 19
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 19/134
At the start of its lifetime the data object is assigned an initial value. For Global data objects this initial value is
assigned when the program is loaded into memory. For local data objects the initial value is assigned each time
the subroutine or function module is called.
If the local data objects are declared with the STATICS statement, then the initial value is assigned the first timethey are called by the surrounding modularization unit.
Page 20
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 20/134
The system will not reserve memory for elementary, variable-length data objects on entering the validity area.
The necessary memory is allocated only when a value has been assigned to the variable.
Page 21
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 21/134
Types i, p, and f represent the three numeric types available. They differ in their inner representation and their
maximum value range and how it does the calculations. Over this and the next two slides you will learn about the
three types and look at their individual arithmetic in detail. This slide shows you how the integer type i is defined
and how it works. Type i is represented internally as a binary number, works faster than the other two types and
always rounds off the result of its calculation to the next whole number.
The image on your screen shows you the valid operations for integers. If the result of the interim calculation lies
outside the maximum value range, then a runtime error occurs.
Page 22
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 22/134
Floating point numbers are represented by binary precision floating point numbers. Floating point numbers are
normalized, and the exponent and the mantissa are also stored in the binary form.
The floating point operations of the relevant processors are used for calculations in floating point arithmetic.
There may be inaccuracies as the algorithms are executed with binary numbers. It is recommended that this data
type is used when an approximation is allowed and not when accurate results are expected.
Page 23
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 23/134
It is possible to define an arithmetic expression of mixed data types including character types. The character type
must contain data that can be interpreted as numeric and there must be at least one data object with a numeric
type.
Once the arithmetic has been determined, all operands are converted to the numeric type that corresponds to
the chosen arithmetic. The system performs the calculation using these converted values and ultimately converts
the result to the desired result type. The image on your screen shows you how this formula has been interpreted
by the system.
Page 24
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 24/134
From the image on your screen you can see that arithmetic to be used is decided by the combination of all the
types in the whole expression. Three rules are shown on the slide as an indicator of the arithmetic that will be
selected.
Page 25
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 25/134
Page 26
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 26/134
To avoid the problems of rounding off when using the type i and the inaccuracy when using the type f, the type p
was introduced.
This type has a wider range and includes decimal numbers. As can be seen from the image, the length can bedefined when defining the type. The term DECIMALS defines how many of the digits in the length of type p are set
aside for digits after the decimal point.
Packed numbers are the best option for business calculations where the correct rounding for the specified
number of decimal places is very important. The algorithm for this arithmetic is similar to using a pencil and
paper. Interim results initially use packed numbers with 31 decimal places. If an overflow occurs, the entire
expression is calculated again with an internal accuracy of 63 decimal places. If another overflow occurs, an
exception is raised and it can be handled.
Page 27
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 27/134
Before the advent of the Unicode character set table, different character tables were used to represent different
sets and data interchange was not an easy process.
As of SAP Web Application Server 6.10 and later, the Unicode character set is also supported and this allows for apossible 65,536 characters that could be represented.
The Unicode check needs to be activated for this to work and can be set for each program. If the Unicode check is
active, it can be run in a non Unicode supported system but the reverse is not true.
Page 28
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 28/134
Page 29
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 29/134
To summarize what you have looked at so far, you must remember that:
All elementary data objects defined as byte like data type will be treated as byte like data objects.
All elementary data objects defined as character like data type will be treated as character like dataobjects.
In non-Unicode systems, the byte like data objects is treated as character like data objects.
In Unicode systems, you must differentiate between them when defining them.
All flat structures are treated as character like data objects only if they contain character like components.
In the image on your screen, you will see some statements. In each of these statements, the operands are treated
like type c fields, regardless of their actual field type. They are not converted.
Page 30
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 30/134
In Unicode, the IN BYTE MODE will have to be added to ensure that each byte is examined individually, and not in
pairs. The corresponding IN CHARACTER MODE addition is optional for processing character-like data objects.
Page 31
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 31/134
The standard function STRLEN( ) is used to determine the occupied length of a string. The corresponding function,
XSTRLEN( ), is available for byte-like data objects.
Page 32
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 32/134
As you can see from the image on your screen, when character fields are defined, the offset and length are
interpreted character by character. When defined as byte-like fields the values are assumed in bytes.
Page 33
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 33/134
In flat structures, offset access is possible even if they are not completely character-like as long as the access does
not go beyond the character-like area.
Page 34
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 34/134
On your screen you can see that if we want to assign the value of one field to another, we can either say MOVE
source TO target or we can say target=source.
Both source and target should be of the same type. There is one more option shown on your screen. The WRITE
statement is used when you want to copy the source to the target in a formatted form. In this case the target field
has to be long enough to accommodate the formatting, for example, spaces or separators.
Page 35
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 35/134
Page 36
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 36/134
There are two ways to declare structures: This can be done using the TYPES statement to explicitly define a
structure type to which the DATA statement refers, or construct the data type implicitly in the DATA statement.
Sample code for both types is shown on your screen for reference.
Page 37
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 37/134
Nested structures can be defined as deep as required. The components of the substructure can be addressed with
a corresponding chain of component names.
On your screen, you can see the sample code where the structure name is nested into the second structure
address.
A deep structure is a structure in which at least one component hasa dynamic type, which can be an elementary
data object with variable length of type string or xstring, a reference to another data object, or an internal table.
Page 38
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 38/134
The nested structure cannot be used when presenting data using the SAP List Viewer or in the Table Control. The
alternative is to use a Named Include. The sample code on your screen shows you how this can be done. The
structure s_name has three components to it, prename, surname and title.
The structure is called using the “Include Type … As.. “ statement. Notice how, it is no longer represented as a
nested structure and the three components are now called name.
To call a structure you can use the Include Structure statement.
Page 39
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 39/134
The contents of one structure can be assigned to another structure. As mentioned earlier, the program is more
efficient if you can keep the types of the structures the same and avoid as much automatic conversion as possible.
If the components of two structures are type compatible, but their component names are different, these two
structures are still compatibly typed as a whole.
Page 40
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 40/134
To assign values between identically named structures, you can use the MOVE-CORRESPONDING statement. The
system will copy each source field to the target field matching it by name. On your screen, the sample code shows
you how the fields of name are moved into the matching fields in address which has the fields of the same name
among other fields. The interpretation of how this is done is shown on the right of the screen.
Page 41
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 41/134
You have already looked at predefined data types and how to work with them. In this topic, you will learn about
Global data types and constants, where they are created, and why and how to use them. The Global data type is
administered centrally and enables better use and control. As they reside in the ABAP Dictionary, it is possible to
use them in all your Repository objects.
Page 42
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 42/134
Global data types are linked to business contexts based on content, and are actively integrated in the SAP system.
Therefore, when searching for a global data type, consider both technical and semantic properties.
Global data types are centrally administered. Hence, you can use them in all repository objects. Also, global data
types minimize maintenance while maximizing system consistency.
Let us now look at what an ABAP Dictionary is.
Page 43
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 43/134
The ABAP Dictionary manages global information that can be accessed and used throughout the repository
objects. This Dictionary includes the Search functions and the global data types.
Simple and complex structured data types can be defined in the ABAP Dictionary. You cannot declare types or
data objects that are known outside the boundaries of a program. Technical and semantic information is also
stored here.
The ABAP Dictionary also maintains all information about database tables which are addressed from the SAP
System. All changes to the database table is first completed in the ABAP Dictionary and then copied to its
appropriate place to ensure a consistent availability of information. This also ensures that there is no dependency
on platforms.
Page 44
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 44/134
Programs in the SAP system may contain user dialogs to input and output data. Global types for input and output
fields have many useful attributes:
When a user enters invalid data, the value ranges that are defined for the Global data type are automatically
checked as they are globally available and an error message can go to the user. A similar feature is available for
formatting and semantic information. This is because the global data objects have the same type as the columns
in the database table.
Page 45
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 45/134
The next advantage of the ABAP Dictionary lies in the fact that it not only maintains information about the global
data type but also contains all required information about the definitions of database table. When you want to
administer a database table, or you want to access data from the database table form within your ABAP program,
the fact that both these information are available globally ensures ease of operations.
Page 46
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 46/134
Global types are used to define the interface parameters for function modules and methods of global classes. If
this type is complete, you can use it directly, at runtime, to define the data object. This makes your program more
robust while reducing maintenance. On your screen you can see how the ABAP program can directly call the
function or the methods as they are linked to the global data Type.
Page 47
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 47/134
Now that we have seen why we need global data types and their advantages, let us look at the types themselves
in detail.
Inside the ABAP dictionary, the elementary data types are known as data elements. They can contain technical
and semantic information, field labels, details about F1 help and a link to the search help.
Structured data types are called structures and just like the local structure types they can be nested to any depth.
Data types for internal tables are called table types. While known as table types, they are stored internally in the
Dictionary as access types. Data types are not the same as the definition of data tables seen earlier.
Global types are formed from elementary types, just like local program data types. Although they are identical
technically, they have different names from the predefined ABAP types. These are only valid within the ABAP
Dictionary. Thus, to make things simple, they are referred to as predefined Dictionary types.
Page 48
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 48/134
The image on your screen shows you how the Dictionary type is mapped to the ABAP type when generating the
program. After that, on actual execution of the program, it is the ABAP type that is used. The documentation for
the same is shown on the rigth of our image.
Page 49
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 49/134
We have already seen that the global data types are formed from elementary types. Just like local program data
types they are technically identical to the predefined ABAP types. They are referred to as predefined Dictionary
types. Some examples of these types are shown in the table on your screen. The two columns in blue show how
the ABAP type is different from the Dictionary type.
Page 50
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 50/134
Data elements are elementary Dictionary types. The options for assigning a technical property to a data element
are either by using a domain, or by direct type specification.
If you assign the technical properties using a domain, then the domain itself contains the technical attributes. This
reduces maintenance. It is recommended to use this method if the technical attributes for usage have to be the
same but not the semantic attributes.
With direct type specification, you would need to reference dictionary type and if this type is an incomplete one,
then the rest of the required information like length or decimal places has to be defined for the data element.
Page 51
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 51/134
Let us now look at how to use these data elements in a program. When you want to assign the type to the input
or output field using a data element, some existing attributes can be used.
With the predefined data type, the type and length attributes can be checked automatically and error messages
can be sent out automatically. Similarly, existing formatting or additional restrictions can be used. Help
information stored with a field is also available automatically when the user hits the F1 key. If any search help is
assigned to the data element, which too is now accessible.
The image on your screen shows you how this is done, as the global data type is used for the assignment. Let us
now look at structures.
Page 52
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 52/134
A structure contains several components and any number of them can be global types. The type to each
component can be assigned by using a data type, by direct type specification or by using a structure type or a
table type.
You have already seen the advantages of using the global data type. Similar advantages exist with the use of
direct type specification and using of the structure type enables you to use any level of complexity.
Page 53
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 53/134
Page 54
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 54/134
The sample code on your screen shows you how to use Dictionary Structures in ABAP programs.
To define a screen interface, a flat global structure type can be used. Formatting options, online help and search
functions, validity checks and so on can come from the global types itself so that the entire program is more
efficient. Similarly, for the user, error messages can come from the global types too, as these would have been
defined there.
You have to define the structure for the data transport between screen and program with the TABLES statement.
Page 55
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 55/134
Page 56
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 56/134
n continuation from the previous slide, here, you can see how all the various checks, like validity, formatting
options, semantic information can be accessed in the new structure as they are originating from the global types.
Similarly, technical information also comes from the technical type to your ABAP program.
Page 57
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 57/134
A type group has to be used to define a global constant. The name of this type group can contain up to 5
characters.
The CONSTANTS statement is used to define constants in the type group.
All predefined ABAP types and the global Dictionary types can be used. To use the types of a type group in a
program, you specify the type group using the TYPE-POOLS statement.
The sample code on your screen shows you how this can be written.
Page 58
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 58/134
Page 59
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 59/134
Page 60
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 60/134
Page 61
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 61/134
Page 62
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 62/134
Page 63
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 63/134
The graphical user interface in the SAP system is based on SAPGUI windows. The dialogs in the system are
implemented using dynpros of application programs. During runtime, they communicate using the services of the
runtime system.
You can also use screen elements other than those provided in the Screen Painter in SAP GUI windows. These
additional screen elements are known as controls which are standalone binary reusable software components.
As of SAP R/3 4.6A, communication for all controls is performed using the Control Framework or CFW.
The Control Framework is implemented using special services in the SAPGUI and the runtime system on the
application.
Page 64
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 64/134
To create a standalone instance of a control, you will need a screen and a special EnjoySAP control. The EnjoySAP
control is connected to the dynpro using a container control:
The dynpro usually contains an area reserved for the container.
In your program, you assign an instance of the container control class, to the reserved area on the screen
The container control instance is assigned the instance of the actual EnjoySAP Control.
Every presentation server control has a representative instance in the ABAP Program.
Page 65
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 65/134
On your screen is a graphical illustration of what we just saw. The connection of an EnjoySAP Control to a dynpro
is “interleaving” of the areas concerned:
An area is reserved on the screen to display a control.
A container control is visualized in this area.
The area of the container control itself acts as the basis for the visualization of the EnjoySAP Control, such as an
ALV Grid Control.
Page 66
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 66/134
Let us now see how the screen painter can be used to create the reserved area for the EnjoySAP control.
A toolbar similar to the one shown here will be visible on your system.
Choose the text custom control icon and use it to select that area on your screen where you would like to have
your reserved area.
You can do this by choosing the top left coordinate on your screen by moving your mouse there, holding down
the mouse click and dragging it down diagonally right and downwards till your area is defined. You can now
choose a name for this area. Resizing is always possible.
Page 67
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 67/134
Next, let us look at how to generate an instance of the container control. Do this in your program at a point
before the screen on which the EnjoySAP Control is to appear. To be able to create a container control instance,
you also require a reference variable for your instance.
To make your program easier to follow, place all control programming in a separate module.
Let us now look at the individual steps.
Page 68
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 68/134
Let us now look at some syntax. We begin with the syntax to define a reference variable. A reference variable is
required as your ABAP program uses instances of classes. The pointers to these instances are generated and
administered in the main memory of the SAP Web AS system. The screen shows you sample code. The variable is
generated using the statement DATA and assigning a name. The addition TYPE REF TO means that the field can
include a pointer to an instance. This is followed by the name of the class which can be either a local or a global
class.
Page 69
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 69/134
Having defined the reference variable, let us now look at how to create the instance.
The CREATE OBJECT statement is used to create an instance of the class.
If this class has a method with the name CONSTRUCTOR, this method is automatically executed when the instance
is generated.
The CONSTRUCTOR method can only have IMPORTING parameters and exceptions as an interface.
The interface must also be specified in the CREATE OBJECT statement. When you do so, you need to assign values
to all of the mandatory IMPORTING parameters, which do not have any default values.
creen illustrates this for you.
Having defined the reference variable, let us now look at how to create the instance.
Page 70
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 70/134
The sample code on your s
Next, let us look at how to create a container control instance.
To create a reference variable for your container control instance, use DATA to create a variable which is
specified using TYPE REF TO.
To generate a container control instance at the presentation server, use the ABAP statement CREATE OBJECT.
This generates an instance of the class as a representative object.
By using the IMPORTING parameter, you can transfer the name of the area reserved for the control, on the
screen.
Page 71
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 71/134
Next, we will look at how to create an object by pattern.
On the Insert Statement initial screen, choose the ABAP Objects Patterns option.
On the next screen, choose the Create Object option.
Now, specify the reference variable for the object to be created under Instance, and the class of the object to be
created under Class.
Page 72
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 72/134
The activity we have just seen can also be done using the drag and drop function of the ABAP Workbench.
You can display the global class in the navigation area and transfer it to the editing area using .drag & drop.
The ABAP statement CREATE OBJECT, including the interface parameters and exceptions, is inserted at the
current cursor position in the source code of the program.
Page 73
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 73/134
If you package the control-specific processing in a PBO module, you need to ensure that an instance is only
generated the first time the dynpro is called. Otherwise there is a danger that a new object will be generated
every time the dynpro is processed:
The container screen usually has itself statically as the next screen.
Each action on the screen that triggers PAI (for example, ENTER) means that the dynpro is processed again after
PAI has been processed.
You can stop unwanted instances from being created by requesting the initial contents for the container
reference.
Page 74
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 74/134
To generate an instance of the ALV Grid Control, you follow a procedure similar to the one for the container
control instance. The instance of the ALV Grid Control must be created after the container control instance, but
before the SAPGUI window is sent to the presentation server.
Page 75
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 75/134
A reference variable has to be declared to create an ALV Grid Control instance. The image on your screen shows
you some sample code for this and also the position where the code comes in.
As you can see the instance of the ALV Grid Control is connected to the container and therefore to the container
screen using the object reference passed in the interface.
Page 76
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 76/134
If you have completed all the processes as defined in the earlier slides, then you have successfully created an ALV
Grid Control as a screen element.
Currently only the frame is visible in the SAPGUI window as the controls do not display anything. For data to be
displayed, you have to supply the presentation server controls with data.
Page 77
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 77/134
Resources that the control occupies at the presentation server are automatically released at the end of the
program by default. However, you can also explicitly release the resources, by calling the instance method free.
The sample course on your screen shows you how to do this. It is recommended that you release unwanted
resources so that they are released to the working memory when the Garbage Collector runs.
Page 78
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 78/134
On the presentation server, a representative instance of the class, packages the technical details of the
communication with the instance of the ALV Grid Control.
The representative instance also communicates with two other partners:
The ABAP programs as a user
The spool system or printer to output the data as an ABAP print list
The communication between the ABAP program - representative instance - ALV Grid Control on the presentation
server, takes place interactively at runtime.
The interactive standard functions that are provided for screen output and the generation of the ABAP print list
are also implemented in the class.
Page 79
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 79/134
On the other hand, any information that is not part of the representative instance needs to be provided by the
calling program as special data objects.
Let us now see how long the data is to be retained.
The data that you want displayed must be passed to the representative object as an internal table.
After that, the representative instance does not have a copy of the data, but rather manages only a reference to
the passed internal table. Hence actions of the instance on the presentation server are performed by the
representative instance on the internal table in the calling program.
This means that, the retention period of the internal table that contains the list data, must be at least as long as
the retention period of the representative instance.
Page 80
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 80/134
The specified global data types can be used to define data objects in the calling program. In this way, the
additional information can be passed to the representative instance.
You can pass display settings for the data area using a structure. You can also use an internal table to hide
functions of the application toolbar.
You can control output properties for the print list using a structure.
You can use internal tables to pass information about sort criteria and filter options.
Usually, the filter and sort criteria are not created manually as these can be interactively changed by the user.
The representative instance automatically changes the associated internal tables at user interactions. Sort and
filter criteria are usually handled as elements of display variants.
Page 81
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 81/134
Now we will see how to pass List Data and additional information.
The method set_table_for_first_display can be used to pass the list data, the field catalog, and other additional
information to the representative instance.
You can pass the list data to be displayed using the parameter it_outtab.
If you pass the name of a global structure type to the parameter i_structure_name,the representative instance
automatically generates the corresponding field catalog.
The parameters is_variants and i_save are used to set the configuration options of the display variants for the
user. You can use the i_default parameter to set an existing display variant as the initial variant. You can pass
default settings for control and print list output using the parameters is_layout and is_print. The names of field
groups defined in the field catalog are passed using the parameter it_special_groups. You can use the parameter
it_toolbar_excluding to pass the names of the standard functions of the application toolbar that are to be hidden.
If you want to change the automatically created field catalog, or create it completely yourself, you need to pass a
corresponding internal table to the parameter it_fieldcatalog. You can pass default settings for filtering and
sorting the data to be displayed using the parameters it_filter and it_sort.
Page 82
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 82/134
You can use various parameters to pass the information for formatting. The simplest variant is to link the
parameter i_structure_nam to a Dictionary structure of the same type. The parameter it_outtab for the internal
table containing the display data is obligatory.
Page 83
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 83/134
You can either use the drag and drop function or the ABAP Objects pattern to implement a method call of a global
class. The method to create the statement CALL METHOD with the ABAP Objects pattern is described below:
On the Insert Statement initial screen, choose the ABAP Objects Patterns option.
On the next screen, choose the Call Method option. Specify
For Instance: the reference variable for the object for which the method is to be used
For Class/Interface: the class of the object (in this example, cl_gui_alv_grid),
For Method: the method names (in this example, set_table_for_first_display).
Page 84
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 84/134
The statement CALL METHOD, including all parameters and exceptions, is then inserted at the cursor position in
the ABAP source code. Optional parameters and exceptions are inserted as comments.
You can display the global class in the navigation area of the ABAP Workbench by using drag & drop; and drag the
method into the editing area by holding down the left mouse button.
The ABAP statement CALL METHOD, including the interface parameters and exceptions, is inserted at the current
cursor position in the source code of the program. Optional parameters and exceptions are inserted as
comments.
Page 85
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 85/134
In order to refresh the display, you can use the method refresh_table_display to prompt the representative
instance to send the list data and, if necessary, also the additional information to the instance on the presentation
server again.
You can use the parameter i_soft_refresh to specify that only the data contents are to be passed again, keeping
the current filter and sort criteria You can use the fields row and column of a structure of the global data type
lvc_s_stbl to specify that possible scroll positions with regard to the rows or columns are retained when
refreshing. Pass the corresponding filled structure to the parameter is_stable.
But note that if you change the row structure of the data table, you need to call the method
set_table_for_first_display again, since the field catalog must be created again.
Page 86
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 86/134
Page 87
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 87/134
Page 88
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 88/134
The field catalog is a format description of the display area for data. This is especially useful when you need to
update the ALV with fresh information. The field catalog enables displaying the updated data, either onscreen or
in a print list.
Page 89
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 89/134
The internal table can have a freely-definable row type. For the data to be displayed either on-screen or in a print
list, a field catalog is required. This contains information corresponding to each row in the table.
The Field Catalog can be automatically generated by the representative instance. When row types have been
defined in the ABAP dictionary, you only need to pass the respective names to the representative instance.
You can also pass this display information on to the representative instance by using an additional internal table.
This additional table is the field catalog. The global data type of this internal table is LVC_T_FCAT. Your row type is
called LVC_S_FCAT.
Every column of the data table that has not been defined in the ABAP dictionary, or has a structure different form
that defined in the dictionary, needs a row in the field catalog. This row must contain the technical properties and
other formatting information for the column.
Page 90
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 90/134
Depending on the row type used for the data table, Field Catalogs are generated differently.
Three types of situations can occur:
Case 1: You can have the field catalog automatically generated by the representative instance by passing the
name of the global structure type. Columns of the data table not defined in the global structure type are not
displayed.
Case 2: Though all fields of a global structure occur in the data table with the same names, adjustments may be
required to be made. Like for example, to the specifications from the ABAP Dictionary or additional columns are
to be output, or both. In this case, you need to create rows in the field catalog for the columns to be changed or
added.
Case 3: The row type of the data table contains either no reference to the ABAP Dictionary, or only to individual
global structure fields or data elements. In this case, the field catalog needs to be completely created by the
calling program.
Page 91
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 91/134
The situation shown here is pertinent to the cases two and three that we just discussed.
First, you create a field catalog in the calling program. Then assign the name of a column from the data table to
the field fieldname. This field assigns a row in the field catalog to a column of the data table.
The other fields of the field catalog can be divided into two groups with regard to their use when creating a field
catalog:
References to global types (that is, structure fields in the ABAP Dictionary) are created using the fields ref_field
and ref_table.
All other fields of the field catalog contain values for the properties of the columns.
Page 92
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 92/134
If you assign values to the fields ref_table and, if necessary, ref_field, all type definitions are transferred from the
specified structure fields in the ABAP Dictionary. You can overwrite these by assigning values to individual fields of
the latter group.
The fieldname column in the field catalog contains the column name of the data table. As you can see from the
example on your screen, every column of the data table for which you want to control formatting must have a
row in the field catalog.
If you want to refer to a field of a global structure with the same name, assign the name of the structure to the
field ref_table.
But, if the column name of the data table and the structure field name are different, you need to add the field
name to the ref_field field.
Page 93
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 93/134
Look at this example. The data table consists of fields (columns) of the type SBOOK and two other fields. You need
to describe these in the field catalog, along with the column that is to be hidden.
Page 94
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 94/134
Page 95
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 95/134
This example shows a semi-automatic field description. Part of the field description comes from the Dictionary
structure (SBOOK), while another part is explicitly defined in the field catalog (it_fieldcat).
The field catalog (internal table) is filled in the program and is passed on together with the name of the
Dictionary structure during the method call. The information is merged accordingly in method
set_table_for_first_display. Note that the fields of the data table it_sbook that cannot be read from the SBOOK
table also need to be filled meaningfully.
Always check the consistency if you are constructing the field catalog semi-automatically or manually.
Page 96
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 96/134
If you have not filled either the field ref_field or the field ref_table, there is not an adequate reference to the
ABAP Dictionary. In this case, the fields shown here allow you to format the relevant columns for output. Using
rollname, you can specify the data element that is used for the F1 help and the text for the column headers,
selection screens and quick info text (if it is not already explicitly set).
Page 97
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 97/134
If the contents of a column are to be formatted in accordance with the formatting options of a currency unit that
is specified in another column of the data table, specify the name of this column in the field cfieldname.
If all values of a column are to be formatted in accordance with a particular currency, specify the relevant
currency abbreviation in the currency column.
If the currency field has a value, entries in the cfieldname are ignored.
If the contents of a column are to be formatted in accordance with the formatting options of a unit that is
specified in another column of the data table, specify the name of this column in the field qfieldname. This is
formatting in terms of quantity.
Page 98
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 98/134
If all values of a column are to be formatted in accordance with a particular unit, specify the relevant unit
abbreviation in the quantity column.
If the quantity field has a value, entries in the qfieldname are ignored.
On the screen you can see that the data table contains the two columns: price, say, the cost of a flight seat); and
currency in which the payment is made. By making the entry “CURRENCY” in the cfieldname field for the price
column, you determine that its contents are to be formatted in accordance with the currency specified in the
currency column.
Page 99
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 99/134
To calculate the column position, hidden columns need to be taken into account, but not the exceptions. Without
explicit positioning, fields that are manually added to the field catalog are positioned before the other fields of
the data table.
Exceptions are always displayed in the first column.
To highlight with a default color, set the EMPHASIZE field with “X”. Else you can define the color yourself by
passing a four-digit numerical code in accordance with the convention.
The field “no output” is hidden on the list (screen or print), but appears in the field selection dialogs of the
standard functions (sorting, filtering, and so on).
Page 100
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 100/134
Similar to the formatting options for currency fields, you can use the two fields, decmlfield and decimals_o, to
define the number of decimal places for numerical content.
Also, if you want to output a column as an icon, set the field icon of the layout structure to "X". If you want to
output a column as a symbol, set the field symbol of the layout structure to "X".
Page 101
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 101/134
If a column has no reference to the ABAP Dictionary, or if you want to explicitly define or override a text, then you
can make entries in the fields listed here.
You can use the value assigned to the field colddictxt to determine which of the four data element texts are to be
used as the column header. These texts are in the fields scrtext_s, scrtext_m scrtext_l, and reptext. If colddictxt
has an initial value, the text of the field coltext is set as the column header.
If coltext also has an initial value, an appropriate text is automatically used from the four data element texts,
depending on the width of the column.
In selection screens, texts have a certain priority. The entry in the seltext field has the highest priority. If it is
missing, the longest of the four data element texts is used. If none of these four texts exists, the contents of the
field tooltip is used, or finally, the field name itself. In tooltip, set the text that is displayed when you hover the
mouse cursor over the column header.
Page 102
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 102/134
In addition to the properties that we have seen so far, there are other properties that can be attributed to a
Column.
Use the field sp_group to combine multiple fields into a group using a group key. This is useful when you want to
display all columns or only those of a specific group.
Page 103
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 103/134
Page 104
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 104/134
Page 105
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 105/134
In the SAP R/3 System, the graphical user interface is based on the SAP GUI windows. Every user dialog in the
system is implemented using Dynpros of application programs. The communication between the application
program and the Dynpro at runtime takes place using various services of the runtime system like the ABAP
processor and Dynpro processor.
Since SAP R/3 4.5, you can also use screen elements other than those provided in the Screen Painter in SAP GUI
windows. These additional screen elements, known as controls, are standalone binary software components that
are reusable. .
Page 106
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 106/134
Every EnjoySAP Control, with which an application program communicates, represents an object on the
presentation server. Therefore, the communication with the instances is through method calls and events of the
objects.
There are representative classes or proxy classes in the class library, for all EnjoySAP Controls which access the
Control Framework. These are referred to as Control Wrappers.
When you use an EnjoySAP control in an ABAP program, there are actually two objects involved: an instance in
the ABAP program, and an instance of the control at the presentation server.
The ABAP program always communicates only with the representative object. The representative object
performs the associated operations on the presentation server instances, using the CFW. Actions that come from
the presentation server control are forwarded to the representative object using the CFW. The representative
object then communicates with the ABAP program.
Page 107
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 107/134
This slide gives you an overview of how an Event is triggered and handled.
When an event is passed to a presentation server control, a range of partner levels are involved:
SAP GUI/Automation Controller: The event triggered by the presentation server control is received by the
Automation Controller in the SAPGUI. The Automation Controller then forwards the information about an event
to the Basis Services of the runtime system as a special function code. The Basis Services forwards the information
to the representative object in the ABAP program. The representative object in the ABAP program then triggers
an event as ABAP Objects, thus informing the components registered for the event. These components then
handle the event with an appropriate handler method.
Page 108
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 108/134
Let us see how ABAP Object events are processed.
An object can announce that its state has changed by triggering an event, or it can contain handler methods that
are executed when the event occurs.
For the handler methods of the instances to be run, these instances need to be entered into a list of the object
that can trigger the event.
At the point when the event is triggered, a Basis Service then ensures that the registered methods are executed.
Unlike explicit method calls where the caller has control and knows the method called, the trigger of the event
does not know who will handle the event in this case. This applies both when the event is defined and when the
event occurs at runtime.
Page 109
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 109/134
The ALV Grid Control has a large number of events:
The event is triggered after a mouse double-clicks.
These events are triggered when you output the print list.
This event is triggered at self-defined function codes like your own buttons in the toolbar or context menu. It
allows you to implement your own functions.
Page 110
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 110/134
Any class can contain handler methods for events of other classes.
Event handler methods require the addition FOR EVENT <event_name> OF <class_name> in the definition part.
This specifies that this method can react to events <event_name> of instances of the class <class_name>.
The interface of an event handler method can only contain formal parameters that were defined when the
corresponding event was defined. The properties of the parameters are also taken from the event. However, the
event handler method does not have to accept all of the parameters passed in the RAISE EVENT statement.
Events always have 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 trigger
Page 111
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 111/134
Let us now look at some mouse operation events.
If the user "double-clicks" the data area the data area, the event double_click is triggered in the calling program.
The export parameters es_row_no and e_column contain information about the data table. You can find the
number of the row of the internal table to which the "double-clicked" row in the data area belongs in the row_id
field. In fieldname, you can find the name of the column of the internal table to which the "double-clicked" row in
the data area belongs.
If a column has been identified as a hotspot, the event hotspot_click is triggered in the calling program when a
user clicks the mouse in this data area.
Page 112
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 112/134
Page 113
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 113/134
A handler method can be either a static method of a local class or an instance method of an object. The significant
difference is that, in the instance method, you do not need to instantiate an object for the local class to use the
method.
To create a handler object for an event, it is first necessary to define a local class. After you have defined the
class, you need to implement it. You store the source code that is to be run when the event is triggered, within
the implementation of the handler method.
The method, receives the information provided by the event about the mouse position at the double-click, and
generates an information message.
Page 114
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 114/134
A handler method can be either a class method (static method of a local class) or an instance method of an
object.
To generate an instance method, use the METHODS statement when defining the class.
Implement the method in exactly the same way as the class method.
Create a reference variable with reference to your local class.
And finally, generate a corresponding object.
Page 115
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 115/134
For an event handler method to react to a triggered event, you must define at runtime the trigger to which it
should react. The SET HANDLER statement links a list of handler methods with the event triggers.
In the above example, the static (cross-instance) method on_double_click of the class lcl_event_handler is to be
called if the instance to which the object reference alv refers triggers the event double_click. This is a static
method for the handling
Page 116
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 116/134
Before the standard toolbar is integrated into the ALV Grid Control, the representative instance triggers the event
toolbar. During the lifetime of the representative instance, you can prompt an additional triggering of this event
by calling the method set_toolbar_interactive
Page 117
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 117/134
The toolbar event has a pointer to an instance of the class cl_alv_event_tool-bar_set as an export parameter. This
instance of a toolbar contains, in turn, the public attribute mt_toolbar. This is an internal table with the row type
stb_button. You therefore need to fill this internal table in the handler method to add additional buttons or other
elements.
If the user chooses an element of the type "1" or "2", the representative instance triggers the event
menu_button with the parameter e_object of the class cl_ctmenu. Therefore, to add a menu to the toolbar, you
also need to implement a handler method in which you create the menu in the same way as a context menu. You
can differentiate between multiple menus by querying the function code.
Page 118
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 118/134
If the user chooses a function element that has been added to the standard toolbar, the representative instance
triggers the event user_command. This contains the function code as the export parameter e_ucomm.
To handle the additional function, you need to implement a handler method for this event. You can differentiate
between the function elements by querying the function code.
Page 119
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 119/134
There are two ways to display a field in the ALV Grid as a button:
Either this attribute is specified for an entire column in the field catalog (using the parameter style).
Or you specify it for individual fields. To do this, add an internal table of the type lvc_t_styl to the data structure,
in which you define for each data record which fields of the data record are to be displayed as a button.
In the above example, a separate field (display_bookings) has been defined for the structure wa_sflight, in which
a button is displayed or is not displayed, depending on other data. (You can, however, also use existing fields of
the data structure as long as they do not have F4 help.)
An entry for each field that is represented as a button is created in the internal table of the lvc_t_styl type (in this
example: ct). The name of the output field is specified with fieldname, the class constant cl_gui_alv_grid ->
mc_style_button is specified with style.
Page 120
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 120/134
Finally, the name of the internal table of the type lvc_t_styl that contains the information about the buttons is
specified in the layout structur
If a user presses a button in a cell, this triggers the event button_click. The event returns the row and column ofthe button click. An associated handler method could, for example, implement a context-dependent display of
detailed as a reaction.
Page 121
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 121/134
The print list automatically generated by the representative instance can be extended by the calling program. Use
the above events to do this. By using these events, you can implement the same logical process steps as are
familiar from the “classic” ABAP list layout. Thus, in the event handler methods to be implemented, you can use
the usual statements for ABAP list output as well as their many additions (write, skip, uline, among others). You
can also use the subtotal_text event to define additional texts for subtotals across columns whose output has
been suppressed. For more information, see the online documentation.
Page 122
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 122/134
To have a page break at a control level change in the print list, you first need to set an indicator in the print
structure that the user can format the control level change in the print list. This is controlled by the field
grpchgedit of the transfer parameter is_print (structure of type lvc_s_prnt). This is the programmer’s task. The
program user then sorts in the ALV Grid or in the print list by the fields for which he or she wants group
processing.
Page 123
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 123/134
In the print list (list display), the user calls the “Define Sort Order” dialog box. This is done by choosing the Sort
button without first selecting a column. The criteria in the CB field can be set for page break, underline, or no
formatting.
The solution presented only works in interactive mode, not in background processing. For background processing,
you need to specify the settings for sort order and for control level formatting in the parameter it_sort of the
method set_table_for_first_display. To do this, assign * or UL to the field GROUP in it_sort.
Page 124
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 124/134
Page 125
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 125/134
The image on your screen shows the structure of the global type used make settings for the print list.
The settings include
Display on the screen before printing. If you assign the value “X” to the print field, you can use the ALV Grid
Control to print without first displaying the list on screen
Number of rows for the page footer
Control level change formatting
Page 126
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 126/134
Print list information. If you assign the value X, information about the sort order, totals, and defined filters are
printed, together with data statistics, at the start of the list
Time of print as title. Specifies the time at which the grid title is to be printed and
No column optimization. If X, no column width optimization occurs.
Page 127
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 127/134
Page 128
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 128/134
There are several methods with which to implement a task. The constructor, set_table_for_first_display and
refresh_table_display methods have already been discussed. The set_toolbar_interactive method triggers the
toolbar event. If you want to expand the toolbar to include your own functions, use this method to construct the
toolbar again. The set_user_command method gives you the opportunity to replace standard functions of the ALV
Grid Control with functions of your own. To do this, you must query the current function code during the
before_user_command event and change it using set_user_command.
Determine for yourself which methods are available for solving a problem.
Become familiar with the interface of the selected method
Add the method call using drag & drop or using .ABAP Objects Pattern.
Page 129
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 129/134
In this example we see that, to implement a self-defined function, it is necessary to determine the current cell.
Page 130
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 130/134
Page 131
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 131/134
In this example you see how a standard function of the ALV Grid is replaced by user-defined function.
Page 132
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 132/134
Page 133
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 133/134
Page 134
7/22/2019 E Learning2012
http://slidepdf.com/reader/full/e-learning2012 134/134