*&---------------------------------------------------------------------*
*& Report ZMMR170
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2022-02-14
*& Program Type : Report
*& Description : 电镀外发邮件提醒
*&---------------------------------------------------------------------*
REPORT ZMMR170.
*&---------------------------------------------------------------------*
*& 包含 YN_TEST02_TOP
*&---------------------------------------------------------------------*
TABLES:MARC,MARA,ZTMJCP,ZTMJZD,ZTMM16,MARD.
TYPE-POOLS:SLIS,T001W.
"定义ALV输出所需变量
DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
TYPES: BEGIN OF GTS_DATA,
MATNR TYPE MARD-MATNR, "物料编码
WERKS TYPE MARD-WERKS, "工厂
LGORT TYPE MARD-LGORT, "库存地点
LABST TYPE MARD-LABST, "非限制使用库存
INSME TYPE MARD-INSME, "质检库存
END OF GTS_DATA.
DATA: GT_DATA TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_A TYPE TABLE OF GTS_DATA WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_MATNR FOR MARD-MATNR MODIF ID C1 . "物料编码
SELECT-OPTIONS: S_WERKS FOR MARD-WERKS MODIF ID C1 . "工厂
SELECT-OPTIONS: S_LGORT FOR MARD-LGORT MODIF ID C1 . "库存地点
SELECT-OPTIONS: S_TELBX FOR ZTMM16-TELBX MODIF ID C1 . "邮件主送人
SELECT-OPTIONS: S_TELBC FOR ZTMM16-TELBX MODIF ID C1 . "邮件抄送人
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& Form SCREEN_OUTPUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_OUTPUT .
LOOP AT SCREEN.
CASE SCREEN-NAME.
WHEN 'S_TELBX-HIGH'.
SCREEN-ACTIVE = '0'.
WHEN 'S_TELBC-HIGH'.
SCREEN-ACTIVE = '0'.
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
DATA: LV_DOCUMENT_DATA TYPE SODOCCHGI1,
GT_CONTENT_TXT TYPE STANDARD TABLE OF SOLISTI1 WITH HEADER LINE,
GT_PACKING_LIST TYPE TABLE OF SOPCKLSTI1 WITH HEADER LINE,
GT_RECEIVERS TYPE STANDARD TABLE OF SOMLRECI1 WITH HEADER LINE,
LC_MAIL_ATTACH TYPE STRING,
GT_CONTENT_HEX TYPE STANDARD TABLE OF SOLIX WITH HEADER LINE,
GT_OBJECT_HEADER TYPE STANDARD TABLE OF SOLISTI1 WITH HEADER LINE,
LC_MAIL_XATTACH TYPE XSTRING,
LV_SENT_TO_ALL TYPE C,
IT_MAKT LIKE TABLE OF MAKT WITH HEADER LINE,
FIR_DATE TYPE SY-DATUM,
MIMETYPE TYPE CHAR64.
DATA: IT_ITAB TYPE TABLE OF ITAB WITH HEADER LINE,
WA_ITAB TYPE ITAB.
CONSTANTS:LC_TAB TYPE C VALUE CL_BCS_CONVERT=>GC_TAB,
LC_CTRL TYPE C VALUE CL_BCS_CONVERT=>GC_CRLF.
DATA SY_VLINE TYPE I.
DATA:
MATNR TYPE STRING,
WERKS TYPE STRING,
LGORT TYPE STRING,
LABST TYPE STRING,
INSME TYPE STRING.
*1 根据选择条件的物料编码、工厂、仓库到表MARD取出非限制使用库存 LABST 或质检库存 INSME 不等于0的物料编码、
* 工厂、库存地点、非限制使用库存LABST、质检库存INSME
CLEAR GT_DATA[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_DATA FROM MARD
WHERE MATNR IN S_MATNR
AND WERKS IN S_WERKS
AND LGORT IN S_LGORT
AND ( LABST <> 0 OR INSME <> 0 )
.
*EXPRESS 1 类型 SO_SND_EX CHAR 1 0 发送快件
*COPY 1 类型 SO_SND_CP CHAR 1 0 发送:作为副本
*BLIND_COPY 1 类型 SO_SND_BC CHAR 1 0 发送时作为密件抄送
IF GT_DATA[] IS NOT INITIAL.
CLEAR GT_RECEIVERS[].
LOOP AT S_TELBX WHERE SIGN = 'I'. "邮件主送人
GT_RECEIVERS-RECEIVER = S_TELBX-LOW .
GT_RECEIVERS-REC_TYPE = 'U'.
GT_RECEIVERS-NOTIF_READ = 'X'.
GT_RECEIVERS-COM_TYPE = 'INT'.
GT_RECEIVERS-NOTIF_DEL = 'X'.
GT_RECEIVERS-NOTIF_NDEL = 'X'.
GT_RECEIVERS-COPY = ''.
GT_RECEIVERS-BLIND_COPY = ''.
APPEND GT_RECEIVERS.
CLEAR GT_RECEIVERS.
CLEAR S_TELBX.
ENDLOOP.
LOOP AT S_TELBC WHERE SIGN = 'I'. "邮件抄送人
GT_RECEIVERS-RECEIVER = S_TELBC-LOW .
GT_RECEIVERS-REC_TYPE = 'U'.
GT_RECEIVERS-NOTIF_READ = 'X'.
GT_RECEIVERS-COM_TYPE = 'INT'.
GT_RECEIVERS-NOTIF_DEL = 'X'.
GT_RECEIVERS-NOTIF_NDEL = 'X'.
GT_RECEIVERS-COPY = 'X'.
GT_RECEIVERS-BLIND_COPY = ''.
APPEND GT_RECEIVERS.
CLEAR GT_RECEIVERS.
CLEAR S_TELBC.
ENDLOOP.
IF GT_RECEIVERS[] IS NOT INITIAL.
LV_DOCUMENT_DATA-OBJ_DESCR = '未镀件及时外发提醒' .
LV_DOCUMENT_DATA-PRIORITY = '1'.
LV_DOCUMENT_DATA-OBJ_NAME = 'OFFER'.
LV_DOCUMENT_DATA-OBJ_LANGU = SY-LANGU.
* ****邮件正文信息
GT_CONTENT_TXT = '各位:'.
APPEND GT_CONTENT_TXT.
GT_CONTENT_TXT = ' '.
APPEND GT_CONTENT_TXT.
GT_CONTENT_TXT = '必须将附件所有数量产品入库库存全部在当天发往博罗电镀厂酸洗钝化,并要求博罗在第二天内完成交货,请及时处理!'.
APPEND GT_CONTENT_TXT.
GT_CONTENT_TXT = ' '.
APPEND GT_CONTENT_TXT.
GT_CONTENT_TXT = ''.
APPEND GT_CONTENT_TXT.
GT_CONTENT_TXT = 'Thanks and regards,'.
APPEND GT_CONTENT_TXT.
DESCRIBE TABLE GT_CONTENT_TXT LINES SY_VLINE.
LV_DOCUMENT_DATA-DOC_SIZE = 255 * ( SY_VLINE - 1 ) + STRLEN( GT_CONTENT_TXT ).
GT_PACKING_LIST-TRANSF_BIN = SPACE.
GT_PACKING_LIST-HEAD_START = 1.
GT_PACKING_LIST-HEAD_NUM = 0 .
GT_PACKING_LIST-BODY_NUM = SY_VLINE.
GT_PACKING_LIST-BODY_START = 1.
GT_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND GT_PACKING_LIST.
LOOP AT GT_DATA.
AT FIRST.
CONCATENATE
'物料编码' LC_TAB
'工厂' LC_TAB
'库存地点' LC_TAB
'非限制使用库存' LC_TAB
'质检库存' LC_CTRL
INTO LC_MAIL_ATTACH.
ENDAT.
CLEAR MATNR .
CLEAR WERKS .
CLEAR LGORT .
CLEAR LABST .
CLEAR INSME .
MATNR = GT_DATA-MATNR .
WERKS = GT_DATA-WERKS .
LGORT = GT_DATA-LGORT .
LABST = GT_DATA-LABST .
INSME = GT_DATA-INSME .
CONCATENATE LC_MAIL_ATTACH
MATNR LC_TAB
WERKS LC_TAB
LGORT LC_TAB
LABST LC_TAB
INSME LC_CTRL
INTO LC_MAIL_ATTACH.
CLEAR GT_DATA.
ENDLOOP.
MIMETYPE = 'APPLICATION/MSEXCEL;CHARSET=UTF-16LE'.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = LC_MAIL_ATTACH
MIMETYPE = MIMETYPE
* ENCODING =
IMPORTING
BUFFER = LC_MAIL_XATTACH
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC = 0.
CONCATENATE CL_ABAP_CHAR_UTILITIES=>BYTE_ORDER_MARK_LITTLE LC_MAIL_XATTACH INTO LC_MAIL_XATTACH IN BYTE MODE.
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LC_MAIL_XATTACH
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =
TABLES
BINARY_TAB = GT_CONTENT_HEX.
GT_OBJECT_HEADER = '需电镀物料库存清单'.
APPEND GT_OBJECT_HEADER.
DESCRIBE TABLE GT_CONTENT_HEX LINES SY_VLINE.
GT_PACKING_LIST-TRANSF_BIN = 'X'.
GT_PACKING_LIST-HEAD_START = 1 .
GT_PACKING_LIST-HEAD_NUM = 0 .
GT_PACKING_LIST-BODY_START = 1.
GT_PACKING_LIST-BODY_NUM = SY_VLINE.
GT_PACKING_LIST-DOC_TYPE = 'XLS'.
GT_PACKING_LIST-DOC_SIZE = SY_VLINE * 255.
GT_PACKING_LIST-OBJ_NAME = '需电镀物料库存清单'.
GT_PACKING_LIST-OBJ_DESCR = GT_PACKING_LIST-OBJ_NAME.
APPEND GT_PACKING_LIST.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = LV_DOCUMENT_DATA
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = LV_SENT_TO_ALL
* NEW_OBJECT_ID =
TABLES
PACKING_LIST = GT_PACKING_LIST[]
OBJECT_HEADER = GT_OBJECT_HEADER[]
* CONTENTS_BIN =
CONTENTS_TXT = GT_CONTENT_TXT[]
CONTENTS_HEX = GT_CONTENT_HEX[]
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = GT_RECEIVERS[]
EXCEPTIONS
* TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 1
* DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 2
PARAMETER_ERROR = 3
X_ERROR = 4
ENQUEUE_ERROR = 5
OTHERS = 6.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY .
CLEAR S_LAYOUT.
S_LAYOUT-ZEBRA = 'X'.
S_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
S_LAYOUT-INFO_FIELDNAME = 'CLR'. "行颜色代码的字段
* S_LAYOUT-BOX_FIELDNAME = 'BOX'.
PERFORM FRM_FILL_FIELD .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = S_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
* I_CALLBACK_HTML_TOP_OF_PAGE = 'HTML_TOP_OF_PAGE'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
TABLES
T_OUTTAB = GT_DATA[].
ENDFORM.
FORM FRM_FILL_FIELD .
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DEFINE FILL_FIELD.
WA_FIELDCAT-FIELDNAME = &1.
WA_FIELDCAT-SELTEXT_L = &2.
* IF WA_FIELDCAT-FIELDNAME = 'MSLJH' OR WA_FIELDCAT-FIELDNAME = 'WCBJH'.
* WA_FIELDCAT-EMPHASIZE = 'C600'. "设置字段的颜色
* ENDIF.
*
* IF WA_FIELDCAT-FIELDNAME = 'MSLMB' OR WA_FIELDCAT-FIELDNAME = 'WCBMB'.
* WA_FIELDCAT-EMPHASIZE = 'C710'. "设置字段的颜色
* ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'PLNBEZ' OR WA_FIELDCAT-FIELDNAME = 'MATNR' .
WA_FIELDCAT-REF_TABNAME = 'MARA'.
WA_FIELDCAT-REF_FIELDNAME = 'MATNR'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'ARKTX' OR WA_FIELDCAT-FIELDNAME = 'WAKTX' .
WA_FIELDCAT-REF_TABNAME = 'VBAP'.
WA_FIELDCAT-REF_FIELDNAME = 'ARKTX'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'AUFNR' .
WA_FIELDCAT-REF_TABNAME = 'AUFK'.
WA_FIELDCAT-REF_FIELDNAME = 'AUFNR'.
ENDIF.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.
END-OF-DEFINITION.
FILL_FIELD :
'MATNR' '物料编码',
'WERKS' '工厂',
'LGORT' '库存地点',
'LABST' '非限制使用库存',
'INSME' '质检库存'.
ENDFORM.
FORM PF_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM.
FORM USER_COMMAND USING I_UCOMM LIKE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD.
DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
DATA : LV_STABLE TYPE LVC_S_STBL. "刷新稳定性
RANGES: L_WERKS FOR MARC-WERKS.
RANGES: L_MATNR FOR MARA-MATNR.
DATA:L_BUKRS TYPE T001K-BUKRS.
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF.
CALL METHOD REF->CHECK_CHANGED_DATA.
CASE I_UCOMM.
WHEN '&IC1'."表示双击
* IF IS_SELFIELD-FIELDNAME = 'EBELN' .
* CHECK IS_SELFIELD-TABINDEX > 0.
* CLEAR GT_DATA .
* READ TABLE GT_DATA INDEX IS_SELFIELD-TABINDEX.
*
* CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
* EXPORTING
* I_EBELN = GT_DATA-EBELN
* EXCEPTIONS
* NOT_FOUND =
* 1
* NO_AUTHORITY = 2
* INVALID_CALL = 3
* PREVIEW_NOT_POSSIBLE = 4
* OTHERS = 5.
*
* IF SY-SUBRC
* <> 0.
*
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER
* SY-MSGNO
*
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
* ENDIF.
*
* IF SY-SUBRC <> 0.
** Implement suitable error handling here
* ENDIF.
*
* ELSE .
* MESSAGE '请选择有效字段!'TYPE 'S' DISPLAY LIKE 'W'.
* ENDIF .
WHEN 'POST_T'.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
ENDFORM.
INITIALIZATION .
AT SELECTION-SCREEN OUTPUT.
PERFORM SCREEN_OUTPUT.
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
PERFORM FOM_GETDATA .
PERFORM FRM_DISPLAY.