11-23-2007 9:20 AM
Hi Guys ,
Iam trying to open two cursors at a time , and below i have attached the code the way iam trying to open the cursor and fetch the records from the cursor .
but iam getting a dump like
Please advice me what is the actual problem .
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught
in
procedure "Z01_FBIWI_AR_EXTRACTOR" "(FUNCTION)", nor was it propagated by a
RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The cursor used in a FETCH or CLOSE CURSOR command is
not open. It was either not yet open or has already
been closed. You can close the cursor explicitly with
the CLOSE CURSOR command, implicitly with the COMMIT WORK command,
or with a screen change.
And below i have attached the code .
**DATA DECLERATION
Maximum number of lines for DB table
STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
counter
S_COUNTER_DATAPAKID LIKE SY-TABIX,
Cursor
S_CURSOR TYPE CURSOR,
S_CURSOR1 TYPE CURSOR.
DATA : FLAG_BSID TYPE BOOLEAN VALUE ' '.
Initialization mode (first call by SAPI) or data transfer mode
(following calls) ?
IF I_INITFLAG = SBIWA_C_FLAG_ON.
APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.
Fill parameter buffer for data extraction calls
S_S_IF-REQUNR = I_REQUNR.
S_S_IF-DSOURCE = I_DSOURCE.
S_S_IF-MAXSIZE = I_MAXSIZE.
Fill field list table for an optimized select statement
(in case that there is no 1:1 relation between InfoSource fields
and database table fields this may be far from beeing trivial)
APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.
ELSE. "Initialization mode or data extraction ?
************************************************************************
Data transfer: First Call OPEN CURSOR + FETCH
Following Calls FETCH only
************************************************************************
First data package -> OPEN CURSOR
IF S_COUNTER_DATAPAKID = 0.
Fill range tables BW will only pass down simple selection criteria
of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'BUKRS'.
MOVE-CORRESPONDING L_S_SELECT TO R_BUKRS.
APPEND R_BUKRS.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'KUNNR'.
MOVE-CORRESPONDING L_S_SELECT TO R_KUNNR.
APPEND R_KUNNR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'GJAHR'.
MOVE-CORRESPONDING L_S_SELECT TO R_GJAHR.
APPEND R_GJAHR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CPUDT'.
MOVE-CORRESPONDING L_S_SELECT TO R_CPUDT.
APPEND R_CPUDT.
ENDLOOP.
Determine number of database records to be read per FETCH statement
from input parameter I_MAXSIZE. If there is a one to one relation
between DataSource table lines and database entries, this is trivial.
In other cases, it may be impossible and some estimated value has to
be determined.
OPEN CURSOR WITH HOLD S_CURSOR FOR
SELECT MANDT KUNNR WRBTR XREF3 BUKRS BELNR GJAHR BUZEI WAERS BLDAT
BUDAT BLART XBLNR SHKZG DMBTR GSBER ZFBDT ZLSCH ZUONR ZTERM
KIDNO XREF1 XREF2 SGTXT MABER HKONT PRCTR KOSTL AUFNR PROJK
VBUND
FROM BSID WHERE BUKRS IN R_BUKRS AND KUNNR IN R_KUNNR AND
GJAHR IN R_GJAHR AND
CPUDT IN R_CPUDT .
OPEN CURSOR WITH HOLD S_CURSOR1 FOR
SELECT MANDT KUNNR WRBTR XREF3 BUKRS BELNR GJAHR BUZEI WAERS BLDAT
BUDAT BLART XBLNR SHKZG DMBTR GSBER ZFBDT ZLSCH ZUONR ZTERM
KIDNO XREF1 XREF2 SGTXT MABER HKONT PRCTR KOSTL AUFNR PROJK
VBUND
FROM BSAD WHERE BUKRS IN R_BUKRS AND KUNNR IN R_KUNNR AND
GJAHR IN R_GJAHR AND
CPUDT IN R_CPUDT .
ENDIF. "First data package ?
Fetch records into interface table.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE IT_BSID
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC EQ 0 .
PERFORM FETCH_BSId12 TABLES E_T_DATA.
ELSE .
CLOSE CURSOR S_CURSOR.
FLAG_BSID = 'X'.
ENDIF .
FETCH NEXT CURSOR S_CURSOR1
APPENDING CORRESPONDING FIELDS
OF TABLE IT_BSAD
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC EQ 0 .
PERFORM FETCH_BSAD12 TABLES E_T_DATA.
ELSEIF FLAG_BSID EQ 'X'.
CLOSE CURSOR S_CURSOR1.
RAISE NO_MORE_DATA.
ENDIF .
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF. "Initialization mode or data extraction ?
ENDFUNCTION.
11-23-2007 9:40 AM
see this example program
DATA: BEGIN OF count_line,
carrid TYPE spfli-carrid,
count TYPE i,
END OF count_line,
spfli_tab TYPE TABLE OF spfli.
DATA: dbcur1 TYPE cursor,
dbcur2 TYPE cursor.
OPEN CURSOR dbcur1 FOR
SELECT carrid count(*) AS count
FROM spfli
GROUP BY carrid
ORDER BY carrid.
OPEN CURSOR dbcur2 FOR
SELECT *
FROM spfli
ORDER BY carrid.
DO.
FETCH NEXT CURSOR dbcur1 INTO count_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
FETCH NEXT CURSOR dbcur2
INTO TABLE spfli_tab PACKAGE SIZE count_line-count.
ENDDO.
CLOSE CURSOR: dbcur1,
dbcur2.