Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com

Declaring variable and Displaying output

In this tutorial we will see the variable declaration and writing the variables data to the output screen.
We write the coding in ABAP Editor.
Step 1: After logging into the SAP Environment open the ABAP editor. To open the ABAP Editor in the command box enters the transaction code SE38.
Transaction code: Transaction code is nothing but a command which is more like a short cut to access a place within SAP instead of navigating through menus.

Step 2: In the ABAP Editor screen, Enter the program name and click on create.

Step 3: In the pop up that appears while creating the program, choose the program type as executable program and provide the description. Click on Save.
Step 4: As of now, we have not created any packages, hence we will store the development object in the local object. (Not transportable). Select the local object.

Step 4: The program will now be created and we will have the editor where we can write our code.

Data: Data is a keyword which is used to define the data object.
Type: Type is a keyword that determines the data type that is to be assigned to the data object.
Data Object: Data object is a variable that is declared using the keyword data. At the time of execution of the program the system allocates memory to the data object to hold values. The memory is allocated based on the data type assigned to it.
Data Types: Data types specify the type of data that is to be assigned to the data object.  
Syntax for declaring Variables:
Data object without default value:
Data :  <<<Data object>>>  Type <<< Data type>>>.
Data object with default value:
Data :  <<<Data object>>>  Type <<< Data type>>>  value ‘<<<Default value>>>’.
Data object with length declaration:
Data :  <<<Data object>>>  Type <<< Data type>>> length ‘<<<length>>>’.

Value: Value is an addition used along with the data keyword at the time of creation of data object for assigning default value to it.
Length: Length is an addition used to specify the length when declaring variable length data types.

Declare the data in the program as below:

Now we have declared the different types of data type.  
While creating a packed number we can specify the no of decimal point. For which use the addition decimal along with the declaration. If we don’t specify the decimal point then the system will the take the decimal point by default as 2.
While declaring the variable data type I have specified the length which will determine how many character the variable can contain. There are two ways of providing the length, either using the addition or specifying the value as in the parenthesis.  In case if we don’t specify the length then system assumes it to be of length 1. In that case when we are assigning value to the data object Say ‘Arun’ only A will be stored in the data object as it can hold only one character.
We always have to specify the length for the data type which has the variable length.
The data and time are assigned in the internal format.
The variable declared using string has dynamic length; we have assigned the value to the string variable as ‘Hello guys’ which is 10 characters. Now the length of the string variable would be 10. Now in the program if I truncate the guys from the variable then the variable will only contain ‘Hello’ and the length will be adjusted to 5.

Assigning values to the Data objects:

Displaying the Output:
Write: Write is the keyword which is used to write the output on the list screen. (Here in ABAP we call the output screen as List)
/  à Indicates the new line characters.
The text can be directly written on the output screen. The text to be written on the output screen has to be provided within single quotes. 
Then the system writes the values which are entered in the data objects.
Tips: After typing the first few letters, press control+ space to get the autocomplete feature. For this the auto completed feature must be checked on.

To verify the program does not have any errors, click on the syntax check button. [CTRL+ F2].

We have to activate the program before executing it. Click on the activate button to activate the program.
[CTRL+F3]. A popup will appear, press enter to activate the program.
Note: The pop up will not appear if there are no other inactive program in the server, system will directly activates the program in that case.

You can see the status of the program changed to active.

To execute the program and see the output press F8 or choose the execute button.

Output of the Program:

About Arun


Post a Comment

Powered by Blogger.