Wednesday, April 4, 2012

All About Webdynpro

SAP Webdynpro, thats one of the very interesting and fascinating topics of SAP. From the time of its launch, all the ABAP developers aim was to get their hand on it. Just not because its interesting, because its one of the hot requirement in the market. Everyone was in the thought of, If you have WD Abap in your resume, then you will make it to the top list of consultants for any opening position. Just like any other developer, I wanted to work on WD Abap pretty badly but I couldnt get my hands on it because of my current work and also because of my lazy or sluggishness :). However, after all these days finally I was able to put some time to read what is all about WD abap, how is it different with other concepts of SAP ABAP and why is it so important. Basically SAP expanded its Screen or UI technology to Web to make it easy and modular for design and development and also provide capability to access SAP transactions over web, without logging onto SAP. I started this to explain about my first WD application but its going somewhere else, may be I will write one more blog about my WD understanding, let me start explaining as what I did.

My First WD Application

WD Abap works on MVC concept, that is Model, View and Controller. To be more specific, if I have an application to create a material, my logic without using WD would be one program which has a screen and it has all the logic related to that complete application, but using WD the design is,

1. View - View has the design of the application, like what is its look and feel and what are all the input and output fields necessary for that application.
2. Model - Model means all the logic to get the data, display the data, logic which triggers when user performs some action over the application and updating Databases accordingly.
3. Controller - Controller is something which joins, Model and View to make it a complete user application.

Coming to my first application: Its a simple application and its behavior is, input an Airline Code and when user clicks on a button, output all the fights for that airline code.

Step 1: Decide what are all the tables/attributes which you would be using in this application and create CONTEXT with nodes for those fields. If you create the Context in COMPONENT CONTROLLER, then it will be available in all the views of it but if you just need fields for that view, which may not be used in other views of the application, then you can just create the context in that view.

Step 2: You define as what are all the UI elements(UI elements are all the elements/objects which make up the final user interface) and MAP the context elements to the UI elements.

Step 3: Now comes the MODEL part, where you get the data from the UI elements, perform some logic and then output the data again using various types of UI elements.

Since you map the CONTEXT nodes/fields/elements to UI, whatever user enters on the UI, it is available in the CONTEXT so inside your model you need to write code to access the context.

Actual Code Logic:

SAP provides some pre-defined interfaces to access the context nodes. IF_WD_CONTEXT_NODE is the interface to access the complete context node and WD_CONTEXT is the instance generated by SAP for that view and it is the means of communication to access all the components of that view in the program.

To access each node of that context, you need to have a reference local instance of the context and then map the appropriate node to that context.

In my example, I created 2 nodes in the context, first node consists of all the fields for input selection(Node name - INPUT_SELECTION) and the second node is the output data node(Node name- OUTPUT_SELECTION).

Inside the program, I created 2 data references, lo_context_node to access Input_Node and lo_context_output to access the output_node.

Now, create instance or map the actual node to the data reference using below statement,

lo_context_node = wd_context->get_child_node( name = 'INPUT_SELECTION' ).
lo_context_output = wd_context->get_child_node( name = 'OUTPUT_SPFLI' ).

now, our local variables will have instance of those specific nodes. Using the methods of if_wd_context_node, get the values entered on the UI, as shown below,

CALL METHOD lo_context_node->get_attribute
EXPORTING
name = 'CARRID'
IMPORTING
value = lw_carrid.

this will get the value of CARRID attribute which is inside INPUT_SELECTION node into our local variable.

Write necessary logic to get the data from tables or call specific methods or function modules and the get the final output data.

Once you get the final output data, we already have an instance of our output context, just bind the data to the output context node as shown below,

CALL METHOD lo_context_output->bind_table
EXPORTING
new_items = it_spfli_data
* set_initial_elements = ABAP_TRUE
* index = .

Above statement will bind the output data to the context node, and our UI which is created in the view has a TABLE UI element and it is mapped to OUTPUT_SPFLI node of the context which will be shown in our output.

In my example, I just have 1 single view, it doesnt deal with navigation from 1 view to another view or transferring data from 1 view to another view and other steps. Those will follow in my next posts.