Académique Documents
Professionnel Documents
Culture Documents
Part I
The title is inspired from the book “Let us C”. A very popular book on “C” at
our part of the world.
Web Dynpro: It is neither a tool with only drag and drop (those who have
actually not worked would say this) nor is it something only for the Geeks
(some who have worked might flaunt). So, neither under estimate it nor be
scared of it. It is like any other area of SAP ABAP, which helps the developer
to achieve the requirement and deliver some cool applications.
In this post and the series to follow, we are planning to provide the concepts
to understand the basics of ABAP Web Dynpro. This series would act as a
launching pad for our readers to develop their initial Web Dynpro applications.
We would hand hold you and provide you some actual project requirements
and how to achieve them.
This series would not give you detailed theories. There are tons of materials
already available for theories and practice.
This would be different than others and would just concentrate on the basics;
and some practical tweaks and tricks.
Let’s start..
We can make vague analogy between Web Dynpro terms and classical ABAP
terms for simplicity. Some of them are:
Context <=> Variable
Context node <=> Internal Table/Structures/Work Areas
Context attribute <=> Fields of variables (single field or fields of
structure / internal table)
Component Controller <=> TOP include program (declare global variables)
Custom/View Controller <=> Sub routine ( declare local variables )
Windows <=> Windows ( container )
Views <=> Views ( content )
WD Applications <=> Transaction codes
There are numerous UI elements in WD ABAP. But the most commonly used
ones are:
1. Tray
2. Group
3. Transparent Container
4. Label
5. Text Edit/View
6. Input Field
7. View Container
8. Button
9. Message Area
10. Checkbox
11. Radio Button
12. Drop down by Index
13. Drop down by Key
14. Link to Action
15. Tab Strip
16. Toggle Button
Assistance Class.. What exactly is it?
Assistance Class is the “M” of the famous “MVC”, Model View Controller. All the
extraction, massaging and modelling should be done in the assistance class.
What are the steps to start a Web Dynpro assignment?
Like any normal program, you should first define the Types and Data
(variables, internal tables, work areas), i.e.in WD, you should declare the
contexts.
Usually, normal program has selection screen parameters and select options.
In most cases, the selection screen data are global. Similarly in WD, the
contexts for the initial view(s) are usually defined at the Component Controller
Level (as they are global).
In normal programs, the global variables are automatically available in all
subroutines. In WD, the context of the global component controller are not
automatically available to other controllers. We need to map the context of
component controller to the respective custom/view controllers. By mapping,
it means, context with the same name is created in the custom/view
controllers (and they are linked). It is like passing parameters to the sub
routines in normal ABAP. If the parameters are changed in the sub routine,
the same is reflected in the calling program. Similarly if the context of the
component controller is changed in the custom/view controller, it is reflected
globally.
Let’s Web Dynpro. Part I
In Part I, we gave you a very basic overview of Web Dynpro. In this part we
will create one Web Dynpro Application.
Before we develop our first Web Dynpro application, let me ask, what steps
do you follow while writing a normal ABAP program/report in SE38/SE80,
which has a selection screen; an output screen and a custom transaction
code?
Happy to get your first Web Dynpro Functional Specification. Let’s jump
into the system.
Give a meaning description and name (as shown in next picture) for your
default/main Window and View. Name it as per your project standard.
Usually we have WI_ or W_ for windows and VI_ or V_ for views. Then save
it. Give appropriate package and transport number else save it as local
object if you do not want to move to next environment. Now you have
created your first WD component which is empty.
Step 2: Declare selection screen parameters. Since it would be used
globally, let us define the variable (context) in the component controller
(global/top). Double click on COMPONENTCONTROLLER in the left panel and
click the Context Tab in the right panel.
Right click the CONTEXT ->Create-> Node. This is the name of your
structure used in selection screen parameter. We generally use CN_ for
context node and CA_ for context attribute. Give a meaningful name and hit
enter.
You created a structure, but it is empty. You need fields in the structure to
make it complete. Right click on the context name CN_SELECTION_SCR -
>Create->Attribute; give a name and data-type of the field and save and
activate all the objects of the components. This is the global variable for the
selection screen.
Tip: Try to activate your component after every major change/development
so that if any error, you can find and resolve it easily. If you activate at the
end, after creating everything, then it might be little more tiresome to
resolve the issue.
As I mentioned in PART I, the global variable are not directly available to the
views. We need to make the view know that the global variable
(CN_SELECTION_SCR) would be used in that view. This can be done by
dragging the COMPONENT CONTROLLER Context attribute to View Context.
Expand the View in the left panel. Double click on the view name. Click the
Context Tab on the right Panel. On the right panel there is a split. Left for
View and Right side for COMPONENT CONTROLLER Context. Left click on the
CONTEXT CN_SELECTION_SCR hold and drag and put it on top of V_MAIN
CONTEXT on the left. This is like USING/CHANGE Parameters of SUB
ROUTINE (PERFORMS) in normal program.
Now we are good to design the screen. View->Layout. Right click on
ROOTUIELEMENTCONTAINER and insert one TRANSPARENT CONTAINER.
Transparent containers are just holder of UI elements. Usually, related UI
elements are collected in a TRANSPARENT CONTAINER.
Now let us define an input parameter for the screen (just like we do in
SE38). Right click on Transparent Container and create Input field.
This is just a variable, but what data would it hold? We will link this input
field to the USERID field defined in the context CN_SELECTION_SCR. Click on
the yellow icon on the right side of value property and bind it with USERID.
It is just like our PARAMETERS: P_INPUT TYPE XUBNAME. Any value entered
in this parameter in selection screen is passed to P_INPUT and it can be used
in the whole program.
Let us give a meaningful label to the selection screen parameter. Just like in
SE38, we create Selection Screen text, in the similar way, a LABEL UI
element tagged to Input Field would act as its text, which would be displayed
in the selection screen. Right click on Transparent Container and create the
Label. Populate the Label For field.
By default it would be on the right side of the field. Move it up so that it is on
the left side.
Let us look how the window looks. In the main window, the default main
view is assigned. So, whatever we have designed till now is available to be
displayed in the window.
Step 3: WD Application like our familier Transaction Code created in SE93:
At this juncture, you would be tempted to see how your selection screen
looks like. For that we need to create the application (like you need a
transaction code for a program). Right click on your Component and create
the application and save it.
Now you can execute it by F8 or by right clicking the application and Test.
You would like to see the three attribute in one row, not in one column. For
this we need to change the layout type to Matrix Layout. We would speak
more about Flow, Matrix data and Matrix Head data layout in subsequent
sessions.
Let us see the screen again.
It has the input field and the execute button. But, what will the button do,
we have still not defined the data extraction and display logic.
Check the READ radio button and then hit the CONTEXT and choose the
CONTEXT field which is bound/linked to the INPUT field. Hit enter. All the
code is generated for you. Remove the commented code and some check
codes which are not needed for our scenario. Whatever user enters in
IP_USERID field in selection screen is available in variable lv_userid.
Now, whatever data you want to display in the three attribute of the output
context, we need to SET them, i.e. we can use the same magic wand to SET
the CN_USER_DETAIL context as shown.
The LS_CN_USER_DETAIL structure would display the user details. But, the
structure is still empty. We need to select the data and populate
the structure. We will write a simple select statement and populate the
structure as shown.
PS: This is the only piece of code we write for this application.. Isn’t it
awesome..
Uffff !!! We have done all steps. Fetched data based on input field and
populated the output structure. And linked all the UI elements to the
underlying context.
Let us test our first baby.. Let me enter an SAP user id present in our system
and hit the Get Data button. Abracadabra… Details are displayed..
This was one of the simple valid project requirements. Please do not smile,
this was one of the requirement in one of our project.. We would add on
the complexity and explore the different features of Web Dynpro in
subsequent parts. Till then, please play around this component and stay
tuned.
Lets start..
Step 1: Create your component in SE80. Go to View Context and define the
selection screen context (CN_SEL_SCREEN). Three attributes/fields i.e.
userid, from date and to date are defined. Similarly define output table
context (CN_RESULT). As per requirement, four fields / attributes i.e. sales
order, created date, createdy by and document type are defined.
Step 2: Go to View Layout and create input fields. Group them in transparent
container. Do not forget to create Labels and align them. Remember to tag
one label with one input field in the LabelFor property of Label.
Your From Date and To Date might not be in one line.. .. Just change the
Did you bind the input fields to the context? By now, you should know
that, context is your work area or variable or internal table. The UI element
with which you tag/bind it, that context would hold your data.. Freeze it..
Step 3: Anxious to see how your screen looks like. Create an application for
your component (right click and created), give a name and description and
save it. Now right click the application and test or hit F8 to test your screen.
Tip: Please keep your input fields in different transparent containers. Check,
we have different containers for different UI elements. You might not imagine
its importance in simple developments. But for complex one with lots of UI
elements, these transparent container would help in easy grouping and
manipulation.
Step 4: Create another transparent container and pur TABLE UI element in it.
This would be our final internal table. Bind it to the CN_RESULT context
which we have already defined.
Still your table shows: Table does not contain visible columns.. What
does it mean?
You have one more step to do for Tables. Although you have bound the
datasource with CN_RESULT, you still need to create a binding and define
how it should look like.
Right click on the Table UI element -> Create Binding and define the Cell
editior for the table columns. We have shown it as text field. You can show it
as button or input fields etc as per your requirement.
Magic.. your columns are visible now..
write by him/herself for this application. Isn’t this cool. Less code…
This is a simple post to show output in table. We should handle the errors,
also the output table skeleton should not be shown when we see the page
first. Columns should be displayed once user hits the Execute button. Also,
the date range should be handled so that, To date is not less than From date.
[adToAppearHere]
Why is it displaying?
Because, we have hardcoded the UI element to be always visible (as shown
in screen shot).
Solution:
Instead of hard coding it to visible, we should point it to a variable, which
should be blank (false) when the user first enters the screen. Once the user
hits the execute button, that variable should be flagged (true) to indicate the
visibility.
Step 1: Define a context node (cardinality 1:1 should be enough) and define
an attribute (say set_table_visible). This attribute is our variable, which we
would bind with the output table visibility parameter.
Step 2: Bind the visibility property with set_table_visible attribute as shown
in figure. Done!! The output structure would not be visible now.
Step 3: But, it would not be visible even if you hit execute. Because, you
have not written the logic to set the attribute to true, when execute button is
hit. In the method which is called on execute button, set the attribute to
true, using the magical wand as shown in the screenshot.
After removing the commented lines, your code should look like below. You
just need to set the variable to ‘X’ or ABAP_TRUE. Only one line of code has
to be written as shown in line 43 of screenshot.
Step 4: Test it. Your output is visible only when you hit the Execute button.
B) Error message should be displayed if mandatory fields are not
entered
Step 1: Make the State property of the input field to “required”. This would
put a small red asterisk (*).
more step.
Link for code snippet for Part III and Part IV in the Execute button
method: OnActionExecute
[adToAppearHere]
We need to use:
a) Interface View ‘TABLE’ of component SALV_WD_TABLE
b) Interface node ‘DATA’ of component SALV_WD_TABLE.
The other very oftenly used standard components are WDR_OVS (for Object
Value Selector OVS) and WDR_SELECT_OPTIONS (for select options).
Let us use the same example we did in Part III. This time we are declaring
global contexts in ComponentController (not necessary, just for
demonstration).
Drag these nodes in the main View and now they are available in the view
(just like we pass variables as parameters in the Subroutine/Performs to
make those variable available in the subroutines).
Hope, by now you know how to create button and link it to an actions
(screen shot below in case you forgot).
For displaying the ALV output, we can use View Container UI Element
(figure above). The View Container UI Element need NOT be bound to any
context here. We will show later how it is bound.
Hope you have bound all other screen elements.
METHOD onactionexecute .
ENDMETHOD.
The View Container UI Element is still not bound to any context. So the final
step is to link a context to the final output. For this we would leverage the
already existing standard WD Component, SALV_WD_TABLE.
Go to the Window W_MAIN. On the right side, right click on the W_MAIN
window and select EMBED View. Choose the view V_MAIN. View V_MAIN
along with the View Container UI element is embedded in the Window. Now
right click on the View Container VC_RESULT and chose EMBED View select
Component Usage View TABLE. Your window is linked to standard component
SALV_WD_TABLE’s TABLE view.
Now we need to bind the output data to the context of the SALV_WD_TABLE.
The context we would be binding to is “DATA”. Click on the
INTERFACECONTROLLER of the Component Usage CU_DETAIL. Check the
icon under “DATA” in context has single arrow underlined. Now we need to
let the SALV_WD_TABLE know, what data would be bound to the “DATA”
context. In our example, CN_RESULT context has the final data, so, we drag
CN_RESULT from right to the “DATA” context on the left.
Check, the arrow is two way now and also you should get the message
“External mapping for context element “DATA” was defined”.
This is one of the simplest way to show ALV. In real project scenarios, you
rarely use one ALV output. In the next parts, we would explore multiple ALVs
and also different features of the ALV list; like onclick of a row/field, make
the ALV display/input only, activate/deactive standard features of ALV, put
custom buttons programatically etc.
[adToAppearHere]
Let us check the important lines related to the custom buttons in this
method.
Create object, provide the image source (optional), Set the text of the button
(optional), provide the function code and add/set the button.
Please click the link for complete code snippet for the
ALV_SET_AVAIL_PLANT. You can use this as your template for all ALV
properties. Just change the field names of your table and you may or may
not need the button parts (shown in the above figure).
Give special emphasis to the function code. Make sure of the case of the
alphabets. You need to give the exact function code to the Event Handler
method as stated below.
Once the ALV Property is set, we need to declare another Event Handler
method to capture the clicks on the ALV; for our example it is
SELECT_DESELECT method.
In this method we need to identify the function code and call corresponding
method for action/activity you want to perform. Please see the function code
in the event handler method and the ALV property method. They are exactly
the same.
Hope, with the above information, you would be able to add as many buttons
you want and make your ALV more interactive. Please let us know, if we
need to provide more information on this topic. We would be happy to add
them in this post.
——————————————————————
Hey Guys,
Have folks telling me that the field was there yesterday because they were
using the link yesterday. When they went in this morning it was gone.
——————————————————————
I went to the user’s desk who complained about the issue. I knew exactly
what had happened and the solution was simple. I right clicked at this screen
and restored the hidden UI element as shown below.
Right Click –> User Setting –> Invisible Elements –> Restore Input
Field
That user was happy with the quick fix. But, it was not the complete solution
my friend!! Later in the day, I got another email (below) saying some other
user complained again.
——————————————————————
It appears IT has not fixed the parts search page. The Manufacturer part
number field is missing again
This time, I did not go to anyone’s desk. I decided to fix it globally for all
users (once and for all). Let’s hit the last nail in the coffin.
Right Click –> User Setting –> More –> Reset User Settings for
Running Application
This time all changes done would be reset to original.. Happy Users!!
There might be number of ways to achieve it, but the easiest way we figured
out is elaborated in this post.
Step 1. Create your Web Dynpro component and application, extract all your
data and prepare a final table(s) which you want to download in excel.
PS: This template can be used for any excel download/formatting. It should
be changed / enhanced for extra features. But this template can be used as
starting point.
Step 5. Prepare a sample excel page you want as output from Web
Dynpro, with all formatting, coloring, borders etc. Make sure you have all the
formatting done.
Step 6. Save that excel as .XML. Open that saved XML in notepad/wordpad.
You will see XML codes. Scan through the code to get the STYLES. Different
Styles will have different format for different rows, cells or columns.
Step 7. Go back to Transformation program XML which is the copy of the
XML template attached. Now copy all your STYLES from excel XML to
program XML.
Step 8. At the top of Transformation program, define the tables and variables
/ workareas which would be imported. TABLE is your internal table which
would be sent from Web Dynpro. Make sure to add your TABLE and
variables. And remove unwanted.
Step 10. Similarly check the Header line of the table ( hard coding). For
example Material#, Created By, Material Type, Material Group. This would be
hard coded. The styles for this may or may not be same to that of the body
of table. We need to check the excel XML to figure out the style and copy the
same style to our Transformation Program.
Step 11. The TABLE body is to be populated in LOOP. The values would be
assigned from the field name (always UPPER CASE). The sequence in which
you call the fields, the structure of the Table is created in that way. See the
figure for the fields called and the structure created.
Make sure, your TABLE in transformation program and your Web Dynpro
internal table are same.
Please check the link below for excel XML code and the final Transformation
program code after making change to the Template. Scan through it to see
how we enhanced the template.
Link for the code snippets related to Transformation call: Sample code in
Method
Step 13. Lets test our development. Check, the color, border, text format
bold etc are there.
Hope we were able to guide you through. If you still have any
queries/suggestions / doubts, please leave your comment or contact us, we
would be happy to respond.
Straight talk today. Let me show you two outputs of the same Web Dynpro
ALV which has three fields; to put my point. Three columns in an ALV
are: Plant, Plant Name and a one character Flag say ‘Set‘.
a) Let us first define the data element as Flag for the one character field
‘Set’ in the context definition. Look at the output ALV.
b) Now, let us define the data element as WDY_BOOLEAN for the same one
character field ‘Set’. Mark the output ALV again.
Do you see the difference?
The second output shows that the “Set” field is displayed as checkbox.
Recently we had our upgrade to EhP740 and with it came the new look and
feel. NEW Operators, VALUE Operators, BOXes, beautiful Google like
suggestions while typing the words etc are really impressive. Even the UI
screens have soothing appearence with advanced features (SAP is really
getting ready for mobile devices, clouds). But our Business users who are so
used to the old UI screens were not so fascinated with the new UI features.
[adToAppearHere]
You might be wondering, has SAP really removed the filter button. Answer is
‘No’. SAP has moved a step ahead. It has filter and sort functionality at
column level (as in Excel) which I believe is very useful. But, who can
Personlly, I like the new feel. Is going back one step to old look, justifiable, is
After little research one of our team member figured out that with Ehp7, we
can add some parameters in the Web Dynpro application to get what
our users wanted.
Most of our young guns do not hesitate to create as many table types as
needed without pondering if we have an alternative way to achieve the same
One of the most commonly done activity is to declare a table type which is
used only once in the Attribute declaration. Say, you already have a data
dictionary structure but you want to define an internal table. You can use the
same structure. Just add TABLE OF or STANDARD TABLE OF <structure
name>. You will get a warning message “The type TABLE OF <structure>
doe not exist” or “The type STANDARD TABLE OF <structure> doe not exist”.
Just hit return/enter key one more time and you are good.
In the above screenshot ZEMAIL_ATT_TAB is a table type and ZEMAIL_ATT is
a structure. We could have avoided the ZEMAIL_ATT_TAB table type
declaration in SE11.