As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.
Join the TIBCO Community TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.
From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
Request access to the private WebFOCUS User Group (login required) to network with fellow members.
Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.
I had a need for converting strings to strings of hexadecimal encoded byte values and created the following to implement that. I wonder whether people see opportunities for improvement?
To be more specific, we have a report that allows users to select data-sets based on a specific key (a string value). Those key's contain all kinds of characters that are invalid in a HOLD file name, but we need to be able to uniquely identify each HOLD file based on its key string. Hence, encoding those strings as hexadecimal. The user can then select several of these data-sets to combine the results (as a logical AND).
I defined a few functions to convert a single character to a hexadecimal value of it's ordinal number:
That's the part that I'm less happy about. A loop with SUBSTR doesn't seem very efficient.
In the end, this is used in this manner in our report:
-DEFAULT &KEY = 'Some key we''d like to convert to hexadecimal';
-SET &OUTPUT = '';
-INCLUDE STRING2HASH
-SET &HOLDFILE = 'YADAYADA_' || &OUTPUT;
TABLE FILE YADAYADA
PRINT *
BY ARTICLE_CODE
WHERE KEY EQ '&KEY';
ON TABLE HOLD AS FOCCACHE/&HOLDFILE FORMAT FOCUS INDEX KEY
END
Which creates a HOLD-file named YADAYADA_536F6D65206B65792077652764206C696B6520746F20636F6E7665727420746F2068657861646563696D616C
We keep a list of KEYs used previously in the same (http-)session, together with their associated HOLD-files. This list is available to the user to select KEYs from that they want to combine the results of the current KEY with, such that they get a report of ARTICLE_CODEs that match all selected KEYs.This message has been edited. Last edited by: Wep5622,
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 :
I quickly threw this together. Not totally neat but something you could play with a little. I tried to include the FPRINT into the decode but it didn't like. Anyway, to get something quickly I dropped the FPRINT out but then of course had to repeat the DECODE!
Just did a search and found this post from Francis (very last one) - glad to say(?) that his solution then was very similar to the one I have suggested above.
T
In FOCUS since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2
WebFOCUS App Studio 8.2.06 standalone on Windows 10
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004
Using that function with a master placed over the string and using occurs to read each character in the string, you can get the output string like this -
-DEFAULT &KEY = 'Some key we''d like to convert to hexadecimal';
DEFINE FUNCTION DEC2HEX(DECVAL/I3)
NUMBFST/I3 = INT(DECVAL / 16);
NUMBLST/I3 = DECVAL - (16 * NUMBFST);
CHARFST/A1 = DECODE NUMBFST(10 'A' 11 'B' 12 'C' 13 'D' 14 'E' 15 'F' ELSE 'X');
CHARLST/A1 = DECODE NUMBLST(10 'A' 11 'B' 12 'C' 13 'D' 14 'E' 15 'F' ELSE 'X');
CHARFST/A1 = IF CHARFST EQ 'X' THEN FPRINT(NUMBFST, 'I1', 'A1') ELSE CHARFST;
CHARLST/A1 = IF CHARLST EQ 'X' THEN FPRINT(NUMBLST, 'I1', 'A1') ELSE CHARLST;
DEC2HEX/A2 = CHARFST || CHARLST;
END
-RUN
FILEDEF STR2CONV DISK STR2CONV.ftm
-RUN
EX -LINES 5 EDAPUT MASTER,STR2CONV,CF,MEM,FILENAME=STR2CONV, SUFFIX=FIX,$
SEGNAME=ONE, SEGTYPE=S0, $
FIELD=CHARSTRING, ,A&KEY.LENGTH ,A&KEY.LENGTH ,$
SEGNAME=TWO, PARENT=ONE, OCCURS=&KEY.LENGTH, POSITION=CHARSTRING, SEGTYPE=S, $
FIELD=CHAR, ,A1 ,A1 ,$
-RUN
-WRITE STR2CONV &KEY
-RUN
TABLE FILE STR2CONV
PRINT COMPUTE HEXCHARS/A2 = DEC2HEX(BYTVAL(CHAR, 'I3'));
COMPUTE ORDER/I3 = ORDER + 1;
BY CHARSTRING NOPRINT
ON TABLE HOLD AS TEMPHLD1
END
-RUN
TABLE FILE TEMPHLD1
SUM HEXCHARS AS 'OUTPUT'
ACROSS ORDER NOPRINT
ON TABLE SAVE AS CHAROUT
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SET ASNAMES ON
END
-RUN
-SET &OutLen = &KEY.LENGTH * 2;
-READ CHAROUT &OUTPUT.A&OutLen.EVAL
-TYPE &OUTPUT
T
In FOCUS since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2
WebFOCUS App Studio 8.2.06 standalone on Windows 10
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004
-SET &CHAR2HEX='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
DEFINE FILE CAR
OUT/A72=UFMT('&CHAR2HEX', 36, 'A72');
END
TABLE FILE CAR
PRINT
COMPUTE HEX/A20 = UFMT(COUNTRY,10,'A20');
OUT
BY COUNTRY
END
"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
That I (and clearly several others) did not manage to find it has no doubt to do with the unfathomable name of the function and the somewhat dubious location in the documentation. Why is that function called UFMT?
It's also not really converting the 'format' of the field, both input and output are alphanumeric fields. There are all kinds of similar functions that change case of characters or turn strings into patterns and such and all those are found under "String Functions". This one is under "Format Conversion Functions" - go figure...
Well, that is kind of typical for WebFOCUS, which is why I figured I should ask around.
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 :
TABLE FILE CAR
PRINT COUNTRY/U20
BY COUNTRY
ON TABLE SET ONLINE-FMT STANDARD AND PAGE NOLEAD
END
1 COUNTRY COUNTRY
------- -------
ENGLAND 454E474C414E4420202020202020202020202020
FRANCE 4652414E43452020202020202020202020202020
ITALY 4954414C59202020202020202020202020202020
JAPAN 4A4150414E202020202020202020202020202020
W GERMANY 57204745524D414E592020202020202020202020
That's why it's called U-format.
- Jack Gross WF through 8.1.05
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005
FILENAME=car, SUFFIX=FOC , $
SEGMENT=ORIGIN, SEGTYPE=S1, $
FIELDNAME=COUNTRY, ALIAS=COUNTRY, USAGE=A10, FIELDTYPE=I, $
SEGMENT=COMP, SEGTYPE=S1, PARENT=ORIGIN, $
FIELDNAME=CAR, ALIAS=CARS, USAGE=U16, $
.
.
.
DEFINE FILE CAR
X_COUNTRY/U10 = COUNTRY;
END
TABLEF FILE CAR
PRINT COUNTRY X_COUNTRY CAR
END
Cannot use on INDEXed fields in FOCUS db, but can be used on ACTUAL (USAGE=U4000,ACTUAL=A4000V),in other DBs.
or if you have SQL Server:
-SET &ECHO=ALL;
-SET &INPUT = 'Some key we'd like to convert to hexadecimal';
-SET &LEN = &INPUT.LENGTH*2;
SQL SQLMSS
SELECT master.dbo.fn_varbintohexstr(CAST(&INPUT.QUOTEDSTRING AS VARBINARY));
TABLE
HOLD
END
-RUN
-READ HOLD &0x.2 &OUTPUT.&LEN.EVAL
-TYPE &OUTPUT
Alan. WF 7.705/8.007
Posts: 1451 | Location: Portugal | Registered: February 07, 2007