Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 21 - March 20, 2002

OPNQRYF and Quotation Marks

Hey, Ted:

I have to create a record selection expression for a character field that can have values like 4" in it. When an expression like ATSIN *EQ "4"" occurs, the Open Query File (OPNQRYF) command gives an error.

Is there a way around it?

-- Nonna

You'll have to double something in your code. In your example, you surround the literal 4" with double quote marks ( " ). You need to change the one double quote mark following the number 4 to two double quote marks. Your query selection string will look like this:

ATSIN *EQ "4"""

The other way to do this is to use two single quote marks ( ' ) to delimit the literal, like this:

ATSIN *EQ ''4"''

That's single quote single quote the numeral four a double quote single quote single quote.

Here's some CL code that illustrates this concept. &DESC is the field holding the user input. &DWORK holds the user input with doubled quote marks.

    DCL        &DESC       *CHAR  LEN( 25)             
    DCL        &DWORK      *CHAR  LEN( 50)             
    DCL        &QRYSLT     *CHAR  LEN(256)             
    DCL        &DBLQUOTE   *CHAR  LEN(  1) VALUE('"')  
                                                       
    DCL        &INX        *DEC   LEN(3 0)             
    DCL        &OUTX       *DEC   LEN(3 0)             
                                                       
/* Get value of &DESC using some input method here */ 
                                                       
/* Begin routine to change a double quote to two     */
/* double quotes so OPNQRYF selects records properly */
                                                       
    CHGVAR     &INX        1                           
    CHGVAR     &OUTX       1                           
                                                       
 NextChar:
    CHGVAR     %SST(&DWORK &OUTX 1)  %SST(&DESC &INX 1)
                                                       
    IF   (%SST(&DESC &INX 1) *EQ &DBLQUOTE) DO         
       CHGVAR     &OUTX                   (&OUTX + 1)  
       CHGVAR     %SST(&DWORK &OUTX 1)    (&DBLQUOTE)  
    ENDDO                                              
                                                       
    CHGVAR     &INX       (&INX + 1)                   
    CHGVAR     &OUTX      (&OUTX + 1)                  
                                                       
    IF   (&INX *LE 25) THEN(GOTO NextChar)             
                                                       
 /* End routine to double quotation marks */           
                                                       
    CHGVAR     &QRYSLT  VALUE('PMDESC *CT' *bcat +     
                               &DblQuote *cat +        
                               &DWork *tcat +          
                               &DblQuote)              
                                             
    OPNQRYF    FILE((PARTS)) QRYSLT(&QRYSLT) 

-- Ted

Sponsored By
MRC (MICHAELS, ROSS & COLE)

Want to get your company to the Web in five days?
Now you can with the mrc-Productivity Series!

We'll design/develop a pilot intranet, extranet, or Internet web site, based on your specifications, so you can explore the possibilities of the Internet using your current iSeries without any of the risks associated with deploying an untested solution.

Click here to find out more!

Spring Giveaway: Enter to win a Sony Clie PDA!

mrc was founded in 1981 and provides software tools and consulting services to over 4000 IBM iSeries and WebSphere customers globally. The company produces the mrc-Productivity Series, the only iSeries development tool suite to provide Web development, rapid application development, and real-time reporting capabilities that can easily be deployed to any platform.

For more information, contact mrc at 450 E. 22nd Street, Suite 203, Lombard, IL 60148; via phone at 630.916.0662; via fax at 630.916.0663; via e-mail at mrc@mrc- productivity.com; or via the Internet at http://www.mrc-productivity.com.

THIS ISSUE
SPONSORED BY:
mrc
Business Computer Design, Int'l
BACK ISSUES
TABLE OF CONTENTS
OPNQRYF and Quotation Marks
Getting to the Information Center URLs
Reader Feedback and Insights: Checking for a Mounted Tape
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 3/20/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.