Friday, January 17, 2014

TAW10 - BASIC ABAP LANGUAGE ELEMENT

USING DATA TYPES
A formal description of a variable is called a data type.
When you define a variable or constant concretely by means of a data type, you define a data object.
The type of a data object defines its technical (and possibly also semantic) properties.
The type of an interface parameter is essential for determining the type of the actual parameter that is transferred when the modularization unit is called.
An input or output field should also be assigned a type. Only then can it provide information in addition to the technical characteristics, such as the field and value input help.


ABAP STANDARD TYPES: COMPLETE



The ABAP standard types predefined by SAP are divided into two groups: complete and incomplete types.
Complete types are type-specific and have a fixed-length specification:
Type D is used for date with format YYYYMMDD and fixed length 8.
T is used for time with format HHMMSS and fixed length 6.
I is used for integer and has a fixed length of 4.
F is used for floating point number and has a fixed length of 8.
DECFLOAT16 or DECimal FLOATing point number has a fixed length of 8 and is available as of AS ABAP 7.02.
DECFLOAT34 or DECimal FLOATing point number has a fixed length of 16 and is available as of AS ABAP 7.02.
STRING is the type used for dynamic length character strings.
XSTRING or heXadecimal string is the type used for dynamic length byte sequence.


ABAP STANDARD TYPES: INCOMPLETE



For some ABAP standard types, you have to specify a fixed length of the variable while defining a data object.
These incomplete ABAP standard types do not contain a fixed length:
C is used for the character string (Character).
N is used for the numerical character string (Numerical character).
X is used for byte sequence (HeXadecimal string).
P is used for packed number (Packed number). In the definition of a packed number, the number of decimal points may also be specified.

DECLARING LOCAL TYPES


The local data type “gty_c_type” is declared with a TYPES statement and is defined with an incomplete standard type ‘c’ of length 8.

GLOBAL TYPES IN THE DICTIONARY



A data type defined in the ABAP Dictionary is called global and can be used throughout the SAP system. Global Types include Data ElementStructure, and Table TypeData Elements define Field TypesStructure and Table Type are used to define a structure type and a type for internal tables, respectively.

DEFINING DATA OBJECTS



Data objects are always defined with the DATA keyword. You can use an ABAP standard type, a local type, or a global type to define a type for the data object.
You can refer to an already defined data object when defining additional variables by using the keyword LIKE.

EXAMPLE OF THE DEFINITION OF ELEMENTARY DATA OBJECTS


You can use the VALUE addition to preassign the value of an elementary data object.
If the length is not specified in the variable definition, a default length for the incomplete standard type is used. The default length is 1 for types C, N, and X, and 8 for type P.
A data object without a type and length specification takes a default type C with length 1.

LITERALS AND CONSTANTS (FIXED DATA OBJECTS)
Fixed data objects have a fixed value and cannot be changed at runtime. Literals and constants belong to the fixed data objects.
You can use literals to specify fixed values in your programs.
Numeric literals are specified without quotation marks.
Text literals are specified with quotation marks.
You define constants using the CONSTANTS statement.
Their type is defined similarly to the definition of elementary data objects. The VALUE addition is mandatory for constants.


TEXT SYMBOLS

Text symbols are used for productive programs that should be executable with different logon languages.
If the program accesses a text symbol when it is executed, the system automatically takes account of the logon language of the user and supplies the text in this language.
A text symbol is identified by means of a three-character alphanumeric ID xxx.
To use a text symbol in your program, you need to address it as TEXT-xxx, where xxx stands for the three-character text symbol ID.
You can also use the syntax '...'(xxx) where, '...' is the text of the text symbol in the original language of the program.

LOCAL VERSUS GLOBAL DATA TYPES



Global data types have at least three advantages over local data types:
  You can use global types systemwide, thereby enhancing the system’s consistency. As global types are reusable, you spend fewer resources on maintenance.

  In the ABAP Dictionary you can generate a where-used list for a global data type. This list names the Repository objects that use that data type.

  In addition to the technical information, global data types can also contain semantic information corresponding to the business descriptions of the objects being defined.

Local data types should be used only if the semantic information does not matter for the definition of the corresponding data objects.

VALUE ASSINGMENTS



Every elementary data object has a preassigned type-specific initial value, except if the VALUE addition was used to set a different value.
The MOVE statement helps transfer the contents of a data object to another data object.
The same effect is achieved by two different syntax variants:
  MOVE variable1 TO variable2.

  variable2 = variable1.

The CLEAR statement resets the contents of a data object to the type-related initial value.

CALCULATIONS



In ABAP you can program arithmetic expressions nested to any depth.
You can list some of the valid operations:
  + indicates addition.

  - indicates subtraction.

  * indicates multiplication.

  / indicates division.

  ** indicates exponentiation.

  DIV indicates integral division without remainder.

  MOD indicates remainder after integral division.

