Thursday, 11 July 2013

JULY 11


 I learned about defining modifiable data objects using "DATA" Statement and "PARAMETER" statement and implementing it using programs.

 Variables(modifiable data object)

Two statements are commonly used to define variables in an ABAP/4 program:

·         data

·         parameters

Data Statement to Define Variables

Using data statement, variables can be declared for the program. Variables defined in the data statement are assigned to a data type and can also have defaults.

Syntax for the data Statement


data v1 [(l)] [type t] [decimals d] [value 'xxx'].
or
data v1 like v2 [value 'xxx'].

where:

·         v1 is the variable name.

·         v2 is the name of a variable previously defined in the program, or is the name of a field that belongs to a table or structure in the Data Dictionary.

·         (l) is the internal length specification.

·         t is the data type.

·         d is the number of decimal places (used only with type p).

·         'xxx' is a literal that supplies a default value.

 

Examples of Variables Defined with the DATA Statement 

data f1(2) type c.
data f2 like f1.
data max_value type i value 100.
data cur_date type d value '19980211'.


NOTE: Variable names can be 1 to 30 characters long. They can contain any characters except 
( ) + . , : and must contain at least one alphabetic character. SAP recommends that variable names should always begin with a character and they should not contain a dash. A dash has special meaning. Instead of a dash, we should use an underscore ( _ ).

The following points also apply to the data statement:

·         The default length depends on the data type.

·         The default data type is c (character).

·         The default initial value is 0, except for data type c, which is blank.

·         The value addition only accepts a literal or constant; we cannot use a variable to supply a default value.

·         When using the like addition, the variable being defined obtains its length and data type from the referenced variable. We cannot specify them on the same statement with like. 

·         When using the like addition, the value is not obtained from the referenced variable. we can specify the value addition to give the variable a default value. If we do not, it is assigned a default initial value of 0 (or blank for a character data type).

The data statement can appear anywhere in a program. The definition for a variable must physically come before the statements that access it. If we place a data statement after executable code, the statements above it cannot access the variables it defines.


Example of a Variable That Is Incorrectly Accessed Before It Is Defined

report zprogram.
data f1(2) value 'Hi'.
write: f1, f2.
data f2(5) value 'there'.

The variable F2 is defined on line 4, and the write statement on line 3 is trying to access it. This will generate a syntax error. The data statement on line four should be moved before line 3.

Parameters Statement to Define Variables

A parameter is a special type of variable that is defined using the parameters statement. parameters is a lot like the data statement, but when we run the program, the system will display the parameters as input fields on a selection screen before the program actually begins to execute. The user can enter or modify their values and then press the Execute button to begin program execution. we can use both parameters and data in the same program. The rules for parameter names are the same as for variable names, except for the following:
  • The maximum length is 8 characters instead of 30.
  • In addition to literals and constants, you can also use a variable to supply default a default value.

Syntax for the parameters Statement

parameters p1[(l)] [type t] [decimals d] ...
or
parameters p1 like v1 ...
... [default 'xxx'] [obligatory] [lower case] [as checkbox] [radiobutton
    group g].
where:
  • p1 is the parameter name.
  • v1 is the name of a previously defined variable or parameter, or is the name of a field that belongs to a table or structure in the Data Dictionary.
  • (l) is the internal length specification.
  • t is the data type.
  • d is the number of decimal places (used only with type p).
  • 'xxx' is a literal or previously defined variable that supplies a default value.
Examples of parameters defined with the parameters statement.
parameters p1(2) type c.
 parameters p2 like p1.
 parameters max_value type i default 100.
 parameters cur_date type d default '19980211'.

Wednesday, 10 July 2013

JULY 10


 I learned about data objects, their definition and declaration.

DATA OBJECTS

Defining Data 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.

 Data objects are memory locations that you use to hold data while the program is running. There are two types of data objects: modifiable and non-modifiable. The types of non-modifiable data objects are literals and constants
