Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with fetch cursor statement

Former Member
0 Likes
928

Hi,

I am using FETCH CURSOR statement to fetch the data from a database table with package size. For the fetched records I am doing parallel processing using parallel processing frame work in banking system.

Here the problem is for the first iteration it works fine but when it comes to FETCH NEXT CURSOR in the second iteration , programs gets dumping by saying that 'CURSOR already closed'.

I am not closing the cursor in the program but some how it got closed some where in the standard function module which I used for parallel processing.

I used WITHHOLD also along with FETCH CURSOR but no use. Please let me know how to avoid the cursor to get close.

Below is my code

IF NOT l_tab_product IS INITIAL.

OPEN CURSOR WITH HOLD lv_cursor FOR

SELECT contract_int prodint cn_currency mig_grp

  • INTO TABLE gt_cont

FROM bca_contract

FOR ALL ENTRIES IN l_tab_product

WHERE prodint = l_tab_product-prodint

AND mig_grp IN s_migrp.

DO.

FETCH NEXT CURSOR lv_cursor

INTO TABLE gt_cont

PACKAGE SIZE lv_size.

IF sy-subrc <> 0.

CLOSE CURSOR lv_cursor.

EXIT.

ELSE.

*

*

*

parallel processing logic

*

*

ENDDO.

ENDIF.

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
842

Using Withhold will not make sure that the cursor will not get closed because of commits.

SAP Doc says

If the addition WITH HOLD is specified, the database cursor is not closed by a database commit executed using Native SQL. The addition does not have an influence, however, on implicit database commits or on any rollbacks which always close the database cursor.

You have to check the part written in your parallel processing logic.

As Brad said please donot dump your old threads like this.

5 REPLIES 5
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
842

You are closing the CURSOR.

IF sy-subrc 0.

CLOSE CURSOR lv_cursor.

Read only

0 Likes
842

Sorry that is typo.

I am not closing it.

If sy-subrc NE 0

CLOSE CURSOR lv_cursor.

EXIT.

I have used above code

Read only

0 Likes
842

Please stop flooding our forum with all of your posts. You don't need to put useless comments in 3 year old posts when you close them. Is this some sort of April Fool's activity?

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
843

Using Withhold will not make sure that the cursor will not get closed because of commits.

SAP Doc says

If the addition WITH HOLD is specified, the database cursor is not closed by a database commit executed using Native SQL. The addition does not have an influence, however, on implicit database commits or on any rollbacks which always close the database cursor.

You have to check the part written in your parallel processing logic.

As Brad said please donot dump your old threads like this.

Read only

ThomasZloch
Active Contributor
0 Likes
842

What Brad said. This gives me a chance though to delete some of these threads altogether.

In the future, please leave the comment box emtpy when closing old threads, unless you want to reveal your own breakthrough solution to the initial problem.

Thomas