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

Upload CSV file from Application server

Former Member
0 Likes
1,761

Hi folks,

I am trying to upload a CSV file from the application server (SAP PRd server) The file is not opening

parameters: p_file like rlgrap-filename.

In p_file here is the path ' E:\sapprd\int_files\sap2008\import-export scripts\123.csv'

'sap2008' is the folder in SAP PRD server and 'import-export scripts' a sub folder and '123.csv' is the file...

OPEN DATASET p_file FOR INPUT IN TEXT MODE.

if sy-subrc = 8.

WRITE:/ 'FILE', P_FILE, 'cannot be opened'.

exit.

endif.

while sy-subrc = 4.

READ DATASET ld_file into wa_string.

if sy-subrc = 0.

MOVE-CORRESPONDING wa_string to itab.

append itab.

clear itab.

endif.

endwhile.

The result is sy-subrc = 8... file cannot open.

Am I missing something here?

Thanks in advance,

VG

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,189

Vinu.....

go to AL11 and take the exact path... i think path would be \sapprd\int_files\sap2008\import-export scripts\123.csv.

Check the path once again and not only that go to that path and double click on the file... and see whether u r able to open the file or not........

if you are not able to open the file then that means u don't have the authorization to do .....

Check that once if u have any further issues let me know.

9 REPLIES 9
Read only

Former Member
0 Likes
1,189

Also,

How can I schedule to run this in batch mode as an automated process?

I need to run this process 2 to 3 times per week and each time I get the file with the date convention attached to it. I need to set this process automatic because running the file manually is cumbersome.

Thanks in advance in this regard,

VG

Read only

0 Likes
1,189

Try changing E:\sapprd\int_files\sap2008\import-export scripts\123.csv to \sapprd\int_files\sap2008\import-export scripts\123.csv

So, they leave the file with a date attached and that same day you pick the file?

Then, just add sy-datum to the name of the file and make it the default value, if someone is running a job it should pick the file of that day

Read only

Former Member
0 Likes
1,190

Vinu.....

go to AL11 and take the exact path... i think path would be \sapprd\int_files\sap2008\import-export scripts\123.csv.

Check the path once again and not only that go to that path and double click on the file... and see whether u r able to open the file or not........

if you are not able to open the file then that means u don't have the authorization to do .....

Check that once if u have any further issues let me know.

Read only

0 Likes
1,189

Hi,

thanks for the response. I tried to locate the path using AL11. I did not find it. Does that mean I do not have the authorisation to read files from APP server? How should I go about from here?

Thanks in advance,

VG

Read only

0 Likes
1,189

Just to mention, the filepath that I had mentioned earlier, is the same physical path that I assign to the logical filenames to write a file on App server from various interfaces. Does it have to be different the other way?

Thanks,

VG

Read only

0 Likes
1,189

Vinu,

If I remember correctly, when using OPEN DATASET, the file name can not have spaces in the name. Try renaming your file removing spaces and retry.

For your code, you'll need to breakdown the CSV file by the delimiter.

This code makes an archive file while reading the main file.


    OPEN DATASET filname IN TEXT MODE MESSAGE t_mesg.
    IF sy-subrc NE 0.
      MOVE 'X' TO t_error.
      MESSAGE e100(z0) WITH 'Error reading file:' t_mesg.
      EXIT.
    ENDIF.

    IF p_load = 'X'.
      OPEN DATASET archfilname FOR OUTPUT IN TEXT MODE MESSAGE t_mesg.
      IF sy-subrc NE 0.
        MOVE 'X' TO t_error.
        MESSAGE e100(z0) WITH 'Error opening achrive file:' t_mesg.
        EXIT.
      ENDIF.
    ENDIF.
    DO.
      READ DATASET filname INTO my_rec.
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
      IF p_load = 'X'.
        TRANSFER my_rec TO archfilname.
      ENDIF.
      SPLIT my_rec AT c_tab       " Here my delimter was a tab change to ',' for comma
        INTO  in_rec-id
              in_rec-fname
              in_rec-lname
              in_rec-addr
              in_rec-apt
              in_rec-city
              in_rec-state
              in_rec-zip
              in_rec-branch
              in_rec-phone1
              in_rec-phone2
              in_rec-phone3
              in_rec-phone3_ext
              in_rec-email
              in_rec-hear
              in_rec-prefcont
              in_rec-ownland
              in_rec-build
              in_rec-ownhome
*              in_rec-get_promo
              in_rec-cmt1
              in_rec-subdate.
      APPEND in_rec TO it_input.
    ENDDO.
    CLOSE DATASET filname.
    IF p_load = 'X'.
      CLOSE DATASET archfilname.
      DELETE DATASET filname.
    ENDIF.
  ENDIF.

Read only

0 Likes
1,189

Thanks for the response. It gives the message 'No such file or directory'. Coming to the use of Split command, I am using that piece of code in my subsequent lines. I am reading the data into a line string and then moving into the individual data elements of the itab.

Let me know if I am missing something here.

VG

Read only

franois_henrotte
Active Contributor
0 Likes
1,189

try to get more info about the error


  data: lv_messg type text50.

  open dataset my_file for input... ... message lv_messg.

  write: / sy-subrc, lv_messg.

that would help to know which is the error exactly

Read only

0 Likes
1,189

Hi folks,

Resolved the issue with the help of basis guy and it was related to file path and file type it is stored in the application server. Shall award the points and close the thread.

Thanks for the help,

VG