【轉載】QP02檢驗計劃批量匯入

hubaichun發表於2018-10-24
其他參考:
https://archive.sap.com/discussions/thread/3430191

*&---------------------------------------------------------------------*
*& PROGRAM NAME(EN)   : ZQMC001
*& SAP module         : QM
*& PROGRAM(CN)        : CA02批量檢驗計劃匯入
*& AUTHOR             : LU.X
*& CREATED DATE       : 2015.05.28
*& DESCRIPTION        :
*----------------------------------------------------------------------*
report ZQMC002.

************************************************************************
*                  DATA DEFINATION                                     *
************************************************************************
tables: MARA,MARC.

types:

  begin of LS_ITAB,
    MATNR      like MARA-MATNR,"物料號
    MAKTX      like MAKT-MAKTX,"物料描述(短文字)
    WERKS      like MARC-WERKS,"工廠
    PLNNR      like MAPL-PLNNR,"任務清單組碼
    PLNAL      like MAPL-PLNAL,"組計數器
    KTEXT      like PLKO-KTEXT,"任務清單描述
    PLNNR_ALT  like PLKOD-PLNNR_ALT,"舊號
    SLWBEZ     like PLKO-SLWBEZ,"檢驗點

    VORNR      like PLPO-VORNR,"操作/活動編號
*    ARBID      like PLPO-ARBID,"物件標識(工作中心ID)
    ARBPL      like CRHD-ARBPL,"工作中心(PLPO-ARIBD= CRHD-OBJID
*         STEUS      like PLPO-STEUS,"控制碼
    LTXA1      like PLPO-LTXA1,"工序短文字

    VERWMERKM  like PLMK-VERWMERKM,"主檔案檢驗特性
    KURZTEXT   like PLMK-KURZTEXT,"檢驗特性的短文字
    PMETHODE   like PLMK-PMETHODE,"檢驗方法
    STICHPRVER like PLMK-STICHPRVER,"檢驗特性中的取樣程式
    PROBEMGEH  like PLMK-PROBEMGEH,"取樣計量單位
    SOLLWERT   type P length 8 decimals 4,"一個數量特性的目標值
    TOLERANZUN type P length 8 decimals 4,"容差下限
    TOLERANZOB type P length 8 decimals 4,"規範上限
    MESSAGE    type CHAR200,
    STATUS(4),

  end of LS_ITAB,

  begin of LS_EXCEL,
    MATNR      type CHAR20,"物料號
    MAKTX      type CHAR20,"物料描述(短文字)
    WERKS      type CHAR20,"工廠
    PLNNR      type CHAR20,"任務清單組碼
    PLNAL      type CHAR20,"組計數器
    KTEXT      type CHAR20,"任務清單描述
    PLNNR_ALT  type CHAR20,"舊號
    SLWBEZ     type CHAR20,"檢驗點

    VORNR      type CHAR20,"操作/活動編號
*    ARBID      like PLPO-ARBID,"物件標識(工作中心ID)
    ARBPL      type CHAR50,"工作中心(PLPO-ARIBD= CRHD-OBJID
*         STEUS      like PLPO-STEUS,"控制碼
    LTXA1      type CHAR20,"工序短文字
    VERWMERKM  type CHAR20,"主檔案檢驗特性
    KURZTEXT   type CHAR20,"檢驗特性的短文字
    PMETHODE   type CHAR20,"檢驗方法
    STICHPRVER type CHAR20,"檢驗特性中的取樣程式
    PROBEMGEH  type CHAR20,"取樣計量單位
    SOLLWERT   type CHAR20,"一個數量特性的目標值
    TOLERANZUN type CHAR20,"容差下限
    TOLERANZOB type CHAR20,"規範上限
  end of LS_EXCEL.



data:
  GT_RAW_TAB type          TRUXS_T_TEXT_DATA,
  GT_EXCEL   type table of LS_EXCEL,
  GT_ALV     type table of LS_ITAB ,
  GS_ALV     type          LS_ITAB.
data:GT_DOWNLOAD type table of LS_EXCEL with header line.

data:
  CL_ALVGRID   type ref to CL_GUI_ALV_GRID,
  CL_CONTAINER type ref to CL_GUI_CONTAINER,
  CL_SPLITTER  type ref to CL_GUI_SPLITTER_CONTAINER,
  CL_CONTROL   type ref to I_OI_CONTAINER_CONTROL,
  CL_ERROR     type ref to I_OI_ERROR,
  CL_ERRORS    type ref to I_OI_ERROR occurs 0 with header line,
  GT_FIELDCAT  type        LVC_T_FCAT,
  GS_LAYOUT    type        LVC_S_LAYO ,
  GT_EXCLUDE   type        UI_FUNCTIONS,
  OK_CODE      type        SY-UCOMM.

data: GT_CPS_TASK_LIST_MAINT_CHA type standard table of CPS_TASK_LIST_MAINT_CHA.

constants:
  GC_DEFAULT type STRING value 'C:\ZQMC002.xls'.

************************************************************************
*                  INITIALIZATION                                      *
************************************************************************
initialization.




************************************************************************
*                  SELECTION SCREEN                                    *
************************************************************************

  selection-screen begin of block BL1  with frame title TEXT-001.

  parameter P1 type C radiobutton group G1.

  select-options:
  S_WERKS for MARC-WERKS,  "工廠
  S_MATNR for MARA-MATNR,  "物料編號
  S_MTART for MARA-MTART. "物料型別
  parameter P2 type C radiobutton group G1 default 'X'.

  selection-screen end of block BL1.

  parameters:
    P_FILE type RLGRAP-FILENAME default 'C:\ZQMC002.xlsx'.


at selection-screen on value-request for P_FILE.

  perform GET_LOCALFILEPATH
  using
        'xlsx'
        'O'
        SY-TITLE
  changing
    P_FILE.





