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: 16  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.
  • 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
  • Rrbond07
    What if I am testing a 150 character field for a single quote? If I am substringing through the field and find a single quote, I want to replace it with a blank.
    655 pointsBadges:
    report
  • TheRealRaven
    It's long seemed best to use a *CHAR ( 1 ) variable for a constant quote value. I've tended to try to use a variable named &q for a single-quote/apostrophe and &qq for a double-quote. These get very handy when building *QMQRY statements.
    27,190 pointsBadges:
    report
  • ToddN2000
    @Rrbond07: if using SQL try the replace like this

    Replace(myfield, char(39),'')

    110,160 pointsBadges:
    report
  • azohawk

    Remember that CL is not well suited to data manipulation. It is intended for executing a series of commands to accomplish something done while limiting human interaction.  Consequently, searching a field for a specific character is not something done easily in CL.

    You have not indicated what you are really trying to do. Providing that may provide a better answer to resolve the issue you are facing.

    3,645 pointsBadges:
    report
  • TheRealRaven
    @Rrbond07:

    What if I am testing a 150 character field for a single quote?

    Just use a DOFOR-loop to run through the string. Use an IF-test inside the loop to test each character.
    27,190 pointsBadges:
    report
  • Rrbond07
    @azohawk The reason I am doing this is because I need to list each special authority that is listed in a user's profile. I have been able to accomplish this however, if there are any single quotes in the Text Description field my program will terminate when I go to insert the record into another file in my SQL statement in my CL. So I am trying to first go through my entire file that lists users profiles and blank out any quote that is found, then insert the record into another file. I have 1200 profiles on the system and of course don't want to go through it manually to find quotes and remove them.
    655 pointsBadges:
    report
  • TheRealRaven
    If these are in a database file on your server, you could simply run a SQL UPDATE against the file to eliminate the quotes.
    27,190 pointsBadges:
    report
  • ToddN2000
    @Rrbond07: I'd still use the Replace(myfield, char(39),'') when creating the field for my SQL table.
    110,160 pointsBadges:
    report
  • TheRealRaven
    Agree with @ToddN2000. No need for programming around this. Eliminate the faulty data from the table column using simple SQL, and any subsequent programming can ignore the problem.
    27,190 pointsBadges:
    report
  • Rrbond07
    TheRealRaven, How would I use the SQL command UPDATE against my file?  I am trying to figure out how I step through the field checking each character for the single quote.  And then replace the quote with a blank without blanking out the entire field.  If I could do it without programing it within a CL that would be great.
    655 pointsBadges:
    report
  • TheRealRaven
    A basic SQL UPDATE statement would be something like:
    UPDATE mytable
       SET myfield = Replace(myfield, char(39),'')
    That's essentially what @ToddN200 has been posting.

    The UPDATE statement should also have a WHERE clause to limit it only to rows that actually contain a single-quote.
    27,190 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.

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

Following

Share this item with your network: