Tuesday, June 30, 2009

WebDynpro: Issue message with reference to an attribute

In normal ABAP reporting we can check the selection screen and do some checks on a field. If there is a problem an error relevant to the selection field is issued. e.g.

AT SELECTION-SCREEN ON p_carrid.
  IF p_carrid IS INITIAL.
    MESSAGE 'Please enter a value' TYPE 'E'.
  ENDIF. 

I am going to list out the process of doing the same in case of a WebDynpro. I have got a simple WD component, the layout of which is:

image

So just 2 input fields called VALUE1 and VALUE2 attached to this context:

image

We want to issue message on the field VALUE1 when the user presses the button GO. For that we will make use of the method WDDOBEFOREACTION, which gets triggered on user action. Double click on that method and go into the code section. Using the code wizard, 1) choose the option of “Read Context –> Node/Attribute” and select VALUE1 (take any actually). You should get code as below:

  DATA:
    node_node                           TYPE REF TO if_wd_context_node,
    elem_node                           TYPE REF TO if_wd_context_element,
    stru_node                           TYPE if_main=>element_node ,
    item_value1                         LIKE stru_node-value1.
* navigate from <CONTEXT> to <NODE> via lead selection
  node_node = wd_context->get_child_node( name = if_main=>wdctx_node ).
* get element via lead selection
  elem_node = node_node->get_element(  ).

I have deleted the extra code beyond “elem_node = node_node->get_element( )” as that is not needed. This will give us a handle to the element of the node. Now for the step 2) click on the code wizard and choose “Generate Message” and in the method take REPORT_ATTRIBUTE_ERROR_MESSAGE. This will generated the code for issuing message and highlighting the relevant field in the process: The code generated is:

* get message manager
  DATA: l_current_controller TYPE REF TO if_wd_controller,
        l_message_manager    TYPE REF TO if_wd_message_manager.
  l_current_controller ?= wd_this->wd_get_api( ).
  CALL METHOD l_current_controller->get_message_manager
    RECEIVING
      message_manager = l_message_manager.
* report message
  CALL METHOD l_message_manager->report_attribute_error_message
    EXPORTING
      message_text        = 'Enter some value'
      element             = elem_node
      attribute_name      = 'VALUE1'
*    PARAMS              =
*    MSG_USER_DATA       =
*    IS_PERMANENT        =
*    SCOPE_PERMANENT_MSG = CO_MSG_SCOPE_CTXT_ELEMENT
*    MSG_INDEX           =
      .

The method REPORT_ATTRIBUTE_ERROR_MESSAGE needs the message text, element reference (elem_node in our case) and the field to highlight (VALUE1 for this example). So lets how it comes out.

Initial screen is:

image

On pressing Go we get:

image

One can also try the other methods in the code wizard for issuing messages.

Friday, June 19, 2009

Utilities: VM for mini SAP

SAP does the developer version of Netweaver that contains ABAP stack, although it is without any applications, you can use it learn new technologies or as play ground. The download is available from here. If you install this on your normal PC/Laptop then it might hog or disturb the normal workings of your PC with registry changes and what not. I instead install it on a virtual machine so that whenever I need the mini SAP I can start the virtual machine and when not in use it is not interfering or taking memory. In the past I had used VMware and Virtual PC but now I am using an open source VM from SUN which I think is robust enough and the main advantage is that you can use it on Linux as well. It can be downloaded from here.

UPDATE: The amount of memory and hard disk that I have on the VM is 1 GB RAM and 30 GB HDD.

Utilities: VM for mini SAP

SAP does the developer version of Netweaver that contains ABAP stack, although it is without any applications, you can use it learn new technologies or as play ground. The download is available from here. If you install this on your normal PC/Laptop then it might hog or disturb the normal workings of your PC with registry changes and what not. I instead install it on a virtual machine so that whenever I need the mini SAP I can start the virtual machine and when not in use it is not interfering or taking memory. In the past I had used VMware and Virtual PC but now I am using an open source VM from SUN which I think is robust enough and the main advantage is that you can use it on Linux as well. It can be downloaded from here.

Thursday, June 11, 2009

Utilities: Download/upload SAP development objects

So you want to upload/download your code before moving on to another project? You have used one of the many common utilities that do this. Those are half baked ones that download/upload ABAP reports and maybe SAPScripts. Now that SAP has ABAP classes, SmartForms, XSLT, WebDynpro, etc. those simple download/upload programs won’t work. I have recently started using SAPlink which is an open source effort to manage you development objects on different SAP system. It can can be downloaded from here. I’ll quote from the website what it does.

SAPlink is a project that aims to make it easier to share ABAP developments between programmers. It provides the ability to easily distribute and package custom objects.

It uses concept of nuggets for many objects, and linkees for single objects. It can download all the objects from a package even. Finally there is a good tool that everyone one needed. Well done SAPlink team!