- Back to Home »
- ABAP , Basic things in ABAP , Introduction , Module pool programming , Reports »
- 5 Basic Things in ABAP Programming
Posted by : Unknown
Wednesday, June 12, 2013
Basic things in ABAP with example
Arithmetic expressions in ABAP
In ABAP you
can program the following valid arithmetic expressions,
·
+
Addition
·
-
Subtraction
·
* Multiplication
·
/ Division
·
**
Exponentiation
·
DIV
Integral division without
remainder
·
MOD
Remainder after integral
division
Parameters
In our
previous program we have written a set of commands for the arithmetic
operations but the input to the variables where hardcoded in the program
itself, now what if the user wants to enter the value during runtime?
What if he
wants to enter different values each time?
So, we have
to write a program which asks input from the user and gives the output.
To get
input from user we should use the abap keyword ‘PARAMETERS’.
Ex:
PARAMETERS:
input1 type I,
input2 type I.
The variable Result should not be
defined in parameters because we are not going to get an input to the variable
result. (Therefore result should be defined by ‘DATA’)
Data types in abap
Data types
A data
type or simply type is a classification for identifying
types of data, such as integer, numeric,
character etc. that determines the possible values for that type; the
operations that can be done on values of that type; the meaning of the data;
and the way values of that type can be stored.
Here in abap we can classify them into two
groups.
·
Complete ABAP standard
types ( length will be fixed except string and xstring)
·
Incomplete ABAP
standard types
Complete types:
·
D
Type for date (D), format YYYYMMDD, LENGTH
8
·
T
Type for time (T), format HHMMSS, LENGTH
6
·
I
Type for integer (I), LENGTH 4
·
F
Type for floating point number (F), LENGTH 8
·
String
Type for dynamic length character string
·
Xstring
Type for dynamic length byte sequence
(HeXadecimal string)
Incomplete types:
·
C
Type for character
string, length should be specified.
·
N
Type for numerical
character, length should be specified.
·
X
Type for byte sequence,
length should be specified.
·
P
Type for packed number,
length should be specified as well as decimal points should be specified.
So with these data types the user
can define a variable in the program, (as how we used Integer in our program)
Conditional branches and logical expressions
In ABAP you
have two ways to execute different sequences of statements.
·
IF
·
CASE
IF-statement
|
CASE-statement
|
IF input1 > 0
Statements
ELSEIF input1 < 0
Statements
ELSEIF input1 = 0
Statements
ENDIF.
|
CASE input1.
When
‘0’.
Statements
When
‘100’
Statements
When
‘200’
Statements
ENDCASE.
|
As we know about the IF-statement and
CASE-statement lets update our previous program (arithmetic calculation) using
these conditional statements.
As you can
see the keyword ‘PARAMETERS’ is used for getting input from user, we are
getting three inputs from the user.
1. Operand1 (input1)
2. Operand2 (input2)
3. The operators ( ‘+’ ‘-’ ‘*’ ‘/’)
And the
output is stored in the variable ‘RESULT’ which is defined by the ‘DATA’
keyword.
Next comes
the conditional operator,
IF-statement:
It checks whether the value in variable
‘SYMBOL’ is one of the symbols described there.
If the
symbol is any of these ‘+, - , *, /’ it comes to the next statement (i.e.
CASE-statement) or else it executes the ‘ELSE’ part.
CASE-statement:
Depending
upon the symbol the case statement is executed i.e. when the symbol is ‘+’ it
executes the addition and when the symbol contains the value ‘-‘ the operation
subtraction is performed.
Whenever an
operation is performed the result is stored in the variable ‘RESULT’, and at
the end of the CASE-statement we are printing the result in the screen.
Now, come
back to the IF-statement (line 16).
If the
symbol contains value which is not defined there, it comes to the ELSE part.
The ELSE
part contains the code for writing an error ‘symbol is not defined in the
program’.
In line 16
the Relational operator OR is described after every condition.
See how the
compiler reads the program.
Line16 -> Checks whether the value in symbol is
‘+’ OR‘-‘ OR‘*’ OR ‘/’ .
(If the
value in symbol is any of the following above Line18 is executed or else Line 30 is executed)
Do you know :
·
Always give preference in using CASE-statements
than IF-statements because it’s
more transparent and performs better.
·
Always provide space between parentheses and operators since they are
ABAP keywords
|
Search An Element in Linked List c programming example codes
ReplyDelete