************************************************************************
*               START-OF-SELECTION                                     *
************************************************************************
start-of-selection.

  if P1 eq 'X'.
    perform CREATE_TEMPLATE_DOWNLOAD.
  endif.

  if P2 eq 'X'.
    perform UPLOAD_EXCEL.
    perform FILL_ITAB.
    call screen 9000.
  endif.


*&---------------------------------------------------------------------*
*&      Form  UPLOAD_EXCEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form UPLOAD_EXCEL .

  data: LS_EXCEL type LS_EXCEL,
        LS_ALV   type LS_ITAB.

  call function 'TEXT_CONVERT_XLS_TO_SAP'
    exporting
*     I_FIELD_SEPERATOR    =
      I_LINE_HEADER        = 'X'
      I_TAB_RAW_DATA       = GT_RAW_TAB
      I_FILENAME           = P_FILE
    tables
      I_TAB_CONVERTED_DATA = GT_EXCEL
*   EXCEPTIONS
*     CONVERSION_FAILED    = 1
*     OTHERS               = 2
    .
  if SY-SUBRC <> 0.
*   Implement suitable error handling here
  endif.


  loop at GT_EXCEL into LS_EXCEL.
    move-corresponding LS_EXCEL to LS_ALV.
    append LS_ALV to GT_ALV.
  endloop.

  data: LT_WERKS type table of LS_ITAB with header line.
  LT_WERKS[] = GT_ALV[].

  sort LT_WERKS by WERKS.

  delete LT_WERKS where WERKS is initial.

  delete adjacent duplicates from LT_WERKS comparing WERKS.

*檢查工廠許可權C_ROUT
  loop at LT_WERKS.
    authority-check object 'C_ROUT' id 'WERKS' field LT_WERKS-WERKS.

    data: L_STR type STRING.
    if SY-SUBRC ne 0.
      concatenate '沒有工廠 ' LT_WERKS-WERKS '操作許可權' into L_STR.
      message S011(ZMM) with L_STR display like 'E'.
      stop.
      "     leave to current transaction and skip first screen.
    endif.
  endloop.
endform.                    " UPLOAD_EXCEL
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module STATUS_9000 output.

  set pf-status 'STATUS_9000'.
  set titlebar 'TITLE_9000'.

endmodule.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  DISPLAY_ALV  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module DISPLAY_ALV output.
  perform DISPLAY_ALV.
endmodule.                 " DISPLAY_ALV  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISPLAY_ALV .

  if CL_ALVGRID is initial .

* 建立CONTIANER
    create object CL_SPLITTER
      exporting
        PARENT  = CL_GUI_CONTAINER=>SCREEN0
        ROWS    = 1
        COLUMNS = 1.
    call method CL_SPLITTER->SET_BORDER
      exporting
        BORDER = CL_GUI_CFW=>FALSE.
    CL_CONTAINER  = CL_SPLITTER->GET_CONTAINER( ROW = 1 COLUMN = 1 ).


    if SY-SUBRC <> 0.
*     Exception handling
    endif.

    create object CL_ALVGRID
      exporting
        I_PARENT          = CL_CONTAINER
      exceptions
        ERROR_CNTL_CREATE = 1
        ERROR_CNTL_INIT   = 2
        ERROR_CNTL_LINK   = 3
        ERROR_DP_CREATE   = 4
        others            = 5.
    if SY-SUBRC <> 0.
*      Exception handling
    endif.

*----Preparing field catalog.
    perform PREPARE_FIELD_CATALOG changing GT_FIELDCAT .

*----Preparing layout structure
    perform PREPARE_LAYOUT changing GS_LAYOUT .


    call method CL_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY
      exporting
*       I_BUFFER_ACTIVE               =
*       I_CONSISTENCY_CHECK           =
*       I_STRUCTURE_NAME              =
*       IS_VARIANT                    =
*       I_SAVE                        =
*       I_DEFAULT                     = 'X'
        IS_LAYOUT                     = GS_LAYOUT
*       IS_PRINT                      =
*       IT_SPECIAL_GROUPS             =
        IT_TOOLBAR_EXCLUDING          = GT_EXCLUDE
*       IT_HYPERLINK                  =
      changing
        IT_OUTTAB                     = GT_ALV
        IT_FIELDCATALOG               = GT_FIELDCAT
*       IT_SORT                       =
*       IT_FILTER                     =
      exceptions
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        others                        = 4.
    if SY-SUBRC <> 0.
    endif.




  else .
    call method CL_ALVGRID->SET_FRONTEND_LAYOUT
      exporting
        IS_LAYOUT = GS_LAYOUT.



    call method CL_ALVGRID->REFRESH_TABLE_DISPLAY
*     EXPORTING
*       IS_STABLE =
*       I_SOFT_REFRESH =
      exceptions
        FINISHED = 1
        others   = 2.
    if SY-SUBRC <> 0.

    endif.
*    CALL METHOD CL_GUI_CFW=>FLUSH.


  endif .

endform.                    " DISPLAY_ALV

*&---------------------------------------------------------------------*
*&      Form  PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
form PREPARE_FIELD_CATALOG changing PT_FIELDCAT type LVC_T_FCAT .
  data LS_FCAT type LVC_S_FCAT .

  refresh PT_FIELDCAT.


  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'STATUS'.
  LS_FCAT-COLTEXT = '匯入結果' .
*  LS_FCAT-INTLEN = 50.
  LS_FCAT-OUTPUTLEN = 4.
  append LS_FCAT to PT_FIELDCAT .




  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'MATNR'.
  LS_FCAT-COLTEXT = '物料編碼' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'MAKTX'.
  LS_FCAT-COLTEXT = '物料描述' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'WERKS'.
  LS_FCAT-COLTEXT = '工廠' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'PLNNR'.
  LS_FCAT-COLTEXT = '組' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'PLNAL'.
  LS_FCAT-COLTEXT = '組計數器' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'KTEXT'.
  LS_FCAT-COLTEXT = '任務清單描述' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'PLNNR_ALT'.
  LS_FCAT-COLTEXT = '舊任務清單' .
  append LS_FCAT to PT_FIELDCAT .


  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'SLWBEZ'.
  LS_FCAT-COLTEXT = '檢驗點' .
  append LS_FCAT to PT_FIELDCAT .



  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'VORNR'.
  LS_FCAT-COLTEXT = '工序' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'ARBPL'.
  LS_FCAT-COLTEXT = '工作中心' .
  append LS_FCAT to PT_FIELDCAT .


