SAP 批量修改工艺路线

一、所用到的修改函数
CPCC_S_TASK_LIST_MAINTAIN
TASK_MAINTAIN_MODE:操作模式:C创建,M:修改,D:删除
我们实例中只使用到了M修改模式,其余模式可以自行修改套用。

二、效果展示
进CA03,查看要修改20023213物料的直接人工与间接费用。
在这里插入图片描述
准备好数据
在这里插入图片描述
导入数据点击执行
在这里插入图片描述
查看导入后的结果,已经修改成功。
在这里插入图片描述

三、实例代码


*----------------------------------------------------------------------*
* TYPE-POOLS: 声明类型组
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
TYPE-POOLS: kcde.

*---------------------------------------------------------------------*
*  TABLES:          声明报表中使用到的数据表
*  Table Work Areas 表工作区
*---------------------------------------------------------------------*
TABLES:sscrfields.

*----------------------------------------------------------------------*
* DATAGlobal Variants Declaration        变量声明
*        Global Internal Tables Declaration 内表声明
*----------------------------------------------------------------------*
DATA: gt_file TYPE filetable.
DATA: g_repid TYPE sy-repid.
DATA: gt_field TYPE slis_t_fieldcat_alv.

*定义内表类型
TYPES: BEGIN OF typ_data ,
         matnr LIKE mara-matnr, "物料号
         werks LIKE marc-werks, "工厂
         aennr LIKE plko-aennr, "变更编号

         plnty TYPE mapl-plnty, " 任务清单类型
         plnnr LIKE mapl-plnnr, "任务清单组码
         plnal LIKE mapl-plnal, "组计数器
         plnfl TYPE plfl-plnfl, "顺序序列
         vornr LIKE plpo-vornr, "工序序号
         arbpl TYPE crhd-arbpl, "工作中心
         vgwrt LIKE plpo-vgw01, "直接人工
         vgw04 LIKE plpo-vgw04, "间接费用

         msgty TYPE msgty,
         msgtx TYPE msgtx,
         sel   TYPE char1,
       END OF typ_data .

DATA : gs_data TYPE typ_data,
       gt_data TYPE TABLE OF typ_data.

FIELD-SYMBOLS: <fs_tab>  TYPE typ_data,
               <fs_cell> TYPE kcde_cells.
DATA : gt_cells LIKE STANDARD TABLE OF kcde_cells.

*** ALV 相关声明
DATA: gs_layout   TYPE lvc_s_layo,   "负责整个ALV的全局属性
      gv_repid    TYPE repid,        "程序为当前程序
      gt_fieldcat TYPE lvc_t_fcat,   "存放列名的列表
      gs_fieldcat TYPE lvc_s_fcat.   "相当于工作区
DATA: g_grid TYPE REF TO cl_gui_alv_grid.

*---------------------------------------------------------------
* DEFINE :定义宏  创建字段宏定义
*---------------------------------------------------------------
DEFINE add_field.
  gs_fieldcat-fieldname = '&1'.   "内表字段名称
  gs_fieldcat-scrtext_m =  &2.    "字段输出名称
*  gs_fieldcat-tabname   =  &1.
*  gs_fieldcat-checkbox  =  &3.    "作为复选框输出
*  gs_fieldcat-just      =  &4.    "对齐
*  gs_fieldcat-emphasize =  &5.    "带有颜色的高亮列
*  gs_fieldcat-edit      =  &6.    "编辑
*  gs_fieldcat-key       =  &7.    "关键字段
*  gs_fieldcat-hotspot   =  &8.    "单击敏感
  APPEND gs_fieldcat TO gt_fieldcat.  "写进显示字段列表
  CLEAR gs_fieldcat.
END-OF-DEFINITION.
DEFINE conversion.
  IF &1 IS NOT INITIAL.
      CALL FUNCTION 'CONVERSION_EXIT_NUMCV_INPUT'
        EXPORTING
          input  = &1
        IMPORTING
          output = &1.
  ENDIF.
END-OF-DEFINITION.
*----------------------------------------------------------------------*
* Selection Screen 选择屏幕定义
*----------------------------------------------------------------------*
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK bl01 WITH FRAME TITLE TEXT-001.

  PARAMETERS:p_file  TYPE rlgrap-filename MODIF ID m1. "回款导入文件路径

SELECTION-SCREEN END OF BLOCK bl01.
*&---------------------------------------------------------------------*
*&   Event AT INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION .   "程序初始化时所执行的代码

  PERFORM frm_initialization.

