Focal Point Banner


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.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Setting a variable from calling an external fex

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] Setting a variable from calling an external fex
 Login/Join
 
Gold member
posted
Is there a way to set a variable in a define by calling an external fex file?

Example:
DEFINE FILE MY_COUNTS
COUNT_1/I8 = EX some_fex_file.fex
END

Is this possible or is there a better way of doing this?

Thank,

Daniel

This message has been edited. Last edited by: Kerry,


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
 
Posts: 59 | Registered: November 15, 2012Report This Post
Expert
posted Hide Post
With thi sort of thing you would call the fex and use one of its results.

In this example the some_fex_file will set an amper variable to a value.

-INCLUDE some_fex_file
DEFINE FILE MY_COUNTS
COUNT_1/I8 = &Res
END


You can also read a hold file from an EX or set a global Amper variable.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Master
posted Hide Post
Depending on what you are doing, DEFINE FUNCTION may be an option.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
 
Posts: 975 | Location: Oklahoma City | Registered: October 27, 2006Report This Post
Member
posted Hide Post
Waz, in your example

COUNT_1/I8 = &Res

Does &Res get set in the some_fex_file?


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 18 | Registered: September 13, 2012Report This Post
Member
posted Hide Post
jgelona,

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.

Thanks,
Brian


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 18 | Registered: September 13, 2012Report This Post
Guru
posted Hide Post
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


WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
 
Posts: 320 | Location: Memphis, TN | Registered: February 12, 2008Report This Post
Member
posted Hide Post
Mighty Max, what if you wanted to split your code up into different fex files, or is this not a good idea?


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 18 | Registered: September 13, 2012Report This Post
Expert
posted Hide Post
From my understanding of your first example, you wanted to have a fex return a value.

You can set an amper variable in the called fex and use it in the calling fex.

-INCLUDE adds a fex inline, and EX executes a FEX with a clean environment.

There are many examples of creating an amper variable from some data in the forum.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
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, 2007Report This Post
Guru
posted Hide Post
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.


WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
 
Posts: 320 | Location: Memphis, TN | Registered: February 12, 2008Report This Post
Gold member
posted Hide Post
Mighty Max, can you explain more what

DEFINE FILE CAR
-INCLUDE DEFI_FLD
END

does? I am new to Webfocus and am trying to understand your code. Thanks

Daniel


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
 
Posts: 59 | Registered: November 15, 2012Report This Post
Expert
posted Hide Post
-INCLUDE add WebFOCUS code from another fex inline with this one, as if it is part of the calling fex.

For example

DEFI_FLD.fex contains
COUNT_1/I9 = {some code} ;


Your fex will at execution effectively contain
DEFINE FILE CAR
COUNT_1/I9 = {some code} ;
END


I would suggest that you look into getting some training on WebFOCUS.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Setting a variable from calling an external fex

Copyright © 1996-2020 Information Builders