I have the following string where i have to replace the from and to dates with new dates.
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;
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)
windows 10This message has been edited. Last edited by: FP Mod Chuck,
Are you on 8105? There's a bunch of new simplified functions that might help but only available in 82xx.
WebFOCUS 8206, Unix, Windows
Unfortunately i am in 8105 still
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
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 :
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));
Prod: 8202M1 Test: 8202M4
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.
|Powered by Social Strata|