+ All Categories
Home > Documents > Chapter 06_Control Statements

Chapter 06_Control Statements

Date post: 24-Dec-2015
Category:
Upload: bakkalibilal
View: 6 times
Download: 0 times
Share this document with a friend
Description:
Chapter 06_Control Statements
24
IBM Global Business Services © IBM Corporation 2013 Control Statements | Dec-2008 Control Statements
Transcript
Page 1: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 2013Control Statements | Dec-2008

Control Statements

Page 2: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20132 Dec-2008Control Statements |

Objectives

The participants will be able to: Use the basic Control Flow Constructs that are available in the ABAP Editor

Use the following statements in an ABAP Program

IF, CASE, DO, WHILE, CHECK, EXIT, and CONTINUE

Use the Logical Expressions that are available in the ABAP Editor

Page 3: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20133 Dec-2008Control Statements |

Basic Flow Control in ABAP

Page 4: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20134 Dec-2008Control Statements |

The IF Statement

IF X =5. WRITE :/ ‘The value of X is 5’.ELSEIF X =6. WRITE :/ ‘The value of X is 6’.ELSE . WRITE :/ ‘X is neither 5 nor 6’.ENDIF.

Page 5: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20135 Dec-2008Control Statements |

Logical Expressions

Logical Expressions use : RELATIONAL OPERATORS LOGICAL OPERATORS STRING COMPARISON OPERATORS

Page 6: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20136 Dec-2008Control Statements |

Comparison SyntaxIs Equal to =, EQ

Is not equal to < >, ><, NE

Greater than >, GT

Greater than or equal to > =, = >, GE

Less than <, LT

Less than or equal to <=, =<, LE

Relational Operators

Page 7: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20137 Dec-2008Control Statements |

Logical Operators

ANDORNOT

The hierarchy of the logical operators is: NOT, AND and then OR. (i.e. different from creating views)

Page 8: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20138 Dec-2008Control Statements |

Bad Programming Practice with Logical Operators

If not ( X = 0 )

or not ( Y = 1 and

Z = X or X = 3

and ( Z = 5 )

Page 9: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 20139 Dec-2008Control Statements |

String Comparison Operators

Comparison SyntaxContains only

Contains any

Contains string

Contains pattern

Contains not only

Contains not any

Contains no string

Contains no pattern

CO

CA

CS

CP

CN

NA

NS

NP

Page 10: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201310 Dec-2008Control Statements |

Demonstration

Writing an ABAP program with the ‘IF’ statement with logical operators.

Page 11: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201311 Dec-2008Control Statements |

Practice

Writing an ABAP program with the ‘IF’ statement with logical operators.

Page 12: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201312 Dec-2008Control Statements |

The CASE Statement

CASESY-UCOMM.

Don’t forgetthose periods!

When

‘SAVE’.

When

‘SRTD’.

When‘PICK’.

When‘GETD’.

When

‘SRTA’.

Page 13: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201313 Dec-2008Control Statements |

Demonstration

Writing an ABAP program with the ‘CASE’ statement.

Page 14: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201314 Dec-2008Control Statements |

Practice

Writing an ABAP program with the ‘CASE’ statement.

Page 15: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201315 Dec-2008Control Statements |

The DO Loop

DO.WRITE :/ ‘Hello world!’.

ENDDO.

J =4.DO J TIMES.

WRITE :/ ‘Hello world!’.

ENDDO.

Page 16: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201316 Dec-2008Control Statements |

The WHILE Loop

If expression evaluates to TRUE, code in loop is executed.

If expression evaluates to FALSE, code in loop is NOT executed, and control moves to after ENDWHILE.

Page 17: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201317 Dec-2008Control Statements |

DO 2 TIMES. WRITE :/ SY-INDEX. DO 3 TIMES. WRITE : / ‘ ‘, SY-INDEX. ENDDO.ENDDO.

Nested Loops and Control Structures

Page 18: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201318 Dec-2008Control Statements |

The CHECK Statement

DO 10 TIMES. CHECK SY-INDEX <= 4. WRITE :/ SY-INDEX.ENDDO.

Page 19: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201319 Dec-2008Control Statements |

The EXIT Statement

IF SY-SUBRC <> 0. EXIT.ENDIF.

Page 20: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201320 Dec-2008Control Statements |

The CONTINUE Statement

DO 10 TIMES. IF SY-INDEX >4. CONTINUE . ENDIF. WRITE :/ SY-INDEX.ENDDO.

Page 21: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201321 Dec-2008Control Statements |

Demonstration

Writing an ABAP program and work with the ‘LOOP’ statement.

Page 22: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201322 Dec-2008Control Statements |

Practice

Writing an ABAP program and work with the ‘LOOP’ statement.

Page 23: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201323 Dec-2008Control Statements |

Summary

Logical expressions are constructed using relational, logical, and string comparison operators.

The CASE statement is used to distinguish between mutually exclusive options.

A DO loop is used to unconditionally execute a block of code multiple times.

WHILE loop conditionally executes a block of code, possibly multiple times.

The CHECK statement is used to test a logical expression

The EXIT statement unconditionally terminates a loop, subroutine, or program.

The CONTINUE statement is used inside a loop.

Page 24: Chapter 06_Control Statements

IBM Global Business Services

© IBM Corporation 201324 Dec-2008Control Statements |

Questions

What are the different kind of control statements in ABAP?

What are different logical expressions available in ABAP?


Recommended