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 have a field in a FOCUS table that contains product codes separated by commas and I would like to sort these codes from lowest to highest. e.g.: when I have as input "2568, 5685, 1025" I would like to get this result: "1025, 2568, 5685". Is there a function or a command in WebFOCUS that does this?
Regards, Mathijs.This message has been edited. Last edited by: Kerry,
WebFOCUS 8.1.0.5 Windows 10 xls, csv, dbf
Posts: 10 | Location: France | Registered: November 24, 2009
Not seeing how that last snippet is going to work. The data that needs to be sorted is all in the same record, so this can't really accomplish what's needed.
As GamP say, there is no functions to accomplish what you want. You're basically just wanting to reorganize the contents of an alpha string. The only way I see this happening is to use some implementation of the MacGuyver technique to create multiple records for each one record, where each individual record contains one of the values from your string. Then you can sort them low to high and hold them. Then re-read your hold file concatentating them back together using the LAST functionality. Not much time to play around with this right now, but that's the gist of what it would take.
Regards,
Darin
In FOCUS since 1991 WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex WF Client: 77 on Linux w/Tomcat
Posts: 2298 | Location: Salt Lake City, Utah | Registered: February 02, 2007
Answers to three questions may help in solving this:
Are the values always numeric? Are there always the same number of values in each set of product codes? Are the values always unique in each set of product codes?This message has been edited. Last edited by: Francis Mariani,
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
Let's hope there are only 5 possible values of product code in the string and not 100.
Regards,
Darin
In FOCUS since 1991 WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex WF Client: 77 on Linux w/Tomcat
Posts: 2298 | Location: Salt Lake City, Utah | Registered: February 02, 2007
Thanks a lot this does exactly what I needed! However as you did not have all the clues there is going to be some modification needed if you can. Here are the answers to your first post, sorry I did not have much time to reply earlier: - yes the values are always numeric but, - the number of values in one record is actually variable and ranges from 1 to up to 6 values in one record - each value is assumed to be unique in each set
I gave this a try with my data and it seems to work great apart from the fact that the number of values being variable the output is not completely right. I guess there will be some counting involved but I don’t know if this is possible without making the thing too complex. The field I am working on is named TXCOMBI and its actual size is A80. Hope you can work out something!
Please let me know if you need any more details.
Mathijs.
WebFOCUS 8.1.0.5 Windows 10 xls, csv, dbf
Posts: 10 | Location: France | Registered: November 24, 2009
Except that extending this to six values makes it completely unusable. And there's a weird thing happening where for some rows, the values of the previous rows are overriding the current rows!
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
SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA
-RUN
-*== Create a file to test with ============================
FILEDEF MASTER DISK product.mas
-RUN
-WRITE MASTER FILENAME=PRODUCT, SUFFIX=FOC, $
-WRITE MASTER SEGNAME=PRODUCT, SEGTYPE=S1, $
-WRITE MASTER FIELDNAME=PRODUCT_NAME , FORMAT=A14, $
-WRITE MASTER FIELDNAME=PRODUCT_CODES, FORMAT=A80, $
-RUN
-*== Create the file and enter some data ===================
CREATE FILE PRODUCT
MODIFY FILE PRODUCT
FIXFORM PRODUCT_NAME/13 PRODUCT_CODES/50
MATCH PRODUCT_NAME
ON MATCH GOTO TOP
ON NOMATCH INCLUDE
DATA
Apples 140, 120, 4550, 1, 333, 27
Oranges 114, 1104, 400
Pomegranates 3400, 1445, 472, 235, 7321, 943
Cherries 125, 46426
Mangoes 516, 9182, 1291, 93
Bananas 11111, 33333, 22222, 44444, 55555, 16, 1786, 432
Clementines 2288
END
-*== And now for the real thing ============================
FILEDEF OUT DISK out.ftm (LRECL 50 RECFM V
MODIFY FILE PRODUCT
COMPUTE PRODCODE/A10 = ;
COMPUTE CNTR/I4=;
NEXT PRODUCT_NAME
ON NEXT COMPUTE CNTR=1;
ON NEXT PERFORM PUT_OUT
ON NONEXT GOTO EXIT
CASE PUT_OUT
COMPUTE PRODCODE = LJUST(10,GETTOK(D.PRODUCT_CODE, 80, CNTR, ',', 10,'A10'), PRODCODE);
IF PRODCODE EQ ' ' THEN GOTO ENDCASE;
TYPE ON OUT "<D.PRODUCT_NAME><PRODCODE>"
COMPUTE CNTR = CNTR+1;
GOTO PUT_OUT
ENDCASE
DATA
END
FILEDEF MASTER DISK out.mas
-RUN
-WRITE MASTER FILENAME=OUT, SUFFIX=FIX, $
-WRITE MASTER SEGNAME=OUT, $
-WRITE MASTER FIELDNAME=DUMMY , FORMAT=A2 , ACTUAL=A2 , $
-WRITE MASTER FIELDNAME=PRODUCT_NAME , FORMAT=A14, ACTUAL=A14, $
-WRITE MASTER FIELDNAME=PROD_CODE , FORMAT=A10, ACTUAL=A10, $
-RUN
TABLE FILE OUT
SUM COMPUTE CODESINORDER/A80V = IF PRODUCT_NAME NE LAST PRODUCT_NAME THEN PROD_CODE ELSE LAST CODESINORDER || ',' || PROD_CODE;
BY PRODUCT_NAME BY PROD_CODE
ON TABLE HOLD
END
TABLE FILE HOLD
SUM MAX.CODESINORDER
BY PRODUCT_NAME
END
It'll work for any number of products in your field. It may need to be adjusted for other fields to be shown in the report, you could do this by means of a join from the last hold file to your original focus file.
Hope this helps ...
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007
I have tried to adapt Tony and GamP's procedures to my master file but being a newbie on WebFocus I'm having some trouble finding out what I must change to fit my master file.
It is originally created by loading a csv file into a FOC file using FILEDEF and the output will also be a FOC file. The field TXCOMBI is the field that contains the codes to be sorted. There are more fields in this master that must be kept as such but I have only kept field PRODUCT for the example.
Thanks in advance and sorry for the late feedback (pretty busy at the moment )
WebFOCUS 8.1.0.5 Windows 10 xls, csv, dbf
Posts: 10 | Location: France | Registered: November 24, 2009
Just to show that there is more than 1 way to tackle a problem with WebFocus, each having its measure of ingenuity...
-* File Mathijs1.fex
FILEDEF PRODUCT DISK product.txt
-RUN
-* Creating the data (added an X in order to have an 80 char field)
-WRITE PRODUCT Apples 140, 120, 4550, 1, 333, 27 X
-WRITE PRODUCT Oranges 114, 1104, 400 X
-WRITE PRODUCT Pomegranates 3400, 1445, 472, 235, 7321, 943 X
-WRITE PRODUCT Cherries 125, 46426 X
-WRITE PRODUCT Mangoes 516, 9182, 1291, 93 X
-WRITE PRODUCT Bananas 11111, 33333, 22222, 44444, 55555, 16 X
-WRITE PRODUCT Clementines 2288 X
-RUN
-* Creating the MASTER for the data
EX -LINES 6 EDAPUT MASTER,PRODUCT,C,MEM
FILENAME=PRODUCT , SUFFIX=FIX
SEGMENT=PRODUCT, SEGTYPE=S0
FIELDNAME=PRODUCT, ALIAS=PRODUCT, USAGE=A15, ACTUAL=A15, $
FIELDNAME=NLIST, ALIAS=NLIST, USAGE=A80, ACTUAL=A80, $
FIELDNAME=NCHAR, ALIAS=NCHAR, USAGE=A1, ACTUAL=A1, $
-RUN
-* Retrieving the values from each field (up to 6)
DEFINE FILE PRODUCT
-REPEAT #GETVAL FOR &I FROM 1 TO 6;
VAL&I / I9 =EDIT(GETTOK(NLIST, 80, &I, ',', 9, 'A9'));
-#GETVAL
END
-* Output the values separately
TABLE FILE PRODUCT
PRINT
-REPEAT #PVAL FOR &I FROM 1 TO 6;
VAL&I
-#PVAL
BY PRODUCT
ON TABLE SAVE AS VLIST
END
-* Create an "alternate" master for this file in order to access each value as a different record
EX -LINES 6 EDAPUT MASTER,VLIST,C,MEM
FILENAME=VLIST , SUFFIX=FIX
SEGMENT=VLIST, SEGTYPE=S0
FIELDNAME=PRODUCT, ALIAS=PRODUCT, USAGE=A15, ACTUAL=A15, $
SEGMENT=VALS, PARENT=VLIST, OCCURS=VARIABLE
FIELDNAME=VAL, ALIAS=VAL, USAGE=I9, ACTUAL=A9, $
-RUN
-* Sort the values
TABLE FILE VLIST
BY PRODUCT
BY VAL
IF VAL NE 0
ON TABLE HOLD
END
-* Concatenate the sorted values
DEFINE FILE HOLD
AVAL/A9=RJUST(9, FTOA(VAL, '(D9c)', 'A9'), 'A9');
VAL_LIST/A80=IF PRODUCT NE LAST PRODUCT THEN AVAL ELSE
SUBSTR(80, LAST VAL_LIST, 1, 70, 70, 'A70') || ',' || AVAL;
END
-* Output the sorted field
TABLE FILE HOLD
SUM MAX.VAL_LIST
BY PRODUCT
END
Daniel In Focus since 1982 wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006
Danny, it looks like a great solution. My only concern is that you are hardwiring the EDAPUT for that file within the FOCEXEC. I am an adamant proponent of 'write ahead code'. Personally I would prefer to create the holdmast on the fly and based upon what is being 'fed in'. Hey just my thoughts.
But then you can't use the OCCURS clause which is the key to the whole solution. And in Danny's example, the occurs is variable which takes care of an unknown numbers of values.
Hi all As promised I have posted the "Creating dynamic reports at run time" code on my website http://www.infogoldusa.com Should you have any questions or concerns, please feel free to contact me.
Just to show that there is more than 1 way to tackle a problem with WebFocus, each having its measure of ingenuity...
Ditto for this late entry.
-* Split the TXCOMBI codes into a single column of values in multiple hold files.
-REPEAT :ENDREPEAT1 FOR &I FROM 1 TO 10
-SET &HOLDNAME = 'HOLD' || '&I';
DEFINE FILE PANEL
VAL_A/A13 = GETTOK(TXCOMBI,80,&I,',',13,'A13');
VAL_N/D13 = ATODBL(VAL_A,'13','D13');
END
TABLE FILE PANEL
PRINT PRODUCT VAL_A VAL_N
WHERE VAL_N NE 0 ;
ON TABLE HOLD AS &HOLDNAME.EVAL
END
-RUN
-IF &LINES EQ 0 GOTO :EXITREPEAT1 ;
-:ENDREPEAT1
-:EXITREPEAT1
-* Combine/merge the hold files and sort the codes by product.
-SET &NUM_REPEATS = &I - 2 ;
TABLE FILE HOLD1
PRINT VAL_A
BY PRODUCT
BY VAL_N
ON TABLE HOLD AS VALHOLD
-REPEAT :ENDREPEAT2 FOR &I FROM 2 TO &NUM_REPEATS
-SET &HOLDNAME = 'HOLD' || '&I';
MORE
FILE &HOLDNAME.EVAL
-:ENDREPEAT2
END
-RUN
-* Put the codes back into strings in one column.
DEFINE FILE VALHOLD
VALSTRING/A80 = IF PRODUCT NE LAST PRODUCT THEN VAL_A ELSE TRIM('B',LAST VALSTRING,80,' ',1,'A65') || ',' || VAL_A ;
END
TABLE FILE VALHOLD
SUM LST.VALSTRING AS 'TXCOMBI'
BY PRODUCT
END
This message has been edited. Last edited by: Dan Satchell,
WebFOCUS 7.7.05
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007
Nice twist Dan, but one thing I would point out is that you are processing the entire data 10 times where as Danny only parses the data twice. Not too bad if you only have hundreds of records, but excessive if they number in the millions!
Hmm, I know which one I'd use
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
... one thing I would point out is that you are processing the entire data 10 times where as Danny only parses the data twice. Not too bad if you only have hundreds of records, but excessive if they number in the millions!
Tony: An excellent observation - although if Mathijs is correct that a maximum of 6 codes can occur for any product, then my code would make a maximum of seven passes through the data in the parsing step. Mathijs did indicate earlier that the original data comes from a CSV file, so I assumed it wasn't millions of records - but Danny's code would definitely prove more efficient. I was interested in avoiding the need for an alternative master.This message has been edited. Last edited by: Dan Satchell,
WebFOCUS 7.7.05
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007