lecture05abapon line 111108223026 phpapp02
DESCRIPTION
abapTRANSCRIPT
![Page 1: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/1.jpg)
Lecture 5Assigning Values, Calculations, Conversions, Control Statements, Debugging
BCO5647 Applications Programming Techniques (ABAP)
![Page 2: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/2.jpg)
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
![Page 3: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/3.jpg)
3BCO5647
Input Parameters
A Parameter is a special type of variable. It requires the value of the variableto be input from a selection screen.
![Page 4: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/4.jpg)
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.
![Page 5: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/5.jpg)
5BCO5647
Input Parameters
![Page 6: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/6.jpg)
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.
![Page 7: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/7.jpg)
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.
![Page 8: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/8.jpg)
8BCO5647
Calculations
![Page 9: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/9.jpg)
9BCO5647
Calculations
![Page 10: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/10.jpg)
10BCO5647
Conversion Rules: Elementary Types
![Page 11: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/11.jpg)
11BCO5647
Calculations with dates
NNN
![Page 12: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/12.jpg)
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.
![Page 13: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/13.jpg)
13BCO5647
Logical Expressions
![Page 14: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/14.jpg)
14BCO5647
Conditions: If / ElseIf
Syntax: if logical expression #1.
command lines.[elseif logical expression #2.
command lines.][else.
command lines.]endif.
Examples.
![Page 15: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/15.jpg)
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.
![Page 16: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/16.jpg)
16BCO5647
Evaluating Field Contents: Case/EndCase Vs If/Endif
![Page 17: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/17.jpg)
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.
![Page 18: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/18.jpg)
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.
![Page 19: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/19.jpg)
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.
![Page 20: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/20.jpg)
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.
![Page 21: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/21.jpg)
21BCO5647
Debugging Mode
![Page 22: Lecture05abapon Line 111108223026 Phpapp02](https://reader035.vdocuments.us/reader035/viewer/2022062613/5451f68fb1af9f83248b4b99/html5/thumbnails/22.jpg)
22BCO5647
Breakpoints in Debugging Mode