I would like to upload a document and create a DIR link to that document. I have created a website in JS where users can upload documents. I would like to pass the uploaded document as input to SAP system such that whenever users upload the document using this website, they do not have to open SAP to do the same.
I have used BAPI_DOCUMENT_CREATE2
for SAP side but my website is in JS and HTML. I would like to know how to connect JS to SAP system, such that when user uploads a file to the website, this file can be passed to the SAP and uploaded there. Please advise!
My website HTML is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Upload Files</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple />
<input type="submit" value="Upload File" name="submit" />
</form>
</body>
<script src="upload.js"></script>
</html>
My SAP API code is as follows:
DATA:
Is_doc LIKE bapi_doc_draw2
If_doctype LIKE bapi_doc_draw2-documenttype,
If_docnumber LIKE bapi_doc_draw2-documentnumber,
If files LIKE bapi_doc_files2 OCCRUS 0 WITH HEADER LINE,
It_drad LIKE bapi_doc_drad OCCURS 0 WITH HEADER LINE.
-------------------------------------------------
Is_doc-documenttype = 'DRW'.
Is_doc-documentnumber = '200121096'
Is_doc-documentversion = '00'
Is_doc-documentpart = '000'
REFRESH It_files.
It_files-storagecategory = 'SAP-SYSTEM'.
It_files-docfile = 'c:\temp\MISC.doc'.
It_wsapplication = 'TXT'.
APPEND It_files.
-------------------------------------------------
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING: documentdate = Is_doc
IMPORTING: documenttype = If_doctype
documentnumber = If_docnumber
documentpart = If_docpart
documentversion = If_docversion
return = Is_return
TABLES: documentdescriptions = It_drat
objectlinks = It_drad
docuemntfiles = It_files
IF Is_return-type CA 'EA'.
ROLLBACK WORK.
MESSAGE ID '26' TYPE 'I' NUMBER '000'
WITH Is_return-message.
ELSE.
COMMIT WORK.
ENDIF.