Wednesday 24 July 2013

JULY 24


Created various programs to illustrate the concept of CLEAR statements.

EXAMPLE-PROGRAMS for CLEAR Statements

Example-1:
Variables Set to Blanks or Zeros by the CLEAR Statement
 1 report ztx0904.
 2 tables ztxlfa1.
 3 data: f1(2) type c value 'AB',
 4       f2    type i value 12345,
 5       f3    type p value 12345,
 6       f4    type f value '1E1',
 7       f5(3) type n value '789',
 8       f6    type d value '19980101',
 9       f7    type t value '1201',
10       f8    type x value 'AA',
11       begin of s1,
12           f1(3) type c value 'XYZ',
13           f2    type i value 123456,
14           end of s1.
15 ztxlfa1-lifnr = 'XXX'.
16 ztxlfa1-land1 = 'CA'.
17 write: / 'f1=''' no-gap, f1 no-gap, '''',
18        / 'f2=''' no-gap, f2 no-gap, '''',
19        / 'f3=''' no-gap, f3 no-gap, '''',
20        / 'f4=''' no-gap, f4 no-gap, '''',
21        / 'f5=''' no-gap, f5 no-gap, '''',
22        / 'f6=''' no-gap, f6 no-gap, '''',
23        / 'f7=''' no-gap, f7 no-gap, '''',
24        / 'f8=''' no-gap, f8 no-gap, '''',
25        / 's1-f1=''' no-gap, s1-f1 no-gap, '''',
26        / 's1-f2=''' no-gap, s1-f2 no-gap, '''',
27        / 'ztxlfa1-lifnr=''' no-gap, ztxlfa1-lifnr no-gap, '''',
28        / 'ztxlfa1-land1=''' no-gap, ztxlfa1-land1 no-gap, ''''.
29 clear: f1, f2, f3, f4, f5, f6, f7, f8, s1, ztxlfa1.
30 write: / 'f1=''' no-gap, f1 no-gap, '''',
31        / 'f2=''' no-gap, f2 no-gap, '''',
32        / 'f3=''' no-gap, f3 no-gap, '''',
33        / 'f4=''' no-gap, f4 no-gap, '''',
34        / 'f5=''' no-gap, f5 no-gap, '''',
35        / 'f6=''' no-gap, f6 no-gap, '''',
36        / 'f7=''' no-gap, f7 no-gap, '''',
37        / 'f8=''' no-gap, f8 no-gap, '''',
38        / 's1-f1=''' no-gap, s1-f1 no-gap, '''',
39        / 's1-f2=''' no-gap, s1-f2 no-gap, '''',
40        / 'ztxlfa1-lifnr=''' no-gap, ztxlfa1-lifnr no-gap, '''',
41        / 'ztxlfa1-land1=''' no-gap, ztxlfa1-land1 no-gap, ''''.
OUTPUT:
f1='AB'
f2='    12,345 '
f3='         12,345 '
f4=' 1.000000000000000E+01'
f5='789'
f6='19980101'
f7='120100'
f8='AA'
s1-f1='XYZ'
s1-f2='   123,456 '
ztxlfa1-lifnr='XXX       '
ztxlfa1-land1='CA '
f1='  '
f2='         0 '
f3='              0 '
f4=' 0.000000000000000E+00'
f5='000'
f6='00000000'
f7='000000'
f8='00'
s1-f1='   '
s1-f2='         0 '
ztxlfa1-lifnr='          '
ztxlfa1-land1='   '

Description:
  • Line 2 defines field string ztxlfa1.
  • Lines 4 through 10 define variables of every type and give them default values.
  • Another field string, s1, is defined on line 11, with default values for each component.
  • Values are assigned to two of the components for field string ztxlfa1 on lines 15 and 16.
  • All variables and components of field strings are set to zeros and blanks by the clear statement on line 29. It can also be said that all variables and components are set to default initial values.
  • The write statements beginning on line 30 write out the cleared variables and components surrounded by single quotes and without intervening spaces between the quotes and the values they surround.
Example-2:
 Variables Filled with Characters Other than Blanks or Zeros Using the WITH Addition of the CLEAR Statement
 1 report ztx0905.
 2 tables ztxlfa1.
 3 data: f1(2) type c value 'AB',
 4       f2(2) type c,
 5       f3    type i value 12345,
 6       begin of s1,
 7           f1(3) type c value 'XYZ',
 8           f2    type i value 123456,
 9           end of s1.
10 write: / 'f1=''' no-gap, f1 no-gap, '''',
11        / 'f2=''' no-gap, f2 no-gap, '''',
12        / 'f3=''' no-gap, f3 no-gap, '''',
13        / 's1-f1=''' no-gap, s1-f1 no-gap, '''',
14        / 's1-f2=''' no-gap, s1-f2 no-gap, '''',
15        / 'ztxlfa1-lifnr=''' no-gap, ztxlfa1-lifnr no-gap, '''',
16        / 'ztxlfa1-land1=''' no-gap, ztxlfa1-land1 no-gap, '''',
17        /.
18 clear: f1 with 'X',
19        f2 with f1,
20        f3 with 3,
21        s1 with 'X',
22        ztxlfa1 with 0.
23 write: / 'f1=''' no-gap, f1 no-gap, '''',
24        / 'f2=''' no-gap, f2 no-gap, '''',
25        / 'f3=''' no-gap, f3 no-gap, '''',
26        / 's1-f1=''' no-gap, s1-f1 no-gap, '''',
27        / 's1-f2=''' no-gap, s1-f2 no-gap, '''',
28        / 'ztxlfa1-lifnr=''' no-gap, ztxlfa1-lifnr no-gap, '''',
29        / 'ztxlfa1-land1=''' no-gap, ztxlfa1-land1 no-gap, ''''. 
 Output:
f1='AB'
f2='  '
f3='    12,345 '
s1-f1='XYZ'
s1-f2='   123,456 '
ztxlfa1-lifnr='          '
ztxlfa1-land1='   '

f1='XX'
f2='XX'
f3='50,529,027 '
s1-f1='XXX'
s1-f2='1482184792 '
ztxlfa1-lifnr='##########'
ztxlfa1-land1='###'
Description:
  • Line 18 fills f1 with the letter X.
  • Line 19 fills f2 with the first byte of f1, also an X.
  • Line 20 fills f3 with the first byte of the literal 3. A numeric literal up to nine digits long is stored as a four-byte integer . f3 is filled with the first byte of this four-byte integer, essentially assigning garbage to f3.
  • Line 21 treats s1 as a type c variable and fills it with X. Component f1 is type c, so it receives valid values. Component f2 is type i and so receives invalid values.
  • Field string ztxlfa1 is filled with the first byte from the four-byte integer value 0, filling it with garbage. Garbage, in this case, is displayed as hash marks (#).