*---------------------------------------------------------------
* AT SELECTION-SCREEN :在选择屏幕上执行的代码
*---------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM frm_open_file.

AT SELECTION-SCREEN.

  PERFORM frm_screen.

*---------------------------------------------------------------
* Event Occurs After The Selection Screen Has Been Processed
* START-OF-SELECTION: 程序运行所处理的代码
*---------------------------------------------------------------
START-OF-SELECTION.
  PERFORM frm_auth_check.    "权限检查
  PERFORM frm_upload_data.   " 读取数据
  PERFORM frm_get_data .     "导入处理数据
  PERFORM frm_display_data.  "ALV显示

*&---------------------------------------------------------------------*
*& Form frm_INITIALIZATION
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_initialization .
  sscrfields-functxt_01 = '下载模板'.           "模板下载

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_screen
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_screen .
  CASE sscrfields-ucomm .
    WHEN 'FC01'.    "这是下载按钮,Excel模板按照我上图数据准备
      PERFORM frm_download_files.
      CLEAR sscrfields-ucomm .

    WHEN OTHERS .
      IF p_file IS INITIAL .
        MESSAGE e000(00) WITH '请输入文件路径' .
      ENDIF .
  ENDCASE .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_auth_check
*&---------------------------------------------------------------------*
*& 权限检查
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_auth_check .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& 导入处理数据
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .
  CHECK gt_data[] IS NOT INITIAL.

  DATA:lt_data TYPE TABLE OF typ_data.

  lt_data[] = gt_data[].
  SORT lt_data BY matnr werks.
  DELETE ADJACENT DUPLICATES FROM lt_data COMPARING matnr werks.
  DELETE lt_data WHERE werks IS INITIAL.

  IF lt_data[] IS NOT INITIAL.
    SELECT * INTO TABLE @DATA(lt_marc)
             FROM marc
             FOR ALL ENTRIES IN @lt_data
             WHERE matnr EQ @lt_data-matnr
               AND werks EQ @lt_data-werks.
    SORT lt_marc BY matnr werks.

    SELECT * INTO TABLE @DATA(lt_mapl)
             FROM mapl
             FOR ALL ENTRIES IN @lt_data
             WHERE matnr EQ @lt_data-matnr
               AND werks EQ @lt_data-werks
               AND loekz NE 'X'.

    SORT lt_data BY matnr.
    DELETE ADJACENT DUPLICATES FROM lt_data COMPARING matnr.
    SELECT * INTO TABLE @DATA(lt_makt)
             FROM v_mara_makt
             FOR ALL ENTRIES IN @lt_data
             WHERE matnr EQ @lt_data-matnr
               AND spras EQ @sy-langu.

    IF lt_mapl[] IS NOT INITIAL.
      SELECT * INTO TABLE @DATA(lt_plpo)
               FROM zvs_plfl
               FOR ALL ENTRIES IN @lt_mapl
               WHERE plnty EQ @lt_mapl-plnty
                 AND plnnr EQ @lt_mapl-plnnr
                 AND plnal EQ @lt_mapl-plnal.

      SELECT * INTO TABLE @DATA(lt_plmk)
               FROM plmk
               FOR ALL ENTRIES IN @lt_mapl
               WHERE plnty EQ @lt_mapl-plnty
                 AND plnnr EQ @lt_mapl-plnnr.
    ENDIF.
  ENDIF.

  SELECT * INTO TABLE @DATA(lt_t430) FROM t430.

  LOOP AT gt_data INTO gs_data.

    READ TABLE lt_marc TRANSPORTING NO FIELDS
                      WITH KEY matnr = gs_data-matnr
                               werks = gs_data-werks BINARY SEARCH.
    IF sy-subrc NE 0.
      gs_data-msgty = 'E'.
      DATA(lv_msgtx) = '物料' && gs_data-matnr &&
                      '不存在于工厂' && gs_data-werks.
      gs_data-msgtx = lv_msgtx.
    ENDIF.

    READ TABLE lt_mapl INTO DATA(ls_mapl)
                       WITH KEY matnr = gs_data-matnr
                                werks = gs_data-werks
                                plnty = 'N'
                                plnal = gs_data-plnal.
    IF sy-subrc NE 0.
      gs_data-msgty = 'E'.
      lv_msgtx =  '物料' && gs_data-matnr && '工厂' &&
                  gs_data-werks && '未分配任务清单'.

      IF gs_data-msgtx IS NOT INITIAL.
        gs_data-msgtx = gs_data-msgtx && '/' && lv_msgtx.
      ELSE.
        gs_data-msgtx = lv_msgtx.
      ENDIF.
    ELSE.
      gs_data-plnnr = ls_mapl-plnnr.
      gs_data-plnty = ls_mapl-plnty.

    ENDIF.

    MODIFY gt_data FROM gs_data.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_DATA  ALV显示
