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 File to SAP..

Former Member
0 Likes
2,281

Hi Expert,

I have developed a Programm to upload data from the desktop to an internal table and it is working very good.

now I need to make sure that the excel is closed before starting the upload process..so if the file still opens the user will receive an Error message to close it first....

can some help regarding this..

Best Regards

Jenie

Hi Expert,

I have developed a Programm to upload data from the desktop to an internal table and it is working very good.

now I need to make sure that the excel is closed before starting the upload process..so if the file still opens the user will receive an Error message to close it first....

can some help regarding this..

Best Regards

Jenie

8 REPLIES 8
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,096

Can you explain what happens as of now when such a situation occurs?

Read only

matt
Active Contributor
0 Likes
2,096

He's uploading from the desktop.

Read only

RaymondGiuseppi
Active Contributor
2,096

Did you try with some OLE2 call wrapped in your program, else you could try to move the file or execute some OS command (or OLE2 using object filesystem) that should fail if already opened (and move back the file once uploaded)

Read only

iklovski
Active Contributor
0 Likes
2,096

Indeed... didn't pay attention to it.

Read only

DoanManhQuynh
Active Contributor
2,096

I dont see the meaning of the check. it already checked and return an error message, what would you do if you check out that file is open? if user somehow want to process upload even that file is opened mean there is a risk to lost data they editing...anw i think it make no sense.

Read only

0 Likes
2,096

you exactly say the meaning and same time you don't see the meaning.
the reason for that as you mentioned . 🙂

it is to make sure that the user will not lose the data by uploading.. so first close then upload
'here is a risk to lost data they editing'

Read only

Former Member
0 Likes
2,096

raymond.giuseppi

I have written the code below using OLE2 this code just blocking the files which I am selecting and testing as this File is became for reading only.

I just want to recive an Error massege

The folder is locked by another user if the foldser is already opened.
START-OF-SELECTION.
  DATA: h_excel TYPE ole2_object,
        h_book  TYPE ole2_object,
       sheet TYPE ole2_object,
       cells TYPE ole2_object.
  DATA locked_flag TYPE abap_bool.
  DATA p_spalte TYPE char255.
  INCLUDE ole2incl.



  CREATE OBJECT h_excel 'Excel.Application'.
  SET PROPERTY OF h_excel 'Visible' = 0.
  CALL METHOD OF
      h_excel
      'Workbooks' = h_book.
  CALL METHOD OF
      h_book
      'OPEN'

    EXPORTING
      #1     = p_fname.
*free_object h_book.  :!:
  GET PROPERTY OF h_excel 'ACTIVEWORKBOOK' = h_book.
  GET PROPERTY OF h_book 'ReadOnly' = locked_flag.
  IF locked_flag = '0'.
*if locked_flag-header(1) = '0'.
    CALL METHOD OF
        h_excel
        'CELLS' = cells
      EXPORTING
        #1      = cells
        #2      = p_spalte.
    SET PROPERTY OF cells 'VALUE' = '1'.

    FREE OBJECT cells .
   WRITE ' The folder is not locked ' .
*call method of h_book 'Save' = h_save.  
*    FREE OBJECT h_save.
  ELSE.

    WRITE 'The folder is locked by another user' .
  ENDIF.

could please help me to achive this..

Thanks

Jenie

Read only

DoanManhQuynh
Active Contributor
2,096

OK, sorry i missunderstood your question. the easiest way i could tell is using gui_upload method to open that file first, if there is any error that method will raise an exception including file already opened check. within OLE, i think there already have that check (when you call open method it should be return sy-subrc = 2 if file opened) but in my system its not happended, maybe it changed with office version, anw OLE just the way you call VBA method, you can check the VBA if there is anyway to check file opened. one more way, but not suggested, is using SM69 to call external command...