Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

GOS

Hi all,

I am working on a scenario where i need to attach a file to the standard nomination header in TSW. I searched for relevant code in sdn and i got one. The code is helpful. I am able to attach the file to the header but i am facing a problem when i try to view it. When i select the file to view, it is empty. The code has logic for attaching note or url or file. I have commented the part of code for url and not.The code which i used for attaching file is as follows:

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

PARAMETERS: p_appl like rlgrap-filename.

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: PRES LIKE rlgrap-filename,

LF_NAME TYPE STRING,

length TYPE I.

DATA : LT_DOC_CONTENT type standard table of SOLIX 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 = 'MHT'.

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

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = PRES

.

LF_NAME = PRES.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lf_name

filetype = 'BIN'

IMPORTING

filelength = length

TABLES

data_tab = LT_DOC_CONTENT.

ENDCASE.

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

commit work.

Pls reply about what has to be done to view the attached file..

Tags:
Not what you were looking for? View more on this topic or Ask a question