Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
ramakrishnappa
Active Contributor
0 Kudos

Hello welcome again

Hope you have gone through the below link to know about

  • Create a custom table YTR_AUTH_CHECK
  • Generate the maintenance view & maintain the entries in the table
  • Create an assistance class YCL_RK_AUTHORIZATIONS and methods to get data from table

How to handle custom authorization checks in Web Dynpro ABAP - Part 1

Now, let us look at the process of creating a Web Dynpro ABAP application for handling authorization checks

4. Create Webdynpro ABAP component

Step 1:

Go to t-code SE80 and create WDA component as below

Step 2:

Provide the assistance class name as shown below

Step 3:

Create a view V_TEACHER for teacher's login and create the page header as shown below

Step 4:

Create an inbound plug for navigation as below

Step 5:

Similarly, create a view V_STUDENT for student's login and create the page header as shown below

Step 6:

Create an inbound plug for navation as below

Step 7:

Create a view V_ADMIN for administrator's roles and create the page header as below

Step 8:

Create a tabstrip with 2 tabs ( i.e. 1 for Teacher's data, 2: for Student's data ) as shown below

Step 9:

Create view containers inside each tab to embed the views V_TEACHER & V_STUDENT as below

Step 10:

Create an inbound plug for navigation as below

Step 11:

Open view V_MAIN and create OUTbound plugs as shown below

Add the below code in WDDOINIT( ) method of view V_MAIN

WDDOINIT( )

  " Data declarations
  DATA lo_api_controller     TYPE REF TO if_wd_controller.
  DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
  DATA lv_message            TYPE string.
  DATA ls_result             TYPE ytr_auth_check.

CLEAR: ls_result.

"=============================
  " Get user data
  "=============================
  wd_assist->get_user_data(
    IMPORTING
      es_result =  ls_result
  ).

"==============================

"Check user role

"==============================
  CASE ls_result-role_name.

    WHEN wd_assist->gc_role_admin.


      " Show administrator's page
      wd_this->fire_to_admin_plg( ).

    WHEN wd_assist->gc_role_teacher.


      "Show Teacher's page
      wd_this->fire_to_teacher_plg( ).

    WHEN wd_assist->gc_role_student.


      " Show Student's page
      wd_this->fire_to_student_plg( ).


    WHEN OTHERS.


      " User is not authorized, raise an error message


      lo_api_controller ?= wd_this->wd_get_api( ).

      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.

      lv_message =
       'You are not authorized, please contact your system admin !!!'.


*     report message
      CALL METHOD lo_message_manager->report_error_message
        EXPORTING
          message_text = lv_message.

      " Show empty view
      wd_this->wd_get_api( )->get_embedding_window_ctlr( )->fire_plug(
*        parameters =
          plug_name  = 'TO_EMPTY_VIEW'
      ).

  ENDCASE.

Step 12:

Go to window W_MAIN and embed the views using drag & drop technique as shown below

Step 13:

Now, the view have been embedded into window as shown below

Step 14:

Embed the views V_TEACHER & V_STUDENT inside the view containers of tabstrip of admin view by using drag & drop technique as shown below

Step15:

Now, the views are embedded successfully inside the view containers of admin view as below

Step 16:

Create the navigation links by using technique drag & drop of outbound plugs onto inbound plugs as shown below

Step 17:

Now, the navigation links are created as below

Step 18:

Create an outbound plug TO_EMPTY_VIEW in window as below

Step 19:

We need to embed an empty view, to show blank screen if user is not authorized.

Right click on window W_MAIN and choose "Embed Empty View" as shown below

Step 20:

Now, empty view has been embedded successfully as below

Step 21:

Crete navigation link from empty view inbound plug "SHOWEMPTYVIEW" to outbound plug "TO_EMPTY_VIEW" as below

Save application and activate

Create WDA application as below

Output:

We have the below data in table

If user "TEACHER1" logs in and run the application, the Teacher's page gets displayed as below

If user "STUDENT1" logs in and run the application, the Student's page gets displayed as below

If user "RAMA" logs in and run the application, the Administator's page gets displayed as below

Admin can see both teacher's data adn students data

If user entry not found in the table YTR_AUTH_CHECK, error message being displayed with empty view as below

Hope this document is helpful for those looking for handling custom authorization check in Webdynpro ABAP

I appreciate your comments/feedback/suggestions

5 Comments
Labels in this area