on 06-28-2007 3:34 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.