*  clear LS_FCAT.
*  LS_FCAT-FIELDNAME = 'STEUS'.
*  LS_FCAT-COLTEXT = '控制碼' .
*  append LS_FCAT to PT_FIELDCAT .


  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'LTXA1'.
  LS_FCAT-COLTEXT = '工序描述' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'VERWMERKM'.
  LS_FCAT-COLTEXT = '主檢驗特性' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'KURZTEXT'.
  LS_FCAT-COLTEXT = '特性描述' .
  append LS_FCAT to PT_FIELDCAT .


  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'PMETHODE'.
  LS_FCAT-COLTEXT = '檢驗方法' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'STICHPRVER'.
  LS_FCAT-COLTEXT = '取樣過程' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'PROBEMGEH'.
  LS_FCAT-COLTEXT = '取樣單位' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'SOLLWERT'.
  LS_FCAT-COLTEXT = '目標值' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'TOLERANZUN'.
  LS_FCAT-COLTEXT = '規範下限' .
  append LS_FCAT to PT_FIELDCAT .


  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'TOLERANZOB'.
  LS_FCAT-COLTEXT = '規範上限' .
  append LS_FCAT to PT_FIELDCAT .

  clear LS_FCAT.
  LS_FCAT-FIELDNAME = 'MESSAGE'.
  LS_FCAT-COLTEXT = '匯入資訊' .
*  LS_FCAT-INTLEN = 50.
  LS_FCAT-OUTPUTLEN = 20.
  append LS_FCAT to PT_FIELDCAT .



endform .
*&---------------------------------------------------------------------*
*&      Form  PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GS_LAYOUT  text
*----------------------------------------------------------------------*
form PREPARE_LAYOUT changing PS_LAYOUT type LVC_S_LAYO.

  clear PS_LAYOUT.
  PS_LAYOUT-ZEBRA = 'X' .
  PS_LAYOUT-CWIDTH_OPT = 'X'.
  PS_LAYOUT-SEL_MODE = 'A'.
  PS_LAYOUT-BOX_FNAME = 'MARK'.

endform. " prepare_layout

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module USER_COMMAND_9000 input.

  case OK_CODE.
    when 'ZBACK'.
      leave to screen 0.

    when 'ZEXIT' or 'ZCANCEL'.
      leave program.


    when 'ZCREATE'.

      perform MODIFY_ROUTING.

    when others.

  endcase.

endmodule.                 " USER_COMMAND_9000  INPUT


*&---------------------------------------------------------------------*
*&      Form  get_localfilepath
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MASK     text
*      -->P_SORO     text
*      -->P_TITLE    text
*      -->P_FILE     text
*----------------------------------------------------------------------*
form GET_LOCALFILEPATH
using
      P_MASK  type C
      P_SORO type C
      P_TITLE type C
changing
  P_FILE  like RLGRAP-FILENAME
  .
  data: L_SORO(1)      type C,
        L_MASK_U(8)    type C,
        L_MASK_L(8)    type C,
        L_MASK_ALL(30) type C,
        L_TITLE        type STRING,
        L_SUBRC        like SY-SUBRC.
  L_SORO = P_SORO.
  translate L_SORO to upper case.
  if not ( L_SORO = 'S' or L_SORO = 'O' ).
    message I398(00) with '開啟模式只能是S或者O!'.
  endif.
  L_MASK_U = P_MASK.
  L_MASK_L = P_MASK.
  translate L_MASK_U to upper case .
  translate L_MASK_L to lower case.
*  concatenate ',*.' L_MASK_L ',*.' L_MASK_U ',*.*' into L_MASK_ALL.
  concatenate  ',*.xls'  ',*.XLS' ',*.xlsx'  ',*.XLSX' ',*.*' into L_MASK_ALL.
  "{added in 20130208:將功能名新增到標題上
  concatenate P_TITLE '-開啟本地路徑' into L_TITLE.
  "}
  "{added in 20090416:設定全域性引數
  if P_FILE is initial.
    get parameter id 'FILE' field P_FILE.
  endif.
  "}
  call function 'WS_FILENAME_GET'
    exporting
      MASK             = L_MASK_ALL
      MODE             = L_SORO
      DEF_FILENAME     = P_FILE
      TITLE            = L_TITLE
    importing
      FILENAME         = P_FILE
    exceptions
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      others           = 5.
  if SY-SUBRC = 0.
    set parameter id 'FILE' field P_FILE.
  endif.
endform. "get_localfile


form MODIFY_ROUTING.

  data: LS_TSK       type                   CPS_TASK_LIST_MAINT_TSK,
        LS_TSK_X     type                   CPS_TASK_LIST_MAINT_TSK_X,
        LT_OPR       type standard table of CPS_TASK_LIST_MAINT_OPR,
        LS_OPR       type                   CPS_TASK_LIST_MAINT_OPR,
        LT_CHA       like                   GT_CPS_TASK_LIST_MAINT_CHA,
        LS_CHA       type                   CPS_TASK_LIST_MAINT_CHA,
        LT_RETURN    type table of          BAPIRET2 with header line,
        L_TEXT       type table of          BAPI1012_TXT_C,
        LV_RESULT(4) type                   C,
        LV_MSG       type                   STRING,
        LV_FROM      type                   I,
        LV_TO        type                   I,
        LV_TABIX     type                   SY-TABIX.
  data: L_PLNNR type PLKO-PLNNR,L_PLNAL type PLKO-PLNAL.
  data: LV_GROUP like MAPL-PLNNR.       " 組
  data: begin of LT_MARA occurs 0,
          MATNR like MARA-MATNR,
          MEINS like MARA-MEINS,
        end of LT_MARA.

  data:L_INSPCHAR_COUNT type I.
  data:LS_ALV type LS_ITAB.