The modifiable data objects are variables, field strings, and internal tables. 
A field string is the ABAP/4 equivalent of a structure. An internal table is the ABAP/4 equivalent of an array. When the program starts, the memory allocation for each data object occurs in the roll area of the program. While the program is running, we can read the contents of a non-modifiable data object or put data into a modifiable data object and then retrieve it. When the program ends, the system frees the memory for all data objects and their contents are lost.
Data objects have three levels of visibility: local, global, and external. The visibility of a data object indicates from where in the program the data object is accessible.
Locally visible data objects are accessible only from inside the subroutine in which they are defined. Globally visible objects can be accessed from anywhere within the program. Externally visible objects are accessible from outside of the program by another program.

The following figure displays these three levels of visibility pictorially.



The local data objects in subroutine 1A are visible only from within that subroutine. Any statement outside of it cannot access them. Similarly, the local data objects in subroutines 1B and 2A are not accessible from anywhere but within those subroutines.
Any statement in program 1, regardless of where the statement appears, can access the global data objects in program 1. Similarly, any statement in program 2 can access the global data objects in program 2.
The external data objects could be accessed from any statement in program 1 or program 2. In actuality, whether they can be or not depends on the type of external memory area used and the relationship between the two programs.


Declaring Data Objects

Apart from the interface parameters of routines, we 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.

Defining Literals (non-modifiable data objects)

literal is a non-modifiable data object. Literals can appear anywhere in a program, and they are defined merely by typing them where needed. There are four types: character string, numeric, floating-point, and hexadecimal.

Character String Literals

Character string literals are case-sensitive character strings of any length enclosed within single quotes. For example, 'JACK' is a character string literal containing only uppercase characters. 'Caesar the cat' is a character string literal containing a mixture of upper- and lowercase characters.
Because a character string literal is enclosed by quotes, we cannot use a single quote by itself in the value of the literal. To represent a single quote, we must use two consecutive single quotes. 
For example, the statement write 'Caesar''s tail'. will write Caesar's tail, but the statement write 'Caesar's tail' will cause a syntax error because it contains a single quote by itself.

Numeric Literals

Numeric literals are hard-coded numeric values with an optional leading sign. They are not usually enclosed in quotes. However, if a numeric literal contains a decimal, it must be coded as a character string enclosed within single quotes. If it is not, the syntax error Statement x is not defined. Please check your spelling. will occur.
For example, 256 is a numeric literal, as is -99'10.5' is a numeric literal that contains a decimal point, so it is enclosed by single quotes. A literal can be used as the default value for a variable, or it can be used to supply a value in a statement.
Examples of invalid literals are: 99- (trailing minus sign), "Confirm" (enclosed in double quotes), and 2.2 (contains a decimal but is not enclosed in quotes).

Floating-Point Literals

Floating-point literals are specified within single quotes as '<mantissa>E<exponent>'. The mantissa can be specified with a leading sign and with or without decimal places, and the exponent can be signed or unsigned, with or without leading zeros.
For example, '9.99E9''-10E-32', and '+1E09' are valid floating-point literals.

Hexadecimal Literals

hexadecimal literal is specified within single quotes as if it were a character string. The permissible values are 0-9 and A-F. There must be an even number of characters in the string, and all characters must be in uppercase.
Examples of valid hexadecimal literals are '00''A2E5', and 'F1F0FF'
Examples of invalid hexadecimal literals are 'a2e5' (contains lowercase characters), '0' (contains an uneven number of characters), "FF"(enclosed in double quotes), and x'00' (should not have a preceding x).

Right and Wrong Ways to Code Literals

Right
Wrong
Explanation
-99
99-
Trailing sign not permitted on a numeric unless it's within quotes.
'-12'

Numerics within quotes can have leading'12-'or trailing sign.
'12.3'
12.3
Numerics containing a decimal point must be enclosed in single quotes.
'Hi'
"Hi"
Double quotes are not permitted.
Right
Wrong
Explanation
'Can''t'
'Can't'
To represent a single quote, use two consecutive single quotes.
'Hi'
'Hi
Trailing quote is missing.
'7E1'
7E1
Floating-point values must be enclosed within quotes.
'7e1'

