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] Purpose for Parameters in Intrinsic (FW) String Functions

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Purpose for Parameters in Intrinsic (FW) String Functions
 Login/Join
 
Gold member
posted
Can someone please help me with an explanation of the inlength and sublength parameters in, for example, the SUBSTR and ARGLEN functions ?

My two (related ?) questions are :

Q1:
It would seem that inlength would be unnecessary, since this is the length of the ‘parent’ string.
When would inlength **NOT** be the length of the ‘parent’ string ?
(If you want to use only part of the string, why not just pass that part ?)

The “Help” files even say that is (usually ?) =(End – Start) + 1, which makes sense.

Q2:
The ARGLEN function has a similar parameter, infield, so I wrote a DEFINE FUNCTION to simplify it, since it seems redundant (imho) :

-*-----------------------------------------------
DEFINE FUNCTION Length (SourceString /A255)
-* Syntax ARGLEN(inlength, SourceString, outlength)
-* Arguments :
-* inlength :
-* Only uses inlength characters if LT actual string length
-* May be longer than original string length with no effect ?
-* SourceString: string to be measured
-* outlength is name of function to return value to calling program

-* Uses inlength=255 as max possible value to eliminate need to know this value :

Length/I4 = ARGLEN(255, SourceString, Length);

END
-*-----------------------------------------------

-*-----------------------------------------------
From “Help” :
SUBSTR(inlength, parent, start, end, sublength, outfield)
ARGLEN(inlength, infield, outfield)
-*-----------------------------------------------

Can someone shed some light on when SUBSTR’s sublength value would **NOT** be (End – Start) + 1 ?

When would inlength **NOT** be the length of the SourceString passed into either FUNCTION ?

Thanks
PS:
I will address the issue of an 'extra level of complexity' separately, but this is mostly an 'academic exercise for now !

Thanks

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
Expert
posted Hide Post
The functions have no access to the master file descriptions. Therefore they have no way of knowing what the in length is.

As for SUBSTR and the sublength. What if you were extracting a piece out of the middle of a string and you had done two POSITs to find out where the beginning and end of the substring were? That would be a situation when the sublength value would not be end - start +1.

I personally do a lot of this when parsing Unix directory listings looking for pieces like the fex name without the .fex suffix.


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

That makes sense. I didn’t realize that access to the MFD/MAS would be necessary.
I just figured that the SUBSTR function would find the original length for you, so to speak, since it would ALWAYS be needed, right ?


Re : ARGLEN :
How would the programmer know how long the string is, without using ARGLEN to find it ? (Seems recursive to me, or am I missing something else ?)

Are there times when you might want to use a length other than the actual length of the string ?


Re : SUBSTR :
I can see why SUBSTR would need either pair of values (start and end) or (Start and sublength), but not why you'd need all three values ?
Given either pair of values, the third value can be calculated, right ?


Plus, it seems almost too obvious to ask why ARGLEN would need the length of the string you’re measuring.
If you know the length, why would you need to use ARGLEN ?

This all makes me think I’m missing something else important (like your little gem about not having access to the MAS - that was enlightening !) ?

Thanks again,


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Expert
posted Hide Post
You should also understand that these function have been around a very long time, used to be called User Written Subroutines.

Once they were created, the parameters couldn't be changed or improved, because any existing program using them would error.


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
Expert
posted Hide Post
Charles,

Upon examination, you could easily pick apart a lot of the functions, most of them seem to require unnecessary parameters.

We just live with them, if they're usable and not buggy...

When a function is used in a DEFINE or a COMPUTE in WebFOCUS code, you don't require ARGLEN, because the length of the data value is the length of the field in a Master or a virtual (DEFINE) field. If the function is used in Dialogue Manager scripting code, you do need to use ARGLEN because the data value is a Dialogue Manager variable and you may not know the length of the data value.


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Gold member
posted Hide Post
Ah ! The legendary "Legacy Software" and the "de facto standard" strike again !

Makes sense though, to be "backward compatible."

Seems like incentive to write new, modern functions, before someone else writes one that requires such explanations.

For simplicity, I've re-written ARGLEN as 'Length', for example, x = Length (String), where this function only requires the one argument :

--------------------------------------------------------
DEFINE FUNCTION Length (SourceString/A255)

