Functionality to attach documents in task list and print documents from PM order
In this blog post we will learn how to attach documents in task list in plant maintenance and print those documents automatically while printing the PM order.
Attachments will be added in task list and while creating PM order those attachments will flow to PM order level automatically. This results in reduced manual error and eliminate duplication of work. This will make the process efficient and will save time.
Attach document in the task list:
(Below steps can be achieved via BASIS and Customizing work, no ABAP coding needed)
- Below Business functions should be switched on
- Files will be stored in SAP Document Management (DMS)
- These objects should be activated in customizing for PMPLKO object (PMPLKO is the document type for PM order)
- Refer to Appendix of OSS note 1821916 for customizing steps.
Below are some referral links :
Print attached documents from IW32 transaction:
Implement BADI WORKORDER_UPDATE method AT_SAVE
- This printing functionality won’t work in PRINT PREVIEW
- As print is done from Menu bar and it doesn’t bring any system command, this functionality should be restricted from other transactions.
- Determine Documents for a PM Order
- Determine detailed data of document
- Open detailed document for printing purpose
- This document will be saved in temp folder of computer and this file can be deleted from temp folder
METHOD if_ex_workorder_update~at_save. * This method is called while saving PM order TYPES: BEGIN OF t_order, documenttype TYPE bapi_doc_keys-documenttype, documentnumber TYPE bapi_doc_keys-documentnumber, documentversion TYPE bapi_doc_keys-documentversion, documentpart TYPE bapi_doc_keys-documentpart, END OF t_order. DATA: ls_order TYPE t_order, ls_files TYPE cvapi_doc_file, ls_comp TYPE cvapi_doc_comp, gt_order TYPE STANDARD TABLE OF t_order, gt_files TYPE STANDARD TABLE OF cvapi_doc_file, gt_comp TYPE STANDARD TABLE OF cvapi_doc_comp, lv_string TYPE string, lv_objky TYPE bapi_doc_drad-objectkey, lv_filename TYPE draw-filep, lt_file_table TYPE STANDARD TABLE OF file_table, ls_file_table TYPE file_table, lv_file TYPE string, lv_rc TYPE i. * Since print from MENU bar does not bring a Sy-ucomm code => Block other transaction codes IF sy-tcode = 'IW32' OR sy-tcode = 'IW33' OR sy-tcode = 'IW3D'. IF sy-ucomm NE 'BU' " BU is the OK code for save. AND sy-ucomm NE 'YES' " YES is the code for Release+Save AND sy-ucomm NE 'WEIT' " WEIT is order technically completion status AND sy-ucomm NE 'BABS' " BABS is order business completion status AND sy-ucomm NE 'SAVX' " Save and Do confirmation Button" on screen AND sy-ucomm NE 'SPER'. " Lock order lv_string = is_header_dialog-objnr. DATA(lv_count) = strlen( lv_string ). lv_count = lv_count - 2. lv_objky = lv_string+2(lv_count). * Determine documents for that PM order CALL FUNCTION 'BAPI_DOCUMENT_GETOBJECTDOCS' EXPORTING objecttype = 'PMAUFK' objectkey = lv_objky TABLES documentlist = gt_order. LOOP AT gt_order INTO ls_order. * Determine detailed data of each document CALL FUNCTION 'CVAPI_DOC_GETDETAIL' EXPORTING pf_dokar = ls_order-documenttype pf_doknr = ls_order-documentnumber pf_dokvr = ls_order-documentversion pf_doktl = ls_order-documentpart TABLES pt_files = gt_files EXCEPTIONS not_found = 1 no_auth = 2 error = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. LOOP AT gt_files INTO ls_files. * Open document for printing purpose CALL FUNCTION 'CVAPI_DOC_VIEW' EXPORTING pf_dokar = ls_order-documenttype pf_doknr = ls_order-documentnumber pf_dokvr = ls_order-documentversion pf_doktl = ls_order-documentpart pf_apptp = '3' " Print-3 Display-1 and Change-2 ps_file = ls_files IMPORTING pfx_file = lv_filename EXCEPTIONS error = 1 not_found = 2 no_auth = 3 no_original = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. ls_file_table-filename = lv_filename. APPEND ls_file_table TO lt_file_table. CLEAR ls_file_table. ENDIF. ENDLOOP. ENDLOOP. IF lt_file_table IS NOT INITIAL. LOOP AT lt_file_table INTO ls_file_table. lv_file = ls_file_table-filename. * “delete the earlier downloaded files CALL METHOD cl_gui_frontend_services=>file_delete EXPORTING filename = lv_file CHANGING rc = lv_rc EXCEPTIONS file_delete_failed = 1 cntl_error = 2 error_no_gui = 3 file_not_found = 4 access_denied = 5 unknown_error = 6 not_supported_by_gui = 7 wrong_parameter = 8 OTHERS = 9. CLEAR: lv_rc. ENDLOOP. ENDIF. ENDIF. ENDIF. ENDMETHOD.
- Attach documents in equipment – Transaction IA02
Add attachments in Documents tab.
Attachments can be viewed in Documents tab.
- After creating new PM order from IW31 transaction, these attached documents will be visible in Additional Data tab.
- Take print of order from Menu bar of transaction IW32.
Manually attachments can be attached to task list, which will flow to PM order level automatically. This makes this process more efficient and less time consumed.