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     [SOLVED] DEFINE FUNCTION : Using temporary, local variables

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] DEFINE FUNCTION : Using temporary, local variables
 Login/Join
 
Gold member
posted
I’ve hunted for a while on how using temporary, local variables in a function definition, but no luck.

Can someone shed some light on how to accomplish this ?

This code shows that the function works, just not when local variables are used to store intermediate values.

This has 2 DEFINE FUNCTIONs, Length1 is right and Length2 is wrong.

 DEFINE FUNCTION Length1 (SourceString/A4028)

-* Assigning to output variable (FUNCTION name) directly works fine :

    Length1/I4  = ARGLEN(4028, SourceString, 'I4');

END

DEFINE FUNCTION Length2 (SourceString/A4028)
-* This DOES NOT work :

-* Use temp variable to store value,
-*   then assign to output variable (FUNCTION name)

-* Function returns 12 = length of the variable name SourceString
-* This does not measure the string contained in SourceString though.

-SET &Temp = ARGLEN(4028, SourceString, 'I4');

    Length2/I4  = &Temp;

END

TABLE FILE CAR
HEADING
"Using DEFINE FUNCTION with 'local' variables causes problems ?"
 PRINT 
   CAR
   MODEL
-* These COMPUTEs test the Length1 function, and do work properly :
   COMPUTE     CAR/I4 = Length1 (CAR)     ;  AS 'CORRECT,Length of,CAR'
   COMPUTE   MODEL/I4 = Length1 (MODEL)   ;  AS 'CORRECT,Length of,MODEL'

-* These COMPUTEs test the Length2 function, and do work WRONG :
   COMPUTE     CAR/I4 = Length2 (CAR)     ;  AS 'WRONG :,Length of,Variable,Name,''SourceString'''
   COMPUTE   MODEL/I4 = Length2 (MODEL)   ;  AS 'WRONG :,Length of,Variable,Name,''SourceString'''
END


Function Length1 works OK when the result of the ARGELN function is assigned directly to the FUNCTION name.

But function Length2 doesn’t work properly because it apparently ‘sees’ the name of the variable instead of the actual value contained in the variable.

Thanks in advance for any insight you can give !

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


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Virtuoso
posted Hide Post
[quote]DEFINE FUNCTION Length2 (SourceString/A4028)
-* This DOES NOT work :

-* Use temp variable to store value,
-* then assign to output variable (FUNCTION name)

-* Function returns 12 = length of the variable name SourceString
-* This does not measure the string contained in SourceString though.

Don't try to use -SET here.

This document gives the syntax -- very tersely, and without giving examples of use of intermediate variables.

Temporary variables, to hold intermediate calculated results, are declared in DEFINE FUNCTION just as in DEFINE FILE:

varname/format=expression;


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Gold member
posted Hide Post
Thanks Jack,

That work nicely in most cases, but for some reason -REPEAT won't take the variable when a value is assigned, although it WILL take a constant :

i.e. :
 
X/I4 = 27; 
-REPEAT label X TIMES 
...
label


...doesn't work, but this DOES work :
((FOC303) CONTROL LINE NOT RECOGNIZED IN FOCEXEC: -REPEAT label X)

 
-REPEAT label 27 TIMES 
...
label


Here's the entire program to put in perspective :

 
-* Variables-Forum-Question-V2.fex

DEFINE FUNCTION Length (SourceString/A4028)

StringLength/I4 = ARGLEN (4096, SourceString, 'I4');
  CountChars/I4 = 0;

-* Does work but NOT with a variable : 
-REPEAT EndCount 27 TIMES
-* Doesn't work : 
-*REPEAT EndCount StringLength TIMES

    CountChars = CountChars + 1;

-EndCount

    Length/I4  = CountChars;

END

-TYPE ---------------------------------------------------------------------

TABLE FILE CAR
HEADING
"Using DEFINE FUNCTION with variables causes problems with REPEAT loop"
""
"Fails using :"
"-REPEAT LABEL   variable   TIMES"
"(FOC303) CONTROL LINE NOT RECOGNIZED IN FOCEXEC: -REPEAT EndCount StringLength"
""
"Works OK with  :"
"-REPEAT LABEL   constant   TIMES"
 PRINT
   CAR
   MODEL