-* Use inlength=255 as max possible value to eliminate need to know this value :
Length/I4 = ARGLEN(255, SourceString, Length);

END

TABLE FILE CAR
PRINT CAR
COMPUTE CarLength/I4 = Length (CAR) ;
MODEL
COMPUTE ModelLength/I4 = Length (MODEL) ;
END
--------------------------------------------------------

All this really does is make it easier to write (and read) the code, although (as I said above) it adds another 'level of complexity' because my 'simple' function calls the more complex WF function.

The upside is that the code is easier to read and more manageable, and the downside is that processing large files takes a little longer.


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Master
posted Hide Post
Having created a few User Written Subroutines myself I understand why they require the length. From what I can see is that the subroutines do not pass the values then self but a reference to the location they are stored, ( a pointer in C). as such when to access an alphanumeric field the subroutine needs to know how many characters at that memory location make up the field.

Hope this helps.




Scott

 
Posts: 865 | Registered: May 24, 2004Report This Post
Gold member
posted Hide Post
Good point – variable/field names are just pointers, and can be passed by reference (i.e.: pointers) or by value.

Numeric variables have fixed lengths, so no problem, but variable length strings are a different breed because the length is not fixed and must be provided in some way.

I think C stores the variable length string as the base address and is delimited with a binary ‘0’/null, while some languages use the base address plus a length parameter/offset ?

Either method would eliminate the need for passing the length as a parameter since it can be calculated or located

GinnyJakes mentioned that the MAS/MFD is not accessible, which would be the third option ?

I was wondering what method is used to store strings in WF - while they are being processed (internally) ?

It seems there would be a less cumbersome way to use these functions, especially ARGLEN, which requires the length as an argument to find the length ?

This seems redundant to me, and that there would be some intrinsic function (i.e.: provided by WebFOCUS at the ‘system level’) to accomplish this ?

Does anyone know exactly how strings are stored internally in WebFOCUS ?

Do newer versions store strings differently, and the “legacy” functions just haven’t ‘caught up’ yet ?

Thanks for any insights into the internal workings of WebFOCUS you can give me !


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Gold member
posted Hide Post
PS:

I have noticed that this ‘inlength’ parameter can be fudged, such as 255, because both ARGEL and SUBSTR seem to use this as the number of bytes you want to use.

X = ARGLEN (7, “ABCDEFG”, ‘I4’) returns 7

X = ARGLEN (5, “ABCDEFG”, ‘I4’) returns 5

Interestingly, maxing out the inlength also gives the right answer :

X = ARGLEN (255, “ABCDEFG”, ‘I4’) returns 7

Both functions will return the minimum of inlength or the actual length of the string, so this value can be ignored (as long as it’s longer than the string you’re using) ?

Has anyone else found this to be true, or false, or is there something I’m overlooking ?


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Expert
posted Hide Post
Hi Charles,

Below is the suggestion from internal experts.

quote:
There are two related issues here:
1. why specify INLENGTH
2. when would OUTLENGTH not be END-START+1

Both have a related response: The USER written subroutine does NOT have access to the length of the input string, nor can it control the resultant field length declared in the call.

For example, suppose SUBSTR was invoked as:

KEYCODE/A4 = SUBSTR(10,VALUE, 1,3,4,'A4');

Alphas are passed be reference (only the starting address is passed). As a result, there's no way for a USER written subroutine to determine that VALUE is 10 characters in length, without that value being passed.

Likewise, the length of the returned string can be determined as END-START+1. However the subroutine doesn't know that the return argument was declared as 4 characters, and the result is ALSO passed by reference. The OUTLENGTH is provide, in case the returned length is DIFFERENT from the declared length, so the subroutine can truncate the result (if too large), or pad with blanks (if too small). This becomes ESPECIALLY important, when the lengths are determined by other subroutines, and may vary, but the OUTPUT is ALWAYS a fixed length.


Hope this helps. Smiler

Cheers,

Kerry


Kerry Zhan
Focal Point Moderator
Information Builders, Inc.
 
Posts: 1948 | Location: New York | Registered: November 16, 2004Report 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] Purpose for Parameters in Intrinsic (FW) String Functions

Copyright © 1996-2020 Information Builders