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

Shortdump for fetch statement in the loop

Former Member
0 Likes
1,308

I am trying download the table data into a file. It is writing first file successfully, when it comes to second set of data to fetch from table it is giving short dump. maybe Database connection lost ?

Runtime Errors DBIF_RSQL_INVALID_CURSOR

Exception CX_SY_OPEN_SQL_DB

Anybody knows about this

OPEN CURSOR WITH HOLD C_CURSOR FOR
        SELECT * FROM (p_table).
  DO.
    FETCH NEXT CURSOR C_CURSOR INTO TABLE <F_FS> PACKAGE SIZE 50.
    IF sy-subrc  <> 0.
      CLOSE CURSOR C_CURSOR.
      EXIT.
    ENDIF.
  LOOP AT <F_FS> ASSIGNING <F_FS2>.
  append itab.
 ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                = L_FILE
        FILETYPE                = 'DAT'
        WRITE_FIELD_SEPARATOR   = '|'
      TABLES
        DATA_TAB                = ITAB
      EXCEPTIONS
        FILE_WRITE_ERROR        = 1
       OTHERS                  = 22.
    IF SY-SUBRC  = 0.
      FREE ITAB.
      REFRESH ITAB.
    ENDIF.
  ENDDO.

Edited by: fract_get on Feb 1, 2010 8:20 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,006

Hi

Probably the fm GUI_DOWNLOAD raises a COMIT and this can interrupt the connection.

U should place the call of that fm out from the selection:

OPEN CURSOR WITH HOLD C_CURSOR FOR
        SELECT * FROM (p_table).
  DO.
    FETCH NEXT CURSOR C_CURSOR INTO TABLE <F_FS> PACKAGE SIZE 50.
    IF sy-subrc  NE 0.
      CLOSE CURSOR C_CURSOR.
      EXIT.
    ENDIF.
     LOOP AT <F_FS> ASSIGNING <F_FS2>.
      append itab.
    ENDLOOP.
 ENDDO.

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                = L_FILE
        FILETYPE                = 'DAT'
        WRITE_FIELD_SEPARATOR   = '|'
      TABLES
        DATA_TAB                = ITAB
      EXCEPTIONS
        FILE_WRITE_ERROR        = 1
       OTHERS                  = 22.
    IF SY-SUBRC  = 0.
      FREE ITAB.
      REFRESH ITAB.
    ENDIF.

Max

I am trying download the table data into a file. It is writing first file successfully, when it comes to second set of data to fetch from table it is giving short dump. maybe Database connection lost ?

Runtime Errors DBIF_RSQL_INVALID_CURSOR

Exception CX_SY_OPEN_SQL_DB

Anybody knows about this

OPEN CURSOR WITH HOLD C_CURSOR FOR
        SELECT * FROM (p_table).
  DO.
    FETCH NEXT CURSOR C_CURSOR INTO TABLE <F_FS> PACKAGE SIZE 50.
    IF sy-subrc  <> 0.
      CLOSE CURSOR C_CURSOR.
      EXIT.
    ENDIF.
  LOOP AT <F_FS> ASSIGNING <F_FS2>.
  append itab.
 ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                = L_FILE
        FILETYPE                = 'DAT'
        WRITE_FIELD_SEPARATOR   = '|'
      TABLES
        DATA_TAB                = ITAB
      EXCEPTIONS
        FILE_WRITE_ERROR        = 1
       OTHERS                  = 22.
    IF SY-SUBRC  = 0.
      FREE ITAB.
      REFRESH ITAB.
    ENDIF.
  ENDDO.

Edited by: fract_get on Feb 1, 2010 8:20 PM

6 REPLIES 6
Read only

Former Member
0 Likes
1,007

Hi

Probably the fm GUI_DOWNLOAD raises a COMIT and this can interrupt the connection.

U should place the call of that fm out from the selection:

