CALL TRANSACTION使用及传参数和权限检查(authority-check)详解编程语言

常见使用方法:

方法1

CALL TRANSACTION T-CODE [AND SKIP FIRST SCREEN].

其中AND SKIP FIRST SCREEN表示根据输入的参数直接跳转到相关操作页面。

方法2

CALL TRANSACTION T-CODE WITH|WITHOUT AUTHORITY-CHECK  
 
                        USING bdc_tab [OPTIONS FROM opt].

常用传参方法:

传参1:

SET PARAMETER ID 参数ID FIELD 传入参数值.

根据被调用T-CODE参数字段的“参数ID”传入值。VA03为例

SET PARAMETER ID ‘AUN’ FIELD ‘订单号’.

CALL TRANSACTION使用及传参数和权限检查(authority-check)详解编程语言

传参2:通过方法2 BDC的方式传入参数值

使用方法参考系统标准DEMO程序:DEMO_CALL_TRANSACTION_BDC

REPORT demo_call_transaction_bdc. 
 
CLASS demo DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS main. 
ENDCLASS. 
 
CLASS demo IMPLEMENTATION. 
  METHOD main. 
 
    DATA class_name TYPE c LENGTH 30 VALUE 'CL_ABAP_BROWSER'. 
 
    DATA bdcdata_tab TYPE TABLE OF bdcdata. 
 
    DATA opt TYPE ctu_params. 
 
    bdcdata_tab = VALUE #( 
      ( program  = 'SAPLSEOD' dynpro   = '1000' dynbegin = 'X' ) 
      ( fnam = 'BDC_CURSOR'       fval = 'SEOCLASS-CLSNAME' ) 
      ( fnam = 'SEOCLASS-CLSNAME' fval = class_name ) 
      ( fnam = 'BDC_OKCODE'       fval = '=WB_DISPLAY' ) ). 
 
    opt-dismode = 'E'. 
    opt-defsize = 'X'. 
 
    TRY. 
        CALL TRANSACTION 'SE24' WITH AUTHORITY-CHECK 
                                USING bdcdata_tab OPTIONS FROM opt. 
      CATCH cx_sy_authorization_error ##NO_HANDLER. 
    ENDTRY. 
 
  ENDMETHOD. 
ENDCLASS. 
 
START-OF-SELECTION. 
  demo=>main( ). 

备注:如果只需要调整到调用T-CODE的参数输入页面,录BDC的时候不需要输入BDC_OKCODE。

实际开发案例

T-CODE: ZPSR018A  对应程序:ZPSR018_CONFIRM。

负责人编号  需要传入值、停留在选择页面

CALL TRANSACTION使用及传参数和权限检查(authority-check)详解编程语言

  DATA: lt_bdcdata_tab TYPE TABLE OF bdcdata, 
        ls_opt         TYPE ctu_params. 
 
  DATA(lra_vernr) = gra_vernr[]. 
 
  READ TABLE lra_vernr INTO DATA(ls_vernr) INDEX 1. 
  IF sy-subrc = 0. 
    DATA(lv_vernr_low) = ls_vernr-low. 
  ENDIF. 
 
  SORT lra_vernr BY low DESCENDING. 
  READ TABLE lra_vernr INTO ls_vernr INDEX 1. 
  IF sy-subrc = 0. 
    DATA(lv_vernr_high) = ls_vernr-low. 
  ENDIF. 
 
  lt_bdcdata_tab = VALUE #( 
    ( program  = 'ZPSR018_CONFIRM' dynpro   = '1000' dynbegin = 'X' ) 
    ( fnam = 'BDC_CURSOR'       fval = 'S_PSPID-LOW' ) 
    ( fnam = 'S_VERNR-LOW'      fval = lv_vernr_low ) 
    ( fnam = 'S_VERNR-HIGH'     fval = lv_vernr_high ) ). 
 
  ls_opt = VALUE #( dismode = 'E' 
                    defsize = 'X' ). 
 
  TRY. 
      CALL TRANSACTION 'ZPSR018A' WITH AUTHORITY-CHECK 
                                 USING lt_bdcdata_tab OPTIONS FROM ls_opt. 
    CATCH cx_sy_authorization_error ##NO_HANDLER. 
  ENDTRY.

效果如下:

CALL TRANSACTION使用及传参数和权限检查(authority-check)详解编程语言

权限控制

CALL TRANSACTION使用及传参数和权限检查(authority-check)详解编程语言

根据帮助文档如下实现

  TRY. 
      CALL TRANSACTION 'F-02' WITH AUTHORITY-CHECK. 
    CATCH cx_sy_authorization_error. 
      MESSAGE s001(00) WITH '无此事务代码操作权限,请检查' DISPLAY LIKE 'E'. 
      RETURN. 
  ENDTRY.

如果程序没有上述权限异常控制,当权限不够时,可能会导致当前程序dump

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/17903.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论