Você está na página 1de 24

21/02/2011

SAP Community Network Blogs

Blogs

Generic object services (GOS) - in Background


Ram Manohar Tiwari Business Card Company: Logica Posted on Oct. 10, 2005 10:43 AM in ABAP
Just kidding ;-)

Subscribe Print Permalink Share

I saw a few un-answered questions on SDN on how to attach documents and URLs with the Business Objects, in background and then it should appear in GOS attachment list. So I am trying to understand the basics inside GOS. [Those un-answered question are years old so I am not sure if GOS is obsolete & now it is only used in Waldorf ;-) ] However, I did manage to write a program using the inside- logic of GOS, to attach Notes and URLs in background. [ Wow...finally I discovered that the earth is flat & it's standstill ;-)...any doubts.. ] Anyway ...here we go.. Attaching documents to Business Objects in background / providing a custom GOS like functionality for BSPs: [ Actually, I pretend that I know BSPs just because I have some experience with JSPs/HTML and..ABAP is...well no... Its not my mother tongue ;-). So I confidently used to pass suggestions about BSPs as long as I don't have to write it by myself. ] The Problem: Since GOS can only be used with SAPGui Front-end ( OK..may be with ITS as well) and only in foreground, mass-attachment of documents (in background) cant be handled with GOS. However, the basic applications (Classes & Methods), used in GOS, can be utilized to create a custom program for this purpose. Use: Since this new program will have the ability to run in background, irrespective of front-end, the same code can also be utilized to provide a GOS like facility in BSPs or while developing an upload program for attaching documents/URLs to Business Objects, in background. Inside GOS: Basically, inside the application, main business object and attachment, both are treated as Business Objects and then a link is maintained between both the object instances. The relationship type, while maintaining the link, describes whether the attached object is a URL or a file attachment, note and so on. However, while the main business object, to which you are trying to attach the document / URL is already known e.g. for Purchase order the Object type ('BUS2012 )is known and instance (?) exists in database but the instance for the attachment has to be created first before the linking. Attachment can be a URL / a Note / a File and so you need to first upload (data as well in case of file) the attahcment info, and in the process also get a business object instance generated of BO type MESSAGE. The program The program-processing will have following steps: Upload the File to be attached or in case of URL just get the URL name. In case of mass upload, the input can be read from a datafile on application server, having info (e.g. URL / File Path ) against the Business Object key ( e.g. Purchase Order Number ). Create an instance of BO type MESSAGE using BO Method MESSAGE.Create. In case you are not comfortable with BO macros, simply call the main FM used within. The important part here is to pass the document type e.g. URL, EXT (for external files), and contents of file as well the file type ( e.g. TXT, PDF ) in case of File attachments. Here the document type can be derived from the relationship type of the link. Now, the attachment is created in database as a MESSAGE and instance is known. Well refer to this as object_b and main Business Object as objet_a. Now, maintain the link. Check the attached documents through GOS toolbar Purchase Orders. Sample Code Attachment List, using main business objects transaction e.g. ME23N for

*---------------------------------------------------------------------* * Report Z_RMTIWARI_ATTACH_DOC_TO_BO *---------------------------------------------------------------------* * Written By : Ram Manohar Tiwari * 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. * Need to check if we can also use FM * 'SO_DOC_INSERT_WITH_ORIG_API1' or SO_OBJECT_INSERT rather * than using Message.Create method. *---------------------------------------------------------------------* REPORT Z_RMTIWARI_ATTACH_DOC_TO_BO * Include for BO macros INCLUDE : <cntn01>. * Load class. CLASS CL_BINARY_RELATION definition load. .

www.sdn.sap.com/irj/scn/weblogs?blo

1/24

21/02/2011
CLASS CL_OBL_OBJECT definition load.

SAP Community Network Blogs

PARAMETERS: * Object_a P_BOTYPE LIKE obl_s_pbor-typeid DEFAULT 'ZFRIENDS', " e.g. 'BUS2012' P_BO_ID LIKE OBL_S_PBOR-INSTID DEFAULT '00007', " Key e.g. PO No. * Object_b P_DOCTY LIKE obl_s_pbor-typeid DEFAULT 'MESSAGE' NO-DISPLAY, P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'URL' NO-DISPLAY, Relationship P_RELTYP LIKE mdoblrel-reltype DEFAULT 'URL'. 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'. P_MSGTYP = 'EXT'. * Not implemented as yet...exit EXIT. 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' 'Title'. 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. * 'DocumentContent' is a multi-line element ( itab ). * 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 File attachments WHEN 'EXT'.

www.sdn.sap.com/irj/scn/weblogs?blo

2/24

21/02/2011
* * *

SAP Community Network Blogs

Upload the file contents using open dataset in lt_doc_content . Some conversion ( Compress ) might be required. Not sure at this point ENDCASE. swc_set_element LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT. swc_call_method LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.

* Refresh to get the reference of create 'MESSAGE' object for attachment swc_refresh_object LO_MESSAGE. * 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. LO_IS_OBJECT_A-INSTID = P_BO_ID. LO_IS_OBJECT_A-TYPEID = P_BOTYPE. LO_IS_OBJECT_A-CATID = 'BO'. * Create attachment BO object_b data: LO_IS_OBJECT_B type SIBFLPORB. LO_IS_OBJECT_B-INSTID = LV_MESSAGE_KEY. LO_IS_OBJECT_B-TYPEID = P_DOCTY. LO_IS_OBJECT_B-CATID = 'BO'. *TRY. CALL METHOD CL_BINARY_RELATION=>CREATE_LINK EXPORTING IS_OBJECT_A = LO_IS_OBJECT_A * IP_LOGSYS_A = IS_OBJECT_B = LO_IS_OBJECT_B * IP_LOGSYS_B = IP_RELTYPE = P_RELTYP * IP_PROPNAM = * I_PROPERTY = * IMPORTING * EP_LINK_ID = * EO_PROPERTY = . *CATCH CX_OBL_PARAMETER_ERROR . *CATCH CX_OBL_MODEL_ERROR . *CATCH CX_OBL_INTERNAL_ERROR . *ENDTRY. * Check if everything OK...who cares!! commit work.

Ram Manohar Tiwari is a SAP Principal Consultant with Logica, UK.

Comment on this weblog Showing messages 1 through 27 of 27. Titles Only GOS attachment find 2010-12-15 13:25:26 ahmet sevil Business Card [Reply] Hi, I would like to find the attachment of a GOS(Generic Object Service) but I will not view attachment. Main Topics Oldest First

Is there a function module like this?

CALL FUNCTION '.....'

www.sdn.sap.com/irj/scn/weblogs?blo

3/24

21/02/2011
.... Exporting attachmet = true / false ...

SAP Community Network Blogs

If there is attachment, I will give it icon in the ALV report.

Thanks, best regards. To move the attachment stored in GOS 2009-09-16 09:02:52 Prabavathi Kalaimani Business Card [Reply] Hi, I have attachment stored in sales order using GOS. I have a requirement to read the attachment and move it to an external file path. Please help me regarding this issue.

Thanks Praba

Saved my day 2009-01-22 02:29:24 Henrik Binggl Business Card [Reply] Excellent - I was looking for a way to create external URLs for different objects for ages! Thank's a lot! BR Henrik Saved my day 2009-01-22 04:09:59 Ram Manohar Tiwari Business Card [Reply] just in case you face the 255 char limit issue the code below will help..never tested it but I think it should work. data l_url_id type so_url. l_url_id = "assign the url id > 255 char

WHEN 'URL'. while not l_url_id is initial. concatenate '&KEY&' l_url_id(250) into LT_DOC_CONTENT. append LT_DOC_CONTENT. shift l_url_id left by 250 places. endwhile.

don't forget to replace the line below

swc_set_element LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT.

with swc_set_table LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT.

www.sdn.sap.com/irj/scn/weblogs?blo

4/24

21/02/2011
cheers, Ram

SAP Community Network Blogs

attaching URLs more than 255 characters 2008-01-22 09:08:43 Pushkarinee Date Business Card [Reply] Hello, Is it possible to attach URL more than 255 in length ? ...I tried but it doesn't seem to work ..I will be very thankful if you have any idea about it

Thanks Pushkarinee attaching URLs more than 255 characters 2008-01-25 05:11:11 vikram patil Business Card [Reply] Hi, I am also facing the same problem. Please update me if u have some solutions.

thanks, Vikram Uploading pictures / images JPG 2007-10-30 09:40:30 Anoop Dosi Business Card [Reply] Hi Guys, I need to upload JPG images as attachment from presentation server using this program. Could you please help me in that. Thanks, Anoop Uploading pictures / images JPG 2007-11-02 03:25:19 Anoop Dosi Business Card [Reply] Hi guys, sorted out the problem. This program was working fine in foreground also and like many others, I also faced the problem at the time of opening attachment it was saying file corrupted. I tried the ways which other used but those were not working in my case. My problem is been sorted out by this way. Just thought of sharing so that in future other guys can give the try to this solution if attachment doesn't open. First change in program: I used structure SOLIX * Binary contents DATA : lt_doc TYPE STANDARD TABLE OF solix WITH HEADER LINE. Second Change: file from application server and doctype is the file extension. SPLIT lf_fname AT '.' INTO xfname xdoctype. TRANSLATE xdoctype TO UPPER CASE. swc_set_element lt_message_container 'DOCUMENTTYPE' xdoctype. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = lf_fname

www.sdn.sap.com/irj/scn/weblogs?blo

5/24

21/02/2011
filetype = 'BIN' IMPORTING filelength = length TABLES data_tab = lt_doc.

SAP Community Network Blogs

Third change: Instead of "DocumentContent" used "Content_hex" method parameter

swc_set_table lt_message_container 'Content_Hex' lt_doc.

And with this it worked fine for BMP JPG PDF and DOC all type of attachment. Thanks, Anoop GOS 2008-10-08 23:02:38 ramanan rs Business Card [Reply] Hi Anoop, I am working on attaching a file to nomination header in TSW. The code given by you is attaching the file to the header and am able to see it in the list of objects. But when i try to open the file from the list of objects the file is empty. The file which i am uploading is with the extension 'mht'. Do i need to make any conversion before uploading? Pls help.. Uploading pictures / images JPG 2008-04-02 07:35:33 Subba Krishna Business Card [Reply] Hello Anoop, i have the same requirement to upload gif on Local PCto invoice documents. could you please send me the latest code.

Thanks, Subba Uploading pictures / images JPG 2007-12-21 22:58:56 Dadarao Padghane Business Card [Reply] Hi Anoop, I was trying to upload the PDF file. I was able to saw the PDF file after reffering the code by you along with Manoj . But the problem i am not ableto dis the attachment. Can you pls. guide what might be the problem?

thanks, Dadarao Please help me for get attachment content from r/3 2006-08-01 11:17:20 srushti srushti Business Card [Reply] Steps Followed to Add attachment in Web dynpro Java + R/3 Code from web dynpro application passing file content as "xtring" parameter to RFC then 1)Convert Xstring to bin using SCMS_XSTRING_TO_BINARY 2)BINARY_RELATION_CREATE Create relations as attachment to network object

