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: 

reading/writing from net storage machine

Former Member
0 Kudos
130

Hi all,

I'm having some problems with a simple requirements: I have to write a report that IN BACKGROUND read a file from a network shared directory folder, do some processing and write some output in a file in the same network folder. I see that I have to use DATASET operation .. this is is my code:

DATA dset_in(256) TYPE c VALUE '\\strg_machine_name\folder\input_file'.
DATA dset_out(256) TYPE c VALUE '\\strg_machine_name\folder\output_file'.
DATA record(80) TYPE c.

" input
OPEN DATASET dset_in FOR INPUT IN TEXT MODE ENCODING DEFAULT .
DO.
  READ DATASET dset INTO RECORD.
  IF sy-subrc NE 0.
    EXIT.
  ELSE.
      " do some processing filling it_table
  ENDIF.
ENDDO.

" output
OPEN DATASET dset_out FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .
LOOP AT it_table INTO record.
   TRANSFER record TO dset_out.
ENDLOOP.

I cannot understand where is my mistake. Also, can I try a piece of code like this from GUI debugging with se38? or it just work in background mode? (I tried both).

Thanks to anyone can help me

Gabriele

1 ACCEPTED SOLUTION

Former Member
0 Kudos
76

Hi,

Try this.

DATA dset_in(256) TYPE c VALUE '
strg_machine_name\folder\input_file'.

DATA dset_out(256) TYPE c VALUE '
strg_machine_name\folder\output_file'.

DATA record(80) TYPE c.

" input

OPEN DATASET dset_in FOR INPUT IN TEXT MODE ENCODING DEFAULT .

DO.

READ DATASET dset INTO RECORD.

IF sy-subrc NE 0.

EXIT.

ELSE.

" do some processing filling it_table

ENDIF.

ENDDO.

Close DataSET.

" output

OPEN DATASET dset_out FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .

DO.

READ DATASET dset INTO RECORD.

IF sy-subrc NE 0.

EXIT.

ELSE.

" do some processing filling it_table

ENDIF.

ENDDO.

Close DataSET.

LOOP AT it_table INTO record.

TRANSFER record TO dset_out.

ENDLOOP.

Regards,

Vijay

5 REPLIES 5

Former Member
0 Kudos
77

Hi,

Try this.

DATA dset_in(256) TYPE c VALUE '
strg_machine_name\folder\input_file'.

DATA dset_out(256) TYPE c VALUE '
strg_machine_name\folder\output_file'.

DATA record(80) TYPE c.

" input

OPEN DATASET dset_in FOR INPUT IN TEXT MODE ENCODING DEFAULT .

DO.

READ DATASET dset INTO RECORD.

IF sy-subrc NE 0.

EXIT.

ELSE.

" do some processing filling it_table

ENDIF.

ENDDO.

Close DataSET.

" output

OPEN DATASET dset_out FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .

DO.

READ DATASET dset INTO RECORD.

IF sy-subrc NE 0.

EXIT.

ELSE.

" do some processing filling it_table

ENDIF.

ENDDO.

Close DataSET.

LOOP AT it_table INTO record.

TRANSFER record TO dset_out.

ENDLOOP.

Regards,

Vijay

0 Kudos
76

I tried but alway getting sy-subrc = 8

runtime error with this message:

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_FILE_OPEN_MODE', was not

caught and

therefore caused a runtime error.

The reason for the exception is:

When accessing the file "
machine\directory_shared\test.txt", the system recognized

that this file is

not open. Therefore, the file cannot be accessed.

0 Kudos
76

Hi Gabriele again,

When you are fetching file from parameter.

you should use FM GUI_UPLOAD to take data into internal table and then use READ DATASET.

I think then only you will able to run it successfully.

Thanks and Regards,

Vijay

Former Member
0 Kudos
76

Hi,

Try to catch the exception and display the error message. That will tell the exact reason for the dump.

Have a look at this thread and try the suggestions mentioned in it.

[]

Regards,

Vikranth

0 Kudos
76

Hi

I checked the link and it works for path in application server.. but still cannot open network shared file: file are put on other machine with sharing folder, and I want to open that file .. better close this and open new post.