abap中程序跳转(全)

1.常用

1.CALL TRANSACTION

1.CALL TRANSACTION ta WITH|WITHOUT AUTHORITY-CHECK [AND SKIP FIRST SCREEN].

其中ta为事务码tcode使用时要打单引号(')

2. CALL TRANSACTION ta WITH|WITHOUT AUTHORITY-CHECK
                      USING bdc_tab { {[MODE mode] [UPDATE upd]}
                                    |  [OPTIONS FROM opt] }
                                       [MESSAGES INTO itab].

其中ta为事务码tcode使用时要打单引号(')

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

代码使用

SET PARAMETER ID 'AAT' FIELD 'RK'.
SET PARAMETER ID 'SPA' FIELD p_shar."这后面可以接变量(选择屏幕变量)
SET PARAMETER ID 'VTW' FIELD '10'."要传几个参数值就写几行
CALL TRANSACTION 'VA01'." AND SKIP FIRST SCREEN .
*++++++++++++++++++++++++++++++++++++++++++++++++++++++*
CALL TRANSACTION 'VA01' AND SKIP FIRST SCREEN .
"加上AND SKIP FIRST SCREEN会在传值之后直接执行或者回车
GET PARAMETER ID 'AAT' FIELD STR."获取值
*FREE MEMORY ID 'AAT'."memory id清除memory id

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

BDC传参

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.

WITH 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

其中的多值传递范例

DATA STR TYPE C LENGTH 25.

GET PARAMETER ID 'VKO' FIELD STR."获取SET ID的值

1.方法1

REPORT ZTXYY_1141.
TABLES:VBRK.
DATA STR TYPE C LENGTH 25.
SELECT-OPTIONS s_matnr FOR VBRK-VKORG ."MEMORY ID ZDEMO.

FREE MEMORY ID 'ZDEMO'."清除MEMORY ID
EXPORT s_matnr FROM s_matnr TO MEMORY ID 'ZDEMO'."传入MEMORY ID
*SET PARAMETER ID 'VKO' FIELD STR."实现单值输入
CALL TRANSACTION 'ZTXYY_1142' ."AND SKIP FIRST SCREEN.

程序ztxyy_1142定义了一个同名的tcode.

REPORT ztxyy_1142.
TABLES:vbrk.
DATA str1 TYPE c LENGTH 25.
SELECT-OPTIONS s_matnr FOR vbrk-vkorg.
SELECT-OPTIONS s_matnr2 FOR vbrk-vkorg.

INITIALIZATION.
*  GET PARAMETER ID 'VKO' FIELD str1."获取SET ID的值
  IMPORT s_matnr TO s_matnr FROM MEMORY ID 'ZDEMO'."读取MEMORY ID
  FREE MEMORY ID  'ZDEMO'."清除MEMORY ID

ABAP程序间跳转CALL TRANSACTION-CSDN博客

2.通过 BDC的方式传入多参数值

 DATA: lt_bdcdata_tab TYPE TABLE OF bdcdata,
        ls_opt         TYPE ctu_params.
lt_bdcdata_tab = VALUE #(
    ( program  = 'ZPSR018_CONFIRM' dynpro   = '1000' dynbegin = 'X' )
    ( fnam = 'BDC_CURSOR'       fval = 'S_PSPID-LOW' ) "其中fval为值 fnam为参数ID
    ( 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.

2.SUBMIT

SUBMIT {rep|(name)} [selscreen_options]
                    [list_options]
                    [job_options]
                    [AND RETURN].

... USING SELECTION-SCREEN dynnr

  SUBMIT zlxf003 VIA SELECTION-SCREEN"跳转后保留zlxf003程序执行后的第一个窗口
                   WITH p_date = p_date "字段传值也可以p_date = 1
                   WITH s_bukrs IN s_bukrs "多值传递 不可用s_bukrs-low = s_bukrs-low
                   WITH s_hkont IN s_hkont "多值传递 不可用s_bukrs-high = s_bukrs-high来实现
                   WITH p_rd1 = p_rd1
                   WITH p_rd2 = p_rd2
                   WITH p_rd3 = p_rd3
                   AND RETURN."从调用程序返回后可以返回到主程序的执行界面

SUBMIT 后面跟着的是程序名而不是tcode事务码

SUBMIT ZTXYY_1142 ."会直接调用程序ZTXYY_1142跳过选择屏幕
*点击返回按钮会直接返回原主程序代码界面

 将被调用程序设置为后台作业模式运行

FORM frm_bajob_data .
 
  DATA: lv_jobname  TYPE tbtcjob-jobname,
        lv_jobcount TYPE tbtcjob-jobcount.
 
  CONCATENATE 'ZLXF003_' sy-datum sy-uzeit INTO lv_jobname.
 
**********************************************************************
*   启动后台作业
  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname          = lv_jobname
      sdlstrtdt        = sy-datum
      sdlstrttm        = sy-uzeit
    IMPORTING
      jobcount         = lv_jobcount
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'.
    RETURN.
  ENDIF.
 
**********************************************************************
*  submit 程序
  SUBMIT zlxf003 AND RETURN
                   WITH p_date = p_date
                   WITH s_bukrs IN s_bukrs
                   WITH s_hkont IN s_hkont
                   WITH p_rd1 = p_rd1
                   WITH p_rd2 = p_rd2
                   WITH p_rd3 = p_rd3
                   USER sy-uname
                   VIA JOB lv_jobname
                   NUMBER lv_jobcount.
 
**********************************************************************
*   关闭后台
  "参数cant_start_immediate设置后天作业启动优先级,如果不设置的话,可能导致作业挂起,不能实时执行
  CALL FUNCTION 'JOB_CLOSE'
    EXPORTING
      jobcount             = lv_jobcount
      jobname              = lv_jobname
      laststrtdt           = sy-datum
      laststrttm           = sy-uzeit
      strtimmed            = 'X'
    EXCEPTIONS
      cant_start_immediate = 1
      invalid_startdate    = 2
      jobname_missing      = 3
      job_close_failed     = 4
      job_nosteps          = 5
      job_notex            = 6
      lock_failed          = 7
      invalid_target       = 8
      invalid_time_zone    = 9
      OTHERS               = 10.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'.
    RETURN.
  ENDIF.
ENDFORM.

abap中程序跳转(全)_第1张图片

abap中程序跳转(全)_第2张图片

3.LEAVE TO TRANSACTION

LEAVE TO { {TRANSACTION ta} | {CURRENT TRANSACTION} }
         [AND SKIP FIRST SCREEN].

1.使用后跳转到对应的事务码====点击返回按钮回到空会话窗口(原程序被关闭)

LEAVE TO TRANSACTION 'VA01' ."AND SKIP FIRST SCREEN.

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

2.函数实现跳转

1.TH_CREATE_MODE

新建session会话的函数

效果1.调用程序需要tcode,2.调用会打开新会话(sap只支持六个会话)

3.点击返回按钮无法返回原来的程序界面4.会进行权限检查

CALL FUNCTION 'TH_CREATE_MODE'
EXPORTING
   TRANSAKTION          = 'VL01N'        "事务码
*   DEL_ON_EOT           = 0
   PARAMETERS           = 'LIKP-VSTEL = 8510 LV50C-DATBI = 20140509 LV50C-VBELN = 35001147'     "事务码选择屏幕的参数
   PROCESS_DARK         = 'X'             "跳过初始选择屏幕(像va01的屏幕就跳不过去)
* IMPORTING
*   MODE                 =
EXCEPTIONS
   MAX_SESSIONS         = 1
   INTERNAL_ERROR       = 2
   NO_AUTHORITY         = 3
   OTHERS               = 4.

abap中程序跳转(全)_第3张图片

abap中程序跳转(全)_第4张图片

2.TH_CREATE_FOREIGN_MODE

新建session会话的函数

效果1.调用程序需要tcode,2.调用会打开新会话(sap只支持六个会话)

3.点击返回按钮无法返回原来的程序界面4.无法在函数中给屏幕字段传值

CALL FUNCTION 'TH_CREATE_FOREIGN_MODE'
  EXPORTING
    client                 = sy-mandt
    user                   = 'T008'  "系统中的用户名
   TCODE                  = 'VA01'    "事务码
   RETURN_ERROR           = 1
   CREATE_EXCLUSIVE       = 0
 EXCEPTIONS
   USER_NOT_FOUND         = 1
   CANT_CREATE_MODE       = 2
   NO_AUTHORITY           = 3
   OTHERS                 = 4
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

3.CC_CALL_TRANSACTION_NEW_TASK

新建session会话的函数

效果1.调用程序需要tcode,2.调用会打开新会话(sap只支持六个会话)

3.点击返回按钮,可以返回原屏幕并关闭打开的新会话.(效果类似SUBMIT语句)

WRITE 'This is the main ABAP program'.
DATA :
  LV_SKIP(1)  TYPE C VALUE 'X',
  LV_VBELN    LIKE VBAK-VBELN VALUE '20000190',
  L_ST_PARAM  TYPE TPARA,
  L_IT_PARAMS TYPE TABLE OF TPARA.
CLEAR L_ST_PARAM.
CLEAR L_IT_PARAMS[].
L_ST_PARAM-PARAMID = 'AUN'.
L_ST_PARAM-PARTEXT = LV_VBELN.
APPEND L_ST_PARAM TO L_IT_PARAMS.
CALL FUNCTION 'CC_CALL_TRANSACTION_NEW_TASK'
"  STARTING NEW TASK 'VA03'"表异步
"  DESTINATION 'NONE'"
  EXPORTING
    TRANSACTION           = 'VA03'
    SKIP_FIRST_SCREEN     = 'X'
  TABLES
    PARAMTAB              = L_IT_PARAMS"传屏幕参数的表
  EXCEPTIONS
    COMMUNICATION_FAILURE = 97
    SYSTEM_FAILURE        = 98
    OTHERS                = 99.
IF SY-SUBRC = 0.
  " Success
ELSEIF SY-SUBRC = 97.
  " Communication Failure
  EXIT.
ELSEIF SY-SUBRC = 98.
  " System Failure
  EXIT.
ELSE.
  EXIT.
ENDIF.

这里原函数

CALL FUNCTION 'CC_CALL_TRANSACTION_NEW_TASK'
  EXPORTING
    transaction             =
    skip_first_screen       =
* TABLES
*   PARAMTAB                =
* EXCEPTIONS
*   ERROR                   = 1
*   OTHERS                  = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

4.ABAP4_CALL_TRANSACTION

新建session会话的函数

效果1.调用程序需要tcode,2.调用会打开新会话(sap只支持六个会话)

3.点击返回按钮,可以返回原屏幕并关闭打开的新会话.(效果类似SUBMIT语句)

WRITE 'This is the main ABAP report calling the SAP Transaction VA03 in a new session or in a new window'.
DATA :    WA_SPA   TYPE RFC_SPAGPA,
          ITAB_SPA TYPE TABLE OF RFC_SPAGPA."传屏幕参数的表
WA_SPA-PARID = 'AUN'.    "屏幕参数id
WA_SPA-PARVAL = '20000190'.
APPEND WA_SPA TO ITAB_SPA.
CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
  STARTING NEW TASK 'VA03'
  DESTINATION 'NONE'
  EXPORTING
    TCODE                 = 'VA03'
    SKIP_SCREEN           = 'X'
  TABLES
    SPAGPA_TAB            = ITAB_SPA"传屏幕参数的表
  EXCEPTIONS
    COMMUNICATION_FAILURE = 1
    SYSTEM_FAILURE        = 2.
IF SY-SUBRC <> 0.
  " ERROR
ENDIF.

原函数代码

CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
  EXPORTING
    tcode                         =
*   SKIP_SCREEN                   = ' '
*   MODE_VAL                      = 'A' "A:前台,显示屏幕    E:遇到错误停止并显示    N:后台模式
*   UPDATE_VAL                    = 'A'"A:异步   S:同步     L:本地模式
* IMPORTING
*   SUBRC                         =
* TABLES
*   USING_TAB                     =
*   SPAGPA_TAB                    =
*   MESS_TAB                      =
* EXCEPTIONS
*   CALL_TRANSACTION_DENIED       = 1
*   TCODE_INVALID                 = 2
*   OTHERS                        = 3
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

有空看看这个

ABAP CALL TRANSACTION 调用事务码方式-SAP技术站ABAP CALL TRANSACTION 调用事务码方式,使用BDC参数调用事务码并进行跳转REPORTYTEST.INCLUDEBDCRECXY."使用BDC一定要包含此文件DATAL_OPTTYPECTU_PARAMS.SELECTION-SCREENPUSHBUTTON/1(20)PUBU1icon-default.png?t=N7T8https://www.sapcenter.cn/archive/post/354567785943109.html

你可能感兴趣的:(abap,数据库)