www.sdn.sap.com/irj/scn/weblogs?blo

6/24

21/02/2011

SAP Community Network Blogs

This part of upload file works fine .This is by refreing you block !!!!!!!! ++++++++++++++++++++++++++++++++++++++++++++++++ Problem is when we do get attachment file contents get corrupted. 1) CL_BINARY_RELATION=>READ_LINKS 2) SO_DOCUMENT_READ_API1 gives document data 3) convert document data using SCMS_BINARY_TO_XSTRING 4) pass that xstring as file data to front end

While getting data file format gets corrupt . Is there any other way i can read attachment ? Is any step missing here in reading attachments? Plz Guide me... 2006-07-09 21:28:22 Seema Chand Business Card [Reply] Hello Mr Ram Manohar Tiwari, Actually i went through ur Blog in SDN named as 'GOS'(47)... Iam using that code for the attachment... Iam getting an output something likeFOLTP FOL FOLYR 25 FOLNO 000000000004 DOCTP EXT DOCYR 31 DOCNO 000000000075 link id C5E5FBEDCB90B4488A7BF3C4EB870E95 THIS IS THE LINK... IN WHICH TABLE DOES THIS LINK GETS STORED??? So that i can have a link between the document attachment and the business object??? also wht should b the approach if i use a Z-Business Object??? Or u can even tell me the name of the Function Module through which i can relate them??? Thank u so much!!! waiting... Seema Chand. U can also E-mail me at seema.chand@vikalpsolutions.com Plz Guide me... 2006-08-08 02:41:56 Bhavani Somaraju LA Business Card [Reply] Hi Seema, You can create an attachment by using Function modules also, Check this ocde below, it worked fine and I have done it for Warranty claim business object. You can do this for any other business object.

