Professional Documents
Culture Documents
4-1
expressions for: assignment of numeric, character, and logical values arithmetic operations logical operations string handling operations
OL864000
Types of Expressions
Assignment / Data conversion Arithmetic Logical String
OL864005
Assignment Opcodes
Eval
Assignment via simple expression Result = Expression Supports all Data Types Data types must be compatible Left justified with character operands
Right justified
MoveL
Left justified
MoveA
For arrays
OL864105
Numeric Assignment
Assign Value CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ C Eval NumericVar = 567 ** C Eval Num2 = 0 - Num2 Clear Numeric to Zero CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** C Eval NumericVar = 0 C Eval NumericVar = *Zeros
OL864110
Move
Character to Character
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Char3 S 3 Inz( NOP ) D Char6 S 6 Inz( ABCDEF ) CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** C Move Char3 Char6 ** Char6 = ABCNOP
Numeric to Character
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Num3 S 3 0 Inz(123-) D Char6 S 6 Inz( ABCDEF ) CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** C Move Num3 Char6 ** Char6 = ABC12L
Character to Numeric
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Char3 S 3 Inz( NOP ) D Num5 S 5 0 Inz(12345) CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** C Move Char3 Num5 ** Num5 = 12567OL864120
4-7
MoveL
Numeric to Character
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Num3 S 3 0 Inz(123-) D Char6 S 6 Inz( ABCDEF ) CL0N01Factor1+++++++Opcode++++Factor2+++++++Result++++++++Len++D+HiLoEq ** C MoveL Num3 Char6 ** Char6 = 12LDEF
4-8
Rules of Move
Move/MoveL/MoveA controlled by length of shorter field length Data conversion is automatic Result field cleared first by P extender Decimal Alignment not performed
OL864130
4-10
OL864200
Arithmetic Opcodes
Legacy OpCodes:
Copyright IBM Corp. 1996, 2000 4-11
OL864205
Multiplication
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Result1 S 5P 1 D Result2 S 5P 1 D Result3 S 5P 2 ** CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++ C Eval Result1 = 123.456 * 10 ** Result1 = 1234.5 - truncated C Eval (H) Result2 = 123.456 * 10 ** Result2 = 1234.6 - rounded C 123.456 Eval (H) Result3= 10 * 123.466 ** Result3 = 234.56 - numeric overflow
OL864215
Numeric Overflow
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D NumericVar S 7P 2 D Fld1 S 3 0 INZ(993) D Fld2 S 3 0 INZ(50) D Fld3 S 4 1 D Fld4 S 5 1 ** CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++ C Eval Fld3 = Fld1 + Fld2 C Eval Fld4 = Fld1 * Fld2
Copyright IBM Corp. 1996, 2000 4-14
What will be the values of Fld3 and Fld4? What will happen when these statements are executed?
OL864220
Exponentiation
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++ D CubeRoot S 5 3 D Cubed S 5 3 ** D Number S 4S 0 Inz(144) D SqRoot S 2S 0 ** CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C Eval (H) Cubed = 3**3 C Eval CubeRoot = Cubed**(1/3) ** CubeRoot = 2.99 C Eval (H) CubeRoot = Cubed**(1/3) ** CubeRoot = 3 C Eval SqRoot = Number**.5 ** SqRoot = 12
OL864230
4-17
OL86410L
Comparison Operations
x = y x <> y x > y x >= y x < y x <= y
Copyright IBM Corp. 1996, 2000 4-18
Equality Not equal Greater Than Greater Than or Equal Less Than Less Than or Equal Logical and Logical or Logical not
OL864305
x AND y x OR y x NOT y
Class Exercise
CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ ** 1 C Eval *In99 = *ON ** 2 C Eval *In99 = (X > Y) ** 3 C Eval *In99 = (X > Y) AND (Z <> 0) ** 4 C Eval *In99 = ((X > Y) AND (Z <> 0)) OR *In23 ** 5 C Eval *In99 = (X > Y) OR NOT *in23
Copyright IBM Corp. 1996, 2000 4-19
OL864310
Setting Indicators
CN0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C Eval *In99 = *ON C Eval *In(99) = *ON CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C Move *ON *In99 ** ** C MoveA 101 *In(97) ** C Eval *In97 = *On C Eval *In98 = *off C Eval *In(99) = *ON
OL864315
4-20
If / Else / EndIf
CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ C If Fld1 = Fld2 C Eval *In99 = *ON C Else C Eval FldTot = FldTot + Fld1 C Endif
C C C C ** C : C
IF Expressions
CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ C If *in99 C C Else C C C C C C
Copyright IBM Corp. 1996, 2000 4-22
| | | | | |
If Else | If | | Else
(X < Y)
C C C C C C C
Ol864325
4-23
OL864400
Matches search argument against character string Extracts substring from a character string Removes left and right blanks from a string Removes left blanks from a string Removes right blanks from a string
OL864405
Concatenation
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++ D FirstName S 6 INZ( John ) D LastName S 6 INZ( Smith ) D FullName S 15 INZ CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C Eval FullName = FirstName + LastName ** FullName = John Smith C Eval FullName = FirstName + + LastName ** FullName = John Smith C Eval FullName = FirstName + + LastName ** FullName = John Smith
Copyright IBM Corp. 1996, 2000 4-25
OL864410
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D AString S 17 Inz( This is it ) D Another S 12 Inz D YetAnoter S 20 Inz D BigOne S 26 Inz D OneMore S 10 Inz CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ C Eval Another = %TRIML(AString) ** Another = This is it C Eval YetAnother = %TRIMR(AString) + ? ? ** YetAnother = This is it?? C Eval OneMore = %TRIM(AString) ** OneMore = This is it C Eval BigOne = %TRIMR(AString) + %TRIML(AString) ** BigOne = This is itThis is it
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++ D FirstName S 6 INZ( John ) D LastName S 6 INZ( Smith ) D FullName S 15 INZ CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C Eval FullName = %trimr(LastName) C + , C + %trimr(FirstName) ** FullName = Smith, John
OL864415
4-26
OL864420
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D Position S 2 0 Inz D String1 S 7 Inz( ABCDEFG ) D String2 S 2 Inz( RS ) D String3 S 5 Inz( TUVXY ) D String4 S 25 Inz( Learn ) CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq ** C Eval Position = %scan( CD : String1) ** Position = 3 C Eval Position = %scan(String2 : String3 : 3) ** Position = 0 C If %scan(%trim(String4) : String3) **
OL864425
OL864440
4-31
4-32
OL864450
4-34
4-35
OL864505
CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ ** Actual Unit Price = ItemPrice - ItemDscnt ** Calculate total price of items ordered (OrdQty) ** C Eval Total = OrdQty * ItemPrice - ItemDscnt ** Above calculation is not correct. Should be written: ** C Eval Total = OrdQty * (ItemPrice - ItemDscnt)
CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ ** Correct but ambiguous: C If *IN03 OR Count > Max AND *IN99 ** Better: C If *IN03 OR (Count > Max AND *IN99)
OL864510
Precision - Expressions
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments D MarkUpPct1 S 5P 2 D MarkUpPct2 S Like(MarkUpPct1) D List S 11P 2 Inz(4.0) D Cost S Like(List) D Inz(3.0) CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ C Eval MarkUpPct1 = (List - Cost) / (Cost / 100) ** MarkUpPct1 = 33.00
Copyright IBM Corp. 1996, 2000 4-37
OL864515
*RESDECPOS on H-spec applies to ALL Evals R-extender without *RESDECPOS applies to single Eval
Maximum Digits: *MAXDIGITS on H-spec (default) applies to ALL Evals M-extender to apply max. digits rules to single Eval
H ExprOpts(*RESDECPOS) DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++Comments ** D PackedN1 s 13p 2 D PackedN2 s 13p 2 D PackedN3 s 13p 2 ** CL0N01Factor1+++++++Opcode(E)+Extended-factor2++++++++++++++++++++++++++ ** Accuracy is maintained to TWO decimal places C Eval PackedN1 = PackedN1 * PackedN2 * PackedN3 ** Accuracy is maintained to THREE decimal places ** because of rounding C Eval (h) PackedN1 = PackedN1 * PackedN2 * PackedN3
Ol864520
OL864525
4-39
4-40
4-41
OL86420L
Unit Summary
Having completed this unit, you should be able to:
code calculation specifications using free form operation codes, and
expressions for: assignment of numeric, character, and logical values arithmetic operations logical operations string handling operations
OL864ZZZ