Previous Topic: ConcatenationNext Topic: Example 1


Convert Variable

The *CVTVAR built-in function specifies that the value of one CA 2E field is to be moved to another field of a different type; that is, the two fields do not have to be of the same domain. CA 2E converts the field values according to the assignment rules of the HLL language in which you create the function.

An example of the use of this function might be to move a numeric code, stored in a CDE field, into a NBR field.

Note: To convert among date (DTE, DT#, TS#), time (TME, TM#), and number (NBR) data types, use the *MOVE built-in function instead.

You can also use the *CVTVAR built-in function with the ELM context to move data between a field and a data structure. In CA 2E a data structure is equivalent to a single element array. This provides a method for decomposition or (re)composition of field data in a single operation.

For example, you can use this technique to compose a complex data string into a single parameter required by a system API (Application Interface Program) or a third party application. Conversely, you can use this technique to decompose and recompose a telephone number or postal code.

For more information on the ELM context field, see Understanding Contexts in this chapter.

There are two parameters associated with the *CVTVAR function type:

By default, CA 2E implements the *CVTVAR built-in function as an RPG MOVEL statement when moving from a numeric field into an alphanumeric field. CA 2E uses an RPG MOVE statement when moving from an alphanumeric field into a numeric field. CA 2E implements the *CVTVAR function as a COBOL MOVE statement.

If the *Result field is longer than the moved field the result field is blanked out or converted to zeroes prior to the move. Any excess characters are converted to blanks or zeros.

Note: If you move an alphanumeric field to a numeric field, COBOL does not convert spaces to zeroes. This can cause decimal data errors.