Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with FM BINARY_RELATION_CREATE

Former Member
0 Likes
4,308

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

1 ACCEPTED SOLUTION
Read only

Jelena_Perfiljeva
Active Contributor
2,127

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.

2 REPLIES 2
Read only

Jelena_Perfiljeva
Active Contributor
2,128

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.

Read only

0 Likes
2,127

Thanks Jelena,

your link was very helpfull in finding the solution to my problem.

10 points awarded!

Carles