Focal Point
the trim function
October 18, 2007, 11:36 AM
tlbrydie2the trim function
Hello,
I have some percentage fields that I need to display on a report in a certain format.
my code is as follows:
FPPCT/A10 =FTOA(pct,'(D7.2)','A10');
-*timtest
TPPCT/A10 =TRIM('T',FPPCT,10,'0',1,'A10');
DPPCT/A10 =TRIM('T',TPPCT,10,'.',1,'A10');
-* PPCT/A100 ='
'|FPPCT|'';
PPCT/A100 ='
'|DPPCT|'';
input what my code produces what I need
------ --------------------- -----------
0.01 .01 0.01
0.10 .10 0.1
1.01 1.01 1.01
1.00 1.00 1
100.00 100.00 100
Prod: WebFOCUS 7.6.10 MRE
Oracle/Sybase
Test: DevStudio 7.6.6
WF Server 7.6.6
Report Caster 7.6.6
Web Server - Tomcat
MS Windows XP SP2
Output: HTML, Excel 2000 , PDF, CSV, DOC
October 18, 2007, 11:53 AM
LeahJust curious. If the calculation is giving you the decimal, why not just multiply it by 100 or use the percent display option?
Leah
October 18, 2007, 01:12 PM
tlbrydie2any other suggestions ?
Prod: WebFOCUS 7.6.10 MRE
Oracle/Sybase
Test: DevStudio 7.6.6
WF Server 7.6.6
Report Caster 7.6.6
Web Server - Tomcat
MS Windows XP SP2
Output: HTML, Excel 2000 , PDF, CSV, DOC
October 18, 2007, 01:29 PM
LeahAs to suggestions, as you are only showing the percent part of your code, are you calculating the value and if I read your message correctly, if it is .01, then you want 1.00. Is there a particular reason you are creating an alpha field? As in you need it that way to concatinate with other alpha fields?
Oh and as Tony and Francis always say, please update your signature on the forum to show what platform and version you are on.
Leah
October 18, 2007, 01:39 PM
Francis MarianiThe solution is what is called "Dynamically Formatted Virtual Fields". Look for "Applying Dynamically Formatted Virtual Fields to Report Columns" in the documentation.
Turing CENT-ZERO on will give you a zero before the decimal when an amount is less than 1. (This, of course has nothing to do with dynamically formatted fields - I always set CENT-ZERO to ON.)
Here's an example using the data you specified:
SET CENT-ZERO=ON
-RUN
DEFINE FILE CAR
PCT/D7.2 =
IF COUNTRY EQ 'ENGLAND' THEN 0.01 ELSE
IF COUNTRY EQ 'FRANCE' THEN 0.10 ELSE
IF COUNTRY EQ 'ITALY' THEN 1.01 ELSE
IF COUNTRY EQ 'W GERMANY' THEN 1.00 ELSE 100.00;
FPPCT/A8 =FTOA(PCT,'(D7.2)','A8');
PCT_FMT/A8 =
IF EDIT(FPPCT,'$$$$$$99') EQ '00' THEN 'D7' ELSE IF EDIT(FPPCT,'$$$$$$$9') EQ '0' THEN 'D7.1' ELSE
'D7.2';
END
TABLE FILE CAR
SUM
PCT
PCT/PCT_FMT
BY COUNTRY
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
October 18, 2007, 01:40 PM
tlbrydie2I am not calculating the value. The value comes in as a (D7.2). I am converting it to show up on the report correctly?
if the field comed in as 0.01 I need to display 0.01 on the report.
If the field codes in as .10 I need to display 0.1 on the report
If the field comes in as 1.00 I need to display 1 on the report.
One thing that seems strange is that (for example) the database shows the pct field as 0.01 however when my program see's it it is .01...with no filtering done on the field at all. Does Web Focus automatically eliminate the preceeding zero prior to the decimal?
Prod: WebFOCUS 7.6.10 MRE
Oracle/Sybase
Test: DevStudio 7.6.6
WF Server 7.6.6
Report Caster 7.6.6
Web Server - Tomcat
MS Windows XP SP2
Output: HTML, Excel 2000 , PDF, CSV, DOC
October 18, 2007, 01:43 PM
Francis MarianiBy default, the zero preceding the decimal place is not displayed, turning CENT-ZERO ON displays it.
Please try the dynamically formatted field and let me know if this works for you - it should give exactly what you want.
Cheers,
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
October 18, 2007, 01:55 PM
LeahWith what you say you want, I agree with Francis, the virtual format calculation is for you. Note you will have to keep your FTOA to create the field you need for the virtual calculation. Have fun in FOCUS.
Leah
October 18, 2007, 02:02 PM
tlbrydie2The code I implemented is as follows:
FPPCT/A10 =FTOA(pct,'(D7.2)','A10');
PCT_FMT/A10 =
IF EDIT(FPPCT,'$$$$$$$$99' EQ '00' THEN 'D7' ELSE IF EDIT(FPPCT,'$$$$$$$$$9') EQ '0' THEN 'D7.1' ELSE
'D7.2'
PPCT/A100 ='
'|FPPCT|''
input what I getting
----- --------------
0.01 0.01 - good
0.10 0.10 - expecting - 0.1
1.00 1.0 - expecting - 1
100.10 100.10 - expecting 100.1
Prod: WebFOCUS 7.6.10 MRE
Oracle/Sybase
Test: DevStudio 7.6.6
WF Server 7.6.6
Report Caster 7.6.6
Web Server - Tomcat
MS Windows XP SP2
Output: HTML, Excel 2000 , PDF, CSV, DOC
October 18, 2007, 02:07 PM
Francis Mariani
SET CENT-ZERO=ON
-RUN
DEFINE FILE CAR
PCT/D7.2 =
IF COUNTRY EQ 'ENGLAND' THEN 0.01 ELSE
IF COUNTRY EQ 'FRANCE' THEN 0.10 ELSE
IF COUNTRY EQ 'ITALY' THEN 1.01 ELSE
IF COUNTRY EQ 'W GERMANY' THEN 1.00 ELSE 100.00;
FPPCT/A8 =FTOA(PCT,'(D7.2)','A8');
PCT_FMT/A8 =
IF EDIT(FPPCT,'$$$$$$99') EQ '00' THEN 'D7' ELSE IF EDIT(FPPCT,'$$$$$$$9') EQ '0' THEN 'D7.1' ELSE
'D7.2';
END
TABLE FILE CAR
SUM
PCT
PCT/PCT_FMT
BY COUNTRY
END
PCT_FMT is the format of the numeric field you want to display. I think it has to be A8. It is then referenced as a field reformat here: PCT/PCT_FMT
Did you know that you can copy the code I provided here, paste it into a fex and run it on your server? The CAR file is distributed with all version of WebFOCUS, so it should be available on your WebFOCUS installation. Give it a try to see how it works.
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
October 18, 2007, 02:08 PM
Francis Marianiquote:
PPCT/A100 =''|FPPCT|''
You don't need that.
Just display the PCT as originally calculated, but reformat it with PCT_FMT.
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
October 19, 2007, 06:47 AM
tlbrydie2Good Morning,
I want to thank you for you assistance in helping me resolve this matter. I have included the code which worked for me. My problem turned out to be that my field had spaces at the end of it and when I tried to "TRIM" the training zeroes it did not work because their was no trailiing zero's. Again, thanks alot.
NPPCT/P7.2C =pct;
-* IPPCT/D4C =NPPCT;
FPPCT/A10 = PTOA(NPPCT,'(P7.2C)',FPPCT);
TPPCT/A10 = RJUST(10,FPPCT,TPPCT);
GPPCT/A10 = TRIM('T',TPPCT,10,'0',1,'A10');
MPPCT/A10 = RJUST(10,GPPCT,MPPCT);
DPPCT/A10 = TRIM('T',MPPCT,10,'.',1,'A10');
PPCT/A100 = '
'|DPPCT|'';
Prod: WebFOCUS 7.6.10 MRE
Oracle/Sybase
Test: DevStudio 7.6.6
WF Server 7.6.6
Report Caster 7.6.6
Web Server - Tomcat
MS Windows XP SP2
Output: HTML, Excel 2000 , PDF, CSV, DOC
October 19, 2007, 06:52 AM
tlbrydie2Good Morning Leah,
I want to thank you for your assistance with my "TRIM" code. I have posted the solution to the problem. Just wanted to say thanks. Have a great day.
Prod: WebFOCUS 7.6.10 MRE
Oracle/Sybase
Test: DevStudio 7.6.6
WF Server 7.6.6
Report Caster 7.6.6
Web Server - Tomcat
MS Windows XP SP2
Output: HTML, Excel 2000 , PDF, CSV, DOC
October 19, 2007, 09:35 AM
Leahquote:
Good Morning Leah,
I want to thank you for your assistance with my "TRIM" code. I have posted the solution to the problem. Just wanted to say thanks. Have a great day
You're most welcome. You will find this forum is a great place for help and learning. I know I get much out of what I see.
Leah
October 19, 2007, 09:54 AM
Francis MarianiSo, you did not try the Dynamically Formatted Virtual Fields method? Two DEFINE fields instead of seven.
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
October 19, 2007, 08:20 PM
susannahFrancis, thanks for reminding about the SET CENT-ZERO=ON.
very useful now that i'm dealing with costs measured in mils.
i just put it in my edasprof.
right before the
set behaviour=abnormal.
| In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID |
October 19, 2007, 11:59 PM
Francis MarianiHey, you must have the Canadian version of WF
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