1、SHDB屏幕录制

执行事务码:SHDB,进入录屏程序
在这里插入图片描述
点击“新建记录”,开始录屏
在这里插入图片描述
点击“开始记录”,进入相应的事务码界面
在这里插入图片描述
按正常操作步骤完成业务操作
在这里插入图片描述
选择 A305对应的“具有审批状态的客户/物料”关键字组合
在这里插入图片描述
填写以下字段值
在这里插入图片描述
在这里插入图片描述
最后点击“保存”,完成业务操作
在这里插入图片描述
保存录屏记录
在这里插入图片描述
返回录屏列表,自动显示当前的录屏记录
在这里插入图片描述

2、录屏代码输出

选中该录屏记录,生成程序
在这里插入图片描述
查看程序源代码
在这里插入图片描述
选择本地对象
在这里插入图片描述
生成的程序如下
在这里插入图片描述
主程序 ZBDC_ZP00_A305

report ZBDC_ZP00_A305
       no standard page heading line-size 255.

* Include bdcrecx1_s:
* The call transaction using is called WITH AUTHORITY-CHECK!
* If you have own auth.-checks you can use include bdcrecx1 instead.
include bdcrecx1_s.

start-of-selection.

perform open_group.

perform bdc_dynpro      using 'SAPMV13A' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'RV13A-KSCHL'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RV13A-KSCHL'
                              'ZP00'.
perform bdc_dynpro      using 'SAPLV14A' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'RV130-SELKZ(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=WEIT'.
perform bdc_dynpro      using 'SAPLSHL2' '1600'.
perform bdc_field       using 'BDC_CURSOR'
                              'HELP_INFO-DYNPPROG'.
perform bdc_field       using 'BDC_OKCODE'
                              '=TCAL'.
perform bdc_dynpro      using 'SAPMV13A' '1305'.
perform bdc_field       using 'BDC_CURSOR'
                              'KONP-KMEIN(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'KOMG-VKORG'
                              '6100'.
perform bdc_field       using 'KOMG-VTWEG'
                              '16'.
perform bdc_field       using 'KOMG-KUNNR'
                              '2000091'.
perform bdc_field       using 'KOMG-MATNR(01)'
                              '000000380100000001'.
perform bdc_field       using 'KONP-KBETR(01)'
                              '              10'.
perform bdc_field       using 'KONP-KONWA(01)'
                              'CNY'.
perform bdc_field       using 'KONP-KPEIN(01)'
                              '    1'.
perform bdc_field       using 'KONP-KMEIN(01)'
                              'PCS'.
perform bdc_field       using 'RV13A-DATAB(01)'
                              '2022/10/25'.
perform bdc_field       using 'RV13A-DATBI(01)'
                              '2022/10/26'.
perform bdc_dynpro      using 'SAPMV13A' '1305'.
perform bdc_field       using 'BDC_CURSOR'
                              'KOMG-MATNR(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=SICH'.
perform bdc_transaction using 'VK11'.

perform close_group.

包含程序 BDCRECX1_S

***INCLUDE BDCRECX1_S.
*  for programs doing a data transfer by creating a batch-input session
*  and
*  for programs doing a data transfer by CALL TRANSACTION USING
*  secured version WITH AUTHORITY-CHECK.

SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS SESSION RADIOBUTTON GROUP CTU.  "create session
  SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.
  selection-screen position 45.
  PARAMETERS CTU RADIOBUTTON GROUP  CTU.     "call transaction
  SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.
  selection-screen position 25.
  PARAMETERS GROUP(12).                      "group name of session
  SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.
  selection-screen position 70.
  PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
                                      "A: show all dynpros
                                      "E: show dynpro on error only
                                      "N: do not display dynpro
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.
  selection-screen position 25.
  PARAMETERS: USER(12) DEFAULT SY-UNAME.     "user for session in batch
  SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.
  selection-screen position 70.
  PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.
                                      "S: synchronously
                                      "A: asynchronously
                                      "L: local
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.
  selection-screen position 25.
  PARAMETERS: KEEP AS CHECKBOX.       "' ' = delete session if finished
                                      "'X' = keep   session if finished
  SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.
  selection-screen position 70.
  parameters E_GROUP(12).             "group name of error-session
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.
  selection-screen position 25.
  PARAMETERS: HOLDDATE LIKE SY-DATUM.
  SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.
  selection-screen position 70.
  PARAMETERS: E_USER(12) DEFAULT SY-UNAME.    "user for error-session
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.
  selection-screen position 70.
  PARAMETERS: E_KEEP AS CHECKBOX.     "' ' = delete session if finished
                                      "'X' = keep   session if finished
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.
  selection-screen position 70.
  PARAMETERS: E_HDATE LIKE SY-DATUM.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.
  PARAMETERS: NODATA DEFAULT '/' LOWER CASE.          "nodata
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 1(33) TEXT-S11 FOR FIELD SMALLLOG.
  PARAMETERS: SMALLLOG as checkbox.  "' ' = log all transactions
                                     "'X' = no transaction logging
