Focal Point
Curious behaviour with SUBSTR function

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9861051332

June 18, 2007, 05:45 PM
Francis Mariani
Curious behaviour with SUBSTR function
In the code below, the expected length for &USER_NAME is 15, but it's set to 17. Anyone know why?

-SET &ECHO=ALL;
-SET &USER_FNAME = 'Francis                                           ';
-SET &USER_LNAME = 'Mariani                                           ';

-SET &USER_NAME1 = &USER_FNAME || (' ' | &USER_LNAME);

-SET &ARGL1 = ARGLEN(&USER_NAME1.LENGTH,&USER_NAME1,'I3');

-* SUBSTR(inlength, parent, start, end, sublength, outfield)
-SET &USER_NAME =
-  SUBSTR(&USER_NAME1.LENGTH, &USER_NAME1, 1, &ARGL1, &ARGL1, 'A&ARGL1');

-TYPE USER_NAME1 &USER_NAME1.LENGTH XXX &USER_NAME1 XXX
-TYPE USER_NAME  &USER_NAME.LENGTH XXX &USER_NAME XXX

Thanks.


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
June 18, 2007, 06:17 PM
Darin Lee
Interesting. If you add .EVAL to ' A&ARGL1' in the SUBSTR function, you get the right length. Someone explain that one.


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
June 18, 2007, 06:34 PM
susannah
quote:
(&USER_NAME1.LENGTH

i'm thinking its the .LENGTH thing.
I've gotten different results using .LENGTH and using ARGLEN. so i only use ARGLEN now, unless i'm absobloodylutely sure that the .LENGTH of some inbound parm can never be user-tinkered-with.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
June 19, 2007, 05:27 AM
hammo1j
Fran

Your syntax is incorrect - you are passing the length as the string AamperARGL1. WF is allowing but misinterpreting this.

Correct syntax is

Either

quote:
- SUBSTR(&USER_NAME1.LENGTH, &USER_NAME1, 1, &ARGL1, &ARGL1, 'A&ARGL1.EVAL');


or

quote:
- SUBSTR(&USER_NAME1.LENGTH, &USER_NAME1, 1, &ARGL1, &ARGL1, 'A' | &ARGL1);


Susannah

.length and ARGLEN are two different things

ARGLEN searches from the right to find the first non blank character.

.length is the length of a dm variable including any trailing blanks.

Regards

John



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
June 19, 2007, 05:53 AM
Alan B
Francis, this is actually less weird than you think.

Darin is correct, the .EVAL works.

What is happening is that the 'A&ARGL1' is literally being passed to the function. You can get the same result by using 'XYZ' or ' ' as the last parameter. The functions are ignoring bad formats. The only weirdy is that the default format is A17, and this applies to other functions, not just SUBSTR.

You could use (as well as .EVAL)
-SET &AL = 'A' | &ARGL1;

-SET &USER_NAME =
- SUBSTR(&USER_NAME1.LENGTH, &USER_NAME1, 1, &ARGL1, &ARGL1, '&AL');

or,

-SET &USER_NAME =
- SUBSTR(&USER_NAME1.LENGTH, &USER_NAME1, 1, &ARGL1, &ARGL1,TRUNCATE(&USER_NAME1));

(- SUBSTR(&USER_NAME1.LENGTH, &USER_NAME1, 1, &ARGL1, &ARGL1, 'A' | &ARGL1); won't work John)

which brings me to the point that to remove trailing spaces, the TRUNCATE function simply works,
-SET &USER_FNAME = 'Francis                                           ';
-SET &USER_LNAME = 'Mariani                                           ';
-SET &USER_NAME1 = &USER_FNAME || (' ' | &USER_LNAME);
-SET &USER_NAME = TRUNCATE(&USER_NAME1);

or

-SET &USER_FNAME = 'Francis                                           ';
-SET &USER_LNAME = 'Mariani                                           ';
-SET &USER_NAME = TRUNCATE(&USER_FNAME) | ' ' | TRUNCATE(&USER_LNAME);

would avoid a lot of coding.

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
June 19, 2007, 09:35 AM
Francis Mariani
Thank you everyone. I forgot I should be using .EVAL in the format argument of a function.

quote:
-SET &USER_FNAME = 'Francis ';
-SET &USER_LNAME = 'Mariani ';
-SET &USER_NAME = TRUNCATE(&USER_FNAME) | ' ' | TRUNCATE(&USER_LNAME);


Alan B, thank you for that simple solution using TRUNCATE.

Cheers.


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