Business Object is : BUS2222

Import parameters

DEFAULT_FILENAME : Any name for your file.

www.sdn.sap.com/irj/scn/weblogs?blo

7/24

21/02/2011

SAP Community Network Blogs

FILETYPE : Type of the file cane be ppt, doc. Pdf , txt etc PATH_AND_FILE : Exact path like c:\text.txt TAR_FOL : This is user folder can be like this 'FOL25000000000004' CLAIMNO : Claim No UPDATE_FLAG : Always Null can be removed LOGSYSTEM : Logical System

Tables : has nothing to do here, that is for internal purpose

function zgos_so_create_attachment . *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(DEFAULT_FILENAME) LIKE RLGRAP-FILENAME DEFAULT SPACE *" VALUE(FILETYPE) LIKE RLGRAP-FILETYPE DEFAULT 'DOC' *" VALUE(PATH_AND_FILE) LIKE RLGRAP-FILENAME DEFAULT SPACE *" VALUE(TAR_FOL) LIKE SOFDK STRUCTURE SOFDK DEFAULT *" 'FOL25000000000004' *" VALUE(CLAIMNO) LIKE PNWTYH-CLMNO *" VALUE(UPDATE_FLAG) LIKE SONV-FLAG OPTIONAL *" VALUE(LOGSYSTEM) LIKE BORIDENT-LOGSYS DEFAULT 'DV3200' *" EXPORTING *" VALUE(FILELENGTH) LIKE SOXWD-DOC_LENGTH *" VALUE(F_CANCELLED) LIKE SONV-FLAG *" VALUE(ACT_FILETYPE) LIKE RLGRAP-FILETYPE *" VALUE(ACT_FILENAME) LIKE RLGRAP-FILENAME *" VALUE(ACT_OBJTYPE) LIKE SOODK-OBJTP *" VALUE(FILE_PUT_TO_KPRO) LIKE SONV-FLAG *" TABLES *" OBJECTCONT STRUCTURE SOLI OPTIONAL *" EXCEPTIONS *" FILE_READ_ERROR *" INVALID_TYPE *" X_ERROR *" OBJECT_TYPE_NOT_ALLOWED *" KPRO_INSERT_ERROR *" SUCCESS_MESSAGE *" LOGSYS_NOTDEFINED *" OBJECT_INSERT_ERROR *"---------------------------------------------------------------------**===================================================================== * Program Name : ZGOS_SO_CREATE_ATTACHMENT * * Version : 1.00 * * Author : S L A Bhavani * * Company : Infotech Enterprises Ltd, Hyderabad * * Date Written : 08/03/2004

