cancel
Showing results for 
Search instead for 
Did you mean: 

not getting class instance in workflow

sugandhianand
Explorer
0 Kudos

Hi,

i have created a workflow using classes. i have done all the configurations for events and also implemented the methods of IF_workflow in the class.

problem is i am not getting the class instance in the workflow. following things i have done:

1. created a custom class Zcl_sd_sales_workflow.

2. this class has a method "Start" which triggers the workflow.

3. i am saving the instance of the class in an table Mt_instance which has two fields 1. UUID and 2. Instance.

4. did the binding of _event_object with the container Zclass (custom container created by refering class in workflow).

5. on execution i am getting all the event parameters except the one which holds the class instance.

6. i searched on SCN and tried many suggestions but unfortunatly none has worked.

7. ifeel i am missing something at the time of triggering the event / filling the mt_instance table in class.

could you please help by providing solution. my class is almost replica of standard class cl_se_pur_po_wf_out.

Regards

Anand Sugandhi

View Entire Topic
sugandhianand
Explorer
0 Kudos

Hello Stephane,

Below is my code:

Class constructor:

* define local data object
     DATA ls_entry TYPE t_s_instance.
* register instance in instance list, for a later lookup

     ls_entry-uuid = zvbeln. "me->get_uuid( ).
     ls_entry-instance = me.
     INSERT ls_entry INTO TABLE zcl0000sd_sales_workflow=>mt_instances.
     me->obj_key = zvbeln.
     me->zmpor-catid = 'CL'.
     me->zmpor-typeid = 'ZCL0000SD_SALES_WORKFLOW'.
     me->zmpor-instid = ls_entry-uuid.

     INSERT ls_entry INTO TABLE zcl0000sd_sales_workflow=>mt_instances.



method Triggering the event:


** define local data
     DATA: ls_por     TYPE sibflpor,
           ls_name    TYPE swfdname,
           lt_names   TYPE swfdnamtab,
*          lv_text    TYPE string,
           lo_wf_cont TYPE REF TO if_swf_ifs_parameter_container,
           lx_cx      TYPE REF TO cx_swf_evt_exception,
           lv_guid TYPE guid_22.
     DATA: l_result    TYPE REF TO bi_persistent.
     DATA: l_event       TYPE REF TO if_swf_evt_event.
     ls_por = me->if_workflow~lpor( ).
     l_result ?= me->bi_persistent~find_by_lpor( ls_por ).

       me->zmpor-instid = me->obj_key.
       me->zmpor-typeid = 'CL'.
       me->zmpor-catid  = 'ZCL0000SD_SALES_WORKFLOW'.

*---- return the handle
       CALL METHOD zcl0000sd_sales_workflow=>bi_persistent~find_by_lpor
         EXPORTING
           lpor   = me->zmpor
         RECEIVING
           result = l_result
           .
* Create workflow container for transporting UUID
     lo_wf_cont = cl_swf_evt_event=>get_event_container(
                 im_objcateg  = ls_por-catid
                 im_objtype   = ls_por-typeid
                 im_event     = me->gc_created  ).
     lt_names = lo_wf_cont->list_names( ).
     LOOP AT lt_names INTO ls_name.
       TRY.
           CASE ls_name.
             WHEN 'GUID'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = lv_guid ).
             WHEN 'X_VBAK'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->g_vbak ).
             WHEN 'X_VBAP'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->g_vbap ).
             WHEN 'X_VBPA'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->g_vbpa ).
             WHEN 'X_KONV'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->g_konv ).
             WHEN 'X_OBJKEY'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->obj_key ).
             WHEN 'ZDEV_MAX'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->zdev_max ).
             WHEN 'ZABS_AMT'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->zabs_amt ).
             WHEN 'ZCLASS'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me ).
             WHEN 'ZLIFSK'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->zlifsk ).
             WHEN 'ZFAKSK'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->zfaksk ).
             WHEN 'ZABGRU'.
               lo_wf_cont->set( EXPORTING name  = ls_name
                                          value = me->mv_abgru ).

             WHEN OTHERS.
           ENDCASE.
         CATCH cx_swf_cnt_cont_access_denied.
           CONTINUE.
         CATCH cx_swf_cnt_elem_access_denied.
           CONTINUE.
         CATCH cx_swf_cnt_elem_not_found.
           CONTINUE.
         CATCH cx_swf_cnt_elem_type_conflict.
           CONTINUE.
         CATCH cx_swf_cnt_unit_type_conflict.
           CONTINUE.
         CATCH cx_swf_cnt_elem_def_invalid.
           CONTINUE.
         CATCH cx_swf_cnt_container.
           CONTINUE.
       ENDTRY.
     ENDLOOP.
     TRY.
         IF iv_update EQ me->g_yes.

  CALL METHOD cl_swf_evt_event=>get_instance
         EXPORTING
           im_objcateg        = ls_por-catid
           im_objtype         = ls_por-typeid
           im_event           = me->gc_created
           im_objkey          = me->obj_key
          im_event_container = lo_wf_cont
         RECEIVING
           re_event           = l_event
           .

       l_event->raise_in_update_task( ).

         ENDIF.
       CATCH cx_swf_evt_exception INTO lx_cx.

     ENDTRY.


