Entering content frameABAP Statements Locate the document in its SAP Library structure

The source code of an ABAP program consists of comments and ABAP statements.

Comments are distinguished by the preceding signs * (at the beginning of a line) and " (at any position in a line).

ABAP statements always begin with an ABAP keyword and are always concluded with a period (.) . Statements can be several lines long; conversely, a line may contain more than one statement.

ABAP statements use ABAP data types and objects.

Statements and Keywords

The first element of an ABAP statement is the ABAP keyword. This determines the category of the statements. The different statement categories are as follows:

Declarative Statements

These statements define data types or declare data objects which are used by the other statements in a program or routine. The collected declarative statements in a program or routine make up its declaration part.

Examples of declarative keywords:

TYPES, DATA, TABLES

Modularization Statements

These statements define the processing blocks in an ABAP program.

The modularization keywords can be further divided into:

· Event Keywords

You use statements containing these keywords to define event blocks. There are no special statements to conclude processing blocks - they end when the next processing block is introduced.

Examples of event keywords are:

AT SELECTION SCREEN, START-OF-SELECTION, AT USER-COMMAND

· Defining keywords

You use statements containing these keywords to define subroutines, function modules, dialog modules and methods. You conclude these processing blocks using the END- statements.

Examples of definitive keywords:

FORM ..... ENDFORM, FUNCTION ... ENDFUNCTION,
MODULE ... ENDMODULE.

Control Statements

You use these statements to control the flow of an ABAP program within a processing block according to certain conditions.

Examples of control keywords:

IF, WHILE, CASE

Call Statements

You use these statements to call processing blocks that you have already defined using modularization statements. The blocks you call can either be in the same ABAP program or in a different program.

Examples of call keywords:

PERFORM, CALL, SET USER-COMMAND, SUBMIT, LEAVE TO

Operational Statements

These keywords process the data that you have defined using declarative statements.

Examples of operational keywords:

WRITE, MOVE, ADD

Database Statements

These statements use the database interface to access the tables in the central database system. There are two kinds of database statement in ABAP: Open SQL and Native SQL.

Open SQL

Open SQL is a subset of the standard SQL92 language. It contains only Data Manipulation Language (DML) statements, such as SELECT, IINSERT, and DELETE. It does not contain any Data Definition Language (DDL) statements (such as CREATE TABLE or CREATE INDEX). Functions of this type are contained in the ABAP Dictionary. Open SQL contains all of the DML functions from SQL92 that are common to all of the database systems supported by SAP. It also contains a few SAP-specific functions. ABAP programs that use only Open SQL statements to access the database are fully portable. The database interface converts the OPEN SQL commands into commands of the relevant database.

Native SQL

Native SQL statements are passed directly from the database interface to the database without first being converted. It allows you to take advantage of all of your database’s characteristics in your programs. In particular, it allows you to use DDL operations. The ABAP Dictionary uses Native SQL for tasks such as creating database tables. In ordinary ABAP programs, it is not worth using DDL statements, since you cannot then take advantage of the central administration functions of thie ABAP Dictionary. ABAP programs that use Native SQL statements are database-specific, because there is no standardized programming interface for SQL92.

Data Types and Objects

The physical units with which ABAP statements work at runtime are called internal program data objects. The contents of a data object occupy memory space in the program. ABAP statements access these contents by addressing the name of the data object. For example, statements can write the contents of data objects in lists or in the database, they can pass them to and receive them from routines, they can change them by assigning new values, and they can compare them in logical expressions.

Each ABAP data object has a set of technical attributes, which are fully defined at all times when an ABAP program is running. The technical attributes of a data object are: Data type, field length, and number of decimal places.

The data type determines how the contents of a data object are interpreted by ABAP statements. As well as occurring as attributes of a data object, data types can also be defined independently. You can then use them later on in conjunction with a data object. You can define data types independently either in the declaration part of an ABAP program (using the TYPES statement), or in the ABAP Dictionary.

The data types you will use in a program depend on how you will use your data objects. The task of an ABAP program can range from passing simple input data to the database to processing and outputting a large quantity of structured data from the database. ABAP contains the following data types:

Predefined and User-defined Elementary Types

There are five predefined non-numeric data types:

Character string (C), Numeric character string (N), Date (D), Time (T) and Hexadecimal (X)

and three predefined numeric types:

Integer (I), Floating-point number (F) and Packed number (P).

The field length for data types D, F, I, and T is fixed. The field length determines the number of bytes that the data object occupies in memory. In types C, N ,X and P, the length is not part of the type definition. Instead, you define it when you declare the data object in your program.

Data type P is particularly useful for exact calculations in a business context. When you define an object with type P, you also specify a number of decimal places.

You can also define your own elementary data types in ABAP using the TYPES statement. You base these on the predefined data types. This determines all of the technical attribtues of the new data type. For example, you could define a data type P_2 with two decimal places, based on the predefined data type P. You could then use this new type in your data declarations.

You use elementary data types to define individual elementary data objects. You use these object to transfer input and output values, as auxiliary fields in calculations, to store intermediate results, and so on. The aggregated data types described below are made up of elementary data types.

An aggregated data type can be a structure or an internal table.

Structures

A structure is a user-defined sequence of data types. It fully defines the data object. You can either access the entire data object, or its individual components. ABAP has no predefined structures. You therefore need to define your own structures, either in the ABAP program in which you want to use it, or in the ABAP Dictionary.

You use structures in ABAP programs to group work areas that logically belong together. Since the individual elements within a structure can be of any type, and can also themselves be structures or internal tables, the possible uses of structures are very wide-ranging. For example, you can use a structure with elementary data types to display lines from a database table within a program. You can also use structures containing aggregated elements to include all of the attributes of a screen or control in a single data object.

Internal Tables

Internal tables consists of a series of lines that all have the same data type.

Internal tables are characterized by:

· Their line type.

The line type of an internal table can be any ABAP data type - an elementary type, a structure or an internal table.

· A key

The key of an internal table is used to identify its entries. It is made up of the elementary fields in the line. The key may be unique or non-unique.

· The access type

The access method determines how ABAP will access individual table entries. There are three access types, namely unsorted tables, sorted index tables and hash tables.
For index tables, the system maintains a linear index, so you can access the table either by specifying the index or the key.
Hashed tables have no linear index. You can only access hashed tables by specifying the key. The system has its own hash algorithm for managing the table.

You should use internal tables whenever you need to use structured data within a program. One imprint use is to store data from the database within a program.

Data Types for Reference

You use references to refer to objects in ABAP Objects. References are stored in reference variables. The data type of the reference determines how it is handled in the program. There are different types for class and interface variables.

Reference variables in ABAP are treated like other elementary data objects. This means that a reference variable can occur as a component of a structure or internal table as well as on its own.

Declaring Data Objects

Apart from the interface parameters of routines, you declare all of the data objects in an ABAP program or routine in its declaration part. The declarative statements establish the data type of the object, along with any missing technical attributes, such as its length or the number of decimal places. This all takes place before the program is actually executed. The exception to this are internal tables.

When you declare an internal table, you specify the above details. However, you do not need to specify the overall size of the data object. Only the length of a row in an internal table is fixed. The number of rows (the actual length of the data object in memory) is adapted dynamically at runtime. In short, internal tables can be extended dynamically while retaining a fixed structure.

The interface parameters of routines are generated as local data objects, but not until the routine is called. You can define the technical attributes of the interface parameters in the routine itself. If you do not, they adopt the attributes of the parameters from which they receive their values.

 

 

 

Leaving content frame