OPEN CURSOR WITH HOLD C_CURSOR FOR
        SELECT * FROM (p_table).
  DO.
    FETCH NEXT CURSOR C_CURSOR INTO TABLE <F_FS> PACKAGE SIZE 50.
    IF sy-subrc  NE 0.
      CLOSE CURSOR C_CURSOR.
      EXIT.
    ENDIF.
     LOOP AT <F_FS> ASSIGNING <F_FS2>.
      append itab.
    ENDLOOP.
 ENDDO.

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                = L_FILE
        FILETYPE                = 'DAT'
        WRITE_FIELD_SEPARATOR   = '|'
      TABLES
        DATA_TAB                = ITAB
      EXCEPTIONS
        FILE_WRITE_ERROR        = 1
       OTHERS                  = 22.
    IF SY-SUBRC  = 0.
      FREE ITAB.
      REFRESH ITAB.
    ENDIF.

Max

Read only

0 Likes
1,006

Probably you are correct, but i want to download next set of data into another file. I am writing a program to download the table data in multiple files based on package size.

How can i get the next set of data...

Read only

0 Likes
1,006

Get all of your data into different internal tables using PACKAGE SIZE and then do the download.

As Max said, anything that causes a COMMIT will cause the CURSOR to lose it's place. I don't think you can do a PERFORM.

Rob

Read only

0 Likes
1,006

Table input is dynamic. How can i create different internal tables during the program execution....

Read only

1,006

Hi

U can try to something like this:

TYPES: TY_FILE TYPE STRING.
TYPES: TY_T_FILES TYPE TABLE OF TY_FILE.

DATA: BEGIN OF T_FILES OCCURS 0,
       L_FILE TYPE STRING,
       T_DATA TYPE TY_T_FILES,
      END   OF T_FILES.

OPEN CURSOR WITH HOLD C_CURSOR FOR
        SELECT * FROM (P_TABLE).
DO.
  FETCH NEXT CURSOR C_CURSOR INTO TABLE <F_FS> PACKAGE SIZE 50.
  IF SY-SUBRC  NE 0.
    CLOSE CURSOR C_CURSOR.
    EXIT.
  ENDIF.
  T_FILES-L_FILE = 'C:\FILE.........'.
  REFRESH T_FILES-T_DATA.
  LOOP AT <F_FS> ASSIGNING <F_FS2>.
    APPEND <F_FS2> TO T_FILES-T_DATA.
*    APPEND ITAB.
  ENDLOOP.
  APPEND T_FILES.
ENDDO.
*
LOOP AT T_FILES.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      FILENAME              = T_FILES-L_FILE
      FILETYPE              = 'DAT'
      WRITE_FIELD_SEPARATOR = '|'
    TABLES
      DATA_TAB              = T_FILES-T_DATA
    EXCEPTIONS
      FILE_WRITE_ERROR      = 1
      OTHERS                = 22.
ENDLOOP.

Max

Read only

Former Member
0 Likes
1,006

Hi,

It seems you want to download the content into different files of 50 lines each. If this is the requirement, why dont you build some sort of logic as shown below to avoid losing database connection for the cursor.

OPEN CURSOR WITH HOLD C_CURSOR FOR

SELECT * FROM (p_table).

DO.

FETCH NEXT CURSOR C_CURSOR INTO TABLE <F_FS> PACKAGE SIZE 50.

IF sy-subrc 0.

CLOSE CURSOR C_CURSOR.

EXIT.

ENDIF.

LOOP AT <F_FS> ASSIGNING <F_FS2>.

append itab.

ENDLOOP.

ENDDO.

Var2 = 1.

Describe Table itab Lines var1. "Count number of tables

no0ftab = var1 Mod 50.

nooftab = nooftab + 1.

Do nooftab Times.

Loop at itab from Var2 to 50.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = L_FILE

FILETYPE = 'DAT'

WRITE_FIELD_SEPARATOR = '|'

TABLES

DATA_TAB = ITAB

EXCEPTIONS

FILE_WRITE_ERROR = 1

OTHERS = 22.

IF SY-SUBRC = 0.

ENDIF.

EndLoop.

Var2 = Var2 + 50.

EndDo.

Thanks,

Vinny