Skip to Content
0
Former Member
Apr 04, 2015 at 08:59 AM

missing file name for SOFM attachment

326 Views

Hello everybody,

I "copy" from this forum below FM for upload attachments to a service notification

On Sap FM work fine , I'm able to attach and open the attachment

The issue that I have is related to an external application due to the fact that file imported have no "filename"

If I look at the attachment list from the notification, the filename column is empty, only title is fill in ( see on the screen shot that I've attach at this message )

Do you know the reason about that ?

If I import manually a file into the attachment list, filename is inside

I suppose the issue was related to a missing swc_set_element but I check inside the program RSSOOT01 used for "swc_call_method xmessage 'CREATE' imessage_container" and I don't see any other element to set related to the file name

Thanks a lot for any help

Silly

FUNCTION Z_GOS_CREATE_ATTACHMENT.

*"----------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" REFERENCE(OBJTYPE) TYPE BORIDENT-OBJTYPE

*" REFERENCE(OBJKEY) TYPE BORIDENT-OBJKEY

*" REFERENCE(FILEPATH) TYPE STRING OPTIONAL

*" REFERENCE(FILENAME) TYPE STRING OPTIONAL

*" REFERENCE(DOCTITLE) TYPE STRING OPTIONAL

*" REFERENCE(DOCTYPE) TYPE SOFM-DOCTP OPTIONAL

*" EXCEPTIONS

*" UNKNOW_ERROR

*" NO_FILE_OR_BIN

*" NO_DOC_TYPE

*"----------------------------------------------------------------------


include : <cntn01>.

constants: c_docnm type borident-objtype value 'MESSAGE',

c_reltyp type breltyp-reltype value '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 : xobject_b type borident.

data : xobject_a type borident.

data : xdoc_size type i.

data : xfile_lines type i.

data : xmessage_key type ty_message_key.

data : xmessage type swc_object.

data : idoc_content type standard table of soli-line.

data : xdoc_content type soli-line.

data : xfilenamepath type string,

filetype(10),

FILELENGTH type I,

itab TYPE TABLE OF string,

wa_itab type string.


data : xdoctitle type string.

data : xdoctype type sofm-doctp.

data : xfname type string.


split filename at '.' into xfname xdoctype.


if sy-subrc ne 0.

split filename at '.' into table itab.

loop at itab into wa_itab.

xdoctype = wa_itab.

endloop.

endif.


translate xdoctype to upper case.

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

* instance-independent method 'Create'.

swc_create_object xmessage 'MESSAGE' xmessage_key.

* define container to pass the parameter values to the method call

* in next step.

swc_container imessage_container.

* Populate container with parameters for method

if doctitle is initial.

xdoctitle = filename.

else.

xdoctitle = doctitle.

endif.

swc_set_element imessage_container 'DOCUMENTTITLE' xdoctitle.

swc_set_element imessage_container 'DOCUMENTLANGU' 'E'.

swc_set_element imessage_container 'NO_DIALOG' 'X'.

swc_set_element imessage_container 'DOCUMENTNAME' c_docnm.

swc_set_element imessage_container 'DOCUMENTTYPE' xdoctype.

concatenate filepath filename into xfilenamepath.

clear filetype.


if xdoctype = 'TXT' or xdoctype = 'CSV' or xdoctype = 'HTM' .

filetype = 'ASC'.

else.

filetype = 'BIN'.

endif.

 


CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = xfilenamepath

filetype = filetype

* HAS_FIELD_SEPARATOR = 'X'

* DAT_MODE = 'X'

* IMPORTING

* filelength = lv_len

IMPORTING

FILELENGTH = FILELENGTH

CHANGING

data_tab = idoc_content

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19.

IF sy-subrc <> 0.

gr_logger->add_symsg( ).

* RAISE EXCEPTION TYPE lcx_migration_error.

ENDIF.

* 'DocumentContent' is a multi-line element ( itab ).

swc_set_table imessage_container 'DocumentContent' idoc_content.

 

swc_set_element imessage_container 'DOCUMENTSIZE' FILELENGTH.

 

* Refresh to get the reference of create 'MESSAGE' object for attachment

swc_refresh_object xmessage.

* Create the message BO

swc_call_method xmessage 'CREATE' imessage_container.

 

 

* Get Key of new object

swc_get_object_key xmessage xmessage_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

xobject_a-objkey = objkey.

xobject_a-objtype = objtype.

* Create attachment BO object_b

xobject_b-objkey = xmessage_key.

xobject_b-objtype = c_docnm.

call function 'BINARY_RELATION_CREATE'

EXPORTING

obj_rolea = xobject_a

obj_roleb = xobject_b

relationtype = c_reltyp

EXCEPTIONS

others = 1.

if sy-subrc = 1.

* raise unknown_error.

endif.

commit work.


 


ENDFUNCTION.