Menu

The figurative constant "QUOTE"

The Lounge
2026-03-09
2026-03-18
  • Eugenio Di Lorenzo

    The COBOL language provides some "figurative constants" like ZEROS SPACES, HIGH-VALUES, etc., that can be convenient to use.
    There's something I've never understood about this.
    What is the purpose of the figurative constant QUOTE or QUOTES, which corresponds to one or more times the character " .
    What was the intention of the creators of the COBOL language regarding this topic ?
    Does anyone know ?
    Has anyone ever used it ?

     
    • Michael Del Solio

      I dont know it for sure but maybe in the early days of COBOL there was no possibility for masking the character " itself like \" or "" like in other languages?

      Personally I found this code more readable with the usage of QUOTE instead of using the character " six more times:

             IDENTIFICATION DIVISION.
             PROGRAM-ID. quotes-test.
      
             DATA DIVISION.
             WORKING-STORAGE SECTION.
             01 WS-NAME PIC X(20) VALUE "Lara".
             01 WS-CITY PIC X(20) VALUE "Munich".
             01 WS-AGE PIC 99 VALUE 42.
             01 WS-CSV-LINE PIC X(100).
      
             PROCEDURE DIVISION.
      
                 STRING
                   QUOTE WS-NAME QUOTE ","
                   QUOTE WS-CITY QUOTE ","
                   QUOTE WS-AGE QUOTE
                   INTO WS-CSV-LINE
                 END-STRING.
      
                 DISPLAY WS-CSV-LINE.
      
                 STOP RUN
                 .
      

      Output:

      "Lara                ","Munich              ","42"
      

      But this is just my try for an explanation :-)

       
  • Vincent (Bryan) Coen

    Yesm have used quote/s although not often and have used zero/s, spaces often and even high-values.
    That said the 'quote" is restricted to double quote so you have do some thing else for the singleton. i.e., "'" for for qquote use ' " ' horses for courses etc.

     
  • Vincent (Bryan) Coen

    A point that I forgot to mention was figurative values like zero, space, quote, high-values etc, when used a compiler generates ONE character for them while doing a :
    move 0 to x multiple times create a new variable for 0 used, each time and this is a benefit of reducing ram usage for the program.

    Of course the above could vary depending on the compiler and if it is a multiple pass compiler - I do not beleave that GC is of this bred that do a clean up exercise before code gen.

    I could be wrong though :)

     
    • Simon Sobisch

      Simon Sobisch - 2026-03-09

      GnuCOBOL caches all literals :-)

       
  • Simon Sobisch

    Simon Sobisch - 2026-03-09

    The general example given is that this is mostly about readability - compare the following:

    INSPECT ITEM CONVERTING
       "ABCD" TO "XYZX" AFTER QUOTE BEFORE "#"
    
    INSPECT ITEM CONVERTING
       "ABCD" TO "XYZX" AFTER """" BEFORE "#"
    

    Also: many compilers allow to replace the meaning of QUOTE; as far as I know all default to ", but OC/GC, MF, IBM and others have options like the APOST (or QUOTE) directives to toggle that, GnuCOBOL additionally provides -fsingle-quote / -fno-single-quote (default).

     
    • Arnold Trembley

      Arnold Trembley - 2026-03-10

      Going back to IBM 1401 or perhaps even earlier, single quote was the standard. I'm not sure the double quote even existed in some print chains. Around the time of IBM COBOL II or COBOL/MVS, the IBM COBOL compilers allowed you to use either single quotes or double quotes to indicate a literal text string, as long as it ended with same type of character as the beginning. So this would be perfectly valid in modern IBM COBOL:

      INSPECT ITEM CONVERTING
      "ABCD" TO "XYZX" AFTER '"' BEFORE "#"

      INSPECT ITEM CONVERTING
      'ABCD' TO 'XYZX' AFTER "'" BEFORE "#"

      
      
       
      • Vincent (Bryan) Coen

        On IBM ANSI Cobol as for the 1401 it uses a double quote i.e., "

        As defined in manual :

        GC28-6396-6_IBM_OS_Full_American_National_Standard_COBOL_Apr76.pdf

        For OS-VS both are allowed via the compiler option APOST.

        For the IBM 7094 it is a single as per :
        C28-6391-0_v13_7094-COBOL.pdf

        Vince

        Now I could go and look at ICL/ICT manuals for 1900, 1500 and 1300
        series but I have now gotten bored with it all :)

        Vince

        On 10/03/2026 06:07, Arnold Trembley wrote:

        Going back to IBM 1401 or perhaps even earlier, single quote was the
        standard. I'm not sure the double quote even existed in some print
        chains. Around the time of IBM COBOL II or COBOL/MVS, the IBM COBOL
        compilers allowed you to use either single quotes or double quotes to
        indicate a literal text string, as long as it ended with same type of
        character as the beginning. So this would be perfectly valid in modern
        IBM COBOL:

        INSPECT ITEM CONVERTING
        "ABCD" TO "XYZX" AFTER '"' BEFORE "#"

        INSPECT ITEM CONVERTING
        'ABCD' TO 'XYZX' AFTER "'" BEFORE "#"

         
  • Jack Tearle

    Jack Tearle - 2026-03-18

    I thought that it originated in the same way as decimal point is comma.

     
  • Vincent (Bryan) Coen

    For that you will have to go back to the original specs dated around 1958/9 and as amended 1960 BUT I am going on very old memory here - Mine.

    The 1401 was one of the first to implement Cobol on bulk sales m/f kit - I have'major' revised manuals dated 1964 so clearly well before that plus Leo 3 that predates that by a lot as it was the first programmable computer offered for sale pre-1960 and I seem to recall with Cobol but I no longer have the manuals for it as there is only one of them in the UK still running (or was).

    Some where on my system there are other manuals but for the moment cannot find them but I do have to go through some 5+ TB of file areas etc.

    Life is too short :)

     

Log in to post a comment.

MongoDB Logo MongoDB