SELECTION-SCREEN END OF LINE.

*----------------------------------------------------------------------*
*   data definition
*----------------------------------------------------------------------*
*       Batchinputdata of single transaction
DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.
*       messages of call transaction
DATA:   MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
*       error session opened (' ' or 'X')
DATA:   E_GROUP_OPENED.
*       message texts
TABLES: T100.


*----------------------------------------------------------------------*
*   at selection screen                                                *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* group and user must be filled for create session
  IF SESSION = 'X' AND
     GROUP = SPACE OR USER = SPACE.
    MESSAGE E613(MS).
  ENDIF.

*----------------------------------------------------------------------*
*   open dataset                                                       *
*----------------------------------------------------------------------*
FORM OPEN_DATASET USING P_DATASET.
  OPEN DATASET P_DATASET
               FOR INPUT IN TEXT MODE
               ENCODING DEFAULT.
  IF SY-SUBRC <> 0.
    WRITE: / TEXT-E00, SY-SUBRC.
    STOP.
  ENDIF.
ENDFORM.

*----------------------------------------------------------------------*
*   close dataset                                                      *
*----------------------------------------------------------------------*
FORM CLOSE_DATASET USING P_DATASET.
  CLOSE DATASET P_DATASET.
ENDFORM.

*----------------------------------------------------------------------*
*   create batchinput session                                          *
*   (not for call transaction using...)                                *
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
  IF SESSION = 'X'.
    SKIP.
    WRITE: /(20) 'Create group'(I01), GROUP.
    SKIP.
*   open batchinput group
    CALL FUNCTION 'BDC_OPEN_GROUP'
         EXPORTING  CLIENT   = SY-MANDT
                    GROUP    = GROUP
                    USER     = USER
                    KEEP     = KEEP
                    HOLDDATE = HOLDDATE.
    WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
            (12) 'returncode:'(I05),
                 SY-SUBRC.
  ENDIF.
ENDFORM.

*----------------------------------------------------------------------*
*   end batchinput session                                             *
*   (call transaction using...: error session)                         *
*----------------------------------------------------------------------*
FORM CLOSE_GROUP.
  IF SESSION = 'X'.
*   close batchinput group
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
            (12) 'returncode:'(I05),
                 SY-SUBRC.
  ELSE.
    IF E_GROUP_OPENED = 'X'.
      CALL FUNCTION 'BDC_CLOSE_GROUP'.
      WRITE: /.
      WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
      E_GROUP_OPENED = ' '.
    ENDIF.
  ENDIF.
ENDFORM.

*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
  DATA: L_MSTRING(480).
  DATA: L_SUBRC LIKE SY-SUBRC.
  DATA: lx_auth_check TYPE REF TO cx_root.
  DATA: l_auth_check_text TYPE string.
* batch input session
  IF SESSION = 'X'.
    CALL FUNCTION 'BDC_INSERT'
         EXPORTING TCODE     = TCODE
         TABLES    DYNPROTAB = BDCDATA.
    IF SMALLLOG <> 'X'.
      WRITE: / 'BDC_INSERT'(I03),
               TCODE,
               'returncode:'(I05),
               SY-SUBRC,
               'RECORD:',
               SY-INDEX.
    ENDIF.
* call transaction using
  ELSE.
    REFRESH MESSTAB.
    TRY.
      CALL TRANSACTION TCODE WITH AUTHORITY-CHECK USING BDCDATA
                       MODE   CTUMODE
                       UPDATE CUPDATE
                       MESSAGES INTO MESSTAB.
    CATCH cx_sy_authorization_error INTO lx_auth_check.
*     Authorization missing for user when executing transaction
      l_auth_check_text = lx_auth_check->get_text( ).
      SY-SUBRC = 99.
    ENDTRY.
    L_SUBRC = SY-SUBRC.
    IF SMALLLOG <> 'X'.
      WRITE: / 'CALL_TRANSACTION',
               TCODE,
               'returncode:'(I05),
               L_SUBRC,
               'RECORD:',
               SY-INDEX.
      IF L_SUBRC <> 99.
        LOOP AT MESSTAB.
          MESSAGE ID     MESSTAB-MSGID
                  TYPE   MESSTAB-MSGTYP
                  NUMBER MESSTAB-MSGNR
                  INTO L_MSTRING
                  WITH MESSTAB-MSGV1
                       MESSTAB-MSGV2
                       MESSTAB-MSGV3
                       MESSTAB-MSGV4.
          WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
        ENDLOOP.
      ELSE.
        WRITE: / l_auth_check_text.
      ENDIF.
      SKIP.
    ENDIF.
