Data type errors

This details other types of data type errors that may occur.

When passing a value, the data type (TYPE parameter) must be the same (*CHAR, *DEC, or *LGL) in the calling procedure or program and in the called procedure or program. Errors frequently occur in this area when you attempt to pass a numeric constant. If the numeric constant is enclosed in apostrophes, it is passed as a character string. However, if the constant is not enclosed in apostrophes, it is passed as a packed numeric field with LEN(15 5).

In the following example, a quoted numeric value is passed to a program that expects a decimal value. A decimal data error (escape message MCH1202) occurs when variable &A is referred to in the called program (PGMA):
CALL   PGMA PARM('123')  /* CALLING PROGRAM */
PGM    PARM(&A)  /* PGMA */
DCL    &A *DEC LEN(15 5)  /* DEFAULT LENGTH */
.
.
.
IF (&A *GT 0) THEN(...) /* MCH1202 OCCURS HERE */

In the following example, a decimal value is passed to a program defining a character variable. Generally, this error does not cause run-time failures, but incorrect results are common:

CALL PGMB PARM(12345678)  /* CALLING PROG */
 
PGM PARM(&A)               /* PGMB */
DCL &A *CHAR 8
.
.
.
ENDPGM

Variable &A in PGMB has a value of hex 001234567800000F.

Generally, data can be passed from a logical (*LGL) variable to a character (*CHAR) variable, and vice versa, without error, so long as the value is expressed as '0' or '1'.