www.sdn.sap.com/irj/scn/weblogs?blo

8/24

21/02/2011

SAP Community Network Blogs

* Purpose : Create attachment to warranty claim object. * : Attachment can be any type (TXT, Doc etc) * * Input : File Name, File Type, Path an File Name,Claim No * *---------------------------------------------------------------------

******--------------decalre constants ---------------------**********

constants: c_objnam(7) value 'MESSAGE', " for attachment type c_reltype(4) value 'ATTA', " relation type c_objtype(3) value 'EXT', " attachment object type c_busobjtype(7) value 'BUS2222', "Business object type c_tarfol(17) value 'FOL25000000000004', c_objla(2) value 'EN'.

******--------------End decalre constants ------------------**********

******--------------decalre variables ------------------**********

data: command_line like rlgrap-filename, "this is to get the path trunc_length type i, " file lenght cancelled, "flag to know whther cancelled the operation stripped_name like rlgrap-filename, "final name of the file file_path like rlgrap-filename. " total file path **** KPro variables data: filesize like sood-objlen, sizelimit like sood-objlen, loio_object like sdokobject, phio_object like sdokobject, new_object_id_phio like sdokobject, put_to_kpro like sonv-flag, context like sdokpropty occurs 0, existing_kpro_doc like sonv-flag, content_lines like sy-tabix.

data screentype(30) type c.

*--------------decalre internal tables-----------------**********

*------------- USED IN SO OBJECT INSERT----------------********** data: objhead like soli occurs 0 with header line.

data: folder_id_api1 like soobjinfi1-object_id, doc_insert_api1 like sodocchgi1,

www.sdn.sap.com/irj/scn/weblogs?blo

9/24

21/02/2011
document_type like soodk-objtp, document_info like sofolenti1.

SAP Community Network Blogs

data: object_hd_change like sood1, object_type like soodk-objtp, objpara like selc occurs 0 with header line, objparb like soop1 occurs 0 with header line. data: objcont like soli occurs 1 with header line, document_id like tar_fol. . *-----used in create binary relation commit------**********

data: v_pnguid like pnwtyh-pnguid. data: v_objtype like borident-objtype. data: obj_rolea like borident occurs 0 with header line, obj_roleb like borident occurs 0 with header line. ******-----used in create binary relation commit------**********

******-----Function Module calls----------------------**********

act_filename = path_and_file. if not act_filename is initial. * path and file is already known act_filetype = filetype. * commit work. * wait up to 5 seconds. ** get file extension from file name perform so_split_file_and_extension using act_filename stripped_name act_objtype. * commit work. * wait up to 5 seconds. * * check (and change) objtype and filetype perform check_object_type tables objcont using act_objtype act_filetype trunc_length. * commit work. * wait up to 5 seconds. * * Decide if a new document should be created describe table objectcont lines content_lines. if content_lines ne 0. call function 'SO_KPRO_DATA_FROM_OBJCONT_GET' importing loio_object = loio_object tables objcont = objectcont context = context

www.sdn.sap.com/irj/scn/weblogs?blo

10/24

21/02/2011
exceptions missing_kpro_data = 1 others = 2. if sy-subrc = 0. existing_kpro_doc = on. else. existing_kpro_doc = off. endif. else. existing_kpro_doc = off. endif. if existing_kpro_doc = off. * * Create new document (in KPro or DB)

