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     [SOLVED] Replace character using CTRAN
Go
New
Search
Notify
Tools
Reply
  
[SOLVED] Replace character using CTRAN
 Login/Join
 
Platinum Member
posted
I’m using CTRAN in dialogue manager to replace single quotes with a space. The parameter string is from a multi selection of countries in the car file.
I’m trying to replace the single quotes with a space and the OR between the countries with a comma.
The &PARM1 variable is stopping at 16 characters. I’m not sure why.

The final output should look like: England , France , Italy , Japan , W Germany

-DEFAULTH &P1 = '';
-DEFAULTH &P2 = '';
-DEFAULTH &P3 = '';
-DEFAULTH &P4 = '';
-DEFAULTH &P5 = '';
-* replace single quote with space (ascii dec) 39 = single quote 32 = space
-SET &PARM1 = CTRAN(100, &COUNTRY, 39, 32, 100);
-TYPE &|PARM1 == &PARM1
-*
FILEDEF TEMPFILE DISK TEMPFILE.TXT

-RUN
-WRITE TEMPFILE &PARM1
-RUN

-READ TEMPFILE,&P1,&P2,&P3,&P4,&P5
-TYPE &|P1 == &P1
-TYPE &|P2 == &P2
-TYPE &|P3 == &P3
-TYPE &|P4 == &P4
-TYPE &|P5 == &P5
-EXIT

DEFINE FILE CAR
COUNTRY1/A50 = COUNTRY;
END
TABLE FILE CAR
SUM CAR.BODY.SALES
BY CAR.ORIGIN.COUNTRY
WHERE CAR.ORIGIN.COUNTRY EQ &COUNTRY.(OR(FIND CAR.ORIGIN.COUNTRY IN CAR)).COUNTRY:.;
END

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


WF 8 version 8.2.04. Windows.
In focus since 1990.
 
Posts: 189 | Location: pgh pa | Registered: October 06, 2004Reply With QuoteReport This Post
Master
posted Hide Post
I had to change this line...

-SET &PARM1 = CTRAN(100, &COUNTRY, 39, 32, 100);


...to this to get it to run...

-SET &PARM1 = CTRAN(100, &COUNTRY, 39, 32, A100);


Now I get this output:

 &PARM1 ==  ENGLAND  OR  FRANCE  OR  ITALY  OR  JAPAN  OR  W GERMANY
 FILEDEF TEMPFILE DISK TEMPFILE.TXT
 &P1 == ENGLAND  OR  FRANCE  OR  ITALY  OR  JAPAN  OR  W GERMANY
 &P2 ==
 &P3 ==
 &P4 ==
 &P5 ==


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Thank you Squatch.


WF 8 version 8.2.04. Windows.
In focus since 1990.
 
Posts: 189 | Location: pgh pa | Registered: October 06, 2004Reply With QuoteReport This Post
Master
posted Hide Post
No problem. My version of WebFOCUS decided to throw an error, but it looks like your version just defaulted to an A16 output format.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Reply With QuoteReport This Post
Platinum Member
posted Hide Post
quote:
&P1 == ENGLAND OR FRANCE OR ITALY OR JAPAN OR W GERMANY


Now the question is can CTRAN or another function convert the OR to a comma? It appears that CTRAN can only convert a single character and not the string of ' OR '.

-DEFAULTH &P1 = '';
-DEFAULTH &P2 = '';
-DEFAULTH &P3 = '';
-DEFAULTH &P4 = '';
-DEFAULTH &P5 = '';
-TYPE &|COUNTRY == &COUNTRY
-* replace single quote with space (ascii dec) 39 = single quote 32 = space
-SET &PARM1 = CTRAN(100, &COUNTRY, 39, 32, A100);
-TYPE &|PARM1 == &PARM1

DEFINE FILE CAR
PARM/A100 = '&PARM1';
PARM1/A100 = CTRAN(100, PARM, 79, 44, PARM1);
PARM2/A100 = CTRAN(100, PARM1, 82, 32, PARM1);
END
TABLE FILE CAR
PRINT PARM
PARM1
PARM2
BY COUNTRY
IF RECORDLIMIT EQ 1
END
-EXIT
-*
FILEDEF TEMPFILE DISK TEMPFILE.TXT

-RUN
-WRITE TEMPFILE &PARM1
-RUN

-READ TEMPFILE,&P1,&P2,&P3,&P4,&P5
-TYPE &|P1 == &P1
-TYPE &|P2 == &P2
-TYPE &|P3 == &P3
-TYPE &|P4 == &P4
-TYPE &|P5 == &P5
-EXIT


DEFINE FILE CAR
COUNTRY1/A50 = COUNTRY;
END
TABLE FILE CAR
SUM CAR.BODY.SALES
BY CAR.ORIGIN.COUNTRY
WHERE CAR.ORIGIN.COUNTRY EQ &COUNTRY.(OR(FIND CAR.ORIGIN.COUNTRY IN CAR)).COUNTRY:.;
END


WF 8 version 8.2.04. Windows.
In focus since 1990.
 
Posts: 189 | Location: pgh pa | Registered: October 06, 2004Reply With QuoteReport This Post
Master
posted Hide Post
Look up STRREP, it "replaces all instances of character string 1 with character string 2".

That's what my WebFOCUS Keysheet book says, anyway. I can try to work up an example for you if you'd like.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Reply With QuoteReport This Post
Master
posted Hide Post
Enjoy!

-DEFAULTH &P1 = '';
-DEFAULTH &P2 = '';
-DEFAULTH &P3 = '';
-DEFAULTH &P4 = '';
-DEFAULTH &P5 = '';
-* replace single quote with space (ascii dec) 39 = single quote 32 = space
-SET &PARM1 = CTRAN(100, &COUNTRY, 39, 32, A100);
-TYPE &|PARM1 == &PARM1
-SET &PARM1 = STRREP(100, &PARM1, 6, '  OR  ', 1, ',', 100, &PARM1);
-TYPE &|PARM1 == &PARM1
-*
FILEDEF TEMPFILE DISK TEMPFILE.TXT

-RUN
-WRITE TEMPFILE &PARM1 
-RUN

-READ TEMPFILE,&P1,&P2,&P3,&P4,&P5
-TYPE &|P1 == &P1
-TYPE &|P2 == &P2
-TYPE &|P3 == &P3
-TYPE &|P4 == &P4
-TYPE &|P5 == &P5
-EXIT

DEFINE FILE CAR
COUNTRY1/A50 = COUNTRY;
END
TABLE FILE CAR
SUM CAR.BODY.SALES
BY CAR.ORIGIN.COUNTRY
WHERE CAR.ORIGIN.COUNTRY EQ &COUNTRY.(OR(FIND CAR.ORIGIN.COUNTRY IN CAR)).COUNTRY:.;
END


Output:

 &PARM1 ==  ENGLAND  OR  FRANCE  OR  ITALY  OR  JAPAN  OR  W GERMANY
 &PARM1 ==  ENGLAND,FRANCE,ITALY,JAPAN,W GERMANY
 FILEDEF TEMPFILE DISK TEMPFILE.TXT
 &P1 == ENGLAND
 &P2 == FRANCE
 &P3 == ITALY
 &P4 == JAPAN
 &P5 == W GERMANY


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Perfect. Thanks again for the help.


WF 8 version 8.2.04. Windows.
In focus since 1990.
 
Posts: 189 | Location: pgh pa | Registered: October 06, 2004Reply With QuoteReport This Post
Expert
posted Hide Post
I don't know were this started, but the format on the functions should be enclosed in quotes.

You can also make the output length the same as the input variable with 'A&Var.LENGTH'


Waz...

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

 
Posts: 6272 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Replace character using CTRAN

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