Wednesday, September 7, 2011

Best Way to Handle Exceptions in ABAP Classes

I've been wanting to switch to exception classes for years but have found them overly cumbersome in most cases.  I've finally figured it out.  Here is a simple way to handle simple exceptions using ABAP exception classes from NetWeaver 6.40 and up.

Wednesday, July 6, 2011

Embedding WebDynpro into BSP

WebDynpro is great for read/write applications but weaker when it comes to presentation, flexibility and leveraging all the goodies available to normal web developers.

For the best of both worlds, you can build great applications in BSP using beautiful CSS and compelling animations (JQuery etc), and then load embedded WebDynpros when you need something heavier that you wouldn't want to code or maintain in your BSP.

How do you get the URL for the WebDynpro page you want to embed?  Try this code for size.

    data lt_parameters          type tihttpnvp.
    data ls_parameters          type line of tihttpnvp.

    clear lt_parameters[].
    ls_parameters-name = 'OBPLUG'.
    ls_parameters-value = i_plug.
    append ls_parameters to lt_parameters.
    clear ls_parameters.
    ls_parameters-name = 'OBFUNC'.
    ls_parameters-value = i_func.
    append ls_parameters to lt_parameters.
    clear ls_parameters.
    cl_wd_utilities=>construct_wd_url( exporting namespace        = 'MYNAME'
                                                 application_name = 'MYAPP'
                                                 in_parameters    = lt_parameters
                                      importing out_absolute_url  = o_url ). 

You will need to manually load the URL reply into the target element on your page:

$.get(o_url, {}, function(reply){
 $("#target").html(reply);
 }, "html");

Wednesday, June 29, 2011

Create Transaction to Execute SAP BSP Application

I have created a BSP Application and want to run it using a transaction code created in SE93.

If you have transaction START_BSP on your NetWeaver box, then you can make a copy of this transaction with your variant.

However, if this is not installed, you need to write a program that determines the appropriate URL and calls the CALL_BROWSER function module.

Here is some sample code:

report  zbsp_start.

data: lv_url type string,
      lv_urlc(4096) type c,
      lt_parms type tihttpnvp.

start-of-selection.
  parameter: p_app type string.
  parameter: p_page type string.
  parameter: p_parms type string.
end-of-selection.

*-- Create URL to BSP Application
  call method cl_http_ext_webapp=>create_url_for_bsp_application
    exporting
      bsp_application      = p_app
      bsp_start_page       = p_page
      bsp_start_parameters = lt_parms
    importing
      abs_url              = lv_url.


*-- Call the BSP Application in the default Browser
  lv_urlc = lv_url.
  call function 'CALL_BROWSER'
    exporting
      url                    = lv_urlc
      window_name            = 'BSP'
      new_window             = ' '
    exceptions
      frontend_not_supported = 1
      frontend_error         = 2
      prog_not_found         = 3
      no_batch               = 4
      unspecified_error      = 5
      others                 6.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.