Trigger a workflow when PR is created using Class and events in ABAP.

-------------------------------------------------------Creating custom class-------------------------------------------------------------------

Step 1: Create a custom class.

Step 2: Give the interfaces.

Step 3: Create an event with parameter E_F_BANFN type BANFN.

Step 4: Create attributes.


Step 5: Create constructor with importing parameter I_F_BANFN.
Step 6: Implement the constructor.

                METHOD constructor.
            DATA l_f_instid TYPE sibflpor-instid.
            l_f_instid i_f_banfn.
            g_r_lpor-catid 'CL'.
            g_r_lpor-typeid 'ZCL_AB_WF_PR_APPROVAL1'.
            g_r_lpor-instid l_f_instid.
        ENDMETHOD.

Step 7: Implement the method - BI_PERSISTENT~FIND_BY_LPOR.

        *----- begin of local data
        DATAl_o_ref_doc     TYPE REF TO zcl_AB_WF_pr_approval1.
        DATAl_r_doc_key    TYPE banfn.
        *----- end   of local data

        *---- instid is the key of the object
        l_r_doc_key :lpor-instid.
        TRY.
            CREATE OBJECT l_o_ref_doc
              EXPORTING
                i_f_banfn l_r_doc_key.
          CATCH cx_bo_error .
        *------ object not found
          RETURN.
        ENDTRY.

        *----Load the current instance to result
            result l_o_ref_doc.
        ENDMETHOD.

Step 8: Implement the method BI_PERSISTENT~LPOR.

     method BI_PERSISTENT~LPOR.
          result g_r_lpor.
     endmethod.

Step 9: Implement the methods.

        BI_PERSISTENT~REFRESH

        BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE

        BI_OBJECT~EXECUTE_DEFAULT_METHOD

        BI_OBJECT~RELEASE

Step 10: Save and activate.

-------------------------------------------------------------Creating workflow-----------------------------------------------------------------------

Step 1: Goto T-code SWDD.

Step 2: Click on create and save.

Step 3: Select workflow container and create fields.

Step 4: In our case creating pr number, instance for class, object for class and business object.

            * PR number-- Importing and exporting


            * Instance for class - Importing and exporting.


            * Business object -- importing and exporting.


            * Instance for workflow-- Importing and exporting.


            * Create an extended field.


            * Create object key field.


            * Create object type field.


Step 5: Save and activate up to this.

Step 6: Click on GOTO --> basic data and click on starts event tab. Select category CL and give class name and event.

         Note: Binding must be imp and active is also imp.

                * Generate binding and activate the class. 

                Save and back.



Step 7: Create activity for Workflow Linkage.


            * Binding must be needed.

            * Main Binding (Below of task).



Step 8: Save and activate.

        * Final workflow.

-----------------------------------------------Raise an event for custom class--------------------------------------------------------------------------------
Step 1: Create BADI implementation for ME_PROCESS_REQ_CUST.
            * Implement the POST method.
                METHOD if_ex_me_process_req_cust~post.
        IF sy-tcode 'ME51N'.
          DATAl_o_ref TYPE REF TO zcl_ab_wf_pr_approval1.
        *------    CREATE OBJECT l_o_ref( ).
          CREATE OBJECT l_o_ref
            EXPORTING
              i_f_banfn im_banfn.
          CALL METHOD l_o_ref->register_wf
            EXPORTING
              i_f_banfn im_banfn.
        ENDIF.
      ENDMETHOD.

----------------------------------------------------------------Testing the workflow-------------------------------------------------------------------------------


            * Goto ME51N T- Code.
            * Create PR.
            * Goto T-code SWIA.


********************************Thank You*****************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).