SAP Community Network Blogs

* Decide about KPro "It's on the PC so it's an external document call function 'SO_KPRO_DECIDE' exporting objtp = c_objtype importing put_into_kpro = put_to_kpro. if put_to_kpro = on. * commit work. * wait up to 5 seconds. *.

* * Put file into KPro perform loio_content_insert(saplso25) using act_filename act_filetype loio_object filesize rcode. if rcode ne 0. if rcode = 8000. f_cancelled = on. exit. endif. raise kpro_insert_error. endif. *-- Export file size filelength = filesize. *-- Export extct file_put_to_kpro = on. * commit work. * wait up to 5 seconds. * *-- Put new LOIO id to OBJCONT call function 'SO_KPRO_DATA_INTO_OBJCONT_PUT' exporting loio_object = loio_object tables objcont = objcont.

www.sdn.sap.com/irj/scn/weblogs?blo

11/24

21/02/2011
else.

SAP Community Network Blogs

*-- Put document into database in classical manner

endif. if act_filetype = 'TRU'. act_filetype = 'ASC'. endif.

else. endif. else. *-- If cancelled, UPLOAD will return cancel = 'x'. if not cancelled is initial. cancelled = on. endif. f_cancelled = cancelled. endif. commit work. * if update_flag ne 'X'. *-- Insert object into Sap Object Definition Database and create *-- document as neighbor.

*-- Put new LOIO id to OBJCONT refresh objcont. append loio_object to objcont. object_type = c_objtype.

*-- Document attributes clear object_hd_change. *-- IT IS ATTACHMENT ALWAYS SO.. OBJTYPE = MESSAGE object_hd_change-objnam = c_objnam. concatenate file_path sy-datum sy-uzeit into object_hd_change-objdes separated by space. object_hd_change-objla = c_objla. object_hd_change-objsns = 'O'. *-- DETERMINE FILE EXTENSION BASED ON THE FILE TYEP. object_hd_change-file_ext = filetype. object_hd_change-extct = 'K'.

object_hd_change-objlen = filesize. object_hd_change-objdes = default_filename.

*** Retrieve the root target folder call function 'SO_FOLDER_ROOT_ID_GET' exporting owner = sy-uname region = 'B' importing folder_id = tar_fol.

www.sdn.sap.com/irj/scn/weblogs?blo

12/24

21/02/2011
. if sy-subrc <> 0.

SAP Community Network Blogs

* * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. if tar_fol = '' . tar_fol = c_tarfol. endif.

call function 'SO_OBJECT_INSERT' exporting folder_id = tar_fol object_hd_change = object_hd_change object_type = object_type owner = sy-uname importing object_id = document_id tables objcont = objcont objhead = objhead objpara = objpara objparb = objparb exceptions active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 dl_name_exist = 4 folder_not_exist = 5 folder_no_authorization = 6 object_type_not_exist = 7 operation_no_authorization = 8 owner_not_exist = 9 parameter_error = 10 substitute_not_active = 11 substitute_not_defined = 12 system_failure = 13 x_error = 14 others = 15. if sy-subrc <> 0. raise object_insert_error. else.

v_objtype = c_busobjtype. *-- get the application object id from the claim no. select single pnguid from pnwtyh into v_pnguid where clmno = claimno and ( oldcn = claimno or oldcn = '' ). *-- Preapre application object role obj_rolea-objtype = v_objtype.

www.sdn.sap.com/irj/scn/weblogs?blo

13/24

21/02/2011
obj_rolea-objkey = v_pnguid.

SAP Community Network Blogs

concatenate tar_fol document_id into obj_roleb-objkey. obj_roleb-objtype = c_objnam. "MESSAGE

*-- Get Logical system from claint call function 'OWN_LOGICAL_SYSTEM_GET' importing own_logical_system = logsystem exceptions own_logical_system_not_defined = 1 others = 2. if sy-subrc <> 0. raise logsys_notdefined.

endif.

obj_rolea-logsys = logsystem. append obj_rolea.

*-- preapare SAp Office object role. obj_roleb-logsys = logsystem. " DV3200 append obj_roleb. **-- create binary relation for application object and sap office object call function 'BINARY_RELATION_CREATE_COMMIT' exporting obj_rolea = obj_rolea obj_roleb = obj_roleb relationtype = c_reltype.

endif.

* endif. "Update flag endfunction. RE : Plz Guide me... 2006-07-10 09:30:27 Ram Manohar Tiwari Business Card [Reply] Please go through my answers in comments section including my other weblog https://weblogs.sdn.sap.com/pub/wlg/3399 You should use the FMs/Methods for getting the relations but just for info, check out the table SRGBTBREL.

