cancel
Showing results for 
Search instead for 
Did you mean: 

Attach documents to the Change requests

Former Member
0 Kudos

Hi Techies,

Our requirement in solution manager, CRM_DNO_MONITOR transaction, is to capture the transport request in the change request and read the list of development objects under the task and prepare a PDF document out of that and attach the same in the Document tab of Transaction data of the change request.

This has to be done when the Transport request is moved from QA System to PRD system when the user sets the user status to u201CIN PRODUCTIONu201D of the change request.

I have completed till capturing the transport request from the text in the objects tab of the change request using READ_TEXT function module, prepared the PDF document out of that.

Now I want to attach this PDF document to the Document tab of Transaction data in the change reqeust.

We found a BADI ORDER_SAVE for this.

Please suggest me how to do this.

Thanks,

Madhan. S

Accepted Solutions (0)

Answers (2)

Answers (2)

khalil_serrhini
Contributor
0 Kudos

Hello Madhan,

it is nt an easy thing to do especially cause you ll have to handle the loio (logical) and phyo(physical) document that you ll upload on a ticket.

You can take a look to form "create_doc" in include (se38) LSKWV_KWUI_DOCUMENTF01

This will definitely help you doing your upload of doc

Regards,

Khalil

Former Member
0 Kudos

Hi Friends,

Thanks for your replies.

I have created a test program with the help of "create_doc" subroutine in include LSKWV_KWUI_DOCUMENTF01. Please find below the code for the same.

*----


REPORT ztest.

CONSTANTS c_formname TYPE tdsfname VALUE 'ZTEST'.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language = v_language

i_application = 'SAPDEFAULT'

IMPORTING

e_devtype = v_e_devtype.

st_output_options-tdprinter = v_e_devtype.

st_control_parameters-no_dialog = 'X'.

st_control_parameters-getotf = 'X'.

PARAMETERS p_guid LIKE dnos_bor_key-guid.

DATA : name LIKE thead-tdname.

DATA: fm_name TYPE RS38L_FNAM.

itab_a_guid-guid = guid.

APPEND itab_a_guid.

*Get the Status of the Message

SELECT SINGLE stat FROM crm_jest INTO st

WHERE objnr = p_guid AND

inact = '' AND

stat LIKE 'E%'.

CONCATENATE p_guid '%' INTO name.

SELECT * FROM stxh INTO TABLE l_stxh WHERE tdobject = 'CRM_ORDERH' AND

tdname LIKE name AND

tdid = 'CD03' AND

tdspras = sy-langu .

  • CRMD_ORDERADM_H

IF l_stxh[] IS NOT INITIAL.

LOOP AT l_stxh.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = 'CD03'

language = sy-langu

name = l_stxh-tdname

object = 'CRM_ORDERH'

archive_handle = 0

local_cat = ' '

IMPORTING

header = header

TABLES

lines = lines.

DATA: ss LIKE tline-tdline .

READ TABLE lines .

ss = lines-tdline+0(8).

IF ss = 'Requests'.

td_name-d2 = lines-tdline+10(10).

APPEND td_name.

exit.

ENDIF.

CLEAR: lines, td_name.

ENDLOOP.

ENDIF.

DELETE ADJACENT DUPLICATES FROM td_name COMPARING d2.

IF NOT td_name[] IS INITIAL.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language = v_language

i_application = 'SAPDEFAULT'

IMPORTING

e_devtype = v_e_devtype.

st_output_options-tdprinter = v_e_devtype.

st_control_parameters-no_dialog = 'X'.

st_control_parameters-getotf = 'X'.

.................GET SMARTFORM FUNCTION MODULE NAME.................

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'YSPOOL_REQUEST'

IMPORTING

FM_NAME = fm_name .

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION fm_name"'/1BCDWB/SF00000041'

EXPORTING

CONTROL_PARAMETERS = st_control_parameters

OUTPUT_OPTIONS = st_output_options

lv_trkorr = td_name-d2

IMPORTING

document_output_info = st_document_output_info

job_output_info = st_job_output_info

job_output_options = st_job_output_options

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = v_bin_filesize

TABLES

otf = st_job_output_info-otfdata

doctab_archive = it_docs

lines = it_lines

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

select single object_id from crmd_orderadm_h into object_id where guid = p_guid.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = object_id

IMPORTING

OUTPUT = object_id

.

........................GET THE FILE NAME TO STORE....................

CONCATENATE object_id '.pdf' INTO v_name.

create object g_terminology.

dyn_relative_url = v_name.

  • find attachment object

IF g_folder IS INITIAL.

  • attach either to package OR folder, not both

ELSEIF NOT dyn_relative_url IS INITIAL.

  • check if folder may have this name

CALL FUNCTION 'SKWF_NMSPC_URL_EXISTENCE_CHECK'

