21/02/2011
SAP Community Network Blogs
Blogs
Generic object services (GOS) - in Background
Subscribe
Ram Manohar Tiwari Business Card Company: Logica Posted on Oct. Oct. 10, 2005 10:43 10: 43 AM in ABAP in ABAP
Print Permalink Share
Just kidding ;-) I saw a f ew un-answered questions on SDN on how to at tach documents documents and a nd URLs with with the t he Business Objects, in background background and then it should appear in GOS atta chment chment list. So I am trying to understa nd the basics inside GOS. [Those un-answered question are y ears old so I a m not sure if GOS is obsolete & now it is only used in Waldorf ;-) ] However, I did manage manage to write a program using the insideinside- logic of GOS, to at tach Notes and URLs in background. background. [ Wow.. .f inally inally I discovered discovered that the earth is f lat & it's standstill standstill ;-)... ;-)... any doubts.. ] Anyway ...here we go.. Attaching documents to Business Objects in background / providing a custom GOS GOS like functionality functionality for BSPs: [ Actually, I prete nd that I know BSPs BSPs just because I have some experience with JSPs/HTM JSPs/HTML L and..ABAP and.. ABAP is.. .well no... no.. . It’s not my mother tongue t ongue ;-). So I confidently use d to pass suggest ions about BSPs as long as I don't don't have hav e to write it by myself. ] The Problem: Since GOS can only be used with SAPGui Front-end ( OK.. may be with ITS as well) well) and only in foregro und, mass-at mass-attachment tachment of documents documents (in background) can’t can’t be handled ha ndled with with GOS. However, the basic ba sic applications applications (Classes & Methods), used in GOS, can be utilized utilized to create cre ate a custom program for t his purpose. Use: Since Since this new program will will have have the abil a bility ity to run in background, background, irrespectiv e of front-end, front -end, t he same code can also be utilized to provide a GOS like like facil fa cility ity in BSPs or while deve loping loping an upload program for a ttaching tta ching documents/URLs documents/URLs to Business Object s, in background. Inside GOS: Basically, Basically, inside inside the a pplication, pplication, main business business object a nd att achment, achment, both are treated trea ted as Business Business Object s and then t hen a link is is maintained between both t he object instances. The relationship relationship type, while while maintaining maintaining the link link,, describes de scribes whether the at tached object is a URL or a file attachment, note and so on. However, while while the main business business object, t o which you are try ing to atta ch the document document / URL is already known e.g. f or Purchase order the Object t ype ('BUS2012’ )is known known and instance instance (?) exists in database but the instance f or the att achment achment has to be crea ted first bef ore the linkin linking. g. Att achment achment can be a URL / a Note Note / a File and so y ou need to f irst upload (data (data as well in in case of f ile) ile) the at tahcment tahcment info, and in the process also get a business object instance generate d of BO ty pe ‘MESSAGE’. ‘MESSAGE’. The program The program-processi program-processing ng will have following following ste ps: Upload the File to be att ached or in case of URL just get t he URL name. name. In case of mass upload, the input can be rea d from a datafile on application application serv er, having ha ving info (e.g. URL / File Path ) against the Business Object key ( e. g. Purchase O rder Number Number ). Creat e an instance of BO type ‘MESSAGE’ ‘MESSAGE’ using using BO Method MESSAGE.Crea MESSAGE.Crea te. In case you a re not comfortable with BO macros, macros, simply simply call the main main FM used within. within. The important important pa rt here is to pass t he document document type t ype e.g. e. g. URL, EXT (for ex ternal files), and contents of file as well the file type ( e. g. TXT, PDF ) in in case of File attachments. Here t he document document ty pe can be derived f rom the relationship type of the link. link. Now, the at tachment is created in database a s a ‘MESSAGE’ ‘MESSAGE’ and instance is known. known. We’ll refer to this as object_b and main main Business Business Object as objet _a. Now, maintain the link. Check the attached documents documents through GOS GOS toolbar Purchase Orders. Sample Code
Attachment Attachment List, List, using using main main business business objects’ transaction transaction e.g. ME23N for
*---------------------------------------------------------------------* * Report Z_RMTIWARI_ATTACH_DOC Z_RMTIWARI_ATTACH_DOC_TO_BO _TO_BO *---------------------------------------------------------------------* * Written By : Ram Manohar Tiwari * Function : We need to maintain links between Business Object and * the attachment.Attachme attachment.Attachment nt 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' 'SO_DOC_INSERT_WITH_ORI G_API1' or SO_OBJECT_INSERT rather * than using Message.Create method. *---------------------------------------------------------------------* REPORT Z_RMTIWARI_ATTACH_DO Z_RMTIWARI_ATTACH_DOC_TO_BO C_TO_BO * Include for BO macros INCLUDE :
. * 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
SAP Community Network Blogs definition load.
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 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 TY_MESSAGE_KEY. .
DATA : LV_MESSAGE_KEY type TY_MESSAGE_KEY TY_MESSAGE_KEY. . DATA : LO_MESSAGE type SWC_OBJECT 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 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 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 P_DOCTY. . swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' P_MSGTYP. 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 P_MSGTYP. . WHEN 'URL'. LT_DOC_CONTENT = '&KEY&http://www.rmtiwari.com' . append LT_DOC_CONTENT 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 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
Main Topics
Oldest First
GOS attachment f ind 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 atta chment.
Is there a f unction module like this?
CALL FUNCTION '.. .. .'
www.sdn.sap.com/irj/scn/weblogs?blo…
3/24
21/02/2011
SAP Community Network Blogs
.... Exporting atta chmet = true / false .. .
If there is attachment, I will give it icon in the ALV report.
Thanks, best regards. To move t he attachment stored in GOS 2009-09-16 09:02:52 Prabavathi KalaimaniBusiness Card [Reply]
Hi,
I have attachment stored in sales order using GOS. I have a requirement to rea d the attachment and move it to an ext ernal file path. Please help me regarding this issue.
Thanks Praba
Saved my day 2009-01-22 02:29:24 Henrik BingglBusiness 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 TiwariBusiness Card [Reply]
just in case y ou face the 255 char limit issue the code below will help.. never test ed it but I t hink 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 t o replace the line below
swc_set_element LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_C ONTENT.
with swc_set_table LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CO NTENT.
www.sdn.sap.com/irj/scn/weblogs?blo…
4/24
21/02/2011
SAP Community Network Blogs
cheers, Ram
atta ching 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 y ou have any idea about it
Thanks Pushkarinee attaching URLs more than 255 characters 2008-01-25 05:11:11 vikram patilBusiness 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 f rom presentation serve r using this program. Could you please he lp 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 tr ied the ways which other used but t hose were not working in my case . My problem is been sorted out by this way.
Just thought of sharing so that in future ot her guys can give the try to this solution if at tachment 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 serve r and doctype is t he file extension. SPLIT lf_fname AT '.' INTO xf name xdoctype. TRANSLATE xdocty pe 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
SAP Community Network Blogs
filetype = 'BIN' IMPORTING filelength = length TABLES data_tab = lt_doc. Third change: Instea d of "DocumentCont ent" 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 f ile to the header and am able to see it in the list of o bjects. But when i try to open t he file from the list of objects the f ile is empty. The file which i am uploading is with the ex tension 'mht'. Do i need to make any conversion bef ore 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 late st 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 aft er reff ering the code by you along with Manoj . But the problem i am not ableto dis the att achment. Can y ou pls. guide what might be the problem?
thanks, Dadarao Please help me for get at tachment content from r/3 2006-08-01 11:17:20 srushti srushti Business Ca rd [Reply]
Steps Followed to Add at tachment in Web dynpro J ava + R/3 Code from web dynpro application passing file content as "xt ring" parameter to RFC t hen 1)Convert Xstring to bin using SCMS_XSTRING_TO_BINARY 2)BINARY_RELATION_CREATE Create relations as atta chment to net work 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 att achment f ile contents get corrupted. 1) CL_BINARY_RELATION=>READ_LINKS 2) SO_DOCUMENT_READ_API1 gives document data 3) convert document dat a using SCMS_BINARY_TO_XSTRING 4) pass that xstring as file data to f ront end
While gett ing data file format gets corrupt . Is there any other way i can read att achment ? 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 hav e a link between the document at tachment and the business object??? also wht should b the approach if i use a Z-Business Object??? Or u can even t ell me the name of the Function Module through which i can relate them??? Thank u so much!!! waiting... Seema C hand. U can also E-mail me at [email protected] 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 f or y our file.
www.sdn.sap.com/irj/scn/weblogs?blo…
7/24
21/02/2011
SAP Community Network Blogs
FILETYPE : Type of the f ile 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 : Creat e attachment to warrant y claim object. * : Attachment can be any t ype (TXT, Doc etc) * * Input : File Name, File Type, Path an File Name,Claim No * *---------------------------------------------------------------------
******--------------decalre constants ---------------------**********
constants: c_objnam(7) value 'MESSAGE', " for a ttachment type c_reltype(4) value 'ATTA', " relation type c_objtype(3) value 'EXT', " attachment object ty pe c_busobjtype(7) value 'BUS2222', "Business object ty pe c_tarfol(17) value 'FOL25000000000004', c_objla(2) value 'EN'.
******--------------End decalre constants ------------------**********
******--------------decalre variables ------------------**********
data: command_line like rlgrap-filename, "this is to ge t 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-f lag, content_lines like sy-ta bix.
data screentype(30) type c.
*--------------decalre internal tables-----------------**********
*------------- USED IN SO OBJECT INSERT----------------********** data: objhead like soli occurs 0 with hea der 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
SAP Community Network Blogs
document_ty pe like soodk-objtp, document_info like sofolenti1.
data: object_hd_change like sood1, object_ty pe 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 hea der line, document_id like t ar_fol. . *-----used in creat e binary relation commit------**********
data: v_pnguid like pnwty h-pnguid. data: v_objtype like borident-objtype. data: obj_rolea like borident occurs 0 with heade r line, obj_roleb like borident occurs 0 with header line. ******-----used in creat e binary relation commit------**********
******-----Function Module calls----------------------**********
act_f ilename = path_and_file. if not act_f ilename is initial. * path and file is already known act_filetype = filetype. * commit work. * wait up to 5 seconds. ** get file ext ension from file name perform so_split_file_and_exte nsion using act_filename stripped_name act_objtype. * commit work. * wait up to 5 seconds. * * check (and change) objtype and filetype perform check_object_ty pe 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
SAP Community Network Blogs
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) * Decide about KPro "It's on the PC so it's an ex ternal 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 f ile size filelength = filesize. *-- Export extct file_put_to_kpro = on. * commit work. * wait up to 5 seconds. * *-- Put new LOIO id to OBJCO NT 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
SAP Community Network Blogs
else. *-- Put document into database in classical manner
endif. if act_f iletype = '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_f lag ne 'X'. *-- Insert object into Sap Object Definition Database and create *-- document a s neighbor.
*-- Put new LOIO id to OBJCO NT refresh objcont. append loio_object to objcont. object_type = c_objtype.
*-- Document at tributes 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 O N THE FILE TYEP. object_hd_change-file_ext = filetype. object_hd_change-extct = 'K'.
object_hd_change-objlen = f ilesize. object_hd_change-objdes = def ault_filename.
*** Retrieve the root target f older call f unction '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
SAP Community Network Blogs
. if sy-subrc <> 0. * * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. if tar_f ol = '' . tar_fol = c_tarf ol. 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_ex ist = 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 syst em_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 f rom 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
SAP Community Network Blogs
obj_rolea-objkey = v_pnguid. 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 = logsyst em exceptions own_logical_system_not_defined = 1 others = 2. if sy-subrc <> 0. raise logsys_notdefined.
endif.
obj_rolea-logsys = logsyst em. append obj_rolea.
*-- preapare SAp Office object role. obj_roleb-logsys = logsyst em. " DV3200 append obj_roleb. **-- create binary relation for application object and sap off ice 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 TiwariBusiness 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 ev erything 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 t o work with Z-Business Objects???
TABLES ZREL_KEY. INCLUDE : . 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_CO NTENT 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 t o the blogs??? Thanks. Seema. RE : Plz Guide me.. . 2006-07-11 07:23:53 Ram Manohar TiwariBusiness 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 t hat will help.
Cheers, Ram GOS through BAPI call (BAPI_REL) 2006-03-23 03:20:45 Tom Christiaens
Business Card [Reply]
Hello,
I have been try ing to find a BAPI that can rea d the link between the OBJECT A (a PM notification for ex ample) and the OBJECT B (the NOTE or URL). I hav e f ound one: BAPI_REL_GETRELATIONS Just ent er 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 f ind all the linked objects. In t he same function group BAPI_REL you finbd another BAPI BAPI_REL_CREATERELATION which enables y ou 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 creat e a link.
I tested: - Through BAPI_REL_GETRELATIONS I got a list of notes att ached 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 t hat 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 atta chment by reading existing att achment(BAPI_REL_GETRELATIONS ), does it create new document (BAPI_REL_CREATERELATION)on server or it just points to the e xisting attachment?
Regards, Dharmesh Tom Christiaens - thanks !! !!! ! Now if you can only te ll 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 hav e picture attachments brought into picture controls, rather t han displayed in something like MS PicMgr, etc.
Anyway , t hanks 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 Ca rd [Reply]
Hello,
I try to understand how is working (I have t o write a specification to link in background URL to FI document).
I don't arrive to understand which or how data I have t o fill into the f ield OBJKEY_B OBJTYPE_B RELATION
Could you help me ?
Best Regards
www.sdn.sap.com/irj/scn/weblogs?blo…
18/24
21/02/2011
SAP Community Network Blogs
Philippe GOS through BAPI call (BAPI_REL) 2006-03-23 03:20:42 Tom Christiaens
Business Card [Reply]
Hello,
I have been try ing to find a BAPI that can rea d the link between the OBJECT A (a PM notification for ex ample) and the OBJECT B (the NOTE or URL). I hav e f ound one: BAPI_REL_GETRELATIONS Just ent er 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 f ind all the linked objects. In t he same function group BAPI_REL you finbd another BAPI BAPI_REL_CREATERELATION which enables y ou 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 creat e a link.
I tested: - Through BAPI_REL_GETRELATIONS I got a list of notes att ached to NOTIF 1 - Through BAPI_REL_CREATERELATION I could attach t hat 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 t o att ach binary images to maintenance orders using a background job. I managed to use y our code and it worked a treat.
The only small change that was re quired was to change t he line:
swc_set_element lt_message_container 'DocumentContent' lt_doc_content.
to
swc_set_table lt_message_container 'DocumentCont ent' lt_doc_content.
as 'DocumentCont ent' is a multiline att ribute.
Thanks
www.sdn.sap.com/irj/scn/weblogs?blo…
19/24
21/02/2011
SAP Community Network Blogs
Mark Briggs Very helpful weblog 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 f ile att ached does not carry the right documnet ty pe so when I try t o double click from the attachment list, I can only extract it not open the document. 2. t he file attached seems to be correupted. I could not f igured what I did wrong.
Appreciate any help and suggestions. t he following is the test program.
REPORT ZGOS_BACKGROUD . *---------------------------------------------------------------------* * Function : We need to maintain links between Business Object and * the atta chment. Att achment document is basiclally a * business object of type 'MESSAGE'.In order to maintain * links, first t he att achment will be crated as Business * Object of t ype '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 : . * 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 DEFA ULT '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
SAP Community Network Blogs
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. 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 SO LI-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 Atta chment'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 pa rameter v alues to the method call * in next step. SWC_CO NTAINER 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 'F ILEEXTENSION' 'DOC'. * 'DocumentContent' is a multi-line element ( itab ).
* In case of URLs.. it should be concatenate d 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 Privat e Notes, get the dat a from files on appl * serv er or from wherever(? - re member background). WHEN 'RAW'. LT_DOC_C ONTENT = '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. W e can now * att ach 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
SAP Community Network Blogs
* Create attachment BO object_b DATA: LO_IS_OBJECT_B TYPE BORIDENT. LO_IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY. LO_IS_OBJECT_B-OBJTYPE = P_DOCTY. * *TRY. * C ALL 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 TiwariBusiness Card [Reply]
check out my ot her 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 TiwariBusiness 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