Lowercase e is allowed for floating-point literals.
'0A00'
'0a00'
Lowercase in hexadecimal literals gives incorrect results.
'0A00'
'A00'
An uneven number of hexadecimal digits gives incorrect results.
'0A00'
X'0A00'
A preceding or following character is not permitted for hexadecimal literals.

Tuesday, 9 July 2013

JULY 9


Introduction to Source Code editor , its functionality and familiarization to tools of the editor.

The Source Code Editor

We use two types of screens :
  • ABAP/4 Editor: Initial Screen
  • ABAP/4 Editor: Edit Program screen

The ABAP/4 Editor: Initial screen is shown as below-


From there, we can display or change all program components. For example, to change the source code component, we can choose the Source Code radio button and then press the Change button. Or, to display the attributes component, choose the Attributes radio button and then press the Display button.
Pressing the Change button displays the selected component in change mode, which enables you to change the component.

NOTE:
In above figure,  the Object Components group box encloses radio buttons, the Display button, and the Change button. When we see a group box enclosing both radio buttons and push-buttons, the radio buttons deter-mine the component acted upon by the enclosed push-buttons. The effect of the radio buttons is limited by the group box; they have no effect on push-buttons outside the box.

Functionality of the Source Code Editor

From the ABAP/4 Editor: Initial Screen, choose the Source Code radio button and press the Change button. The ABAP/4 Editor: Edit Program screen is shown, as in Figure below.





The Standard Toolbar

The Standard toolbar controls and the Application toolbar controls are shown in Figure below.


