160 likes | 331 Views
Flow of Control. MINS298c Fall 1998 Chapter 9. Overview. ABAP Programming Structures for: Iteration Decisions Control Flow If … Then Do & While loops In Class Exercise. Decisions. Conditions are created with logical operators Simple or Compound (with parentheses)
E N D
Flow of Control MINS298c Fall 1998 Chapter 9
Overview • ABAP Programming Structures for: • Iteration • Decisions • Control Flow • If … Then • Do & While loops • In Class Exercise
Decisions • Conditions are created with logical operators • Simple or Compound (with parentheses) • Standard Logical Operators = eq EQUAL > gt GREATER THAN <> ne NOT EQUAL < lt LESS THAN >= ge GREATER THAN or EQUAL TO <= le LESS THAN or EQUAL TO • New Operators a BETWEEN b AND c means (a >= b) AND (a <= c) IS INITIAL means variable has initial condition
New Operators • Between a BETWEEN b AND c means (a >= b) AND (a <= c) • IS INITIAL means variable has initial condition • Character Strings • CA : contains any characters of the right side • CO : contains only characters from right side • CS : contains string from right side • ignore trailing blanks; not case sensitive • CP : contains pattern from right side • use * for any char string and + for any single char
String Operators Given var1(6) value ‘ABAP/4’. IF var1 ca ‘XP’. IF var1 co ‘ABP4’. IF var1 cs ‘AA’. IF var1 cp ‘*/4’. IF var1 cp ‘*/4++’. True or False
If IF condition. process one. ELSEIF condition. process two. ELSE. process three. ENDIF. Things to watch - no THEN - periods
If F T IF condition. process one. ELSEIF condition. process two. ELSE. process three. ENDIF. 1 F T 2 3
Comparisons of different types • IF a < b {where a and b are of different types} • Hierarchy of conversion rules • same type then pad • one type f all type f • one type p all type p • one type d (or t) convert other • comparing n to c or to x converts all to type p • type x and type c converts x to c
Will it write or not? data: num1(4) value ‘124’, num2(5) value ‘00124’. if num1 = num2. write ‘numbers are equal’. endif.
Case • Requires same item in every comparison CASE variable WHEN value1. same as (variable = value1) process1. WHEN value2. process2. WHEN value3. process3. WHEN OTHERS. catches all the other conditions process4. ENDCASE. !!! Only deals with =
Looping • DO loops - • does at least once • may be counted or unconditional • WHILE Loops • conditional: may or may do initially • EXIT • SY-INDEX
Two Dos • DO • process • condition to exit (Use EXIT Command) • ENDDO • DO x times • process • alternate condition to exit (Use EXIT Command) • ENDDO
While • WHILE condition • process • change in condition • ENDWHILE
Do vs While T T
Efficiencies • Compound Conditions • ANDs put most restrictive condition first • ORs puts least restrictive condition first • CASE and nested IF statements • put most likely conditions first
In-class Assignment #5 • Create a program to display all the numbers between 0 and 100 and report which are divisible by 2, 3, or 5 Assignment 5 MINS298c Spring 1998 Number Divisible by 2 3 5 1 no no no … 30 yes yes yes