ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SQLRPLE compilation Problem

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

  • SQLRPLE compilation Problem

    Hello,

    I want to read a file with SQL in a RPGLE program.
    But when i try to compile the program, the field "RECORD" is undefine (error 7030).

    Could you help me ?

    Thank for your help
    Attached Files

  • #2
    Can you just post your code

    I can't read this file it looks to still be in EBCDIC.


    Or is it a savf??????




    Thanks
    Jamie
    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


    • #3
      The code !

      ================================================== =====================
      The file EFTPLOG
      ================================================== =====================
      A R RFTPLOG
      A RECORD 200 COLHDG('RECORD LOGS')
      ================================================== =====================
      The program
      ================================================== =====================
      D rcd S 30
      *
      C EXSR SQLOPEN
      *
      C SQLCOD DOWEQ 0
      C Eval rcd = %Subst(RECORD:1:30)
      C rcd dsply
      C ENDDO
      *
      C EXSR SQLCLOSE
      *
      *
      C SETON LR
      *================================================= ===============
      * Execute SQL prepare and open statement
      *================================================= ===============
      C SQLOPEN BEGSR
      C/EXEC SQL
      C+ DECLARE A CURSOR FOR
      C+ SELECT RECORD
      C+ FROM EFTPLOG
      C+ WHERE RECORD LIKE 'fmacn%'
      C+ FOR FETCH ONLY
      C/END-EXEC
      *
      C/EXEC SQL
      C+ OPEN A
      C/END-EXEC
      *
      C/EXEC SQL
      C+ SET RESULT SETS CURSOR A
      C/END-EXEC
      C ENDSR
      *================================================= ===============
      *
      *================================================= ===============
      * Close the cursor
      *================================================= ===============
      C SQLCLOSE BEGSR
      C/EXEC SQL
      C+ CLOSE A
      C/END-EXEC
      C ENDSR

      Comment


      • #4
        This should work

        Great to see you back
        I attached it so you can download.


        Code:
             d rcd             S             30
             d reply           S             01
             d record          S            200
             d Work200         S            200
             d SQLErrorCode    s              1  0 inz(0)
              *
             c                   exsr      $openSQL
              *
             c                   exsr      $fetchSQL
             c                   dow       SQLCOD = SQLErrorCode
             c                   eval      rcd = %trim(Work200)
             c     rcd           dsply     reply
             c                   exsr      $fetchSQL
             c                   enddo
              *
             c                   exsr      SQLCLOSE
             c                   eval      *INLR = *on
              *=======================================
              * Declare the SQL
              *=======================================
             c     $declareSQL   begsr
              *
             c/EXEC SQL
             c+ DECLARE cursor CURSOR FOR
             c+ SELECT RECORD
             c+ FROM FILE
             c+ WHERE RECORD LIKE '%JAMIE%'
             c/END-EXEC
              *
             c                   endsr
              *=======================================
              * Execute SQL prepare and open statement
              *=======================================
             c     $openSQL      begsr
             c/EXEC SQL
             c+ OPEN cursor
             c/END-EXEC
             c                   endsr
              *=======================================
              * Close the cursor
              *=======================================
             c     SQLCLOSE      begsr
             c/EXEC SQL
             c+ CLOSE cursor
             c/END-EXEC
             c                   endsr
              *=======================================
              * Fetch SQL
              *=======================================
             c     $FetchSQL     begsr
              *
             c/EXEC SQL
             c+   FETCH cursor
             c+   INTO  :Work200
             c/END-EXEC
              *
             c                   endsr
        Attached Files
        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
          It works !

          Thank's a lot for your help Jamy.

          Does it mean that we can't use directly a filed in an SQLRPLE when using SQL ?
          we are obliged to declare an other field with then property's ?

          Have a nice day.

          Comment


          • #6
            You can still define a file in the program, just fetch into those fields of the file--rather than define new/separate fields in the program--if that's what you mean. Essentially the file becomes an external field description set.

            Too avoid a compiler error, you probably want to add something likes these two lines:

            fFILENAME if e disk usropn

            c lr open FILENAME <== I usually put it in *INZSR (to create condition that will never actually occur).

            Comment

            Working...
            X