Lecture05 abap on line

22
Lecture 5 Assigning Values, Calculations, Conversions, Control Statements, Debugging BCO5647 Applications Programming Techniques (ABAP)

description

 

Transcript of Lecture05 abap on line

Page 1: Lecture05 abap on line

Lecture 5Assigning Values, Calculations, Conversions, Control Statements, Debugging

BCO5647 Applications Programming Techniques (ABAP)

Page 2: Lecture05 abap on line

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: Lecture05 abap on line

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: Lecture05 abap on line

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: Lecture05 abap on line

5BCO5647

Input Parameters

Page 6: Lecture05 abap on line

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: Lecture05 abap on line

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: Lecture05 abap on line

8BCO5647

Calculations

Page 9: Lecture05 abap on line

9BCO5647

Calculations

Page 10: Lecture05 abap on line

10BCO5647

Conversion Rules: Elementary Types

Page 11: Lecture05 abap on line

11BCO5647

Calculations with dates

NNN

Page 12: Lecture05 abap on line

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: Lecture05 abap on line

13BCO5647

Logical Expressions

Page 14: Lecture05 abap on line

14BCO5647

Conditions: If / ElseIf

Syntax: if logical expression #1.

command lines.[elseif logical expression #2.

command lines.][else.

command lines.]endif.

Examples.

Page 15: Lecture05 abap on line

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: Lecture05 abap on line

16BCO5647

Evaluating Field Contents: Case/EndCase Vs If/Endif

Page 17: Lecture05 abap on line

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: Lecture05 abap on line

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: Lecture05 abap on line

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: Lecture05 abap on line

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: Lecture05 abap on line

21BCO5647

Debugging Mode

Page 22: Lecture05 abap on line

22BCO5647

Breakpoints in Debugging Mode