Monday 29 July 2013

JULY 29


Created a program for illustrating move-corresponding statements concept and studied various statements for performing calculations.
Example:
The MOVE-CORRESPONDING Statement Generates Individual MOVE Statements and Thus Performs Data Conversion
 1 report ztx0912.
 2 data: begin of s1,
 3           c1    type p decimals 2 value '1234.56',
 4           c2(3)                   value 'ABC',
 5           c3(4)                   value '1234',
 6           end of s1,
 7       begin of s2,
 8           c1(8),
 9           x2(3)                   value 'XYZ',
10           c3    type i,
11           end of s2.
12 write: / 's1                          :', s1-c1, s1-c2, s1-c3.
13 write: / 's2 before move-corresponding:', s2-c1, s2-x2, s2-c3.
14 move-corresponding s1 to s2. "same as coding the following two statements
15 * move s1-c1 to s2-c1.       "performs conversion
16 * move s1-c3 to s2-c3.       "performs conversion
17 write: / 's2 after  move-corresponding:', s2-c1, s2-x2, s2-c3.
Output:
s1                          :         1,234.56  ABC 1234
s2 before move-corresponding:          XYZ          0
s2 after  move-corresponding: 1234.56  XYZ      1,234

Performing Calculations

we can perform calculations using the following statements:
  • compute
  • add or add-corresponding
  • subtract or subtract-corresponding
  • multiply or multiply-corresponding
  • divide or divide-corresponding

Using the compute Statement:

Compute is the statement most commonly used to perform calculations.

Syntax for the compute Statement

The following is the syntax for the compute statement. Operators and operands must be separated by spaces. More than one operator per statement is permitted.
compute v3 = v1 op v2 [op vn ...].
or
v3 = v2 op v2 [op vn ...].

where:
  • v3 is the receiving variable for the result of the computation.
  • v1v2, and vn are the operands.
  • op is a mathematical operator.
 List of valid operators:
 Valid Operators for the COMPUTE Statement
Operator
Operation
+
Addition
-
Subtraction
*
Multiplication
/
Division
**
Exponentiation
DIV
Integer division
MOD
Remainder of integer division

Operator precedence is as follows:
  • Built-in functions are evaluated,
  • then exponentiation,
  • then */DIV, and MOD, in the order they appear in the expression,
  • then + and - in the order they appear in the expression.

Using the add and add-corresponding Statements

Use the add statement to add one number to another. Field strings with components having the same name can be added together with add-corresponding.

Syntax for the add Statement

Following is the syntax for the add statement. Conversions are performed as necessary in the same way as the compute statement.
add v1 to v2.
where:
  • v2 is the variable being added to.
  • v1 is the variable added to v2.
The syntax for the subtractmultiply, and divide is similar.

Syntax for the add-corresponding Statement

Below is the syntax for the add-corresponding statement.
add-corresponding s1 to s2.
where:
  • s2 is the field string being added to.
  • s1 is the field string added to s2.
An add statement is generated for each pair of components having the same name in s1 and s2. Data conversions are performed in the same way as for the add statement. Subtract-corresponding,multiply-correspondingand divide-corresponding operate in a similar fashion.
The program below explains the concept.
Example:
  Using ADDSUBTRACTMULTIPLYDIVIDE, and CORRESPONDING Statements
 1 report ztx0913.
 2 data: f1 type i value 2,
 3       f2 type i value 3,
 4       begin of s1,
 5           c1 type i value 10,
 6           c2 type i value 20,
 7           c3 type i value 30,
 8           end of s1,
 9       begin of s2,
10           c1 type i value 100,
11           x2 type i value 200,
12           c3 type i value 300,
13           end of s2.
14 add                    f1  to   f2.   write  / f2.   "f1 is unchanged
15 subtract               f1  from f2.   write  / f2.
16 multiply               f2  by   f1.   write  / f2.
17 divide                 f2  by   f1.   write  / f2.
18 add-corresponding      s1  to   s2.   write: / s2-c1, s2-x2, s2-c3.
19 subtract-corresponding s1  from s2.   write: / s2-c1, s2-x2, s2-c3.
20 multiply-corresponding s2  by   s1.   write: / s2-c1, s2-x2, s2-c3.
21 divide-corresponding   s2  by   s1.   write: / s2-c1, s2-x2, s2-c3.
Output:
     5
         3
         6
         3
       110         200         330
       100         200         300
     1,000         200       9,000
       100         200         300