** Erzeugen fehlermappe ************************************************
    IF L_SUBRC <> 0 AND L_SUBRC <> 99 AND E_GROUP <> SPACE.
      IF E_GROUP_OPENED = ' '.
        CALL FUNCTION 'BDC_OPEN_GROUP'
             EXPORTING  CLIENT   = SY-MANDT
                        GROUP    = E_GROUP
                        USER     = E_USER
                        KEEP     = E_KEEP
                        HOLDDATE = E_HDATE.
         E_GROUP_OPENED = 'X'.
      ENDIF.
      CALL FUNCTION 'BDC_INSERT'
           EXPORTING TCODE     = TCODE
           TABLES    DYNPROTAB = BDCDATA.
    ENDIF.
  ENDIF.
  REFRESH BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  IF FVAL <> NODATA.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
  ENDIF.
ENDFORM.

3、录屏代码调整

拷贝主程序代码,调整为自己的FORM

FORM FRM_BDC_UPLOAD.
  CLEAR GS_DISPLAY1.
 " GT_DISPLAY1为需要批导的价格记录内表,包含业务操作时需要填写的字段
  LOOP AT GT_DISPLAY1 INTO GS_DISPLAY1 WHERE CHECK = 'X'.
    DATA: LT_BDCDATA TYPE TABLE OF BDCDATA,    " BDC执行内表
          LT_MSGTAB  TYPE TABLE OF BDCMSGCOLL, " BDC返回信息表
          LS_BDCDATA TYPE BDCDATA,
          LS_MSGTAB  TYPE BDCMSGCOLL,          " BDC返回信息表
          LV_MESS    TYPE STRING,
          LV_MESSAGE TYPE STRING.

    DATA: LC_MODE     	TYPE C  VALUE 'N'.      	" BDC运行模式:A、E、N、P
    DATA: LC_UPMODE   	TYPE C  VALUE 'S'.      	" BDC更新模式:L、A、S
          LV_TCODE(10) 	TYPE C VALUE 'VK11'.  		" 销售定价新增

    DEFINE BDC_DYNPRO.
      CLEAR LS_BDCDATA.
      LS_BDCDATA-PROGRAM  = &1.
      LS_BDCDATA-DYNPRO   = &2.
      LS_BDCDATA-DYNBEGIN = 'X'.
      APPEND LS_BDCDATA TO LT_BDCDATA.
    END-OF-DEFINITION.

    DEFINE BDC_FIELD.
      CLEAR LS_BDCDATA.
      LS_BDCDATA-FNAM = &1.
      LS_BDCDATA-FVAL = |{ &2 }|.
      APPEND LS_BDCDATA TO LT_BDCDATA.
    END-OF-DEFINITION.
    
*    perform open_group.
    BDC_DYNPRO 'SAPMV13A' '0100'.
    BDC_FIELD  'BDC_CURSOR' 'RV13A-KSCHL'.
    BDC_FIELD  'BDC_OKCODE' '/00'.
    BDC_FIELD  'RV13A-KSCHL' 'ZP00'.
    BDC_DYNPRO 'SAPLV14A' '0100'.
    BDC_FIELD  'BDC_CURSOR' 'RV130-SELKZ(01)'.
    BDC_FIELD  'BDC_OKCODE' '=WEIT'.
    BDC_DYNPRO 'SAPLSHL2' '1600'.
    BDC_FIELD  'BDC_CURSOR' 'HELP_INFO-DYNPPROG'.
    BDC_FIELD  'BDC_OKCODE' '=TCAL'.
    BDC_DYNPRO 'SAPMV13A' '1305'.
    BDC_FIELD  'BDC_CURSOR' 'KONP-KMEIN(01)'.
    BDC_FIELD  'BDC_OKCODE' '/00'.
    BDC_FIELD  'KOMG-VKORG' GS_DISPLAY1-VKORG.		" 销售组织
    BDC_FIELD  'KOMG-VTWEG' GS_DISPLAY1-VTWEG.		" 分销渠道
    BDC_FIELD  'KOMG-KUNNR'  GS_DISPLAY1-KUNNR.		" 客户代码
    BDC_FIELD  'KOMG-MATNR(01)' GS_DISPLAY1-MATNR.	" 物料代码
    BDC_FIELD  'KONP-KBETR(01)' GS_DISPLAY1-KBETR.	" 价格
    BDC_FIELD  'KONP-KONWA(01)' GS_DISPLAY1-KONWA.	" 币别
    BDC_FIELD  'KONP-KPEIN(01)' GS_DISPLAY1-KPEIN.		" 单位数量
    BDC_FIELD  'KONP-KMEIN(01)' GS_DISPLAY1-KMEIN.		" 计量单位
    BDC_FIELD  'RV13A-DATAB(01)'  GS_DISPLAY1-DATAB.	" 生效日期
    BDC_FIELD  'RV13A-DATBI(01)' GS_DISPLAY1-DATBI.		" 截止日期
    BDC_DYNPRO 'SAPMV13A' '1305'.
    BDC_FIELD  'BDC_CURSOR' 'KOMG-MATNR(01)'.
    BDC_FIELD  'BDC_OKCODE' '=SICH'.

    CALL TRANSACTION LV_TCODE         " BDC调用的事务码
      USING LT_BDCDATA                " BDC执行内表
            MODE LC_MODE              " BDC运行模式
            MESSAGES INTO LT_MSGTAB   " BDC返回信息表
            UPDATE LC_UPMODE.         " 批导更新模式(A = '异步',S = '同步')
