Parameters in ABAP

  • Parameters keyword allows the user to provide values for variables through the input screen.
  • The input screen can be generated by the keywords Parameters or Select-options.
  • Technically input screen is known as Selection Screen. It’s screen number is standard and is 1000.
Ex. PARAMETERS A TYPE I.

PARAMETERS file_name(40) TYPE C DEFAULT 'c:\sample.txt'.
  • The data types F(Float), STRING and XSTRING are not allowed with parameters.

Parameters keyword can be used to generate Check boxes and Radio buttons on the selection screen. Continue reading “Parameters in ABAP”

ABAP Data Types

ABAP report program’s structure

  • Report Statement.
  • Macro Definitions.
  • Data Objects’s Declarations.
  • Selection-Screen Designing Statements.
  • Selection-Screen Events.
  • Main Program Events.
  • List Screen Events.
  • Subroutine Definitions.

Most of the above sections are optional. REPORT keyword and Main program logic are mandatory.

Data Types

These are built-in types of SAP-ABAP language.

DATA keyword and these Data Types together are  used to declare Data Objects.

Data Objects are simply variables which represent Memory Locations in Application Server’s temporary memory RAM.

Type I

Integer type for Integer numbers.

Example:

DATA var_num TYPE I.

Creates a variable var_num with initial value 0.

DATA var_num TYPE I value 45.

Creates a variable var_num with initial value 45.

Type F

Floating point type for Floating point (Fractional) numbers.

Example:

 DATA var_num TYPE F.

creates a variable var_num with initial value 0.0

DATA var_num TYPE F VALUE '45.723'.

creates a variable var_num with initial value 45.723

by default displays values in Exponential format / Scientific format

Example:

WRITE var_num.            //Output will be 4.5722999E+01

Its mathematical equivalent is 4.5723X10^1

Type P

Packed type for Packed (Fractional) numbers.

Example:

DATA var_num TYPE P DECIMALS 3.

creates a variable var_num with initial value 0.000

DATA var_num TYPE P DECIMALS 3 VALUE '45.723'

by default displays values in Fractional format.

Example:

WRITE var_num.      //Output will be 4.5723

Always specify fractional values / exponential values as strings in Single Quotes

Example:

var_num = '45.723'.

var_num = '45723E-3'.

Number of Decimal places and value of exponent in Exponential form can be adjusted at the time of display.

Example:

 WRITE var_num EXPONENT 3.

WRITE var_num DECIMALS 3.

WRITE var_num EXPONENT 4 DECIMALS 3.

Maximum number of Decimal Places possible are 14 only.

Type C

Character type for Fixed Size Character type values (Strings).

Example:

DATA var_opt TYPE C.

creates a variable var_opt with initial value SPACE.

DATA var_name (40) TYPE C VALUE 'America'.

creates var_name with initial value ‘America’.

40 indicates width of the string in number of characters.

This is default data type in SAP-ABAP. Its default length is 1 character.

Example:

DATA var_opt.
DATA var_opt TYPE C.

both create a single character variable.

DATA var_name(45).

DATA d_name(45) TYPE C.

Both create a character variable of size 45 characters.

Type STRING

String type for Varying Size Character type values (Strings).

Example:

DATA var_name TYPE STRING.

creates a variable var_name with initial value all SPACES.

DATA var_name TYPE STRING VALUE 'America'.

creates var_name with initial value ‘America’.

Size of the string variable depends on the length of the String variable assigned to it.

Type N

Numeric type for Positive Integers only with Leading zeroes.

Example:

DATA var_num TYPE N.

creates a variable var_num with initial value 0.

DATA var_num(10) TYPE N VALUE '345'.

creates var_num with initial value ‘0000000345’.

If assigned string contains other than digit characters then they will be ignored.

Type D

Data type for representing Date values.

Internal format of Date that must be mentioned at the time of coding is

YYYYMMDD

The size if fixed and it is 8 characters.

Example:

DATA var_date TYPE D.

creates a variable var_date with initial value all 0s.

DATA var_date TYPE D VALUE '19470815'.

creates var_date with initial value 1947 August 15th.

External format of the date can be adjusted by the user as per his requirement by the menu path

MenuBar -> System -> User Profile -> Own Data -> Defaults tab

Type T

Time type for representing Time values

Internal format of Time that must be mentioned at the time of coding is

HHMMSS

The size is fixed and it is 6 characters.

Example:

DATA timein TYPE T.

creates a variable timein with initial value all 0s.

DATA timein TYPE T value '084530'.

creates timein variable with initial value 08:45:30.

Example ABAP Program

Prepare an ABAP program to find the sum of two numbers 11 and 22. Display result in three different ways.

Report.

DATA a TYPE I.

DATA b TYPE I.

DATA s TYPE I.

A = 11.

B = 22.

S = A + B.

WRITE S.            "Here output will be 33.

