

{"id":92390,"date":"2021-05-18T09:00:17","date_gmt":"2021-05-18T03:30:17","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=92390"},"modified":"2021-11-29T13:30:31","modified_gmt":"2021-11-29T08:00:31","slug":"abap-data-types-variables-constants-literals","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/","title":{"rendered":"SAP ABAP Data Types, Variables, Constants &amp; Literals"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In this tutorial, we are going to learn about SAP ABAP data types, variables, constants and literals. Like any other object-oriented programming language, you need data types, variables, constants and literals to facilitate ABAP programming. Let\u2019s learn what they are all about.<\/span><\/p>\n<h3>What are Data Types?<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Think about the different kinds of data we have &#8211; characters, text, numbers, and so on.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">For a computer to perform functions on data, it is a much easier process if it falls under a pre-defined category.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Declaring a type for the data that we have speeds up execution considerably, and also reduces the time identifying data that would have otherwise been spent on producing useful output for the code.<\/span><\/li>\n<\/ul>\n<h3>Data Types in ABAP<\/h3>\n<p><span style=\"font-weight: 400\">In ABAP, we have several types of fixed as well as variable data types, as follows:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>TYPE<\/b><\/td>\n<td><b>KEYWORD<\/b><\/td>\n<td><b>DESCRIPTION<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Byte Field<\/span><\/td>\n<td><span style=\"font-weight: 400\">X<\/span><\/td>\n<td><span style=\"font-weight: 400\">Byte number in hexadecimal &#8211; e.g. 2B, 511, DC, etc.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Text Field<\/span><\/td>\n<td><span style=\"font-weight: 400\">C<\/span><\/td>\n<td><span style=\"font-weight: 400\">Any kind of alphanumeric or special character &#8211; e.g. \u2018c\u2019<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Integer<\/span><\/td>\n<td><span style=\"font-weight: 400\">I<\/span><\/td>\n<td><span style=\"font-weight: 400\">Any kind of number e.g. 24, 1, -3478<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Floating Point<\/span><\/td>\n<td><span style=\"font-weight: 400\">F<\/span><\/td>\n<td><span style=\"font-weight: 400\">Numbers with decimal point &#8211; e.g. 3.14, 2.0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Packed Number<\/span><\/td>\n<td><span style=\"font-weight: 400\">P<\/span><\/td>\n<td><span style=\"font-weight: 400\">Number defined by parameters \u2018length\u2019 and \u2018decimal\u2019 places &#8211; e.g. <\/span><span style=\"font-weight: 400\">100000000.00<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">String<\/span><\/td>\n<td><span style=\"font-weight: 400\">STRING<\/span><\/td>\n<td><span style=\"font-weight: 400\">A series of alphanumeric and special characters &#8211; \u201cData Flair\u201d, \u201cSAP #2\u201d, \u201cABAP123\u201d<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Complex and Reference Data Types in ABAP<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">There are also complex data types in ABAP.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Complex types are for structures (object made of components stored one after the other in memory) and tables (a 2D structure of rows and columns in which data is stored sequentially).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">For structure types, the primary data types as well as nested structures may be grouped together.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">When these primary types are grouped together, the entire structure can be accessed as one or the individual elements can be retrieved as well &#8211; this is known as internal tables in ABAP.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Now let\u2019s see with what parameters these internal tables can be described &#8211;<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>PARAMETER<\/b><\/td>\n<td><b>DESCRIPTION<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Line\/row<\/span><\/td>\n<td><span style=\"font-weight: 400\">Rows, or the horizontal lines of a table can be of type\u00a0 elementary, complex or reference.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Key<\/span><\/td>\n<td><span style=\"font-weight: 400\">Keys are unique identifiers of table rows, and are usually of elementary type.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Access method<\/span><\/td>\n<td><span style=\"font-weight: 400\">Access methods are modifiers that basically declare how the individual table rows or cells can be authorised for access<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">Reference types are the data types used to refer to instances of class, interface and run-time data items.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Here\u2019s a sample program based on Data Types in ABAP &#8211;<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">EPORT ZR_SS_DATAFLAIR_SAMPLE_001.\r\n\r\nDATA text_line TYPE C LENGTH 40.\r\ntext_line = 'Data Flair SAP ABAP Tutorial'.\r\nWrite text_line.\r\n\r\nDATA text_string TYPE STRING.\r\ntext_string = 'Awesome Tutorial on Data Types by Data Flair'.\r\nWrite \/ text_string.\r\n\r\nDATA sample_int TYPE I.\r\nsample_int = -1234.\r\nWrite \/ sample_int.\r\n\r\nDATA sample_byte TYPE X.\r\nsample_byte = 'FF'.\r\nWrite \/ sample_byte.\r\n\r\nDATA sample_float TYPE F.\r\nsample_float = '3.14'.\r\nWrite \/ sample_float.\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Data Flair SAP ABAP Tutorial\r\nAwesome Tutorial on Data Types by Data Flair\r\n-1234\r\nFF\r\n3,140000000000001E+00\r\n<\/pre>\n<h3>What are Variables?<\/h3>\n<p><span style=\"font-weight: 400\">Now, think about the data to be stored with an example.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Suppose you want to take an integer as input, add 1 to it, and output the result<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">How will you take the input?<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Via keyboard, mouse and so on.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">However, once you receive the input, how will you make sure whatever it is gets added to 1?<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">You store it, of course!<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">And to store the integer, you need something that would hold the value and \u2018vary\u2019 according to what the input is, i.e. you require a variable.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Therefore, a variable is a symbol that holds some data, which can be performed upon by some additional instructions.<\/span><\/p>\n<h3>Variables in ABAP<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">In ABAP, you can create variables according to one data type.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">That is, before creating a variable, you must know what data type it will belong to.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Similarly, in our above example, we have declared that our input will be an integer.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Hence, the variable will be an integer variable.<\/span><\/li>\n<\/ul>\n<p><strong>SYNTAX FOR VARIABLE in ABAP<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">DATA variableName TYPE dataType.<\/pre>\n<p><span style=\"font-weight: 400\">Here,<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Length limit to variable name is 30 characters (max)<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Any data type &#8211; elementary, complex or reference can be used in declaration<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\"><strong>EXAMPLE FOR VARIABLE in ABAP<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">DATA dataFlairID Type I.<\/span><\/p>\n<p><span style=\"font-weight: 400\">There are three variable types in ABAP &#8211;\u00a0<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Static variables<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Reference variables<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">System variables<\/span><\/li>\n<\/ol>\n<h3><span style=\"font-weight: 400\">STATIC VARIABLES IN ABAP<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Static variables are variables that are active throughout the block in which they are declared i.e. its lifetime extends from the point of declaration in the block to the end of that block.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">With local variables (described above) the declaration begins with \u2018DATA\u2019, for static variables within a class the declaration has \u2018CLASS-DATA\u2019 instead.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Along with \u2018CLASS-DATA\u2019 statement, \u2018PARAMETERS\u2019 are used to declare linked data objects and \u2018SELECT-OPTIONS\u2019 to include selection screens and their internal tables<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Static variables are usually declared within subroutines or function modules.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">There are a few rules to follow when naming a variable. Those rules are as follows &#8211;\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">1. Do not use any ABAP keyword as a variable name<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. Do not use special characters in variable name except underscore \u2018_\u2019 used to separate words for easier understanding<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. Don&#8217;t try to change names of predefined structures, objects and data<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. Variable name must be lucid and it should easily convey the use without explanation<\/span><\/p>\n<p><span style=\"font-weight: 400\">5. Avoid using hyphens \u2018-\u2019 in variable names as they are used in structures<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>Example of static variables in ABAP<\/strong>:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">REPORT ZDataflair_001. \r\nPARAMETERS: NAME(10) TYPE C, \r\nCLASS TYPE I, \r\nID TYPE P DECIMALS 2, \r\nCONNECT TYPE MARA-MATNR. \r\nWRITE: ID.\r\n<\/pre>\n<p><b>Output:<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">2<\/pre>\n<h3><span style=\"font-weight: 400\">REFERENCE VARIABLES IN ABAP<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Reference variables refer to another type, usually elementary data type<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">These may refer to a class as well<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">They are of dynamic type, whereas in its declaration a static type which is more general is used<\/span><\/li>\n<\/ul>\n<p><strong>Example of ABAP reference variables:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">CLASS DATAFLAIRCLASS DEFINITION. \r\nPUBLIC SECTION. \r\nDATA DATAFLAIRDATA TYPE I VALUE 1. \r\nENDCLASS. DATA: ODATAFLAIRREF TYPE REF TO DATAFLAIRCLASS , \r\nDDATAFLAIRREF1 LIKE REF TO ODATAFLAIRREF, \r\nDDATAFLAIRREF2 TYPE REF TO I . \r\nCREATE OBJECT ODATAFLAIRREF. \r\nGET REFERENCE OF ODATAFLAIRREF INTO DDATAFLAIRREF1. \r\nCREATE DATA DDATAFLAIRREF2. \r\nDDATAFLAIRREF2\u2192* = DDATAFLAIRREF1\u2192*\u2192 DATAFLAIRDATA.\r\nWRITE: DATAFLAIRDATA.<\/pre>\n<p><strong>OUTPUT<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">1<\/pre>\n<h3>SYSTEM VARIABLES IN ABAP<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">System variables are ones that can be accessed by all ABAP programs<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Once accessed, they are allotted values by the runtime environment itself<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">These values reflect the current status of the system at the given point in time<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The SYST table provides a complete reference to all system variables in ABAP<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The SYST structure, as all structures, comprises elementary components which can be accessed by using \u2018SYST-\u2019 or \u2018SY-\u2019<\/span><\/li>\n<\/ul>\n<p><strong>Example of ABAP system variables:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">REPORT ZDATAFLAIR_001. \r\n\r\nWRITE:\/'SY-SAPRL', SY-SAPRL,\r\n \/'SY-ABCDE', SY-ABCDE,       \r\n      \/'SY-HOST ', SY-HOST, \r\n      \/'SY-DBSYS', SY-DBSYS, \r\n      \/'SY-TCODE', SY-TCODE,\r\n      \/'SY-LANGU', SY-LANGU,\r\n\/'SY-SYSID', SY-SYSID,\r\n      \/'SY-MANDT', SY-MANDT,\r\n\/'SY-DATUM', SY-DATUM,\r\n      \/'SY-UNAME', SY-UNAME<\/pre>\n<p><strong>Output<\/strong>:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/image4-10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-93029\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/image4-10.png\" alt=\"SAP ABAP Program\" width=\"454\" height=\"441\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/image4-10.png 454w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/image4-10-300x291.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/image4-10-150x146.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/image4-10-320x311.png 320w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/a><\/p>\n<h3>What are constants?<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">A constant is exactly what it sounds like &#8211; a constant value.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">We can store a constant under a fixed name, similar to a variable.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">However, the difference is that you cannot change the value of a constant once it is declared.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">For e.g. if you want to store the value of pi = 3.14, you would use a constant!<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">A constant has a value attached to it, which is assigned via its declaration.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">This value is stored in the program memory.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The value attached cannot be changed during the execution of a program &#8211; which may lead to a run-time error, and this unchangeable value can be considered a literal.<\/span><\/li>\n<\/ul>\n<h3>Constants in ABAP<\/h3>\n<p><strong>SYNTAX FOR ABAP CONSTANT:<\/strong><\/p>\n<p style=\"padding-left: 40px\"><span style=\"font-weight: 400\">CONSTANTS constantName TYPE dataType VALUE constantValue.<\/span><\/p>\n<p><strong>EXAMPLE FOR ABAP CONSTANT<\/strong><\/p>\n<p style=\"padding-left: 40px\"><span style=\"font-weight: 400\">CONSTANTS dataFlairID TYPE I VALUE 1.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The VALUE parameter here is important in constants. It assigns an initial value.<\/span><\/p>\n<h4>Types of constants in ABAP<\/h4>\n<p><span style=\"font-weight: 400\">1. <strong>Elementary<\/strong>: when we define a single element as constant<\/span><\/p>\n<p><span style=\"font-weight: 400\">SYNTAX<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">CONSTANTS &lt;constant_name&gt; TYPE &lt;date_type&gt; LENGTH &lt;data_length&gt; DECIMALS &lt;decimal_places_no&gt; VALUE &lt;value_of_constant&gt;<\/pre>\n<p><span style=\"font-weight: 400\">e.g.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">CONSTANTS PI TYPE P LENGTH 4 DECIMALS 2 VALUE \u20183.14\u2019\r\n<\/pre>\n<p>2. <strong>Complex<\/strong>: when we combine a few elementary constants together<\/p>\n<p><span style=\"font-weight: 400\">SYNTAX<\/span><\/p>\n<p><span style=\"font-weight: 400\">CONSTANTS:<\/span><\/p>\n<p><span style=\"font-weight: 400\">BEGIN-OF &lt;constant_name&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u2026<\/span><\/p>\n<p><span style=\"font-weight: 400\">END-OF &lt;constant_name&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400\">e.g.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">CONSTANTS:\r\nBEGIN-OF dataflaircomplex\r\nCONSTANTS PI TYPE P LENGTH 4 DECIMALS 2 VALUE \u20183.14\u2019\r\nCONSTANTS PIE TYPE P LENGTH 6 DECIMALS 4 VALUE \u20183.1412\u2019\r\nEND-OF dataflaircomplex\r\n<\/pre>\n<p>3. <strong>Reference<\/strong>: when we pass reference to constants, usually to pass value to parameters<\/p>\n<p><span style=\"font-weight: 400\">SYNTAX:<\/span><\/p>\n<p><span style=\"font-weight: 400\">CONSTANTS &lt;pointer_name&gt; TYPE REF TO &lt;object_name&gt; VALUE IS INITIAL.<\/span><\/p>\n<p><span style=\"font-weight: 400\">E.g.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">CONSTANTS dataflairref TYPE REF TO dataflairobj VALUE IS INITIAL.\r\n<\/pre>\n<h3>What are literals?<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">While variables and constants required a name, literals are quite literally the opposite.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">A literal is a data value without a name.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Simply put, it is a value.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">And since it is something that does not have a name, it cannot be changed either.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">A literal is a nameless constant.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It is declared through a keyword and value, which is stored in the program\u2019s memory.<\/span><\/li>\n<\/ul>\n<h3>Literals in ABAP<\/h3>\n<p><span style=\"font-weight: 400\">There are two types of literals in ABAP:<\/span><\/p>\n<h4>1. Numeric Literal in ABAP<\/h4>\n<p>Numeric literals are simply integers. They may have a negative sign as prefix, but they cannot have decimal points, logarithms, etc.<\/p>\n<p>E.g.<br \/>\n564<br \/>\n-324<br \/>\n3489732<br \/>\nare all numeric literals.<\/p>\n<h4>2. Character Literal in ABAP<\/h4>\n<p>Character literals are a combination of alphanumeric characters. They are usually written enclosed in quotation marks. They are also called text literals or string literals.<\/p>\n<p>E.g.<br \/>\n\u2018Hello Data Flair\u2019<br \/>\n\u2018Testing Data Flair\u2019<br \/>\nare all character literals<\/p>\n<p>P.S. &#8211; If you try to change the value of a literal, a run-time error shall occur.<\/p>\n<h4>Here is how you add variables, constants &amp; literals in ABAP code &#8211;<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">REPORT ZR_SS_DATAFLAIR_SAMPLE_001.\r\n\r\nDATA: A TYPE I VALUE 2,\r\n      B TYPE I VALUE 4.\r\nWrite: \/ 'The variable value A is = ', A.\r\nWrite: \/ 'The variable value B is =', B.\r\n*Here, A &amp; B are variables.\r\n\r\nWrite: \/ 'Data Flair is awesome'.\r\nWrite: \/ 'This is an ABAP Tutorial'.\r\n*The above two are text literals\r\n\r\nCONSTANTS C TYPE P DECIMALS 4 VALUE '1.2356'.\r\nWrite: \/ 'The value of Constant Value is:', C.\r\n*The above is an example of a constant of type - packed number\r\n<\/pre>\n<p><strong>OUTPUT:<\/strong><\/p>\n<p>The variable value A is = 2<br \/>\nThe variable value B is = 4<br \/>\nData Flair is awesome<br \/>\nThis is an ABAP Tutorial<br \/>\nThe value of Constant Value is: 1,2356<\/p>\n<h3>Summary<\/h3>\n<p>Today, we learnt about the various data types, variables, constants &amp; literals available in SAP ABAP. We learnt their meaning, why and how they are used. We also learnt through examples &#8211; both with code and without, on how to use these components.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we are going to learn about SAP ABAP data types, variables, constants and literals. Like any other object-oriented programming language, you need data types, variables, constants and literals to facilitate ABAP&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":93005,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23786],"tags":[24169,24174,24167,24175,24170,24172,24171,24173,24168],"class_list":["post-92390","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sap-abap","tag-complex-data-types-in-abap","tag-constants-in-abap","tag-data-types-in-abap","tag-literals-in-abap","tag-reference-data-types-in-abap","tag-reference-variables-in-abap","tag-static-variables-in-abap","tag-system-variables-in-abap","tag-variables-in-abap"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SAP ABAP Data Types, Variables, Constants &amp; Literals - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what are data types, Variables, Constants and Literals in ABAP. Learn their types with syntax and examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SAP ABAP Data Types, Variables, Constants &amp; Literals - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what are data types, Variables, Constants and Literals in ABAP. Learn their types with syntax and examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-18T03:30:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-29T08:00:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/04\/SAP-ABAP-Data-types-Variables-Constants-and-Literals.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SAP ABAP Data Types, Variables, Constants &amp; Literals - DataFlair","description":"Learn what are data types, Variables, Constants and Literals in ABAP. Learn their types with syntax and examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/","og_locale":"en_US","og_type":"article","og_title":"SAP ABAP Data Types, Variables, Constants &amp; Literals - DataFlair","og_description":"Learn what are data types, Variables, Constants and Literals in ABAP. Learn their types with syntax and examples.","og_url":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-05-18T03:30:17+00:00","article_modified_time":"2021-11-29T08:00:31+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/04\/SAP-ABAP-Data-types-Variables-Constants-and-Literals.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"SAP ABAP Data Types, Variables, Constants &amp; Literals","datePublished":"2021-05-18T03:30:17+00:00","dateModified":"2021-11-29T08:00:31+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/"},"wordCount":1409,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/04\/SAP-ABAP-Data-types-Variables-Constants-and-Literals.jpg","keywords":["Complex data types in ABAP","Constants in ABAP","Data Types in ABAP","Literals in ABAP","Reference data types in ABAP","Reference variables in ABAP","Static variables in ABAP","System variables in ABAP","Variables in ABAP"],"articleSection":["SAP ABAP Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/","url":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/","name":"SAP ABAP Data Types, Variables, Constants &amp; Literals - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/04\/SAP-ABAP-Data-types-Variables-Constants-and-Literals.jpg","datePublished":"2021-05-18T03:30:17+00:00","dateModified":"2021-11-29T08:00:31+00:00","description":"Learn what are data types, Variables, Constants and Literals in ABAP. Learn their types with syntax and examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/04\/SAP-ABAP-Data-types-Variables-Constants-and-Literals.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/04\/SAP-ABAP-Data-types-Variables-Constants-and-Literals.jpg","width":1200,"height":628,"caption":"SAP ABAP Data types, Variables, Constants and Literals"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/abap-data-types-variables-constants-literals\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"SAP ABAP Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/sap-abap\/"},{"@type":"ListItem","position":3,"name":"SAP ABAP Data Types, Variables, Constants &amp; Literals"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/92390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=92390"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/92390\/revisions"}],"predecessor-version":[{"id":104463,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/92390\/revisions\/104463"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/93005"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=92390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=92390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=92390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}