Wednesday, August 1, 2007

Workaround solution for MOVE operation

MOVE operation can be used to convert integer values to character values. But in ILE free format, we have to use %CHAR built in function for that.

Let us define two variables
A char 10
B dec 10 0 Inz(2510)

MOVE B A

The value in A is now '0000002510'

A = %char(B)

The value in A is now ' 2510'

Main difference is leading zeros. Sometimes it is necessary to have leading zeros in variables. Therefore the below mentioned code can be used.

Evalr a = %editc(b:'4':*ASTFILL)
a = %xlate('*':'0':a)

%EDITC built in function converts numeric field into character field and edit the value according to the edit code. *ASTFILL fills the leading spaces with '*'. %XLATE function translate '*' to '0'.