Tuesday, September 4, 2012

Call Transaction Authorization

Many times you find useful to call a transaction from your program. Most common request when creating an ALV report for example is "...the user should click on the customer number field and XD03 should be called..." or something similar.
The first response from your side would be, "...sure this is piece of cake...". So in your code after fetching the customer number you would call transaction XD03.

CALL transaction 'XD03' AND skip first screen.

I am not sure how many of you know that with call transaction you bypass the standard authorization check for S_TCODE object. So it would be possible for someone to have access in a transaction that it is not intended to have . Only when you use LEAVE TO transaction the S_TCODE authorization check is called.

So it is necessary to do an authorization check for object S_TCODE prior using CALL TRANSACTION.
Another alternative ( and much better in my opinion) would be to use the FM ABAP4_CALL_TRANSACTION

This FM gives you the option to skip first screen, to pass parameters or even batch input data and of course you won't have to worry and implement authorization checks.


DATA lt_mem TYPE TABLE OF rfc_spagpa.
FIELD-SYMBOLS <lfs_mem> TYPE rfc_spagpa.

APPEND INITIAL LINE TO lt_mem ASSIGNING <lfs_mem>.
<lfs_mem>-parid  = 'KUN'.
<lfs_mem>-parval = lv_kunnr.

APPEND INITIAL LINE TO lt_mem ASSIGNING <lfs_mem>.
<lfs_mem>-parid  = 'BUK'.
<lfs_mem>-parval = lv_bukrs.

CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
  EXPORTING
    tcode       = 'XD03'
    skip_screen = 'X'
  TABLES
    spagpa_tab  = lt_mem
  EXCEPTIONS
    OTHERS      = 1.
ENDIF.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.