Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article demonstrates how to create System Tasks in the FAB Process Designer. System Task is a configuration in the Task Setting that provides the ability for a Task to execute an ABAP code in the background.

Table of Contents

Procedure

Step 1

Create a FAB application in transaction /n/IQX/FAB. Define the Properties, set the Workflow Mode to Process, and click Save.

Image RemovedImage Added

Step 2

Add an Input control in the Form Container and bind it to field Field1 in the Data Model.

Add a Text control in the Form Container and bind it to field Result in the Data Model. This holds the result from the background task.

Step 3

Create an Implementation Class for the System Task. Go to Code to open the Form Life-Cycle dialog. Select Click the button Auto-Generate Class Name, followed by the button Generate Class.

The ABAP logic used by the System Task needs to be added in the ABAP Class that implements the /IQX/IF_SYSTEM_TASK Interface. You may create a dedicated Class for this, or you may use the Implementation Class of your application. In this example, we will use the latter option.

Step 4

In the Form Life-Cycle dialog, select click the button ABAP Routine next to the Perform System/Background Task to create an implementation and select click it again to open the Class editor.

Any logic can be implemented in method PERFORM_SYSTEM_TASK, but a boolean value (either ABAP_TRUE or ABAP_FALSE) must be returned in parameter E_SUCCESS.

In this example, we will only add a logic that generates a random number, log the results, and set the value of E_SUCCESS to ABAP_TRUE. However, in an actual implementation, you might need to use SAP master data or any transactional data.

language
Code Block
abap
method /iqx/if_forms_system_task~perform_system_task.
    move-corresponding cr_data to gs_data.
    "implement your actions.
    data: lo_ran type ref to cl_abap_random_int,
          lv_i   type i,
          lv_seed type i, 
		  lv_message type string.
    lv_seed = sy-timlo.
    lo_ran = cl_abap_random_int=>create( min = 1 max = 99999999 seed = lv_seed ).
    lv_i = lo_ran->get_next( ).
    gs_data-result = lv_i. "set result into data model
    lv_message = |Document | && gs_data-result && | created|.
    call method me->add_to_log   "log your results
      exporting
        i_form_name = i_form_name
        i_instance  = i_instance
        i_type      = 'S'
        i_message   = lv_message.
    move-corresponding gs_data to cr_data.
    e_success = abap_true. " or ABAP_FALSE.
endmethod.

Step 5

In the Form Life-Cycle dialog, select click the button ABAP Routine next to the Determine approvers for Roles Task to create an implementation and select click it again to open the Class editor.

In this example, we will use the user FABAPPR1 as the Approver and WF-BATCH as the System User.

Code Block
languageabap
method DETERMINE_APPROVERS_FOR_ROLE.
  FIELD-SYMBOLS: <fs_approvers> LIKE LINE OF ct_approvers.
    CASE i_role.
      WHEN 'Approver1'.
        APPEND INITIAL LINE TO ct_approvers ASSIGNING <fs_approvers>.
        <fs_approvers>-approval_level = i_level.
        <fs_approvers>-node_id = i_node.
        <fs_approvers>-role_id = i_role.
        <fs_approvers>-zinstance = i_instance.
        <fs_approvers>-objty = 'US'.
        <fs_approvers>-objid = 'FABAPPR1'.

       WHEN 'System User'.
        APPEND INITIAL LINE TO ct_approvers ASSIGNING <fs_approvers>.
        <fs_approvers>-approval_level = i_level.
        <fs_approvers>-node_id = i_node.
        <fs_approvers>-role_id = i_role.
        <fs_approvers>-zinstance = i_instance.
        <fs_approvers>-objty = 'US'.
        <fs_approvers>-objid = 'WF-BATCH'.
    ENDCASE.
endmethod.

Step 56

Select Click the Workflow button to open the FAB Process Designer.

Step 6

Define the Roles.

Select Click the Add button to create 2 custom Roles for the Approvers. In this example, we will use the role Approver1 for the Approve Task and the System User for the Update SAP System Task. Existing Roles can also be used for the System Task.

Image RemovedImage Added

Step 7

Define the Levels. Select Click the Add button to create the Levels.

In this example, we will use the level Update SAP for the Update SAP System Task and Administrator for the Administrator Task.

Image Removed

Image Added

Please note that it is currently a requirement that a System Task is defined in its own Level - it should not be inserted in a Level that has other Tasks in it.

Step 8

Define the Tasks using the Template and the Add buttons.

System Tasks run in the background. If the processing fails, a dedicated Task can be created to notify rectify the user of the issue . This also provides the user with the ability to make any corrections or re-submit the Task. In this example, the Administrator Task is can be used when the Update SAP Task fails.

Image Removed

Image Added

Step 9

Define the Roles for each Task.

Start - Initiator

Draft - Initiator

Approve - Approver1

Update SAP - System User

Administrator - Administrator

Complete - No Role

In this example, the The System Role, Administrator, is assigned to the Administrator Task. This allows the user with an administrator role to carry out the Administrator functions. A User can be configured as an Administrator in transaction /n/IQX/FAB_CONFIGRoles for Users and the Admin flag should be ticked. A Role can be configured for a specific Form in /n/IQX/FAB_CONFIGForms For Roles. Alternatively, the Administrator can also be defined via code in method DETERMINE_APPROVERS_FOR_ROLE.

Step 10

Set the Implementing Class of the System Task.

Select Click the Ellipsis button (More Task Settings) of the Update SAP task.

Tick the flag for the System Task or Recording and enter the class name in the Implementing Class field.

Select Click OK.

Image Modified

Step 11

Define the Outcomes for each Task Action. Go to ActionsOutcomes.

Start and Draft Tasks

Approve Task

Update SAP Task

Action Types have to be defined for a System Task.

Administrator Task

In this example, when the task fails, the action is directed to the Administrator for issue rectification or task resubmission.

The Process Flow will be as follows:

Image RemovedImage Added

Select Click Save & Close.

Step 12

Add a FAB Process Flow control by right-clicking on Page Add Process FlowAdd FAB Process Flow.

Image Removed

. Click Save.

Image Added

The application will be as follows:

Image Added

Positive Testing

Step 1

Enter any data in Field1 and click Submit.

Image Added

Step 2

Check the Data Report in transaction /n/IQX/FAB_DATA. Enter the Form Name and click Execute.

The data has been submitted. The current status is Approval and the next approver is FABAPPR1.

Image AddedImage Added

Step 3

Log in to the application as the Approver. Go to My Forms → To Approve. Open the application and click Approve.

Image Added

Step 4

Refresh the Data Report in transaction /n/IQX/FAB_DATA.

The current status is Update SAP and the next approver is WF-BATCH.

Image Added

Step 5

Go to transaction SM37 search for Jobs with a similar name as the application.

Image Added

Step 6

Refresh the Data Report in transaction /n/IQX/FAB_DATA.

The Current Status is now Completed. The Header Changes show the history and the Log shows all the relevant log entries.

Image Added

The field Result holds the random number generated from the class.

Image Added

Step 7

Check the results from the application. Log in as the Submitter. Go to My Forms → Submitted By Me.

Image Added

Negative Testing

Step 1

Go to Code to open the Form Life-Cycle dialog. In the Form Life-Cycle dialog, click the button ABAP Routine next to the Perform System/Background Task to open the Class editor.

Use the following logic in method PERFORM_SYSTEM_TASK. For testing purposes, set the value of parameter E_SUCCESS to ABAP_FALSE.

Code Block
languageabap
data: lv_message type string.

lv_message = |Error creating Document|.

call method me->add_to_log   "log your results
  exporting
    i_form_name = i_form_name
    i_instance  = i_instance
    i_type      = 'E'
    i_message   = lv_message.

e_success = ABAP_FALSE.

Step 2

Repeat Steps 1 to 5 from the Positive Testing guide.

In transaction SM37, the job logged a Failure message.

Image Added

Step 3

Check the Data Report in transaction /n/IQX/FAB_DATA. Enter the Form Name and click Execute.

The Current Status is now Administrator. The errors are included in the Log.

Image Added

The Administrator defined in transaction /n/IQX/FAB_CONFIG or in method DETERMINE_APPROVERS_FOR_ROLE can rectify the issue and resubmit the Form.

Debugging and Troubleshooting

Debugging

The System Task runs in the background. To debug it, you can run the event in the foreground by executing the report /IQX/FAB_SYSTEM_TASK and enter the following parameters:

Form Name - FAB App Name

Instance - FAB Instance (Form ID)

Status - Status of the Instance at the time of processing

Task ID - Process Task ID (Example: Update SAP)

Troubleshooting

Check the Logs in transaction /n/IQX/FAB_DATA. The logs should contain this message Starting Event Handler for Background Task. Otherwise, check the transaction SWETYPV if Event Type Linkages are configured.

Object Category - BOR Object Type

Object Type - /IQX/FAB

Event - BACKGROUND_TASK_START

Receiver Type - BACKGROUND_TASK

Troubleshooting - Workflow runtime is not configured properly

In an event if the Event Type linkages are configured and activate, but no background job/system task is created/released should have been found in SM37, then please check if the Workflow runtime is configured properly in transaction SWU3 as below screenshot:

Image Added

In TS4 environment, there is no RFC destination configured as well as no WF-BATCH user is created for the workflow runtime.