Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Fetch Cursor failing to retreive data

Hi All,

I have wriiten a query using cursors. After execution the cursor's count is 2 . However while I fetch the cursor data into an internal table it fails

and gives sy-subrc = 0.'

Please help.

OPEN CURSOR gv_cursor FOR

       SELECT a~ebeln

              a~lifnr

              a~bukrs

              a~aedat

              a~bsart

              a~statu

              a~waers

              a~angnr

              a~ihrez

              b~ebelp

              b~txz01

              b~afnam

              b~netpr

              c~prctr

              c~aufnr

              c~kostl

              c~sakto

              d~etenr

              d~eindt

     FROM     ekko AS a

     LEFT OUTER JOIN  ekpo AS b ON  a~ebeln = b~ebeln

     JOIN     ekkn AS c    ON  a~ebeln = c~ebeln

                           AND b~ebelp = c~ebelp

                           AND c~zekkn = '01'

     JOIN     eket AS d ON  a~ebeln = d~ebeln

                           AND b~ebelp = d~ebelp

     WHERE    a~ebeln in lr_ebeln

     AND      a~bukrs IN lr_bukrs

     AND      a~lifnr IN lr_lifnr

     AND      c~sakto IN lr_saknr

     AND      d~eindt IN lr_eindt

     AND      d~etenr = '001'

     ORDER BY a~ebeln

              b~ebeln b~ebelp

              c~ebeln c~ebelp c~zekkn

              d~ebeln d~ebelp d~etenr.


FETCH NEXT CURSOR gv_cursor

      INTO TABLE lt_main

      PACKAGE SIZE 1000.

     IF sy-subrc <> 0.

.

   

     ENDIF.

replied

Hi Faizur,

Please go through the below code, It is working fine for me,

TABLES: ekko,ekkn,eket.

TYPES: BEGIN OF ty_t,

        ebeln TYPE ekko-ebeln,

        lifnr TYPE ekko-lifnr,

        bukrs TYPE ekko-bukrs,

        aedat TYPE ekko-aedat,

        bsart TYPE ekko-bsart,

        statu TYPE ekko-statu,

        waers TYPE ekko-waers,

        angnr TYPE ekko-angnr,

        ihrez TYPE ekko-ihrez,

        ebelp TYPE ekpo-ebelp,

        txz01 TYPE ekpo-txz01,

        afnam TYPE ekpo-afnam,

        netpr TYPE ekpo-netpr,

        prctr TYPE ekkn-prctr,

        aufnr TYPE ekkn-aufnr,

        kostl TYPE ekkn-kostl,

        sakto TYPE ekkn-sakto,

        etenr TYPE eket-etenr,

        eindt TYPE eket-eindt,

        END OF ty_t.

DATA: gv_cursor TYPE cursor,

       lt_main TYPE TABLE OF ty_t,

       wa_main TYPE ty_t.

SELECT-OPTIONS:

                 lr_ebeln FOR ekko-ebeln,

                 lr_bukrs FOR ekko-bukrs,

                 lr_lifnr FOR ekko-lifnr,

                 lr_saknr FOR ekkn-sakto,

                 lr_eindt FOR eket-eindt.

OPEN CURSOR gv_cursor FOR

        SELECT a~ebeln

               a~lifnr

               a~bukrs

               a~aedat

               a~bsart

               a~statu

               a~waers

               a~angnr

               a~ihrez

               b~ebelp

               b~txz01

               b~afnam

               b~netpr

               c~prctr

               c~aufnr

               c~kostl

               c~sakto

               d~etenr

               d~eindt

      FROM     ekko AS a

      LEFT OUTER JOIN  ekpo AS b ON  a~ebeln = b~ebeln

      JOIN     ekkn AS c    ON  a~ebeln = c~ebeln

                            AND b~ebelp = c~ebelp

                            AND c~zekkn = '01'

      JOIN     eket AS d ON  a~ebeln = d~ebeln

                            AND b~ebelp = d~ebelp

      WHERE    a~ebeln in lr_ebeln

      AND      a~bukrs IN lr_bukrs

      AND      a~lifnr IN lr_lifnr

      AND      c~sakto IN lr_saknr

      AND      d~eindt IN lr_eindt

      AND      d~etenr = '001'

      ORDER BY a~ebeln

               b~ebeln b~ebelp

               c~ebeln c~ebelp c~zekkn

               d~ebeln d~ebelp d~etenr.

DO.

   FETCH NEXT CURSOR gv_cursor

         INTo wa_main.

   IF sy-subrc <> 0.

     close cursor gv_cursor.

     exit.

   ELSE.

     APPEND wa_main to lt_main.

     CLEAR wa_main.

   ENDIF.

ENDDO.


Regards,

John.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question