Focal Point
getting rid of leading zeros in an integer field

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

June 25, 2007, 11:27 AM
serenekk
getting rid of leading zeros in an integer field
I have integer field (/I05)that may look like 00465 or 00010 or 01000 etc. I want to show this integer field as 465 or 10 or 1000. FTOA function changes it to alpha field and strip takes out the zeros but can someone show me how to use these 2 functions correctly so that only leading zeros will be taken out, please.
Thanks in advance,
KK


on VMS: OpenVMS AXP V8.2 Prod and TestEnvironment
Webfocus: WebFocus 7.6.1 Prod and TestEnvironment
June 25, 2007, 11:39 AM
Leah
quote:
I want to show this integer field as 465 or 10


If just wanting output to surpess zeroes on the report, add an 'S', that is,
PRINT
FEILDI/I05S
...

Or is it that you want to convert it to an alpha field for some other reason, that is what FTOA is used for. Such as for concatenation to build a print line. I do that in a report here is an excerpt

CAQHRS/A7 = FTOA(CDQHRS,'(D6.2)',CAQHRS);
CAQPNTS/A7 = FTOA(CDQPNTS,'(D6.2)',CAQPNTS);
CAGPA/A7 = FTOA(CDGPA,'(D6.3)',CAGPA);
MATOTAL/A5 = FTOA(MDTOTAL,'(D4)',MATOTAL);
GAATAWA/A5 = FTOA(GDATAWA,'(D4)',GAATAWA);

I then build one print line for this special report concatenating some fields with spaces in between.


Leah
June 25, 2007, 11:47 AM
Francis Mariani
Something like this:

TABLE FILE CAR
PRINT
SALES
COMPUTE SALESD/D6 = SALES; NOPRINT
COMPUTE SALESB/A9 = FTOA(SALES, '(D6)', 'A9');
BY COUNTRY
BY CAR
BY MODEL
BY BODYTYPE
END



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
June 25, 2007, 12:06 PM
serenekk
thanks, but I was using FTOA exactly like in Francis's post was giving leading zeros.
This is how mine looks like:
I have 2 fields that are scores and codes and both are alpha fields. I converted the scores field into I05 first like this.

DEFINE FILE TEST
scores/i05 = edit (scores);
codea /a04 = if codea eq 'A' then scores else 0;
codeb /a04 = if codea eq 'B' then scores else 0;
END

TABLE FILE TEST
SUM CODEA CODEB
BY PID
ON TABLE HOLD AS HOLD1
END

so that I get codea and codeb in one line for each ID.

DEFINE FILE HOLD1
CODEA /A05 = FTOA (CODEA, '(I05)', CODEA);
CODEB /A05 = FTOA (CODEB, '(I05)', CODEB);
END

TABLE FILE HOLD1
PRINT CODEA CODEB
BY PID
ON TABLE PCHOLD FORMAT HTML
END

if codea is holding 00200 and codeb is 00030, I want these codea and codeb to just be showing 200 and 30. So I tried using strip? or something else?
KK


on VMS: OpenVMS AXP V8.2 Prod and TestEnvironment
Webfocus: WebFocus 7.6.1 Prod and TestEnvironment
June 25, 2007, 12:18 PM
Leah
quote:
DEFINE FILE HOLD1
CODEA /A05 = FTOA (CODEA, '(I05)', CODEA);
CODEB /A05 = FTOA (CODEB, '(I05)', CODEB);
END

TABLE FILE HOLD1
PRINT CODEA CODEB
BY PID
ON TABLE PCHOLD FORMAT HTML
END

if codea is holding 00200 and codeb is 00030, I want these codea and codeb to just be showing 200 and 30. So I tried using strip? or something else?


If you are just displaying then why bother to convert back to alpha, just use

PRINT CODEA/I05S CODEB/I05S
BY PID ....


Leah
June 25, 2007, 12:30 PM
serenekk
Thanks Leah, but I need to convert it back to alpha because I want these scores to be a part of a string, like this:

STRING1 = NAME | CODEA | ',' | CODEB;

so that it will show

