fareez.info

Integrating Applications With Suspend, Resume & Exit Plugs

Integrating two different applications in Web Dynpro ABAP is quite a challenging task. Most of the time we choose to integrate applications by making component usage of one component in another. But sometimes this becomes a tedious task, especially when both component are dependent on each other. Here we are going to see an alternative option which is redirecting URL by using Suspend, Resume & Exit plugs.

Now we will see a small example where there are two applications with URLs A & B. Application A will contain a InputField and a Button captioned ‘Open Application B’ and application B will contain TextView element and a Button captioned ‘Exit’. On clicking ‘Open Application B’ the text from the InputField goes to application B and get displayed in the TextView. On clicking exit button it jumps back exiting application B and resuming application A. Here the message is passed as a URL parameter and it is processed at the handler of the default plug of window of application B.

Create two components ZFAR_APP1 and ZFAR_APP2. Create the context as shown below for the both components in the component controller. Attribute MSG is of type STRING.

Context

Create mapping for the context node NODE in both MAIN view and the window (ZFAR_APP1 and ZFAR_APP2) of both the components.

Now design the UI of application A as shown below in the MAIN view and bind the InputField to MSG attribute of NODE.

Context

Design the UI of application B as shown below in the MAIN view and bind the TextView to MSG attribute of NODE.

Context

##Creating plugs for Application A

Create an outbound plug named TO_WINDOW in the MAIN view. Now create inbound plugs & outbound plugs in the window as shown below.

Context

Context

When you create a Suspend or Exit plug, you can create a non-optional parameter named URL and pass the URL to which the application should redirect to when the plug is fired. You can create any number of optional parameters which will be passed as URL parameters to the URL which we are redirecting to. Here I have MSG parameter which will carry the message from App A to App B.

Create a navigation link between TO_WINDOW of MAIN view and FROM_VIEW of the ZFAR_APP1 window. Now in the handler method of FROM_VIEW we are going to fire the Suspend plug so that we can navigate to Application B suspending our current application. Unlike an Exit plug, a suspend plug does not close the current application, it just suspends it and jumps to another URL so that it can resume later. When the Exit plug is called in the application B, it automatically resumes application A from the same point we left it. Suspend plug and Resume plug always exists in pair. You cannot create either one alone, it will create a runtime exception. Following is the code in the handler method of FROM_VIEW.

method HANDLEFROM_VIEW .

  data msg type string.
  data app2_url type string.
  data node type ref to if_wd_context_node.

  node = wd_context->get_child_node( 'NODE' ).
  node->get_attribute( exporting name = 'MSG' importing value = msg ).

  cl_wd_utilities=>construct_wd_url(
    exporting
      application_name = 'ZFAR_APP2'
    importing
      out_absolute_url = app2_url
  ).

    wd_this->fire_to_app2_plg(
     msg = msg
      url = app2_url
    ).

endmethod.

Context

Now on click of the button ‘Open Application B’ fire the TO_WINDOW plug.

method ONACTIONOPEN .

    wd_this->fire_to_window_plg(
    ).

endmethod.

That’s all with application A.

##Creating plugs for Application B

The message which is sent as the URL parameter should be processed in the handler of the DEFAULT inbound plug of the window ZFAR_APP2. Following is the code to process URL parameters and move the message to context node.

method HANDLEDEFAULT .

  data params type tihttpnvp.
  data params_stru type line of tihttpnvp.
  data node type ref to if_wd_context_node.

  wdevent->get_data(
    exporting
      name = if_wd_application=>all_url_parameters
    importing
      value = params
   ).

  node = wd_context->get_child_node( name = 'NODE' ).

  loop at params into params_stru.
    if params_stru-name = 'MSG'.
      node->set_attribute( exporting name = 'MSG' value = params_stru-value ).
    endif.
  endloop.
endmethod.

Create an outbound plug named EXIT in the MAIN view. Now create inbound plugs & outbound plugs in the window as shown below.

Context

Context

Create a navigation link between EXIT of MAIN view and FROM_VIEW of the ZFAR_APP2 window. Now in the handler method of FROM_VIEW we are going to fire the exit plug so that we can navigate back to application A exiting application B.

Context

Following is the code in the handler method of FROM_VIEW.

method HANDLEFROM_VIEW .

    wd_this->fire_back_to_app1_plg(
    ).

endmethod.

Now on click of the button ‘Exit’ fire the Exit plug.

method HANDLEFROM_VIEW .

    wd_this->fire_back_to_app1_plg(
    ).

endmethod.

Now activate both the components and create applications in the same name of the components and run application A.

Context

Context

Choose the data that has to be transferred through URL carefully as data are sent through GET and not POST. You can also do some additional security programming by creating tokens from application and transferring only the token number to application B. With the token number application B can request data through some BAPI. Though this URL redirection alternative is not the best solution always, it comes handy in situations when Application A and Application B are totally independent large applications.

comments powered by Disqus