*
  if GT_ALV[] is not initial.

    sort LT_MARA by MATNR.
*    loop at GT_ALV into GS_ALV.
*
*      if GS_ALV-PLNAL is not initial.
*
*        call function 'CONVERSION_EXIT_ALPHA_INPUT'
*          exporting
*            INPUT  = GS_ALV-VORNR
*          importing
*            OUTPUT = GS_ALV-VORNR.
*
*        call function 'CONVERSION_EXIT_ALPHA_INPUT'
*          exporting
*            INPUT  = GS_ALV-PLNAL
*          importing
*            OUTPUT = GS_ALV-PLNAL.
*        LS_ALV = GS_ALV.
*        modify GT_ALV from GS_ALV index SY-TABIX transporting  VORNR PLNAL .
*      else.
*        call function 'CONVERSION_EXIT_ALPHA_INPUT'
*          exporting
*            INPUT  = LS_ALV-VORNR
*          importing
*            OUTPUT = LS_ALV-VORNR.
*
*        call function 'CONVERSION_EXIT_ALPHA_INPUT'
*          exporting
*            INPUT  = LS_ALV-PLNAL
*          importing
*            OUTPUT = LS_ALV-PLNAL.
*        GS_ALV-MATNR = LS_ALV-MATNR.
*        GS_ALV-MAKTX = LS_ALV-MAKTX.
*        GS_ALV-WERKS = LS_ALV-WERKS.
*        GS_ALV-PLNNR = LS_ALV-PLNNR.
*        GS_ALV-PLNAL = LS_ALV-PLNAL.
*        GS_ALV-KTEXT = LS_ALV-KTEXT.
*        GS_ALV-PLNNR_ALT = LS_ALV-PLNNR_ALT.
*        GS_ALV-SLWBEZ = LS_ALV-SLWBEZ.
*
*        if GS_ALV-VORNR is initial.
*          GS_ALV-VORNR = LS_ALV-VORNR.
*          GS_ALV-ARBPL = LS_ALV-ARBPL.
*          GS_ALV-LTXA1 = LS_ALV-LTXA1.
*        endif.
*
*        modify GT_ALV from GS_ALV index SY-TABIX transporting MATNR MAKTX WERKS PLNNR PLNAL KTEXT PLNNR_ALT SLWBEZ VORNR ARBPL LTXA1.
*
*      endif.
*
*    endloop.
  endif.




  clear: L_PLNNR, L_PLNAL.
  loop at GT_ALV into GS_ALV.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        INPUT  = GS_ALV-VORNR
      importing
        OUTPUT = GS_ALV-VORNR.




    if  L_PLNNR ne GS_ALV-PLNNR  or  L_PLNAL ne GS_ALV-PLNAL  ."一個新的組開始,
*


*準備新組資料
      refresh: LT_OPR,LT_CHA.
      clear: LS_OPR,LS_TSK,LS_TSK_X,LS_CHA.

      L_PLNNR = GS_ALV-PLNNR.
      L_PLNAL = GS_ALV-PLNAL.

      LS_TSK-IDENT_KEY = GS_ALV-SLWBEZ.
      LS_TSK_X-IDENT_KEY = 'X'.
      LS_TSK-OLD_NUMBER_OF_TASK_LIST = GS_ALV-PLNNR_ALT."'Z50'.
      LS_TSK_X-OLD_NUMBER_OF_TASK_LIST = 'X'.

    endif.



    if LS_OPR-ACTIVITY ne GS_ALV-VORNR.
      L_INSPCHAR_COUNT = 10."檢驗特性編號初始值
      clear LS_OPR.
      LS_OPR-MAINTAIN_MODE = 'C'.
      LS_OPR-ACTIVITY = GS_ALV-VORNR.
      LS_OPR-SEQUENCE_NO = '000000'.
      LS_OPR-CONTROL_KEY = 'QM01'.
      LS_OPR-WORK_CNTR = GS_ALV-ARBPL.
      LS_OPR-PLANT = GS_ALV-WERKS.
      LS_OPR-BASE_QUANTITY = '1'.
      LS_OPR-DENOMINATOR = '1'.
      LS_OPR-NOMINATOR = '1'.
*      LS_OPR-OPERATION_MEASURE_UNIT = 'KG'.
      LS_OPR-DESCRIPTION = GS_ALV-LTXA1.
      LS_OPR-INSP_POINT_COMPLT_FLOW_VARIANT = 2."檢驗點完成   這個只能修改用,因為TSK中IDENT_KEY設定值,就不允許輸入過程
      LS_OPR-FREE_GRID = 'X'."間隔無時間或數量參考 這個只能修改用,因為TSK中IDENT_KEY設定值,就不允許輸入過程

*      LS_OPR-MAINTAIN_MODE = 'C'.
*      LS_OPR-ACTIVITY = '0040'.
*      LS_OPR-SEQUENCE_NO = '000000'.
*      LS_OPR-CONTROL_KEY = 'QM01'.
*      LS_OPR-WORK_CNTR = 'Q2001001'.
*      LS_OPR-PLANT = '2001'.
*      LS_OPR-BASE_QUANTITY = '1'.
*      LS_OPR-DENOMINATOR = '1'.
*      LS_OPR-NOMINATOR = '1'.
**    LS_OPR-OPERATION_MEASURE_UNIT = 'KG'.
*      LS_OPR-DESCRIPTION = 'Operation created'.
*      LS_OPR-INSP_POINT_COMPLT_FLOW_VARIANT = 2."檢驗點完成   這個只能修改用,因為TSK中IDENT_KEY設定值,就不允許輸入過程
*      LS_OPR-FREE_GRID = 'X'."間隔無時間或數量參考 這個只能修改用,因為TSK中IDENT_KEY設定值,就不允許輸入過程

      append LS_OPR to LT_OPR.
    endif.


    perform FILL_CHA tables LT_CHA
                     changing LS_CHA
                      L_INSPCHAR_COUNT.


    at end of PLNAL.




      call function 'CPCC_S_TASK_LIST_MAINTAIN'
        exporting
