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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |