---
title: "转 Call instance method from workflow using class"
author: "evangxli"
date: "2013-08-13T13:38:10Z"
tags: []
categories: ["行业应用"]
slug: "call-instance-method-from-workflow-using-class"
draft: false
lastmod: "2013-08-07T14:51:50Z"
id: 1917158
url: "https://sapabap.iteye.com/blog/1917158"
---

## Call instance method from workflow using class

By Rakesh Dhudipala from [Link](http://www.saptechnical.com/)

**Scenario**:

Below document explains how to call instance Method from Workflow task  

**Prerequisites**:

ABAP objects  

**Step by step Procedure**:  

Go to SE24, create a class by name ZCL\_TEST\_WORKFLOW.  

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan11.jpg)

Implement interface IF\_WORKFLOW in the class.

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan12.gif)

Create one instance method called GET\_RESULT

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan13.gif)

Define below attributes in the Attributes TAB

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan14.gif)

Create below methods in the methods tab.

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan15.jpg)

1)     **Constructor**:

Define with below parameters.

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan16.gif)

In the 'Constructor' write the below code.

method CONSTRUCTOR.

  m\_lpor-INSTID = i\_id.  
  m\_lpor-CATID = 'CL'.  
  m\_lpor-TYPEID = 'ZCL\_TEST\_WORKFLOW'.  
endmethod.

2)     **GET\_RESULT**:

Method contains below parameters.

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan17.jpg) 

Write the below code in the GET\_RESULT method.

method GET\_RESULT.  
  p3 = p1 * p2.  
endmethod.  

3)    **Create:**

Create method contains below parameters.

Write the below logic in the CREATE method.

method CREATE.  
  CREATE OBJECT e\_instance  
    TYPE  
      zcl\_test\_workflow  
    EXPORTING  
      i\_id              = i\_id.  
endmethod.

In BI\_PERSISTENT~FIND\_BY\_LPOR interface method write the below code

method BI\_PERSISTENT~FIND\_BY\_LPOR.  
  CREATE OBJECT result  
    TYPE  
      zcl\_test\_workflow  
    EXPORTING  
      i\_id              = lpor-instid(10).  
endmethod.

In the BI\_PERSISTENT~LPOR method write the below code

method BI\_PERSISTENT~LPOR.  
  result = me-&gt;M\_Lpor.  
endmethod.

Go to SWDD transaction and create new workflow.  

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan18.gif)

Create new activity  

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan19.jpg)

Create new task and enter the CREATE method

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan20.gif)  
This will map the below parameters  

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan21.gif)

Create one more task and enter the get\_result method in the task like below  

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan22.jpg)

 

Now container mapping with the below parameters

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan23.gif)

Assign the agents to the task  

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan24.gif) 

Make task as general task

![](http://www.saptechnical.com/Tutorials/Workflow/Classes/Instan25.jpg)

Now if we run the workflow it will executes the instance method.