KKS编码批量上传并创建,相关Tcode: IL01(创建功能位置)
上载模板:smw0-Webrfc 应用程序的二进制数据-对象名称-输入ZNYPMR00030
*&---------------------------------------------------------------------*
*&*********************************************************************
*& Program ID :
*& PROGRAM NAME :
*& Author :
*& Date :
*& Program Description :
*& CHANGE HISTORY
*& REQUEST NUMBER | CHANGED BY | DATE |DESCRIPTION
*&
*&*********************************************************************
REPORT ZNYPMR00030 NO STANDARD PAGE HEADING MESSAGE-ID oo.
* 全局变量定义
INCLUDE ZNYPMR0030_top.
* 注册按钮
LOAD-OF-PROGRAM.
SSCRFIELDS-FUNCTXT_01 = text-t01."下载模板
* 用户选择屏幕定义
SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_SWERK LIKE IFLOT-IWERK MODIF ID M2 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK BLK2.
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-002.
PARAMETERS P_FILE LIKE RLGRAP-FILENAME OBLIGATORY MODIF ID M1 DEFAULT '请选择Excel文件上传...'. "读取文件路径
SELECTION-SCREEN END OF BLOCK BLK1.
"设置选择屏幕按钮
SELECTION-SCREEN: FUNCTION KEY 1.
* 初始化
INITIALIZATION.
* PBO
at SELECTION-SCREEN.
* 批导模板
IF SSCRFIELDS-UCOMM = 'FC01'.
PERFORM FRM_DOWNLOAD_TEMPLATE.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
* 读取本地文件
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FRM_GET_FILE CHANGING p_file.
* PAI
START-OF-SELECTION.
* 权限检查
PERFORM FRM_CHECK_AUTHORITY.
* PERFORM FRM_CHECK_AUT USING LS_T001W-WERKS
* CHANGING LV_SUBRC.
* IF LV_SUBRC NE 0.
* "没有工厂的权限
* MESSAGE E001(00) WITH '没有工厂' LS_T001W-WERKS '的权限'.
* CONTINUE.
* ENDIF.
* 检验文件格式
PERFORM FRM_check_FILE USING p_file.
* 数据上传
PERFORM FRM_CHECK_UPLOAD_TABLE CHANGING LT_EXCEL. " CHANGING LT_item.
* 数据校验
PERFORM FRM_CHECK_ITEM USING lt_excel CHANGING lt_item.
* 数据显示
PERFORM FRM_dis_data USING LT_item.
INCLUDE znypmr00030_frm.
*----------------------------------------------------------------------*
***INCLUDE ZNYPMR00030_FRM.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DOWNLOAD_TEMPLATE .
*------定义Excel导出所需变量-----------------*
DATA: L_NAME LIKE WWWDATATAB, "记录XLS模板文件名的结构, 该模板文件存在于SAP系统服务器中
L_MIME LIKE W3MIME OCCURS 10, "记录XLS模板文件内容的内表
L_DEFAULT_FILENAME TYPE STRING VALUE 'KKS批量导入', "默认文件名
L_FILENAME TYPE STRING , "要保存的文件名
L_PATH TYPE STRING, "文件路径
L_DEFAULT_EXTENSION TYPE STRING VALUE 'XLS', "默认扩展名
L_FULLPATH TYPE STRING, "文件名+路径
L_TITLE TYPE STRING, "窗口标题
L_SHEET_NUMBER TYPE I, "sheet页号
L_TEXT(50) TYPE C. "表头信息
DATA: VAL1(30) TYPE C."单元格值
*------读入Excel模板-----------*
L_NAME-RELID = 'MI'. "模板类型
L_NAME-OBJID = 'ZNYPMR00030'. "模板对象名
CALL FUNCTION 'WWWDATA_IMPORT'
EXPORTING
KEY = L_NAME
TABLES
MIME = L_MIME
EXCEPTIONS
WRONG_OBJECT_TYPE = 1
IMPORT_ERROR = 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.
*------弹出Excel保存对话框----------*
L_TITLE = SY-TITLE.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = L_TITLE
DEFAULT_EXTENSION = L_DEFAULT_EXTENSION
DEFAULT_FILE_NAME = L_DEFAULT_FILENAME
FILE_FILTER = '(电子表格EXCEL)'
CHANGING
FILENAME = L_FILENAME
PATH = L_PATH
FULLPATH = L_FULLPATH.
*
**-------建立本地Excel文件---------*
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = L_FULLPATH
FILETYPE = 'BIN'
TABLES
DATA_TAB = L_MIME.
MESSAGE '模板下载完成!' TYPE 'S'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_AUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_WERKS text
*----------------------------------------------------------------------*
FORM FRM_CHECK_AUT USING P_WERKS TYPE WERKS_D
CHANGING P_SUBRC TYPE I.
AUTHORITY-CHECK OBJECT 'I_SWERK'
ID 'SWERK' FIELD P_WERKS.
P_SUBRC = SY-SUBRC.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_F_FILE text
*----------------------------------------------------------------------*
FORM FRM_CHECK_FILE USING F_FILE.
IF ( F_FILE IS INITIAL ) OR F_FILE EQ '请选择Excel文件上传...'.
MESSAGE '请选择上传文件!' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ELSE.
SEARCH F_FILE FOR '.xls'.
IF SY-SUBRC <> 0.
MESSAGE '文件格式不正确!' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_UPLOAD_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_CHECK_UPLOAD_TABLE USING PT_excel like lt_excel.
* 设置上传状态
PERFORM FRM_set_status USING '正在读取功能位置(KKS)数据,请等待……'.
* 读取本地文件
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = 2
I_BEGIN_ROW = 6
I_END_COL = 10
I_END_ROW = 20000
TABLES
INTERN = TAB_EXCEL
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
.
IF TAB_EXCEL[] IS INITIAL.
MESSAGE S000 WITH '没有读到数据' DISPLAY LIKE 'E'.
STOP.
ENDIF.
*&------------ 读取的数据转置
FIELD-SYMBOLS:
DATA: L_COL TYPE I.
LOOP AT TAB_EXCEL.
L_COL = TAB_EXCEL-COL.
ASSIGN COMPONENT L_COL OF STRUCTURE LS_EXCEL TO
AT END OF ROW.
APPEND LS_EXCEL TO PT_EXCEL.
CLEAR: LS_excel.
ENDAT.
ENDLOOP.
FREE: TAB_EXCEL[].
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0197 text
*----------------------------------------------------------------------*
FORM FRM_SET_STATUS USING L_TEXT .
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = L_TEXT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_ITEM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_EXCEL text
* <--P_LT_ITEM text
*----------------------------------------------------------------------*
FORM FRM_CHECK_ITEM USING PT_EXCEL LIKE LT_excel
CHANGING Pt_ITEM like lt_item.
CHECK PT_excel[] is not INITIAL.
DATA l_lenth TYPE i.
*&----- 数据校验
CLEAR: ls_item,lt_item.
LOOP AT PT_excel into ls_excel.
MOVE-CORRESPONDING LS_excel to ls_item.
*&----- 校验功能位置编号
PERFORM frm_check_TPLNR USING LS_item-TPLNR
CHANGING ls_item-message.
*&---- 上一级功能位置
PERFORM FRM_check_TPLMA USING ls_item-TPLMA
CHANGING ls_item-message.
*&----- 其它字段
IF LS_item-PLTXT is INITIAL.
CONCATENATE '功能位置(KKS)描述不能为空/' LS_item-message into ls_item-message.
ELSE.
"add by damon at 20180122.
l_lenth = strlen( LS_item-PLTXT ).
if l_lenth > 40.
CONCATENATE '功能位置(KKS)描述长度超过40字符/' LS_item-message into ls_item-message.
endif.
ENDIF.
* IF LS_item-SWERK is INITIAL.
* CONCATENATE '维护工厂 不能为空/' LS_item-message into ls_item-message.
* ENDIF.
*-----计划人员组
IF LS_item-INGRP is not INITIAL.
PERFORM FRM_CHECK_ingrp using P_swerk ls_item-ingrp
CHANGING ls_item-message.
endif.
*----工作中心
IF LS_ITEM-GEWRK IS NOT INITIAL.
PERFORM FRM_CHEKC_crhd using P_swerk ls_item-gewrk
CHANGING ls_item-message.
ENDIF.
*&----- 校验状态
IF LS_item-message is INITIAL.
LS_item-icon = icon_green.
else.
LS_item-icon = icon_red.
ENDIF.
LS_item-swerk = p_swerk.
ls_item-iwerk = p_swerk.
APPEND LS_item to lt_item.
CLEAR: ls_item.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_TPLNR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_ITEM_TPLNR text
* <--P_LS_ITEM_MESSAGE text
*----------------------------------------------------------------------*
FORM FRM_CHECK_TPLNR USING PV_TPLNR
CHANGING PV_MESSAGE.
IF PV_tplnr is INITIAL.
CONCATENATE '功能位置(KKS)编码不能为空/' PV_message INTO PV_message.
ELSE.
SELECT SINGLE TPLNR INTO GV_tplnr
from IFLOT
WHERE TPLNR = PV_tplnr.
IF SY-SUBRC = 0.
CONCATENATE '功能位置(KKS)编码在系统中已存在/' PV_message into pv_message.
ENDIF.
"add by damon at 20180122
if PV_TPLNR(4) ne p_swerk.
CONCATENATE '功能位置(KKS)编码中工厂与导入工厂不一致/' PV_message into pv_message.
endif.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DIS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ITEM text
*----------------------------------------------------------------------*
FORM FRM_DIS_DATA USING PT_ITEM LIKE LT_item.
* 获取布局
PERFORM FRM_LAYOUT_STRUCTURE.
* 字段组
PERFORM FRM_FIELD_CATALOG_TABLE USING :
'TABIX' 4 '序号' 'C' 'X', "
'ICON' 6 '状态' 'C' 'X',
* 'TPLNR' 12 'KKS编码' ' ' 'X',
'TPLNR' 12 '功能位置(KKS)编码' ' ' 'X',
* 'PLTXT' 20 'KKS描述' '' 'X', "
'PLTXT' 20 '功能位置(KKS)描述' '' 'X', "
* 'TPLMA' 12 '上一级KKS编码' ' ' 'X',
'TPLMA' 12 '上一级功能位置(KKS)编码' ' ' 'X',
* 'DATAB' 8 '技术对像开始日期' ' ' ' ',
'DATAB' 8 '技术对象开始日期' ' ' ' ',
'IWERK' 6 '计划工厂' ' ' ' ',
'INGRP' 10 '计划员组' ' ' ' ',
* 'GEWRK' 10 '维护部门' ' ' ' ',
'GEWRK' 10 '工作中心' ' ' ' ',
'SWERK' 6 '维护工厂' ' ' ' ',
'MESSAGE' 20 '处理消息' ' ' ' '.
* 初始化表头
PERFORM FRM_ALV_HEADER USING I_HEADER.
* Events
PERFORM FRM_EVENTS USING I_EVENTS.
* CALL FUNCTION
PERFORM FRM_CALL_ALV_FUNCTION TABLES PT_item.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P_FILE text
*----------------------------------------------------------------------*
FORM FRM_GET_FILE CHANGING f_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = F_FILE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_TPLMA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_ITEM_TPLMA text
* <--P_LS_ITEM_MESSAGE text
*----------------------------------------------------------------------*
FORM FRM_CHECK_TPLMA USING Pv_TPLMA
CHANGING Pv_MESSAGE.
IF PV_TPLMA IS INITIAL.
CONCATENATE '上一级功能位置(KKS)字段 不能为空/' pv_message INTO pv_message.
ELSE.
SELECT SINGLE TPLNR INTO GV_TPLNR
FROM IFLOT
WHERE TPLNR = PV_TPLMA.
IF SY-SUBRC <> 0.
CONCATENATE '上一级功能位置(KKS)编码在系统中不存在/' PV_message into pv_message.
ENDIF.
"add by damon at 20180122
if PV_TPLMA(4) ne p_swerk.
CONCATENATE '上一级功能位置(KKS)编码编码中工厂与导入工厂不一致/' PV_message into pv_message.
endif.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_LAYOUT_STRUCTURE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_LAYOUT_STRUCTURE .
CLEAR LAYOUT.
* 自动调节列的宽度
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT-ZEBRA = 'X'.
LAYOUT-F2CODE = 'DIS'.
LAYOUT-BOX_FIELDNAME = 'SEL'.
LAYOUT-BOX_TABNAME = 'LT_ITEM'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_FIELD_CATALOG_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0424 text
* -->P_4 text
* -->P_0426 text
* -->P_0427 text
* -->P_0428 text
*----------------------------------------------------------------------*
FORM FRM_FIELD_CATALOG_TABLE USING F O D H TL .
DATA L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
CLEAR L_FIELDCAT.
STATICS POS LIKE SY-INDEX VALUE 20.
POS = POS + 1.
MOVE 1 TO L_FIELDCAT-ROW_POS.
MOVE POS TO L_FIELDCAT-COL_POS. "
MOVE F TO L_FIELDCAT-FIELDNAME. "
* MOVE T TO L_FIELDCAT-TABNAME.
MOVE O TO L_FIELDCAT-OUTPUTLEN. "
MOVE D TO L_FIELDCAT-SELTEXT_M. "
MOVE H TO L_FIELDCAT-JUST.
MOVE TL TO L_FIELDCAT-KEY. "
L_FIELDCAT-NO_zero = 'X'.
APPEND L_FIELDCAT TO FIELDCAT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_HEADER text
*----------------------------------------------------------------------*
FORM FRM_ALV_HEADER USING I_HEADER TYPE SLIS_T_LISTHEADER.
DATA: LV_LINE TYPE I,
LV_CHAR(5) TYPE C.
DESCRIBE TABLE LT_ITEM LINES LV_LINE.
LV_CHAR = LV_LINE.
DATA: WA_LINE TYPE SLIS_LISTHEADER.
CLEAR WA_LINE.
WA_LINE-TYP = 'H'.
WA_LINE-INFO = text-t02.
"'KKS 主数据批量导入 '.
APPEND WA_LINE TO I_HEADER.
CLEAR WA_LINE .
WA_LINE-TYP = 'S'.
CONCATENATE '当前共读取 ' LV_CHAR '条数据' INTO WA_LINE-INFO.
APPEND WA_LINE TO I_HEADER.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_EVENTS text
*----------------------------------------------------------------------*
FORM FRM_EVENTS USING IT_EVENTS TYPE SLIS_T_EVENT.
DATA : WA_EVENT TYPE SLIS_ALV_EVENT.
CLEAR WA_EVENT.
WA_EVENT-NAME = 'TOP_OF_PAGE'.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
APPEND WA_EVENT TO I_EVENTS.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CALL_ALV_FUNCTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PT_ITEM text
*----------------------------------------------------------------------*
FORM FRM_CALL_ALV_FUNCTION TABLES PT_item LIKE LT_item.
"为 <...> 插入正确的名称.
*&----- 函数调用
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'USER_STATUS'
I_CALLBACK_USER_COMMAND = 'W_CALLBACK_UCOMM'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'A'
* IS_VARIANT =
IT_EVENTS = I_EVENTS[]
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = PT_ITEM
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LT_ITEM text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_HEADER.
ENDFORM. "top-of-page
* ------------------------------------------------------------------------*
* 注册程序标准的工具栏* *
*-------------------------------------------------------------------------*
FORM USER_STATUS USING R_FLG_POPUP.
SET PF-STATUS 'STANDARD' . " EXCLUDING lt_ucomm.
ENDFORM. " build_status
*-------------------------------------------------------------------------*
* 事件触发功能注册 *
*-------------------------------------------------------------------------*
FORM W_CALLBACK_UCOMM USING
R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA l_flag TYPE char1.
CASE R_UCOMM.
WHEN 'EXE'. "
* 校验数据
PERFORM FRM_CHECK_SEL USING LT_item CHANGING gv_markd.
* 数据批导
CHECK GV_markd is INITIAL.
PERFORM FRM_EXC_ITEM TABLES LT_item CHANGING gv_MARKD.
*&---- 生成的数据是否同步至PMIS系统
* PERFORM FRM_sender_pmis TABLES lt_item.
WHEN 'DIS'. "
READ TABLE LT_item into ls_item INDEX RS_SELFIELD-tabindex.
CHECK SY-SUBRC = 0.
CASE RS_SELFIELD-fieldname.
WHEN 'TPLNR'.
IF LS_item-icon = icon_ok.
set PARAMETER ID 'IFL' FIELD ls_item-tplnr.
call TRANSACTION 'IL03' AND SKIP FIRST SCREEN.
endif.
WHEN 'TPLMA'.
set PARAMETER ID 'IFL' FIELD ls_item-tpLMA.
call TRANSACTION 'IL03' AND SKIP FIRST SCREEN.
ENDCASE.
WHEN 'IMPORT'.
"数据同步的校验逻辑
CLEAR l_flag.
LOOP at LT_ITEM INTO Ls_item WHERE message ne '生成数据成功'.
l_flag = 'X'.
ENDLOOP.
if l_flag = 'X'.
MESSAGE '生成功能位置(KKS)主数据”按钮,再同步数据!' TYPE 'S' DISPLAY LIKE 'E'.
exit.
endif.
* 数据导入
PERFORM FRM_IMPORT_ITEM TABLES LT_ITEM.
ENDCASE.
* 数据刷新或内表更新
RS_SELFIELD-REFRESH = 'X'. "自动刷新
ENDFORM. "FRM_COMMONDf-page
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_SEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ITEM text
* <--P_GV_MARKD text
*----------------------------------------------------------------------*
FORM FRM_CHECK_SEL USING PT_ITEM LIKE lt_item
CHANGING Pv_MARKD.
CLEAR: PV_MARKD.
CHECK PT_item[] is not INITIAL.
READ TABLE pt_item into ls_item with key icon = ICON_red.
* SEL = 'X'.
IF SY-SUBRC = 0.
MESSAGE S000 WITH '清单中有错误行,请修正EXCEL后重新导入' DISPLAY LIKE 'E'.
PV_markd = 'X'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_EXC_ITEM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ITEM text
* <--P_GV_MARKD text
*----------------------------------------------------------------------*
FORM FRM_EXC_ITEM TABLES PT_ITEM LIKE LT_item " STRUCTURE < LT_ITEM #本地# >
"为 <...> 插入正确的名称
CHANGING PV_MARKD.
*& 变量定义
TABLES: IFLOT.
DATA: LS_GENERAL TYPE BAPI_ITOB,
LS_SPECIFIC TYPE BAPI_ITOB_FL_ONLY,
LS_RETURN TYPE BAPIRET2,
LV_number type BAPI_ITOB_PARMS-FUNCLOC.
CLEAR: LS_general,ls_specific,ls_return.
"change by damon at 20180123.
DATA LS_TPLKZ TYPE ZNYPMT00040-TPLKZ.
SELECT SINGLE TPLKZ
FROM ZNYPMT00040
INTO LS_TPLKZ
WHERE SWERK = p_SWERK.
* 数据计算
LOOP AT PT_item into ls_item WHERE " SEL = 'X'
ICON = ICON_GREEN.
GV_tabix = sy-tabix.
*&---- 填充general
LS_general-START_FROM = LS_item-datab. " 技术对像开始日期
LS_general-DESCRIPT = LS_item-PLTXT. " 描述
LS_general-PLANPLANT = ls_item-IWERK. " 计划工厂
LS_general-MAINTPLANT = P_SWERK. " 维护工厂
LS_general-PLANGROUP = LS_item-INGRP. " 计划员组
* WORK_CTR
PERFORM FRM_get_WORK_CTR USING LS_item-gewrk CHANGING LS_general-WORK_CTR.
* 获取公司代码
PERFORM FRM_get_comp_code using p_swerk CHANGING LS_general-COMP_CODE .
LS_general-READ_CRDAT = sy-datum.
LS_general-READ_CRNAM = sy-uname.
*&---- BAPI SPEC
* LS_SPECIFIC-STRIND = 'GXKKS'.
"change by damon at 20180123
LS_SPECIFIC-STRIND = LS_TPLKZ.
LS_SPECIFIC-CATEGORY = 'G'.
LS_SPECIFIC-SUPFLOC = LS_item-TPLMA.
LS_SPECIFIC-EQINSTALL = 'X'.
*&--- 调用BAPI 生成KKS编码
* PERFORM FRM_call_bapi USING
LV_number = ls_item-tplnr.
CALL FUNCTION 'BAPI_FUNCLOC_CREATE'
EXPORTING
EXTERNAL_NUMBER = LV_number
* LABELING_SYSTEM =
DATA_GENERAL = LS_general
DATA_SPECIFIC = ls_specific
* AUTOMATIC_INSTALL =
IMPORTING
FUNCTLOCATION = IFLOT-TPLNR
* DATA_GENERAL_EXP =
* DATA_SPECIFIC_EXP =
RETURN = LS_return.
*&---- 是否成功
IF LS_return-type <> 'E'.
LS_item-icon = icon_ok.
LS_item-message = '生成数据成功'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
else.
LS_item-icon = icon_red.
LS_item-message = ls_return-message.
ENDIF.
modify pt_item from ls_item INDEX gv_tabix TRANSPORTING icon message.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_COMP_CODE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_SWERK text
* <--P_LS_GENERAL_COMP_CODE text
*----------------------------------------------------------------------*
FORM FRM_GET_COMP_CODE USING Pv_SWERK
CHANGING Pv_COMP_CODE.
SELECT SINGLE BUKRS INTO PV_comp_code
from t001k
WHERE BWKEY = pv_swerk.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_INGRP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_SWERK text
* -->P_LS_ITEM_INGRP text
* <--P_LS_ITEM_MESSAGE text
*----------------------------------------------------------------------*
FORM FRM_CHECK_INGRP USING Pv_SWERK
P_LS_ITEM_INGRP
CHANGING P_LS_ITEM_MESSAGE.
DATA: LS_t024i type t024i.
CLEAR: ls_t024i.
SELECT SINGLE * INTO LS_t024i
from t024i
WHERE IWERK = PV_swerk
and INGRP = P_LS_ITEM_INGRP.
IF SY-SUBRC <> 0.
CONCATENATE P_LS_ITEM_MESSAGE '计划员组在当前工厂不存在/' INTO P_LS_ITEM_MESSAGE.
endif.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHEKC_CRHD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_SWERK text
* -->P_LS_ITEM_GEWRK text
* <--P_LS_ITEM_MESSAGE text
*----------------------------------------------------------------------*
FORM FRM_CHEKC_CRHD USING Pv_SWERK
PV_ITEM_GEWRK
CHANGING PV_MESSAGE.
DATA: LS_crhd TYPE CRHD.
CLEAR: ls_crhd.
SELECT SINGLE WERKS into ls_crhd-WERKS
from CRHD
WHERE WERKS = PV_swerk
and ARBPL = PV_ITEM_GEWRK.
IF SY-SUBRC <> 0.
CONCATENATE PV_MESSAGE '工作中心在当前工厂不存在' INTO PV_MESSAGE.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SENDER_PMIS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ITEM text
*----------------------------------------------------------------------*
FORM FRM_SENDER_PMIS TABLES PT_ITEM like LT_item. "STRUCTURE < LT_ITEM #本地# >
"为 <...> 插入正确的名称.
DATA: BEGIN OF gs_item,
TPLNR LIKE ZNYPMT00010-TPLNR,
TPLMA LIKE ZNYPMT00010-TPLMA,
TPLKZ LIKE ZNYPMT00010-TPLKZ,
FLTYP LIKE ZNYPMT00010-FLTYP,
PLTXT LIKE ZNYPMT00010-PLTXT,
DATAB LIKE ZNYPMT00010-DATAB,
IWERK LIKE ZNYPMT00010-IWERK,
INGRP LIKE ZNYPMT00010-INGRP,
GEWRK LIKE ZNYPMT00010-GEWRK,
STAT LIKE ZNYPMT00010-stat,
SWERK LIKE ZNYPMT00010-SWERK,
KOSTL LIKE ZNYPMT00010-KOSTL,
BUKRS TYPE BUKRS,
NAME_CRE TYPE CHAR20,
ERDAT TYPE SY-DATUM,
NAME_CHG TYPE CHAR20,
AEDAT TYPE SY-DATUM,
END OF gs_item.
DATA: gt_item like TABLE OF gs_item.
* 新读取数据
DATA: lt_IFLO type TABLE OF IFLO,
ls_IFLO like LINE OF lt_IFLO.
CLEAR: lt_IFLO[].
*& 数据提取
SELECT TPLNR
KOSTL
OBJNR
BUKRS
ERDAT
AEDAT
TPLKZ
FLTYP
INTO CORRESPONDING FIELDS OF TABLE LT_IFLO
FROM IFLO
FOR ALL ENTRIES IN PT_item
WHERE tplnr = pt_item-tplnr
and tplnr <> space
and SPRAS = sy-langu.
*& 读取当前处理人
DATA: name_txt type char20.
PERFORM FRM_get_name_txt using sy-uname CHANGING name_txt.
* 组合发数送数据
CLEAR: gs_item.
LOOP AT PT_item into ls_item WHERE icon = icon_ok.
move-CORRESPONDING ls_item to gs_item.
* 读取成本中心公司代码状态
READ TABLE LT_IFLO INTO LS_IFLO WITH KEY TPLNR = LS_item-tplnr.
IF SY-SUBRC = 0.
gs_item-kostl = ls_IFLO-KOSTL.
gs_item-bukrs = ls_IFLO-BUKRS.
gs_item-TPLKZ = LS_IFLO-TPLKZ.
GS_item-FLTYP = ls_IFLO-FLTYP.
GS_item-erdat = ls_iflo-erdat.
gs_item-aedat = ls_iflo-aedat.
gs_item-name_cre = name_txt.
* gs_item-NAME_CRE = sy-uname.
* 读取状态
PERFORM from_get_stat using ls_IFLO-OBJNR CHANGING GS_item-stat.
ENDIF.
APPEND GS_item to gt_item.
ENDLOOP.
*&--- 调用函数进行数据发送
CALL FUNCTION 'ZNYFG_PM_00010_FM0010'
* EXPORTING
** PS_IFLO =
* PV_MODE =
* IMPORTING
* O_MARKD =
TABLES
PT_ITEM = gt_item .
* PT_RETN =
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FROM_GET_STAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_IFLO_OBJNR text
* <--P_GS_ITEM_STAT text
*----------------------------------------------------------------------*
FORM FROM_GET_STAT USING P_LS_IFLO_OBJNR
CHANGING P_GS_ITEM_STAT.
data:
LV_stsma like JSTO-STSMA,
LV_stonr like TJ30-STONR,
LV_act_stat TYPE J_STATUS.
CLEAR: LV_stsma,LV_stonr,LV_act_stat.
CALL FUNCTION 'STATUS_READ'
EXPORTING
CLIENT = SY-MANDT
OBJNR = P_LS_IFLO_OBJNR
ONLY_ACTIVE = 'X'
IMPORTING
* OBTYP =
STSMA = LV_stsma
STONR = LV_stonr
* TABLES
* STATUS =
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CHECK LV_stsma IS NOT INITIAL.
* 读取当前活动的状态
SELECT SINGLE ESTAT INTO LV_act_stat
from tj30
WHERE STSMA = lv_STSMA
AND STONR = lv_STONR.
CHECK SY-SUBRC = 0.
P_GS_ITEM_STAT = LV_act_stat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_NAME_TXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_SY_UNAME text
* <--P_NAME_TXT text
*----------------------------------------------------------------------*
FORM FRM_GET_NAME_TXT USING P_SY_UNAME
CHANGING P_NAME_TXT.
data: LS_adrp type adrp.
CLEAR: ls_adrp.
* 读取登录名
SELECT SINGLE NAME_last
name_first
INTO (ls_adrp-name_last, ls_adrp-name_first)
from usr21
INNER JOIN adrp
on usr21~PERSNUMBER = adrp~PERSNUMBER
WHERE usr21~bname = P_SY_UNAME.
CHECK sy-subrc = 0.
CONCATENATE LS_adrp-name_last ls_adrp-name_first into p_name_txt.
CONDENSE p_name_txt NO-GAPS.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_WORK_CTR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_ITEM_GEWRK text
* <--P_LS_GERERAL_WORK_CTR text
*----------------------------------------------------------------------*
FORM FRM_GET_WORK_CTR USING P_GS_ITEM_GEWRK
CHANGING P_LS_GERERAL_WORK_CTR.
SELECT SINGLE OBJID INTO P_LS_GERERAL_WORK_CTR
FROM CRHD
WHERE ARBPL = P_GS_ITEM_GEWRK
AND OBJTY = 'A'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_IMPORT_ITEM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ITEM text
*----------------------------------------------------------------------*
FORM FRM_IMPORT_ITEM TABLES LT_ITEM LIKE LT_item . "STRUCTURE < LT_ITEM #本地# >
"为 <...> 插入正确的名称.
*&------- 发送主数据表
DATA: BEGIN OF SENDS_item,
TPLNR LIKE ZNYPMT00010-TPLNR,
TPLMA LIKE ZNYPMT00010-TPLMA,
TPLKZ LIKE ZNYPMT00010-TPLKZ,
FLTYP LIKE ZNYPMT00010-FLTYP,
PLTXT LIKE ZNYPMT00010-PLTXT,
DATAB LIKE ZNYPMT00010-DATAB,
IWERK LIKE ZNYPMT00010-IWERK,
INGRP LIKE ZNYPMT00010-INGRP,
GEWRK LIKE ZNYPMT00010-GEWRK,
STAT LIKE ZNYPMT00010-stat,
SWERK LIKE ZNYPMT00010-SWERK,
KOSTL LIKE ZNYPMT00010-KOSTL,
BUKRS TYPE BUKRS,
NAME_CRE TYPE CHAR20,
ERDAT TYPE SY-DATUM,
NAME_CHG TYPE CHAR20,
AEDAT TYPE SY-DATUM,
ICON TYPE CHAR15,
END OF SENDS_item.
DATA: SENDT_item like TABLE OF SENDS_item.
DATA: BEGIN OF GS_return,
TPLNR LIKE ZNYPMT00010-TPLNR,
PLTXT TYPE CHAR40,
RESULT LIKE ZNYPMT00010-STATS,
MESSAGE TYPE CHAR200,
END OF GS_RETURN.
DATA: GT_RETURN LIKE TABLE OF GS_return.
*&--------------------------------------------------------*
DATA: LT_IFLO LIKE TABLE OF IFLO,
LS_IFLO LIKE LINE OF LT_IFLO.
CLEAR: lt_IFLO,LS_iflo.
CHECK LT_ITEM[] IS NOT INITIAL.
SELECT TPLNR
TPLMA
TPLKZ
FLTYP
PLTXT
DATAB
IWERK
INGRP
* GEWRK
LGWID
SWERK
KOSTL
BUKRS
OBJNR
ERDAT
AEDAT
ERNAM
INTO CORRESPONDING FIELDS OF TABLE LT_IFLO
FROM IFLO
FOR ALL ENTRIES IN LT_ITEM
WHERE TPLNR = LT_ITEM-TPLNR.
*----- 读取主工作中心
DATA: LT_CRHD TYPE TABLE OF CRHD,
LS_CRHD LIKE LINE OF LT_CRHD.
CLEAR: LT_CRHD.
SELECT OBJID ARBPL INTO TABLE LT_CRHD
FROM CRHD
FOR ALL ENTRIES IN LT_IFLO
WHERE OBJID = LT_IFLO-LGWID.
*&----- 过滤数据
CLEAR: sends_item,sendt_item.
LOOP AT LT_IFLO INTO LS_IFLO.
GV_tabix = sy-tabix.
MOVE-CORRESPONDING LS_IFLO TO SENDS_item.
* 读取主工作中心
READ TABLE LT_crhd into ls_crhd WITH KEY OBJID = LS_iflo-LGWID.
if sy-subrc = 0.
sends_item-GEWRK = ls_crhd-arbpl.
endif.
* 读取创建人
PERFORM FRM_get_cre_name IN PROGRAM ZNYPMR00010
using LS_iflo-ernam CHANGING sends_item-NAME_cre.
* 当前状态
SENDS_ITEM-STAT = 'E0001'.
APPEND SENDS_ITEM TO SENDT_ITEM.
ENDLOOP.
*&--------- 如果前台操作。
CALL FUNCTION 'ZNYFG_PM_00010_FM0010'
* EXPORTING
* PS_IFLO =
* PV_MODE =
* IMPORTING
* O_MARKD =
TABLES
PT_ITEM = SENDT_ITEM
PT_RETN = gt_return
.
*& 发送完成之后,报一个message
MESSAGE I000 WITH '数据发送完毕'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_AUTHORITY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_CHECK_AUTHORITY .
DATA:LT_T001W TYPE TABLE OF T001W,
LS_T001W TYPE T001W.
DATA:LV_SUBRC TYPE I.
SELECT WERKS
FROM T001W
INTO CORRESPONDING FIELDS OF TABLE LT_T001W
WHERE WERKS = P_SWERK.
IF LT_T001W[] IS INITIAL.
MESSAGE S001(00) WITH '工厂' P_SWERK '不存在' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
LOOP AT LT_T001W INTO LS_T001W.
*&检查工厂权限
CLEAR:LV_SUBRC.
PERFORM FRM_CHECK_AUT USING LS_T001W-WERKS
CHANGING LV_SUBRC.
IF LV_SUBRC NE 0.
"没有工厂的权限
MESSAGE E001(00) WITH '没有工厂' LS_T001W-WERKS '的权限'.
CONTINUE.
ENDIF.
* S_WERKS-SIGN = 'I'.
* S_WERKS-OPTION = 'EQ'.
* S_WERKS-LOW = LS_T001W-WERKS.
* APPEND S_WERKS.
ENDLOOP.
CLEAR:LS_T001W,LT_T001W.
ENDFORM.