cancel
Showing results for 
Search instead for 
Did you mean: 

SAP_WAPI_WRITE_CONTAINER does not write to WF container from Program Exit

0 Kudos

Dear helpful gurus:

Function module SAP_WAPI_WRITE_CONTAINER has no effect when called from my program exit.

SAP does not take into account when a workflow "requested end" deadline falls after working hours or on a weekend or holiday. In order to achieve this, I wrote an ABAP OO Class to write an adjusted reference date and time to the container.

The workflow task uses these 2 container variables as a reference so its requested end always falls within working hours. I call this class from a task program exit, using the interface IF_SWF_IFS_WORKITEM_EXIT. I need this to run before the task is created so the variables will be available when the requested end time is calculated.

I can successfully step through the entire process in the ABAP debugger. The local container is updated when I call SWC_SET_ELEMENT.

But when my class calls SAP_WAPI_WRITE_CONTAINER, the workflow container is not modified, even though the function returns successfully (sy-subrc = 0).

What am I doing wrong?

Aaron Ortiz

P.D. Here is my code:

method ESCRIBIR_CONTAINER.

  data:
    wiid         type SWW_WIID.

  swc_container wf_container.

  wiid     = me->contexto->get_workflow_id( ).

  CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
    EXPORTING
      WORKITEM_ID                    = wiid
*     LANGUAGE                       = SY-LANGU
*     USER                           = SY-UNAME
*   IMPORTING
*     RETURN_CODE                    =
*     IFS_XML_CONTAINER              =
*     IFS_XML_CONTAINER_SCHEMA       =
    TABLES
      SIMPLE_CONTAINER               = wf_container.
*     MESSAGE_LINES                  =
*     MESSAGE_STRUCT                 =
*     SUBCONTAINER_BOR_OBJECTS       =
*     SUBCONTAINER_ALL_OBJECTS       =

  SWC_SET_ELEMENT wf_container 'zc24fechabase' me->fecha_base.
  SWC_SET_ELEMENT wf_container 'zc24horabase' me->hora_base.

  CALL FUNCTION 'SAP_WAPI_WRITE_CONTAINER'
    EXPORTING
      WORKITEM_ID             = wiid
*     LANGUAGE                = SY-LANGU
*     ACTUAL_AGENT            = SY-UNAME
      DO_COMMIT               = 'X'
*     IFS_XML_CONTAINER       =
*   IMPORTING
*     RETURN_CODE             =
    TABLES
      SIMPLE_CONTAINER        = wf_container.
*     MESSAGE_LINES           =
*     MESSAGE_STRUCT          =

endmethod.

Accepted Solutions (1)

Accepted Solutions (1)

mh97
Contributor
0 Kudos

Aaron,

I agree with Karri. You can use function module END_TIME_DETERMINE. That allows you to input a factory calendar.

I just had a similar requirement and I did use END_TIME_DETERMINE. I didn't find an existing method so I just created my own and a task to insert it in my workflow. It worked perfectly.

I hope this helps.

Margaret

0 Kudos

Thanks Mike, Karri, and Margaret

I will try your ideas and get back to you about the results

Aaron Ortiz

pokrakam
Active Contributor
0 Kudos

Hello Aaron,

You should be able to use a functional method to calculate the deadline. If you get syntax errors you probably need to apply [Note 1225337 - Workflow builder: Functional expressions return error WD 266|https://service.sap.com/sap/support/notes/1225337].

Cheers,

Mike

0 Kudos

Thanks Mike,

This note looks like it's going to be the solution to the problem. I will get permission to apply it. Hopefully it will.

thanks!

Aaron Ortiz

Answers (1)

Answers (1)

pokrakam
Active Contributor
0 Kudos

Hello Aaron,

Please look at [this thread|; for some resources on what you're after. It should not be necessary to fiddle with containers.

The problem with your code is the commit. If you're in the exit the WF system executes the workitem as a LUW and doing a commit in the middle of it can cause problems. Apart from that, you cannot easily change containers in an exit because the WF system will just overwrite your changes when it completes the workitem.

Cheers,

Mike

0 Kudos

Thanks Mike,

I removed the DO_COMMIT from the function call, but I still get this error:

"Cannot call WAPI interface 'SAP_WAPI_WRITE_CONTAINER' in this context"

I had read the article you linked to already, it is a very helpful guide, thanks! But the problem is that the alerts I need to set need a granularity of hours, not days. That's the main reason I created the class.

For example, I have a task should take no longer than 6 hours, but often, since the workday is only 8 hours, I have to split the time between two working days, using the factory calendar. The class I wrote calculates an offset to use as the base time and date for the requested end of the workflow...but I can't write to the container from my code. Is there another way to do this?

Thanks for your help!

Aaron

Former Member
0 Kudos

Hi,

Maybe you should create a step just before your current problematic step. In this new step you can calculate the exact deadline(s) and then deliver them to the following step. Not probably the most elegant solution due to the need for extra step in the workflow, but at least it should work and will be easy to implement.

Then it would be possible to create your own custom class (or business object) with deadline attributes, but it becomes a bit more complex.

Regards,

Karri