*&---------------------------------------------------------------------*
*       报表展示
*----------------------------------------------------------------------*
FORM frm_display_data .
  DATA : lv_html_header TYPE slis_formname  .
*定义输出模式
  CLEAR:gs_layout,gt_fieldcat.
  gs_layout-cwidth_opt  = 'X'.
  gs_layout-zebra     = 'X'.
  gs_layout-box_fname  = 'SEL'.
  gv_repid = sy-repid.
  PERFORM frm_set_fieldcat.

  "ALV输出"
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = gv_repid
      i_callback_user_command  = 'FRM_USER_COMMAND'
      i_callback_pf_status_set = 'FRM_PF_STATUS'
      is_layout_lvc            = gs_layout
      it_fieldcat_lvc          = gt_fieldcat
      i_save                   = 'A'
    TABLES
      t_outtab                 = gt_data
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*       AVL展示绑定及显示效果
*----------------------------------------------------------------------*
FORM frm_set_fieldcat.
*
  add_field :
        msgty     '返回状态'     ,
        msgtx     '返回信息'     ,

        matnr     '物料编码'     ,
        werks     '工厂'    ,
        aennr     '变更编号',

        plnty     '任务清单类型'      ,
        plnnr     '任务清单组'          ,
        plnal     '组计数器'     ,
        plnfl     '顺序序列'     ,
        vornr     '工序序号'       ,
        arbpl     '工作中心',
        vgwrt     '直接人工' ,
        vgw04     '间接费用' .



ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_pf_status
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_pf_status USING pt_extab TYPE kkblo_t_extab .
  SET PF-STATUS 'STANDARD' EXCLUDING pt_extab..
ENDFORM. "f_set_pf_status

*&---------------------------------------------------------------------*
*& Form frm_user_command
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*"
FORM frm_user_command USING pv_ucomm TYPE sy-ucomm
                            ps_selfield TYPE slis_selfield..
  CASE pv_ucomm.
    WHEN '&IC1'.  "Double click

    WHEN 'CREATE'.
      PERFORM frm_create_routing.
    WHEN OTHERS.

  ENDCASE.

  ps_selfield-refresh    = 'X'.
  ps_selfield-col_stable = 'X'.
  ps_selfield-row_stable = 'X'.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_open_file
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*"
FORM frm_open_file .
  DATA:lv_filetable TYPE filetable,
       lv_rc        TYPE i,
       lv_file      TYPE file_table.

  CONSTANTS:cv_file_filter TYPE string
                           VALUE 'Microsoft Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|(*.*)|*.*|'.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = '请选择导入文件'
      file_filter             = cv_file_filter
      multiselection          = space
    CHANGING
      file_table              = lv_filetable
      rc                      = lv_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.

  IF sy-subrc = 0 AND lv_rc = 1.
    READ TABLE lv_filetable INTO lv_file INDEX 1.
    p_file = lv_file-filename .
  ENDIF .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_upload_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_upload_data .
  DATA:lt_intern TYPE TABLE OF alsmex_tabline,
       ls_intern TYPE alsmex_tabline,
       lv_index  TYPE i.
  FIELD-SYMBOLS <fv_value> TYPE any.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 23
      i_end_row               = 65000
    TABLES
      intern                  = lt_intern
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  SORT lt_intern BY row col.
  LOOP AT lt_intern INTO ls_intern.
    lv_index = ls_intern-col .
    ASSIGN COMPONENT lv_index OF STRUCTURE  gs_data TO <fv_value>.
    <fv_value> = ls_intern-value.
    AT END OF row.
      IF gs_data-matnr IS INITIAL.
        gs_data-msgty = 'E'.
        gs_data-msgtx = '物料编号不能为空'.
      ELSE.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input  = gs_data-matnr
          IMPORTING
            output = gs_data-matnr.
      ENDIF.

      IF gs_data-plnfl IS INITIAL.
        gs_data-plnfl = 0.
      ENDIF.
      conversion:gs_data-vornr,
                 gs_data-plnal,
                 gs_data-plnfl.

      APPEND gs_data TO gt_data.
      CLEAR gs_data.
    ENDAT.
  ENDLOOP.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_FILES
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_download_files .

  DATA:ls_key TYPE wwwdatatab.
  SELECT SINGLE * INTO CORRESPONDING FIELDS OF ls_key
         FROM wwwdata
         WHERE srtf2 EQ 0
           AND relid EQ 'MI'
           AND objid EQ 'ZQMR0002' ." 这个使用SMW0 进行上传"
  IF sy-subrc NE 0.
    MESSAGE '模板文件ZQMR0002不存在' TYPE 'E'.
    RETURN.
  ENDIF.

  DATA:lv_filename TYPE string,
       lv_path     TYPE string,
       lv_fullpath TYPE string.

  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      default_file_name    = '工艺路线质量数据批导模板.xlsx'
      default_extension    = 'xls'
    CHANGING
      filename             = lv_filename
      path                 = lv_path
      fullpath             = lv_fullpath
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.

  DATA: lv_destination LIKE  rlgrap-filename .
  DATA lv_subrc TYPE sy-subrc.
  lv_destination = lv_fullpath.

  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      key         = ls_key
      destination = lv_destination
    IMPORTING
      rc          = lv_subrc.
  IF lv_subrc <> 0.
    MESSAGE '模板文件:下载失败,请与相关人员联系' TYPE 'E'.
    RETURN.
  ENDIF.

  DATA: application TYPE ole2_object,
        workbook    TYPE ole2_object,
        sheet       TYPE ole2_object.

