Wednesday 17 July 2013

JULY 17


Detailed study of field strings was done today. Brief of it is given below with illustrations.

Using a Field String as a Variable of Type "char"

Not only can we address the individual components of a field string, we can also address all components at once as if they were a single variable of type char.  The following example illustrates this concept.
Example-1:

 Using a Field String as Both Multiple Variables and as a Single Variable of Type CHAR 

 1 report ztx0807.
 2 data: begin of fs1,
 3         c1 value 'A',
 4         c2 value 'B',
 5         c3 value 'C',
 6         end of fs1.
 7
 8 write: / fs1-c1, fs1-c2, fs1-c3,
 9        / fs1.
10
11 fs1 = 'XYZ'.
12
13 write: / fs1-c1, fs1-c2, fs1-c3,
14        / fs1.
Output:
A B C
ABC
X Y Z 

XYZ 



Description: 

Lines 2 through 6 define field string fs1. It has three components, each with a default value. On line 8, each component is written out individually. On line 9, the field string is written out as if it were a single variable. Consequently, the output shows the contents of fs1 as if it were a single variable defined as char 3. On line 11, the value 'XYZ' is assigned to the field string, again treating it as a char variable. The resulting output shows that the individual components reflect the change because they are accessing the same storage.


Example-2:


An Example of Assignment Involving Two Field Strings
 1 report ztx0808.
 2 data: begin of fs1,
 3         c1 value 'A',
 4         c2 value 'B',
 5         c3 value 'C',
 6         end of fs1,
 7       fs2 like fs1.
 8
 9 fs2 = fs1.
10 write: / fs2-c1, fs2-c2, fs2-c3.
Output: 
A B C

Description:
Lines 2 through 6 define field string fs1. Line 7 defines field string fs2 exactly like fs1. On line 9, fs1 is moved to fs2, just as if it were a single variable of type char. On line 10, the components of fs2 are written out.


Using the TABLES Statement to Define a Field String:

A field string defined using the tables statement is a modifiable data object. Field strings defined using the tables statement follow the same rules as field strings defined using the data statement.

Syntax for Defining a Field String Using the TABLES Statement

The following is the syntax for defining a field string using the tables statement.
tables fs1.
where:
  • fs1 is the field string name. A table or structure of the same name must exist in the Data Dictionary.
 Example:
Field String Defined Using the TABLES Statement
1 report ztx0809.
2 tables ztxlfa1.
3
4 ztxlfa1-name1 = 'Bugsy'.
5 ztxlfa1-land1 = 'US'.
6
7 write: / ztxlfa1-name1, ztxlfa1-land1.
Description:
Line 2 defines field string ztxlfa1. Its definition is exactly like the Data Dictionary table of the same name. On lines 4 and 5, values are given to two of its components, which are written out on line 7.

Field String Defined Using TABLES Interacting with SELECT:

The tables statement does more than just define a field string. It does two things:
  • It defines a field string.
  • It gives the program access to a database table of the same name, if one exists.
Example:
1 report ztx0810.
2 tables ztxlfa1.
3 select * from ztxlfa1 into z lfa1 order by lifnr.
4     write / z lfa1-lifnr.
5     endselect.

Description:
Line 2 defines field string ztxlfa1. Its definition is exactly like the Data Dictionary table of the same name. There is also a database table of the same name, so the program is given access to that table, meaning that it can now be used in a select statement. Each time line 3 is executed, a record is read from the database table ztxlfa1 into field string ztxlfa1. For each record, the value of component ztxlfa1-lifnr is written out (line 4).