Single quotes around a CL variable

pts.
Tags:
Application development
CLP
The easiest way to do the above please

Answer Wiki

Thanks. We'll let you know when a new response is added.

CHGVAR VAR(&FIELDX) VALUE (”’VALUE IN SINGLE QUOTES”’)

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Raddy59
    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 pointsBadges:
    report
  • astradyne
    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 pointsBadges:
    report
  • Raddy59
    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 pointsBadges:
    report
  • JDWWms
    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 pointsBadges:
    report
  • astradyne
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following