Find by LPOR:


* define local data object
     DATA: ls_instance TYPE t_s_instance,
           lv_uuid     TYPE guid_22,
           lv_vbeln type vbak-vbeln.

check lpor-instid is not initial.
     lv_uuid = lpor-instid.
     READ TABLE ZCL0000SD_SALES_WORKFLOW=>mt_instances
       WITH KEY uuid = lv_uuid
           INTO ls_instance.
     IF sy-subrc GT 0.
       lv_vbeln = lpor-instid.
       CLEAR ls_instance.
       CREATE OBJECT ls_instance-instance exporting zvbeln = lv_vbeln .
       ls_instance-uuid = ls_instance-instance->get_uuid( ).
       INSERT ls_instance INTO TABLE ZCL0000SD_SALES_WORKFLOW=>mt_instances.
     ENDIF.

     result ?= ls_instance-instance.


method LPOR:


     result-catid  = cl_swf_evt_event=>mc_objcateg_cl.
     result-typeid = 'ZCL0000SD_SALES_WORKFLOW'.                  "#EC *
     result-instid = me->obj_key.



issue is when i open the workflow log debugger on Find By LPOR, MT_INSTANCE is empty.

and hence new instance is created.


visibility of MT_Instance:


MT_INSTANCES    Static Attribute    Protected    Type    T_T_INSTANCES


types:
     BEGIN OF t_s_instance ,
                uuid     TYPE guid_22,
                instance TYPE REF TO ZCL0000sd_sales_workflow,
              END   OF t_s_instance .
   types:
     t_t_instances TYPE SORTED TABLE OF t_s_instance WITH UNIQUE KEY uuid .




Regards

Anand


StephaneBailleu
Active Contributor
0 Kudos

Hi

Your code could be more simple I think and it will gain in clarity

Within method lpor

just write

result = zmpor .



Find by LPOR:


DATA :   lo_object    TYPE REF TO zcl0000sd_sales_workflow',

              lv_vebln        TYPE vebln.

     lv_vebln = lpor-instid.

     TRY.

         CREATE OBJECT lo_object

           EXPORTING

             iv_vebln        = lv_vebln .

       CATCH cx_bo_error.

     ENDTRY.

     result ?= lo_object.


constructor :


* define local data object
     DATA ls_entry TYPE t_s_instance.
* register instance in instance list, for a later lookup


     me->obj_key = iv_vbeln.
     me->zmpor-catid = 'CL'.
     me->zmpor-typeid = 'ZCL0000SD_SALES_WORKFLOW'.
     me->zmpor-instid = iv_vbeln

     ls_entry-instance ?= ZCL0000SD_SALES_WORKFLOW'=>bi_persistent~findbylpor(me->zmpor).

     ls_entry-uuid = iv_vbeln.


     INSERT ls_entry INTO TABLE zcl0000sd_sales_workflow=>mt_instances.

cheers

Stephane

sugandhianand
Explorer
0 Kudos

Hi Stephane,

suggested code creates infinite loop between constructor and Find_By_LOPR method.

could you please check and suggest right way?

regards

Anand

StephaneBailleu
Active Contributor
0 Kudos

Ok yep little mistake

Find by LPOR:

* define local data object

     DATA ls_entry TYPE t_s_instance.

* register instance in instance list, for a later lookup

DATA :   lo_object    TYPE REF TO zcl0000sd_sales_workflow',

              lv_vebln        TYPE vebln.

     lv_vebln = lpor-instid.

read table mt_instances with key UUID = lv_vebln into ls_entry.

if sy-subrc <> 0.

     ls_entry-uuid = iv_vbeln.

     TRY.

         CREATE OBJECT ls_entry-instance

           EXPORTING

             iv_vebln        = lv_vebln .

       CATCH cx_bo_error.

          exit.

     ENDTRY.

     result ?= lo_object.

APPEND ls_entry to mt_instances.

endif.

    

result = ls_entry-instance.
endmethod


constructor :



     me->obj_key = iv_vbeln.
     me->zmpor-catid = 'CL'.
     me->zmpor-typeid = 'ZCL0000SD_SALES_WORKFLOW'.
     me->zmpor-instid = iv_vbeln

  

I hope that works better but you get the logic ...

I am givingg guidelines not the actual code you have to adapt it to your logic


Cheers

Stephane