Upload
mkpatil
View
1.593
Download
5
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Lecture 5Assigning Values, Calculations, Conversions, Control Statements, Debugging
BCO5647 Applications Programming Techniques (ABAP)
2BCO5647
Readings & Objectives
Readings
Keller & Kruger Chapter 4 Section 4.3Chapter 2 Section 2.3.8
Objectives
This lecture will
Introduce the Input Parameter
Explore changing variables by copying and initialisation
Examine how calculations can be made in ABAP
Examine Control Statements and Logical Expressions in ABAP
Explore Debugging techniques in ABAP via the Debug Function
3BCO5647
Input Parameters
A Parameter is a special type of variable. It requires the value of the variableto be input from a selection screen.
4BCO5647
Input Parameters
report lec401.
tables: spfli.
parameters: carr like spfli-carrid
default ‘LH’.
select * from spfli
where carrid = carr.
write: / spfli-carrid, spfli-connid,
spfli-cityfrom, spfli-cityto.
endselect.
if sy-subrc <> 0.
write / 'no records found'.
endif.
5BCO5647
Input Parameters
6BCO5647
Changing variables: copy & initialisation
You can set a start value for an elementary field yourself using the VALUE addition.
You can copy the field contents of a data object to another data object with the MOVE statement. Ifthe two data objects have different types, the type is automatically converted if there is aconversion rule.
The CLEAR statement resets the field contents of a variable to the initial value for the particular type.
7BCO5647
Changing variables: Initialisation
The CLEAR statement sets the value of a variable or a structure tozeros. If the data type is c, the value is instead set to blanks.
data: a1(2) type c value ‘AB’,a2 type i value 123,
a3 type p value 12345,a4(3) type n value ‘789’,a5 type d value ‘19990112’,a6 type t value ‘1330’,begin of g1, a1(3) type c value ‘ASD’, a2 type i value 123,
end of g1.
clear: a1, a2, a3, a4, a5, a6,g1-a1 with ‘X’,g1-a2.
write: a1, a2, a3, a4, a5, a6, g1-a1, g1-a2.
8BCO5647
Calculations
9BCO5647
Calculations
10BCO5647
Conversion Rules: Elementary Types
11BCO5647
Calculations with dates
NNN
12BCO5647
Control Statements
ABAP has 2 conditional logic statements:
If/Endif and Case/Endcase
2 loops: Do/Enddo While/Endwhile
and others such as Continue, Check & Exit.
ABAP does not have a GOTO statement.
Control commands can be nested and/or joined with logical operators.
13BCO5647
Logical Expressions
14BCO5647
Conditions: If / ElseIf
Syntax: if logical expression #1.
command lines.[elseif logical expression #2.
command lines.][else.
command lines.]endif.
Examples.
15BCO5647
Logical Expressions & Operators
IF statements may be joined using the AND, OR or NOT operators. Logical expressions may use the following comparative operators :
eq = ne <> ><gt > ge >=lt < le <=betweenco, ca, cs, cp (string comparisons)
Examples.
16BCO5647
Evaluating Field Contents: Case/EndCase Vs If/Endif
17BCO5647
Loops : Do/EndDo
An unconditional loop.
Syntax : do [N times].Commands.
enddo.
The [N times] parameter is optional. How do you end the loop ?
A system field, sy-index, automatically stores the number of the current looppass.
Examples.
18BCO5647
Loops : While/EndWhile
Loop with terminating condition.
Syntax : while logical expressioncommands
endwhile
While the logical expression is true, the sequence of commands isexecuted.
Examples.
19BCO5647
Other control commands
The CONTINUE statement inside a loop bypasses all subsequent statementswithin the loop and forces the next loop to begin.
The CHECK statement has the same effect as CONTINUE if the specifiedlogical expression is not true.
The EXIT statement within a loop structure stops the processing of the loopand the program will continue after ENDDO/ENDWHILE.
Examples.
20BCO5647
Debugging a program
To investigate runtime errors, ABAP has a simple and efficientdebugging facility which allows you to :
set breakpoints and stop the program during runtime.continue statement by statement.skip over subroutines.view and change the contents of variables.
21BCO5647
Debugging Mode
22BCO5647
Breakpoints in Debugging Mode