cancel
Showing results for 
Search instead for 
Did you mean: 

File Upload in BSP Applications and store in Application server

Former Member
0 Kudos
1,737

Hi we have requirement to store the attachments from BSP application into the external/internal storage space connected to application server.

I search for weblogs and all talking about <a href="http://help.sap.com/saphelp_me21sp2/helpdata/en/eb/8c683c8de8a969e10000000a114084/content.htm">File Upload in BSP Applications and store in MIME Repository</a>.

But our requirement is upload and store(no need to read the file content) attachments from BSP page into file server, and then make a link back in BSP page to open.

I know we can handle documnets in R/3 using DMS, but our system is SRM.

Please give a suggestion and solution.

Thanks,

Giri

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I faced a similar problem some time ago (uploading a file via BSP, storing it to the application server and then linking the archived document to a business object.

Here is the coding I used:

when 'SubmitUploadFile'. "OnInputProcessing

DATA: data_fileupload TYPE REF TO CL_HTMLB_FILEUPLOAD,

l_filename type string,

l_archiv_doc_id type SAPB-SAPADOKID,

l_content type string,

l_file_ixos(100) type c value '/transfer/PV2/aus/IXOS/',

l_file(200) type c,

tbl_bin TYPE STANDARD TABLE OF tbl1024,

wa_bin type TBL1024,

l_xstring type xstring,

l_arc_doc_id type SAPB-SAPADOKID,

l_doctype type TOADD-DOC_TYPE,

l_filename_e type DRAW-FILEP.

  • upload the file from the BSP web interface (e.g. file C:TempSUTestPDF_SU.pdf)

data_fileupload ?= CL_HTMLB_MANAGER=>GET_DATA(

request = runtime->server->request

name = 'fileUpload'

id = ‘InputFieldFileUpload’

).

IF NOT data_fileupload IS INITIAL.

l_filename = data_fileupload->file_name.

l_content = data_fileupload->file_content.

l_content_type = data_fileupload->file_content_type.

ENDIF.

  • The uploaded file is returned as XSTRING, so we have to convert it to BINARY

  • (or STRING alternatively)!

l_xstring = l_content.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = l_xstring

APPEND_TO_TABLE = 'X'

TABLES

BINARY_TAB = tbl_bin.

  • split path for storing the file to the application server

l_filename_c = l_filename.

CALL FUNCTION 'CV120_SPLIT_PATH'

EXPORTING

PF_PATH = l_filename_c

IMPORTING

PFX_FILE = l_filename_e.

  • write the uploaded file to the application server

l_filename = l_filename_e.

concatenate l_file_ixos l_filename into l_file.

open dataset l_file for output IN LEGACY BINARY MODE.

loop at tbl_bin into wa_bin.

transfer wa_bin-line to l_file.

endloop.

close dataset l_file.

  • store the uploaded file on the IXOS-archive

l_doctype = l_content_type.

CALL FUNCTION 'ARCHIVOBJECT_CREATE_FILE'

EXPORTING

ARCHIV_ID = '2T'

DOCUMENT_TYPE = l_doctype

PATH = l_file_arc

IMPORTING

ARCHIV_DOC_ID = l_arc_doc_id

EXCEPTIONS

ERROR_ARCHIV = 1

ERROR_COMMUNICATIONTABLE = 2

ERROR_UPLOAD = 3

ERROR_KERNEL = 4

OTHERS = 5.

  • link the archived document to the business object ‘DRAW’

CALL FUNCTION 'ARCHIV_CONNECTION_INSERT'

EXPORTING

ARCHIV_ID = '2T'

ARC_DOC_ID = l_arc_doc_id

AR_OBJECT = 'DRW'

OBJECT_ID = g_object_id_arc

SAP_OBJECT = 'DRAW'

DOC_TYPE = l_extend

EXCEPTIONS

ERROR_CONNECTIONTABLE = 1

OTHERS = 2.

Remark: It´s vital to convert the uploaded file from XSTRING to BINARY. Otherwise the file cannot be stored/archived properly.

The archived document can then be displayed by inserting the (IXOS-web client-)link to the BSP page (e.g. http://193.228.208.78:4060/archive.dll/get?arc=2T&doc=44439F1B4F701E65E1000000C1E4D00A).

Hope this helps!

Regards,

Ulli

Former Member
0 Kudos

Hi Ulli,

Thanks for your reply. I didn't understand some thing here, after you write the file content to application server you are storing the uploaded file to IXOS-archive. I didn't understand this part, please explain what this part do.

What value should I pass to the parameter 'PATH' to FM ARCHIVOBJECT_CREATE_FILE. And please give an example for parameter 'l_extend' & g_object_id_arc in FM ARCHIV_CONNECTION_INSERT.

To display the Archived document, the link you mentioned is not working.

Please clear it.

Thanks,

Giri

Former Member
0 Kudos

Hi Giri,

Storing the uploaded file to any archive system (e.g. IXOS) is just one possibility to make the file available globally.

The parameter "PATH" holds the path, where the uploaded document is stored on the application server. (e.g. '/transfer/PV2/aus/IXOS/testfile.pdf', with "testfile.pdf" being the filename of the uploaded file).

The FM "ARCHIVOBJECT_CREATE_FILE" then creates an "archive doc id" that is used in FM "ARCHIV_CONNECTION_INSERT" to connect the archived document to the relevant object id (e.g. object "document" (=DRAW), see transaction code CV03N, another object could be BUS2012 (=purchase order).

The import parameter "g_object_id_arc" for FM "ARCHIV_CONNECTION_INSERT" could look something like that: "D01RABEST01 00D05". (This object id contains all the key fields of table "DRAW" (DRAW-DOKAR (=D01), DRAW-DOKNR (=RABEST01), DRAW-DOKVR (=00) and DRAW-DOKTL (=D05).

Regards,

Ulli

Former Member
0 Kudos

Hi Ulli,

Could please help the link you provided is not working.

http://193.228.208.78:4060/archive.dll/get?arc=2T&doc=44439F1B4F701E65E1000000C1E4D00A

Plesae help.

Thanks,

Gireesh

Former Member
0 Kudos

Hi Giri,

Look at this sample code, for how to handle file upload in the application server from BSP.

Layout:

<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
  <htmlb:page title=" " >
    <htmlb:form id           = "form1"
                encodingType = "multipart/form-data" >
      <htmlb:fileUpload id          = "myUpload"
                        onUpload    = "HandleUpload"
                        upload_text = "Display"
                        size        = "30"></htmlb:fileUpload>
      <hr>
      <%
  if file_content is not initial.
      %>
      <br>Name = <%= file_name%>
      <br>MIME-Type = <%= file_mime_type%>
      <br>Length = <%= file_length%>
      <br>URL = <%= display_url %>
      <br>File Content <%= file_content %>
      <%
  endif.
      %>
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

OnInput Processing:

DATA: fileUpload TYPE REF TO CL_HTMLB_FILEUPLOAD.
fileUpload ?= CL_HTMLB_MANAGER=>GET_DATA(
                       request = request
                       id      = 'myUpload'
                       name    = 'fileUpload' ).

file_name      = fileUpload->file_name.
file_mime_type = fileUpload->file_content_type.
file_length    = fileUpload->file_length.
file_content   = fileUpload->file_content.

DATA: fname type string.

* Enter the path to be stored in the server here....

Data : filepath type string,

       t1 type string.

filepath = file_name .

while filepath CA ''.

  split filepath at '' into t1 filepath.

endwhile.


* Enter the path to be stored in the server here....

*This location is not shared,…

fname = '<Path in the application server>' .


concatenate fname filepath into fname.


OPEN DATASET fname FOR OUTPUT IN BINARY MODE.
TRANSFER file_content TO FNAME.
CLOSE DATASET FNAME.

* You can generate the URL..display_url shows you URL

REPLACE ALL OCCURRENCES OF '/' IN fname WITH ''.

concatenate '<hostname>' fname into display_url.

* to update the path into a data base table
data: s_no type int3.
data: wa type ZFILE_UPLOAD.
SELECT MAX( S_NO ) FROM ZFILE_UPLOAD INTO s_no.
wa-s_no = s_no + 1.
wa-PATH = fname.

Using this approach we handled file upload, into the application server, and the path of the file is maintained in a DB table, so that we can download the file the application server later.

Hope this helps,

Regards,

Ravikiran.