程序功能:根据上传模板,抓取相关数据,并进行物料主数据除基本视图外批量扩展维护
*&---------------------------------------------------------------------*
*&*********************************************************************
*& Program ID :MM-041
*& PROGRAM NAME :ZTYMME00020
*& Date :2016/8/26
*& Program Description :物料主数据除基本视图外批量扩展维护
*& CHANGE HISTORY
*& REQUEST NUMBER | CHANGED BY | DATE |DESCRIPTION
*&
*&*********************************************************************
REPORT ZTYMME00020 NO STANDARD PAGE HEADING MESSAGE-ID 00.
TYPE-POOLS:SLIS.
TABLES:SSCRFIELDS,MARC.
DATA:ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA:GT_FIELDCAT TYPE LVC_T_FCAT,
GS_LAYOUTLVC TYPE LVC_S_LAYO,
GS_S_GLAY TYPE LVC_S_GLAY,
GT_EVENTS TYPE SLIS_T_EVENT,
GV_REPID LIKE SY-REPID.
DATA:BEGIN OF GT_ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
WERKS LIKE MARC-WERKS,
LGFSB LIKE MARC-LGFSB,
EKGRP LIKE MARC-EKGRP,
MTART LIKE MARA-MTART,
MAKTX LIKE MAKT-MAKTX,
MEINS LIKE MARA-MEINS,
MATKL LIKE MARA-MATKL,
WGBEZ LIKE T023T-WGBEZ,
NAME1 LIKE T001W-NAME1,
BWKEY LIKE T001W-BWKEY,
LGOBE LIKE T001L-LGOBE,
EKNAM LIKE T024-EKNAM,
XCHPF LIKE MARC-XCHPF,
DISMM LIKE MARC-DISMM,
DISPO LIKE MARC-DISPO,
DISLS LIKE MARC-DISLS,
FHORI LIKE MARC-FHORI,
MTVFP LIKE MARC-MTVFP,
ZBWMOD like T001K-BWMOD, "change by damon
ZWGBEZ like T023T-WGBEZ, "change by damon
PRCTR LIKE MARC-PRCTR,
KTEXT LIKE CEPCT-KTEXT,
BKLAS LIKE MBEW-BKLAS,
BKBEZ LIKE T025T-BKBEZ,
QKLAS like T025T-BKLAS, "change by damon
ZBKBEZ like T025T-BKBEZ, "change by damon
VERPR LIKE MBEW-VERPR,
ZSEL TYPE C,
STATUS TYPE C LENGTH 4,
MESSA TYPE C LENGTH 255,
CELLSTYLES TYPE LVC_T_STYL,
END OF GT_ITAB.
DATA:GT_T438A TYPE TABLE OF T438A WITH HEADER LINE, "MRP 类型
GT_T001W TYPE TABLE OF T001W WITH HEADER LINE, "工厂
GT_T001L TYPE TABLE OF T001L WITH HEADER LINE, "库存地点
GT_T023T TYPE TABLE OF T023T WITH HEADER LINE, "物料组
GT_T024 TYPE TABLE OF T024 WITH HEADER LINE, "采购组
GT_T024D TYPE TABLE OF T024D WITH HEADER LINE, "MRP控制者
GT_T439A TYPE TABLE OF T439A WITH HEADER LINE, "MRP 批量
GT_T436A TYPE TABLE OF T436A WITH HEADER LINE, "计划边际码
GT_TMVF TYPE TABLE OF TMVF WITH HEADER LINE, "可用量检查控制
GT_T025T TYPE TABLE OF T025T WITH HEADER LINE, "评估类
GT_CEPCT TYPE TABLE OF CEPCT WITH HEADER LINE, "评估类
GT_ZTYMMT00020 TYPE TABLE OF ZTYMMT00020 WITH HEADER LINE,
GT_ZTYMMT00030 TYPE TABLE OF ZTYMMT00030 WITH HEADER LINE.
SELECTION-SCREEN FUNCTION KEY 1."下载模板
SELECTION-SCREEN FUNCTION KEY 2."上传数据
SELECTION-SCREEN BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:S_MATNR FOR MARC-MATNR MEMORY ID MAT,
S_WERKS FOR MARC-WERKS MEMORY ID WRK.
SELECTION-SCREEN END OF BLOCK BLK01.
INITIALIZATION.
SSCRFIELDS-FUNCTXT_01 = '@EZ@下载模板'.
SSCRFIELDS-FUNCTXT_02 = '@J2@上传数据'.
*AT SELECTION-SCREEN ON EXIT-COMMAND.
AT SELECTION-SCREEN .
IF SSCRFIELDS-UCOMM EQ 'FC01'. "FC01"模板下载按钮
PERFORM DOWNLOAD_TEMPLE_EXCEL.
ELSEIF SSCRFIELDS-UCOMM EQ 'FC02'."FC02"数据上传按钮
PERFORM FRM_GET_BASE_DATA.
PERFORM FRM_IMPORT_DATA.
ELSEIF SY-UCOMM EQ 'ONLI'. "F8执行按钮
IF S_MATNR[] IS INITIAL.
MESSAGE S001 WITH '请输入物料编码' DISPLAY LIKE 'E'.
STOP.
ENDIF.
IF S_WERKS[] IS INITIAL.
MESSAGE S001 WITH '请输入工厂' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
* SET PF-STATUS 'PS001'.
START-OF-SELECTION.
PERFORM FRM_CHECK_AUTHORITY.
PERFORM FRM_GET_BASE_DATA.
PERFORM FRM_GET_DATA.
IF NOT GT_ITAB[] IS INITIAL.
PERFORM FRM_ALVSHOW TABLES GT_FIELDCAT GT_ITAB
USING 'GT_ITAB'.
ELSE.
MESSAGE S001 WITH '无数据' DISPLAY LIKE 'E'.
STOP.
ENDIF.
END-OF-SELECTION.
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 IN S_WERKS.
IF LT_T001W[] IS INITIAL.
MESSAGE S001(00) WITH '工厂' S_WERKS-LOW '不存在' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
CLEAR:S_WERKS.
FREE:S_WERKS.
LOOP AT LT_T001W INTO LS_T001W.
*&检查工厂权限
CLEAR:LV_SUBRC.
PERFORM FRM_AUTHORITY_CHECK 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.
FORM FRM_AUTHORITY_CHECK USING P_WERKS TYPE WERKS_D
CHANGING P_SUBRC TYPE I.
AUTHORITY-CHECK OBJECT 'M_MATE_NEU'
ID 'DUMMY' FIELD P_WERKS.
P_SUBRC = SY-SUBRC.
ENDFORM.
FORM FRM_GET_BASE_DATA.
SELECT * INTO TABLE GT_T438A FROM T438A.
SELECT * INTO TABLE GT_T001W FROM T001W.
SELECT * INTO TABLE GT_T001L FROM T001L.
SELECT * INTO TABLE GT_T023T FROM T023T WHERE SPRAS EQ '1'.
SELECT * INTO TABLE GT_T024 FROM T024.
SELECT * INTO TABLE GT_T024D FROM T024D.
SELECT * INTO TABLE GT_T439A FROM T439A.
SELECT * INTO TABLE GT_T436A FROM T436A.
SELECT * INTO TABLE GT_TMVF FROM TMVF.
SELECT * INTO TABLE GT_T025T FROM T025T WHERE SPRAS EQ '1'.
SELECT * INTO TABLE GT_CEPCT FROM CEPCT
WHERE SPRAS EQ '1'
AND DATBI GE SY-DATUM
AND KOKRS EQ 'JSGX'.
SELECT * INTO TABLE GT_ZTYMMT00020 FROM ZTYMMT00020.
SELECT * INTO TABLE GT_ZTYMMT00030 FROM ZTYMMT00030.
SORT:GT_T438A BY DISMM,
GT_T001W BY WERKS,
GT_T001L BY WERKS LGORT,
GT_T023T BY MATKL,
GT_T024 BY EKGRP,
GT_T024D BY WERKS DISPO,
GT_T439A BY DISLS,
GT_T436A BY WERKS FHORI,
GT_TMVF BY MTVFP,
GT_T025T BY BKLAS,
GT_CEPCT BY PRCTR,
GT_ZTYMMT00020 BY WERKS,
GT_ZTYMMT00030 BY MATKL ZBWMOD,
.
ENDFORM.
FORM FRM_GET_DATA.
DATA:LT_MATNR TYPE TABLE OF MATNR WITH HEADER LINE,
LT_WERKS TYPE TABLE OF WERKS WITH HEADER LINE.
DATA:LV_PER TYPE I VALUE 1,
LV_TEXT TYPE STRING.
LV_PER = 1.
LV_TEXT = '数据处理中......'.
PERFORM SAPGUI_PROGRESS_INDICATOR USING LV_PER LV_TEXT.
CLEAR:GT_ITAB.
FREE: GT_ITAB.
SELECT MATNR INTO TABLE LT_MATNR
FROM MARA
WHERE MATNR IN S_MATNR
AND LVORM EQ ABAP_FALSE.
CHECK NOT LT_MATNR[] IS INITIAL.
SELECT WERKS INTO TABLE LT_WERKS
FROM T001W
WHERE WERKS IN S_WERKS.
LOOP AT LT_MATNR.
LOOP AT LT_WERKS.
GT_ITAB-MATNR = LT_MATNR.
GT_ITAB-WERKS = LT_WERKS.
PERFORM FRM_DATA_CHECK_AND_FILL USING GT_ITAB.
IF GT_ITAB-STATUS EQ ICON_YELLOW_LIGHT AND GT_ITAB-MESSA IS INITIAL.
GT_ITAB-ZSEL = ABAP_TRUE.
ENDIF.
APPEND GT_ITAB.
CLEAR:GT_ITAB.
ENDLOOP.
ENDLOOP.
ENDFORM.
FORM FRM_SELECT_FILE USING P_FILE TYPE RLGRAP-FILENAME.
DATA:LV_RC TYPE SY-SUBRC,
LV_ACTION TYPE I,
LV_FILENAME TYPE STRING,
LT_FILETABLE TYPE FILETABLE,
LW_FILETABLE TYPE FILE_TABLE.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE = '选择导入文件'
DEFAULT_EXTENSION = ',*.XLS,*.XLSX.'
DEFAULT_FILENAME = LV_FILENAME
FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
MULTISELECTION = ''
CHANGING
FILE_TABLE = LT_FILETABLE
RC = LV_RC
USER_ACTION = LV_ACTION
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
NOT_SUPPORTED_BY_GUI = 4.
IF SY-SUBRC EQ 0 AND LV_ACTION EQ 0.
LOOP AT LT_FILETABLE INTO LW_FILETABLE.
P_FILE = LW_FILETABLE-FILENAME.
EXIT.
ENDLOOP.
ELSE.
LEAVE TO TRANSACTION SY-TCODE.
ENDIF.
ENDFORM.
FORM FRM_IMPORT_DATA.
DATA:LT_TABLINE TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA:LV_COL TYPE I,
LV_FILE TYPE RLGRAP-FILENAME.
DATA:LV_PER TYPE I VALUE 1,
LV_TEXT TYPE STRING.
DATA:LW_ITAB LIKE GT_ITAB.
FIELD-SYMBOLS:
PERFORM FRM_SELECT_FILE USING LV_FILE.
CHECK NOT LV_FILE IS INITIAL.
LV_PER = 1.
LV_TEXT = 'Excel数据处理中......'.
PERFORM SAPGUI_PROGRESS_INDICATOR USING LV_PER LV_TEXT.
CLEAR:LT_TABLINE.
FREE:LT_TABLINE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = LV_FILE
I_BEGIN_COL = '1'
I_BEGIN_ROW = '4'
I_END_COL = '4'
I_END_ROW = '65535'
TABLES
INTERN = LT_TABLINE
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0 .
MESSAGE E001 WITH '上载EXCEL文件出错'.
ENDIF.
* -转换内表
SORT LT_TABLINE BY ROW COL.
LOOP AT LT_TABLINE ASSIGNING
* 读取EXCEL数据
LV_COL =
ASSIGN COMPONENT LV_COL OF STRUCTURE LW_ITAB TO
IF LV_COL EQ 1.
PERFORM CONVERSION_EXIT_MATN1_INPUT CHANGING
ENDIF.
AT END OF ROW.
PERFORM FRM_DATA_CHECK_AND_FILL USING LW_ITAB.
APPEND LW_ITAB TO GT_ITAB.
CLEAR:LW_ITAB.
ENDAT.
CLEAR:LT_TABLINE.
ENDLOOP.
DELETE GT_ITAB WHERE MATNR IS INITIAL.
LW_ITAB-ZSEL = ABAP_TRUE.
MODIFY GT_ITAB FROM LW_ITAB TRANSPORTING ZSEL WHERE STATUS EQ ICON_YELLOW_LIGHT
AND MESSA IS INITIAL.
IF NOT GT_ITAB[] IS INITIAL.
PERFORM FRM_ALVSHOW TABLES GT_FIELDCAT GT_ITAB
USING 'GT_ITAB'.
ELSE.
MESSAGE S001 WITH '无数据' DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDFORM. " FRM_IMPORT_DATA
FORM CONVERSION_EXIT_ALPHA_INPUT CHANGING P_INOUT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = P_INOUT
IMPORTING
OUTPUT = P_INOUT.
ENDFORM.
FORM CONVERSION_EXIT_MATN1_INPUT CHANGING P_INOUT.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
INPUT = P_INOUT
IMPORTING
OUTPUT = P_INOUT
EXCEPTIONS
LENGTH_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
FORM FRM_DATA_CHECK_AND_FILL USING P_STRUC STRUCTURE GT_ITAB.
TABLES:*MARA,*MARC.
DATA:LT_STYL TYPE LVC_T_STYL,
LW_STYL TYPE LVC_S_STYL.
DATA:LV_SUBRC TYPE I.
CLEAR:P_STRUC-MESSA,P_STRUC-CELLSTYLES,LT_STYL,LW_STYL,LV_SUBRC.
*检验物料
CLEAR:*MARA.
SELECT SINGLE * INTO *MARA
FROM MARA
WHERE MATNR EQ P_STRUC-MATNR.
IF SY-SUBRC NE 0.
P_STRUC-MESSA = P_STRUC-MESSA
&& '物料'
&& P_STRUC-MATNR
&& '不存在;'.
ELSEIF *MARA-LVORM EQ ABAP_TRUE.
P_STRUC-MESSA = P_STRUC-MESSA
&& '物料'
&& P_STRUC-MATNR
&& '已被删除;'.
ELSE.
P_STRUC-MTART = *MARA-MTART.
P_STRUC-MEINS = *MARA-MEINS.
CLEAR:GT_T023T.
READ TABLE GT_T023T WITH KEY MATKL = *MARA-MATKL BINARY SEARCH.
P_STRUC-MATKL = *MARA-MATKL.
P_STRUC-WGBEZ = GT_T023T-WGBEZ.
SELECT SINGLE MAKTX INTO P_STRUC-MAKTX
FROM MAKT
WHERE MATNR EQ P_STRUC-MATNR
AND SPRAS EQ '1'.
IF P_STRUC-WERKS IS INITIAL.
P_STRUC-MESSA = P_STRUC-MESSA && '工厂不能为空;'.
ELSE.
CLEAR:*MARC.
SELECT SINGLE * INTO *MARC
FROM MARC
WHERE MATNR EQ P_STRUC-MATNR
AND WERKS EQ P_STRUC-WERKS.
IF SY-SUBRC EQ 0. "工厂数据存在即提示已存在,目前未考虑MRP、采购、会计视图是否创建
P_STRUC-MESSA = P_STRUC-MESSA
&& '物料' && P_STRUC-MATNR
&& '在工厂' && P_STRUC-WERKS
&& '下视图已存在;'.
P_STRUC-LGFSB = *MARC-LGFSB.
P_STRUC-EKGRP = *MARC-EKGRP.
LW_STYL-FIELDNAME = 'LGFSB'.
LW_STYL-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LW_STYL INTO TABLE LT_STYL.
LW_STYL-FIELDNAME = 'EKGRP'.
LW_STYL-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LW_STYL INTO TABLE LT_STYL.
ELSE.
IF P_STRUC-MTART EQ 'Z002'."服务类型物料
LW_STYL-FIELDNAME = 'LGFSB'.
LW_STYL-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LW_STYL INTO TABLE LT_STYL.
ENDIF.
PERFORM FRM_AUTHORITY_CHECK USING P_STRUC-WERKS
CHANGING LV_SUBRC.
IF LV_SUBRC NE 0.
P_STRUC-MESSA = P_STRUC-MESSA
&& '您没有'
&& P_STRUC-WERKS
&& '工厂的权限;'.
ENDIF.
ENDIF.
CLEAR:GT_T001W.
READ TABLE GT_T001W WITH KEY WERKS = P_STRUC-WERKS BINARY SEARCH.
IF SY-SUBRC EQ 0.
P_STRUC-NAME1 = GT_T001W-NAME1.
P_STRUC-BWKEY = GT_T001W-BWKEY.
ELSE.
P_STRUC-MESSA = P_STRUC-MESSA
&& '工厂' && P_STRUC-WERKS
&& '不存在;'.
ENDIF.
IF NOT P_STRUC-LGFSB IS INITIAL.
CLEAR:GT_T001L.
READ TABLE GT_T001L WITH KEY WERKS = P_STRUC-WERKS
LGORT = P_STRUC-LGFSB
BINARY SEARCH.
IF SY-SUBRC EQ 0.
P_STRUC-LGOBE = GT_T001L-LGOBE.
ELSE.
P_STRUC-MESSA = P_STRUC-MESSA
&& '库存地点' && P_STRUC-LGFSB
&& '在工厂' && P_STRUC-WERKS
&& '中不存在;'.
ENDIF.
ENDIF.
* 默认值配置
CLEAR:GT_ZTYMMT00020.
READ TABLE GT_ZTYMMT00020 WITH KEY WERKS = P_STRUC-WERKS BINARY SEARCH.
IF SY-SUBRC EQ 0.
P_STRUC-PRCTR = GT_ZTYMMT00020-PRCTR.
IF P_STRUC-MTART EQ 'Z002'."服务类型物料
* P_STRUC-BKLAS = GT_ZTYMMT00020-BKLAS.
* P_STRUC-VERPR = GT_ZTYMMT00020-VERPR.
CLEAR:GT_T025T.
READ TABLE GT_T025T WITH KEY BKLAS = P_STRUC-BKLAS BINARY SEARCH.
P_STRUC-BKBEZ = GT_T025T-BKBEZ.
ELSE.
P_STRUC-XCHPF = GT_ZTYMMT00020-XCHPF.
P_STRUC-DISMM = GT_ZTYMMT00020-DISMM.
P_STRUC-DISPO = GT_ZTYMMT00020-DISPO.
P_STRUC-DISLS = GT_ZTYMMT00020-DISLS.
P_STRUC-FHORI = GT_ZTYMMT00020-FHORI.
P_STRUC-MTVFP = GT_ZTYMMT00020-MTVFP.
**************************change by damon at 20180118******************************
P_STRUC-ZBWMOD = GT_ZTYMMT00020-ZBWMOD.
**************************change by damon at 20180118******************************
ENDIF.
CLEAR:GT_CEPCT.
READ TABLE GT_CEPCT WITH KEY PRCTR = P_STRUC-PRCTR BINARY SEARCH.
P_STRUC-KTEXT = GT_CEPCT-KTEXT.
IF GT_ZTYMMT00020-EKGRP_REQ EQ ABAP_TRUE OR NOT P_STRUC-EKGRP IS INITIAL.
CLEAR:GT_T024.
READ TABLE GT_T024 WITH KEY EKGRP = P_STRUC-EKGRP BINARY SEARCH.
IF SY-SUBRC EQ 0.
P_STRUC-EKNAM = GT_T024-EKNAM.
ELSE.
P_STRUC-MESSA = P_STRUC-MESSA
&& '采购组' && P_STRUC-EKGRP
&& '不存在;'.
ENDIF.
ENDIF.
ELSE.
P_STRUC-MESSA = P_STRUC-MESSA
&& '配置表ZTYMMT00020中无此工厂'
&& P_STRUC-WERKS
&& '的配置;'.
ENDIF.
ENDIF.
IF P_STRUC-MTART NE 'Z002'."非服务类型物料
CLEAR:GT_ZTYMMT00030.
**************************change by damon at 20180118******************************
READ TABLE GT_ZTYMMT00030 WITH KEY MATKL = P_STRUC-MATKL
ZBWMOD = P_STRUC-ZBWMOD
BINARY SEARCH.
**************************change by damon at 20180118******************************
IF SY-SUBRC EQ 0.
CLEAR:GT_T025T.
READ TABLE GT_T025T WITH KEY BKLAS = GT_ZTYMMT00030-BKLAS BINARY SEARCH.
P_STRUC-BKLAS = GT_ZTYMMT00030-BKLAS.
P_STRUC-BKBEZ = GT_T025T-BKBEZ.
**************************change by damon at 20180118******************************
P_STRUC-QKLAS = GT_ZTYMMT00030-QKLAS.
**************************change by damon at 20180118******************************
ELSE.
P_STRUC-MESSA = P_STRUC-MESSA
&& '配置表ZTYMMT00030中无此物料组'
&& P_STRUC-MATKL
&&'的配置;'.
ENDIF.
ENDIF.
ENDIF.
P_STRUC-CELLSTYLES = LT_STYL.
IF P_STRUC-MESSA IS INITIAL.
P_STRUC-STATUS = ICON_YELLOW_LIGHT.
ELSE.
P_STRUC-STATUS = ICON_RED_LIGHT.
ENDIF.
ENDFORM.
FORM DOWNLOAD_TEMPLE_EXCEL.
DATA:W_OBJDATA LIKE WWWDATATAB,
W_MIME LIKE W3MIME,
W_FILENAME TYPE STRING VALUE '物料主数据扩展模板.XLSX',
W_FULLPATH TYPE STRING VALUE 'D:/SAPREPORT/',
W_PATH TYPE STRING VALUE 'D:/SAPREPORT/',
W_DESTINATION LIKE RLGRAP-FILENAME,
W_OBJNAM TYPE STRING,
W_RC LIKE SY-SUBRC,
W_ERRTXT TYPE STRING,
W_ACTION TYPE I.
DATA:W_OBJID TYPE WWWDATATAB-OBJID,
W_DEST LIKE SAPB-SAPPFAD.
W_OBJID = 'ZTYMME00020'.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = '下载导入模板'
DEFAULT_EXTENSION = ',*.XLS,*.XLSX.'
DEFAULT_FILE_NAME = W_FILENAME
FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
CHANGING
FILENAME = W_FILENAME
PATH = W_PATH
FULLPATH = W_FULLPATH
USER_ACTION = W_ACTION
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC = 0 AND W_ACTION EQ 0.
W_DEST = W_FULLPATH.
CONDENSE W_OBJNAM NO-GAPS.
SELECT SINGLE RELID OBJID
INTO CORRESPONDING FIELDS OF W_OBJDATA
FROM WWWDATA
WHERE SRTF2 = 0 AND RELID = 'MI' AND OBJID = W_OBJID.
IF SY-SUBRC NE 0 OR W_OBJDATA-OBJID EQ SPACE.
CONCATENATE '模板文件' W_OBJNAM '不存在' INTO W_ERRTXT.
MESSAGE W_ERRTXT TYPE 'I'.
ENDIF.
W_DESTINATION = W_DEST.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = W_OBJDATA
DESTINATION = W_DESTINATION
IMPORTING
RC = W_RC.
IF W_RC NE 0.
CONCATENATE '模板文件:' W_OBJNAM '下载失败' INTO W_ERRTXT.
MESSAGE W_ERRTXT TYPE 'E'.
ENDIF.
ELSE.
LEAVE TO TRANSACTION SY-TCODE.
ENDIF.
ENDFORM. "DOWNLOAD_TEMPLE_EXCEL
FORM FRM_ALVSHOW TABLES P_FIELDCAT TYPE LVC_T_FCAT
P_TAB TYPE STANDARD TABLE
USING P_STRUC TYPE CLIKE.
PERFORM FRM_CATALOG TABLES P_FIELDCAT.
PERFORM FRM_CREATE_EVENTS CHANGING GT_EVENTS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = GV_REPID
I_GRID_SETTINGS = GS_S_GLAY
IS_LAYOUT_LVC = GS_LAYOUTLVC
IT_FIELDCAT_LVC = GT_FIELDCAT[]
I_CALLBACK_USER_COMMAND = 'FRM_COMMAND'
I_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_SET'
IT_EVENTS = GT_EVENTS[]
I_SAVE = 'A'
TABLES
T_OUTTAB = P_TAB[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
FORM FRM_CATALOG TABLES P_FIELDCAT STRUCTURE LVC_S_FCAT.
DATA:ID TYPE I VALUE 1,
LW_FIELDCAT TYPE LVC_S_FCAT.
GV_REPID = SY-REPID.
CLEAR:ID,GT_FIELDCAT.
*定義宏來設置FIELDCAT屬性
DEFINE FIELDCATSET.
LW_FIELDCAT-FIELDNAME = &1.
LW_FIELDCAT-SCRTEXT_L = &2.
LW_FIELDCAT-FIX_COLUMN = &3.
LW_FIELDCAT-COL_POS = &4.
LW_FIELDCAT-REF_TABLE = &5.
LW_FIELDCAT-REF_FIELD = &6.
LW_FIELDCAT-OUTPUTLEN = &7.
IF &1 EQ 'ZSEL'.
LW_FIELDCAT-EDIT = 'X'.
LW_FIELDCAT-CHECKBOX = 'X'.
ELSEIF &1 EQ 'LGFSB' OR &1 EQ 'EKGRP'.
LW_FIELDCAT-EDIT = 'X'.
ENDIF.
LW_FIELDCAT-COLTEXT = LW_FIELDCAT-SCRTEXT_L.
ADD 1 TO ID.
APPEND LW_FIELDCAT TO P_FIELDCAT.
CLEAR:LW_FIELDCAT.
END-OF-DEFINITION.
FIELDCATSET 'ZSEL' '选择' 'X' ID '' '' 4.
FIELDCATSET 'STATUS' '状态' 'X' ID '' '' 4.
FIELDCATSET 'MESSA' '提示信息' '' ID '' '' 50.
FIELDCATSET 'MATNR' '物料' 'X' ID 'MARA' 'MATNR' 18.
FIELDCATSET 'MAKTX' '物料描述' 'X' ID 'MAKT' 'MAKTX' 40.
FIELDCATSET 'MEINS' '计量单位' '' ID 'T006' 'MSEHI' 8.
FIELDCATSET 'MATKL' '物料组' '' ID 'T023' 'MATKL' 6.
FIELDCATSET 'WGBEZ' '物料组描述' '' ID 'T023T' 'WGBEZ' 20.
FIELDCATSET 'WERKS' '工厂' '' ID 'MARC' 'WERKS' 4.
FIELDCATSET 'NAME1' '工厂名称' '' ID 'T001W' 'NAME1' 30.
FIELDCATSET 'LGFSB' '外部采购仓储地点' '' ID 'MARC' 'LGFSB' 16.
FIELDCATSET 'LGOBE' '外部采购仓储地点' '' ID 'T001L' 'LGOBE' 16.
FIELDCATSET 'EKGRP' '采购组' '' ID 'T024' 'EKGRP' 6.
FIELDCATSET 'EKNAM' '采购组名称' '' ID 'T024' 'EKNAM' 18.
FIELDCATSET 'XCHPF' '批次管理' '' ID 'MARC' 'XCHPF' 8.
FIELDCATSET 'DISMM' 'MRP类型' '' ID 'MARC' 'DISMM' 7.
FIELDCATSET 'DISPO' 'MRP控制者' '' ID 'MARC' 'DISPO' 9.
FIELDCATSET 'DISLS' '批量大小' '' ID 'MARC' 'DISLS' 8.
FIELDCATSET 'FHORI' '计划边际码' '' ID 'MARC' 'FHORI' 10.
FIELDCATSET 'MTVFP' '可用性检查' '' ID 'MARC' 'MTVFP' 10.
FIELDCATSET 'ZBWMOD' '评估分组代码' '' ID 'T001K' 'BWMOD' 10.
FIELDCATSET 'PRCTR' '利润中心' '' ID 'CEPC' 'PRCTR' 10.
FIELDCATSET 'KTEXT' '利润中心名称' '' ID 'CEPCT' 'KTEXT' 20.
FIELDCATSET 'BKLAS' '评估类' '' ID 'MBEW' 'BKLAS' 6.
FIELDCATSET 'BKBEZ' '评估类描述' '' ID 'T025T' 'BKBEZ' 25.
FIELDCATSET 'QKLAS' '项目评估类' '' ID 'MBEW' 'BKLAS' 6.
FIELDCATSET 'ZBKBEZ' '项目评估类描述' '' ID 'T025T' 'BKBEZ' 25.
FIELDCATSET 'VERPR' '服务移动平均价' '' ID 'MBEW' 'VERPR' 25.
GS_LAYOUTLVC-ZEBRA = 'X'.
GS_LAYOUTLVC-CWIDTH_OPT = 'X'.
GS_LAYOUTLVC-STYLEFNAME = 'CELLSTYLES'.
GS_LAYOUTLVC-NO_ROWMARK = 'X'.
GS_S_GLAY-EDT_CLL_CB = 'X'.
GS_S_GLAY-NO_COLWOPT = 'X'.
ENDFORM.
FORM FRM_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
FREE:RT_EXTAB.
CLEAR:RT_EXTAB.
APPEND '&EB9' TO RT_EXTAB.
APPEND '&UMC' TO RT_EXTAB.
APPEND '&SUM' TO RT_EXTAB.
APPEND '&XPA' TO RT_EXTAB.
APPEND '&OMP' TO RT_EXTAB.
APPEND '%SL' TO RT_EXTAB.
APPEND '&ABC' TO RT_EXTAB.
APPEND '&LFO' TO RT_EXTAB.
APPEND '&NFO' TO RT_EXTAB.
APPEND '&CRB' TO RT_EXTAB.
APPEND '&CRL' TO RT_EXTAB.
APPEND '&CRR' TO RT_EXTAB.
APPEND '&CRE' TO RT_EXTAB.
APPEND '&AQW' TO RT_EXTAB.
APPEND '&ALL' TO RT_EXTAB.
APPEND '&NAL' TO RT_EXTAB.
SET PF-STATUS 'ST_MM_GUI' EXCLUDING RT_EXTAB.
ENDFORM.
FORM FRM_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA:LV_ACTION TYPE C,
LV_MES TYPE C LENGTH 50.
DATA:LV_GRID TYPE REF TO CL_GUI_ALV_GRID,
LW_STBL TYPE LVC_S_STBL.
DATA:LW_ITAB LIKE GT_ITAB.
LW_STBL-ROW = ABAP_TRUE.
LW_STBL-COL = ABAP_TRUE.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LV_GRID.
IF NOT LV_GRID IS INITIAL.
CALL METHOD LV_GRID->CHECK_CHANGED_DATA.
CALL METHOD LV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LW_STBL
* I_SOFT_REFRESH =
EXCEPTIONS
FINISHED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
CASE R_UCOMM.
WHEN '&IC1'. "双击
IF RS_SELFIELD-FIELDNAME EQ 'MATNR'.
CLEAR:LW_ITAB.
READ TABLE GT_ITAB INTO LW_ITAB
INDEX RS_SELFIELD-TABINDEX.
IF NOT LW_ITAB-MATNR IS INITIAL.
SET PARAMETER ID 'MAT' FIELD LW_ITAB-MATNR.
SET PARAMETER ID 'WRK' FIELD LW_ITAB-WERKS.
SET PARAMETER ID 'MXX' FIELD 'K'. "基本视图
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
WHEN '&SALL'. "全选
LW_ITAB-ZSEL = ABAP_TRUE.
MODIFY GT_ITAB FROM LW_ITAB TRANSPORTING ZSEL
WHERE ZSEL EQ ABAP_FALSE.
WHEN '&NSAL'. "取消全选
LW_ITAB-ZSEL = ABAP_FALSE.
MODIFY GT_ITAB FROM LW_ITAB TRANSPORTING ZSEL
WHERE ZSEL EQ ABAP_TRUE.
WHEN '&EXPEND'.
LOOP AT GT_ITAB TRANSPORTING NO FIELDS
WHERE ZSEL EQ ABAP_TRUE
AND STATUS EQ ICON_YELLOW_LIGHT
AND MESSA IS INITIAL.
EXIT.
ENDLOOP.
IF SY-SUBRC NE 0.
MESSAGE S001 WITH '请至少选择一条有效数据' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
LV_MES = '确认扩展物料主数据?'.
PERFORM COFIRM_ACTION USING LV_MES
CHANGING LV_ACTION.
IF LV_ACTION EQ '1'.
PERFORM FRM_EXCUTE_BAPI.
ENDIF.
WHEN OTHERS.
ENDCASE.
*动态刷新
RS_SELFIELD-COL_STABLE = 'X'.
RS_SELFIELD-ROW_STABLE = 'X'.
RS_SELFIELD-REFRESH = 'X'.
ENDFORM.
FORM FRM_CREATE_EVENTS CHANGING CT_EVENTS TYPE SLIS_T_EVENT.
DATA:LS_EVENT TYPE SLIS_ALV_EVENT.
CLEAR:CT_EVENTS.
FREE:CT_EVENTS.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = CT_EVENTS.
READ TABLE CT_EVENTS INTO LS_EVENT
WITH KEY NAME = SLIS_EV_DATA_CHANGED.
LS_EVENT-NAME = SLIS_EV_DATA_CHANGED.
LS_EVENT-FORM = 'FRM_DATA_CHANGED'.
APPEND LS_EVENT TO CT_EVENTS.
ENDFORM.
FORM FRM_DATA_CHANGED USING ER_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
DATA:LS_MOD_CELLS TYPE LVC_S_MODI.
DATA:LV_GRID TYPE REF TO CL_GUI_ALV_GRID,
LW_STBL TYPE LVC_S_STBL.
FIELD-SYMBOLS:
* 稳定刷新
LW_STBL-ROW = 'X'." 基于行的稳定刷新
LW_STBL-COL = 'X'." 基于列稳定刷新
LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MOD_CELLS.
READ TABLE GT_ITAB ASSIGNING
IF LS_MOD_CELLS-FIELDNAME EQ 'EKGRP'.
PERFORM FRM_DATA_CHECK_AND_FILL USING
ELSEIF LS_MOD_CELLS-FIELDNAME EQ 'LGFSB'.
PERFORM FRM_DATA_CHECK_AND_FILL USING
* ELSEIF LS_MOD_CELLS-FIELDNAME EQ 'ZSEL'.
*
ENDIF.
ENDLOOP.
IF ER_DATA_CHANGED->MT_MOD_CELLS IS NOT INITIAL
OR ER_DATA_CHANGED->MT_DELETED_ROWS IS NOT INITIAL
OR ER_DATA_CHANGED->MT_INSERTED_ROWS IS NOT INITIAL.
ENDIF.
IF NOT LV_GRID IS INITIAL.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LV_GRID.
IF LV_GRID IS BOUND.
CALL METHOD LV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LW_STBL.
ENDIF.
ENDFORM.
FORM COFIRM_ACTION USING P_TEXT TYPE CLIKE
CHANGING P_ANSWER TYPE C.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = '确认'
DIAGNOSE_OBJECT = ' '
TEXT_QUESTION = P_TEXT
TEXT_BUTTON_1 = '是'
ICON_BUTTON_1 = 'ICON_OKAY'
TEXT_BUTTON_2 = '否'
ICON_BUTTON_2 = 'ICON_CANCEL'
DEFAULT_BUTTON = '2'
DISPLAY_CANCEL_BUTTON = ''
USERDEFINED_F1_HELP = ' '
START_COLUMN = 25
START_ROW = 6
POPUP_TYPE = 'ICON_MESSAGE_QUESTION'
IV_QUICKINFO_BUTTON_1 = ' '
IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
ANSWER = P_ANSWER
* TABLES
* PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
FORM FRM_EXCUTE_BAPI.
DATA:LW_MATHEAD TYPE BAPIMATHEAD,
LW_MARC TYPE BAPI_MARC,
LW_MARCX TYPE BAPI_MARCX,
LW_MARD TYPE BAPI_MARD,
LW_MARDX TYPE BAPI_MARDX,
LW_MBEW TYPE BAPI_MBEW,
LW_MBEWX TYPE BAPI_MBEWX,
LW_TE_MARC TYPE BAPI_TE_MARC,
LW_TE_MARCX TYPE BAPI_TE_MARCX.
DATA:BEGIN OF LT_EXTENSIONIN OCCURS 0.
INCLUDE STRUCTURE BAPIPAREX.
DATA:END OF LT_EXTENSIONIN.
DATA:BEGIN OF LT_EXTENSIONINX OCCURS 0.
INCLUDE STRUCTURE BAPIPAREXX.
DATA:END OF LT_EXTENSIONINX.
DATA:LW_RETURN TYPE BAPIRET2, "返回参数
LT_RETURN LIKE TABLE OF BAPI_MATRETURN2 WITH HEADER LINE."返回信息
DATA:LV_PER TYPE I VALUE 1,
LV_TEXT TYPE STRING.
LOOP AT GT_ITAB WHERE ZSEL EQ ABAP_TRUE
AND STATUS EQ ICON_YELLOW_LIGHT
AND MESSA IS INITIAL.
LV_PER = SY-TABIX.
* IF GT_ITAB-MTART NE 'Z002'."非服务类型物料
* LV_TEXT = '正在为物料' && GT_ITAB-MATNR && '创建分类视图......'.
* PERFORM SAPGUI_PROGRESS_INDICATOR USING LV_PER LV_TEXT.
* PERFORM FRM_CLASSIFICATION USING GT_ITAB.
*
* IF GT_ITAB-STATUS EQ ICON_RED_LIGHT.
* MODIFY GT_ITAB TRANSPORTING STATUS MESSA.
* CONTINUE.
* ENDIF.
* ENDIF.
LV_PER = SY-TABIX.
LV_TEXT = '正在为物料' && GT_ITAB-MATNR && '扩展' && GT_ITAB-WERKS && '工厂的主数据视图......'.
PERFORM SAPGUI_PROGRESS_INDICATOR USING LV_PER LV_TEXT.
LW_MATHEAD-MATERIAL = GT_ITAB-MATNR. "物料
LW_MATHEAD-PURCHASE_VIEW = ABAP_TRUE. "采购视图
LW_MATHEAD-MRP_VIEW = ABAP_TRUE. "物料需求计划(MRP)视图
LW_MATHEAD-ACCOUNT_VIEW = ABAP_TRUE. "会计视图
LW_MATHEAD-COST_VIEW = ABAP_TRUE. "成本视图
LW_MATHEAD-SALES_VIEW = ABAP_TRUE. "销售视图
IF NOT GT_ITAB-LGFSB IS INITIAL.
LW_MATHEAD-STORAGE_VIEW = ABAP_TRUE. "存储视图
ENDIF.
LW_MARC-PLANT = GT_ITAB-WERKS. "工厂
LW_MARC-PUR_GROUP = GT_ITAB-EKGRP. "采购组
LW_MARC-BATCH_MGMT = GT_ITAB-XCHPF. "批次管理需求的标识
LW_MARC-MRP_TYPE = GT_ITAB-DISMM. "物料需求计划类型
LW_MARC-MRP_CTRLER = GT_ITAB-DISPO. "MRP 控制者(物料计划人)
LW_MARC-LOTSIZEKEY = GT_ITAB-DISLS. "批量 (物料计划)
LW_MARC-SM_KEY = GT_ITAB-FHORI. "浮动的计划边际码
LW_MARC-AVAILCHECK = GT_ITAB-MTVFP. "可用性检查的检查组
LW_MARC-SLOC_EXPRC = GT_ITAB-LGFSB. "外部采购的缺省仓储位置
LW_MARC-PROFIT_CTR = GT_ITAB-PRCTR. "利润中心
IF NOT GT_ITAB-LGFSB IS INITIAL.
LW_MARD-PLANT = GT_ITAB-WERKS. "工厂
LW_MARD-STGE_LOC = GT_ITAB-LGFSB. "库存地点
ENDIF.
LW_MARCX-PLANT = GT_ITAB-WERKS. "工厂
LW_MARCX-PUR_GROUP = ABAP_TRUE. "采购组
LW_MARCX-BATCH_MGMT = ABAP_TRUE. "批次管理需求的标识
LW_MARCX-MRP_TYPE = ABAP_TRUE. "物料需求计划类型
LW_MARCX-MRP_CTRLER = ABAP_TRUE. "MRP 控制者(物料计划人)
LW_MARCX-LOTSIZEKEY = ABAP_TRUE. "批量 (物料计划)
LW_MARCX-SM_KEY = ABAP_TRUE. "浮动的计划边际码
LW_MARCX-AVAILCHECK = ABAP_TRUE. "可用性检查的检查组
LW_MARCX-SLOC_EXPRC = ABAP_TRUE. "外部采购的缺省仓储位置
LW_MARCX-PROFIT_CTR = ABAP_TRUE. "利润中心
IF NOT GT_ITAB-LGFSB IS INITIAL.
LW_MARDX-PLANT = GT_ITAB-WERKS. "工厂
LW_MARDX-STGE_LOC = GT_ITAB-LGFSB. "库存地点
ENDIF.
LW_MBEW-VAL_AREA = GT_ITAB-BWKEY. "评估范围
LW_MBEW-VAL_TYPE = ''. "评估类型
LW_MBEW-VAL_CLASS = GT_ITAB-BKLAS. "评估类
IF GT_ITAB-MTART EQ 'Z002'."服务类物料
LW_MBEW-MOVING_PR = GT_ITAB-VERPR. "移动平均价
ENDIF.
**************************change by damon at 20180118******************************
LW_MBEW-VM_P_STOCK = GT_ITAB-QKLAS.
**************************change by damon at 20180118******************************
LW_MBEWX-VAL_AREA = GT_ITAB-WERKS. "评估范围
LW_MBEWX-VAL_TYPE = ''. "评估类型
LW_MBEWX-VAL_CLASS = ABAP_TRUE. "评估类
IF GT_ITAB-MTART EQ 'Z002'."服务类物料
LW_MBEWX-MOVING_PR = ABAP_TRUE. "移动平均价
ENDIF.
**************************change by damon at 20180118******************************
LW_MBEWX-VM_P_STOCK = ABAP_TRUE.
**************************change by damon at 20180118******************************
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = LW_MATHEAD
PLANTDATA = LW_MARC
PLANTDATAX = LW_MARCX
STORAGELOCATIONDATA = LW_MARD
STORAGELOCATIONDATAX = LW_MARDX
VALUATIONDATA = LW_MBEW
VALUATIONDATAX = LW_MBEWX
IMPORTING
RETURN = LW_RETURN
TABLES
EXTENSIONIN = LT_EXTENSIONIN
EXTENSIONINX = LT_EXTENSIONINX
RETURNMESSAGES = LT_RETURN.
IF LW_RETURN-TYPE NE 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
GT_ITAB-STATUS = ICON_GREEN_LIGHT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
GT_ITAB-STATUS = ICON_RED_LIGHT.
ENDIF.
GT_ITAB-MESSA = GT_ITAB-MESSA && LW_RETURN-MESSAGE && ';'.
MODIFY GT_ITAB TRANSPORTING STATUS MESSA.
CLEAR:LW_MATHEAD,LW_MARC,LW_MARCX,LW_MARD,LW_MARDX,LW_MBEW,LW_MBEWX,LW_TE_MARC,LW_TE_MARCX.
ENDLOOP.
ENDFORM.
FORM SAPGUI_PROGRESS_INDICATOR USING P_PER TYPE I
P_TEXT TYPE CLIKE.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = P_PER
TEXT = P_TEXT.
ENDFORM.
FORM FRM_CLASSIFICATION USING P_STRUC STRUCTURE GT_ITAB. "创建分类视图
DATA:LV_OBJECTKEY TYPE OBJNUM,
LV_OBJECTTABLE TYPE TABELLE,
LV_CLASSTYPE TYPE KLASSENART,
LV_CLASS TYPE KLASSE_D.
DATA:LT_ALLOCVALUESNUM TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM,
LW_ALLOCVALUESNUM TYPE BAPI1003_ALLOC_VALUES_NUM,
LT_ALLOCVALUESCHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR,
LW_ALLOCVALUESCHAR TYPE BAPI1003_ALLOC_VALUES_CHAR,
LT_ALLOCVALUESCURR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR,
LW_ALLOCVALUESCURR TYPE BAPI1003_ALLOC_VALUES_CURR,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2.
LV_OBJECTKEY = P_STRUC-MATNR.
LV_OBJECTTABLE = 'MARA'.
LV_CLASS = 'Z001'.
LV_CLASSTYPE = '022'.
CALL FUNCTION 'BAPI_OBJCL_EXISTENCECHECK'
EXPORTING
OBJECTKEY = LV_OBJECTKEY
OBJECTTABLE = LV_OBJECTTABLE
CLASSNUM = LV_CLASS
CLASSTYPE = LV_CLASSTYPE
KEYDATE = SY-DATUM
TABLES
RETURN = LT_RETURN.
READ TABLE LT_RETURN TRANSPORTING NO FIELDS
WITH KEY TYPE = 'S'.
IF SY-SUBRC NE 0. "表示不存在分类视图
CLEAR:LT_RETURN,LT_RETURN[].
CALL FUNCTION 'BAPI_OBJCL_CREATE'
EXPORTING
OBJECTKEYNEW = LV_OBJECTKEY
OBJECTTABLENEW = LV_OBJECTTABLE
CLASSNUMNEW = LV_CLASS
CLASSTYPENEW = LV_CLASSTYPE
TABLES
ALLOCVALUESNUM = LT_ALLOCVALUESNUM
ALLOCVALUESCHAR = LT_ALLOCVALUESCHAR
ALLOCVALUESCURR = LT_ALLOCVALUESCURR
RETURN = LT_RETURN.
READ TABLE LT_RETURN INTO LW_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
P_STRUC-MESSA = P_STRUC-MESSA && LW_RETURN-MESSAGE.
P_STRUC-STATUS = ICON_RED_LIGHT.
ELSE.
LOOP AT LT_RETURN INTO LW_RETURN WHERE TYPE EQ 'S'.
ENDLOOP.
P_STRUC-MESSA = P_STRUC-MESSA && LW_RETURN-MESSAGE && ';'.
P_STRUC-STATUS = ICON_GREEN_LIGHT.
ENDIF.
ENDIF.
ENDFORM.
*Text elements
*----------------------------------------------------------
* 001 选择
*Selection texts
*----------------------------------------------------------
* S_MATNR 物料
* S_WERKS 工厂
*Messages
*----------------------------------------------------------
*
* Message class: 00
*001 &1&2&3&4&5&6&7&8