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

Problemas with Batch input process to open a file in server.

Former Member
0 Likes
1,606

Hi all,

I need a help in read server file in batch input. ( The file address is correct and contains data.)

Follows my attempts:

- OPEN DATASET p_patch FOR INPUT IN TEXT MODE ENCODING DEFAULT.

The sy-subrc returns OK, but when I try read dataset the sy-subrc = 4.

- The Gui_upload function - Don't work to batch

What's wrong?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,364

Also, it can be the case where the file exists on server but it's empty which might be the reason sy-subrc gives 4. Check transaction Al11 for the file and the contents. If not, then create a manual file, upload it through CG3y or CG3z and test your code.

Hi all,

I need a help in read server file in batch input. ( The file address is correct and contains data.)

Follows my attempts:

- OPEN DATASET p_patch FOR INPUT IN TEXT MODE ENCODING DEFAULT.

The sy-subrc returns OK, but when I try read dataset the sy-subrc = 4.

- The Gui_upload function - Don't work to batch

What's wrong?

8 REPLIES 8
Read only

Former Member
0 Likes
1,364

You cannot use GUI_UPLOAD for application file server.

You need to use dataset commands. First Open, then Read into a string variable and then close the dataset. Later split the string variable into specific internal table format.

(Do an F1 on Dataset and you will find the exact syntax. or explore SDN as well).

Read only

Former Member
0 Likes
1,365

Also, it can be the case where the file exists on server but it's empty which might be the reason sy-subrc gives 4. Check transaction Al11 for the file and the contents. If not, then create a manual file, upload it through CG3y or CG3z and test your code.

Read only

Former Member
0 Likes
1,364

post your "read code" . Generally, it is done inside a do loop.

do.

read dataset <name> into <variable or structure of appropriate definition>.

if sy-subrc ne 0. "end of file reached

exit. "get out of DO

endif.

Do something with the variable or structure, to append an internal table

enddo.

Read only

Former Member
0 Likes
1,364

Hi,

u could use FTP functions, such as:

FTP_CONNECT : use parameter rfc_destination = 'SAPFTPA' for background'

FTP_COMMAND

FTP_SERVER_TO_R3

Regards

Read only

Former Member
0 Likes
1,364

Hi...

The Open, read and close dataset have already been declared and don't work. Sorry if I don't post all informations.

Follows the code:

open dataset p_path for input in text mode encoding default .

if sy-subrc = 0.

do.

read dataset p_path into t_arquivo.

if sy-subrc = 0.

append t_arquivo.

clear t_arquivo.

else.

exit.

endif.

enddo.

endif.

close dataset p_path.

Read only

Former Member
0 Likes
1,364

Firstly, avoid using an internal table with header line.

Next SY-SUBRC = 4 when The end of the file has been reached. Can you check the file in Al11 and confirm if it has some data to read?

Regards,

Verma

Read only

Former Member
0 Likes
1,364

Andrea,

The problem may be with the file. For your test purpose, try these two things:

1. Upload another test file, using C3GY/CG3X transactions and test your code.

2. See that your file has some splitter, and try moving the contents to string workarea first then split at the separator.

A sy-subrc can be 4 when the end of file reached. Either file is empty or some issue with the contents of the file.

Regards,

Verma

Read only

Former Member
0 Likes
1,364

Hi...

The problem was solved.

The problem was a directory.. I was to AL11 transaction and don't found the server there... I used the CG3z transaction to upload the file a directory existent and change the parameters to ope, read and close file and well done!

Thanks you all for help.