Friday, June 15, 2007

Removing leading zeroes from a non zero character variable

I have a character variable which accepts numeric data. If this data is non-zero, we will have to take out any leading zeroes and then pass the resulting data to an SQL statement for further processing. This is how I acheived it using free form RPG.

InUpc is the character variable.

If %Trim(InUpc) <> *Zeros; // if data is non-zero
DoW %SubSt(%Trim(InUpc):1:1) = '0'; // take out first digit if it is zero
InUpc = %SubSt(%Trim(InUpc):2);
EndDo;
EndIf;

No comments: