ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Ampersands and apostrophes

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

  • Ampersands and apostrophes

    Hello.

    When did apostrophes become optional (line 5), and how can the following code compile when the ampersand is missing on line 7? This compiles and the expression at line 7 evaluates to false at runtime:

    Code:
    0001.00 pgm
    0002.00
    0003.00 dcl &text *char len(10)
    0004.00
    0005.00 chgvar &text value(ABC)
    0006.00
    0007.00 if (text *eq 'ABC') then(sndmsg msg('TEST') tousr(MIKE))
    0008.00
    0009.00 endpgm​
    Thanks in advance,

    Mike

  • #2
    I've seen this in very old programs so it seems quotes haven't been required for a while, though if you had a space or hyphen or something odd in there the quotes would be required. I believe the non-quoted text will be automatically capitalised as well. I've always avoided it because it can be confusing. It's no different to entering character strings in a command I guess, you don't need to quote those unless there's a space or something odd in there.
    Line 7 is basically comparing 2 character strings - if ('TEXT' *eq 'ABC'), which of course it doesn't.

    Comment


    • #3
      It has always been like this.

      Comment


      • #4
        CL is literally a list of commands, every instruction in a CL program is a CMD. And command syntax has always allowed, for text type parameters (not name type params) a string of characters that starts with a letter and contains no spaces to be treated as such with no apostrophes.
        e.g.
        Code:
        WRKMBRPDM FILE(QRPGLESRC) MBRTYPE(SQLRPGLE)
        /* is the same as*/
        WRKMBRPDM FILE(QRPGLESRC) MBRTYPE('SQLRPGLE')​

        Comment

        Working...
        X