EWM PPF Trigger the existing PPF Action through Custom Program
Aim:
Same as title
Description:
An Action has been scheduled for the Handling Unit in the EWM Monitor and we need to execute it in a Custom Program without executing it from the Monitor.
What to do?
Use the below code accordingly.
Code:
*&---------------------------------------------------------------------*
*& Report ZAG_TEST_HU_PRINTING
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zag_test_hu_printing.
PARAMETERS: p_hu TYPE /scwm/huident DEFAULT '154118660000024802'.
DATA: lt_huhdr TYPE /scwm/tt_huhdr_int,
lt_protocol TYPE bal_t_logh,
lt_contexts TYPE ppftcntxts,
lo_hu_ppf TYPE REF TO /scwm/cl_hu_ppf,
lo_manager TYPE REF TO cl_manager_ppf,
lt_trigger TYPE ppfttrgor,
lv_lines TYPE i,
lv_read_lint TYPE i,
lv_oid TYPE os_guid,
lv_object TYPE REF TO object,
lv_action TYPE REF TO cl_trigger_ppf.
*--> Get HU Header
CALL FUNCTION '/SCWM/HUHEADER_READ'
EXPORTING
iv_appl = wmegc_huappl_wme
iv_huident = p_hu
iv_db_select = 'X'
IMPORTING
et_huheader = lt_huhdr
EXCEPTIONS
not_found = 1
input = 2
error = 3
deleted = 4
OTHERS = 5.
IF sy-subrc = 0.
*--> Set Global Data
CALL FUNCTION '/SCWM/PRINT_GLOBAL_DATA'
EXPORTING
iv_caller = wmegc_hu_processing.
*--> Print HU
CALL FUNCTION '/SCWM/PRINT_HU'
EXPORTING
it_huhdr = lt_huhdr
iv_caller = wmegc_hu_processing
* IV_CXT_PARTNER =
* IV_HUSTEP =
* IV_WORKCENTER =
iv_noexe = ' '
* IV_NODIALOG = 'X'
* IV_HUIDENT_O =
* IV_PMAT_O =
* IV_G_WEIGHT_O =
* IV_G_VOLUME_O =
* IV_G_CAPA_O =
* IV_LDEST =
* IV_FORM_GROUP =
* IV_LOG_PROCESS =
* IV_DOCNO =
IMPORTING
et_protocol = lt_protocol
et_contexts = lt_contexts
EXCEPTIONS
no_previous_print = 1
error_on_log_save = 2
previous_print = 3
OTHERS = 4.
IF sy-subrc = 0.
READ TABLE lt_contexts ASSIGNING FIELD-SYMBOL(<lfs_contexts>) INDEX 1.
IF sy-subrc = 0.
lo_manager = cl_manager_ppf=>get_instance( ).
CALL METHOD lo_manager->get_active_triggers
EXPORTING
it_contexts = lt_contexts
IMPORTING
et_triggers = lt_trigger.
IF lt_trigger IS NOT INITIAL.
DESCRIBE TABLE lt_trigger LINES lv_lines.
lv_read_lint = lv_lines - 1.
READ TABLE lt_trigger ASSIGNING FIELD-SYMBOL(<lfs_trigger>) INDEX lv_read_lint.
IF sy-subrc = 0.
lv_oid = <lfs_trigger>->read_guid( ).
CALL METHOD ca_trigger_ppf=>agent->if_os_ca_persistency~get_persistent_by_oid
EXPORTING
i_oid = lv_oid
RECEIVING
result = lv_object.
lv_action ?= lv_object.
TRY.
CALL METHOD lv_action->set_is_changed
EXPORTING
i_is_changed = 'X'.
CATCH cx_os_object_not_found .
ENDTRY.
CALL METHOD lv_action->execute
RECEIVING
rp_rc = DATA(lv_status)
EXCEPTIONS
empty_medium_reference = 1
empty_appl_reference = 2
locked = 3
document_is_locked = 4
inactive = 5
startcondition_not_true = 6
OTHERS = 7.
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF." HU Header Read FM
Same as title
Description:
An Action has been scheduled for the Handling Unit in the EWM Monitor and we need to execute it in a Custom Program without executing it from the Monitor.
What to do?
Use the below code accordingly.
Code:
*&---------------------------------------------------------------------*
*& Report ZAG_TEST_HU_PRINTING
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zag_test_hu_printing.
PARAMETERS: p_hu TYPE /scwm/huident DEFAULT '154118660000024802'.
DATA: lt_huhdr TYPE /scwm/tt_huhdr_int,
lt_protocol TYPE bal_t_logh,
lt_contexts TYPE ppftcntxts,
lo_hu_ppf TYPE REF TO /scwm/cl_hu_ppf,
lo_manager TYPE REF TO cl_manager_ppf,
lt_trigger TYPE ppfttrgor,
lv_lines TYPE i,
lv_read_lint TYPE i,
lv_oid TYPE os_guid,
lv_object TYPE REF TO object,
lv_action TYPE REF TO cl_trigger_ppf.
*--> Get HU Header
CALL FUNCTION '/SCWM/HUHEADER_READ'
EXPORTING
iv_appl = wmegc_huappl_wme
iv_huident = p_hu
iv_db_select = 'X'
IMPORTING
et_huheader = lt_huhdr
EXCEPTIONS
not_found = 1
input = 2
error = 3
deleted = 4
OTHERS = 5.
IF sy-subrc = 0.
*--> Set Global Data
CALL FUNCTION '/SCWM/PRINT_GLOBAL_DATA'
EXPORTING
iv_caller = wmegc_hu_processing.
*--> Print HU
CALL FUNCTION '/SCWM/PRINT_HU'
EXPORTING
it_huhdr = lt_huhdr
iv_caller = wmegc_hu_processing
* IV_CXT_PARTNER =
* IV_HUSTEP =
* IV_WORKCENTER =
iv_noexe = ' '
* IV_NODIALOG = 'X'
* IV_HUIDENT_O =
* IV_PMAT_O =
* IV_G_WEIGHT_O =
* IV_G_VOLUME_O =
* IV_G_CAPA_O =
* IV_LDEST =
* IV_FORM_GROUP =
* IV_LOG_PROCESS =
* IV_DOCNO =
IMPORTING
et_protocol = lt_protocol
et_contexts = lt_contexts
EXCEPTIONS
no_previous_print = 1
error_on_log_save = 2
previous_print = 3
OTHERS = 4.
IF sy-subrc = 0.
READ TABLE lt_contexts ASSIGNING FIELD-SYMBOL(<lfs_contexts>) INDEX 1.
IF sy-subrc = 0.
lo_manager = cl_manager_ppf=>get_instance( ).
CALL METHOD lo_manager->get_active_triggers
EXPORTING
it_contexts = lt_contexts
IMPORTING
et_triggers = lt_trigger.
IF lt_trigger IS NOT INITIAL.
DESCRIBE TABLE lt_trigger LINES lv_lines.
lv_read_lint = lv_lines - 1.
READ TABLE lt_trigger ASSIGNING FIELD-SYMBOL(<lfs_trigger>) INDEX lv_read_lint.
IF sy-subrc = 0.
lv_oid = <lfs_trigger>->read_guid( ).
CALL METHOD ca_trigger_ppf=>agent->if_os_ca_persistency~get_persistent_by_oid
EXPORTING
i_oid = lv_oid
RECEIVING
result = lv_object.
lv_action ?= lv_object.
TRY.
CALL METHOD lv_action->set_is_changed
EXPORTING
i_is_changed = 'X'.
CATCH cx_os_object_not_found .
ENDTRY.
CALL METHOD lv_action->execute
RECEIVING
rp_rc = DATA(lv_status)
EXCEPTIONS
empty_medium_reference = 1
empty_appl_reference = 2
locked = 3
document_is_locked = 4
inactive = 5
startcondition_not_true = 6
OTHERS = 7.
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF." HU Header Read FM
hello, thanks for the information, it helped to go forward with my requirement. but why is it lv_read_lint = lv_lines - 1.?
ReplyDeleteI need help with triggering the PPF by passing the printer, form, spool, number of copies etc in a container( passed from selection screen)? We do not want to call FM /SCWM/PRINT_HU.
ReplyDeleteVery good program!!! You saved me!! I just only bypass lv_read_lint = lv_lines - 1 issue doing after:
ReplyDeleteIF lv_read_lint = 0.
lv_read_lint = 1.
ENDIF.
If someone knows how change printer params, please let know too!
Best regards!
The printer selection is determine when calling the function '/SCWM/PRINT_HU' parameter 'IV_LDEST'.
DeleteThe current example is working only when the action has already been processed once. Example: If the custom program needs to print the HU label, it won't work if the label has not already been processed once, through the standard process. If we can see the result in the SPPFP tcode this code will reprocess and change the value of the column changed by.
I need to process for the first time the action. So, it has not been processed yet. The custom program should act like the standard process and process the action.
In my example, the action to process for the first time will be the HU_LABEL printing.
All ideas will be highly appreciated.
Nice piece of code.
ReplyDeleteWhen the action can already been seen using tcode SPPFP, it is working fine to relaunched it.
But when the action has not already been processed, so no entry found using SPPFP, it doesn't work.
What will look like the program to be able to launch an action that has not been processed yet?
After running the program, we most see it in the SPPFP.
Regards