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

Attachments

pbechani
Participant
0 Likes
724

Hi

I have created an Bussiness Object that I attach a pdf file. Later on in the process I have to read that attachment and attach it to another BO.

I read the attachment from my previous BO using BAPI_REL_GETRELATIONS. The list of attachments is returned in LISTOFRELATIONS structure. I want to attach these to another BO using BAPI_REL_CREATERELATION or BINARY_RELATION_CREATE. I am not able to create an object reference to the attachments.

Below is template of my code

INCLUDE : <cntn01>.

DATA :

P_BOTYPE LIKE BORIDENT-OBJTYPE.

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,

P_MSGTYP LIKE SOFM-DOCTP,

P_DOCTY LIKE borident-OBJTYPE,

  • Relationship

P_RELTYP LIKE BRELTYP-RELTYPE.

data: LO_IS_OBJECT_A type BORIDENT.

  • Create an initial instance of BO 'MESSAGE' - to call the

  • instance-independent method 'Create'.

Data : RelList type table of BAPIRELLK,

wa_rellist type BAPIRELLK.

CALL FUNCTION 'BAPI_REL_GETRELATIONS'

EXPORTING

objectid = *here i put object ID structure of BO with attachment

  • ROLE =

RELATION = 'ATTA'

  • RECURSIONLEVEL = 1

  • IMPORTING

  • RETURN =

TABLES

LISTOFRELATIONS = rellist

.

loop at RelList into wa_rellist.

LV_MESSAGE_KEY = wa_rellist-objkey_b.

swc_create_object LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY.

  • Get Key of new object

  • swc_set_object_key LO_MESSAGE msg_key.

swc_refresh_object LO_MESSAGE.

P_BOTYPE = 'BUS2080'.

P_BO_ID = '000004000285'.

swc_get_object_key LO_MESSAGE LV_MESSAGE_KEY.

P_DOCTY = 'MESSAGE'.

LO_IS_OBJECT_A-OBJKEY = P_BO_ID.

LO_IS_OBJECT_A-OBJTYPE = P_BOTYPE.

  • 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.

call function 'BINARY_RELATION_CREATE'

EXPORTING

obj_rolea = LO_IS_OBJECT_A

obj_roleb = LO_IS_OBJECT_B

relationtype = P_RELTYP

EXCEPTIONS

others = 1.

commit work.

endloop.

Kind Regards

3 REPLIES 3
Read only

athavanraja
Active Contributor
0 Likes
551

why not copy them from one bo to another using

BDS_BUSINESSDOCUMENT_COPY

Read only

0 Likes
551

Hi Durairaj

Can you assit me no how to use BDS_BUSINESSDOCUMENT_COPY. I can't seem to find documentation for it.

Kind Regards

Read only

pbechani
Participant
0 Likes
551

Solution worked. The parameters to the functions were wrong