Thursday, June 07, 2012

Authorization Check (FM)

After our QA checked our program, she found out that we are not checking auhtorization before calling a tcode. Upon checking the program, other "CALL TRANSACTION" statement is using function module " AUTHORITY_CHECK_TCODE" to check the authority before calling a tcode. This is very simple to use by just passing the tcode you want to call and make sure to declare the exception parameters for you to be able to handle the appropriate returned error code.

      CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
        EXPORTING
          tcode  = [tcode]
        EXCEPTIONS
          ok     = 1
          not_ok = 2
          OTHERS = 3.
      IF sy-subrc NE 1.
        wa_errmsg-type = c_error.
        wa_errmsg-message = 'No authorization for Transaction'(031).
        APPEND wa_errmsg TO p_tb_errmsg.
      ELSE.
 

Happy coding everyone!!