0% found this document useful (0 votes)
53 views

07 - ABAP - Common Control Statements

The document discusses ABAP control statements including IF, CASE, DO, WHILE, EXIT, CONTINUE, CHECK, and WRITE. It explains how to use each statement, provides syntax examples, and compares the EXIT, CONTINUE, and CHECK statements. The IF and CASE statements are used for comparisons, DO and WHILE for loops, and EXIT, CONTINUE, and CHECK modify loop processing. The WRITE statement allows specifying output position and length.

Uploaded by

VaraPrasad.P
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

07 - ABAP - Common Control Statements

The document discusses ABAP control statements including IF, CASE, DO, WHILE, EXIT, CONTINUE, CHECK, and WRITE. It explains how to use each statement, provides syntax examples, and compares the EXIT, CONTINUE, and CHECK statements. The IF and CASE statements are used for comparisons, DO and WHILE for loops, and EXIT, CONTINUE, and CHECK modify loop processing. The WRITE statement allows specifying output position and length.

Uploaded by

VaraPrasad.P
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

ABAP - Common Control Statements

Contents
Objectives Control Statements
Using the IF Statement Using the CASE Statement Using the EXIT Statement Using the DO Statement Using the WHILE Statement Using the CONTINUE Statement Using the CHECK Statement Comparing the EXIT, CONTINUE, and CHECK Statements

Simple Position and Length Specifications for the WRITE Statement

Summary
Q&A

Contents
Objectives

Objectives
Code the common control statements IF, CASE, DO, and WHILE Control program sequence using EXIT, CONTINUE, and CHECK Code simple position and length specifications on the WRITE statement

Contents
Using the IF Statement

IF Statement
Syntax:
if [not] exp [ and [not] exp ] [ or [not] exp ]. --[elseif exp. ---] [else. ---] endif.

where:
exp is a logical expression that evaluates to a true or false condition. --- represents any number of lines of code. Even zero lines are allowed.

IF Statement

IF Statement
Data Conversion of Literals During Comparisons

IF Statement
REPORT y_vu_1001. DATA: BEGIN OF s1, x VALUE 'X', y VALUE 'Y', z VALUE 'Z', END OF s1, BEGIN OF s2, x VALUE 'X', z VALUE 'Z', END OF s2. IF s1-x = s2-x. WRITE: / s1-x, '=', s2-x. ELSE. WRITE: / s1-x, '<>', s2-x. ENDIF. IF s1 = s2. "comparing field strings byte by byte WRITE: / 's1 = s2'. ELSE. WRITE: / 's1 <> s2'. ENDIF.

IF 0 = ' '. "Watch out for this one WRITE: / '0 = '' '''. ELSE. WRITE: / '0 <> '' '''. ENDIF.

IF s1-x BETWEEN s2-x AND s2-z. WRITE: / s1-x, 'is between', s2-x, 'and', s2-z. ELSE. WRITE: / s1-x, 'is not between', s2-x, 'and', s2-z. ENDIF.

Using ELSEIF
to avoid nesting IFs
IF f1 = f2. WRITE: / f1, '=', f2. ELSEIF f1 = f3. WRITE: / f1, '=', f3. ELSEIF f2 = f3. WRITE: / f2, '=', f3. ELSE. WRITE: / 'all fields are different'. ENDIF. IF f1 = f2. WRITE: / f1, '=', f2. ELSE. IF f1 = f3. WRITE: / f1, '=', f3. ELSE. IF f2 = f3. WRITE: / f2, '=', f3. ELSE. WRITE: / 'all fields are different'. ENDIF. ENDIF. ENDIF.

Character String Operators

Character String Operators


'AABB' co 'AB' 'ABCD' co 'ABC' 'AABB' cn 'AB' 'ABCD' cn 'ABC' True False False True

'AXCZ' ca 'AB'
'ABCD' ca 'XYZ' 'AXCZ' na 'ABC' 'ABCD' na 'XYZ'

True
False False True

CP contains pattern

Contents
Using the CASE Statement

