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'm Daniel's co-worker, I'll try to describe what we're doing.
We are getting data based on multiple parameters. For example: Count all of the yellow items that weigh less than 1 lb. that were in stock in the month of Jan, Feb, ..., Dec.
Using a loop, we're able to get the data we want, but it runs 12 different reports.
The code looks something like this:
report_display.fex
Loop through each month Jan, Feb, ..., Dec
TABLE FILE ITEM_DATA
-INCLUDE count_items.fex
ON TABLE HOLD AS ITEM_DATA
END
count_items.fex
...Work to get what we want...
TABLE FILE ITEM_COUNT
SUM
CNT.ITEMS
ON TABLE HOLD AS ITEM_COUNT
END
When we run the code, we get 12 different tables with the correct counts, which we're expecting. But we'd like to be able to just store these numbers and pass them back to the parent so they can be displayed along with other fex's we'll need to call to get other data.
The reason we don't just put this in one file is because we'll eventually need to do this with all the blue, red, green items. We're trying to have as little duplicate code as possible.
When we call the count_items.fex file, we'll pass in what the variables needed to retrieve the count from the parent.
Any help on how to do this would be greatly appreciated.
You can build your list of DEFINE fields and PRINT fields. Then use them in your table request. Take a look at sample below.
-* Create the list of Define fields
TABLE FILE CAR
SUM
COMPUTE CNTRY_LEN/I8 = ARGLEN(10, COUNTRY, CNTRY_LEN); NOPRINT
COMPUTE SEAT_ALPHA/A11 = EDIT(CNT.SEATS); NOPRINT
COMPUTE SEAT_CNT/A11 = IF CNT.SEATS EQ 0 THEN '0' ELSE TRIM('B', SEAT_ALPHA, 11, '0', 1, 'A11'); NOPRINT
COMPUTE DEFI_FLD/A500 = CTRAN(CNTRY_LEN, COUNTRY, 32, 95, 'A10') || '_CNT' || '/I11 = ' | SEAT_CNT || ';' ;
BY COUNTRY NOPRINT
ON TABLE SET ASNAMES ON
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS DEFI_FLD
END
-RUN
-* Create the list of Print fields
TABLE FILE CAR
SUM
COMPUTE CNTRY_LEN/I8 = ARGLEN(10, COUNTRY, CNTRY_LEN); NOPRINT
COMPUTE PRNT_FLD/A500 = CTRAN(CNTRY_LEN, COUNTRY, 32, 95, 'A10') || '_CNT' | ' AS ' | '''' | LCWORD2(10, COUNTRY, 'A10') || ',' || 'Count' || '''';
BY COUNTRY NOPRINT
ON TABLE SET ASNAMES ON
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS PRNT_FLD
END
-RUN
DEFINE FILE CAR
-INCLUDE DEFI_FLD
END
TABLE FILE CAR
PRINT
-INCLUDE PRNT_FLD
BY COUNTRY NOPRINT
WHERE RECORDLIMIT EQ 1;
END
-RUN
Here's an example of code I use to get date values put into amper variables for later usage:
TABLE FILE CAR
PRINT COUNTRY NOPRINT
COMPUTE CURRENT_DATE/A8 = EDIT(TODAY('A10'), '$$$$$$9999') | EDIT(TODAY('A10'), '99$99');
COMPUTE CURRENT_DATE_YYMD/YYMD = DATECVT(CURRENT_DATE, 'A8YYMD', 'YYMD');
COMPUTE CUTOFF_DATE/YYMD = DATEADD(DATEMOV(DATEADD(CURRENT_DATE_YYMD, 'M', -1), 'BOM'), 'D', -1);
WHERE RECORDLIMIT EQ 1;
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS DATEVALUES FORMAT ALPHA
END
-RUN
-READ DATEVALUES &CURRENT_DATE.A8 &CURRENT_DATE_YYMD.A8 &CUTOFF_DATE.A8
-TYPE &CURRENT_DATE
You could do the same thing where your TABLE FILE command produces your sum and drops it into a hold file, then the -READ pulls the values from the hold and puts them into ampervariables. Once they're in ampers you can do anything you like with them, including assigning them to DEFINE fields later in your code.
Notice that the -READ is reading from the file created by the TABLE FILE command.
Note -- HOLDLIST PRINTONLY very important, FORMAT ALPHA very important. Make sure you only have one line of output so the -READ grabs that line.
I'll be honest, it looks like you're dividing your code into a ton of pieces to "avoid duplication" which is a worthy goal. But maintainability should be your primary goal since it's the most expensive part of your process. Don't slice the pie into too many pieces.
J.
Posts: 1012 | Location: At the Mast | Registered: May 17, 2007
I don't see a problem with breaking it into 3 fexes. Why don't you go ahead and test it out.
-* Create the list of Define fields
-INCLUDE build_defines.fex
-* Create the list of Print fields
-INCLUDE build_prints.fex
DEFINE FILE CAR
-INCLUDE DEFI_FLD
END
TABLE FILE CAR
PRINT
-INCLUDE PRNT_FLD
BY COUNTRY NOPRINT
WHERE RECORDLIMIT EQ 1;
END
-RUN
Also as John pointed out trying to reduce the number of files and increasing the amount of reusable code sounds cool but it is a PIA to maintain. I was on project where everything was dynamic. The table name, by fields, print fields, where clauses (multiselect) and much more. And then we had to provide drilldowns as well. It was fun but not for the average WebFocus Developer.