• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Those Stupid Quotation Marks!

    October 26, 2005 Hey, Ted

    I am attempting to use QCMDEXC to run Open Query File within an RPG IV program but the compiler generates errors RNF0312 (A right parenthesis is expected but is not found) and RNF5347 (An assignment operator is expected with the EVAL operation). Do you see anything wrong with my code?

    –PG

    Here’s the free-format RPG code PG sent me. (The file and field names have been changed to protect the guilty.)

    @qcmdexec('OPNQRYF FILE((MYFILE)) QRYSLT('FLD *EQ %WLDCRD("*AA*")')');
    

    PG is trying to select all records in file MYFILE that have AA anywhere in field FLD. PG’s problem is that he (she?) has embedded single quotation marks (or “quotes,” as they’re often called, or “tick marks,” as a former associate of mine referred to them) within single quotation marks. I get lots and lots of complaints about the use of quotes, almost always from people who complain that they don’t like CL. But PG’s case shows that it’s not just CL that suffers from this problem. My email and my experience on the job show that it’s not just newbies who don’t understand how to use quotes.

    To use quotes properly in CL, RPG, and DDS, follow these simple rules.

    Rule 1: You must always have an even number of quotes in a character string, including the quotes that delimit the string.

    If you have an even number of quotes, you may or may not have a problem. If you have an odd number of quotes, you’ve definitely got a problem somewhere.

    Rule 2: You must place two adjacent quotes inside a string in order to store one quote.

    Since the quote character delimits a character literal, IBM had to come up with a special way to indicate that a quote is part of a literal. Look at this:

    eval ClubName = 'The Ladies' Red Rubber Ball Society'
    

    How is the RPG compiler to know that the string doesn’t stop after the final letter of the second word?

    Here’s the example I always use. If the message you want to get across is that people should dine at your friend Joseph’s food emporium, you might write code like the following:

    /* CL */
    chgvar  var(&Message)  value('Eat at Joe''s!')
    
    /* RPG IV */
    eval Message = 'Eat at Joe''s!'
    
    /* DDS */
    A                             2 34'Eat at Joe''s!'
    

    In all these cases, the message is the same: Eat at Joe’s!

    Rule 3: Some people like to use a one-byte identifier that contains a quote in order to avoid doubled quotes. (Well, it’s not really a rule, but it’s still useful information.)

    /* CL */
    dcl  &Quote       *char    1    value('''')
    dcl  &Message     *char   80
    
    chgvar var(&Message) +
           value('Eat at Joe' *cat &Quote *cat 's!')
    
    /* RPG IV */
    
    D Quote           c                   const('''')
    D Message         s             80a
    
    C                   eval      Message = 'Eat at Joe' +
    C                               Quote + 's!'
    

    You don’t avoid doubled quotes completely, as the initial value of the Quote constant or variable has four quotes. The outer two delimit the string. The inner two signify one quote. But you don’t have to use a doubled quote anywhere else in the program.


    Now back to PG’s question. All he (she?) has to do is double the embedded single quotes.

    @qcmdexec('OPNQRYF FILE((MYFILE)) QRYSLT(''FLD *EQ %WLDCRD("*AA*")'')');
    

    I’m glad PG took the time to write. I see this mistake and many imaginative work-arounds quite often, but it had never occurred to me to write about the “tick-mark” problem in Four Hundred Guru. Thanks.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    For LANSA, 3-Way Product Data Synch is as Easy as ABI EC Kronos Tackles Unscheduled Absenteeism with Labor Software

    One thought on “Those Stupid Quotation Marks!”

    • Greg Law says:
      June 8, 2018 at 5:21 pm

      Thanks so much!

      Reply

    Leave a Reply Cancel reply

Volume 5, Number 40 -- October 26, 2005
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
Linoma Software
WorksRight Software

Table of Contents

  • How to Count with SQL
  • Those Stupid Quotation Marks!
  • Admin Alert: New TCP/IP Functions to Check Out When Upgrading to i5/OS V5
  • Correction: Bugged by the Bugged by Interactive Debugger Tip

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Tweaks Some Power Systems Prices Down, Others Up
  • Disaster Recovery: From OS/400 V5R3 To IBM i 7.4 In 36 Hours
  • The Disconnect In Modernization Planning And Execution
  • Superior Support: One Of The Reasons You Pay The Power Systems Premium
  • IBM i PTF Guide, Volume 25, Number 13
  • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
  • When You Need Us, We Are Ready To Do Grunt Work
  • Generative AI: Coming to an ERP Near You
  • Four Hundred Monitor, March 22
  • IBM i PTF Guide, Volume 25, Number 12

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2023 IT Jungle