CASE Statement
Syntax:
case v1. when v2 [ or vn ... ]. --when v3 [ or vn ... ]. --[ when others. --- ] endcase.

where:
v1 or v2 can be a variable, literal, constant, or field string. --- represents any number of lines of code. Even zero lines are allowed.

CASE Statement
REPORT y_vu_1005. PARAMETERS f1 TYPE i DEFAULT 2. CASE f1. WHEN 1. WRITE / 'f1 = 1'. WHEN 2. WRITE / 'f1 = 2'. WHEN 3. WRITE / 'f1 = 3'. WHEN OTHERS. WRITE / 'f1 is not 1, 2, or 3'. ENDCASE.

Contents
Using the EXIT Statement

EXIT Statement
Syntax: exit. prevents further processing from occurring
in main program: exits program inside LOOP, SELECT, DO, WHILE: leaves loop processing inside subroutine: leaves subroutine

REPORT y_vu_1006. WRITE: / 'This line is showed.'. EXIT. WRITE: / 'This line is not showed.'.

Contents
Using the DO Statement

DO Statement
Syntax:
do [ v1 times ] --[exit.] --enddo.

where:
v1 is a variable, literal, or constant.

SY-INDEX: the current iteration number

DO Statement
sy-index = 99. WRITE: / 'before loop, sy-index =', sy-index, / ''. DO 5 TIMES. WRITE sy-index. ENDDO. WRITE: / 'after loop, sy-index =', sy-index, / ''. DO 4 TIMES. WRITE: / 'outer loop, sy-index =', sy-index. DO 3 TIMES. WRITE: / ' inner loop, sy-index =', sy-index. ENDDO. ENDDO. WRITE: / ''. DO 10 TIMES. WRITE sy-index. IF sy-index = 3. EXIT. ENDIF. ENDDO. "new line

Contents
Using the WHILE Statement

WHILE Statement
similar to DO statement Syntax:
while exp. --[ exit. ] --endwhile.

where:
exp is a logical expression.

Contents
Using the CONTINUE Statement

CONTINUE Statement
only within a loop
terminates the current loop pass jumps to the beginning of the next loop pass
DO 10 TIMES. IF sy-index BETWEEN 3 AND 8. CONTINUE. ENDIF. WRITE sy-index. ENDDO.

Contents
Using the CHECK Statement

CHECK Statement
Syntax: CHECK exp. within a loop
If exp is TRUE: does nothing If exp is FALSE: same as CONTINUE
terminates the current loop pass jumps to the beginning of the next loop pass

DO 10 TIMES. CHECK NOT sy-index BETWEEN 3 AND 8. WRITE sy-index. ENDDO.

Contents
Comparing the EXIT, CONTINUE, and CHECK Statements

Comparing EXIT, CONTINUE, and CHECK

Contents
Simple Position and Length Specifications for the WRITE Statement

WRITE Statement
Syntax:
write [/][P][(L)] v1.

where:
v1 is a variable, literal, or constant. P is a number indicating a position on the current line of output. L is a number indicating the number of bytes allocated in the list for outputting v1.

WRITE Statement

WRITE Statement
WRITE: / '....+....1....+....2....+....3....+....4', /1 'Hi', 4 'There', /1 'Hi', 3 'There', /1 'Hi', 2 'There', /1 'Hi', 1 'There', /2 'Hi', 'There', /2(1) 'Hi', 'There', /2(3) 'Hi', 'There', /2 'Hi', 10(3) 'There'. ....+....1....+....2....+....3....+....4 Hi There HiThere HThere There Hi There H There Hi There Hi The

Contents
Summary

Summary
Comparison statements: IF and CASE
CASE: compares 2 values only and only for equality Conversions occur when comparing differing data types string comparisons
CP and NP to match strings against patterns SY-FDPOS is set after each comparison

Loop statements: DO and WHILE

EXIT, CONTINUE, and CHECK statements: to modify loop processing.


EXIT: leaves the current loop. CONTINUE: unconditional jump to the end of the loop CHECK exp: jumps to the end of the loop if exp is false

SY-INDEX: contains the counter for the current loop pass

WRITE statement: position and length

Summary

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy