Focal Point
[SOLVED] Replace character using CTRAN

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

January 13, 2016, 02:11 PM
Spence
[SOLVED] Replace character using CTRAN
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.
January 13, 2016, 02:28 PM
Squatch
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
January 13, 2016, 02:37 PM
Spence
Thank you Squatch.


WF 8 version 8.2.04. Windows.
In focus since 1990.
January 13, 2016, 02:40 PM
Squatch
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
January 13, 2016, 03:06 PM
Spence
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.
January 13, 2016, 03:10 PM
Squatch
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
January 13, 2016, 03:15 PM
Squatch
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
January 13, 2016, 03:39 PM
Spence
Perfect. Thanks again for the help.


WF 8 version 8.2.04. Windows.
In focus since 1990.
January 13, 2016, 04:41 PM
Waz
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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!