*         CHANGE_NO                  =
          KEY_DATE                   = SY-DATUM
          TASK_LIST_TYPE             = 'N'
          TASK_LIST_GROUP            = GS_ALV-PLNNR  "L_PLNNR
          GROUP_COUNTER              = L_PLNAL "GS_ALV-PLNAL
          TASK_MAINTAIN_MODE         = 'M'
          TASK                       = LS_TSK
          TASK_X                     = LS_TSK_X
        tables
          OPERATIONS                 = LT_OPR
*         operations_x               = lt_opr_x
          INSPECTION_CHARACTERISTICS = LT_CHA
*         inspection_characteristics_x = lt_cha_x
*         inspection_values          = lt_chv
*         inspection_values_x        = lt_chv_x
          RETURN                     = LT_RETURN.

      clear LV_RESULT.
      LV_RESULT = '成功'.
      loop at LT_RETURN where TYPE = 'E' or TYPE = 'A'.

        LV_RESULT = '失敗'.
        exit.
      endloop.
      clear LV_MSG.

      if LV_RESULT eq '失敗'.
        call function 'BAPI_TRANSACTION_ROLLBACK'.
        call function 'FORMAT_MESSAGE'
          exporting
            ID        = LT_RETURN-ID
            LANG      = SY-LANGU
            NO        = LT_RETURN-NUMBER
            V1        = LT_RETURN-MESSAGE_V1
            V2        = LT_RETURN-MESSAGE_V2
            V3        = LT_RETURN-MESSAGE_V3
            V4        = LT_RETURN-MESSAGE_V4
          importing
            MSG       = LV_MSG
          exceptions
            NOT_FOUND = 1
            others    = 2.


      else.
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            WAIT = 'X'.

        read table LT_RETURN with key TYPE = 'S'.
        call function 'FORMAT_MESSAGE'
          exporting
            ID        = LT_RETURN-ID
            LANG      = SY-LANGU
            NO        = LT_RETURN-NUMBER
            V1        = LT_RETURN-MESSAGE_V1
            V2        = LT_RETURN-MESSAGE_V2
            V3        = LT_RETURN-MESSAGE_V3
            V4        = LT_RETURN-MESSAGE_V4
          importing
            MSG       = LV_MSG
          exceptions
            NOT_FOUND = 1
            others    = 2.
      endif.

      read table GT_ALV into GS_ALV with key PLNNR = L_PLNNR PLNAL = L_PLNAL.
      GS_ALV-STATUS = LV_RESULT.
      GS_ALV-MESSAGE = LV_MSG.
      modify GT_ALV from GS_ALV index SY-TABIX transporting STATUS MESSAGE  .

    endat.




  endloop.








endform.
*&---------------------------------------------------------------------*
*&      Form  FILL_CHA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form FILL_CHA    tables    LT_CHA  like GT_CPS_TASK_LIST_MAINT_CHA
                 changing LS_CHA    type  CPS_TASK_LIST_MAINT_CHA
                   L_INSPCHAR_COUNT type I.

  data: LV_KURZTEXT like QPMT-KURZTEXT.
  data:LV_STEUERKZ like QPMK-STEUERKZ.
  data: LV_STELLEN like QPMK-STELLEN.
  data:LV_MASSEINHSW like QPMK-MASSEINHSW.
  data:L_AUSWMENGE1 like QPMZ-AUSWMENGE1.

  clear LS_CHA.

  write L_INSPCHAR_COUNT to LS_CHA-INSPCHAR.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      INPUT  = LS_CHA-INSPCHAR
    importing
      OUTPUT = LS_CHA-INSPCHAR.

  LS_CHA-MAINTAIN_MODE = 'C'.
  LS_CHA-SEQUENCE_NO = '000000'.
  LS_CHA-ACTIVITY = GS_ALV-VORNR.
*  LS_CHA-INSPCHAR = LS_CHA-INSPCHAR."檢驗特性編號


  LS_CHA-MSTR_CHAR = GS_ALV-VERWMERKM."主檔案檢驗特性100-001
  LS_CHA-PMSTR_CHAR = GS_ALV-WERKS."工廠
*    LS_CHA-VMSTR_CHAR = '000001'."version.

  clear LV_KURZTEXT.
  select single KURZTEXT into LV_KURZTEXT
  from QPMT
  where ZAEHLER = LS_CHA-PMSTR_CHAR
  and MKMNR = LS_CHA-MSTR_CHAR.

  LS_CHA-CHAR_DESCR = LV_KURZTEXT.

  LS_CHA-METHOD = GS_ALV-PMETHODE.        "方法。
  LS_CHA-PMETHOD = GS_ALV-WERKS.        "工廠
  LS_CHA-VMETHOD = '000001'."version.

  clear: LV_STEUERKZ,LV_STELLEN, LV_MASSEINHSW.
  select single STEUERKZ STELLEN MASSEINHSW
  into (LV_STEUERKZ, LV_STELLEN, LV_MASSEINHSW)
  from QPMK
  where ZAEHLER = LS_CHA-PMSTR_CHAR
  and MKMNR = LS_CHA-MSTR_CHAR.


  LS_CHA-DEC_PLACES = LV_STELLEN.
  LS_CHA-MEAS_UNIT  = LV_MASSEINHSW.
