cancel
Showing results for 
Search instead for 
Did you mean: 

Getting sy-subrc = 8 at the time of opening CSV file

Former Member
0 Kudos

Hi,

In my program i wriien like this. Here i am getting sy-subrc = 8 .please let me know why??

I am giving my file path like this : C\temp\batchfile.csv

TRANSLATE SOURCE_FILE TO LOWER CASE.

OPEN DATASET SOURCE_FILE FOR INPUT IN TEXT MODE.

IF SY-SUBRC NE 0. " File open error

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Suhas,

Here, you are opening the file from the C\temp\batchfile.csv, instead you have to read the file from the application server.

You wrote the code:

OPEN DATASET SOURCE_FILE FOR INPUT IN TEXT MODE.

which means that you are reading the file from the application server.

Effect

OPEN ... FOR INPUT opens the file in read mode.

If the file does not exist, OPEN ... FOR INPUT fails with Return Code SY-SUBRC = 8.

I think you want to write the file to the appication server so use the below syntax.

OPEN DATASET SOURCE_FILE FOR OUTPUT IN TEXT MODE.

Hope the answer of your question.

Regards,

Md Ziauddin

Answers (2)

Answers (2)

Former Member
0 Kudos

HI,

Does your file name is having spaces??

Check this link

Regards and Best wishes.

satyajit_mohapatra
Active Contributor
0 Kudos

Are you uploading the file from desktop or application server? If you are uploading it from application server check the existence of the file. If you are uploading it from presentation server use FM GUI_UPLOAD.

Former Member
0 Kudos

Hi,

I am uploading file from application server.

How to i put my file in application server?

Please help me

Former Member
0 Kudos

Hi Suhas,

You are saying that you are uploading the file from the application server and you are giving the path C\temp\batchfile.csv

which means the file is not present in the application server.

eg.

Please see example code below to read the file from the application server.

REPORT ZEX_DATATOFILE .

&----


*& ABAPLOVERS: Data Transfer

&----


  • Parameters to enter the path

PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat' (file on application server)

LOWER CASE.

  • Table Declaration

TABLES VBAK.

  • Data Declaration

DATA D_MSG_TEXT(50).

  • Get data for file transfer

DATA INT_VBAK LIKE VBAK OCCURS 100

WITH HEADER LINE.

SELECT * FROM VBAK INTO TABLE INT_VBAK.

SORT INT_VBAK BY VBELN.

LOOP AT INT_VBAK.

WRITE: / INT_VBAK-VBELN,

INT_VBAK-KUNNR.

ENDLOOP.

  • Opening the File

OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE

MESSAGE D_MSG_TEXT.

IF SY-SUBRC NE 0.

WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.

EXIT.

ENDIF.

  • Transferring Data

LOOP AT INT_VBAK.

TRANSFER INT_VBAK-VBELN TO FILENAME.

ENDLOOP.

  • Closing the File

CLOSE DATASET FILENAME.

Regads,

Md Ziauddin.