Skip to Content

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

1.PNG

Step 2:

Provide the assistance class name as shown below

2.PNG

Step 3:

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

3.PNG

Step 4:

Create an inbound plug for navigation as below

3_1.PNG

Step 5:

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

4.PNG

Step 6:

Create an inbound plug for navation as below

4_1.PNG

Step 7:

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

5.PNG

Step 8:

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

5_1.PNG

Step 9:

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

5_2.PNG

Step 10:

Create an inbound plug for navigation as below

5_3.PNG

Step 11:

Open view V_MAIN and create OUTbound plugs as shown below

6.PNG

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

7.PNG

Step 13:

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

7_1.PNG

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

7_2.PNG

Step15:

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

7_3.PNG

Step 16:

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

7_4.PNG

Step 17:

Now, the navigation links are created as below

7_5.PNG

Step 18:

Create an outbound plug TO_EMPTY_VIEW in window as below

7_6.PNG

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

/wp-content/uploads/2014/02/7_7_392358.png

Step 20:

Now, empty view has been embedded successfully as below

7_9.PNG

Step 21:

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

7_91.PNG

Save application and activate

Create WDA application as below

8.PNG

Output:

We have the below data in table

O.PNG

If user “TEACHER1” logs in and run the application, the Teacher’s page gets displayed as below

O2.PNG

If user “STUDENT1” logs in and run the application, the Student’s page gets displayed as below

O3.PNG

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

O4.PNG

O5.PNG

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

o1.PNG

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

I appreciate your comments/feedback/suggestions

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Dharmkrit Bhagat

    Hi Rama,

    Thanks for writing such a nice article with step by step approach. Good work.

    An another approach can be done by creating custom parameter table. Maintaing master data for authorized user (if user is less) having field program_name (unique id) , user . etc

    Or by using agr_users also.

    Within program select and check if user  is not available through error message .

    (0) 
    1. Ramakrishnappa Gangappa Post author

      Thanks a lot Bhagat 🙂 for your feedback.

      Could you please through some more light on how the parameter table can be created and used for authorizations?

      Regards,

      Rama

      (0) 

Leave a Reply