-* These COMPUTEs test the Length function using a REPEAT loop :
   COMPUTE     CAR/I4 = Length (CAR)      ;  AS 'Length,of CAR,Using,REPEAT'
   COMPUTE   MODEL/I4 = Length (MODEL)    ;  AS 'Length,of MODEL,Using,REPEAT'
END


Does REPEAT require some 'prep work' to make it work ?

Thanks again,

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


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Virtuoso
posted Hide Post
The function you define, when used in other defines that are ultimately used in table, is fired up once per input record, and its argument values vary accordingly.

Any dialog manager statements (-SET, -REPEAT, etc.) appearing in the DEFINE ... END chunk of code are executed when the DEFINE FUNCTION code is initially parsed, not when the function is subsequently referenced. Hence, the dialog manager statements have no access to the function's argument values. Dialog Manager, as a macro language, can sometimes be useful within DEFINE (to calculate constants, or to generate repetative lines of code).

The reason your -REPEAT referencing StringLength does not work should now be clear: StringLength, to dialog manager, is not a reference to a variable -- it is interpreted an alphanumeric constant (where a numeric value is expected).


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Gold member
posted Hide Post
Yes, thanks Jack,

That fits the results of "View Source" on the HTML output, where I see it looking at the positions in the variable SourceString and returning S,o,u,r,c,e,S,t,r,i,n, and g !

I did notice the HTML source showed the DEFINEs at the top, which made me suspicious, and you've validated my suspicion !

I resorted to DM's -REPEAT when the WF version of REPEAT gave me problems that seemed to be resolved by using -REPEAT.

Question now is, how to do a WF REPEAT (not the DM '-REPEAT') in a DEFINE FUNCTION to spin through a string (as just one application) ?

Thanks for the lesson in Dialog Manager, too, that was insightful. I hadn't realized the impact on defining functions.

So, how can a value in the argument passed into the function, or a value based on that (such as the lengtrh of the field data) be stored and used with each new record in the TABLE ?

I'll work on that, but if you have any insight that helps me find the answer, I'd appreciate it !

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


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
<JG>
posted
Charles,

Unfortunately there is no such thing as REPEAT in the WebFocus Reporting language.

REPEAT is specific to MODIFY and MAINTAIN.

Within reporting you only have the DM -REPEAT functionality which as Jack indicated
can only work with variables and constants not real columns directly.
 
Report This Post
Gold member
posted Hide Post
I was afraid of REPEAT being peculiar to MAINTAIN.

Help shows DM's -REPEAT and two (2) listings for REPEAT (without the DM '-'), one of which specifies "Maintain" and one does not, so I (mistakenly ?) thought there was one for MAINTAIN and one for regular WF.

So, is there a way to "loop" in a user-defined DEFINE FUNCTION ?

I want to loop through a string to pick out parts of it.

Thanks for all the help from everyone !

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


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
<JG>
posted
Charles,

Someone may know better but the only way that you will be able to achieve that
is by writing and linking a true function (user written sub routine) not using DEFINE FUNCTION
and passing the length as a parameter.
 
Report This Post
Gold member
posted Hide Post
Ah ! My mistake !

I thought a "DEFINE FUNCTION" **was** a 'user-written subroutine' !

I'll start a new thread on this question :
"How to write subroutines using WebFOCUS ?"

Thanks for the tip !


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Expert
posted Hide Post
User-written subroutines as referenced here are 3GL programs that are compiled and linked into an executable library.

A DEFINE FUNCTION is only for defines. You could actually put your -REPEAT code in a DEFINE stub that you -INCLUDEd into your program to do what you want. Give that a thought or two.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Expert
posted Hide Post
Any Dialog Manager statements in a Define Function are evaluated at the time the Define Function is evaluated and loaded into memory.

You can put as many DM statements as you in it, but when the Define Function is called, all that is left is the results of the DM evalualted as FOCUS commands.


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
Gold member
posted Hide Post
Thanks Waz,

DM seems to be the deal-breaker here, and so now I've started a new thread on this question :

See "How to write subroutines using WebFOCUS ?"

Where I am still trying to performa loop in a DEFINE FUNCTION, or any way that works ! (Even GOTOs if necessary !)

Thanks


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report 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     [SOLVED] DEFINE FUNCTION : Using temporary, local variables

Copyright © 1996-2020 Information Builders