The value in single quotes is not a string, it’s a varaiable.
So I am looking for something like
Chgvar &VAR = (‘&VAR1′)
Can anybody help?
It depends on what you’re trying to do. I tend to use either of the following methods, depending on the complexity of the statement I am coding;
a) Define a single character variable "E and give it a value of a single quotation mark:
DCL VAR("E) TYPE(*CHAR) LEN(1) VALUE(””)
Then, you simply concatenate the quote where you want it. For example:
CHGVAR VAR(&MSG) VALUE("E *CAT ‘This is in quotes’ *CAT "E)
b) My current favourite for formatting messages like the one above as well as command strings to be called from RPG programs is to code the string in a message file either with a quote being passed as message data in position 1, or using two single quotes in the message text. Then I use RTVMSG (or the QMHRTVM system API) to pull back the string and format it at the same time. This is especially useful in CL for coding the selection value for OPNQRYF statements.
Hope the suggestions help.
All the best
But what if the string specified is actually a variable name
So, I say again
DCL &VAR Value(‘TEAM’)
so I want another var to contain:
‘TEAM’, with quotes in place
I’m sure it’s not difficult?
The easiest way to add a single qoute to a varible is to put two single quotes together in the CHGVAR command.
CHGVAR var(&TXT) VALUE(”” *cat ‘String’ *cat ””)
would result in:
‘String’ for &TXT.
This could have also been done as:
CHGVAR var(&TXT) VALUE(”’String”’)
with the same result.
If you want &VAR1 to contain the contents of &VAR within single quotes then you can use:
DCL &VAR *CHAR 10 VALUE(‘TEAM’)
DCL &VAR1 *CHAR 10
DCL "E *CHAR 1 VALUE(””)
CHGVAR &VAR1 ("E *BCAT &VAR *TCAT "E)
Using *BCAT and *TCAT instead of *CAT will remove any leading and trailing blanks in &VAR.
Alternatively you could replace "E in the CHGVAR with ”” four quotes to get the same result.
Or you could define a message in a message file:
ADDMSGD MSGID(MSG0001) MSGF(EXAMPLES/MYMSGF) +
MSG(”’&1”’) FMT((*CHAR 128))
and then use:
RTVMSG MSGID(MSG0001) MSGF(EXAMPLES/MYMSGF) +
to load &VAR1 (although this is probably overkill for what you want).