cancel
Showing results for 
Search instead for 
Did you mean: 

Add pdf file to BSP

Former Member
0 Kudos

Hi Friends,

please let me know how to add PDF File for bsp page. I got a BSP Page of a table for data entry of many fields With description field as well,and I want to add/attach a pdf file to this field( so that it will be stored in ITAB FOR that field, and while retrieving , this has to be displayed in in that field of table only). I tried through the following code.

<u>OnInputProcessing</u>



when 'save'.
ITAB_WA-DESCRIPTION = request->get_form_field( 'DESCRIPTION.pdf' ).
Append ITAB_WA TO ITAB.
MODIFY  STUDENT1 FROM  TABLE ITAB.
  ENDIF.

Please mail me details as I required some sort of help in this regard and it is urgent.

Regards

CSM Reddy

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

what do you exactly want to do - upload a pdf from client and show it in browser/save to database or generate a pdf and show it in browser ?

Regards

Former Member
0 Kudos

Hi ,

I just want only to upload a pdf from client and show it in (BSP PAGE)browser/save to database.

Regards

CSM REDDY

athavanraja
Active Contributor
0 Kudos

for uploading pdf check out the following weblog.

/people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents

In this weblog sample is shown on how to upload image, but the same can be used for pdf as well. make sure to set the MIME type

If you have problem in understanding the weblog do let us know.

Regards

Raja

Former Member
0 Kudos

Hi Raja,

Thanks for reply. I do know about this web log & to upload Images in BSP Page( as I thought MIMES IS only for .ZIP,.JPEG OR IMAGE FILES). But, my BSP Page contains a table with many fields displaying from ITAB. I would like to upload the PDF File for ONLY Particular table field. i.e example . only Description field.in that case How to add the pdf file only for this table field( as This field in ITAB ,only Holds maximum of 255 chars).I need to resolve this problem.

Regards

CSM REDDY

eddy_declercq
Active Contributor
0 Kudos

Hi,

Do you need the file as a whole in the itab or just the reference to a location? Since you've only 255 chars, you won't be able to have the content as such. I would say that a reference is the only solution and that you save the actual file on your file system or like we do in Ixos.

Eddy

Former Member
0 Kudos

Hi,

Reference is fine, could you mail me how to refer it from my file system, Is it same TAG like using <href> tag, to that field??

Regards

CSM REDDY

Former Member
0 Kudos

Hi again,

I think you have to extend your table by some fields which mustn't be displayed on client side. I defined following:

filename type string (which is shown on client side)

filetype type char132

filesize type int4 (or bigger?)

uploaddate type dats

lines type soli_tab (for file content)

in the upload handling you have to manage the incoming data and give it to specialised fields.

Especially for the filecontent you have to know in which format you want to save it to database. We bind our files by GOS to business objects - so we convert the incoming xstring-content into the char format:

<i>

data: lines type sytabix,

conv type ref to cl_abap_conv_in_ce,

inhalt_hex type xstring,

doc_line(255) type c,

len type i,

len_hex type syfdpos.

  • Konvertierung Hex->Char

len_hex = xstrlen( data->file_content ).

try.

conv = cl_abap_conv_in_ce=>create( input = data->file_content ).

catch cx_parameter_invalid_range

cx_sy_codepage_converter_init.

  • RAISE attachments_error.

endtry.

do.

clear doc_line.

try.

conv->read( importing data = doc_line

len = len ).

catch cx_sy_conversion_codepage

cx_sy_codepage_converter_init

cx_parameter_invalid_type

cx_parameter_invalid_range.

  • RAISE attachments_error.

endtry.

append doc_line to <row>-lines.

if conv->position ge len_hex.

exit.

endif.</i>

Regards,

Sebastian

eddy_declercq
Active Contributor
0 Kudos

Hi,

The reference is the name of the file you've used. Let's call it FNAME as variable name.

Let's pretend you've retrieved the file from the browser into the xstring. See my earlier post for details.

Then you need to do this.

fname = '/usr/tmp/eddy.txt'.

OPEN DATASET fname FOR OUTPUT IN BINARY MODE.

TRANSFER XTSRINGVAR TO FNAME.

CLOSE DATASET FNAME.

Later you can retrieve it via

OPEN DATASET FNAME FOR INPUT IN BINARY MODE.

DO.

READ DATASET FNAME INTO it_attach LENGTH LENG.

append it_attach.

clear it_attach.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET FNAME.

Eddy

athavanraja
Active Contributor
0 Kudos

i feel a clickable image to upload file should be placed in a column of table view and once the image is clicked you should open up a page with htmlb:fileupload and do the processing of fileupload from that page and once done you should updated your htmlb:tablview with one more column with a image or link saying click here to view the document.

Regards

Raja

Former Member
0 Kudos

Hi,

I mean to upload file on Server side, not on client side.The clients has got only display mode.

Regards

CSM Reddy

Message was edited by: SRIMALLIKARJUNA REDDY CHEMICALA

athavanraja
Active Contributor
0 Kudos

i am not sure whether i got your question.

Do youwant to show the for example c folder and user can drag and drop the files there.

if you use htmlb:file upload and click on the browse button it would show the file open dialog for browsing local directory to choose file. is this what youw ant?

Regards

Raja

Former Member
0 Kudos

As Raja wrote - use htmlb:fileupload for client side upload, either you use it in your table by iterator or popup an upload-window.

If you're now meaning the download feature from inside the sapgui you are on the wrong way.

You're supposed to store the data to server-disk (as Eddy wrote) or in database as you are on the server. And by the way - its not a FTP-Fileserver - but a SAP WebAS - I think.

Regards

Regards

Message was edited by: Sebastian Behne

athavanraja
Active Contributor
0 Kudos

let me understand.

you have a tableview and within the tableview on of the columns you want to provide a functionality where by the user can upload a document for that record? and the uploaded document should be stored in the server side.

lets say the tablview shows purch order number and item number. each po number/line item number combination user can upload document. (multiple users loading documents to the same ponumber / line item number?)

just provide a htmlb:fileupload for each row using tableview iterator and the user can click the browse button which would open up the file open dialog and the user can select local files from his PC. in the oninputprocessing collect the file contect (explained in the weblog i have mentioned by Brian) which is in binary format and store the same as suggested by Eddy.

Am i right in understanding your requirement. what problem you are having in implementing this .

Regards

Raja

Answers (1)

Answers (1)

eddy_declercq
Active Contributor
0 Kudos

Hi,

First of all make sure that you've specified enctype="multipart/form-data"

in you form tag.

in the oninputprocessing you need to do something like this:

data: entity TYPE REF TO if_http_entity,num_multiparts TYPE i,

i TYPE i VALUE 1,

name type string,

file TYPE xstring.

num_multiparts = request->num_multiparts( ).

WHILE i <= num_multiparts.

entity = request->get_multipart( i ).

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

IF NOT name IS INITIAL.

file = entity->get_data( ).

ENDIF.

i = i + 1.

ENDWHILE.

The result is a variable called file with an X string. Your table should support that type of course.

Eddy