*&& 打开模版 文件
  CREATE OBJECT application 'EXCEL.APPLICATION'.
  IF sy-subrc NE 0.
    MESSAGE '不能创建Excel对象' TYPE 'E'.
    RETURN.
  ENDIF.

  CALL METHOD OF
    application
      'WORKBOOKS' = workbook.
  CALL METHOD OF
    workbook
    'OPEN'
    EXPORTING
      #1 = lv_destination.
  CALL METHOD OF
      application
      'WORKSHEETS' = sheet
    EXPORTING
      #1           = 1.
  GET PROPERTY OF  application 'ACTIVESHEET' = sheet.
  SET PROPERTY OF application 'VISIBLE' = 1.

  FREE sheet.
  FREE workbook.
  FREE application.
  CALL METHOD OF
    workbook
    'CLOSE'.
  CALL METHOD OF
    application
    'QUIT'.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_change_no_check
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_change_no_check USING iv_aennr TYPE plko-aennr
                         CHANGING cv_datuv TYPE sy-datum.
  DATA lv_flg_date TYPE csdata-xfeld.

  CALL FUNCTION 'CCCN_ECN_WITH_EFFECTIVITY'
    EXPORTING
      eaennr          = iv_aennr
    IMPORTING
      flg_date        = lv_flg_date
    EXCEPTIONS
      no_record_found = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
