How do I zero fill an incoming part number field?
How do I zero fill an incoming part number field, specifically alphanumeric? The field coming in may be from 6 to 12 positions long, and I'm trying to pad the number with zeros on the left to pad it out to 12 positions. There are 6 or 7 significant digits on the actual number.
There is a way to zero fill the incoming part number field with leading zeros for 6 to 12 position part number field.
By using the scalar, assign a different variable to each position of the incoming part number field.
&LSET S1 &E(SPART SC 1.1)
&LSET S2 &E(SPART SC 2.1)
&LSET S3 &E(SPART SC 3.1), etc.
If the position didn't exist, the variable is not created.
A 6-position field means that variables for 7-12 are not created.
A 7-position field means that variables for 8-12 are not created.
Then by adding another check, see if the variable exists. Determine the length of the incoming field and add on the appropriate leading zeros to the alphanumeric part number.
&IF(S12 GE '0') &IFNOVAR &LSET OPART &E(CHAR(SPART))
&IF(S11 GE '0') &IFNOVAR &LSET OPART &E(CHAR(Z1)+CHAR(SPART)), etc.
&IF(S6 GE '0') &IFNOVAR &LSET OPART &E(CHAR(Z6)+CHAR(SPART))
If the variable doesn't exist, then the line is ignored, and marked N/A.
The OPART variable is created the first time a valid check is hit.
No compares are actually done between the alpha and numeric positions - at least while there are no alphas in the last position of the part numbers.
Another technique, suggested by one in the user community as a more straightforward approach, is:
&SET VPARTNM &E('0000000' + CHAR(VPARTNM))
&SET VPARTNM &E(CHAR(VPARTNM) TU 12)
Translate this page: