cancel
Showing results for 
Search instead for 
Did you mean: 

Upload Master Data documents

Former Member
0 Kudos

Hi,

here is my problem : i want to upload documents to master data in my BSP application. For this, i use RSOD_DOC_CHANGE. This module function call gui_upload and this doesn't work. I follow the sample in Weblogs but i don't know where is my file and if i can put it in master data. Someone can help me ?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

What type, if any, error messages are you getting? Is there a Dump in the system? (ST22)

Former Member
0 Kudos

I have a blank page, the same when you try to call GUI_UPLOAD in the event OnInputProcessing

Former Member
0 Kudos

Have you set external debugging breakpoints and tried stepping through your code line by line to see where your ouput fails?

Code you post the code here using [ code] [/ code] without the spaces of course ?

Former Member
0 Kudos

It fails on GUI_UPLOAD.

Like some posts and Brian McKellar says, GUI_UPLOAD doesn't work in BSP application.

In my search, i found the method GET_URL of the class CL_RSOD_MAST. This return the url to the document browser. But I cannot find another way to add a document to master data.

Former Member
0 Kudos

Here are a few posts I found using the search function for this forum they deal with uploading files using BSP for excel but I'm sure you could alter the code to meet your needs.

And this one deals directly with the upload topic

[url=;Upload File BSP [/url]

Former Member
0 Kudos

It's what i've said at the beginning of my post : i try this but i don't know how can i use the sample in weblog to add a document to master data. I have to enter in RSOD_DOC_CHANGE which is not very easy...

Former Member
0 Kudos

Perhaps something like this would help???

This is from Brian's web log on <a href="/people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents Programming: Handling Of Non-HTML Documents</a>

Page Attributes


        file_length    TYPE  STRING
        file_mime_type TYPE  STRING
        file_name      TYPE  STRING
        file_content   TYPE  XSTRING
        display_type   TYPE  STRING
        display_url    TYPE  STRING

Page Layout


<htmlb:fileUpload id          = "myUpload"
                          onUpload    = "HandleUpload"
                          upload_text = "Display"
                          size        = "90" />

Page Event Handler Input 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.

* I have the file now what?

Unforutnatly I have no way of testing but it looks like you would then add the file_content to the

"I_T_FILE_CONTENT_ASCII" Table of the FM "RSOD_DOC_CHANGE", from looking at it seems to be the file content in ASCII form there is also the "I_T_FILE_CONTENT_BINARY" for binary form both have different structures which you can look into by double clicking on the structure type name.

I wish I could help more but I have no possibilites

For the FM you are required only to set the following import parameters:

I_OVERWRITE_MODE Values: 0: new LOIO; 1: new PHIO, 2: Replace PHIO

I_T_PROP - Settings for the document (Type: SDOKPROPTYS, which is a name and a value)

I_DOC_CLASS - BW Document Class

The other parameters are optional, but maybe you need them.

<b>Not tried it</b>!!

Former Member
0 Kudos

It's what i said, i try this solution from weblog but cannot apply it to upload a master data document. The FM RSOD_DOC_CHANGE call GUI_UPLOAD to upload the file. It means that i have to re-write RSOD_DOC_CHANGE to bypass GUI_UPLOAD and replace it by another solution, but for the moment, i haven't find how !

Thansk

Former Member
0 Kudos

Actually you don't have to do that at all. If you look at the code of the FM RSOD_CHANGE_DOC

<b>Line number 52</b>


*     upload from PC if no content is given
      IF i_t_file_content_binary[] IS INITIAL AND
         i_t_file_content_ascii[]  IS INITIAL.
*       load file with I_S_CONTENT_INFO-file_name
        DATA l_string TYPE string. l_string = i_s_content_info-file_name
        .
        DATA l_int    TYPE i.      l_int    = i_s_content_info-file_size
        .
        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            filename                      = l_string
            filetype                      = 'BIN'
*           HAS_FIELD_SEPARATOR           = ' '
*           HEADER_LENGTH                 = 0
*           READ_BY_LINE                  = 'X'
*           DAT_MODE                      = ' '
          IMPORTING
            filelength                    = l_int
*           HEADER                        =
          TABLES
            data_tab                      = i_t_file_content_binary
          EXCEPTIONS
            file_open_error               = 1
            file_read_error               = 2
            no_batch                      = 3
            gui_refuse_filetransfer       = 4
            invalid_type                  = 5
            no_authority                  = 6
            unknown_error                 = 7
            bad_data_format               = 8
            header_not_allowed            = 9
            separator_not_allowed         = 10
            header_too_long               = 11
            unknown_dp_error              = 12
            access_denied                 = 13
            dp_out_of_memory              = 14
            disk_full                     = 15
            dp_timeout                    = 16
            OTHERS                        = 17.

The FM looks first to the content of <i>i_t_file_content_binary[]</i> and <i>i_t_file_content_ascii[]</i> therefore my example would work for you. You upload the file and place the contents into one of those two structures (DOC, PDF, XLS are binary) then call the function.

Former Member
0 Kudos

Yes, it's what i'm seeing in my exploration of th FM. Now, i'm trying to upload my file and give it to the FM RSOD_DOC_CHANGE. If i manage to do this, i will post the code

Thanks

Former Member
0 Kudos

I would assume the type you will be putting in is <i>i_t_file_content_binary[]</i>, and the code example would be appreciated!! Never know when someone else might need it.

Former Member
0 Kudos

Argh !!! I'am getting crazy !! All i want is convert my xstring to var like raw (1022) !! Cannot convert easily !!!

Former Member
0 Kudos

What's the error?

What code are you using?

Former Member
0 Kudos

Here is how i retrieve my file :

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.

file_content is a xstring that contains my file (like D0CF11E0A1B11AE1000..)

When i use GUI_UPLOAD with the same file, the first line start like D0CF11E0A1B11AE1000.. Then i have to found how to put my xstring to a table of line type raw (1022).

-> l_t_data_tab_bin TYPE sdokcntbins.

This is the result table used in GUI_UPLOAD and in RSOD_DOC_CHANGE.

sdokcntbins is table type of line of structure sdokcntbin. sdokcntbin is composed with LINE RAW 1022

I thought about a loop which takes 1022 caracters of xstring and put it into LINE but it doesn't work !! I cannot find how to make this

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Here is a code example where I take a byte string and break it up into an internal table with a line width of raw 255:


  data: xdocument1 type xstring.

*... ->fill xdocument1

  data: l_line type solix.
  cdocument_length = xstrlen( xdocument1 ).
  while not xdocument1 is initial.
    l_line-line = xdocument1.
    append l_line to cdocument_table.
    shift xdocument1 left by 255 places in byte mode.
  endwhile.

Former Member
0 Kudos

Here is my code :

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: v_struct TYPE SDOKCNTBIN.

DATA: v_cur_pos type I.

DATA: v_line type SDOK_SDATX.

DATA: v_temp type xstring.

DATA: v_length type i.

DATA: v_test type string.

v_cur_pos = 0.

v_test = file_content.

WHILE v_cur_pos < file_length.

v_length = file_length - v_cur_pos.

IF v_length >= 1022.

v_length = 1022.

ENDIF.

v_temp = file_content+v_cur_pos(v_length).

v_cur_pos = v_cur_pos + 1022.

move v_temp to v_line.

v_struct-line = v_line.

INSERT v_struct INTO TABLE l_t_data_tab_bin.

ENDWHILE.

It doesn't work because the table contains 231022 lines and in GUI_UPLOAD, it contains 121022 !! And lines are diffent !!

My head is going to explode !!!

Former Member
0 Kudos

Thomas, i follow your code and write this :

v_temp = file_content.

while not v_temp is initial.

v_line = v_temp.

v_struct-line = v_line.

INSERT v_struct INTO TABLE l_t_data_tab_bin.

shift v_temp left by 1022 places in byte mode.

endwhile.

But it doesn't work. 13*1022 lines in my table

former_member181879
Active Contributor
0 Kudos

Cédric,

What I still don't see, is why you don't check the splitted table against the original string? Already a simple sanity check will go a long to keep the head on.


DATA: xtable TYPE STANDARD TABLE OF SDOK_SDATX.
FIELD-SYMBOLS: <xline> LIKE LINE OF xtable.

DATA: sanity_size TYPE I.

WHILE file_content IS NOT INITIAL.
  APPEND INITIAL LINE TO xtable ASSIGNING <xline>.
  DATA: n TYPE I.
  n = xstrlen( file_content ).
  IF n > 1022. n = 1022. ENDIF.
  <xline> = file_content(n).
  file_content = file_content+n.
  sanity_size = sanity_size + n.
ENDWHILE.

IF sanity_size <> file_length.
  CALL FUNCTION 'HOUSTON WE HAVE A PROBLEM'. 
ENDIF.

Notice the use of the field symbol to effective move the content directly into the table. For the above code, when I upload a binary file, the two sizes match. Always keep in mind that the last row is x(1022), but will not always be filled.

So what is now to do?

(1) First you write a very small program in SE38. All that this program does, is use GUI upload to get the file into the server. Then you look at my weblog on crawling SDN. In the last few lines I use a server side cookie to store a 130KB table. You use the same few lines, and store the xstring from GUI upload into a server side cookie.

(2) Now the first sanity test will be to see if the file upload is actually working correctly. You do the file upload. You read the server side cookie, and then you compare these two xstrings to see that they match! Do this, so that you get a base on which to build.

(3) Next you copy any of the above split routines into you code. I like mine. You add the sanity check like I did, and verify that the length that you counted matches file_length.

(4) As a next step, I would have considered to store this new table of 1022 xstrings into a server side cookie again. And then change the program again in se38 to now compare the table you created against the table that gui upload gives you.

With this, you should be able to crack the problem.

Former Member
0 Kudos

My code and your code has the same result. When i use GUI_UPLOAD for a file, it fills the table with 12x1022. And when i use my/your code, it fills the table with 23x1022 and that's my problem. Why the hell GUI_UPLOAD gives a table of 12x1022 ??? My file length is 22528.

12*1022 = 12264 (how can it store my file ??)

23*1022 = 23506 (can store my file ...)

I have call RSOD_DOC_CHANGE whith my table filled (23*1022) using your code. But when i want to see the document via RSA1, it tells me that it didn't find the document. Is it because of my table which is wrong filled ? Or is it because i miss something ?

> In the last few lines I use a server side cookie to store a 130KB table

Is it this (from Handling Of Non-HTML Documents) :

response->set_header_field( name = 'Content-Disposition'

value = 'attachment; filename=myFile.xyz' ).

response->set_header_field( name = 'Content-Disposition'

value = 'inline' ).

Sorry for all my questions but i really need it to work and i want to understand how

Former Member
0 Kudos

Sorry, forget the last part of my last post. My Baby takes all my rest time, and my eyes are tricking me.

I see the right weblogs (SDN crawling). But i don't understand how, after putting my file on a server side cookie, can i use RSOD_DOC_CHANGE with my table filled and then, have my file in Master data.

When i give my table filled to RSOD_DOC_CHANGE, why can't it put it in master data ? In RSOD_DOC_CHANGE, if the binary and ascii table are not filled, it calls GUI_UPLOAD but there, i have filled my table, where is the problem ?

former_member181879
Active Contributor
0 Kudos

Cédric,

The problem is that you are running around all over, and not systematically trying to solve it. You also sometimes skip information. Looking at your problem, it seems that you want to indicate the GUI upload is the cause. Hmmmm... I wonder if we are on a unicode system here.

So now I am going to write you only one thing to do.

Write in SE38 a small program that contains ONLY gui-upload plus the call to RSOD_DOC_CHANGE that works for you. It must not be more than 25 lines of code.

Which means that

you

are calling gui_upload, setting the parameters correctly, and then this doc_change function. First this must work. Then we do the next step.

Append the 25 lines here.

Former Member
0 Kudos

Is exactly what i have done. I wrote a FM that call GUI_UPLOAD and then RSOD_DOC_CHANGE. In se38, it works great. But when i call it in my bsp application, it fails on GUI_UPLOAD.

Here is the FM :

FUNCTION Z_CG_DOC_ADD.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(OBJET) TYPE STRING DEFAULT 'Z_CONTCOD'

*" REFERENCE(CONTRAT) TYPE STRING

*" REFERENCE(DOCTYPE) TYPE STRING OPTIONAL

*" REFERENCE(FILE) TYPE C

*" REFERENCE(DESCRIPTION) TYPE STRING OPTIONAL

*" EXCEPTIONS

*" FILE_NOT_FOUND

*" ADD_ERROR

*"----


DATA: v_s_content_info TYPE rsod_s_content_info.

DATA: l_t_return TYPE bapiret2.

DATA: v_exist type C.

DATA: v_isdir type C.

DATA: v_name TYPE skwf_urlp.

DATA: V_CHARNAM TYPE RSCHANM.

DATA: V_CHARVAL TYPE RSCHAVL.

DATA: V_DOCTYPE TYPE RSODWWWDOCTYPE.

DATA: V_DESC TYPE SDOK_DESCR.

  • On teste si le fichier existe

CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'

EXPORTING

FNAME = FILE

IMPORTING

EXIST = v_exist

ISDIR = v_isdir

.

IF SY-SUBRC <> 0.

RAISE FILE_NOT_FOUND.

ELSE.

IF v_exist NE 'X' or v_isdir NE ' '.

RAISE FILE_NOT_FOUND.

ELSE.

v_s_content_info-file_name = FILE.

ENDIF.

ENDIF.

  • Renseignement des variables

V_NAME = FILE.

V_CHARNAM = OBJET.

V_CHARVAL = CONTRAT.

V_DOCTYPE = DOCTYPE.

V_DESC = DESCRIPTION.

  • On upload le document dans le master data

CALL FUNCTION 'RSOD_DOC_MAST_CHANGE'

EXPORTING

I_CHANM = V_CHARNAM

I_CHAVL = V_CHARVAL

I_DOC_TYPE = V_DOCTYPE

I_DESCRIPTION = V_DESC

I_NAME = v_name

I_OVERWRITE_MODE = if_rsod_const=>mode_new_phio

I_WITH_CONTENT = 'X'

I_S_CONTENT_INFO = v_s_content_info

IMPORTING

E_S_RETURN = l_t_return

.

ENDFUNCTION.

Former Member
0 Kudos

Ok, i've found it !!!!

I just use your code (not for server side cookie) and pass right arguments to RSOD_DOC_MAST_CHANGE with my table filled (23*1022) and it works.

Sorry for all time you have lost for me but very very very big thanks !!

former_member181879
Active Contributor
0 Kudos

Yes!

(GUI_UPLOAD does NOT work in BSP! Out there is a browser, and not a thing called GUI!).

Former Member
0 Kudos

Hello, How about adding your code to the code sample section for others who might have the same needs or similiar ones?

Former Member
0 Kudos

Here is my code (not the final version) :

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: v_struct TYPE SDOKCNTBIN.

DATA: v_cur_pos type I.

DATA: v_line type SDOK_SDATX.

DATA: v_temp type xstring.

DATA: v_length type i.

v_cur_pos = 0.

v_temp = file_content.

while not v_temp is initial.

v_line = v_temp.

v_struct-line = v_line.

INSERT v_struct INTO TABLE l_t_data_tab_bin.

shift v_temp left by 1022 places in byte mode.

endwhile.

DATA: l_s_content_info TYPE rsod_s_content_info.

l_s_content_info-mimetype = 'application/msword'.

l_s_content_info-file_size = file_length.

CALL FUNCTION 'RSOD_DOC_MAST_CHANGE'

EXPORTING

I_CHANM = 'Z_CONTCOD'

I_CHAVL = '00011'

I_DOC_TYPE = 'SUP_ASS'

I_DESCRIPTION = 'Description'

I_NAME = 'Test2.doc'

I_OVERWRITE_MODE = if_rsod_const=>mode_replace_phio

I_WITH_CONTENT = 'X'

I_S_CONTENT_INFO = l_s_content_info

TABLES

I_T_FILE_CONTENT_BINARY = l_t_data_tab_bin

.

Be sure ton fill correctly l_s_content_info-mimetype, l_s_content_info-file_size and I_WITH_CONTENT. Otherwise, file cannot be uploaded correctly (informations are store but not the file).

Thanks all for your help

Answers (2)

Answers (2)

Former Member
0 Kudos

hi,

i want to attach the logical file in the document tab of the Campaign. can anyone guide me how to proceed it.

Thanks & Regards

DInesh

Former Member
0 Kudos

I hesitate whether It's still interesting for you)) But...

You can use a class CL_RSOD_MAST. Create an instance using character name and value. Then call method <IF_RSOD_CONTEXT>~get_documents to get a class which has a list of documents attached to this value. Through the methods of this class you can add new document.

Former Member
0 Kudos

Hello All,

i am new SDN member have a problem of uploading and downloading file into BSP application. I need to upload a file in BSP application and the file should be downloaded from sap memory or server in to same page by clicking the file name. I tried the code given here. But am wondering where the uploaded file is stored and how it could be downloaded into same or different pages. Please help me out.

I have created 2 (File_upload.htm and display.htm) htm files with flow logic.still am facing problem and am not able to upload & download files properly.

File_upload.htm code :

<%@page language="abap" %>

<%@extension name="htmlb" prefix="htmlb" %>

<htmlb:content design="design2002" >

<htmlb:page>

<htmlb:form method = "post"

encodingType = "multipart/form-data" >

<htmlb:fileUpload id = "myUpload"

onUpload = "HandleUpload"

upload_text = "Upload"

size = "70" />

</htmlb:form>

</htmlb:page>

</htmlb:content>

Event :oninputprocessing:

  • event handler for checking and processing user input and

  • for defining navigation

data: entity type ref to if_http_entity,

file type xstring,

content_type type string,

content_length type string,

num_multiparts type i,

i type i value 1,

doEcho type string,

value type string.

  • find multipart containing file

num_multiparts = request->num_multiparts( ).

while i <= num_multiparts.

entity = request->get_multipart( i ).

value = entity->get_header_field( '~content_filename' ).

if not value is initial.

  • found a file!

navigation->set_parameter( name = 'content_filename'

value = value ).

content_type = entity->get_header_field( 'Content-Type' ).

navigation->set_parameter( name = 'content_type'

value = content_type ).

  • get file content

file = entity->get_data( ).

  • get file size

content_length = xstrlen( file ).

navigation->set_parameter( name = 'content_length'

value = content_length ).

  • echo/download the same file again?

doEcho = request->get_form_field( 'doEcho' ).

if doEcho is not initial.

  • set response data to be the file content

runtime->server->response->set_data( file ).

  • set the mime-type and file size in the response

runtime->server->response->set_header_field(

name = 'Content-Type'

value = content_type ).

runtime->server->response->set_header_field(

name = 'Content-Length'

value = content_length ).

runtime->server->response->delete_header_field(

name = 'Cache-Control' ).

runtime->server->response->delete_header_field(

name = 'Expires' ).

endif.

exit.

endif.

i = i + 1.

endwhile.

if doEcho is not initial.

  • signal to the BSP runtime that the response data is

  • complete and no onLayout method should be called to

  • create the response

navigation->response_complete( ).

else.

navigation->goto_page( 'display.htm' ).

endif.

Display.htm

<%@page language="abap" %>

<%@include file="head_abap.htm" %>

<p>

The file has been properly uploaded.

<p>

<table border=1 width="100%">

<tr>

<td> Filename </td>

<td> <a href = " <%= content_filename %> "</a> </td>

</tr>

<tr>

<td> Content-type </td>

<td> <%= content_type %> </td>

</tr>

<tr>

<td> Content-Length </td>

<td> <%= content_length %> </td>

</tr>

</table>

<p>

<a href="File_upload.htm">Get back</a>.

%@include file="tail_abap.htm" %

Even:

CLASS CL_HTMLB_MANAGER DEFINITION LOAD.

DATA: data TYPE REF TO CL_HTMLB_FILEUPLOAD.

data ?= CL_HTMLB_MANAGER=>GET_DATA(

request = runtime->server->request

name = 'fileUpload'

id = 'myFileUpload1'

).

IF data IS NOT INITIAL.

name = data->file_name.

content = data->file_content.

length = data->file_length.

content_type = data->file_content_type.

ENDIF.

Regards,

Shanmuga

maximilian_schaufler
Active Contributor
0 Kudos

Hi Shanmuga,

as the question to this old thread has already been answered, please open a new thread with your question.

We want to keep things organized a bit, so for a new question create a new thread, makes it a lot easier for other people to find and read your question as well as the (hopefully upcoming) answers.

Thx

Max