Converting and Shortening an Integer to Alphanumeric



Converting and Shortening an Integer to Alphanumeric

By Carl Fuglein, Tom Flynn, Gerard van der Paal, and John Lewis

 

Problem:

Started with a Focal Point post, Carl's question is, we need to convert an I11 format number to a 6 character string (even though the format is I11, all the fields are 6 characters). The original code is:

	DEFINE FILE PRIMARY
	BAT_ID1/A6=FTOA(BAT_ID, '(I11)', BAT_ID1);
	END
	TABLE FILE PRIMARY
	PRINT BAT_ID
	BAT_ID1
	END

And got this:

	PAGE 1
	
	BAT_ID BAT_ID1
	168403 ******
	170206 ******
	170206 ******
	171520 ******

If the BAT_ID1 field is changed to A11, I get 11 *

So, how to resolve this one?

Solution:

There is an old saying, there are many ways to skin a cat. Very often, this is also true in FOCUS - many ways to achieve the same goal. Three of our Focal Pointers made suggestions, and not surprise at all, all three solutions worked for Carl.

Solution #1, from Tom Flynn of SunGard Higher Education:

PTOA - Doesn't matter if it's an I,P,D...

APP PREPENDPATH IBISAMP
-RUN 
DEFINE FILE GGSALES
  ALPHA_UNITS/A8      = PTOA(UNITS,      '(P8)', ALPHA_UNITS);
  ALPHA_DOLLARS/A8    = PTOA(DOLLARS,    '(P8)', ALPHA_DOLLARS);
  ALPHA_BUDUNITS/A8   = PTOA(BUDUNITS,   '(P8)', ALPHA_BUDUNITS);
  ALPHA_BUDDOLLARS/A8 = PTOA(BUDDOLLARS, '(P8)', ALPHA_BUDDOLLARS);
END
TABLE FILE GGSALES
PRINT
    UNITS
    ALPHA_UNITS
    DOLLARS
    ALPHA_DOLLARS
    BUDUNITS
    ALPHA_BUDUNITS
    BUDDOLLARS
    ALPHA_BUDDOLLARS
  BY CATEGORY
  BY REGION
WHERE RECORDLIMIT EQ 100;
END
-EXIT

 

Solution #2, from Gerard van der Paal of BI-Solutions:

This is also possible to do with FTOA, only then a floating format will have to be specified - so it has to be a F or D format. If the input field is itself not a F or D field, it will be converted to F or D before processing.

DEFINE FILE PRIMARY
BAT_ID1/A6=FTOA(BAT_ID, '(F6)', 'A6');
END
TABLE FILE PRIMARY
PRINT BAT_ID 
BAT_ID1
END

 

Solution #3, from John Lewis of Partner Intelligence:

DEFINE FILE PRIMARY
BAT_ID1/I6=BAT_ID;
BAT_IDA/A6=EDIT(BAT_ID1);
END
TABLE FILE PRIMARY
PRINT BAT_ID
BAT_IDA
END


Any questions, please contact Carl, Tom, GamP, and/or John.