ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Inserting double quotes

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

  • Inserting double quotes

    I am trying to create an extract file where the first line confains the column header enclosed in double quotes and delimited by commas. I am receiving a Cast error when I try to insert the double quote into the file.

    Code:
    dcl-c $quote ('"');
    dcl-c $delim (',');
    dcl-s exstr char(500);
    
    exstr = $quote + field1 + $quote + $delim +
                  $quote + field2 + $quote;
    
    exec sql 
       insert into flatfilepf values :exstr;
    What am I missing?

  • #2
    Can you confirm the file layout of flatfilepf?

    Can you copy/paste the full error message?

    What happens if you put the values value in brackets: values(:exstr)

    Comment


    • #3
      Layout for flatfile:
      Code:
      r rflatfil
        extrct   500a
      i forgot to put it in my previous post but the paeenthesis is there on the code.

      error message:
      Data exception: Character in CAST argument not valid

      Comment


      • #4
        Hmmm, don't you need a single quote for character values?

        I.e;

        Code:
        dcl-c $quote (''');
        dcl-c $dblquote ('"');
        dcl-c $delim (',');
        dcl-s exstr char(500);
        
        exstr = $quote + $dblquote + field1 + $dblquote + $quote + $delim +
                $quote + $dblquote + field2 + $dblquote + $quote;
        
        exec sql
           insert into flatfilepf values :exstr;

        Edit: Scratch that I was wrong.

        I've tried this with Field1 and Field2 being 10a with Heading1 and Heading2 as the values and it works.

        Comment


        • #5
          A cast error implies that the type of exstr does not match the type of the column in flatfilepf. But according to you they are both 500a chars.

          I'm curious, what happens if you do this:

          Code:
          exstr = '"test1","test2"';
          
          exec sql
          insert into flatfilepf values :exstr;
          Or this:

          Code:
          exec sql
          insert into flatfilepf values('"test1","test2"')
          Are you sure there is not another file on the system called flatfilepf, that might be higher in the library list?

          Comment


          • #6
            Try this:
            Code:
             
             dcl-c $quote ('''');
            Regards

            Kit
            http://www.ecofitonline.com
            DeskfIT - ChangefIT - XrefIT
            ___________________________________
            There are only 3 kinds of people -
            Those that can count and those that can't.

            Comment


            • #7
              You were right Vectorspace. The program was picking up an earlier version of the flatfile where I had the field defined as a numeric. Deleted it and recompiled ghe PF and then defined the $quote as Kit suggested and it worked! Thanks for the help guys.

              Comment

              Working...
              X