Focal Point
[SOLVED] Converting and shortening an integer to alphanumeric

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9467015895

February 10, 2011, 06:37 PM
Carlf
[SOLVED] Converting and shortening an integer to alphanumeric
I need to convert an I11 format number to a 6 character string (even though the format is I11, all the fields are 6 characters).

I tried this:


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 I change the BAT_ID1 field to A11, I get 11 *

Any Suggestions?


Thanks,
carl

This message has been edited. Last edited by: Kerry,


Carl

FOCUS 7.1.6 on Windows XP
Output: Excel, HTML, PDF
February 10, 2011, 07:15 PM
Tom Flynn
PTOA - Doesn't matter if it's an I,P,D...

BAT_ID1/A11=PTOA(BAT_ID, '(P11)', BAT_ID1);

  
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


All the columns are formatted I8 in GGSALES...


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
February 11, 2011, 04:56 AM
GamP
You could also do it with FTOA, only then you will have to specify a floating format - 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.
Consider this code:
DEFINE FILE PRIMARY
BAT_ID1/A6=FTOA(BAT_ID, '(F6)', 'A6');
END
TABLE FILE PRIMARY
PRINT BAT_ID 
BAT_ID1
END
This will also provide the correct result.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
February 11, 2011, 07:54 AM
JRLewis
I believe this will also work.

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



WebFOCUS 8
February 11, 2011, 10:28 AM
Carlf
All 3 of these solutions work. Thanks for the help.


Carl

FOCUS 7.1.6 on Windows XP
Output: Excel, HTML, PDF