Generic object services (GOS) – in Background – Part II
This weblog is a sequel to my most successful weblog till date. [ was quoted in at least 2 Forum threads, only once by myself 😉 ]. Just trying to capitalize on it.
I tried to clarify a few points about attaching URL, Notes & documents in background using GOS basics in my earlier weblog.
Generic object services (GOS) – in Background .
However, I received a few queries from the readers who wanted the code for attaching documents in background [ Also for 4.6C ].
The code for it, might well have been discussed in the forums since my earlier weblog was published but I would like to present the code here for attaching documents like DOC, PDF, GIF etc. Last time I cheated my readers with ‘only funda but no code’ for document attachments.
The code from my earlier weblog was converted to suit 4.6C by one of my weblog readers [ Madeleine Kempka / Kempka Madeleine – I am not sure about the sequence of first & last name 🙂 ] and then I corrected a few problems with it for attaching PDF and other documents.
Points to remember:
- For file attachments: Pass the file path on application server and also choose correct message type [ P_MSGTYP ] as per the file extension[e.g. PDF,DOC etc]. P_RELTYP should be ‘ATTA’. Also file size should be calculated and passed while creating the message.
- For URLs: P_RELTYP should be ‘URL’ & P_MSGTYP will be derived as ‘URL’.
- For Notes: P_RELTYP should be ‘NOTE’ & P_MSGTYP will be derived as ‘RAW’.
Sample Code:
In case you find bugs in the code below…rememeber, it’s just a sample…real one contains too many 😉
REPORT Z_RMTIWARI_ATTACH_DOC_TO_BO_46 .*---------------------------------------------------------------------** Function : We need to maintain links between Business Object and* the attachment.Attachment document is basiclally a* business object of type 'MESSAGE'.In order to maintain* links, first the attachment will be crated as Business* Object of type 'MESSAGE' using Message.Create method.** This program can be used to attach PC documents eg. PDF* ,DOC,TXT,GIF etc. to a SAP Business Object e.g Purchase* Order etc. You should pass the correct message type* [ P_MSGTYP ] as per the file extension[e.g. PDF,DOC etc].** The code below is suitable for 4.6C+, though you might* like to use the commented code, instead, for 4.7+*---------------------------------------------------------------------** Include for BO macros INCLUDE : <cntn01>.* Load class.* CLASS CL_BINARY_RELATION definition load. PARAMETERS:* Object_a* P_BOTYPE LIKE obl_s_pbor-typeid DEFAULT 'BUS2031', " e.g. 'BUS2012'* P_BO_ID LIKE OBL_S_PBOR-INSTID DEFAULT '0002029816', P_BOTYPE LIKE borident-OBJTYPE DEFAULT 'BUS2031', " e.g. 'BUS2012' P_BO_ID LIKE borident-OBJKEY DEFAULT '0002029816', " Key e.g. PO No.* Object_b P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'PDF', P_DOCTY LIKE borident-OBJTYPE DEFAULT 'MESSAGE',* Relationship P_RELTYP LIKE BRELTYP-RELTYPE DEFAULT 'ATTA',* File Name P_FNAME like rlgrap-filename Default '/usr/data/Test.pdf'. types: BEGIN OF TY_MESSAGE_KEY, FOLTP TYPE SO_FOL_TP, FOLYR TYPE SO_FOL_YR, FOLNO TYPE SO_FOL_NO, DOCTP TYPE SO_DOC_TP, DOCYR TYPE SO_DOC_YR, DOCNO TYPE SO_DOC_NO, FORTP TYPE SO_FOR_TP, FORYR TYPE SO_FOR_YR, FORNO TYPE SO_FOR_NO, END OF TY_MESSAGE_KEY. DATA : LV_MESSAGE_KEY type TY_MESSAGE_KEY. DATA : LO_MESSAGE type SWC_OBJECT. DATA : LT_DOC_CONTENT type standard table of SOLI-LINE with header line.*----------------------------------------------------------------------** First derive the Attachment's ( MESSAGE )document type. P_DOCTY = 'MESSAGE'. CASE P_RELTYP.* In case of URls WHEN 'URL'. P_MSGTYP = 'URL'.* In case of Notes / Private Notes WHEN 'NOTE' OR 'PNOT'. P_MSGTYP = 'RAW'. WHEN 'ATTA'.* Take given parameter e.g. 'DOC', 'PDF' etc.* P_MSGTYP = 'EXT'. WHEN OTHERS.* ....exit EXIT. ENDCASE.*----------------------------------------------------------------** Create an initial instance of BO 'MESSAGE' - to call the* instance-independent method 'Create'. swc_create_object LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY.* define container to pass the parameter values to the method call* in next step. swc_container LT_MESSAGE_CONTAINER.* Populate container with parameters for method swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' 'TestDocument'. swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' 'E'. swc_set_element LT_MESSAGE_CONTAINER 'NO_DIALOG' 'X'. swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTNAME' P_DOCTY. swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' P_MSGTYP.* In case of URLs..it should be concatenated with &KEY& in the begining. CASE P_MSGTYP. WHEN 'URL'. LT_DOC_CONTENT = '&KEY&http://www.rmtiwari.com' . append LT_DOC_CONTENT.* In case of Notes or Private Notes, get the data from files on appl* server or from wherever(? - remember background). WHEN 'RAW'. LT_DOC_CONTENT = 'Hi How r u?' . append LT_DOC_CONTENT.* In case of PC File attachments WHEN OTHERS. OPEN DATASET P_FNAME FOR INPUT. IF SY-subrc EQ 0. DO. READ DATASET P_FNAME INTO LT_DOC_CONTENT. IF SY-subrc EQ 0. append LT_DOC_CONTENT. ELSE. EXIT. ENDIF. ENDDO. CLOSE DATASET P_FNAME. ENDIF. ENDCASE.* 'DocumentContent' is a multi-line element ( itab ). swc_set_table LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT.* Size is required in case of File attachments data : LV_DOC_SIZE type i. data : L_FILE_LINES type i. DESCRIBE TABLE LT_DOC_CONTENT LINES L_FILE_LINES. READ TABLE LT_DOC_CONTENT INDEX L_FILE_LINES. LV_DOC_SIZE = ( 255 * ( L_FILE_LINES - 1 ) ) + STRLEN( LT_DOC_CONTENT ). swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_DOC_SIZE .* Refresh to get the reference of create 'MESSAGE' object for attachment swc_refresh_object LO_MESSAGE. swc_call_method LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.* Get Key of new object swc_get_object_key LO_MESSAGE LV_MESSAGE_KEY.* Now we have attachment as a business object instance. We can now* attach it to our main business object instance.* Create main BO object_a* data: LO_IS_OBJECT_A type SIBFLPORB. "type SIBFLPORB is unknown, so I data: LO_IS_OBJECT_A type BORIDENT. LO_IS_OBJECT_A-OBJKEY = P_BO_ID. LO_IS_OBJECT_A-OBJTYPE = P_BOTYPE.* LO_IS_OBJECT_A-CATID = 'BO'.* Create attachment BO object_b* data: LO_IS_OBJECT_B type SIBFLPORB. "type SIBFLPORB is unknown data: LO_IS_OBJECT_B type BORIDENT. LO_IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY. LO_IS_OBJECT_B-OBJTYPE = P_DOCTY.* LO_IS_OBJECT_B-CATID = 'BO'.*TRY.*CALL METHOD CL_BINARY_RELATION=>CREATE_LINK* EXPORTING* IS_OBJECT_A = LO_IS_OBJECT_A* IS_OBJECT_B = LO_IS_OBJECT_B* IP_RELTYPE = P_RELTYP.call function 'BINARY_RELATION_CREATE' EXPORTING obj_rolea = LO_IS_OBJECT_A obj_roleb = LO_IS_OBJECT_B relationtype = P_RELTYP EXCEPTIONS others = 1.* Check if everything OK...who cares!!commit work.
I think it's due to the fact that documents having more than 255 chars are not handled.
Please try to replace the code in
WHEN OTHERS section as below [ or equivalent to upload data in a wide [ width more than 255 ] itab and then convert it to 255 width itab:
thank you, Ram, for an excellent blog. It saved me a hours of searching and trying...
But...
1. you cannot use a source structure that is longer than 1345 chars (1600-255). That is because of exception that is raised in the function module 'QCE1_CONVERT' at this place:
L_MAX = L_LENGTH_TARGET + L_LENGTH_SOURCE.
IF L_MAX > 1600.
RAISE CONVERT_NOT_POSSIBLE.
ENDIF.
2. if i use the function module GUI_UPLOAD it only works for me if the filetype is set to BIN. Otherwise the attachments get corrupted (TXT attachments as well)
3. The last question is: Is there any possibility to set the icon of the attachment to something else...for example "Word" icon for DOC attachments and so on....'cause now all of the attachments get the same icon...
thank you very much in advance
Andrey
solved it on my own...
If i use the p_msgtyp with upper case, the right icon is displayed, so, after the WS_FILENAME_GET
i do:
DATA: lv_length type i.
lv_length = strlen( p_file ) - 3.
p_msgtyp = p_file+lv_length.
TRANSLATE p_msgtyp to upper case.
Thank you again for the helpfull blog
Andrey
Does GUI_upload function call, uploads the file without damaging the file.
I tried using all filetypes, BIN, ASC, DAT,
but the files are corrputed after attachment when i tried to view it...
Do u have a code... if possible share the code...
please email me at contactjaffer@yahoo.com
we have the problem, that txt-files uploaded this way are saved as RAW documents and not as EXT, since RAW causes the txt-files to be displayed inline in SAPGUI. Is there a list of elements supportet by msg_container ?
Another problem is the missing supposed filename when downloading the files from SAPGUI ?
Thanks in advance for your hints!
Replace
P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'PDF',
with
P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'PDF' LOWER CASE ,
and pass 'txt' for this parameter instead of 'TXT'.
This problem is due to the code below in SO_DOC_INSERT_WITH_ORIG_API1
* check whther document_type is ok. If not it's a PC-bject.
PERFORM CHECK_OBJECT_TYPE(SAPFSSO3) USING DOCUMENT_TYPE
RCODE.
IF RCODE NE OK.
MOVE DOCUMENT_TYPE TO OBJECT_HD_CHANGE-FILE_EXT.
IF-IS-RAW-EXT DOCUMENT_TYPE.
* * it's a RAW document with byte count
MOVE RAW TO DOCUMENT_TYPE.
ELSE.
* * it's an Pc application object
MOVE 'EXT' TO DOCUMENT_TYPE.
endif.
ENDIF.
Can you tell something about the way around? I would also like to get attachments created with GOS out of the system.
Did you have sucess, if so could you help how you did it?
Thanks
implementing an access to GOS in this way works fine (to create new documents or attachments).
But: It seems that I´m to silly to implement a CHANGE function for existing documents (or even to get the text of an existing document).
Assuming I have a object key of an existing GOS document: Can anyone please help me in retrieving the text (or binary data) from this document or to change it?
Thank you very much for your help,
Stefan
How can you read the atatchments?TRY.<br/>CALL METHOD CL_BINARY_RELATION=>READ_LINKS<br/> EXPORTING<br/> IS_OBJECT = lo_is_object_a<br/> IP_LOGSYS =<br/>* IT_ROLE_OPTIONS =<br/> IT_RELATION_OPTIONS = lt_rel<br/>* IP_NO_BUFFER = SPACE<br/> IMPORTING<br/> ET_LINKS = lt_links<br/>* ET_ROLES =<br/> .<br/>CATCH CX_OBL_PARAMETER_ERROR .<br/>CATCH CX_OBL_INTERNAL_ERROR .<br/>CATCH CX_OBL_MODEL_ERROR .<br/>ENDTRY.<br/><br/><br/>call function 'SREL_GET_NEXT_RELATIONS'<br/> exporting<br/>* object = lo_is_object_a<br/>** ROLETYPE =<br/>* relationtype = p_reltyp<br/>** MAX_HOPS = 1<br/>** INCL_APPLRELS = ' '<br/>** EXCL_ROLES =<br/>** EXCL_RELATIONS =<br/>* tables<br/>* links = lt_links<br/>** ROLES =<br/>** APPLLINKS =<br/>* exceptions<br/>* internal_error = 1<br/>* no_logsys = 2<br/>* others = 3<br/>* .<br/>if sy-subrc <> 0.<br/><br/>endif.<br/><br/>data : lv_document_id type sofolenti1-doc_id.<br/><br/>data : lt_header type standard table of SOLISTI1 with header line,<br/> lt_content type standard table of SOLISTI1 with header line.<br/><br/>loop at lt_links into wa_links where typeid_b = 'MESSAGE'.<br/><br/>move wa_links-INSTID_B to lv_document_id.<br/><br/>CALL FUNCTION 'SO_DOCUMENT_READ_API1'<br/> EXPORTING<br/> DOCUMENT_ID = lv_document_id<br/> FILTER = 'X '<br/>* IMPORTING<br/>* DOCUMENT_DATA =<br/> TABLES<br/> OBJECT_HEADER = lt_header<br/> OBJECT_CONTENT = lt_content<br/>* OBJECT_PARA =<br/>* OBJECT_PARB =<br/>* ATTACHMENT_LIST =<br/>* RECEIVER_LIST =<br/>* CONTENTS_HEX =<br/> EXCEPTIONS<br/> DOCUMENT_ID_NOT_EXIST = 1<br/> OPERATION_NO_AUTHORIZATION = 2<br/> X_ERROR = 3<br/> OTHERS = 4<br/> .<br/>IF SY-SUBRC <> 0.<br/> MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO<br/> WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.<br/>ENDIF.<br/><br/>LOOP AT lt_header.<br/> write /: lt_header.<br/>endloop.<br/><br/>loop at lt_content.<br/> write /:lt_content.<br/>endloop.<br/><br/>endloop.<br/><br/></pre><br/>
I imagine I would need to use FM SO_DOCUMENT_DELETE_API1 to delete the document, then call CL_BINARY_RELATION=>DELETE_LINKS to remove from GOS.
But, CL_BINARY_RELATION=>DELETE_LINKS requires IS_OBJECT_B and I couldn't find that value read READ_LINKS.
Any suggestions?
You should first read the links and delete the links one by one. However, this will now delete the message ( attachment ) doc itself but only the links. <br/><br/>You can use SO_DOCUMENT_DELETE_API1 to delete the actual docs from database.<br/><br/><code><br/>REPORT Z_RMTIWARI_DELETE_GOS_ATT .<br/><br/>* Include for BO macros<br/>include : <cntn01>.<br/><br/><br/>parameters:<br/> p_botype like borident-objtype default 'BUS2012',<br/> p_bo_id like borident-objkey default '3500000503'," Key e.g. PO No.<br/> p_reltyp like breltyp-reltype default 'ATTA'.<br/><br/>data: lo_is_object_a type SIBFLPORB,<br/> lt_links type OBL_T_LINK,<br/> wa_links like line of lt_links.<br/><br/>data : lt_rel type OBL_T_RELT,<br/> wa_rel like line of lt_rel.<br/><br/>lo_is_object_a-INSTID = p_bo_id.<br/>lo_is_object_a-typeid = p_botype.<br/>lo_is_object_a-CATID = 'BO'.<br/><br/>wa_rel-sign = 'I'.<br/>wa_rel-option = 'EQ'.<br/>wa_rel-LOW = p_reltyp.<br/>append wa_rel to lt_rel.<br/><br/>TRY.<br/>CALL METHOD CL_BINARY_RELATION=>READ_LINKS<br/> EXPORTING<br/> IS_OBJECT = lo_is_object_a<br/> IP_LOGSYS =<br/>* IT_ROLE_OPTIONS =<br/> IT_RELATION_OPTIONS = lt_rel<br/>* IP_NO_BUFFER = SPACE<br/> IMPORTING<br/> ET_LINKS = lt_links<br/>* ET_ROLES =<br/> .<br/>CATCH CX_OBL_PARAMETER_ERROR .<br/>CATCH CX_OBL_INTERNAL_ERROR .<br/>CATCH CX_OBL_MODEL_ERROR .<br/>ENDTRY.<br/><br/><br/>call function 'SREL_GET_NEXT_RELATIONS'<br/> exporting<br/>* object = lo_is_object_a<br/>** ROLETYPE =<br/>* relationtype = p_reltyp<br/>** MAX_HOPS = 1<br/>** INCL_APPLRELS = ' '<br/>** EXCL_ROLES =<br/>** EXCL_RELATIONS =<br/>* tables<br/>* links = lt_links<br/>** ROLES =<br/>** APPLLINKS =<br/>* exceptions<br/>* internal_error = 1<br/>* no_logsys = 2<br/>* others = 3<br/>* .<br/>if sy-subrc <> 0.<br/><br/>endif.<br/><br/>TRY.<br/><br/>data: lo_is_object_b type SIBFLPORB,<br/> lv_reltype type OBLRELTYPE.<br/>loop at lt_links into wa_links where typeid_b = 'MESSAGE'.<br/><br/>lo_is_object_b-INSTID = wa_links-INSTID_B.<br/>lo_is_object_b-typeid = wa_links-TYPEID_B.<br/>lo_is_object_b-CATID = 'BO'.<br/><br/>lv_reltype = wa_links-RELTYPE.<br/><br/>CALL METHOD CL_BINARY_RELATION=>DELETE_LINK<br/> EXPORTING<br/> IS_OBJECT_A = lo_is_object_a<br/>* IP_LOGSYS_A =<br/> IS_OBJECT_B = lo_is_object_b<br/>* IP_LOGSYS_B =<br/> IP_RELTYPE = lv_reltype .<br/>CATCH CX_OBL_PARAMETER_ERROR .<br/>CATCH CX_OBL_INTERNAL_ERROR .<br/>CATCH CX_OBL_MODEL_ERROR .<br/>ENDTRY.<br/>commit work.<br/><br/>*CL_GOS_DOCUMENT_SERVICE-DELETE_ATTACHMENT.<br/><br/>endloop.<br/></code>
I am trying to use your program to get the list of URL links for a particular area. I was able to get the details successfully for XD03 transaction using the Customer Number and KNA1 Business Object as the input criteria. But, I am unable to get the URL list for FB02 transaction (Accounts Receivable/Lockbox details). I am passing the Document Number and I have tried different Business Objects. But, the program does not return any items. Any idea as what is the correct Business Object, etc.?
Thanks.
_________________
Naveen
You will come to know about the business object name.Further use that BO in your program.
Cheers,
Ram
Thanks...that was very helpful. I tried with BKPF and BSEG Business Objects earlier but I was giving the wrong key. I used only the Document Number whereas the actual key includes "Company Code + Document Number + Fiscal Year" and this value is stored in SRGBTBREL-INSTID_A field.
Regards,
Naveen
Thanks!
Thank you for your blog. It is very helpful. I was able to create attachment to a billing document (BO 'VBRK'). However when I go to trans VF03 and click on attachment list, I can see the attachment but when I open, I got message 'There was an error opening this document. The file is damaged and could not be repaired'.
My attatchment is a Sapscript invoice that converted to PDF file. First my file was on UNIX srvr and I was able to attach using statement OPEN file, Read, Close file similar to your code. So, when I could not view the file, I thought may be because the file was not located on the presentation server. So, I move the PDF file to PC, use FM 'GUI_UPLOAD' to load to table lt_doc_content. But I still get the same error messages when try to view the attachment. Your help is greatly appreciated.
Another questions: My final goal is to archive the whole invoice, if I create the attachment and then archive later would the attachment will be archived as well? Or do I have to do the store business document to external storate systems?
Thanks,
VT
a. If you have not read the complete line of PDF file as line-width of PDF file is more than your target itab line width.
b. If your code is not able to properly convert the itab into 255 char wide itab , required for final message creation.
Please see the comments posted in this weblog or check the PDF email-problem errors of similar kind [ in ABAP Forum ].
2.Please understand that GOS attachments are not the same as Business Documents attached using Archive-Link. Business Documents are created using CV02N transaction and are not the same as GOS attachments which are basically created as a 'MESSAGE' object [ similar to SAP mail/email ].
If you are archiving Invoice object then I am almost sure that GOS attachments will not be archived [ automatically ] along with the Invoice. However, you can possibly do the archiving of GOS documents by downloading the related MESSAGE ( atatchments ) and then deleting it from MESSAGE tables.
However, you should check and ensure that GOS is the one that you wanted to use for the purpose and not Archive-Link as I am sure Archive-Link concept will be much more sofisticated way to handle business documents.
Thanks,
Ram
I tried the code to load to lt_wide_content as you suggested but got the return code of 1 - conversin is not possible. The funny thing is that I can attach in the foreground with no problem using the same file as in background. I can even attach and view the document in foreground using the file reside in UNIX directory. But when I did in background, using the same file, I cannot view the file.<br/>I tried all doc type 'URL', 'RAW' and it was OK, only with 'PDF' that I have problem. Can you see what was wrong with the code.<br/>By the way, I am on 4.7<br/><br/>REPORT z_attach_doc_to_bo .<br/><br/>----
<br/>* Function : We need to maintain links between Business Object and<br/>* the attachment.Attachment document is basiclally a<br/>* business object of type 'MESSAGE'.In order to maintain<br/>* links, first the attachment will be crated as Business<br/>* Object of type 'MESSAGE' using Message.Create method.<br/><br/> This program can be used to attach PC documents eg. PDF<br/>* ,DOC,TXT,GIF etc. to a SAP Business Object e.g Purchase<br/>* Order etc. You should pass the correct message type<br/>* as per the file extension[e.g. PDF,DOC etc].<br/><br/> The code below is suitable for 4.6C, though you might<br/>* like to use the commented code, instead, for 4.7<br/>----
<br/>* Include for BO macros<br/>INCLUDE : <cntn01>.<br/><br/> Load class.<br/>CLASS cl_binary_relation DEFINITION LOAD.<br/><br/>PARAMETERS:<br/>* Object_a<br/> P_BOTYPE LIKE obl_s_pbor-typeid DEFAULT 'VBRK', " e.g. 'BUS2012'<br/> P_BO_ID LIKE OBL_S_PBOR-INSTID DEFAULT '0090000027',<br/>* p_botype LIKE borident-objtype DEFAULT 'VBRK', " e.g. 'BUS2012'<br/>* p_bo_id LIKE borident-objkey DEFAULT '0090000027',<br/> " Key e.g. P.O<br/>* Object_b<br/> p_msgtyp LIKE sofm-doctp DEFAULT 'PDF',<br/> p_docty LIKE borident-objtype DEFAULT 'MESSAGE',<br/><br/>* Relationship<br/> p_reltyp LIKE breltyp-reltype DEFAULT 'ATTA',<br/><br/>* File Name<br/> p_fname LIKE rlgrap-filename DEFAULT<br/> '/projects/i314/DEV/STN/PDFINV/CAS/jpotest/doc_90000021.pdf'.<br/><br/>PARAMETERS: p_unix RADIOBUTTON GROUP rad1 default 'X',<br/> p_pc RADIOBUTTON GROUP rad1.<br/><br/>TYPES: BEGIN OF ty_message_key,<br/> foltp TYPE so_fol_tp,<br/> folyr TYPE so_fol_yr,<br/> folno TYPE so_fol_no,<br/> doctp TYPE so_doc_tp,<br/> docyr TYPE so_doc_yr,<br/> docno TYPE so_doc_no,<br/> fortp TYPE so_for_tp,<br/> foryr TYPE so_for_yr,<br/> forno TYPE so_for_no,<br/> END OF ty_message_key.<br/>DATA : lv_message_key TYPE ty_message_key.<br/>DATA : lo_message TYPE swc_object.<br/>DATA : lt_doc_content TYPE STANDARD TABLE OF soli-line<br/> WITH HEADER LINE.<br/>DATA : lt_wide_content TYPE STANDARD TABLE OF dxrawdata-data<br/> WITH HEADER LINE.<br/>DATA: p_file TYPE string.<br/>----
<br/><br/>* First derive the Attachment's ( MESSAGE )document type.<br/>p_docty = 'MESSAGE'.<br/>CASE p_reltyp.<br/>* In case of URls<br/> WHEN 'URL'.<br/> p_msgtyp = 'URL'.<br/>* In case of Notes / Private Notes<br/> WHEN 'NOTE' OR 'PNOT'.<br/> p_msgtyp = 'RAW'.<br/> WHEN 'ATTA'.<br/>* Take given parameter e.g. 'DOC', 'PDF' etc.<br/>* p_msgtyp = 'PDF'.<br/> WHEN OTHERS.<br/>* ....exit<br/> EXIT.<br/>ENDCASE.<br/>----
<br/><br/>* Create an initial instance of BO 'MESSAGE' - to call the<br/>* instance-independent method 'Create'.<br/>swc_create_object lo_message 'MESSAGE' lv_message_key.<br/><br/>* define container to pass the parameter values to the method call<br/>* in next step.<br/>swc_container lt_message_container.<br/><br/>* Populate container with parameters for method<br/>swc_set_element lt_message_container 'DOCUMENTTITLE' 'VLT_TestDocument'.<br/>swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.<br/>swc_set_element lt_message_container 'NO_DIALOG' 'X'.<br/>swc_set_element lt_message_container 'DOCUMENTNAME' p_docty.<br/>swc_set_element lt_message_container 'DOCUMENTTYPE' p_msgtyp.<br/><br/>* In case of URLs..it should be concatenated with &KEY& in the begining.<br/>CASE p_msgtyp.<br/> WHEN 'URL'.<br/> lt_doc_content = '&KEY&http://www.yahoo.com' .<br/> APPEND lt_doc_content.<br/>* In case of Notes or Private Notes, get the data from files on appl<br/>* server or from wherever(? - remember background).<br/> WHEN 'RAW'.<br/> lt_doc_content = 'Hi How r u?' .<br/> APPEND lt_doc_content.<br/><br/>* In case of PC File attachments<br/> WHEN OTHERS.<br/> IF p_unix = 'X'.<br/> OPEN DATASET p_fname FOR INPUT IN BINARY MODE.<br/> IF sy-subrc EQ 0.<br/> DO.<br/> READ DATASET p_fname INTO lt_doc_content.<br/> IF sy-subrc EQ 0.<br/> APPEND lt_doc_content.<br/> ELSE.<br/> EXIT.<br/> ENDIF.<br/> ENDDO.<br/>* DO.<br/>* READ DATASET p_fname INTO lt_wide_content.<br/>* IF sy-subrc EQ 0 OR sy-index EQ 1.<br/>** Appending to 5000 wide char text itab.<br/>* APPEND lt_wide_content.<br/>* ELSE.<br/>* EXIT.<br/>* ENDIF.<br/>* ENDDO.<br/><br/> CLOSE DATASET p_fname.<br/><br/>** now convert the 5000 wide char table to 255 wide char table<br/>* call function 'QCE1_CONVERT'<br/>* tables<br/>* t_source_tab = lt_wide_content<br/>* t_target_tab = lt_doc_content<br/>* exceptions<br/>* convert_not_possible = 1<br/>* others = 2.<br/> ENDIF.<br/> ELSE.<br/> MOVE p_fname TO p_file.<br/> CALL FUNCTION 'GUI_UPLOAD'<br/> EXPORTING<br/> filename = p_file<br/> TABLES<br/> data_tab = lt_doc_content.<br/><br/> ENDIF.<br/>ENDCASE.<br/><br/><br/>* 'DocumentContent' is a multi-line element ( itab ).<br/>swc_set_table lt_message_container 'DocumentContent' lt_doc_content.<br/><br/>* Size is required in case of File attachments<br/>DATA : lv_doc_size TYPE i.<br/>DATA : l_file_lines TYPE i.<br/><br/>DESCRIBE TABLE lt_doc_content LINES l_file_lines.<br/><br/>READ TABLE lt_doc_content INDEX l_file_lines.<br/><br/>lv_doc_size = ( 255 * ( l_file_lines - 1 ) ) +<br/> STRLEN( lt_doc_content ).<br/><br/>swc_set_element lt_message_container 'DOCUMENTSIZE' lv_doc_size .<br/><br/>* Refresh to get the reference of create 'MESSAGE' object for attachment<br/>swc_refresh_object lo_message.<br/>swc_call_method lo_message 'CREATE' lt_message_container.<br/><br/>* Get Key of new object<br/>swc_get_object_key lo_message lv_message_key.<br/><br/>* Now we have attachment as a business object instance. We can now<br/>* attach it to our main business object instance.<br/><br/>* Create main BO object_a<br/>* data: LO_IS_OBJECT_A type SIBFLPORB. "type SIBFLPORB is unknown, so I<br/>DATA: lo_is_object_a TYPE borident.<br/><br/>lo_is_object_a-objkey = p_bo_id.<br/>lo_is_object_a-objtype = p_botype.<br/>LO_IS_OBJECT_A-CATID = 'BO'.<br/><br/> Create attachment BO object_b<br/>* data: LO_IS_OBJECT_B type SIBFLPORB. "type SIBFLPORB is unknown<br/>DATA: lo_is_object_b TYPE borident.<br/><br/>lo_is_object_b-objkey = lv_message_key.<br/>lo_is_object_b-objtype = p_docty.<br/>* LO_IS_OBJECT_B-CATID = 'BO'.<br/><br/>TRY.<br/>CALL METHOD CL_BINARY_RELATION=>CREATE_LINK<br/>* EXPORTING<br/>* IS_OBJECT_A = LO_IS_OBJECT_A<br/>* IS_OBJECT_B = LO_IS_OBJECT_B<br/>* IP_RELTYPE = P_RELTYP.<br/><br/>CALL FUNCTION 'BINARY_RELATION_CREATE'<br/> EXPORTING<br/> obj_rolea = lo_is_object_a<br/> obj_roleb = lo_is_object_b<br/> relationtype = p_reltyp<br/> EXCEPTIONS<br/> OTHERS = 1.<br/><br/>COMMIT WORK.<br/><br/>Thanks.<br/><br/>VT<br/>
VT
DO.
READ DATASET p_fname INTO lt_doc_content.
IF sy-subrc EQ 0.
APPEND lt_doc_content.
ELSE.
APPEND lt_doc_content. "Added to get the last line when end of file is encountered.
EXIT.
ENDIF.
Also, if you are reading in binary [ that you should ] you don't have to use any conversion for the internal table from wide to 255 rather you can directly read the file in 255 char itab. You are already doing this but just to clarify. [ No need to use lt_wide_content and any function to convert it ]
Thanks again
This is Jaffer...
I am facing a problem... in document acctachment..
To attach a file from the presentation server..
I am using GUI_upload function module to read the .doc, .pdf file..
The file is attached, but it corrupted...
My code is
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
TABLES
data_tab = lt_doc_content.
ENDCASE.
Can u just tell me what is the problem...
Can you please explain the difference between these 2 FMs?
Can you also please explain the SO_ATTACHMENT module? I am having a hard time understanding the required import/tables parameters.
Your help is greatly appreciated.
TR
Many thanks.
Luca
Many thanks.
Luca
We have recently upgraded to ERP 2005. I'm not sure if this have anyting to do with it; but I have to multiply the doc size by 2. Then it works.
My steps:
CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
swc_create_object
etcetera...
Anyway. If anyone are experiencing the same problems this might be a solution.
(problem is that file is corrupt although it is attached correctly).
A couple of years has passed since you wrote this solution.
I have a question.
It is possible to go backwards, in the opposite way?
I mean:
If I have attached (e.g. manually) a file to a PO, it is possible (using similar functions) to read that file and download it to a server ?
Thanks in advance!
This looks interesting - but where can I seen the act. documents in SAP R3 ?
If I load documents to BO VBRK (billing doc) - can I see this auto. in VF03 ? - I have tryied but can find the menu-point in VF03 to access this document - do I need som customizing first ??
Thanks
Lars
while trying to open the document in sales order screen vA03.
can u pls rectify the error?
My question is HOW to pass this data(sapscript) to LT_DOC_CONTENT.
Please suggest.
Â
How to convert PO PDF in xstring (which is in byte mode) to binary format and attaching it to ME23N ? I tried it and attached the PDF but it is corrupted coz i am not able to convert xstring to binary format successfully for getting it attached to the ME23N … please suggest how to convert it from xstring which is in byte mode ?
I followed this discussion and built the program to link PDF as attachment to VF03/FB03, I can see the attachment but when i tried to open i'm getting the error message saying 'content is not decoded correctly'.
Is anybody successfully attached PDF?
the problem which is occurred in the email is normal things but the problem arises in such way that the users cannot able to overcome the problem so they need a Yahoo customer support with the guide from them the users will able to know the steps then access the emails.