Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] STRREP when string is unknown
Go
New
Search
Notify
Tools
Reply
  
[CLOSED] STRREP when string is unknown
 Login/Join
 
Platinum Member
posted
Hi All,
I have the following string where i have to replace the from and to dates with new dates.

Department:'None';Participant_address:N;FROM_DATE:11/01/2018;TO_DATE:03/31/2019;REDACT_IND:N;

The problem is i wont know the dates at runtime.
for now i am doing

-SET &OTHER_PARMS = TRUNCATE(&OTHER_PARMS);
-SET &FROM_DT_OTHER_PARMS = STRREP (&OTHER_PARMS.LENGTH, &OTHER_PARMS, 10, 'FROM_DATE', 1, '!', &OTHER_PARMS.LENGTH, 'A&OTHER_PARMS.LENGTH');
-SET &ABCD = GETTOK(&FROM_DT_OTHER_PARMS, &FROM_DT_OTHER_PARMS.LENGTH ,-1, '!', 31, 'A31');
-SET &ABCD = '!'||&ABCD;
-SET &FROM_DT_OTHER_PARMS = STRREP (&FROM_DT_OTHER_PARMS.LENGTH, &FROM_DT_OTHER_PARMS, &ABCD.LENGTH,&ABCD, 0, '', 100, A100);
-SET &OTHER_PARMS = TRUNCATE(&FROM_DT_OTHER_PARMS)||&DATES;
-TYPE &OTHER_PARMS

Is there any way to do this more efficiently.
In future i might have cases where there are some more date parameters(Say,Transaction_Start and End Dates)

WF8105M
windows 10

This message has been edited. Last edited by: FP Mod Chuck,
 
Posts: 152 | Registered: October 25, 2017Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Are you on 8105? There's a bunch of new simplified functions that might help but only available in 82xx.

https://webfocusinfocenter.inf...source/substring.htm


WebFOCUS 8204, Unix, Windows
 
Posts: 1610 | Location: New York City | Registered: December 30, 2015Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Unfortunately i am in 8105 still
 
Posts: 152 | Registered: October 25, 2017Reply With QuoteReport This Post
Expert
posted Hide Post
There are a number of simplified functions in 8105.

Check out the documentation.

Are the dates always in the same position ?, i.e. token number, assuming a semicolon can be trusted.

An example of what you want out the other side would help


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6053 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
You probably need to replace that date "manually", by finding the POSITION() of the strings "FROM_DATE:" and "TO_DATE:" and using the fact that a date is 10 characters long (assuming it can't be left empty).

Armed with that, you can concatenate substrings based on these positions to get the desired string.
-SET &FROM_START = POSITION(&OTHER_PARAMS, 'FROM_DATE:') + CHAR_LENGTH('FROM_DATE:');
-SET &FROM_LENGTH = CHAR_LENGTH('11/01/2018');
-SET &FROM_END = &FROM_START + &FROM_LENGTH -1;
-SET &TO_START = POSITION(&OTHER_PARAMS, 'TO_DATE:') + CHAR_LENGTH('TO_DATE:');
-SET &TO_LENGTH = CHAR_LENGTH('11/01/2018');
-STE &TO_END = &TO_START + &TO_LENGTH -1;

-SET &OTHER_PARAMS = SUBSTRING(&OTHER_PARAMS, 1, &FROM_START)
- + &NEW_FROM_DATE
- + SUBSTRING(&OTHER_PARAMS, &FROM_END, &TO_START - &FROM_END, &TO_LENGTH)
- + &NEW_TO_DATE
- + SUBSTRING(&OTHER_PARAMS, &TO_END, &OTHER_PARAMS.LENGTH - &TO_END);


I'm sure there are some off-by-one errors in that example, but you get the drift.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1639 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Guru
posted Hide Post
Assuming that the string will always be semicolon delimited and that the date positions will always be in the third and fourth positions, the following seems to work on my end:
  
-SET &ECHO=ALL;
-SET &MYSTRING = 'Department:''None'';Participant_address:N;FROM_DATE:11/01/2018;TO_DATE:03/31/2019;REDACT_IND:N;';
-SET &NEW_FROM_DATE = '01/01/2019';
-SET &NEW_TO_DATE = '05/31/2019';

-SET &OLD_FROM_DATE = TOKEN( TOKEN(&MYSTRING, ';', 3)||':', ':', 2 );
-SET &OLD_TO_DATE = TOKEN( TOKEN(&MYSTRING, ';', 4)||':', ':', 2 );

-SET &MYSTRING = TRUNCATE(STRREP(CHAR_LENGTH(&MYSTRING), &MYSTRING, CHAR_LENGTH(&OLD_FROM_DATE), &OLD_FROM_DATE, CHAR_LENGTH(&NEW_FROM_DATE), &NEW_FROM_DATE, 1000, 'A1000'  ) );
-SET &MYSTRING = TRUNCATE(STRREP(CHAR_LENGTH(&MYSTRING), &MYSTRING, CHAR_LENGTH(&OLD_TO_DATE), &OLD_TO_DATE, CHAR_LENGTH(&NEW_TO_DATE), &NEW_TO_DATE, 1000, 'A1000'  ) );
-TYPE &MYSTRING


As Waz mentioned, there are Simplified Character Functions in 8105, and this uses two of those: CHAR_LENGTH and TOKEN

In 8201 there is also a simplified function for replacing a string, simply called REPLACE that would would simplify it further by changing the STRREP with:
 
-SET &MYSTRING = TRUNCATE(REPLACE(&MYSTRING, &OLD_FROM_DATE, &NEW_FROM_DATE));
-SET &MYSTRING = TRUNCATE(REPLACE(&MYSTRING, &OLD_TO_DATE, &NEW_TO_DATE));
 


Hallway
WF(Prod):8202M
WF(Test):8202M
OS/Platform:Win 10
Outputs:All
 
Posts: 347 | Location: Salt Lake City, UT, USA | Registered: November 18, 2015Reply With QuoteReport This Post
Expert
posted Hide Post
Will the source string always have "FROM_DATE:" and "TO_DATE:" in it?If so, getting the tokens should be the key to this working as desired.
 
Posts: 2967 | Location: Middle Tennessee [8204M Gen48 in Test&Prod] | Registered: February 23, 2005Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] STRREP when string is unknown

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.