Application Development 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: 

Error :DATASET_NOT_OPEN Except.: CX_SY_FILE_OPEN_MODE

Former Member
0 Kudos

Hello experts

Kindly help me on this... All my scheduled background job were CANCELLED due to this error...

Error analysis: ST22 An exception occurred that is explained in detail below. The exception, which is assigned to class 'CX_SY_FILE_OPEN_MODE', was not caught in procedure "BACKGROUND_JOB" "(FORM)", 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: When accessing the file "C:\tempfiles\empdata\EmpData20100112.csv", the system recognized that this file is not open. Therefore, the file cannot be accessed.

FORM BACKGROUND JOB CODES:

DATA: LV_BET01 TYPE STRING.

  IF P_TEST EQ 'X'.
    CONCATENATE P_PATH 'EmpData' SY-DATUM 'test' '.csv' INTO V_FILEPATH.
  ELSE.
    CONCATENATE P_PATH 'EmpData' SY-DATUM '.csv' INTO V_FILEPATH.
  ENDIF.

  OPEN DATASET V_FILEPATH FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
  LOOP AT GT_EMP INTO WA_EMP.

    WHILE WA_EMP-NACHN CS ','.
      REPLACE ',' WITH ' ' INTO WA_EMP-NACHN.
    ENDWHILE.

    WHILE WA_EMP-VORNA CS ','.
      REPLACE ',' WITH ' ' INTO WA_EMP-VORNA.
    ENDWHILE.

    WHILE WA_EMP-CARD CS ','.
      REPLACE ',' WITH ' ' INTO WA_EMP-CARD.
    ENDWHILE.

    CONCATENATE
        WA_EMP-PERNR
        WA_EMP-WERKS
        WA_EMP-VORNA
        WA_EMP-NACHN
        WA_EMP-NATIO
        WA_EMP-GBDAT
        WA_EMP-ADD
        WA_EMP-ORT01
        WA_EMP-PSTLZ
        WA_EMP-GESCH
        WA_EMP-CELL
        WA_EMP-EMAIL
        WA_EMP-TEL
        WA_EMP-F_DAY
        WA_EMP-S_DAY
        WA_EMP-PERSG
        WA_EMP-L_GROUP
        WA_EMP-P_GROUP
        WA_EMP-P_GRP_BEG
        WA_EMP-P_GRP_END
        WA_EMP-ORGEH
        WA_EMP-POS_EFF
        WA_EMP-POS_END
        WA_EMP-STELL
        WA_EMP-STELL2
        WA_EMP-PRIM
        WA_EMP-CARD
    INTO V_FILEPATH1 SEPARATED BY ','.

    TRANSFER V_FILEPATH1 TO V_FILEPATH.
  ENDLOOP.
  CLOSE DATASET V_FILEPATH.

PLEASE help me how can i resolved this... Thank you!

6 REPLIES 6

nirajgadre
Active Contributor
0 Kudos

Hi,

check that while running the background job the specified file is not open in the presentation server.

martin_voros
Active Contributor
0 Kudos

Hi,

you should check if the command OPEN DATASET was successful. You try to write data to file which is not open. My guess is that the problem is with access. Maybe somebody change rights on your folder.

Cheers

Former Member
0 Kudos

hi,

In background you cannot take a file from the PC or desktop.

So you goto CG3Z transaction,Source FIle from front end give your file path C:\tempfiles\empdata\EmpData20100112.csv

Then in Application server path Give /Tmp/EmpData20100112.csv

then You can see your file in AL11 Tcode in TMP directory.

prf_file = /Tmp/EmpData20100112.csv.

Now use

OPEN DATASET prf_file FOR INPUT IN TEXT MODE .

if sy-subrc <> 0.

MESSAGE i000(8i) WITH text-401.

ENDIF.

DO.

READ DATASET prf_file INTO gds_field.

enddo.

CLOSE DATASET prf_file

OPEN DATASET w_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT MESSAGE MSG.

IF SY-SUBRC EQ 0.

LOOP AT itab INTO wa_itab.

TRANSFER wa_itab TO w_file.

ENDLOOP.

CLOSE DATASER w_file.

ELSE.

" Display the message from MSG

ENDIF.

Regards,

Manesh.R

Former Member
0 Kudos

Hi,

it is true, that You should check sy-subrc after OPEN DATASET, but problem in your case is on a different place. You are changing the variable which contains a dataset name. Never do that between OPEN DATASET and CLOSE DATASET. You should create a new variable for a file line.

So instead:

CONCATENATE x1 x2 x3 ... INTO V_FILEPATH.
TRANSFER v_filepath1 TO v_filepath.

use:

DATA: lv_file_line TYPE string.
CONCATENATE x1 x2 x3 ... INTO lv_file_line.
TRANSFER lv_file_line TO v_filepath.

Hope it helps.

Regards,

Adrian

0 Kudos

Hi,

as far as I can see he has a separate variable V_FILEPATH1 for output line

Cheers

0 Kudos

Hi Martin,

sorry, as I can see now, You are right:-) Just names of variables are little bit confusing.

Adrian