cancel
Showing results for 
Search instead for 
Did you mean: 

Problem attach document with the FileUpload UI.

apachon
Participant
0 Kudos

I am trying to attach a document to a CRM Notification from application Web Dynpro for ABAP, I have build a FM that includes the method

cl_crm_documents=>create_with_file

When I test the FM from SE37 transaction, I am able to attach a file from a local disk succesfully. But If I call this FM from Web Dynpro, trying to do the same operation, document cannot attach to notification and Method returns the following error: “Error loading file ” (Class of message CRM_DOCUMENTS and number 100).

Thanks in advance.

FUNCTION z_crm_anexar_docs_inc.

*"----

-


""Interfase local

*" IMPORTING

*" VALUE(GUID) TYPE CRMT_OBJECT_GUID

*" VALUE(FILENAME) TYPE SDOK_FILNM

*" VALUE(PATH) TYPE SDOK_CHTRD OPTIONAL

*" VALUE(DESCRIPTION) TYPE STRING

*"----

-


DATA: ls_bor TYPE sibflporb,

lv_loio TYPE skwf_io,

lv_phio TYPE skwf_io,

lv_error TYPE skwf_error.

MOVE: 'BUS2000116' TO ls_bor-typeid, "aqui le pasamos el tipo de objeto que estemos tratando

'BO' TO ls_bor-catid,

guid TO ls_bor-instid.

DATA: wa_result_tab TYPE string.

DATA: result_tab TYPE STANDARD TABLE OF string.

DATA: lin TYPE i.

DATA: long_nombre TYPE i.

DATA: long_total TYPE i.

DATA: desplazamiento TYPE i.

DATA: filename_aux TYPE skwf_descr.

SPLIT filename AT '' INTO TABLE result_tab.

DESCRIBE TABLE result_tab LINES lin.

READ TABLE result_tab INDEX lin INTO wa_result_tab.

IF sy-subrc EQ 0.

long_total = STRLEN( filename ).

long_nombre = STRLEN( wa_result_tab ).

desplazamiento = long_total - long_nombre.

path = filename(desplazamiento).

filename = wa_result_tab.

filename_aux = wa_result_tab.

ENDIF.

  • aqui le pasamos el guid del documento sap crm que estemos tratando

CALL METHOD cl_crm_documents=>create_with_file

EXPORTING

  • aqui le pasamos el nombre del fichero que queremos anexar

file_name = filename

  • 'c:' "aqui le pasamos la ruta del fichero que queremos anexar

directory = path

business_object = ls_bor

IMPORTING

loio = lv_loio

phio = lv_phio

error = lv_error.

  • aqui llamamos a este método porque de lo contrario el sistema crea el anexo con el nombre que

  • le da la gana y no con el que hemos indicado en el punto anterior. por eso renombramos el fichero

CALL METHOD cl_crm_documents=>rename_object

EXPORTING

is_io = lv_loio

iv_name = filename_aux.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

  • IMPORTING

  • RETURN =

ENDFUNCTION.

Call from WDA.

CALL FUNCTION 'Z_CRM_ANEXAR_DOCS_INC'

EXPORTING

guid = guid_jarcode

  • guid = stru_importing-guid

filename = stru_importing-filename

  • PATH =

description = stru_importing-description.

ENDMETHOD.

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

mohammed_anzys
Contributor
0 Kudos

Hi Angel,

I dont think cl_crm_documents=>create_with_file will work in the Webdynpro UI as it is meant for the SAP GUI.So for file upload , use the file upload UI element provided by the WebDynpro and once you upload the data.It will be available in the attribute of the context and you could this to pass the data to other function modules.

Thanks

Anzy

apachon
Participant
0 Kudos

Hi Mohammed, thank you very much, I will look for a FM that adjusts to my necessities.

Thanks.

mohammed_anzys
Contributor
0 Kudos

Hi Angel.

You dont have to find out any new FMs , the existing ones that used in the program can be used with a minor change.Instead of the creating the document with the class.use the UI element context and get the data and process it.

Thanks

Anzy

0 Kudos

Hi Anzy,

I am also facing the simialr problem, when i tried to use it in BSP. So please can u elaborate it more, like what need to be passed to the same FM used above.

ChandraMahajan
Active Contributor
0 Kudos

Hi,

you can use below steps,

1. Create attribute file_content of type xstring and bind it to data attribute of FileUpload UI .

2.Put the button Upload next to your FileUpload UI element and write action upload.

3. in action, read the attribute file_content and pass it to below code

  • Convert XString to String

CALL METHOD cl_abap_conv_in_ce=>create

EXPORTING

input = file_content

encoding = 'UTF-8'

replacement = '?'

ignore_cerr = abap_true

RECEIVING

conv = loc_conv.

*Read the file contents

TRY.

CALL METHOD loc_conv->read

IMPORTING

data = file_content_string

CATCH cx_sy_conversion_codepage.

*-- Should ignore errors in code conversions

CATCH cx_sy_codepage_converter_init.

*-- Should ignore errors in code conversions

CATCH cx_parameter_invalid_type.

CATCH cx_parameter_invalid_range.

ENDTRY.

4. After that u may want to put the contents into internal table so use

SPLIT file_content string AT crlf INTO TABLE itstring_tab.

5. At last, fill the internal table

loop AT it_string_tab INTO wa_string.

CHECK sy-tabix GT 1 . "skip the first line

SPLIT wa_string AT ',' INTO .....

endloop.

here in my code i have splitted the contents at comma as i had .csv file . so based on file type u can split it and fill internal table.

hope this will help you.

Regards,

Chandra

(Award points if Helpful)

Former Member
0 Kudos

hi, Chandrashekhar

I get the string 'R3MATCLASS#SOGOU#SG001#点火装置#点火装置##R3MATCLASS#SOGOU#SG002#仪表#仪表' from file.

How can i split the string by 'Enter' and 'Tab'?

Thank you very much!