Wednesday, 12 June 2013

Disable Fields in Selection Screen of Report Program based on Authority Check.

1.  First check for Required condition ( Checking authorization in  current example) in INITIALIZATION . Based on condition use LOOP AT SCREEN to disable or make the field invisible.

Example       
  INITIALIZATION.
gv_readonly_flag 'X' .
 LOOP AT SCREEN.

      IF screen-name EQ 'P_R1'.
        break mavb.
        screen-invisible '1'.
        screen-active '0' .
        MODIFY SCREEN.
      ENDIF.

    ENDLOOP.



2. Keep a flag when you run the above code and copy the same code in  AT SELECTION-SCREEN OUTPUT.  as initially the field will be invisible in the selection screen but when the user press ENTER, the field will become visible as INITIALIZATION will be executed only once in the life of program, so when the user press enter the field will become visible. So we have to write the same code in  AT SELECTION-SCREEN OUTPUT.
Example

  AT SELECTION-SCREEN OUTPUT.
  IF gv_readonly_flag 'X' .
    LOOP AT SCREEN.

      IF screen-name EQ 'P_R1'.
        break mavb.
        screen-invisible '1'.
        screen-active '0' .
        MODIFY SCREEN.
      ENDIF.

    ENDLOOP.

  ENDIF.



Example with a scenario for Authorisation check :

  SELECTION-SCREEN  BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS p_r1  RADIOBUTTON GROUP g1 ,
             p_r2  RADIOBUTTON GROUP g1 .

SELECTION-SCREEN END OF BLOCK b2.



  INITIALIZATION.

  CALL FUNCTION 'AUTHORITY_CHECK'
    EXPORTING
      user                sy-uname
      object              'ZQMCERTMGR'
      field1              'ZQMCRTACVT'
      value1              '01'
    EXCEPTIONS
      user_dont_exist     1
      user_is_authorized  2
      user_not_authorized 3
      user_is_locked      4
      OTHERS              5.

  IF sy-subrc NE 2.

    CALL FUNCTION 'AUTHORITY_CHECK'
      EXPORTING
        user                sy-uname
        object              'ZQMCERTMGR'
        field1              'ZQMCRTACVT'
        value1              '03'
      EXCEPTIONS
        user_dont_exist     1
        user_is_authorized  2
        user_not_authorized 3
        user_is_locked      4
        OTHERS              5.
    IF sy-subrc EQ .
      gv_readonly_flag 'X' .
    ELSEIF sy-subrc NE .
      MESSAGE 'User is not Authorised'(019TYPE 'E' .
      LEAVE TO LIST-PROCESSING.
      EXIT.
    ENDIF.
  ENDIF.

  IF gv_readonly_flag 'X' .

    LOOP AT SCREEN.

      IF screen-name EQ 'P_R1'.
        break mavb.
        screen-invisible '1'.
        screen-active '0' .
        MODIFY SCREEN.
      ENDIF.

    ENDLOOP.

  ENDIF.

AT SELECTION-SCREEN OUTPUT.
  IF gv_readonly_flag 'X' .
    LOOP AT SCREEN.

      IF screen-name EQ 'P_R1'.
        break mavb.
        screen-invisible '1'.
        screen-active '0' .
        MODIFY SCREEN.
      ENDIF.

    ENDLOOP.

  ENDIF.



Explanation : P_R1 and P_R2 are radion buttons. P_R1 is for write access and P_R2 is for read only report. So when we check for authorisation using the Authority_check function module, if user has authorisation for write access, authority FM with field value '01' will pass, if the user doesn't have write access , then we check for read access.If user has read access then we make the radio button P_R1 invisible as per above code.

No comments:

Post a Comment