Cheers, Ram RE : Plz Guide me... 2006-07-11 06:39:15 Seema Chand Business Card [Reply] Hi again, Actually i tried almost everything but nothing worked dont knw wht approach should i take???

www.sdn.sap.com/irj/scn/weblogs?blo

14/24

21/02/2011

SAP Community Network Blogs


well here is my code jus let me knw if u can help me out and ya i also wanted to knw wht if i want to work with Z-Business Objects???

TABLES ZREL_KEY. INCLUDE : <CNTN01>. CLASS CL_BINARY_RELATION DEFINITION LOAD. CLASS CL_OBL_OBJECT DEFINITION LOAD. DATA: EP_LINK_ID LIKE ZREL_KEY-LINKID, P_FILE TYPE STRING. PARAMETERS: P_BOTYPE LIKE OBL_S_PBOR-TYPEID DEFAULT 'BUS2032', "e.g. 'BUS2012' P_BO_ID LIKE OBL_S_PBOR-INSTID DEFAULT '0000002000', "Key e.g. PO No P_DOCTY LIKE OBL_S_PBOR-TYPEID DEFAULT 'MESSAGE' NO-DISPLAY, P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'URL' NO-DISPLAY, P_RELTYP LIKE MDOBLREL-RELTYPE DEFAULT 'ATTA'.

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.

P_DOCTY = 'MESSAGE'. CASE P_RELTYP. WHEN 'URL'. P_MSGTYP = 'URL'. WHEN 'NOTE' OR 'PNOT'. P_MSGTYP = 'RAW'. WHEN 'ATTA'. P_MSGTYP = 'EXT'. WHEN OTHERS. EXIT. ENDCASE.

SWC_CREATE_OBJECT LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY. SWC_CONTAINER LT_MESSAGE_CONTAINER. SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' 'Title'. SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' 'E'.

www.sdn.sap.com/irj/scn/weblogs?blo

15/24

21/02/2011

SAP Community Network Blogs


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. CASE P_MSGTYP. WHEN 'URL'. LT_DOC_CONTENT = '&KEY&http://www.rmtiwari.com' . APPEND LT_DOC_CONTENT. WHEN 'RAW'. LT_DOC_CONTENT = 'Hi How r u?' . APPEND LT_DOC_CONTENT. WHEN 'EXT'. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING MASK = ',All Files,*.*.' TITLE = 'Attachment' IMPORTING FILENAME = P_FILE EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = P_FILE TABLES DATA_TAB = LT_DOC_CONTENT.

IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDCASE.

*SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT. SWC_SET_TABLE LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT. SWC_CALL_METHOD LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER. SWC_REFRESH_OBJECT LO_MESSAGE. SWC_GET_OBJECT_KEY LO_MESSAGE LV_MESSAGE_KEY. DATA: LO_IS_OBJECT_A TYPE SIBFLPORB. LO_IS_OBJECT_A-INSTID = P_BO_ID. LO_IS_OBJECT_A-TYPEID = P_BOTYPE. LO_IS_OBJECT_A-CATID = 'BO'. DATA: LO_IS_OBJECT_B TYPE SIBFLPORB.

www.sdn.sap.com/irj/scn/weblogs?blo

16/24

21/02/2011

SAP Community Network Blogs


LO_IS_OBJECT_B-INSTID = LV_MESSAGE_KEY. LO_IS_OBJECT_B-TYPEID = P_DOCTY. LO_IS_OBJECT_B-CATID = 'BO'. 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. *This is a table in which m storing links wit docno temporarily!!! ZREL_KEY-DOCNO = LV_MESSAGE_KEY-DOCNO. ZREL_KEY-LINKID = EP_LINK_ID. MODIFY ZREL_KEY. Well how can i allot rewards to the blogs??? Thanks. Seema. RE : Plz Guide me... 2006-07-11 07:23:53 Ram Manohar Tiwari Business Card [Reply] Use commit work at the end. Also this will work for Z objects as well. You can search "sap gos" in Google & Yahoo and that will help.

Cheers, Ram GOS through BAPI call (BAPI_REL) 2006-03-23 03:20:45 Tom Christiaens Hello, I have been trying to find a BAPI that can read the link between the OBJECT A (a PM notification for example) and the OBJECT B (the NOTE or URL). I have found one: BAPI_REL_GETRELATIONS Just enter in the import structure OBJECTID the following fields: - OBJKEY (e.g. 0001000009) - OBJTYPE (for PM notif BUS2038) Business Card [Reply]

The result is a internal table with the LISTOFRELATIONS where you find all the linked objects. In the same function group BAPI_REL you finbd another BAPI BAPI_REL_CREATERELATION which enables you to create a LINK.