*XX X  =   X    X


  LS_CHA-QUANTITATIVE_IND = LV_STEUERKZ+0(1)."是否是數量特性。等於X是,QN=X;空時QL=X
  LS_CHA-MEAS_VALUE_CONFIRM_IND = LV_STEUERKZ+1(1).     "                         x
  LS_CHA-ATTRIBUTE_REQUIRED_IND = LV_STEUERKZ+2(1)."選擇集
  LS_CHA-UP_TOL_LMT_IND = LV_STEUERKZ+3(1)."
  LS_CHA-LW_TOL_LMT_IND = LV_STEUERKZ+4(1).
  LS_CHA-TARGET_VAL_CHECK_IND = LV_STEUERKZ+5(1).
  LS_CHA-SCOPE_IND = LV_STEUERKZ+6(1)."= 固定的檢驗範圍 ;  不固定範圍 ;  < 允許的小的檢驗範圍 ;  >  允許的大的檢驗範圍
  LS_CHA-LONG_TERM_INSP_IND = LV_STEUERKZ+7(1).
  LS_CHA-RESULT_RECORDING_TYPE = LV_STEUERKZ+8(1). " '' 彙總記錄 ; +  單值記錄 ;* 分類記錄; - 無結果記錄
  LS_CHA-DOCU_REQU = LV_STEUERKZ+9(1).
  LS_CHA-CONFIRMATION_CATEGORY = LV_STEUERKZ+10(1).  "x
  LS_CHA-ADD_SAMPLE_QUANTITY = LV_STEUERKZ+11(1).
  LS_CHA-DESTRUCTIVE_INSP_IND = LV_STEUERKZ+12(1).
  LS_CHA-FORMULA_IND = LV_STEUERKZ+13(1).
  LS_CHA-SAMPLING_PROCEDURE_IND = LV_STEUERKZ+15(1)."是否有采樣過程




  if  LS_CHA-SAMPLING_PROCEDURE_IND is not initial.
    LS_CHA-SMPL_PROCEDURE = GS_ALV-STICHPRVER."取樣過程
    LS_CHA-SMPL_UNIT = GS_ALV-PROBEMGEH.     "取樣單位
    LS_CHA-SMPL_QUANT = '1'."取樣的取樣數量因子(多重取樣計量單位)
  endif.


  LS_CHA-TARGET_VAL = GS_ALV-SOLLWERT."一個數量特性的目標值
  LS_CHA-TARGET_VAL_NI = 'X'."一個數量特性的目標值
  if LS_CHA-TARGET_VAL_CHECK_IND is not initial.
    LS_CHA-TARGET_VAL = GS_ALV-SOLLWERT."一個數量特性的目標值
    LS_CHA-TARGET_VAL_NI = 'X'."一個數量特性的目標值
  endif.




  if LS_CHA-UP_TOL_LMT_IND is not initial and GS_ALV-TOLERANZOB is not initial and GS_ALV-TOLERANZOB ne 0.

    LS_CHA-UP_TOL_LMT = GS_ALV-TOLERANZOB.
    LS_CHA-UP_TOL_LMT_NI = 'X'."一個數量特性的目標值
  else.
    LS_CHA-UP_TOL_LMT_IND = ''.
  endif.

  if LS_CHA-LW_TOL_LMT_IND is not initial and GS_ALV-TOLERANZUN is not initial and GS_ALV-TOLERANZUN ne 0.
    LS_CHA-LW_TOL_LMT =  GS_ALV-TOLERANZUN.
    LS_CHA-LW_TOL_LMT_NI = 'X'."一個數量特性的目標值
  else.
    LS_CHA-LW_TOL_LMT_IND = ''.
  endif.

  if LS_CHA-ATTRIBUTE_REQUIRED_IND is not initial.
    LS_CHA-IND_SELSET_OR_CODEGRP1 = 'X'."目錄條目是一個選擇集
    LS_CHA-CAT_TYPE1  = 'X'.
    select single AUSWMENGE1 into L_AUSWMENGE1
    from QPMZ
    where ZAEHLER = LS_CHA-PMSTR_CHAR
    and MKMNR = LS_CHA-MSTR_CHAR.

    LS_CHA-SEL_SET1 = L_AUSWMENGE1.     "分配的程式碼組或選擇集
    LS_CHA-PSEL_SET1 =  GS_ALV-WERKS."分配的選擇集的工廠
  endif.

  append LS_CHA to LT_CHA.
  L_INSPCHAR_COUNT = L_INSPCHAR_COUNT + 10.