WRITE: / 'The sum of' , A, 'and', B, 'is', S.

"here the output will be..."The sum of 11 and 22 is 33"

WRITE:/ A, '+', B, '=', S.

"here the output will be..."11 + 22 = 33"

 

 

Definition of Data Dictionary in ABAP

A data dictionary in computing terms is the source of information in which the system data is defined in a logical way. The data dictionary is the centralized and structured source of information for business applications.

The ABAP data dictionary (DDIC) can be seen as a logical representation or a superior layer over the physical underlying database.

The elements that make up a DDIC are known as metadata. Metadata is the computing term for the data whose function is to describe other data.

An advantage of having a DDIC is avoiding inconsistencies when defining data types that will later be used in different parts of an application; this avoids redundancies and considerably decreases the cost of maintenance.

When a type of data is defined in DDIC, it is available to any program or function module in the application. A change in the definition of a type of data in the DDIC automatically affects any other data, module, function, or program which has data or variables defined using the modified data type.

The ABAP DDIC is the core of the R/3 development system. It is the source of every definition within R/3, from the very basic domains to the company model. It is totally integrated with the other tools of the development environment.

Transaction code SE11 for Data Dictionary and SE16 for Data Browser.

Data Dictionary Objects

abap-dictionary

  1. Database Tables
  2. Views
  3. Data Elements
  4. Structures
  5. Table Types
  6. Type Groups
  7. Domains
  8. Search Helps
  9. Lock Objects

 

Declarative Statements in ABAP

These statements define data types or declare data objects which are used by the other statements in a program or routine.

Ex:

TYPES, DATA, TABLES, CONSTANTS, FIELD-SYMBOLS, PARAMETERS, SELECT-OPTIONS

Constants  This keyword is for declaring constant identifiers.

CONSTANTS PI TYPE P DECIMALS 3 VALUE ‘3.147’.

Constants cannot be modified in the further program.

Field-Symbols These are similar to pointers in C language. Used for referring to any type of data object in a program.

FIELD-SYMBOLS: <FS1>, <FS2>.

DATA:  A TYPE I, str(20) TYPE C.

ASSIGN  A TO <FS1>.

WRITE <FS1>.    //Value of A will be displayed

ASSIGN STR TO <FS1>.

WRITE <FS1>.   //Value of STR will be displayed.

Types This keyword is used to define new user defined data types.

TYPES FLOATING TYPE P DECIMALS 6.

DATA A TYPE FLOATING.

DATA B TYPE FLOATING.

Tables This keyword is used to create a structure in RAM corresponding to a database table.

TABLES: mara, vbrk.

Type-Pools This keyword is used to attach a Data Dictionary (DDIC) type group to the current program. Type Group is a central repository object that maintains definitions of user defined data types.

TYPE-POOLS SLIS.              //Used in ALV Reporting

TYPE-POOLS SSCRFIELDS.     //Used for selection screen.

 

Courtesy: ABAP Technical Documentation

System Fields in ABAP

All the below system fields belong to the data dictionary (DDIC) Structure – SYST.

SY-INDEX for loop counting
SY-SUBRC condition of previous statement
SY-FDPOS position of substring in main string (works with SEARCH)
SY-ABCDE a string of 26 characters
SY-ULINE for horizontal lines of any length
SY-VLINE for only one vertical character
SY-DATUM for application server’s date
SY-UZEIT for application server’s current time
SY-DATLO for Presentation server’s date
SY-TIMLO for Presentation server’s current time
SY-DBSYS backend database name
SY-HOST name of application server
SY-SYSID name of the R/3 system
SY-OPSYS name of application server’s operating system
SY-MANDT Logon client number
SY-UNAME Logon User name
SY-LANGU Logon language
SY-MSGID message class name
SY-MSGNO message number
SY-MSGTY message type
SY-MSGV1 message variable 1
SY-MSGV2 message variable 2
SY-MSGV3 message variable 3
SY-MSGV4 message variable 4
SY-LSIND secondary list index
SY-PAGNO current page number
SY-LINSZ current width of a line
SY-LINCT current number of lines per page
SY-TABIX index of internal table’s record
SY-DBCNT no. of records processed by database statement
SY-DYNNR current screen number
SY-REPID current program name
SY-TITLE title of the program
SY-PFKEY name of the current GUI status
SY-UCOMM funtion code of the current pushbutton or menu option

Courtesy: ABAP Technical Documentation

How to write ABAP routine to look up a DSO Active table

Looking up a table while doing data load is a common scenario in SAP BW.

Here the look up table can be active table of some other DSO.

You can note a point here that cube cannot be used for look up. This is because, a cube has a fact table which is based on star schema. Hence the primary keys in a fact table will be dimension ids instead of the primary key values.

Now coming to our scenario, suppose data is loaded from DSO1 to CUBE1. Continue reading “How to write ABAP routine to look up a DSO Active table”