cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to catch class instantiation in a task.

former_member538160
Participant
0 Kudos

Hi Gurus,

Some how my workflow is driving me nuts. need your expert advise again.

I am trying to instantiate a class to display default method under 'objects and assignment' in a user decision step of WF. i have a Zclass with 3 attributes: 2 key fileds(Instance and public) and one MS_LPOR(instance & public).

Have a method called 'instantiate_CL' importing document no from workflow task. this document no is then passed to constructor and instance of the class is created as required.

My code for instantiation

TRY.
CREATE OBJECT cl_instance
EXPORTING
iv_irdoc = iv_doc
iv_year = iv_gjahr.
CATCH cx_bo_error.
ENDTRY.

instance of above code

i have to catch this back in workflow task. some how i am not able to get this instance properly in workflow task.

CL_INSTANCE value in workflow task.

your inputs would be higly helpfull in resolving this.

Accepted Solutions (0)

Answers (2)

Answers (2)

pokrakam
Active Contributor

Firstly, you don't need a task to instantiate a class. Just call a static method in a container operation.

%zcl_name.get_instance( i_year = &YEAR& i_docno = &DOCNO& )%

Secondly, as Anjan already suggested, I don't think your LPOR/FIND_BY_LPOR is working correctly. Make sure that FIND_BY_LPOR returns your object instance. Post your code if it doesn't work / not sure.

PS. Tags are for tagging things to make them searchable. It does not alert anyone. Putting someone's name in a tag only means someone looking for Sandra Rossi will find this post. As I already know my name, I do not usually search SCN for it.

former_member538160
Participant
0 Kudos

Hi Mike, Thanks for the response. below is my code.

My observation: Value of importing parameter LPOR inside method FIND_BY_LPOR is always initial.

****************************************FIND_BY_LPOR
METHOD bi_persistent~find_by_lpor.
    DATA: lv_docno TYPE rseg-belnr,
          lv_year  TYPE rseg-gjahr.
    
lv_docno = lpor+0(10).
lv_year = lpor+10(4).

   TRY.
       CREATE OBJECT result
          TYPE Zcl_wf_ap_payblock
          EXPORTING
            iv_irdoc = lv_docno
            iv_year  = lv_year.
CATCH cx_bo_error .
*------ object not found
        EXIT.
    ENDTRY.
ENDMETHOD

****************************************Method LPOR
METHOD bi_persistent~lpor.
    result = me->ms_lpor.
ENDMETHOD.

***************************************Constructor
METHOD constructor.
    DATA: lv_id TYPE char14.
    CONCATENATE iv_irdoc iv_year INTO lv_id.
    me->gv_irdoc = iv_irdoc.
    me->gv_year = iv_year.


    me->ms_lpor-instid = lv_id.
    me->ms_lpor-catid = 'CL'.
    me->ms_lpor-typeid = '/ESTA/CL_WF_AP_PAYBLOCK'.
ENDMETHOD.

*******************************************Initiate

This method gets  gets iv_gjahr iv_doc from workflow task


  METHOD instantiate_cl.
    DATA: lv_id TYPE char14,
          rak   TYPE c.

    CONCATENATE iv_doc iv_gjahr INTO lv_id.

    TRY.
        CREATE OBJECT cl_instance
          EXPORTING
            iv_irdoc = iv_doc
            iv_year  = iv_gjahr.
      CATCH cx_bo_error.
    ENDTRY.
  ENDMETHOD.<br>
Sandra_Rossi
Active Contributor

Is your class named ZCL_WF_AP_PAYBLOCK?

So, why did you enter:

me->ms_lpor-typeid = '/ESTA/CL_WF_AP_PAYBLOCK'.

Shouldn't it be:

me->ms_lpor-typeid = 'ZCL_WF_AP_PAYBLOCK'.

?

former_member538160
Participant
0 Kudos

Hi Sandra,

That piece of code was wrongly written. I was trying out few diff things yesterday. It was corrected.

Sandra_Rossi
Active Contributor
0 Kudos

So, where are we now? Please update the code or screenshots, because it's still not coherent.

former_member538160
Participant
0 Kudos

Hi Sandra,

Able to resolve the issue this morning.

Its the issue with code written in constructor. i have explained the reason below.

Thanks a lot Sandra for your time. your inputs were really helpful through out this WF development.

METHOD constructor.
    DATA: lv_id TYPE char14.
    CONCATENATE iv_irdoc iv_year INTO lv_id.
    me->gv_irdoc = iv_irdoc.
    me->gv_year = iv_year.
    me->ms_lpor-instid = lv_id.
    me->ms_lpor-catid = 'CL'.

Below line is the cause of error. My class name is start with '/ETSA*' but i have hard coded as '/ESTA'. so find_by_LPOR is not able to catch the instance created. it's all fixed now. 
 
    me->ms_lpor-typeid = '/ESTA/CL_WF_AP_PAYBLOCK'.
ENDMETHOD.
anjan_paul
Active Contributor

Hi,

You have to first check two things. Is the class uses if_workflow interface. And LPOR and Find_by_lpor method properly implemented or not

Thanks

former_member538160
Participant
0 Kudos

hi anjan,

Yep class uses if_workflow interface. As per my knowledge find_by_lpor and Lpor methods are implementaed correctly.

If you want I can paste the code of those methods here..

Sandra_Rossi
Active Contributor
0 Kudos

In method FIND_BY_LPOR, you must intantiate your class based on the object key, and initialize the 3 attributes.

former_member538160
Participant
0 Kudos

HI Anjan & Sandra,

I have pasted the code used in class. your inputs would be higly helpful..