Skip to Content
0

How to add pdf file to attachment tab in GRC request through code dynamically?

Mar 02, 2017 at 06:16 AM

256

avatar image
Former Member

I have a requirement to read a inbound mail from offline approval in the SAP system, convert to PDF and attach it to the GRC request in the attachment tab. I did debugging but couldn't find a definite solution for it. Attachment related information are stored in the tables GRPCCHKO and GRPCPHIO.

It involves multiple GUID creation. So is there any class method or FM to attach the file dynamically? Any solution for this?

Thanks in advance.

Vishnu Prakash K.

10 |10000 characters needed characters left characters exceeded

Hi Vishnu,

Did you find any solution for this requirement?

Regards

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Jan 23 at 10:23 AM
0

I resolved it myself and it is working fine now. I created a z-smartform and passed my data to z-smartform, then converted z-smartform xtring to OTF and finally passed the OTF data to the GRC class method grc_cl_grfn_doc_collection->_insert_document_to_storage. This is a private method. So took a copy of it and changed the visibility.

I have used the below code.

Data : io_obj TYPE REF TO zgrc_cl_grfn_doc_collection,

ls_document TYPE grfnd_s_runtime_docs,
ls_appl_obj_key TYPE grfnd_application_object_key,
lo_oref TYPE REF TO cx_uuid_error.

" Create new GUID
TRY.
lv_my_guid = cl_system_uuid=>create_uuid_x16_static( ).
CATCH cx_uuid_error INTO lo_oref.
lv_my_guid = '0'.
ENDTRY.

" Get the device type
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language = sy-langu
i_application = c_sapdef
IMPORTING
e_devtype = lv_e_devtype.

st_output_options-tdprinter = lv_e_devtype. " Device type
st_control_parameters-no_dialog = c_x.
st_control_parameters-getotf = c_x.

*.................GET SMARTFORM FUNCTION MODULE NAME.................*
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_form_name " Smartform name
IMPORTING
fm_name = lv_fm_name " FM name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
*...........................CALL SMARTFORM............................*
lv_from = lv_email. " From mail ID
" Read "To" mail ID
READ TABLE it_recipients INTO wa_recipients INDEX 1.
IF sy-subrc IS INITIAL.
lv_to = wa_recipients. " To Mail ID
TRANSLATE lv_to TO UPPER CASE.
ENDIF.
lv_sub = ls_mail_attr-subject. " Subject line

" Call smartform and pass data
" Get OTF data
CALL FUNCTION lv_fm_name
EXPORTING
control_parameters = st_control_parameters
output_options = st_output_options
gv_from = lv_from
gv_to = lv_to
gv_sub = lv_sub
IMPORTING
document_output_info = ls_doc_info
job_output_info = ls_job_info
job_output_options = ls_job_opt
TABLES
it_body = lt_lines
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

*.................GET XSTRING FROM OTF DATA.................*
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = c_pdf
max_linewidth = 132
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_xstr " XSTRING
TABLES
otf = ls_job_info-otfdata
lines = it_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.

ls_appl_obj_key-ref_object_type = c_accreq.
ls_appl_obj_key-ref_object_id = lv_reqid. " Req ID

" Create object for storing the pdf data
CREATE OBJECT io_obj
EXPORTING
i_appl_obj_key = ls_appl_obj_key.

ls_document-kpro_key-class_id = c_classid. " Document class
ls_document-kpro_key-document_guid = lv_my_guid. " New GUID
ls_document-kpro_header-loio_owning_appl_object-ref_object_type = c_accreq.
ls_document-kpro_header-loio_owning_appl_object-ref_object_id = lv_reqid. " Request ID
ls_document-kpro_header-phio_owning_appl_object-ref_object_type = c_accreq.
ls_document-kpro_header-phio_owning_appl_object-ref_object_id = lv_reqid.

GET TIME STAMP FIELD lv_timestamp. " Get timestamp

ls_document-kpro_header-create_timestamp = lv_timestamp.
ls_document-kpro_header-create_user = lv_approver. " Approver user ID
ls_document-kpro_header-modify_timestamp = lv_timestamp.
ls_document-kpro_header-modify_user = lv_approver.
ls_document-kpro_header-orig_language = sy-langu. " Language
ls_document-kpro_content-raw_content = lv_xstr. " xstring data
ls_document-kpro_content-content_type = c_mimetyp. " PDF mimetype
ls_document-runtime_change-no_change = c_n. " New file

IF lv_action EQ c_a.
ls_document-kpro_header-description = c_desc_a. " File description
ls_document-kpro_content-upload_name = c_fapprv. " File name
ELSE.
ls_document-kpro_header-description = c_desc_r. " File description
ls_document-kpro_content-upload_name = c_frejec. " File name
ENDIF.

lv_syname = sy-uname.
sy-uname = lv_approver.
TRY.
" Insert the file to the request
CALL METHOD io_obj->_insert_document_to_storage
EXPORTING
is_document = ls_document
i_override_task_id = ' '.
CATCH cx_grfn_documents.
ENDTRY.
sy-uname = lv_syname.
ENDIF.

Regards,

Vishnu

Share
10 |10000 characters needed characters left characters exceeded
Maria Erdey-Gruz
Jan 11 at 03:01 PM
0

SAP cannot convert a file to PDF, for this you need ADS or any other service that converts to PDF.

Regarding File upload, see following documentation: FileUpload

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Maria,

If we get the pdf then how to attach this PDF to GRC request programmatically.

Is there any FM/Method for the same?

Regards

0

Check out this older blog post, I think it gives a really deatiles step-by-step desription on how you could do it:

Upload and Download files in Webdynpro ABAP

0