Skip to Content
0

Not able to catch class instantiation in a task.

Dec 01, 2017 at 04:28 AM

103

avatar image
Former Member

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.

wf-v-1.png (32.7 kB)
wf-v-2.png (41.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Mike Pokraka Dec 01, 2017 at 11:15 AM
2

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.

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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>
0

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'.

?

2
Former Member

Hi Sandra,

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

0

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

0
Former Member

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.
0
Anjan Paul Dec 01, 2017 at 06:39 AM
1

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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..

0

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

0
Former Member

HI Anjan & Sandra,

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

0