Hi Friends,
Many of us might have come across the requirement ‘to display the text of the fixed values
of particular data element’ in ABAP WEBDYNPRO.
The following is the blog that describes how to achieve this requirement using classes with example.
Take for example:- WebDynpro: Table Cell Design
We may have to display/read the fixed values of the data element ‘WDUI_TABLE_CELL_DESIGN’, when we working with
celldesign of particular field.
Now let us observe the ‘WDUI_TABLE_CELL_DESIGN’ in SE11.
Double click on the data domain WDUI_TABLE_CELL_DESIGN and go to the value range tab as follows
Now we need to read the above shown fixed values and display or use them in one of our
WEBDYNPRO Requirement. How to get those Using classes? Not with function module.
Let us see how to do this globally in SE24:-
**********************************************************************************************************
A small recollection of RTTS for those who want to know about RTTS before going SE24
***********************************************************************************************************
If we recollect the concept of RTTS (Runtime type services), RTTS further classified into
RTTI (Runtime type identification) and RTTC (Runtime type creation).
There is a hierarchy of Runtime type services(classes) in RTTC is as follows.
The super class of all the classes is CL_ABAP_TYPEDESCR. If we observe the method of each following classes, the returning parameter of all the methods is Reference of superclass CL_ABAP_TYPEDESCR
The above is the Hierarchy of Runtime Type services(classes).
The reason we are discussing about the above hierarchy is, if we see there is a Runtime
service(Class) in the above hierarchy called ‘CL_ABAP_ELEMDESCR’ which serves our purpose in this requirement of reading the text of fixed values using classes. Rest of the Runtime type services are useful for data reference,
complex data types, classes and interfaces respectively.
WDUI_TABLE_CELL_DESIGN is a data element which used for a particular field, a field comes under
Elementary data type category, so to describe the properties of this particular
elementary data type, we need to work with runtime type service ‘CL_ABAP_ELEMDESCR’.
Note:- Every Runtime type service(class) has 4 different static methods used to describe the
type information as follows.
- DESCRIBE_BY_DATA
- DESCRIBE_BY_NAME(When we know the
pre-defined name of particular data element then we will use this method as
follows) - DESCRIBE_BY_OBJECT_REF
- DESCRIBE_BY_DATA_REF
*******************************************************************
Go to SE 24
Give the Runtime type service ‘CL_ABAP_ELEMDESCR’.
Execute the class by click on Execute Button, it will give as follows
Click on ‘Continue’ button, and then it will give as follows
Execute the DESCRIBE_BY_NAME method.
It gives the following AND give our Data element ‘WDUI_TABLE_CELL_DESIGN’ as
follows in P_NAME and click on execute button
It gives as follows
Now click on Edit Object REFERENCE as follows
Click on the circle and drag down
Now execute the Method GET_DDIC_FIXED_VALUES
It will give as follows
Now execute directly, it will show the text of fixed values as follows
Click on above entries
Now Let us see how to achieve the same programmatically as follows
Program
The same Program:-
REPORT zrtts_test1.
"The following example demonstrtates both the methods of DESCRIBE_BY_NAME and DESCRIBLE_BY_DATA.
"DESCRIBE_BY_NAME we will use when we have the name of the pre defined data object
"DESCRIBE_BY_DATA we will use when we have the name of the data object declared with the keyword DATA
DATA: lr_elem1 TYPE REF TO cl_abap_elemdescr,
lr_elem2 TYPE REF TO cl_abap_elemdescr,
lt_values TYPE ddfixvalues,
lv_cell TYPE wdui_text_view_design.
"Here we are doing the wide casting, because the return parameter of each method of runtime service is superclass CL_ABAP_TYPEDESCR.
"Now we need to covert that reference to our class(CL_ABAP_ELEMDESCR) reference variable by wide casting. Then our reference variable
"can access the its own class methods describe_by_name, describe_data
lr_elem1 ?= cl_abap_elemdescr=>describe_by_name('WDUI_TABLE_CELL_DESIGN').
lr_elem2 ?= cl_abap_elemdescr=>describe_by_data( lv_cell ).
lr_elem1->get_ddic_fixed_values(
EXPORTING
p_langu = sy-langu
RECEIVING
p_fixed_values = lt_values
EXCEPTIONS
not_found = 1
no_ddic_type = 2
OTHERS = 3
).
IF sy-subrc EQ 0.
DATA: ls_value LIKE LINE OF lt_values.
LOOP AT lt_values INTO ls_value.
WRITE: / ls_value-low, ls_value-ddtext.
ENDLOOP.
ENDIF.
REFRESH lt_values.
WRITE: / '***********************'.
lr_elem2->get_ddic_fixed_values(
EXPORTING
p_langu = sy-langu
RECEIVING
p_fixed_values = lt_values
EXCEPTIONS
not_found = 1
no_ddic_type = 2
OTHERS = 3
).
IF sy-subrc EQ 0.
* data: ls_Value like line of lt_values.
LOOP AT lt_values INTO ls_value.
WRITE: / ls_value-low, ls_value-ddtext.
ENDLOOP.
ENDIF.
When we execute the program, we will get the following output along with fixed values and their text, so that we can use that internal
table having those values in our WEBDYNPRO component to display in our view
OUTPUT:-
Thank You All,
VSV