*  clear LS_CHA.
*  LS_CHA-MAINTAIN_MODE = 'C'.
*  LS_CHA-SEQUENCE_NO = '000000'.
*  LS_CHA-ACTIVITY = '0040'.
*  LS_CHA-INSPCHAR = '110'."檢驗特性編號
*
*
*  LS_CHA-MSTR_CHAR = '300-024'."主檔案檢驗特性100-001
*  LS_CHA-PMSTR_CHAR = '2001'."工廠
**    LS_CHA-VMSTR_CHAR = '000001'."version.
*
*  select single KURZTEXT into LV_KURZTEXT
*  from QPMT
*  where ZAEHLER = LS_CHA-PMSTR_CHAR
*  and MKMNR = LS_CHA-MSTR_CHAR.
*
*  LS_CHA-CHAR_DESCR = LV_KURZTEXT.
*
*  LS_CHA-METHOD = 'GB/T5530'.        "方法。
*  LS_CHA-PMETHOD = '2001'.        "工廠
*  LS_CHA-VMETHOD = '000001'."version.
*
*  clear: LV_STEUERKZ,LV_STELLEN, LV_MASSEINHSW.
*  select single STEUERKZ STELLEN MASSEINHSW
*  into (LV_STEUERKZ, LV_STELLEN, LV_MASSEINHSW)
*  from QPMK
*  where ZAEHLER = LS_CHA-PMSTR_CHAR
*  and MKMNR = LS_CHA-MSTR_CHAR.
*
*
*  LS_CHA-DEC_PLACES = LV_STELLEN.
*  LS_CHA-MEAS_UNIT  = LV_MASSEINHSW.
*
*  LS_CHA-QUANTITATIVE_IND = LV_STEUERKZ+0(1)."是否是數量特性。等於X是,QN=X;空時QL=X
*  LS_CHA-MEAS_VALUE_CONFIRM_IND = LV_STEUERKZ+1(1).     "                         x
*  LS_CHA-ATTRIBUTE_REQUIRED_IND = LV_STEUERKZ+2(1)."選擇集
*  LS_CHA-UP_TOL_LMT_IND = LV_STEUERKZ+3(1)."
*  LS_CHA-LW_TOL_LMT_IND = LV_STEUERKZ+4(1).
*  LS_CHA-TARGET_VAL_CHECK_IND = LV_STEUERKZ+5(1).
*  LS_CHA-SCOPE_IND = LV_STEUERKZ+6(1)."= 固定的檢驗範圍 ;  不固定範圍 ;  < 允許的小的檢驗範圍 ;  >  允許的大的檢驗範圍
*  LS_CHA-LONG_TERM_INSP_IND = LV_STEUERKZ+7(1).
*  LS_CHA-RESULT_RECORDING_TYPE = LV_STEUERKZ+8(1). " '' 彙總記錄 ; +  單值記錄 ;* 分類記錄; - 無結果記錄
*  LS_CHA-DOCU_REQU = LV_STEUERKZ+9(1).
*  LS_CHA-CONFIRMATION_CATEGORY = LV_STEUERKZ+10(1).  "x
*  LS_CHA-ADD_SAMPLE_QUANTITY = LV_STEUERKZ+11(1).
*  LS_CHA-DESTRUCTIVE_INSP_IND = LV_STEUERKZ+12(1).
*  LS_CHA-FORMULA_IND = LV_STEUERKZ+13(1).
*  LS_CHA-SAMPLING_PROCEDURE_IND = LV_STEUERKZ+15(1)."是否有采樣過程
*
*  if  LS_CHA-SAMPLING_PROCEDURE_IND is not initial.
*    LS_CHA-SMPL_PROCEDURE = '1003'."取樣過程
*    LS_CHA-SMPL_UNIT = 'KG'.     "取樣單位
*    LS_CHA-SMPL_QUANT = '1'."取樣的取樣數量因子(多重取樣計量單位)
*  endif.
*
*
*  if LS_CHA-TARGET_VAL_CHECK_IND is not initial.
*    LS_CHA-TARGET_VAL = '100'."一個數量特性的目標值
*    LS_CHA-TARGET_VAL_NI = 'X'."一個數量特性的目標值
*  endif.
*
*
*  if LS_CHA-LW_TOL_LMT_IND is not initial.
*    LS_CHA-LW_TOL_LMT = '90'.
*    LS_CHA-LW_TOL_LMT_NI = 'X'."一個數量特性的目標值
*  endif.
*
*  if LS_CHA-UP_TOL_LMT_IND is not initial.
*    LS_CHA-UP_TOL_LMT = '110'.
*    LS_CHA-UP_TOL_LMT_NI = 'X'."一個數量特性的目標值
*  endif.
*
*  if LS_CHA-ATTRIBUTE_REQUIRED_IND is not initial.
**      LS_CHA-IND_SELSET_OR_CODEGRP1 = 'X'."目錄條目是一個選擇集
**      LS_CHA-CAT_TYPE1  = 'X'.
*    LS_CHA-SEL_SET1 = '02'.     "分配的程式碼組或選擇集
*    LS_CHA-PSEL_SET1 = '2001'."分配的選擇集的工廠
*  endif.
*
*  append LS_CHA to LT_CHA.





endform.                    " FILL_CHA
*&---------------------------------------------------------------------*
*&      Form  CREATE_TEMPLATE_DOWNLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form CREATE_TEMPLATE_DOWNLOAD .


*  物料編碼  物料描述  工廠  組 組計數器  任務清單描述  舊任務清單 檢驗點 工序  工作中心  工序描述  主檢驗特性 特性描述  檢驗方法  取樣過程  取樣單位  目標值 規範下限  規範上限
  GT_DOWNLOAD-MATNR = '物料編碼'.
  GT_DOWNLOAD-MAKTX = '物料描述'.
  GT_DOWNLOAD-WERKS = '工廠'.
  GT_DOWNLOAD-PLNNR = '組'.
  GT_DOWNLOAD-PLNAL = '組計數器'.
  GT_DOWNLOAD-KTEXT = '任務清單描述'.
  GT_DOWNLOAD-PLNNR_ALT = '舊任務清單'.
  GT_DOWNLOAD-SLWBEZ = '檢驗點'.
  GT_DOWNLOAD-VORNR = '工序'.
  GT_DOWNLOAD-ARBPL = '工作中心'.
  GT_DOWNLOAD-LTXA1 = '工序描述'.
  GT_DOWNLOAD-VERWMERKM = '主檢驗特性'.
  GT_DOWNLOAD-KURZTEXT = '特性描述'.
  GT_DOWNLOAD-PMETHODE = '檢驗方法'.
  GT_DOWNLOAD-STICHPRVER = '取樣過程'.
  GT_DOWNLOAD-PROBEMGEH = '取樣單位'.
  GT_DOWNLOAD-SOLLWERT = '目標值'.
  GT_DOWNLOAD-TOLERANZUN = '規範下限'.
  GT_DOWNLOAD-TOLERANZOB = '規範上限'.

  append GT_DOWNLOAD.

  select A~MATNR A~PLNNR A~WERKS A~PLNAL MAKTX KTEXT
  appending corresponding fields of table GT_DOWNLOAD
  from MAPL  as A
  inner join MARA as B on A~MATNR = B~MATNR
  inner join PLKO as C on A~PLNNR = C~PLNNR and A~PLNAL = C~PLNAL
  inner join MAKT as D on A~MATNR = D~MATNR and SPRAS = SY-LANGU
  where A~MATNR in S_MATNR and A~WERKS in S_WERKS and MTART in S_MTART and A~PLNTY = 'N'
  and A~LOEKZ eq SPACE and C~LOEKZ eq SPACE." .


  perform TEMPLATE_DOWNLOAD.

