tags:

views:

108

answers:

1

Hi there, I'm trying to write some native SQL in abap but got some problems.

Here's my code:

method GET_SOMEDATA.

  DATA:   lt_table    TYPE TABLE OF /BI0/TCUSTOMER,
          c1          TYPE /BI0/TCUSTOMER.

  DATA: BEGIN OF wa,
          customer    TYPE /BI0/OICUSTOMER,
          txtsh       TYPE RSTXTSH,
          txtmd       TYPE RSTXTMD,
          txtlg       TYPE RSTXTLG,
        END OF wa.

    EXEC SQL.
      OPEN c1 FOR
        SELECT * FROM /BI0/TCUSTOMER
         WHERE customer LIKE '229'.
    ENDEXEC.
    DO.
      EXEC SQL.
          FETCH NEXT c1 INTO :wa-customer, :wa-txtmd
*         ERROR: CX_SY_NATIVE_SQL_ERROR
      ENDEXEC.
      IF sy-subrc = 0.
*        <process data>
      ENDIF.
    ENDDO.
    EXEC SQL.
      CLOSE c1
    ENDEXEC.

endmethod.

After calling "FETCH NEXT c1 INTO :wa-customer, :wa-txtmd" I'm getting an "CX_SY_NATIVE_SQL_ERROR" - I guesse something with my cursor is not ok - but I have no idea. Some help would be great.

+2  A: 

Rule 1: Don't use Native SQL.

Rule 2: Don't use Native SQL.

Rule 3: Don't use Native SQL.

...

Rule n: Don't use Native SQL.

Rule n+1: Seriously, don't.

Rule n+2: If you really have to, remember you'll have to specify the client manually.

Rule n+3: Don't use SELECT * in Native SQL, always select the fields specifically by name. Reason: You can't FETCH ... INTO CORRESPONDING FIELDS but have to take care that the sequence, number and data types of the target fields match. If your table /BI0/TCUSTOMER does not only consist of two fields typed as /BI0/OICUSTOMER and RSTXTMD, that's most probably the cause for the exception.

vwegert