*&---------------------------------------------------------------------*
*& 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 decimals ,"一个数量特性的目标值
TOLERANZUN type P length decimals ,"容差下限
TOLERANZOB type P length decimals ,"规范上限
MESSAGE type CHAR200,
STATUS(), 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 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-. 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 .
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 <> .
* 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 .
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 =
COLUMNS = .
call method CL_SPLITTER->SET_BORDER
exporting
BORDER = CL_GUI_CFW=>FALSE.
CL_CONTAINER = CL_SPLITTER->GET_CONTAINER( ROW = COLUMN = ). if SY-SUBRC <> .
* Exception handling
endif. create object CL_ALVGRID
exporting
I_PARENT = CL_CONTAINER
exceptions
ERROR_CNTL_CREATE =
ERROR_CNTL_INIT =
ERROR_CNTL_LINK =
ERROR_DP_CREATE =
others = .
if SY-SUBRC <> .
* 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 =
PROGRAM_ERROR =
TOO_MANY_LINES =
others = .
if SY-SUBRC <> .
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 =
others = .
if SY-SUBRC <> . 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 = .
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 = .
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 . 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() type C,
L_MASK_U() type C,
L_MASK_L() type C,
L_MASK_ALL() 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() 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 =
NO_BATCH =
SELECTION_CANCEL =
SELECTION_ERROR =
others = .
if SY-SUBRC = .
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() 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 ,
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 = ."检验特性编号初始值
clear LS_OPR.
LS_OPR-MAINTAIN_MODE = 'C'.
LS_OPR-ACTIVITY = GS_ALV-VORNR.
LS_OPR-SEQUENCE_NO = ''.
LS_OPR-CONTROL_KEY = 'QM01'.
LS_OPR-WORK_CNTR = GS_ALV-ARBPL.
LS_OPR-PLANT = GS_ALV-WERKS.
LS_OPR-BASE_QUANTITY = ''.
LS_OPR-DENOMINATOR = ''.
LS_OPR-NOMINATOR = ''.
* LS_OPR-OPERATION_MEASURE_UNIT = 'KG'.
LS_OPR-DESCRIPTION = GS_ALV-LTXA1.
LS_OPR-INSP_POINT_COMPLT_FLOW_VARIANT = ."检验点完成 这个只能修改用,因为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 =
others = . 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 =
others = .
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 = ''.
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 = ''."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+()."是否是数量特性。等于X是,QN=X;空时QL=X
LS_CHA-MEAS_VALUE_CONFIRM_IND = LV_STEUERKZ+(). " x
LS_CHA-ATTRIBUTE_REQUIRED_IND = LV_STEUERKZ+()."选择集
LS_CHA-UP_TOL_LMT_IND = LV_STEUERKZ+()."
LS_CHA-LW_TOL_LMT_IND = LV_STEUERKZ+().
LS_CHA-TARGET_VAL_CHECK_IND = LV_STEUERKZ+().
LS_CHA-SCOPE_IND = LV_STEUERKZ+()."= 固定的检验范围 ; 不固定范围 ; < 允许的小的检验范围 ; > 允许的大的检验范围
LS_CHA-LONG_TERM_INSP_IND = LV_STEUERKZ+().
LS_CHA-RESULT_RECORDING_TYPE = LV_STEUERKZ+(). " '' 汇总记录 ; + 单值记录 ;* 分类记录; - 无结果记录
LS_CHA-DOCU_REQU = LV_STEUERKZ+().
LS_CHA-CONFIRMATION_CATEGORY = LV_STEUERKZ+(). "x
LS_CHA-ADD_SAMPLE_QUANTITY = LV_STEUERKZ+().
LS_CHA-DESTRUCTIVE_INSP_IND = LV_STEUERKZ+().
LS_CHA-FORMULA_IND = LV_STEUERKZ+().
LS_CHA-SAMPLING_PROCEDURE_IND = LV_STEUERKZ+()."是否有采样过程 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 = ''."采样的采样数量因子(多重采样计量单位)
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 . 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 .
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 + . * 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 .
search L_STR for '.xlsx'.
if SY-SUBRC ne .
search L_STR for '.xls'.
if SY-SUBRC ne .
search L_STR for '.XLS'.
if SY-SUBRC ne . 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 =
NO_BATCH =
GUI_REFUSE_FILETRANSFER =
INVALID_TYPE =
NO_AUTHORITY =
UNKNOWN_ERROR =
HEADER_NOT_ALLOWED =
SEPARATOR_NOT_ALLOWED =
FILESIZE_NOT_ALLOWED =
HEADER_TOO_LONG =
DP_ERROR_CREATE =
DP_ERROR_SEND =
DP_ERROR_WRITE =
UNKNOWN_DP_ERROR =
ACCESS_DENIED =
DP_OUT_OF_MEMORY =
DISK_FULL =
DP_TIMEOUT =
FILE_NOT_FOUND =
DATAPROVIDER_EXCEPTION =
CONTROL_FLUSH_ERROR =
others = .
if SY-SUBRC <> .
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 .
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
05-06 07:26