Ads

Constant and Literals in SAP ABAP programming

Constant and Literals in SAP ABAP programming


In SAP,there is available two types of literals that are Numeric and Character.Literals are unnamed data objects which we can create within the ABAP program.They are predefined by their value and we can't change value of literal.We creates constants using declarative statements .Constants are named data objects and assigning a value to it and can not be changed constant while executing the program.

Literals
Constants

Literals


Numeric literals are number literals which are sequence of digits and having prefixed signs.

Example:1000,-45,+72.



Character literals are sequence of alphanumeric characters in the ABAP program declared within the single quotation marks.They have predefined data type C.

Text field literals 

REPORT Z_LIT_EX. Write 'sinu abap tutor'.
Write / 'ABAP Tutorials'.

String field literals 

REPORT Z_LIT_EX1. Write `sinu abap tutor `. Write / `ABAP Tutorials'.

The output is same in both the above cases:
sinu abap tutor
ABAP Tutorial

Constants


We are delcaring constant statements using the constant statement.

CONSTANTS <f> TYPE <type> VALUE <val>.
The CONSTANTS statement is equal to the DATA statement.

<f> is a name for the constant. TYPE <type> represents a constant named <f>, which derives the same technical attributes as the existing data type <type>. VALUE <val> assigns an initial value.
 to the declared constant name <f>.

Constants are three types which are elementary, complex and reference constants.

Elementary constant.

REPORT ZR_SAP_E. CONSTANTS TUT TYPE P DECIMALS 4 VALUE '1.536'.
Write: / 'The value of TUT is:', TUT.
The output is:
The value of TUT is: 1.536.


Complex constants:

BEGIN OF INISTITUTE,
Sinu(25) TYPE C VALUE 'ABAPER',
tutor(40) TYPE C VALUE 'tutorial',
abap(10) TYPE C VALUE 'course',
END OF INISTITUTE.

Here, Institute is a complex constant fields.



Constant reference: 

CONSTANTS sinu_tutor TYPE REF TO object VALUE IS INITIAL.
We can use the constant reference in comparisons.

Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced