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"

 

 

Comments

Popular posts from this blog

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

OPEN SQL EXAMPLES IN ABAP – PART 2

Domains and Data Elements