EXPORTING

url_part = dyn_relative_url

folder = g_folder

IMPORTING

x_exists = l_x_exists.

IF NOT l_x_exists IS INITIAL.

CALL METHOD g_terminology->get_msg_data

EXPORTING

p_msg = g_terminology->c_msg_name_not_unique

IMPORTING

p_msg_id = p_error-id

p_msg_no = p_error-no.

p_error-type = 'E'.

ENDIF.

ENDIF.

CHECK p_error IS INITIAL.

  • append properties

DEFINE append_property.

if not cl_kwui_utilities=>property_is_modelled(

p_class = &1

p_property = &3 ) is initial.

l_property-name = &3.

l_property-value = &4.

append l_property to &2.

endif.

END-OF-DEFINITION.

append_property dyn_doc_class l_phio_properties

skwfc_prop_description dyn_description.

append_property dyn_doc_class l_phio_properties

skwfc_prop_relative_url dyn_relative_url.

append_property dyn_doc_class l_phio_properties

skwfc_prop_language DYN_LANG.

append_property dyn_log_doc_class l_loio_properties

skwfc_prop_description dyn_description.

append_property dyn_log_doc_class l_loio_properties

skwfc_prop_orig_language DYN_LANG.

append_property dyn_log_doc_class l_loio_properties

skwfc_prop_relative_url dyn_relative_url.

  • retrieve auxilliary phio properties

IF NOT g_phio_attr_control IS INITIAL

AND NOT g_phio_aux_attrs[] IS INITIAL.

  • check validity

CALL METHOD g_phio_attr_control->validate_props

IMPORTING

bad_property = l_bad_property.

IF NOT l_bad_property IS INITIAL.

g_dyn_tabs-pressed_tab = c_dyn_tabs-tab2.

RETURN.

ENDIF.

CALL METHOD g_phio_attr_control->get_modified_props

IMPORTING

inserted_props = l_modified_props

deleted_props = l_deleted_props.

LOOP AT l_modified_props INTO l_objprop.

l_property-name = l_objprop-name.

l_property-value = l_objprop-value.

APPEND l_property TO l_phio_properties.

ENDLOOP.

ENDIF.

  • retrieve auxilliary loio properties

CLEAR: l_modified_props[], l_deleted_props[].

IF NOT g_loio_attr_control IS INITIAL

AND NOT g_loio_aux_attrs[] IS INITIAL.

  • check validity

CALL METHOD g_loio_attr_control->validate_props

IMPORTING

bad_property = l_bad_property.

CALL METHOD g_loio_attr_control->get_modified_props

IMPORTING

inserted_props = l_modified_props

deleted_props = l_deleted_props.

LOOP AT l_modified_props INTO l_objprop.

l_property-name = l_objprop-name.

l_property-value = l_objprop-value.

APPEND l_property TO l_loio_properties.

ENDLOOP.

ENDIF.

  • create the document itself

CALL FUNCTION 'SKWF_LOIO_WITH_PHIO_CREATE'

EXPORTING

loio_class = dyn_log_doc_class

phio_class = dyn_doc_class

parentpos = g_parentpos

IMPORTING

error = p_error

phio = g_new_phio

loio = g_new_loio

TABLES

loio_properties = l_loio_properties

phio_properties = l_phio_properties.

IF p_error IS INITIAL.

G_FILENAME = v_name.

IF not g_filename IS INITIAL.

  • use imported document

l_filename = g_filename.

  • check p_error is initial.

  • component name will be extracted from filename and technical name

PERFORM file_get_basename USING l_filename

CHANGING l_basename

l_extension.

DATA: i_dru type i.

DESCRIBE FIELD dyn_relative_url LENGTH i_dru IN CHARACTER MODE.

IF dyn_relative_url(i_dru) NE l_basename(i_dru) AND

not dyn_relative_url is initial.

PERFORM file_get_basename USING dyn_relative_url

CHANGING l_url_basename

l_url_extension.

l_basename = l_url_basename.

ENDIF.

IF l_extension IS INITIAL.

l_comp_name = l_basename.

ELSE.

CONCATENATE l_basename '.' l_extension INTO l_comp_name.

ENDIF.

  • load content from local host

l_fn = l_filename.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_name "l_fn

filetype = 'BIN' "#EC NOTEXT

IMPORTING

filelength = v_bin_filesize "l_filesize

TABLES

data_tab = l_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

OTHERS = 8.

  • error in non-queued mode

IF sy-subrc <> 0.

  • skwfd_m_make_err p_error skwfd_e_sdok_load_error.

APPEND g_new_loio TO l_ios.

CALL FUNCTION 'SKWF_IOS_DELETE'

EXPORTING

x_delete_children = skwfc_yes

TABLES

ios = l_ios.

CLEAR l_ios.

RETURN.

ENDIF.

