Reading Workitem / Workflow Container

Simple value as string

Definition
CLASS-METHODS read_single_container_value
  IMPORTING
	i_name         TYPE clike
	i_workitem_id  TYPE sww_wiid
  RETURNING
    VALUE(r_value) TYPE string.
Implementation
METHOD read_single_container_value.
 DATA:
   wf_cont TYPE STANDARD TABLE OF swr_cont.

 CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
   EXPORTING
	 workitem_id      = i_workitem_id
	 user             = CONV syuname( 'WF-BATCH' )
   TABLES
	 simple_container = wf_cont.

 LOOP AT wf_cont INTO DATA(value) WHERE element = CONV swc_elem( i_name ) .
   r_value = value.
   EXIT.
 ENDLOOP.

ENDMETHOD.

Value of container element (value, work area, internal table)

Type of the result must be known by the caller. 

Definition
CLASS-METHODS:
  read_container_value
	IMPORTING
	  i_workitem_id TYPE sww_wiid
	  i_name        TYPE swfdname
	EXPORTING
	  e_value       TYPE any.
Implementation
METHOD read_container_value.
 DATA:
   wi_handle    TYPE REF TO if_swf_run_wim_internal,
   wf_container TYPE REF TO if_swf_cnt_container.

 TRY.
	 wi_handle = cl_swf_run_wim_factory=>find_by_wiid( im_wiid = i_workitem_id ).
	 wf_container = wi_handle->get_wi_container( ).

	 CALL METHOD wf_container->if_swf_ifs_parameter_container~get
	   EXPORTING
		 name  = i_name
	   IMPORTING
		 value = e_value.

   CATCH cx_root.
	 "Noooooooo
 ENDTRY.
ENDMETHOD

Method is for single access, no reuse of wi_handle or wf_container.