You can use the optional COMPUTE keyword for calculations that use these arithmetic expressions.


CONDITIONAL BRANCHES
There are two ways to execute different sequences of statements, depending on certain conditions.
In the IF construct you can define logical expressions as check conditions. If the condition is met, the system executes the relevant statement block. Otherwise, the condition specified in the next ELSEIF branch is checked. If none of the specified conditions are fulfilled, the ELSE branch is executed. ELSEIF and ELSE branches are optional.
The CASE construct is used to clearly distinguish cases. The content of the field specified in the CASE part is checked against the data objects listed in the WHEN branches to see whether they match. If the field contents match, the statement block is processed. If there are no successful matches, the system executes the OTHERS branch if it is available.
The IF and CASE constructs should be concluded with an ENDIF and an ENDCASE statement, respectively.


EXAMPLES: IF STATEMENTS

You can nest the IF and CASE structures in any way you wish: just keep the logic of every structure correct.
You can formulate negations by placing the NOT operator before the logical expression. When negating the IS INITIAL query, you can use the special IS NOT INITIAL query.


LOOPS



You can use four loop constructs in ABAP:
  The statement block between DO and ENDDO is executed continuously until the loop is left using termination statements such as EXIT. This is anunconditional or index-controlled loop.

  The statement block between WHILE and ENDWHILE is continuously executed until the specified condition is no longer met. The condition is always checked before executing the statement block. This is a header-controlled loop.

  You can use the SELECT loop to read several entries of a database table in succession.

  In an internal table, the same read function is implemented with the LOOP loop. This is a read loop.

In the DO and WHILE loops, the system field SY-INDEX contains the number of the current loop pass.


SOME INTRESTING SYSTEM FIELDS


The runtime system uses system fields to provide the application program with information about the actual system status. This slide depicts some interesting system fields and their meanings.

RETURN CODE OF AN ABAP STATEMENT


One of the most important system fields is the field sy-subrc. It is filled with the corresponding return code to indicate whether the statement was executed successfully. The value zero means that the statement was executed successfully.


DIALOG MESSAGES

You can send dialog messages to the users of your program by using the MESSAGE statement. You must specify the three-digit message number and the message class, which clearly identify the message to be displayed. The message type specifies where the message is to be displayed.
If the specified message contains placeholders, you can use the WITH addition to supply them with values from your program. Instead of the placeholders, the transferred values then appear in the displayed message text.


EXECUTE A PROGRAM IN DEBUGGING MODE



You have different options for starting a program in debugging mode from within the Object Navigator:
  In the navigation area for the selected program, choose the context menu and then the path: Execute → Debugging.

  In the editor area, select the requested program line from which you wish to debug. Choose the Set/Delete Breakpoint icon and start the program by choosing F8; otherwise, in the navigation area, choose the context menu and follow the path: Execute → Direct.

SWITCH TO DEBUGGING MODE AT RUNTIME



In order to debug a certain function of a program, you must first start the program without the Debugger and then switch to debug mode immediately before executing the function.
There are two ways of doing this:
  Choose System → Utilities → Debugging ABAP (or Debugging screen).

  Enter /h in the command field in the standard toolbar and click Enter.


ABAP DEBUGGER: SINGLE STEP AND FIELD CONTENTS


You can choose the option Single Step, to execute the program statement by statement. Furthermore, you can display data objects and their current content in the variable by double-clicking the corresponding data objects in the source code or by simply entering the name of the data object.

ABAP DEBUGGER: BREAKPOINTS



You can set a breakpoint in the new debugger with a single click before the line in the source code.
You can also set a breakpoint for specific ABAP statements by choosing: Breakpoints → Breakpoint at → Statement.
If you click Continue, the program is executed up to the next breakpoint.
The set breakpoints are only valid for the current debugger session. However, if you press Save, the breakpoints will stay in place for the duration of your current SAP session.

ABAP DEBUGGER: TRACING DATA CHANGES
Watchpoints are breakpoints that depend on the field content.
If you set a watchpoint without specifying a relational operator or comparative value on a field and choose Continue, then the program is executed until the content of the field changes.
However, if you specify the relational operator and comparative value and choose Continue, then the program will be executed until the specified condition is met.


ABAP DEBUGGER: CHANGING FIELD CONTENTS
To change the content of a field during debugging, double-click Change in the variable display: now the value is ready for input.
You can now change the field value and confirm the change by choosing ENTER. The value is now changed while the debugger is running.



ADDITIONAL FUNCTIONS OF THE NEW DEBUGGER


A number of useful functions have been added in the new debugger with the release of SAP NetWeaver 7.0.
In the Object Navigator you can determine which debugger you want to use as standard by following the path:
Utilities → Settings → ABAP Editor → Debugging.

No comments:

Post a Comment