Conclusion: The GOS is using the BINARY RELATIONSHIP framework (whatever that may be) in order to link the NOTES and URL's to the object (PM notif for example).

Instead of using the _BINARY_RELATION=>CREATE_LINK, one can use a BAPI to create a link.

I tested: - Through BAPI_REL_GETRELATIONS I got a list of notes attached to NOTIF 1

www.sdn.sap.com/irj/scn/weblogs?blo

17/24

21/02/2011

SAP Community Network Blogs

- Through BAPI_REL_CREATERELATION I could attach that same note to NOTIF 2 in background.

It worked fine...

GOS through BAPI call (BAPI_REL) 2007-07-31 05:35:49 Dharmesh Rathod Business Card [Reply] Hi TOM, When i create new attachment by reading existing attachment(BAPI_REL_GETRELATIONS ), does it create new document (BAPI_REL_CREATERELATION)on server or it just points to the existing attachment?

Regards, Dharmesh Tom Christiaens - thanks !!!!!! Now if you can only tell me ... 2007-07-20 16:30:40 David Halitsky Business Card [Reply] ... how I can take a ".bmp" stored as an onject of type "MESSAGE" in the BOR and provide it to a picture control ?????? My customer has a pressing need to have picture attachments brought into picture controls, rather than displayed in something like MS PicMgr, etc.

Anyway, thanks very much for tqaking the time to point out that wonderful BAPI. See this forum thread here:

https://forums.sdn.sap.com/thread.jspa?threadID=490827&tstart=0

for the way I'm using it ... it's a gift from the gods.

Very best regards djh GOS through BAPI call (BAPI_REL) 2006-06-01 11:48:11 Philippe Gauthier Business Card [Reply] Hello, I try to understand how is working (I have to write a specification to link in background URL to FI document).

I don't arrive to understand which or how data I have to fill into the field OBJKEY_B OBJTYPE_B RELATION

Could you help me ?

Best Regards

www.sdn.sap.com/irj/scn/weblogs?blo

18/24

21/02/2011
Philippe GOS through BAPI call (BAPI_REL) 2006-03-23 03:20:42 Tom Christiaens Hello,

SAP Community Network Blogs

Business Card [Reply]

I have been trying to find a BAPI that can read the link between the OBJECT A (a PM notification for example) and the OBJECT B (the NOTE or URL). I have found one: BAPI_REL_GETRELATIONS Just enter in the import structure OBJECTID the following fields: - OBJKEY (e.g. 0001000009) - OBJTYPE (for PM notif BUS2038)

The result is a internal table with the LISTOFRELATIONS where you find all the linked objects. In the same function group BAPI_REL you finbd another BAPI BAPI_REL_CREATERELATION which enables you to create a LINK.

Conclusion: The GOS is using the BINARY RELATIONSHIP framework (whatever that may be) in order to link the NOTES and URL's to the object (PM notif for example).

Instead of using the _BINARY_RELATION=>CREATE_LINK, one can use a BAPI to create a link.

I tested: - Through BAPI_REL_GETRELATIONS I got a list of notes attached to NOTIF 1 - Through BAPI_REL_CREATERELATION I could attach that same note to NOTIF 2 in background.

It worked fine...

Very helpful weblog 2005-11-04 03:57:10 Mark Briggs Business Card [Reply] We had a requirement to attach binary images to maintenance orders using a background job. I managed to use your code and it worked a treat. The only small change that was required was to change the line:

swc_set_element lt_message_container 'DocumentContent' lt_doc_content.

to

swc_set_table lt_message_container 'DocumentContent' lt_doc_content.

as 'DocumentContent' is a multiline attribute.

Thanks

www.sdn.sap.com/irj/scn/weblogs?blo

19/24

21/02/2011
Mark Briggs Very helpful weblog

SAP Community Network Blogs

2006-05-09 19:01:05 SHUI-CHIANG (RAY) Ng Business Card [Reply] I am trying to make it work by attaching to the business objects, but I have two problems, 1. The file attached does not carry the right documnet type so when I try to double click from the attachment list, I can only extract it not open the document. 2. the file attached seems to be correupted. I could not figured what I did wrong. Appreciate any help and suggestions. the following is the test program.

REPORT ZGOS_BACKGROUD . *---------------------------------------------------------------------* * 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. * Need to check if we can also use FM * 'SO_DOC_INSERT_WITH_ORIG_API1' or SO_OBJECT_INSERT rather * than using Message.Create method. *---------------------------------------------------------------------*

* Include for BO macros INCLUDE : <CNTN01>. * Load class. CLASS CL_BINARY_RELATION DEFINITION LOAD. CLASS CL_OBL_OBJECT DEFINITION LOAD.

