In SAP Transportation Management, we get many scenarios to trigger a PPF (Post Processing Framework) Action by stand alone code. Examples being; Trigger a PPF Action from a POWL (Personal Object Work list) or trigger a PPF action in TRQ (Booking Request) when a condition satisfies in TOR (Manifestation). So we need a mechanism to trigger the PPF action configured in a BO via stand alone code.
2.0 Technical Design
The following design is based on a requirement in a project where a PPF Action was triggered from a legacy system via a RFC enabled FM which is called on certain events in the system. So appropriate inputs were created considering the requirement. These inputs can be changed as per project needs.
Inputs to the FM.
a) Booking #
b) Application Name (Defaulted to ‘/SCMTMS/TRANSPORTATION ‘)
c) Context Name (Name of the Action)
d) Name of the Action Definition
e) Commit (Default = ‘X’)
The following code is written with the constraint in PPF frame work that the Schedule Condition BADI (EVAL_SCHEDCOND_PPF) will not be instantiated and hence it cannot be called as a part of frame work. So we have to do the necessary code for doing the schedule condition check and then if that passes we can call the FM to trigger the PPF. In this part of discussion we will talk about the trigger to a BADI implementation of EVAL_STARTCOND_PPF & EXEC_METHODCALL_PPF.
2.1 Code snippet (Where we configure EXEC_METHODCALL_PPF BADI as final method)
Step 1) Get an instance of PPF manager
TRY. lo_manager = cl_manager_ppf=>get_instance( ). CHECK lo_manager IS BOUND. ENDTRY. " Get persistent PPF object lo_agent = /bofu/ca_ppf_container=>agent. lv_bo_key = /scmtms/if_trq_c=>sc_bo_key. lv_appl_key = ls_key-key. TRY. lo_agent->get_persistent( EXPORTING i_bo_key = lv_bo_key i_db_key = ls_key-key i_node_key = /scmtms/if_trq_c=>sc_node-root i_ppf_profile = iv_context RECEIVING result = lo_ppf_container ). CATCH cx_os_object_not_found. " Create persistant object TRY. lo_agent->create_persistent( EXPORTING i_appl_key = lv_appl_key i_bo_key = lv_bo_key i_db_key = ls_key-key i_node_key = /scmtms/if_trq_c=>sc_node-root i_ppf_profile = iv_context RECEIVING result = lo_ppf_container ). CATCH cx_os_object_existing . ENDTRY. ENDTRY.
Step 2) Create PPF context
CREATE OBJECT lo_context. lo_context->name = iv_context. lo_context->appl = lo_ppf_container. lo_context->applctn = iv_applctn. lo_context->applkey = lv_appl_key. CLEAR lo_trigger. IF lo_trigger IS INITIAL. " Create trigger for PPF action lo_manager->create_trigger( EXPORTING ip_ttype_name = iv_ttype io_context = lo_context RECEIVING ro_trigger = lo_trigger EXCEPTIONS empty_triggertype = 1 empty_context = 2 OTHERS = 3 ). IF sy-subrc <> 0. RAISE error_trigger_creation. ENDIF. ENDIF. * Set partner Independent flag as TRUE IF lo_trigger IS NOT INITIAL. lo_trigger->set_partindep( i_partindep = abap_true ). ENDIF. * Set application key for all triggers of the context lo_manager->set_applkey( EXPORTING ip_applkey = lv_appl_key io_context = lo_context ).
Step 3) Execute the trigger
CALL METHOD lo_trigger->execute RECEIVING rp_rc = ev_rc 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.
Commit is required to make the changes reflect in the output management tab. Please be cautious if you are writing the code in BOPF. As we need not write commit work in BOPF coding as the system commit will take care of it.
2.2 PPF Action for triggering Adobe / smart forms (Where we configure DOC_PERSONALIZE_BCS BADI as final method)
When we are dealing with triggering BADI Implementations for DOC_PERSONALIZE_BCS for printing forms we need to add following lines of code to set the Medium of PPF action for Printers and Number of copies before calling Step 3 to execute the call. You can have the printer & number of copies as variable input in your FM. In this example I have hard coded for easy understanding.
**For 'External Communication' populate mandatory parameters. E.g.: Printer and Number of copies. IF lref_trigger IS BOUND. CREATE OBJECT lref_bcs. lref_medium_ppf = lref_trigger->get_medium( ). IF lref_medium_ppf IS BOUND. lref_bcs ?= lref_medium_ppf. lref_bcs->print_copies = lc_copies. “001 lref_bcs->device = lc_printer. “LOCL lref_medium_ppf = lref_bcs. **Set the medium of PPF Action CALL METHOD lref_trigger->set_medium EXPORTING i_medium = lref_medium_ppf. ENDIF. ENDIF.