The Standard toolbar controls in order, are:
    • Enter: Pressing the Enter button has the same effect as pressing the Enter key. It is also the split line function. To split a line of code, position the cursor at the point where we want to split the line and press Enter.
    • Command Field: This accepts transaction codes and various other commands.
    • Back and Exit: Both return  to the ABAP/4 Editor: Initial Screen. If we have unsaved changes, we will be prompted to save them.
    • Cancel: Returns  to the ABAP/4 Editor: Initial Screen without saving our changes. If we have unsaved changes, we will be prompted to save them.
    • Print: This will print the source code of our program. When we press it, the Print Parameters screen is displayed. To receive the output,the Print Immed. check box is checked.
    • Find: Provides search and replace functionality. When we press it, the Search/Replace screen is shown. 
    • Find Next: This is a handy shortcut for finding the next occurrence of a string.
    • First Page, Previous Page, Next Page, and Last Page: These enable us to page up and down through the source code.
    • Help: Displays a dialog box from which we can obtain help about the editor and ABAP/4 syntax, among other things. Position the cursor on an ABAP/4 keyword or a blank line before pressing the Help button. 

    The Application toolbar controls, in the order they appear on the toolbar, are as follows:
    • Display <-> Change: Changes the screen from display mode to change mode. Press it again to change it back to display mode.
    • Check: Checks the syntax of the current program.
    • Where-Used List: When we press this button while our cursor is on any variable name, it will display all the lines of code that use it.
    • Stack: Displays the contents of the current navigation stack.
    • Cut: Deletes the line containing the cursor and places it in the buffer.
    • Copy To Buffer: Copies the contents of the line containing the cursor to the buffer.
    • Insert From Buffer: Inserts the contents of the buffer to a new line above the current cursor position.
    • Insert Line: Inserts a blank line above the current cursor position.
    • Select: Selects a single line or a block of lines for moving, cutting, and pasting. Place the cursor on the first line of the block and press Select. Place the cursor on the last line of the block and press Select again. The lines contained in the block will turn red. We can now cut, copy, or duplicate the block of code the same way we did for a single line. To deselect the selected lines, choose the menu pathEdit->Deselect.
    • Undo: Reverses your last change. Only one level of undo is available.
    • ABAP/4 Help: Provides help about the editor and about ABAP/4 in general.
    • Pattern: Enables to insert an automatically generated ABAP/4 statement. 
    • Concatenate: Joins two lines together. To use it, place the cursor at the end of a line and press the Concatenate button to concatenate the next one to it. To split a line, position the cursor where we want the split to occur and press the Enter key.
    • Duplicate Line: Duplicates a single line or an entire block of code if one is selected .
    • Move Line: Moves lines left and right. To move a line, put the cursor at the target position and press the Move Line button. To move a whole block of code, mark the block and place the cursor on the first line of the block at the position to which it should be moved, and then press the Move Line button. To move it to the left, place the cursor to the left of the beginning of the line and press the Move Line button.
    • Mark Line: Places a bookmark on a line. We can display all marked lines with the menu path Goto -> Markers.



    Monday, 8 July 2013

    JULY 8

    I learned to know the Program Types, Report Components and created the first program.


    Exploring the Development Environment

    development object is anything created by a developer. Examples of development objects are programs, screens, tables, views, structures, data models, messages, and includes.
    The R/3 system contains tools for creating and testing development objects. These tools are located in the R/3 Development Workbench. To access any development tool, we go to the workbench.
    The workbench contains these tools to help us create development objects:


    • The ABAP/4 program editor where we can create and modify ABAP/4 source code and other program components
    • The Data Dictionary where we can create tables, structures, and views
    • The Data modeler where we can document the relationships between tables
    • The Function library where we can create global ABAP/4 function modules
    • The screen and menu painters where we can create a user interface for our programs
    The following testing and search tools are also available:


    • the ABAP/4 Debugger
    • the SQL trace tool used to tune SQL statements
    • the runtime analyzer for optimizing our program's performance
    • a where-used tool for impact analysis
    • a computer-aided test tool for regression testing
    • a repository search tool for finding development objects
    • the Workbench Organizer for recording changes to objects and promoting them into production

    All development objects are portable, meaning that we can copy them from one R/3 system to another. This is usually done to move our development objects from the development system to the production system. If the source and target systems are on different operating systems or use different database systems, our development objects will run as-is and without any modification. This is true for all platforms supported by R/3.


    Discovering Program Types

    There are two main types of ABAP/4 programs:
    • reports
    • dialog programs

    Defining Reports

    The purpose of a report is to read data from the database and write it out. It consists of only two screens.



    The first screen is called the selection screen. It contains input fields allowing the user to enter criteria for the report. For example, the report may produce a list of sales for a given date range, so the date range input fields would appear on the report's selection screen.
    The second screen is the output screen. It contains the list. The list is the output from the report, and usually does not have any input fields. In our example, it would contain a list of the sales that occurred within the specified date range.
    The selection screen is optional. Not all reports have one. However, all reports generate a list.


    Defining Dialog Programs

    Dialog programs  are more complex at the program level. They can contain any number of screens, and the screen sequence can be changed dynamically at run time. On each screen, we can have input fields, output fields, pushbuttons, and more than one scrollable area.


    Discovering Report Components

    ABAP/4 reports consist of five components
    • Source Code
    • Attributes
    • Text elements
    • Documentation
    • Variants
    Only the source code and program attribute components are required. The rest of the components are optional.
    All development objects and their components are stored in the R/3 database.


    Discovering the Program Run-time Object

    ABAP/4 programs are interpreted; they are not compiled. The first time we execute a program, the system automatically generates a run-time object. The run-time object is a pre-processed form of the source code. However, it is not an executable that we can run at the operating system level. Instead, it requires the R/3 system to interpret it. The run-time object is also known as the generated form of the program.
    If we change the source code, the run-time object is automatically regenerated the next time we execute the program.



    Introduction to Program Naming Conventions

    The company we work for is a customer of SAP. Therefore, programs that we create at our company are called customer programs.
    Customer development objects must follow naming conventions that are predefined by SAP. These conventions are called the customer name range.  For Programs-
    •  the customer name range is two to eight characters long 
    • the program name must start with the letter y or z. SAP reserves the letters a through x for their own programs.

    Creating My First Program

    What follows is a description of the process that we will follow to create a program.
    When we sign on to R/3 to create our first ABAP/4 program, the first screen we see will be the SAP main menu. From there, we will go to the Development Workbench, and then to the editor. We will enter a program name, and create the program. The first screen we will see will be the Program Attributes screen. There, we must enter the program attributes and save them. We will then be allowed to proceed to the source code editor. In the source code editor, we will enter source code, save it, and then execute the program.

    We can follow this procedure to create our first program. 
    1. From the R/3 main menu, select the menu path Tools->ABAP/4 Workbench. A screen with the title ABAP/4 Development Workbench is displayed.
    2. Press the ABAP/4 Editor button on the application toolbar. The ABAP/4 Editor: Initial Screen is displayed.
    3. In the Program field, type the program name Zdemo_program.
    4. Press the Create button. The ABAP/4: Program Attributes screen is displayed. The fields containing question marks are required.
    5. Type My First ABAP/4 Program  in the Title field. By default, the contents of this field will appear at the top of the list.
    6. Type "executable program" in the Type field. It indicates the program is a report.
    7. Type "test program" in the status field.
    8. Type "Basis"  in the Application field. The value in the Application field indicates to which application area this program belongs. The complete list of values can be obtained by positioning your cursor on this field and then clicking on the down-arrow to the right of it..
    9. To save the program attributes, press the Save button on the Standard toolbar. The Create Object Catalog Entry screen is displayed.
    10. Type "$TMP" in the package field and press the Local Object button. The program attributes screen is re-displayed. In the status bar at the bottom of the screen, the message "Attributes for program saved" appears. 
    11.  The ABAP/4 Editor: Edit Program screen is displayed.
    12. At line 1 it contains the statement Report zdemo_program.If it does not contain this statement , type it then.
    13. On line 2, type write 'Hello SAP world'. Use single quotes and put a period at the end of the line.
    14. Press the Save button on the Standard toolbar.
    15. To execute your program, choose the menu path Program->Execute. A screen with the title My First ABAP/4 Program is displayed, and the words Hello SAP world are written below it. This is the output of the report, also known as the list.
    These are the Common Problems Encountered While Creating a Program and Their Solutions

    Trouble
    Solution
    When we press the Create button, we get a dialog box saying Do Not Create Objects in the SAP Name Range.We have entered the wrong program name. Our program names must start with y or z. Press the Cancel button (the red X) to return and enter a new program name.
    When we press the Create button, we get a dialog box with an input field asking for a key.We have entered the wrong program name. Our program names must start with y or z. Press the Cancel button (the red X) to return and enter a new program name.
    We are getting a Change Request Query screen asking for a Request Number.On the Create Object Catalog Entry screen, do not enter a value in the Development class field.
    Press the Local Object button instead.
    Various transaction codes (T-codes) are used in ABAP/4. Most frequently used one are:
    • se38 - ABAP editor 
    • se11 - ABAP dictionary
    • se51 - screen painter
    • se80 - object navigator

    In the above given steps for creating program, we can replace step 1 and step 2 by using T-code se38. It will directly take us to program field.

    Friday, 5 July 2013

    JULY 5


    On the fourth day of my training I  learned about various elementary , reference and complex data types and their length in ABAP/4.

    Data Types in ABAP/4


    Programs work with local data. Data consists of strings of bytes in the memory area of the
    program. A string of related bytes is called a field. Each field has an identity (a name) and a
    data type. All programming languages have a concept that describes how the contents of a field
    are interpreted according to the data type.
    In the ABAP type concept, fields are called data objects. Each data object is an instance of an
    abstract data type. Data types in ABAP are not just attributes of fields, but can be defined in their
    own right. There are separate name spaces for data objects and data types. This means that a
    name can at the same time be the name of a data object as well as the name of a data type.
    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.
    We can then use them later on in conjunction with a data object. We can define data types
    independently either in the declaration part of an ABAP program (using the TYPES statement), or
    in the ABAP Dictionary.

    ABAP contains the following data types:

    • elementary
    •  reference
    •  complex types.

    Elementary Types

    Elementary types are the smallest indivisible unit of types. They can be grouped as those withfixed length and those with variable length.

    • Fixed-Length Elementary Types:   

    There are eight predefined types in ABAP with fixed length:
    Four character types: Character (C), Numeric character (N), Date (D), and Time (T).
     One hexadecimal type: Byte field (X).

    List of Pre-defined Data Types


    Data
    Type
    Internal
    Description
    Default
    Internal
    Length
    Max
    Internal
    Length

    Valid
    Values
    Default
    Initial
    Value
    c
    character
    1
    65535
    Any char
    Blank
    n
    numeric text
    1
    65535
    0-9
    0
    d
    date
    8 (fixed)
    -
    0-9
    00000000
    t
    time
    6 (fixed)
    -
    0-9
    000000
    x
    hexadecimal
    1
    65535
    Any
     


    Three numeric types: Integer (I), Floating-point number (F) and Packed number (P).

    List Of Numeric Data Types

    Data
    Type


    Description
    Default
    Internal
    Length

    Max
    Length

    Max
    Decimals

    Valid
    Values
    Default
    Initial
    Value
    i
    integer
    4(fixed)
    -
    0
    -231 to +231
    0
    p
    packed decimal
    8
    16
    14
    0-9 .
    0
    f
    floating-point
    8
    8
    15*
    -1E-307 to 1E308
    0.0

    • Variable-Length Elementary Types:

    There are two predefined types in ABAP with variable length:
    STRING for character strings
    XSTRING for byte strings

    Reference Types :

    Reference types describe data objects that contain references (pointers) to other objects (data
    objects and objects in ABAP Objects). There is a hierarchy of reference types that describes the
    hierarchy of objects to which the references can point. There are no predefined references - we
    must define them ourself in a program.

    Complex Types:

    Complex types are made up of other types. They allow us to manage and process
    semantically-related data under a single name. We can access a complex data object either as
    a whole or by individual component. There are no predefined complex data types in ABAP. We
    must define them either in our ABAP programs or in the ABAP Dictionary.

    Complex types are divided further into structures and internal tables.

    • Structures

    A structure is a sequence of any elementary types, reference types, or complex data types.
    We use structures in ABAP programs to group work areas that logically belong together. Since
    the elements of a structure can have any data type, structures can have a large range of uses.
    For example, we can use a structure with elementary data types to display lines from a database
    table within a program.
    The following terms are important when we talk about structures:

    • Nested and non-nested structures
    • Flat and deep structures

    A nested structure is a structure that contains one or more other structures as components. Flat
    structures contain only elementary data types with a fixed length (no internal tables, reference

    types, or strings). The term deep structure can apply regardless of whether the structure is nested or not. Nested structures are flat so long as none of the above types is contained in any
    nesting level.
    • Internal Tables

    Internal tables consists of a series of lines that all have the same data type. Internal tables are
    characterized by:

    1. The line type, which can be any elementary type, reference type, or complex data type.
    2. The key identifies table rows. It is made up of the elementary fields in the line. The key can be unique or non-unique.
    3. 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 we can access the table either by specifying the index or the key.Hashed tables have no linear index. We can only access hashed tables by specifying  the key. The system has its own hash algorithm for managing the table.

    Examples for Complex Data Types

    The following list contains examples of complex data types in ascending order of complexity:
    1. Structures consisting of a series of elementary data types of fixed length (non-nested, flat
    structures)

    2. An internal table whose line type is an elementary type (vector).
     
    3. Internal tables whose line type is a non-nested structure ('real' table)

    4. Structures with structures as components (nested structures, flat or deep)

    5. structures containing internal tables as components (deep structures)

    6. Internal tables whose line type contains further internal tables.