‎2012 Feb 09 4:32 PM
Hi experts,
I need to copy an attached document from an financial invoice to another financial invoice. I've been surfing the net and found that I can achieve this by using FM BINARY_RELATION_CREATE. But I'm not getting any success. Can you help me?
This is the code I'm using, obviously the program will not be used just for one case, this is just a test code with an existing invoice in my system.
INCLUDE: <cntn01>.
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: lt_connections TYPE TABLE OF bdn_con,
lwa_connections TYPE bdn_con,
system TYPE logsys.
DATA: objectid TYPE bapiborid.
DATA: lt_rellist TYPE TABLE OF bapirellk,
lwa_rellist TYPE bapirellk.
DATA: lo_is_object_a TYPE borident.
DATA: lo_is_object_b TYPE borident.
Relationship
DATA: p_reltyp LIKE breltyp-reltype.
DATA: p_botype LIKE borident-objtype.
DATA: lv_message_key TYPE ty_message_key.
DATA: lo_message TYPE swc_object.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
own_logical_system = system
EXCEPTIONS
own_logical_system_not_defined = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
objectid-objkey = '52000001512011'. "This is the original invoice
objectid-objtype = 'BUS2081'.
objectid-logsys = system.
CALL FUNCTION 'BAPI_REL_GETRELATIONS'
EXPORTING
objectid = objectid
relation = 'ATTA'
recursionlevel = 1
TABLES
listofrelations = lt_rellist.
READ TABLE lt_rellist INTO lwa_rellist INDEX 1.
lv_message_key = lwa_rellist-objkey_b.
swc_create_object lo_message 'MESSAGE' lv_message_key.
swc_refresh_object lo_message.
swc_get_object_key lo_message lv_message_key.
p_reltyp = 'ATTA'.
lo_is_object_a-objkey = '52000001512011'. "This is the original invoice
lo_is_object_a-objtype = 'BUS2081'.
lo_is_object_a-logsys = system.
lo_is_object_b-objkey = '52000001482011'. "This is the destination invoice
lo_is_object_b-objtype = 'MESSAGE'.
*lo_is_object_b-objtype = 'BUS2081'.
lo_is_object_b-logsys = system.
CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
EXPORTING
obj_rolea = lo_is_object_a
obj_roleb = lo_is_object_b
relationtype = p_reltyp
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Any help will be appreciated.
Thanks!!
Carles
‎2012 Feb 09 10:20 PM
Please use the code tag.
You're getting objectid, but you're not using it anywhere in the code. See [this blog|http://friendlyabaper.blogspot.com/2008/07/oh-my-gos.html], for example of GOS attachment creation. You don't need all the steps, but it explains in general how it works. Hopefully this will make it more clear.
‎2012 Feb 09 10:20 PM
Please use the code tag.
You're getting objectid, but you're not using it anywhere in the code. See [this blog|http://friendlyabaper.blogspot.com/2008/07/oh-my-gos.html], for example of GOS attachment creation. You don't need all the steps, but it explains in general how it works. Hopefully this will make it more clear.
‎2012 Feb 13 11:32 AM
Thanks Jelena,
your link was very helpfull in finding the solution to my problem.
10 points awarded!
Carles