Академический Документы
Профессиональный Документы
Культура Документы
DO statement is used for creating unconditional loops. Syntax DO [<n> TIMES] [ !"#I$% <f> &"OM <f'> $E(T <f)>]. *.. E$DDO
TIMES addition is used for specifying the number of loop iterations. If we are not specifying this additions, we should use EXIT or STOP li e loop terminating statements to a!oid endless looping. "#$%I&' addition is used for specifying the distance between the fields for iteration. (O statement bloc s should always end with E&((O statement.
WHILE loops
,.I/E statement is used for creating conditional loops. !s long as t0e specified condition is T"1E t0e loop iterations 2ill continue. ,0en t0e condition 3ecomes &!/SE t0e loop 2ill 3e terminated. Syntax ,.I/E <condition> [ !"# <f> &"OM <f'> $E(T <f )>]. *. E$D,.I/E.
We can use both the symbolic representation as well as the character representation.
Logi al Operators: Checking relation between multiple conditions are processed using logical operators. OR: A !: If any one of the conditions satisfies, then only it returns true. If all conditions are satisfied, then only it returns true.
!on"itional Operators: Controlling e"ecution of a block of statements is processed using conditional statements.
#ingle $% state&ent: I# $condition%. &&&&'lock of stmts&&& ( !I#. $% ' Else state&ent: I# $condition%. &&&&'lock of stmts&&& ()*(. &&&&'lock of stmts&&& ( !I#. ()ltiple $% state&ent: I# $condition+%.
&&&&'lock of stmts&&& ()*(I# $condition,%. &&&&'lock of stmts&&& ()*(. &&&&'lock of stmts&&& ( !I#. The !A#E !ontrol #tr) t)re: -his control structure is introduced with the CA*( statement. -he CA*( control
structure allows you to control which statement blocks are processed based on the contents of a data ob.ect. CA*( $/%. W0( $/++% 1OR $/+,% OR ...2. $*tatement block% W0( $/,+%.1OR $/,,% OR ...2
-he statement block following a W0( statement is e"ecuted if the contents of $/% are the same as those of one of the fields $/i*%. Afterwards, the program carries on processing after the ( !CA*( statement. -he statement block after the optional W0( O-0(R* statement is e"ecuted if the contents of $/% does not e4ual any of the $/i*% contents. -he last statement block must be concluded with ( !CA*(.
)O&TI&*E OPTIO&
-he CONTINUE statement can only be used in loops. If it is used, the current loop pass is ended immediately and the program flow is continued with the ne"t loop pass. E+a&ple
A loop pass is e"ited using CONTINUE if the loop inde" sy-index is an odd number.
(#T# remainder T%PE i. (O +, TIMES. remainder - sy.inde/ MO( +. I0 remainder 12 ,. )O&TI&*E. E&(I0. 3$ITE 4 sy.inde/. E&((O. O*TP*T5 + 6 7 8 9, 9+ 96 97 98 +,
):E); OPTIO&
CHECK log_exp. Effe t If the statement CHECK is e"ecuted in a loop and log_exp is incorrect, the statement CHECK immediately terminates the current loop pass and the program continues with the ne"t loop pass. #or log_exp, you can specify any logical e"pression. Note Outside a loop, the statement CHECK e"its the current processing block 5see CHECK 6rocessing 'lock7. E+a&ple -ermination of the loop pass using CHECK when the loop inde" sy-index is odd&numbered. DATA remainder TYPE i. DO ! TI"E#. remainder $ sy-index "OD CHECK remainder $ !. %&ITE ' sy-index. ENDDO.
O*TP*T5 + 6 7 8 9, 9+ 96 97 98 +,
E(IT. Effe t If the E(IT statement is listed within a loop, it lea/es the loop by ending the current loop process. 6rogram e"ecution is continued after the closing statement in the loop. Note Outside of a loop, the E(IT statement lea/es the current processing block 5see E(IT & 6rocessing block7. We recommend that you use E(IT within loops only. E+a&ple )ea/ing a loop with E(IT if the loop inde" sy-index is greater than a number limi). DATA limi) TYPE i *A+UE ,!. DO. I- sy-index . limi). E(IT. ENDI-. %&ITE ' sy-index. ENDDO.
O*TP*T5 9 + < 6
= 7 > 8 ? 9,
(#T#5'"CTEXTD9,E
3$ITE
'"CTEXT.
M#T:EM#TI)#@ OPE$#TIO&S5
n = abs( m ).
WRITE:
'A S: '! n.
n = *)++,( m ). WRITE: $ '-L..R:'! n. n = /,0n'( m ). WRITE: $ 'TRU&C:'! n. n = *,a'( m ). WRITE: $ '-RAC: '! n.
A S:
5.55
SI%&:
3.44-
CEIL:
5.44-
-L..R:
5.44-
TRU&C:
5.44-
-RAC:
4.55-
a/s sign
+>-
*mallest integer /alue not smaller than the argument. )argest integer /alue not larger than the argument. Integer part of argument. #raction part of argument.