KK 220 10
etc.

so when converting it back to alpha from integer using FTOA gives me leading zeros and I need to stip off the leading zeros so that it will show like the above line and not like
KK 00220 00010 etc.


on VMS: OpenVMS AXP V8.2 Prod and TestEnvironment
Webfocus: WebFocus 7.6.1 Prod and TestEnvironment
June 25, 2007, 12:43 PM
Leah
Kind of reminds me of the mess I have to convert names properly when using LCWORD. You might be able to use something like this, of course, you'd have to watch for the fact that it was only leading characters you wanted to change.

FULXNAMA/A32 = LCWORD(32,FUL_NAME,FULXNAMA);
I_IDX/I2 = IF FULXNAMA CONTAINS ' Mc' THEN
POSIT(FULXNAMA,32,' Mc',3,I_IDX) ELSE 0;
I_IDX2/I2 = I_IDX + 3;
I_IDX3/I2 = I_IDX + 4;
GETCHAR/A1 = IF I_IDX EQ 0 THEN ' ' ELSE
SUBSTR (32,FULXNAMA,I_IDX2,I_IDX3,1,GETCHAR);
NEWCHAR/A1 = UPCASE(1,GETCHAR,NEWCHAR);
FULXNAMT/A32 = IF GETCHAR EQ ' ' THEN FULXNAMA ELSE
OVRLAY(FULXNAMA,32,NEWCHAR,1,I_IDX2,FULXNAMT);
I_IDXA/I2 = IF FULXNAMT CONTAINS ' Mac' THEN
POSIT(FULXNAMT,32,' Mac',4,I_IDX) ELSE 0;
I_IDXB/I2 = I_IDXA + 4;
I_IDXC/I2 = I_IDXA + 5;
GETCHARA/A1 = IF I_IDXA EQ 0 THEN ' ' ELSE
SUBSTR (32,FULXNAMT,I_IDXB,I_IDXC,1,GETCHARA);
NEWCHARA/A1 = UPCASE(1,GETCHARA,NEWCHARA);
FULXNAMZ/A32 = IF GETCHARA EQ ' ' THEN FULXNAMT ELSE
OVRLAY(FULXNAMT,32,NEWCHARA,1,I_IDXB,FULXNAMZ);
I_IDX4/I2 = IF FULXNAMZ CONTAINS ' Iii' THEN
POSIT(FULXNAMZ,32,' Iii',4,I_IDX4) ELSE 0;
I_IDX5/I2 = I_IDX4 + 1;
GETCHAR6/A3 = IF I_IDX4 EQ 0 THEN ' ' ELSE 'III';
FULXNAMW/A32 = IF GETCHAR6 EQ ' ' THEN FULXNAMZ ELSE
OVRLAY(FULXNAMZ,32,GETCHAR6,3,I_IDX5,FULXNAMW);
I_IDX6/I2 = IF FULXNAMW CONTAINS ' Ii' THEN
POSIT(FULXNAMW,32,' Ii',3,I_IDX6) ELSE 0;
I_IDX7/I2 = I_IDX6 + 1;
GETCHAR7/A3 = IF I_IDX6 EQ 0 THEN ' ' ELSE 'II';
FULXNAME/A32 = IF GETCHAR7 EQ ' ' THEN FULXNAMW ELSE
OVRLAY(FULXNAMW,32,GETCHAR7,2,I_IDX7,FULXNAME);


Leah
June 25, 2007, 02:04 PM
Francis Mariani
To my surprise, FTOA does not correctly convert from I to A (I had old code lying around that suggested it did).

My example first converts from I to D and then uses FTOA on the D field, which has suppressed leading zeros.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
June 25, 2007, 02:41 PM
Alan B
If you have an I05, an EDIT can move this to alpha, then follow with the TRIM function and remove leading occurences of zero.


Alan.
WF 7.705/8.007
June 25, 2007, 02:58 PM
serenekk
Thanks very much, Both!


on VMS: OpenVMS AXP V8.2 Prod and TestEnvironment
Webfocus: WebFocus 7.6.1 Prod and TestEnvironment