ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Embedding single quotes into a string in RPG

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Embedding single quotes into a string in RPG

    Ok, I've come across this problem before and solved it but not in my ideal way of thinking. Here is what I've done in the past...

    Code:
    whereclause  += ' and accsbu = ''' + bsbu + '''';
    This will embed a single quote, concat the value of bsbu and embed another single quote around the other end. I don't really want to move a string into a variable or create a constant and do it this way. I'd rather just code it all right inline....

    Something like...

    Code:
    whereclause +=' and accsbu = 'mysbu'';
    Now this doesn't work for obvious reasons... but is there an easy way to just escape a single quote into the string? Why can't this be as easy as by beloved C++?

    Just dreaming here...
    Code:
    whereclause +=' and accsbu = /'mysbu/'';
    a guy can dream nowadays right?
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

  • #2
    Re: Embedding single quotes into a string in RPG

    i might not be following you cause its friday but..

    PHP Code:
    d DQ              C                   CONST('"')
    d Q               C                   CONST('''')

          *
          * 
    strpccmd 'net use Z: \\lbi-nt1\SharedDocs\ProcessSchedule'
          
    *
         
    c                   eval      cmdstring 'strpccmd ' +
         
    c                             'net use Z: \\lbi-nt1\SharedDocs\' +
         c                             '
    Processes' + Q
          *
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   '
    QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength 
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Embedding single quotes into a string in RPG

      Isn't there an easy way to do it without all the @#%@#%@#%@#% concatenation? Its just annoying to me to have to break my thought process to add the + then the variable then another + and on and on. It starts to make the code look ugly...

      Maybe searching things out like this shouldn't be done on a friday... this is probably a Tuesday through Thursday problem
      Your future President
      Bryce

      ---------------------------------------------
      http://www.bravobryce.com

      Comment


      • #4
        Re: Embedding single quotes into a string in RPG

        Hello

        In EBCDIC a quote is x'7d'. The easy way to do it is to put a character that you never use in place of the quote and then XLATE the quote into its place:

        Code:
        D  string         s             50A                                
         /free                                                             
            string = 'I want to put in some ¢quotes¢';                     
            string = %xlate('¢':x'7d':string);                             
         /end-free                                                         
        c                   seton                                        lr

        Comment


        • #5
          Re: Embedding single quotes into a string in RPG

          That's an interesting way, but once again, another step that I'd like to avoid... maybe I'll add it to Cozzi's list of RPGIV improvements...
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: Embedding single quotes into a string in RPG

            I tried this but for some reason it didn't work.
            Code:
            d singlequote         C                   x'27'
            http://www.linkedin.com/in/chippermiller

            Comment


            • #7
              Re: Embedding single quotes into a string in RPG

              did you try x'7d'?
              Your future President
              Bryce

              ---------------------------------------------
              http://www.bravobryce.com

              Comment


              • #8
                Re: Embedding single quotes into a string in RPG

                This is what I'm reduced to right now, its not very pretty....

                Code:
                         wheretxt = 'sid=' + q + 'SO' + q + ' and iclas ' +
                                    'in(' + q + 'DE' + q + ',' + q + 'DI' + q + ',' +
                                    q + 'DR' + q +')';
                Your future President
                Bryce

                ---------------------------------------------
                http://www.bravobryce.com

                Comment


                • #9
                  Re: Embedding single quotes into a string in RPG

                  I agree, Bryce. I have always thougt that quote stuff was ugly.

                  What is we had a procedure that returned a variable string with the quotes appended.

                  wheretxt = 'sid=' + quote('SO') + ' and iclas ' +
                  'in(' + quote('DE') + ',' + quote('DI') + ',' +
                  quote('DR') +')';
                  Denny

                  If authority was mass, stupidity would be gravity.

                  Comment


                  • #10
                    Re: Embedding single quotes into a string in RPG

                    Originally posted by bryce4president View Post
                    did you try x'7d'?
                    Oops -- it helps if I use the EBCDIC hex table instead of the ASCII hex table.
                    http://www.linkedin.com/in/chippermiller

                    Comment


                    • #11
                      Re: Embedding single quotes into a string in RPG

                      shrug i just do it like this:
                      Code:
                      SQL$ = 'UPDATE QTEMP/' + %Trim(MLName) + ' SET SRCDTA = '
                           + 'REPLACE(SRCDTA,''' + %Trim(FromChar) +''','''    
                           + %Trim(ToChar) + ''')';
                      just double up the quotes
                      I'm not anti-social, I just don't like people -Tommy Holden

                      Comment


                      • #12
                        Re: Embedding single quotes into a string in RPG

                        I've done that before too Tom, but you still gotta use the + symbol to accomplish it. You can't just escape it right in line without breaking.... RPGIV should have better string literal handling... but i'm guessing this didn't really become much of an issue until the command API's and the SQL stuff came along... even then it wasn't use so very often that it annoyed people that much, but I would think that its getting used more and more nowadays and that it would become more annoying to people...

                        just some thoughts...

                        Denny, you bring up an interesting way of handling it..., still have to concat though... I'm guessing that I can't get what I wish for...
                        Your future President
                        Bryce

                        ---------------------------------------------
                        http://www.bravobryce.com

                        Comment


                        • #13
                          Re: Embedding single quotes into a string in RPG

                          Hi,

                          please avoid x'7D' for single quotes, because it may change in an other EBCDIC code. Douplication the quote instead can be used everywhere.

                          Birgitta

                          Comment

                          Working...
                          X