04-09-2008 10:12 PM
Hi all,
I have PDF files in application server.My requirement is to read these PDF
files and send it as a PDF attachement to some receipients.Do anyone know
how to read PDF files from application server.thanks in advance.
04-09-2008 11:35 PM
Not really any different from reading 'any' other file from application server, just use OPEN DATASET but this time in BINARY MODE.
04-10-2008 6:08 PM
Hi,
even if I read the files from application server nad store it in an internal table,how do i send it as a pdf attachment.??In the fm 'SO_DOCUMENT_SEND_API1'
the tables parameter contents_bin (maximum length per line s only 255...) but the pdf file on the application server will be more than that??? could you please help???
04-10-2008 6:15 PM
Yes, if you use open dataset with that structure you need to use a loop until the file is completed
Your code needs to look like this
open dataset dsn for input in binary mode.
do.
read dataset dsn into contents_bin-line.
if sy-subrc ne 0.
exit.
endif.
append contents_bin.
enddo.
close dataset dsn.
Edited by: Ramiro Escamilla on Apr 10, 2008 7:16 PM
04-10-2008 6:37 PM
Aakash,
You are right.
As, SOLISTI1 is off length 255 characters, you can not have more than 255 character width in attachment doc, if you use SO_NEW_DOCUMENT_ATT_SEND_API1.
However, there is a way out. You need to use Business Communication Service. Class CL_BCS provides a way to do that.
Check the demo program BCS_EXAMPLE_5.
G@urav.
04-10-2008 7:06 PM
Hi,
yeah u r right..I tried this for populating my internal table and i used this internal table
in FM 'SO_DOCUMENT_SEND_API1' . As expected ,I got an attachement as pdf file but
when i tried opening the pdf document,i got a pop up saying
'there was an error opening this document .The file is damaged and could not be repaired'.
how to fix this??Pls help.thanks much for ur reply.
04-10-2008 7:10 PM
hi akash this is the problem with the file name only....
some times /tmp will give error so choose another directory and test it ...i think it will work..
regards,
venkat.
04-10-2008 7:28 PM
No venkat,
I tried doing that..it is not working..am getting the same error.
04-10-2008 7:41 PM
I've done this for you... enjoy.
DATA: send_request TYPE REF TO cl_bcs.
DATA: text TYPE bcsy_text.
DATA: binary_content TYPE solix_tab.
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO cl_sapuser_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
START-OF-SELECTION.
PERFORM main.
*---------------------------------------------------------------------*
* FORM main *
*---------------------------------------------------------------------*
FORM main.
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document from internal table with text
APPEND 'Hello world!' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = 'test created by Gaurav' ).
DATA: file TYPE string VALUE '\\yourfile_in_application_server.pdf'.
data : wa_bin type SOLIX.
FIELD-SYMBOLS <hex_container> TYPE x.
open dataset file for input in binary mode.
DO.
ASSIGN wa_bin TO <hex_container> CASTING.
READ DATASET file INTO <hex_container>.
IF sy-subrc = 0.
append wa_bin to binary_content.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET file.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = 'My attachment'
i_att_content_hex = binary_content.
* add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
recipient = cl_cam_address_bcs=>create_internet_address(
'email address' ).
* add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IF sent_to_all = 'X'.
WRITE text-003.
ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
WRITE: 'Fehler aufgetreten.'(001).
WRITE: 'Fehlertyp:'(002), bcs_exception->error_type.
EXIT.
ENDTRY.
ENDFORM. "main
04-10-2008 8:08 PM
hi gaurav,
am getting the same error as before...no luck..
there was an error opening this document .the file is damaged and could not be repaired.
04-10-2008 8:22 PM
I think you need to specify the file size in order to work
Try with this FM to see if you can get the file size IWB_KXF_CALC_FILESIZE, if the table can't be converted, I think a good idea is to copy the routine is only 6 lines after all
04-10-2008 8:33 PM
I've executed this code, and it is working for me...
G@urav.
04-10-2008 8:46 PM
then may be the file which i hav in the application server as pdf is not correct???
04-10-2008 8:52 PM
Yes.. it can be the reason..
Try accessing that file directly.
G@urav.
04-11-2008 3:00 PM
hi gaurav,
can u tell me how u uploaded the PDF into application server...is it thr CG3Y??
04-11-2008 3:54 PM
CG3Y is to get file from application server... use CG3Z instead.
G@urav.
04-28-2008 4:05 PM
hi gaurav,
i hav a text file in application server.The demo pgm works fine for a pdf file in application server.
But am not able to send the text fie as pdf attachment.i tried opening the file in application server
with open dataset in text mode and then used the demo pgm..i even tried reading in binary mode but it is not working.Pls help me on this.
thanks,
aakash.
04-28-2008 5:01 PM
Have you tried passing 'TXT' to parameter i_attachment_type of
method add_attachment?
Can you provide the code u r using?
G@urav.
04-28-2008 6:07 PM
HI,
if i give 'TXT' as attachment type, how will i get a pdf attachment?? i have used the same code as in the demo example....also do u know how to read a group of files from a specific directory??
like say for eg i want all the filenames in a specific directory??
Thanks,
aakash.
04-28-2008 7:15 PM
Okay..
I got u wrong in that part.. i thought u r not able to send TXT attachment.
we have 'TMP_GUI_DIRECTORY_LIST_FILES' FM for presentation server. Not sure about application server.
G@urav.