CALL METHOD cl_gui_cfw=>flush

EXCEPTIONS

OTHERS = 1.

  • error in queued mode

IF sy-subrc <> 0.

  • skwfd_m_make_err p_error skwfd_e_sdok_load_error.

APPEND g_new_loio TO l_ios.

CALL FUNCTION 'SKWF_IOS_DELETE'

EXPORTING

x_delete_children = skwfc_yes

TABLES

ios = l_ios.

CLEAR l_ios.

RETURN.

ENDIF.

CALL FUNCTION 'SKWF_MIMETYPE_OF_FILE_GET'

EXPORTING

FILENAME = g_filename

X_USE_LOCAL_REGISTRY = ''

IMPORTING

MIMETYPE = l_mimetype.

dyn_mimetype = l_mimetype.

IF NOT p_error IS INITIAL.

APPEND g_new_loio TO l_ios.

CALL FUNCTION 'SKWF_IOS_DELETE'

EXPORTING

x_delete_children = skwfc_yes

TABLES

ios = l_ios.

CLEAR l_ios.

ENDIF.

ENDIF. "filename not initial

ENDIF. "loio_phio created

  • send event

CALL METHOD cl_kwui_events=>raise_event_kwui_objs_changed

EXPORTING

io = g_new_phio.

&----


cleanup_and_terminate -
&

IF NOT g_phio_attr_control IS INITIAL.

CALL METHOD g_phio_attr_control->free.

FREE g_phio_attr_control.

ENDIF.

IF NOT g_loio_attr_control IS INITIAL.

CALL METHOD g_loio_attr_control->free.

FREE g_loio_attr_control.

ENDIF.

v_name1 = v_name.

if g_parentpos is INITIAL.

G_PARENTPOS-TYPE = '02'.

g_parentpos-PACKAGE_ID = g_package_id.

endif.

CALL FUNCTION 'CRM_KW_DOC_IMPORT_NEW'

EXPORTING

package_id = g_package_id

PARENTPOS = g_parentpos

IMPORT_FILE = v_name1

PHIO_CLASS = dyn_doc_class

TERMINOLOGY = g_terminology

IMPORTING

NEW_PHIO = g_new_phio

NEW_LOIO = g_new_loio

TABLES

PHIO_PROPERTIES = l_phio_properties

LOIO_PROPERTIES = l_loio_properties .

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

FORM file_get_basename USING p_filename

CHANGING p_basename TYPE skwf_filnm

p_extension TYPE skwf_filnm.

DATA: l_filename TYPE skwf_filnm,

l_parts TYPE TABLE OF sdok_filnm,

l_part TYPE sdok_filnm,

l_i TYPE i.

CLEAR: p_basename, p_extension.

CHECK NOT p_filename IS INITIAL.

l_filename = p_filename.

  • normalize filename

TRANSLATE l_filename USING '/\'.

SPLIT l_filename AT '\' INTO TABLE l_parts.

DESCRIBE TABLE l_parts LINES l_i.

READ TABLE l_parts INTO l_part INDEX l_i.

CLEAR l_parts[].

SPLIT l_part AT '.' INTO TABLE l_parts.

DESCRIBE TABLE l_parts LINES l_i.

IF l_i > 1.

READ TABLE l_parts INTO p_extension INDEX l_i.

l_i = l_i - 1.

READ TABLE l_parts INTO p_basename INDEX 1.

LOOP AT l_parts INTO l_part FROM 2 TO l_i.

CONCATENATE p_basename '.' l_part INTO p_basename.

ENDLOOP.

ELSE.

CLEAR p_extension.

p_basename = l_part.

ENDIF.

ENDFORM. " file_get_basename

*----


Now I want to determine the value for g_package_id. I tried debugging the standard transaction CRM_DNO_MONITOR. But before the method EXECUTE_FUNCTION of class cl_crm_documents is getting called, the value for package id is determined in the variable M_PACKAGE_ID.

I dont know how is the package id determined.

The above program works fine till the function module CRM_KW_DOC_IMPORT_NEW. It fails in this function module call with the empty package id.

Former Member
0 Kudos

Hi All,

I have fixed this requirement using the function module CRM_ICSS_UPLOAD_SR_ATTACHMENT.

Thanks for all your support.

Madhan.

aabida_majeed
Participant
0 Kudos

Hi could I know where exactly are these documents stored physically for each ticket and how we can obtain them. I would also like to know if they available in a table ?

Thanks.

Aru
Participant
0 Kudos

Hi guys

I am also having similar requirement like this , need to attach the document with the CR which uploading the change request

is there any function modules to attach a document to the change request

Regards

Arumugam

Former Member
0 Kudos

Hi,

please check class cl_crm_documents, method create_with_table.

Your change request has to be delivered in input parameter business_object.

Hope this helps,

Christoph