ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Error Executung Sql - Sqlcod = -000000303

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

  • Error Executung Sql - Sqlcod = -000000303

    C* Declare cursor
    C/EXEC SQL
    C+ DECLARE C1 CURSOR FOR
    C+ SELECT DESIRED_FIELDS
    C+ FROM MY_FILE
    C+ WHERE CONDITION_1 AND CONDITION_2
    C+ ORDER BY SOME_FIELD
    C/ END-EXEC
    :
    :
    C* Open the cursor
    C/EXEC SQL
    C+ OPEN C1
    C/END-EXEC
    :
    :
    C SQLCOD DOWEQ *ZEROS
    :
    :
    C* Fetch the data.
    C/EXEC SQL
    C+ FETCH FROM C1
    C+ INTO
    C+ DESIRED_FIELDS
    C/END-EXEC

    :
    :
    C IF SQLCOD <> *ZEROS
    C LEAVE
    C ENDIF

    C EXSR PROCESS_SQL_DATA

    C ENDDO

    C* Close the Cursor
    C/EXEC SQL
    C+ CLOSE C1
    C/END-EXEC

    At above IF I am getting error with error code: SQLCOD = -000000303
    and then I am leaving the loop.

    Here is my job log:

    ODP created.
    Blocking used for query.
    Cursor C1 opened.
    Host variable VARIABLE1 not compatible.
    SQLCOD = -000000303.

    I am having valid data to satisfy my above conditions in my_file.
    It is working fine in Interfactive SQL. I am not able to understand what
    could go wrong.... Any help would be greatly appreciated.

  • #2
    Re: Error Executung Sql - Sqlcod = -000000303

    How is "DESIRED_FIELDS" defnied in your program?
    "Time passes, but sometimes it beats the <crap> out of you as it goes."

    Comment


    • #3
      Re: Error Executung Sql - Sqlcod = -000000303

      Hi,

      In my select statement I have at least 13 fields (my desired fields) from file (my_file). I hope I understand right what you are asking.

      Comment


      • #4
        Re: Error Executung Sql - Sqlcod = -000000303

        I dont think you need the from in the fetch
        Code:
        C* Fetch the data. 
        C/EXEC SQL 
        C+ FETCH FROM C1 
        C+ INTO 
        C+ DESIRED_FIELDS
        C/END-EXEC
        try

        C* Fetch the data.
        C/EXEC SQL
        C+ FETCH C1
        C+ INTO
        C+ DESIRED_FIELDS
        C/END-EXEC


        May we see your actual CONDITION_1 AND CONDITION_2
        it may be formatted incorrectly Trying to match character data with decimal

        I searched for error code 303
        Code:
        SQL -303 VALUE ASSIGNMENT ERROR 
        
        SQLCODE  -303, Error: A VALUE CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE NUMBER  BECAUSE THE DATA TYPES ARE
        NOT COMPARABLE
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Error Executung Sql - Sqlcod = -000000303

          ~ or try ~

          C* Fetch the data.
          C/EXEC SQL
          C+ FETCH NEXT FROM C1
          C+ INTO
          C+ DESIRED_FIELDS
          C/END-EXEC

          Comment


          • #6
            Re: Error Executung Sql - Sqlcod = -000000303

            I found the problem. It was my mistake on select statement. I forgot to specify comma (,) after first line of selection fields.

            Strange things is my program compiled well; But while executing the program I am getting error after "FETCH" SQLCODE WITH ERROR -000000303 and I am leaving the loop without processing any records from file.

            Thanks

            Comment


            • #7
              Re: Error Executung Sql - Sqlcod = -000000303

              It's hard to speculate on what an error might be without seeing the actual code (in full). ^^' Anyway, in regards to your error message, it appears to be this situation:

              SQL0303

              Message Text: Host variable &2 not compatible.

              Cause Text: A FETCH, SELECT, CALL, SET, or VALUES INTO cannot
              be performed because the data type of host variable &2
              is not compatible with the data type of the corresponding
              list item.

              v When selecting a date value, a character host variable
              must be at least 6 bytes for a Julian date, at least 8
              bytes for a date in the MDY, YMD, DMY formats, or at
              least 10 bytes for all other formats.
              v When selecting a time value, a character host variable
              must be at least 8 bytes for a time in the USA format
              and at least 5 bytes for all other formats.
              v When selecting a timestamp value, a character host
              variable must be at least 19 bytes.
              v If the host variable is C NUL-terminated and the
              program was compiled with *CNULRQD option, then
              an additional byte is required for the NUL-terminator for
              date/time values.
              The relative position of the host variable in the INTO
              clause, the SQLDA, or the CALL statement is &1. If the
              host variable name is *N, an SQLDA was specified on a
              FETCH statement.

              Recovery Text: Ensure that the data types are compatible for each of the
              corresponding list items. Ensure the host variables are
              defined correctly for date, time, and timestamp values.
              SQLCODE or SQLCODEs: -303
              SQLSTATE or SQLSTATEs: 22001 42806

              Comment


              • #8
                Re: Error Executung Sql - Sqlcod = -000000303

                Its a problem with the host declaration.

                The table columns and the host variables should match in declaration with the same datatype and length.

                Comment

                Working...
                X