Entering content frameAssigning Values with WRITE TO Locate the document in its SAP Library structure

As well as the MOVE statement, which converts the value of the source field into the data type of the target field, there is also a statement WRITE TO, which converts the contents of the source field into a field with type C.

WRITE <f1> TO <f2> [<option>].

This statement converts the contents of a data object <f1> to type C, and places the string in the variable <f2>. The data type of <f1> must be convertible into a character field; if it is not, a syntax or runtime error occurs. The contents of <f1> remain unchanged. The variable <f2> is always interpreted as a character string, regardless of its actual line type. The conversion does not take other data types into account. Therefore, you should not use a target field with a numeric data type (F, I , or P). If you do use a numeric data type, the syntax check displays a warning if the target field is statically defined. However, this warning may be upgraded to a real syntax or runtime error in future releases.

The WRITE TO statement always checks the settings in the user’s master record. These specify, for example, whether the decimal point appears as a period (.) or a comma (,). You can also use all of the formatting options available with the WRITE statement, apart from UNDER and NO-GAP.

Example

DATA: NUMBER TYPE F VALUE '4.3',
TEXT(10),
FLOAT TYPE F,
PACK TYPE P DECIMALS 1.

WRITE NUMBER.

WRITE NUMBER TO TEXT EXPONENT 2.
WRITE / TEXT.

WRITE NUMBER TO FLOAT.
WRITE / FLOAT.

WRITE NUMBER TO PACK.
WRITE / PACK.

MOVE NUMBER TO PACK.
WRITE / PACK.

In this example, the syntax check would warn you that PACK and FLOAT should be character fields (types C, D, N, T, or X). The output list is as follows:

4.30000000000000E+00

0.043E+02

1.50454551753894E-153

20342<33452;30,3

             4.3

The first line contains the contents of the field NUMBER in the standard output format for type F fields. The second line contains the string resulting from the conversion of the field NUMBER to a type C field with length 10 and the formatting option EXPONENT 2. The third and fourth output lines show that it is not feasible to use target fields which are of numeric data type. The fifth line illustrates that the MOVE statement works differently to WRITE TO. The type F field has been correctly converted to type P.

Specifying the Source Field Dynamically

In the WRITE TO statement, you can specify the name of the source field dynamically as the contents of another field. To do this, specify the name of the field containing the name of the source field in parentheses:

WRITE (<f>) TO <g>.

The system places the value of the data object assigned to <f> in <g>. If you want to specify a target field dynamically, you must use a field symbol.

Example

DATA: NAME(10) VALUE 'SOURCE',
SOURCE(10) VALUE 'Antony',
TARGET(10).

...
WRITE (NAME) TO TARGET.
WRITE: TARGET.

This produces the output

Antony

The connection between field names and field contents is shown in the following diagram.

This graphic is explained in the accompanying text

 

 

 

 

 

Leaving content frame