*  perform close_group.         
   
    " BDC 消息处理
    CLEAR LV_MESSAGE.
    LOOP AT LT_MSGTAB INTO LS_MSGTAB WHERE MSGTYP = 'E' OR MSGTYP = 'A'.
      CALL FUNCTION 'MESSAGE_TEXT_BUILD'
        EXPORTING
          MSGID               = LS_MSGTAB-MSGID
          MSGNR               = LS_MSGTAB-MSGNR
          MSGV1               = LS_MSGTAB-MSGV1
          MSGV2               = LS_MSGTAB-MSGV2
          MSGV3               = LS_MSGTAB-MSGV3
          MSGV4               = LS_MSGTAB-MSGV4
        IMPORTING
          MESSAGE_TEXT_OUTPUT = LV_MESS.

      LV_MESSAGE = LV_MESSAGE && LV_MESS.
    ENDLOOP.

    CLEAR: LT_BDCDATA, GS_DISPLAY1.
  ENDLOOP.
ENDFORM.

说明:
执⾏模式,有下列可选值(执⾏模式常⽤的是 A/ N)
“A” 显⽰所有输⼊屏幕,如果在 bdc_tab 中包含该屏幕的功能码,则会出现⼩窗⼝显⽰这个功能码。它也是默认值,如果指定不是下⾯的值,则都认为是 A。
"E只有在出现错误时才显⽰屏幕,⽤户可以修正数据,修正后程序可以继续处理。
“N” 不显⽰屏幕的静默模式,如果到达被调⽤事务的断点,则系统处理终⽌,并设置⼀些系统字段。
sy-subrc 为 1001,sy-msgty 为 “S”、sy-msgid 为 “00”、sy-msgno 为 “344”、sy-msgv1 为 “SAPMSSY3”、sy-msgv2 为 “0131”。
“P” 不显⽰屏幕的调试模式。如果到达被调⽤事务的断点,则系统⾃动转到 ABAP 调试器,这种⽅式主要⽤于调试过程。

更新模式,有下列可选值(更新模式常⽤的是 S)
“A” 异步更新,被调⽤程序的更新按照没有指定 COMMIT WORK 语句和 AND WAIT 附加的⽅式执⾏。也就是说,数据更新被放到更新队列⾥,由另⼀个专门的更新进程执⾏,主程序⼀旦提交数据就继续执⾏,⽽不管提交的更新是否执⾏完成。这种⽅式⽐较适合于⽤⼀个事务码⼤量更新指定数据,⽐如维护主数据等。
“S” 同步更新,被调⽤程序的更新按照指定了 COMMIT WORK 语句和 AND WAIT 附加的⽅式执⾏。也就是说,数据更新被放到更新队列⾥,由专门的更新进程执⾏,但是主程序会等到数据提交完成,返回结果信息后才继续执⾏。这种⽅式⽐较适合于数据⼀致性要求⽐较⾼,多个不同事务码的连续处理。
“L” 本地更新,被调⽤程序的更新按照执⾏ SET UPDATE TASK LOCAL 语句的⽅式执⾏。也就是说,数据更新在主程序所在的进程中完成,主程序必定等到被调⽤事务完成才继续执⾏。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