*&---------------------------------------------------------------------*
*& Report ZMMR0082
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMMR0082.
TABLES: ZTMM0167,RLGRAP,SSCRFIELDS,ICON.
CONTROLS CNS_TROL_9001 TYPE TABLEVIEW USING SCREEN 9001.
DATA:BEGIN OF GS_9001_HEAD," R1维护视图的屏幕9001抬头字段
ZMJLH TYPE ZTMM0167-ZMJLH,
ZMJMC TYPE ZTMM0167-ZMJMC,
LIFNR TYPE ZTMM0167-LIFNR,
ZZJE TYPE ZTMM0167-ZZJE,
MENGE TYPE ZTMM0167-MENGE,
ZCGNAME TYPE ZTMM0167-ZCGNAME,
ZXMFZR TYPE ZTMM0167-ZXMFZR,
SMTP_ADDR TYPE ZTMM0167-SMTP_ADDR,
END OF GS_9001_HEAD.
DATA: BEGIN OF GT_VIEW OCCURS 0,"R3 维护视图字段,也是删除界面字段
* INCLUDE STRUCTURE ZTMM0167.
ZMJLH TYPE ZTMM0167-ZMJLH,
ZMJMC TYPE ZTMM0167-ZMJMC,
LIFNR TYPE ZTMM0167-LIFNR,
ZZJE TYPE ZTMM0167-ZZJE,
MENGE TYPE ZTMM0167-MENGE,
ZCGNAME TYPE ZTMM0167-ZCGNAME,
ZXMFZR TYPE ZTMM0167-ZXMFZR,
SMTP_ADDR TYPE ZTMM0167-SMTP_ADDR,
MATNR TYPE ZTMM0167-MATNR,
MARK,"多行的表,储存MATNR
SEL,"表明被选中
ICON TYPE ICON-ID,
MSG TYPE STRING,
END OF GT_VIEW.
TYPES:BEGIN OF TY_EMAIL,"发送邮件字段
SMTP_ADDR TYPE ZTMM0167-SMTP_ADDR, "在后续逻辑中使用了AT NEW 等逻辑,该字段需要放在首位
ZMJLH TYPE ZTMM0167-ZMJLH,
ZMJMC TYPE ZTMM0167-ZMJMC,
LIFNR TYPE ZTMM0167-LIFNR,
NAME1 TYPE LFA1-NAME1,
ZJHL TYPE MSEG-MENGE,
ZZJE TYPE ZTMM0167-ZZJE,
MENGE2 TYPE MSEG-MENGE,
ZYZF TYPE ZTMM0167-ZZJE,
ZDZF TYPE ZTMM0167-ZZJE,
ZJD(13) TYPE C,
ZCGNAME TYPE ZTMM0167-ZCGNAME,
ZXMFZR TYPE ZTMM0167-ZXMFZR,
MATNR TYPE ZTMM0167-MATNR,
END OF TY_EMAIL.
TYPES:BEGIN OF TY_ALV."R2 ALV查询字段
INCLUDE TYPE TY_EMAIL.
TYPES: SEL,"表明被选中删除
END OF TY_ALV.
TYPES:BEGIN OF TY_ALV1 ,"R4批导的导入数据后提示界面
ZMJLH TYPE ZTMM0167-ZMJLH,
ZMJMC TYPE ZTMM0167-ZMJMC,
LIFNR TYPE ZTMM0167-LIFNR,
ZZJE TYPE ZTMM0167-ZZJE,
MENGE TYPE ZTMM0167-MENGE,
ZCGNAME TYPE ZTMM0167-ZCGNAME,
ZXMFZR TYPE ZTMM0167-ZXMFZR,
SMTP_ADDR TYPE ZTMM0167-SMTP_ADDR,
MATNR TYPE ZTMM0167-MATNR,
ICON TYPE ICON-ID,
MSG TYPE STRING,
END OF TY_ALV1.
DATA:GT_ALV TYPE STANDARD TABLE OF TY_ALV,
GS_ALV TYPE TY_ALV.
DATA:GT_ALV1 TYPE STANDARD TABLE OF TY_ALV1,
GS_ALV1 TYPE TY_ALV1.
DATA:GT_TABLE TYPE STANDARD TABLE OF ZTMM0167,
GS_TABLE TYPE ZTMM0167.
DATA: GS_VIEW LIKE LINE OF GT_VIEW.
DATA: OK_CODE TYPE SY-UCOMM.
DATA: GV_ERR.
DATA: GT_FIELDCAT TYPE LVC_T_FCAT."邮件的alv全局变量
DATA:FUNCTXT TYPE SMP_DYNTXT,
FUNCTXT1 TYPE SMP_DYNTXT,
FUNCTXT2 TYPE SMP_DYNTXT.
SELECTION-SCREEN:FUNCTION KEY 1. "在屏幕定义功能码
INITIALIZATION.
FUNCTXT-ICON_ID = ICON_EXPORT.
FUNCTXT-QUICKINFO = '下载模板'.
FUNCTXT-ICON_TEXT ='下载模板'.
SSCRFIELDS-FUNCTXT_01 = FUNCTXT.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS:R1 RADIOBUTTON GROUP RAD1 DEFAULT 'X' USER-COMMAND UC.
PARAMETERS:R2 RADIOBUTTON GROUP RAD1.
PARAMETERS:R3 RADIOBUTTON GROUP RAD1.
PARAMETERS:R4 RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS:S_ZMJMC FOR ZTMM0167-ZMJMC MODIF ID M1,
S_ZCGMC FOR ZTMM0167-ZCGNAME MODIF ID M1,
S_ZXMFZR FOR ZTMM0167-ZXMFZR MODIF ID M1,
S_LIFNR FOR ZTMM0167-LIFNR MODIF ID M1.
PARAMETERS:P_SEND TYPE C MODIF ID M1.
SELECT-OPTIONS:S_ZMJMC2 FOR ZTMM0167-ZMJMC MODIF ID M2,
S_ZCGMC2 FOR ZTMM0167-ZCGNAME MODIF ID M2,
S_ZXMFZ2 FOR ZTMM0167-ZXMFZR MODIF ID M2.
SELECTION-SCREEN:SKIP.
PARAMETERS:P_FILE LIKE RLGRAP-FILENAME OBLIGATORY DEFAULT 'C:\upload.xls' MODIF ID M3.
SELECTION-SCREEN END OF BLOCK B2.
AT SELECTION-SCREEN .
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
PERFORM FRM_BEFORE_EXE. "下载模板
EXIT.
WHEN OTHERS.
ENDCASE.
INITIALIZATION.
AT SELECTION-SCREEN OUTPUT.
CASE 'X'.
WHEN R1 .
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'M1' OR SCREEN-GROUP1 EQ 'M2' OR SCREEN-GROUP1 EQ 'M3' .
SCREEN-ACTIVE = '0'.
ELSE.
SCREEN-ACTIVE = '1'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
WHEN R2.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'M2' OR SCREEN-GROUP1 EQ 'M3'.
SCREEN-ACTIVE = '0'.
ELSE.
SCREEN-ACTIVE = '1'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
WHEN R3.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'M1' OR SCREEN-GROUP1 EQ 'M3'.
SCREEN-ACTIVE = '0'.
ELSE.
SCREEN-ACTIVE = '1'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
WHEN R4.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'M1' OR SCREEN-GROUP1 EQ 'M2'.
SCREEN-ACTIVE = '0'.
ELSE.
SCREEN-ACTIVE = '1'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDCASE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FRM_F4_FILEPATH. "选择上传路径
INITIALIZATION.
START-OF-SELECTION.
CASE 'X'.
WHEN R1."维护
PERFORM: FRM_SCREEN_9001.
WHEN R2."查询
DATA(L_GUID) = ZCL_UTIL_LOG=>CREATE_LOG( ).
PERFORM: FRM_GET_ALV.
ZCL_UTIL_LOG=>SAVE_LOG( L_GUID )."保存日志到数据库
WHEN R3.
PERFORM: FRM_DELETE_DATA.
WHEN R4.
PERFORM FRM_UPLOAD_FILE. "上传Excel
* PERFORM FRM_SAVESHOW_TABLE .
WHEN OTHERS.
ENDCASE.
MODULE STATUS_9001 OUTPUT.
SET PF-STATUS 'STATUS_9001'.
SET TITLEBAR 'TITLE'.
ENDMODULE.
MODULE MOD_MODIFY_DATA_9001 OUTPUT.
DESCRIBE TABLE GT_VIEW LINES CNS_TROL_9001-LINES.
DATA: LS_COLS_9001 LIKE LINE OF CNS_TROL_9001-COLS.
RANGES: LR_FIELDNAME_9001 FOR SCREEN-NAME.
CLEAR LR_FIELDNAME_9001[].
LR_FIELDNAME_9001[] = VALUE #( BASE LR_FIELDNAME_9001[]
( LOW = 'GT_VIEW-MATNR' SIGN = 'I' OPTION = 'EQ' )
( LOW = 'GT_VIEW-MARK' SIGN = 'I' OPTION = 'EQ' )
).
DATA LV_TABIX LIKE SY-TABIX.
LOOP AT CNS_TROL_9001-COLS INTO LS_COLS_9001.
IF LS_COLS_9001-SCREEN-NAME NOT IN LR_FIELDNAME_9001[].
LS_COLS_9001-INVISIBLE = 'X'.
ELSE.
LS_COLS_9001-INVISIBLE = ''.
READ TABLE LR_FIELDNAME_9001 WITH KEY LOW = LS_COLS_9001-SCREEN-NAME.
IF SY-SUBRC EQ 0 AND LR_FIELDNAME_9001-HIGH IS NOT INITIAL.
LV_TABIX = LR_FIELDNAME_9001-HIGH.
LS_COLS_9001-INDEX = LV_TABIX.
ENDIF.
ENDIF.
MODIFY CNS_TROL_9001-COLS FROM LS_COLS_9001.
CLEAR LS_COLS_9001.
ENDLOOP.
ENDMODULE.
MODULE MOD_MODIFY_DATA_ITEM_9001 INPUT.
MODIFY GT_VIEW
INDEX CNS_TROL_9001-CURRENT_LINE.
ENDMODULE.
MODULE MOD_CHECK_DATA INPUT.
ENDMODULE.
MODULE MOD_USER_COMMAND INPUT.
CLEAR: OK_CODE.
OK_CODE = SY-UCOMM.
CASE OK_CODE.
WHEN 'CACEL' OR 'EXIT'.
LEAVE PROGRAM.
*LEAVE TO CURRENT TRANSACTION.
WHEN '&BACK' OR 'BACK'.
LEAVE TO CURRENT TRANSACTION.
WHEN 'SEL_ALL'.
* PERFORM: FRM_SEL_ALL.
LOOP AT GT_VIEW ASSIGNING FIELD-SYMBOL(<FS_VIEW>) WHERE MARK = SPACE.
<FS_VIEW>-MARK = 'X'.
ENDLOOP.
WHEN '&SAVE'.
PERFORM: FRM_SAVE_VIEW.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
FORM FRM_F4_FILEPATH .
DATA: LV_FILENAME LIKE RLGRAP-FILENAME.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',*.* ,*.*.'
MODE = '0'
TITLE = '请选择要上传的信息文件'
IMPORTING
FILENAME = LV_FILENAME
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
ENDIF.
P_FILE = LV_FILENAME.
ENDFORM.
FORM FRM_SCREEN_9001.
IF GT_VIEW[] IS INITIAL.
DO 20 TIMES.
* gt_view-gjahr = COND #( )
GT_VIEW[] = VALUE #( BASE GT_VIEW[] (
ZMJLH = COND #( WHEN GS_9001_HEAD-ZMJLH IS NOT INITIAL THEN GS_9001_HEAD-ZMJLH ELSE SPACE )
ZMJMC = COND #( WHEN GS_9001_HEAD-ZMJMC IS NOT INITIAL THEN GS_9001_HEAD-ZMJMC ELSE SPACE )
LIFNR = COND #( WHEN GS_9001_HEAD-LIFNR IS NOT INITIAL THEN GS_9001_HEAD-LIFNR ELSE SPACE )
ZZJE = COND #( WHEN GS_9001_HEAD-ZZJE IS NOT INITIAL THEN GS_9001_HEAD-ZZJE ELSE SPACE )
MENGE = COND #( WHEN GS_9001_HEAD-MENGE IS NOT INITIAL THEN GS_9001_HEAD-MENGE ELSE SPACE )
ZCGNAME = COND #( WHEN GS_9001_HEAD-ZCGNAME IS NOT INITIAL THEN GS_9001_HEAD-ZCGNAME ELSE SPACE )
ZXMFZR = COND #( WHEN GS_9001_HEAD-ZXMFZR IS NOT INITIAL THEN GS_9001_HEAD-ZXMFZR ELSE SPACE )
SMTP_ADDR = COND #( WHEN GS_9001_HEAD-SMTP_ADDR IS NOT INITIAL THEN GS_9001_HEAD-SMTP_ADDR ELSE SPACE )
*MATNR = COND #( WHEN GS_9001_HEAD-MATNR IS NOT INITIAL THEN GS_9001_HEAD-MATNR ELSE SPACE )
)
).
ENDDO.
ENDIF.
CALL SCREEN 9001.
ENDFORM.
MODULE MOD_SET_HEAD_VALUE INPUT.
CLEAR GV_ERR.
* 9001子屏幕的选择屏幕设置
IF GS_9001_HEAD-LIFNR IS INITIAL
OR GS_9001_HEAD-ZMJMC IS INITIAL
* OR GS_9001_HEAD-ZMJLH IS INITIAL
OR GS_9001_HEAD-ZZJE IS INITIAL
OR GS_9001_HEAD-MENGE IS INITIAL
OR GS_9001_HEAD-ZCGNAME IS INITIAL
OR GS_9001_HEAD-ZXMFZR IS INITIAL
OR GS_9001_HEAD-SMTP_ADDR IS INITIAL
.
* MESSAGE '所有字段均不能为空' TYPE 'E' DISPLAY LIKE 'E'.
* WAIT UP TO 1 SECONDS.
GV_ERR = 'X'.
EXIT.
ENDIF.
IF GV_ERR IS NOT INITIAL.
EXIT.
ENDIF.
LOOP AT GT_VIEW.
GT_VIEW-ZMJMC = GS_9001_HEAD-ZMJMC.
GT_VIEW-ZMJLH = GS_9001_HEAD-ZMJLH.
GT_VIEW-LIFNR = GS_9001_HEAD-LIFNR.
GT_VIEW-ZZJE = GS_9001_HEAD-ZZJE.
GT_VIEW-MENGE = GS_9001_HEAD-MENGE.
GT_VIEW-ZCGNAME = GS_9001_HEAD-ZCGNAME.
GT_VIEW-ZXMFZR = GS_9001_HEAD-ZXMFZR.
GT_VIEW-SMTP_ADDR = GS_9001_HEAD-SMTP_ADDR.
MODIFY GT_VIEW TRANSPORTING ZMJMC LIFNR ZZJE MENGE ZMJLH
ZCGNAME ZXMFZR SMTP_ADDR MATNR .
ENDLOOP.
ENDMODULE.
FORM FRM_GET_ALV."查询
* DATA:BEGIN OF LS_MSEG,
* MATNR TYPE MSEG-MATNR,
* MENGE TYPE MSEG-MENGE,
* END OF LS_MSEG.
* DATA:LT_MSEG LIKE LS_MSEG OCCURS 0 WITH HEADER LINE.
* DATA:LT_MSEG1 LIKE LS_MSEG OCCURS 0 WITH HEADER LINE.
SELECT * FROM ZTMM0167
INTO TABLE @DATA(LT_ZTMM0167)
WHERE ZMJMC IN @S_ZMJMC
AND ZCGNAME IN @S_ZCGMC
AND ZXMFZR IN @S_ZXMFZR
AND LIFNR IN @S_LIFNR.
LOOP AT LT_ZTMM0167 INTO DATA(LS_ZTMM0167).
LS_ZTMM0167-MATNR = '000000' && LS_ZTMM0167-MATNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = LS_ZTMM0167-LIFNR
IMPORTING
output = LS_ZTMM0167-LIFNR.
MODIFY LT_ZTMM0167 FROM LS_ZTMM0167.
CLEAR:LS_ZTMM0167.
ENDLOOP.
IF LT_ZTMM0167[] IS NOT INITIAL.
SELECT MATNR,LIFNR, MBLNR, ZEILE, MENGE, BWART FROM MSEG
* INTO CORRESPONDING FIELDS OF TABLE LT_MSEG
INTO TABLE @DATA(LT_MSEG)
FOR ALL ENTRIES IN @LT_ZTMM0167
WHERE MATNR = @LT_ZTMM0167-MATNR
AND LIFNR = @LT_ZTMM0167-LIFNR
AND ( BWART = '101' OR BWART = '102' OR BWART = '122' OR BWART = '123').
SORT LT_MSEG BY MATNR.
SELECT LIFNR,NAME1 FROM LFA1
INTO TABLE @DATA(LT_LFA1)
FOR ALL ENTRIES IN @LT_ZTMM0167
WHERE LIFNR = @LT_ZTMM0167-LIFNR.
ENDIF.
* LOOP AT LT_MSEG INTO DATA(LS_MSEG).
* AT NEW MATNR.
** COLLECT LT_MSEG INTO LT_MSEG1.
* ENDLOOP.
DATA:LV_ZJD TYPE ZTMM0167-ZZJE .
LOOP AT LT_ZTMM0167 INTO LS_ZTMM0167.
MOVE-CORRESPONDING LS_ZTMM0167 TO GS_ALV.
* READ TABLE LT_MSEG INTO DATA(LS_MSEG) WITH KEY MATNR = LS_ZTMM0167-MATNR.
LOOP AT LT_MSEG INTO DATA(LS_MSEG) WHERE MATNR = LS_ZTMM0167-MATNR AND LIFNR = LS_ZTMM0167-LIFNR.
IF SY-SUBRC = 0.
IF LS_MSEG-BWART = '101' OR LS_MSEG-BWART = '123'.
GS_ALV-ZJHL = GS_ALV-ZJHL + LS_MSEG-MENGE .
ELSEIF LS_MSEG-BWART EQ '102' OR LS_MSEG-BWART EQ '122'.
GS_ALV-ZJHL = GS_ALV-ZJHL - LS_MSEG-MENGE .
ENDIF.
ENDIF.
ENDLOOP.
READ TABLE LT_LFA1 INTO DATA(LS_LFA1) WITH KEY LIFNR = LS_ZTMM0167-LIFNR.
GS_ALV-NAME1 = COND #( WHEN SY-SUBRC = 0 THEN |{ LS_LFA1-NAME1 }| ELSE '' ).
GS_ALV-MENGE2 = LS_ZTMM0167-MENGE - GS_ALV-ZJHL.
GS_ALV-ZYZF = LS_ZTMM0167-ZZJE / LS_ZTMM0167-MENGE * GS_ALV-ZJHL.
GS_ALV-ZDZF = LS_ZTMM0167-ZZJE - GS_ALV-ZYZF.
LV_ZJD = GS_ALV-ZYZF / LS_ZTMM0167-ZZJE * 100.
GS_ALV-ZJD = LV_ZJD && '%'.
APPEND GS_ALV TO GT_ALV.
CLEAR:GS_ALV.
ENDLOOP.
PERFORM: FRM_DISPLAY_DATA.
CLEAR:GT_ALV.
ENDFORM.
FORM FRM_DISPLAY_DATA.
DATA: LV_POS TYPE I, " 指定第几列
LS_FIELDCAT TYPE LVC_S_FCAT, " 相当于工作区
LT_FIELDCAT TYPE LVC_T_FCAT, " 存放列名的表
LS_LAYOUT TYPE LVC_S_LAYO. " 负责整个ALV的全局属性
DATA IS_GRID_SETTINGS TYPE LVC_S_GLAY.
DEFINE ADD_FIELDCAT.
CLEAR:LS_FIELDCAT.
LV_POS = LV_POS + 1.
LS_FIELDCAT-COL_POS = LV_POS." 指定列数
LS_FIELDCAT-FIELDNAME = &1." 需要输出的内表的字段名
LS_FIELDCAT-SCRTEXT_L = &2." 字段的描述-长字段标签
LS_FIELDCAT-SCRTEXT_S = &2.
LS_FIELDCAT-SCRTEXT_M = &2.
LS_FIELDCAT-REPTEXT = &2.
LS_FIELDCAT-REF_TABLE = &3.
LS_FIELDCAT-REF_FIELD = &4.
LS_FIELDCAT-EMPHASIZE = &5.
LS_FIELDCAT-TECH = &6.
IF &1 EQ 'MARK'.
LS_FIELDCAT-EDIT = 'X'.
LS_FIELDCAT-CHECKBOX = 'X'.
*LS_FIELDCAT-BOX_FNAME = 'SEL'.
ENDIF.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
END-OF-DEFINITION.
CLEAR LS_LAYOUT.
LS_LAYOUT-ZEBRA = 'X' . " 使ALV界面呈现颜色交替
LS_LAYOUT-SEL_MODE = 'A' . " 选择模式,“A”在最左端有选择按钮
LS_LAYOUT-CWIDTH_OPT = 'X' . " 自动优化列宽
LS_LAYOUT-BOX_FNAME = 'SEL'.
DATA: LV_STATUS TYPE SLIS_FORMNAME,
LV_UCOMMS TYPE SLIS_FORMNAME.
IF R3 = 'X'.
LV_STATUS = 'ALV_GUI_STATUS'.
LV_UCOMMS = 'USER_COMMAND'.
ADD_FIELDCAT 'ZMJLH' '模具料号' 'ZTMM0167' 'ZMJLH' 'C410' ''.
ADD_FIELDCAT 'ZMJMC' '模具名称' 'ZTMM0167' 'ZMJMC' 'C410' ''.
ADD_FIELDCAT 'LIFNR' '模具开设厂商' 'ZTMM0167' 'LIFNR' 'C410' ''.
ADD_FIELDCAT 'ZZJE' '模具分摊总金额' 'ZTMM0167' 'ZZJE' 'C410' ''.
ADD_FIELDCAT 'MENGE' '模具分摊数量' 'ZTMM0167' 'MENGE' 'C410' ''.
ADD_FIELDCAT 'ZCGNAME' '采购负责人' 'ZTMM0167' 'ZCGNAME' 'C410' ''.
ADD_FIELDCAT 'ZXMFZR' '项目负责人' 'ZTMM0167' 'ZXMFZR' 'C410' ''.
ADD_FIELDCAT 'SMTP_ADDR' '邮箱地址' 'ZTMM0167' 'SMTP_ADDR' 'C410' ''.
ADD_FIELDCAT 'MATNR' '物料编号' 'ZTMM0167' 'MATNR' 'C410' ''.
READ TABLE GT_VIEW INTO GS_VIEW WITH KEY SEL = 'X'.
IF SY-SUBRC = 0.
ADD_FIELDCAT 'icon' '传输状态' '' '' 'C410' ''.
ADD_FIELDCAT 'Msg' '返回消息' '' '' 'C410' ''.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID " 当前程序
I_CALLBACK_PF_STATUS_SET = LV_STATUS
I_CALLBACK_USER_COMMAND = LV_UCOMMS
IS_LAYOUT_LVC = LS_LAYOUT
I_GRID_SETTINGS = IS_GRID_SETTINGS
IT_FIELDCAT_LVC = LT_FIELDCAT
I_SAVE = 'X' " 是否保存布局
TABLES
T_OUTTAB = GT_VIEW
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ELSEIF R2 = 'X'.
ADD_FIELDCAT 'ZMJLH' '模具料号' 'ZTMM0167' 'ZMJLH' 'C410' ''.
ADD_FIELDCAT 'ZMJMC' '模具名称' 'ZTMM0167' 'ZMJMC' 'C410' ''.
ADD_FIELDCAT 'ZJHL' '材料交货量' '' '' 'C410' ''.
ADD_FIELDCAT 'LIFNR' '模具开设厂商' 'ZTMM0167' 'LIFNR' 'C410' ''.
ADD_FIELDCAT 'NAME1' '厂商名称' 'LFA1' 'NAME1' 'C410' ''.
ADD_FIELDCAT 'ZZJE' '模具总金额' 'ZTMM0167' 'ZZJE' 'C410' ''.
ADD_FIELDCAT 'MENGE2' '待摊提数量' 'ZTMM0167' 'MENGE2' 'C410' ''.
ADD_FIELDCAT 'ZYZF' '模具已支付' '' '' 'C410' ''.
ADD_FIELDCAT 'ZDZF' '模具待支付' '' '' 'C410' ''.
ADD_FIELDCAT 'ZJD' '模具分摊进度(百分比)' '' '' 'C410' ''.
ADD_FIELDCAT 'ZCGNAME' '采购负责人' 'ZTMM0167' 'ZCGNAME' 'C410' ''.
ADD_FIELDCAT 'ZXMFZR' '项目负责人' 'ZTMM0167' 'ZXMFZR' 'C410' ''.
ADD_FIELDCAT 'MATNR' '物料编号' 'ZTMM0167' 'MATNR' 'C410' ''.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID " 当前程序
* I_CALLBACK_PF_STATUS_SET = LV_STATUS
* I_CALLBACK_USER_COMMAND = LV_UCOMMS
IS_LAYOUT_LVC = LS_LAYOUT
I_GRID_SETTINGS = IS_GRID_SETTINGS
IT_FIELDCAT_LVC = LT_FIELDCAT
I_SAVE = 'X' " 是否保存布局
TABLES
T_OUTTAB = GT_ALV
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
GT_FIELDCAT[] = LT_FIELDCAT[].
* ENDIF.
IF SY-SUBRC <> 0.
ENDIF.
IF P_SEND = 'X'.
PERFORM: FRM_SEND_EMAIL."发邮件
ENDIF.
ELSEIF R4 = 'X'.
CLEAR: LS_LAYOUT-BOX_FNAME .
LV_STATUS = 'ALV_GUI_STATUS'.
LV_UCOMMS = 'USER_COMMAND'.
ADD_FIELDCAT 'ZMJLH' '模具料号' 'ZTMM0167' 'ZMJLH' 'C410' ''.
ADD_FIELDCAT 'ZMJMC' '模具名称' 'ZTMM0167' 'ZMJMC' 'C410' ''.
ADD_FIELDCAT 'LIFNR' '模具开设厂商' 'ZTMM0167' 'LIFNR' 'C410' ''.
ADD_FIELDCAT 'ZZJE' '模具总金额' 'ZTMM0167' 'ZZJE' 'C410' ''.
ADD_FIELDCAT 'MENGE2' '待摊提数量' 'ZTMM0167' 'MENGE2' 'C410' ''.
ADD_FIELDCAT 'ZCGNAME' '采购负责人' 'ZTMM0167' 'ZCGNAME' 'C410' ''.
ADD_FIELDCAT 'ZXMFZR' '项目负责人' 'ZTMM0167' 'ZXMFZR' 'C410' ''.
ADD_FIELDCAT 'SMTP_ADDR' '邮箱地址' 'ZTMM0167' 'SMTP_ADDR' 'C410' ''.
ADD_FIELDCAT 'MATNR' '物料编号' 'ZTMM0167' 'MATNR' 'C410' ''.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID " 当前程序
I_CALLBACK_PF_STATUS_SET = LV_STATUS
I_CALLBACK_USER_COMMAND = LV_UCOMMS
IS_LAYOUT_LVC = LS_LAYOUT
I_GRID_SETTINGS = IS_GRID_SETTINGS
IT_FIELDCAT_LVC = LT_FIELDCAT
I_SAVE = 'X' " 是否保存布局
TABLES
T_OUTTAB = GT_ALV1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
GT_FIELDCAT[] = LT_FIELDCAT[].
* ENDIF.
IF SY-SUBRC <> 0.
ENDIF.
ENDIF.
ENDFORM.
FORM FRM_SEND_EMAIL."发邮件
DATA:L_XSTR TYPE XSTRING,
L_BCS_EXCPTION TYPE REF TO CX_BCS,
LT_CONTENT TYPE SOLIX_TAB,
L_SIZE TYPE SO_OBJ_LEN,
LV_TITLE TYPE SO_OBJ_DES,
LT_MAIL_BODY TYPE BCSY_TEXT,
L_LIN TYPE SO_TEXT255,
ZNAMEFJ TYPE SOOD-OBJDES,
L_TYPE TYPE BAPI_MTYPE,
L_MSG TYPE STRING.
DATA:LT_EMAIL TYPE STANDARD TABLE OF TY_EMAIL,
LS_EMAIL TYPE TY_EMAIL.
DATA LT_SEND_TO TYPE BCSY_SMTPA.
SORT GT_ALV BY SMTP_ADDR.
LOOP AT GT_ALV INTO GS_ALV.
AT NEW SMTP_ADDR.
FREE LT_EMAIL.
FREE LT_SEND_TO.
ENDAT.
MOVE-CORRESPONDING GS_ALV TO LS_EMAIL.
APPEND LS_EMAIL TO LT_EMAIL.
AT END OF SMTP_ADDR.
APPEND GS_ALV-SMTP_ADDR TO LT_SEND_TO.
CALL FUNCTION 'ZZMM_TABLE2EXCEL'
EXPORTING
IT_FIELDCAT = GT_FIELDCAT
IMPORTING
EV_DATA = L_XSTR
TABLES
TT_TAB = LT_EMAIL.
IF L_XSTR IS INITIAL.
MESSAGE '转换EXCEL失败' TYPE 'E' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
CLEAR:LT_CONTENT.
TRY.
CALL METHOD CL_BCS_CONVERT=>XSTRING_TO_SOLIX
EXPORTING
IV_XSTRING = L_XSTR
RECEIVING
ET_SOLIX = LT_CONTENT.
CATCH CX_BCS INTO L_BCS_EXCPTION.
CALL METHOD L_BCS_EXCPTION->IF_MESSAGE~GET_TEXT
RECEIVING
RESULT = GV_ERR.
RETURN.
ENDTRY.
LV_TITLE = '模具分摊报表邮件--- '.
ZNAMEFJ = '模具分摊报表邮件.XLSX'.
CALL FUNCTION 'ZZMM_SEND_MAIL_COMM'
EXPORTING
IV_TITLE = LV_TITLE
IT_BODY = LT_MAIL_BODY
IT_BINARY_CONTENT = LT_CONTENT
IV_CONTENT_SIZE = L_SIZE
IV_CONTENT_TYPE = ''
IV_CONTENT_NAME = ZNAMEFJ
IT_SEND_TO = LT_SEND_TO
IV_SEND_FRM = 'SAP-BO'
IMPORTING
EV_TYPE = L_TYPE
EV_MSG = L_MSG.
IF L_TYPE EQ 'E'.
MESSAGE '采购订单审批邮件EXCEL发送失败,错误信息:' && L_MSG TYPE 'E' DISPLAY LIKE 'E'.
ELSEIF L_TYPE EQ 'S'.
SUBMIT RSCONN01 WITH MODE ='INT' AND RETURN.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM.
FORM ALV_GUI_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
DATA: BEGIN OF LT_CODE OCCURS 0,
CODE LIKE SY-UCOMM,
END OF LT_CODE.
CLEAR LT_CODE[].
IF R3 = 'X'.
SET PF-STATUS 'STANDARD' EXCLUDING LT_CODE[].
ELSEIF R4 = 'X'.
SET PF-STATUS 'STATUS' EXCLUDING LT_CODE[].
ENDIF.
ENDFORM.
FORM FRM_DELETE_DATA .
SELECT * FROM ZTMM0167
INTO CORRESPONDING FIELDS OF TABLE GT_VIEW
WHERE ZMJMC IN S_ZMJMC2
AND ZCGNAME IN S_ZCGMC2
AND ZXMFZR IN S_ZXMFZ2.
PERFORM: FRM_DISPLAY_DATA.
CLEAR:GT_VIEW.
ENDFORM.
FORM USER_COMMAND USING S_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
IF R3 = 'X'.
CASE S_UCOMM.
WHEN 'DELETE'.
PERFORM FRM_DELETE_VIEW.
WHEN OTHERS.
ENDCASE.
ELSEIF R4 = 'X'.
CASE S_UCOMM.
WHEN '&SAVE'.
PERFORM FRM_SAVE_VIEW.
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDFORM.
FORM FRM_DELETE_VIEW.
DATA: LS_ZTMM0167 TYPE ZTMM0167.
LOOP AT GT_VIEW INTO GS_VIEW WHERE SEL = 'X'.
MOVE-CORRESPONDING GS_VIEW TO LS_ZTMM0167.
DELETE ZTMM0167 FROM LS_ZTMM0167.
IF SY-SUBRC = 0.
GS_VIEW-ICON = ICON_LED_GREEN.
GS_VIEW-MSG = '数据删除成功!'.
ELSE.
GS_VIEW-ICON = ICON_LED_RED.
GS_VIEW-MSG = '数据删除失败请重试!'.
ENDIF.
MODIFY GT_VIEW FROM GS_VIEW.
ENDLOOP.
PERFORM:FRM_DISPLAY_DATA.
*LEAVE SCREEN.
LEAVE TO CURRENT TRANSACTION.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SAVE_VIEW
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_SAVE_VIEW .
DATA: LS_ZTMM0167 TYPE ZTMM0167.
DATA:LT_ZTMM0167 TYPE STANDARD TABLE OF ZTMM0167.
* DELETE ZTMM0167 FROM LS_ZTMM0167.
IF R1 = 'X'.
IF GV_ERR IS NOT INITIAL.
MESSAGE '数据校验错误,请核对' TYPE 'E' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF GT_VIEW[] IS NOT INITIAL.
LOOP AT GT_VIEW INTO GS_VIEW WHERE MATNR IS NOT INITIAL.
MOVE-CORRESPONDING GS_VIEW TO LS_ZTMM0167.
APPEND LS_ZTMM0167 TO LT_ZTMM0167.
ENDLOOP.
ENDIF.
ELSEIF R4 ='X'.
MOVE-CORRESPONDING GT_ALV1 TO LT_ZTMM0167.
ENDIF.
IF LT_ZTMM0167[] IS NOT INITIAL.
MODIFY ZTMM0167 FROM TABLE LT_ZTMM0167."这个表全是主键,只能新增不能修改,警告无需在意
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
MESSAGE '保存成功' TYPE 'S'.
ELSE.
ROLLBACK WORK .
MESSAGE '保存失败' TYPE 'S'.
ENDIF.
ELSE.
MESSAGE '物料数据不能为空' TYPE 'S'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form FRM_BEFORE_EXE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_BEFORE_EXE .
DATA: LS_KEY TYPE WWWDATATAB,
LV_DOWN TYPE RLGRAP-FILENAME,
LV_NAME TYPE RLGRAP-FILENAME,
LV_PATH TYPE RLGRAP-FILENAME,
LV_PATH_S TYPE STRING,
LV_NAME_S TYPE STRING,
LV_PATH_F TYPE STRING,
LV_ACTION TYPE I,
LV_TITLE TYPE STRING,
LV_FILENAME TYPE STRING.
DATA:LV_SAVE_PATH TYPE STRING,
LT_RET TYPE STANDARD TABLE OF BAPIRET2.
CLEAR: LS_KEY.
LS_KEY-RELID = 'MI'. "1000-对象
LS_KEY-OBJID = 'ZTMM0167'. "1000-对象
" CONCATENATE '' SY-DATUM '.xlsx' INTO LV_FILENAME.
LV_TITLE = TEXT-010.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = LV_TITLE
DEFAULT_EXTENSION = 'xlsx'
DEFAULT_FILE_NAME = '批量维护模具信息导入模板.xlsx'
FILE_FILTER = 'Excel Files(2007/2010/2013)|*.xlsx|Excel Files(2003)|*.xls'
INITIAL_DIRECTORY = LV_SAVE_PATH
CHANGING
FILENAME = LV_NAME_S
PATH = LV_PATH_S
FULLPATH = LV_PATH_F
USER_ACTION = LV_ACTION
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2
SY-MSGV3 SY-MSGV4.
RETURN.
ELSE.
LV_SAVE_PATH = LV_PATH_S.
IF LV_ACTION EQ CL_GUI_FRONTEND_SERVICES=>ACTION_CANCEL.
MESSAGE S004(ZSD01).
RETURN.
ENDIF.
ENDIF.
LV_DOWN = LV_PATH_F.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = LS_KEY
DESTINATION = LV_DOWN.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
FULL_NAME = LV_DOWN
IMPORTING
STRIPPED_NAME = LV_NAME
FILE_PATH = LV_PATH.
CALL FUNCTION 'GUI_RUN'
EXPORTING
COMMAND = 'EXCEL'
PARAMETER = LV_NAME
CD = LV_PATH.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_FILE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_UPLOAD_FILE .
DATA: LT_RET TYPE STANDARD TABLE OF BAPIRET2.
CLEAR:GT_TABLE[].
CLEAR:GT_ALV1[].
CALL FUNCTION 'ZZZZ_UPLOAD_FILE'
EXPORTING
I_FILENAME = P_FILE
I_SKIP = 'X'
TABLES
IT_DATA = GT_ALV1
IT_RETURN = LT_RET.
IF LT_RET[] IS NOT INITIAL.
CALL FUNCTION 'ZZZZ_POPUP_MESSAGE'
TABLES
T_MESSAGE = LT_RET.
LEAVE LIST-PROCESSING.
ENDIF.
IF GT_ALV1 IS INITIAL.
MESSAGE: '导入文件为空' TYPE 'S'.
ELSE.
PERFORM:FRM_DISPLAY_DATA.
ENDIF.
ENDFORM.
03-31
333
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-22
271
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-19
412
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)