0 pts.
 Single quotes around a CL variable
The easiest way to do the above please

Software/Hardware used:
ASKED: November 7, 2006  6:47 AM
UPDATED: November 7, 2006  9:03 AM

Answer Wiki:
CHGVAR VAR(&FIELDX) VALUE ('''VALUE IN SINGLE QUOTES''')
Last Wiki Answer Submitted:  November 7, 2006  8:02 am  by  Coyets   0 pts.
All Answer Wiki Contributors:  Coyets   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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?

 0 pts.

 

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 &QUOTE and give it a value of a single quotation mark:

DCL VAR(&QUOTE) TYPE(*CHAR) LEN(1) VALUE(””)

Then, you simply concatenate the quote where you want it. For example:

CHGVAR VAR(&MSG) VALUE(&QUOTE *CAT ‘This is in quotes’ *CAT &QUOTE)

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

Jonathan

 370 pts.

 

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?

 0 pts.

 

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.

 0 pts.

 

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 &QUOTE *CHAR 1 VALUE(””)

CHGVAR &VAR1 (&QUOTE *BCAT &VAR *TCAT &QUOTE)

Using *BCAT and *TCAT instead of *CAT will remove any leading and trailing blanks in &VAR.

Alternatively you could replace &QUOTE 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) +
MSGDTA(&VAR) MSG(&VAR1)

to load &VAR1 (although this is probably overkill for what you want).

Jonathan

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?

 370 pts.