Focal Point
[TIP] CTRAN without pain
March 24, 2010, 03:18 PM
Francis Mariani[TIP] CTRAN without pain
I thought I'd make a separate post about this.
You can use CTRAN without having to figure out the Hex value (which is different for ASCII and EBCDIC) by incorporating the BYTVAL function into the code:
Original syntax:
CTRAN(charlen, string, decimal, decvalue, outfield);
BYTVAL(character, outfield);
Adapted syntax:
CTRAN(charlen, string, BYTVAL('from','I3'), BYTVAL('to','I3'), outfield);
e.g.:
-*-- Convert Apostrophe to Right Single Quotation Mark -------------------------
-SET &OBJ_NAME4 = CTRAN(&OBJ_NAME.LENGTH, &OBJ_NAME, BYTVAL('''','I3'), BYTVAL('’','I3'), 'A&OBJ_NAME.LENGTH');
-*-- Convert Slash and Dash to blank -------------------------------------------
RGN1/A50 = CTRAN(50, RGN0, BYTVAL('/','I2'), BYTVAL(' ','I2'), 'A50');
RGN2/A50 = CTRAN(50, RGN1, BYTVAL('-','I2'), BYTVAL(' ','I2'), 'A50');
You never have to look for an ASCII or EBCDIC chart again!
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
March 24, 2010, 03:27 PM
njsdenVery nice indeed Francis. I'll make sure to take note of the tip (a bookmark on this topic would be better, of course
)
- Neftali.
Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
March 24, 2010, 05:10 PM
WazThat is great. Cross Platform.
The only issue is when you want to CTRAN a non printable.
Waz...Prod: | WebFOCUS 7.6.10/8.1.04 | Upgrade: | WebFOCUS 8.2.07 | OS: | Linux |
Outputs: | HTML, PDF, Excel, PPT |
In Focus since 1984 |
Pity the lost knowledge of an old programmer! |
March 25, 2010, 09:47 AM
Francis MarianiIt's not an issue - you can use CTRAN in it's usual form for that.
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
March 25, 2010, 01:23 PM
jgelonaI think Waz's point is that with non-printable characters you still have to look up the code in and ASCII or EBCDIC manual (unless you have them memorized).
This is a great tip. Probably why I never thought of it.
In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
March 25, 2010, 03:03 PM
j.grossInteresting that HEXBYT behaves properly even when the fex source is in Unicode.
Apparently 16-bit Unicode source is mapped to 8-bit (ASCII) coding before dialog manager sees it, and that's how the Focus code is placed in FOCSTACK for execution.
-- But what does the mapping do with non-Latin Unicode values?
March 25, 2010, 05:26 PM
Wazquote:
It's not an issue - you can use CTRAN in it's usual form for that.
I was only pointing out that if you wanted to CTRAN a character to, say, a carriage return, you would have to go with the number.
Waz...Prod: | WebFOCUS 7.6.10/8.1.04 | Upgrade: | WebFOCUS 8.2.07 | OS: | Linux |
Outputs: | HTML, PDF, Excel, PPT |
In Focus since 1984 |
Pity the lost knowledge of an old programmer! |
March 26, 2010, 12:49 AM
Devi CThanks for the tip...Francis
WebFOCUS 7.6.4,7.6.9
OS: Windows XP
HTML,EXCEL,PDF
June 25, 2010, 12:38 PM
Cati - FranceBonjour Francis,
I have a field in a table which contains this value : "100-130-150-200-250 €".
In excel the field appears as "100-130-150-200-250 ¤" (euro sign is not converted properly).
How can I use your example to keep the euro sign in excel ?
Thanks for your help.
Catherine
7.7.02 (Html, Excel, Ahtml, Pdf,Graph,.....)
OS400 V5R3, V5R4
Windows 2000/2003/2007/2010
June 29, 2010, 04:49 PM
N.SelphThat is probably related to your NLS values. There have been other recent posts on that.
(Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats)
July 13, 2010, 03:14 PM
FrankDutchCati
is this field always in the same format?
numbers and dash at the same place?
If i would suggest some other solution
something like
NEWFORMAT1/A15=EDIT(OLDFIELD,'999$999$999$999$999$$');
-* this wil give you the string without dashes and valuta code
NEWFORMAT2/D15=EDIT(NEWFORMAT1);
now your newformat2 field is a number and you can present it with any valuta code, and that might work in excel as it should (although the NLS remark might still be important)
|
Frank |
| prod: WF 7.6.10 platform Windows, databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7 test: WF 7.6.10 on the same platform and databases,IE7 |