Quantcast
Channel: SCN : All Content - Web Dynpro ABAP
Viewing all articles
Browse latest Browse all 3667

How to get the text of Fixed values using class

$
0
0

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.

 

1.JPG

2.JPG

 

 

Double click on the data domain WDUI_TABLE_CELL_DESIGN and go to the value range tab as follows

 

3.JPG

 

 

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

 

4.JPG

 

 

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.

 

 

  1. DESCRIBE_BY_DATA
  2. DESCRIBE_BY_NAME(When we know the
    pre-defined name of particular data element then we will use this method as
    follows)
  3. DESCRIBE_BY_OBJECT_REF
  4. DESCRIBE_BY_DATA_REF

 

 

 

*******************************************************************

 

Go to SE 24

5.JPG

 

 

Give the Runtime type service ‘CL_ABAP_ELEMDESCR’.

 

6.JPG

 

 

Execute the class by click on Execute Button, it will give as follows

 

7.JPG

 

 

Click on ‘Continue’ button, and then it will give as follows

8.JPG

 

 

Execute the DESCRIBE_BY_NAME method.

 

9.JPG

 

 

It gives the following AND give our Data element ‘WDUI_TABLE_CELL_DESIGN’ as
follows in P_NAME and click on execute button

 

10.JPG

 

 

It gives as follows

 

11.JPG

 

 

Now click on Edit Object REFERENCE as follows

 

12.JPG

 

 

Click on the circle and drag down

 

13.JPG

 

 

Now execute the Method GET_DDIC_FIXED_VALUES

 

 

It will give as follows

 

14.JPG

 

 

Now execute directly, it will show the text of fixed values as follows

 

15.JPG

 

 

 

Click on above entries

 

16.JPG

 

 

 

Now Let us see how to achieve the same programmatically as follows

 

 

Program

 

17.JPG

18.JPG

 

 

 

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:-

 

19.JPG

 

 

Thank You All,

 

 

VSV


Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>