PARAMETERS: ** Object_a P_BOTYPE LIKE OBL_S_PBOR-TYPEID DEFAULT 'BUS2080', " e.g. 'BUS2012' P_BO_ID LIKE OBL_S_PBOR-INSTID DEFAULT '000300154116', PC_FILE(128) DEFAULT '/usr/sap/tmp/lam/lamdata/test1.XLS' LOWER CASE,

* Object_b P_DOCTY LIKE BORIDENT-OBJTYPE DEFAULT 'MESSAGE' NO-DISPLAY, P_RELTYP LIKE BRELTYP-RELTYPE DEFAULT 'ATTA' NO-DISPLAY, P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'EXT' NO-DISPLAY.

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,

www.sdn.sap.com/irj/scn/weblogs?blo

20/24

21/02/2011
FORTP TYPE SO_FOR_TP, FORYR TYPE SO_FOR_YR, FORNO TYPE SO_FOR_NO, END OF TY_MESSAGE_KEY. TYPES : BEGIN OF TY_BINARY, BINARY_FIELD(255) TYPE C, END OF TY_BINARY.

SAP Community Network Blogs

DATA : LT_BINARY TYPE TABLE OF TY_BINARY WITH HEADER LINE, WA_BINARY TYPE TY_BINARY. 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. DATA: LISTOBJECT LIKE ABAPLIST OCCURS 1 WITH HEADER LINE. DATA: LV_DOC_SIZE TYPE I. DATA: FILESIZE TYPE SO_DOC_LEN. DATA: L_FILE_LINES TYPE I. DATA HELP_OBJCONT LIKE SOLI OCCURS 0 WITH HEADER LINE. DATA FILE_TYPE LIKE RLGRAP-FILETYPE. DATA ACT_FILETYPE LIKE RLGRAP-FILETYPE. DATA ACT_FILENAME LIKE RLGRAP-FILENAME. DATA H_FILENAME LIKE RLGRAP-FILENAME. DATA DOC_LENGTH LIKE SOXWD-DOC_LENGTH. DATA DEF_FILENAME(12). DATA:FILESTRING TYPE XSTRING. DATA OBJECT_HD_DISPLAY LIKE SOOD2.

START-OF-SELECTION. * 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'. P_MSGTYP = 'EXT'. WHEN OTHERS. 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' 'Ray Test title'.

www.sdn.sap.com/irj/scn/weblogs?blo

21/24

21/02/2011

SAP Community Network Blogs

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. SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'FILEEXTENSION' 'DOC'. * 'DocumentContent' is a multi-line element ( itab ).

* 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 File attachments WHEN 'EXT'. * open dataset p_fname for input in binarymode. OPEN DATASET PC_FILE FOR INPUT IN BINARY MODE. READ DATASET PC_FILE INTO FILESTRING. CLOSE DATASET PC_FILE. ENDCASE. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING BUFFER = FILESTRING * APPEND_TO_TABLE = ' ' IMPORTING OUTPUT_LENGTH = LV_DOC_SIZE TABLES BINARY_TAB = LT_BINARY . SWC_SET_TABLE LT_MESSAGE_CONTAINER 'DocumentContent' LT_BINARY. SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_DOC_SIZE. SWC_REFRESH_OBJECT LO_MESSAGE. SWC_CALL_METHOD LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER. * Refresh to get the reference of create 'MESSAGE' object for attachment * swc_refresh_object lo_message. * 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 BORIDENT. LO_IS_OBJECT_A-OBJKEY = P_BO_ID. LO_IS_OBJECT_A-OBJTYPE = P_BOTYPE.

www.sdn.sap.com/irj/scn/weblogs?blo

22/24

21/02/2011
* Create attachment BO object_b

SAP Community Network Blogs

DATA: LO_IS_OBJECT_B TYPE BORIDENT. LO_IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY. LO_IS_OBJECT_B-OBJTYPE = P_DOCTY. * *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 AND WAIT. Very helpful weblog 2006-05-09 21:36:30 Ram Manohar Tiwari Business Card [Reply] check out my other weblog.. https://weblogs.sdn.sap.com/pub/wlg/3399

Thanks, Ram Very helpful weblog 2006-03-21 08:19:28 SHUI-CHIANG (RAY) Ng Business Card [Reply] Mark, Would you be kindly enough to share your code?

Thanks,

Very helpful weblog 2005-11-06 04:17:57 Ram Manohar Tiwari Business Card [Reply] Thanks Mark. Yes..you are right, The macro swc_set_table should be used for multiline attributes ( internal tables ).

Thanks, Ram

www.sdn.sap.com/irj/scn/weblogs?blo

23/24

21/02/2011

SAP Community Network Blogs

Showing messages 1 through 27 of 27.

www.sdn.sap.com/irj/scn/weblogs?blo

24/24

Você também pode gostar