endform.                    " CREATE_TEMPLATE_DOWNLOAD


form TEMPLATE_DOWNLOAD.
  data: L_STR type STRING.
  L_STR = P_FILE.
  search L_STR for '.XLSX'.
  if SY-SUBRC ne 0.
    search L_STR for '.xlsx'.
    if SY-SUBRC ne 0.
      search L_STR for '.xls'.
      if SY-SUBRC ne 0.
        search L_STR for '.XLS'.
        if SY-SUBRC ne 0.

          concatenate L_STR '.xls' into L_STR.
        endif.
      endif.
    endif.

  endif.

  call function 'GUI_DOWNLOAD'
    exporting
*     BIN_FILESIZE            =
      FILENAME                = L_STR
      FILETYPE                = 'DAT'
*     CODEPAGE                = '8404'
    tables
      DATA_TAB                = GT_DOWNLOAD
*     FIELDNAMES              =
    exceptions
      FILE_WRITE_ERROR        = 1
      NO_BATCH                = 2
      GUI_REFUSE_FILETRANSFER = 3
      INVALID_TYPE            = 4
      NO_AUTHORITY            = 5
      UNKNOWN_ERROR           = 6
      HEADER_NOT_ALLOWED      = 7
      SEPARATOR_NOT_ALLOWED   = 8
      FILESIZE_NOT_ALLOWED    = 9
      HEADER_TOO_LONG         = 10
      DP_ERROR_CREATE         = 11
      DP_ERROR_SEND           = 12
      DP_ERROR_WRITE          = 13
      UNKNOWN_DP_ERROR        = 14
      ACCESS_DENIED           = 15
      DP_OUT_OF_MEMORY        = 16
      DISK_FULL               = 17
      DP_TIMEOUT              = 18
      FILE_NOT_FOUND          = 19
      DATAPROVIDER_EXCEPTION  = 20
      CONTROL_FLUSH_ERROR     = 21
      others                  = 22.
  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  FILL_ITAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form FILL_ITAB .
  data:LT_ITAB type table of LS_ITAB with header line.
  data:LT_QPMT type table of QPMT with header line.


  data:LS_ALV type LS_ITAB.


*
  if GT_ALV[] is not initial.


    loop at GT_ALV into GS_ALV.

      if GS_ALV-PLNAL is not initial.

        call function 'CONVERSION_EXIT_ALPHA_INPUT'
          exporting
            INPUT  = GS_ALV-VORNR
          importing
            OUTPUT = GS_ALV-VORNR.

        call function 'CONVERSION_EXIT_ALPHA_INPUT'
          exporting
            INPUT  = GS_ALV-PLNAL
          importing
            OUTPUT = GS_ALV-PLNAL.
        LS_ALV = GS_ALV.
        modify GT_ALV from GS_ALV index SY-TABIX transporting  VORNR PLNAL .
      else.
        if GS_ALV-VORNR is not initial.
          LS_ALV-VORNR = GS_ALV-VORNR.
          LS_ALV-ARBPL = GS_ALV-ARBPL.
          LS_ALV-LTXA1 = GS_ALV-LTXA1.
        endif.


        call function 'CONVERSION_EXIT_ALPHA_INPUT'
          exporting
            INPUT  = LS_ALV-VORNR
          importing
            OUTPUT = LS_ALV-VORNR.

        call function 'CONVERSION_EXIT_ALPHA_INPUT'
          exporting
            INPUT  = LS_ALV-PLNAL
          importing
            OUTPUT = LS_ALV-PLNAL.
        GS_ALV-MATNR = LS_ALV-MATNR.
        GS_ALV-MAKTX = LS_ALV-MAKTX.
        GS_ALV-WERKS = LS_ALV-WERKS.
        GS_ALV-PLNNR = LS_ALV-PLNNR.
        GS_ALV-PLNAL = LS_ALV-PLNAL.
        GS_ALV-KTEXT = LS_ALV-KTEXT.
        GS_ALV-PLNNR_ALT = LS_ALV-PLNNR_ALT.
        GS_ALV-SLWBEZ = LS_ALV-SLWBEZ.

        if GS_ALV-VORNR is initial.
          GS_ALV-VORNR = LS_ALV-VORNR.
          GS_ALV-ARBPL = LS_ALV-ARBPL.
          GS_ALV-LTXA1 = LS_ALV-LTXA1.
        endif.

        modify GT_ALV from GS_ALV index SY-TABIX transporting MATNR MAKTX WERKS PLNNR PLNAL KTEXT PLNNR_ALT SLWBEZ VORNR ARBPL LTXA1.

      endif.

    endloop.
  endif.
  LT_ITAB[] = GT_ALV[].


  sort LT_ITAB by WERKS VERWMERKM.
  delete adjacent duplicates from LT_ITAB comparing WERKS VERWMERKM.

  if LT_ITAB[] is not initial.
    select ZAEHLER MKMNR KURZTEXT
    into corresponding fields of table LT_QPMT
    from QPMT
    for all entries in LT_ITAB
    where ZAEHLER = LT_ITAB-WERKS and  MKMNR = LT_ITAB-VERWMERKM and SPRACHE eq SY-LANGU.


    sort LT_QPMT by ZAEHLER MKMNR.

    loop at GT_ALV into GS_ALV.
      read table LT_QPMT with key ZAEHLER = GS_ALV-WERKS  MKMNR = GS_ALV-VERWMERKM.
      if SY-SUBRC eq 0.
        GS_ALV-KURZTEXT = LT_QPMT-KURZTEXT.
        modify GT_ALV from GS_ALV  transporting KURZTEXT where WERKS = GS_ALV-WERKS and VERWMERKM = GS_ALV-VERWMERKM.
      endif.
    endloop.
  endif.

endform.                    " FILL_ITAB

相關文章