*    MESSAGE e000 WITH '变更编号不存在'.
* Implement suitable error handling here
  ENDIF.

  IF lv_flg_date EQ abap_true.
    CALL FUNCTION 'CC_CHANGE_NUMBER_READ'
      EXPORTING
        eaennr          = iv_aennr
      IMPORTING
        adatuv          = cv_datuv
      EXCEPTIONS
        no_record_found = 1
        OTHERS          = 2.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_create_routing
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_create_routing .

  READ TABLE gt_data INTO gs_data WITH KEY msgty = 'E'.
  IF sy-subrc EQ 0.
    MESSAGE  '导入的数据存在错误,请先更正错误!' TYPE  'S' DISPLAY LIKE 'E'.
    RETURN.
  ENDIF.
  .


  DATA:ls_tsk    TYPE cps_task_list_maint_tsk,
       ls_tsk_x  TYPE cps_task_list_maint_tsk_x,
       lt_opr    TYPE cpt_task_list_maint_opr,
       lt_opr_x  TYPE cpt_task_list_maint_opr_x,
       lt_seq    TYPE cpt_task_list_maint_seq,
       lt_seq_x  TYPE cpt_task_list_maint_seq_x,
       lt_return TYPE bapiret2_t,
       ls_return TYPE bapiret2.
  DATA lv_count  TYPE i.
  DATA lv_datuv  TYPE sy-datum.

  SORT gt_data BY  matnr werks plnal aennr msgty.

  LOOP AT gt_data INTO gs_data .
    DATA(ls_data) = gs_data.
    AT NEW aennr.
      lv_count = 10.
      PERFORM frm_change_no_check USING ls_data-aennr
                                  CHANGING lv_datuv.
    ENDAT.

    PERFORM frm_opr_data TABLES lt_opr
                                lt_opr_x
                              .
    AT END OF plnal.
      CALL FUNCTION 'CPCC_S_TASK_LIST_MAINTAIN'
        EXPORTING
          change_no          = ls_data-aennr
          key_date           = lv_datuv
          task_list_type     = ls_data-plnty
          task_list_group    = ls_data-plnnr
          group_counter      = ls_data-plnal
          task_maintain_mode = 'M'
        TABLES
          operations         = lt_opr
          operations_x       = lt_opr_x
          return             = lt_return.

      LOOP AT lt_return INTO ls_return WHERE type CA 'AXE'.
        EXIT.
      ENDLOOP.
      IF sy-subrc NE 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = abap_true.
        ls_data-msgty = 'S'.
        ls_data-msgtx = '数据保存成功'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        SORT lt_return BY type message.
        DELETE ADJACENT DUPLICATES FROM lt_return COMPARING type message.
        LOOP AT lt_return INTO ls_return WHERE type CA 'AXE'.

          ls_data-msgtx = ls_data-msgtx && '/' && ls_return-message.
        ENDLOOP.
        IF gs_data-msgtx(1) EQ '/'.
          ls_data-msgtx(1) = space.
          CONDENSE ls_data-msgtx.
        ENDIF.
        ls_data-msgty = 'E'.
      ENDIF.
      MODIFY gt_data FROM ls_data TRANSPORTING msgty msgtx
                     WHERE  matnr EQ ls_data-matnr
                       AND werks EQ ls_data-werks
                       AND plnal EQ ls_data-plnal
                       AND aennr EQ ls_data-aennr.
      CLEAR:lt_return[],lt_opr[],lt_opr_x,ls_data.

    ENDAT.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_opr_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- LS_OPR
*&---------------------------------------------------------------------*
FORM frm_opr_data TABLES et_opr   TYPE cpt_task_list_maint_opr
                         et_opr_x TYPE cpt_task_list_maint_opr_x
                         .
  DATA:ls_opr   TYPE cps_task_list_maint_opr,
       ls_opr_x TYPE cps_task_list_maint_opr_x,
       ls_seq   TYPE cps_task_list_maint_seq,
       ls_seq_x TYPE cps_task_list_maint_seq_x.

  DATA(lv_pointer) = lines( et_opr ).
  ls_opr-flag_bar_pointer = lv_pointer + 1.
  ls_opr-maintain_mode = 'M'.
  ls_opr-activity = gs_data-vornr.       "操作/活动编号
  IF gs_data-plnfl IS INITIAL.
    ls_opr-sequence_no = '000000'. "序列
  ELSE.
    ls_opr-sequence_no = gs_data-plnfl.
  ENDIF.

  "数据未填写不更改。
  ls_opr-work_cntr = gs_data-arbpl .     "工作中心
  ls_opr-plant = gs_data-werks.          "工厂
  IF gs_data-vgwrt NE '0.000'.
    ls_opr-std_value_01 = gs_data-vgwrt.  "直接人工
    ls_opr_x-std_value_01 = abap_true.
  ENDIF.

  IF gs_data-vgw04  NE '0.000'.
    ls_opr-std_value_04 = gs_data-vgw04.  "间接费用
    ls_opr_x-std_value_04 = abap_true.
  ENDIF.

  IF gs_data-vgwrt  NE '0.000'   OR  gs_data-vgw04  NE '0.000'.
    APPEND ls_opr TO et_opr.
    APPEND ls_opr_x TO et_opr_x.
  ENDIF.
"在这里添加你自己要修改的字段
ENDFORM.

三、注意点
1.这个实例,只修改直接人工和间接费用,而且前面的字段都是必须的。
不然的话报错:找不到合适的对象。

2.要自己在SWM0上载自己的excel模板,才能下载模板。

3.变更编号和其他数据可以在PLKO,PLPO中找到。

四、参考链接
CA02检验计划批量导入 模板在文件

好了,分享使我快乐,我是寒武青锋。觉得不错的话记得点赞哟!
在这里插入图片描述

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值