We have been messing with this all day, thinking there has to be a better way to strip zeros and trailing spaces from an Integer that's been converted to an alpha.
This is the best we could come up with.
We use PTOA so it doesn't create the preceding zeros. We use STRREP to strip off the preceding spaces, then have to use TRUNCATE to remove the trailing spaces. What a task.
SET ASNAMES=MIXED
-DEFAULTH &MULTIPLIER = 13713;
-DEFAULTH &MYCNT = _FOC_NULL;
TABLE FILE CAR
SUM
COMPUTE MYCNT/A11V = STRREP(11, PTOA(CNT.DST.COUNTRY*&MULTIPLIER, '(P11)', 'A11V'), 1, ' ', 0, '', 11, MYCNT);
ON TABLE HOLD AS MYHOLD FORMAT INTERNAL
END
-RUN
-READFILE MYHOLD
-SET &MYCNT = TRUNCATE(&MYCNT);
-TYPE MYCNT = ->&MYCNT<-
END
Is it me or is the 100x harder than it should be based on any other language out there. We are unsure why IBI auto pads and creates preceding zeros.This message has been edited. Last edited by: GavinL,
- FOCUS Man, just FOCUS! ----------------------------- Product: WebFOCUS Version: 8.1.04 Server: Windows 2008 Server
September 12, 2015, 12:20 PM
George Patton
If you happen to know what the length of your integer will be it gets a lot simpler. In your example the length is 5 and as loing as the first COMPUTE has a length of 5 it doesn't appear to matter what you use as the length for the alpha field - although obviously you would want them the same.
I don't know if there is a way to figure out what the length of an integer is dynamically.
TABLE FILE CAR
SUM
COMPUTE GP/I5 = CNT.DST.COUNTRY*&MULTIPLIER;
COMPUTE GP2/A5=EDIT(GP);
END
Or (better) you can use a double precision number as the first COMPUTE and the FTOA in the second. Note the lower case c in the second parameter which removes the comma
TABLE FILE CAR
SUM
COMPUTE GP/D10 = CNT.DST.COUNTRY*&MULTIPLIER;
COMPUTE GP3/A10=FTOA(GP, '(D10c)', 'A10');
END
We use LJUST instead of STRREP for this particular purpose. And sometimes we use FPRINT instead of PTOA, but that doesn't make a lot of difference:
-DEFAULTH &MULTIPLIER = 13713;
TABLE FILE CAR
SUM
COMPUTE MYCNT/A11V = LJUST(11, FPRINT(CNT.DST.COUNTRY*&MULTIPLIER, 'P11', 'A11'), MYCNT);
END
Still not very convenient, but perhaps a small improvement.
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010 : Member of User Group Benelux :
September 14, 2015, 07:15 AM
TexasStingray
Look at TRIM and TRIMV function.
Scott
September 14, 2015, 10:27 AM
GavinL
I'll play with it some more today with this tips.
Thanks for your input.
- FOCUS Man, just FOCUS! ----------------------------- Product: WebFOCUS Version: 8.1.04 Server: Windows 2008 Server