> 스마트폼 발행내역을 PDF파일로 첨부하여 메일발송하기 <
DATA: OUTPUT_OPTIONS TYPE SSFCOMPOP,
CONTROL_PARAMETERS TYPE SSFCTRLOP,
GS_OUTPUT TYPE SSFCRESCL,
LV_LANGUAGE TYPE SFLANGU,
LV_DEVTYPE TYPE RSPOPTYPE,
LV_FM_NAME TYPE RS38L_FNAM,
PDF_DATA TYPE XSTRING,
PDF_SIZE TYPE I,
LT_LINES LIKE TLINE OCCURS 0 WITH HEADER LINE,
LV_OTF LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
CONTENT_TXT TYPE SOLI_TAB,
CONTENT_BIN TYPE SOLIX_TAB,
CONTENTS_HEX LIKE SOLIX OCCURS 0 WITH HEADER LINE,
TRANSFER_BIN TYPE SX_BOOLEAN,
OBJHEAD TYPE SOLI_TAB,
LEN_IN LIKE SOOD-OBJLEN,
LS_MHEAD LIKE SODOCCHGI1,
LV_SENDER TYPE TEXT70,
LV_MSENDER LIKE SOEXTRECI1-RECEIVER,
LV_MSENDTP LIKE SOEXTRECI1-ADR_TYP,
LT_RECV LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
LT_MAIL_BODY LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
LT_OBJCON LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
LT_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
LV_LINES LIKE SY-TABIX,
LV_DOC_SIZE LIKE SY-TABIX.
CLEAR: OUTPUT_OPTIONS, CONTROL_PARAMETERS, GS_OUTPUT.
"- 스마트폼.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZFI_FORM' "- 스마트폼 양식명.
IMPORTING
FM_NAME = LV_FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 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.
EXIT.
ENDIF.
"- 디바이스타입.
LV_LANGUAGE = SY-LANGU.
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
I_LANGUAGE = LV_LANGUAGE
I_APPLICATION = 'SAPDEFAULT'
IMPORTING
E_DEVTYPE = LV_DEVTYPE.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
"- 스마트폼 발행.
OUTPUT_OPTIONS-XSFCMODE = 'X'.
OUTPUT_OPTIONS-XSF = ' '.
OUTPUT_OPTIONS-XDFCMODE = 'X'.
OUTPUT_OPTIONS-XDF = ' '.
OUTPUT_OPTIONS-TDPRINTER = LV_DEVTYPE.
CONTROL_PARAMETERS-NO_DIALOG = 'X'.
CONTROL_PARAMETERS-GETOTF = 'X'.
CALL FUNCTION LV_FM_NAME
EXPORTING
CONTROL_PARAMETERS = CONTROL_PARAMETERS
OUTPUT_OPTIONS = OUTPUT_OPTIONS
GS_FIS0011 = P_GS_FIS0011
IMPORTING
JOB_OUTPUT_INFO = GS_OUTPUT
TABLES
GT_LIST1 = P_GT_LIST1
GT_LIST2 = P_GT_LIST2
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 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.
EXIT.
ENDIF.
"- 발행내역을 OTF Table에 저장.
LOOP AT GS_OUTPUT-OTFDATA INTO OTF_TOT.
MOVE-CORRESPONDING OTF_TOT TO OTF_TAB.
APPEND OTF_TAB.
CLEAR : OTF_TOT, OTF_TAB.
ENDLOOP.
"- OTF Table Data를 PDF로 Convert.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
IMPORTING
BIN_FILESIZE = PDF_SIZE
BIN_FILE = PDF_DATA
TABLES
OTF = OTF_TAB
LINES = LT_LINES
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
GV_CHECK = 'X'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
"- Content Text 생성.
CLEAR CONTENT_TXT.
REFRESH CONTENT_TXT.
LOOP AT OTF_TAB.
CONCATENATE OTF_TAB-TDPRINTCOM OTF_TAB-TDPRINTPAR INTO LV_OTF.
APPEND LV_OTF TO CONTENT_TXT.
ENDLOOP.
"- Content BIN 생성.
CLEAR CONTENT_BIN.
REFRESH CONTENT_BIN.
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
FORMAT_SRC = 'OTF'
FORMAT_DST = 'PDF'
CHANGING
TRANSFER_BIN = TRANSFER_BIN
CONTENT_TXT = CONTENT_TXT
CONTENT_BIN = CONTENT_BIN
OBJHEAD = OBJHEAD
LEN = LEN_IN
EXCEPTIONS
ERR_CONV_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
GV_CHECK = 'X'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
"- 메일헤더.
CLEAR LS_MHEAD.
LS_MHEAD-OBJ_DESCR = '메일제목'. "- 메일제목.
LS_MHEAD-OBJ_NAME = '메일명칭'. "- 메일명칭(내부관리용)
LS_MHEAD-OBJ_LANGU = SY-LANGU.
LS_MHEAD-SENSITIVTY = 'O'. "'O' : Standard 'P': Confidential
LS_MHEAD-OBJ_PRIO = '2'.
LS_MHEAD-NO_CHANGE = 'X'.
LS_MHEAD-PRIORITY = '2'.
"- 발신자.
LV_MSENDER = 'sender@gmail.com'.
LV_MSENDTP = 'INT'.
"- 수신자.
CLEAR LT_RECV.
REFRESH LT_RECV.
"- receiver 1.
LT_RECV-RECEIVER = 'receiver1@gmail.com'.
LT_RECV-REC_TYPE = 'U'.
LT_RECV-EXPRESS = 'X'.
APPEND LT_RECV.
CLEAR LT_RECV.
"- receiver 2.
LT_RECV-RECEIVER = 'receiver2@gmail.com'.
LT_RECV-REC_TYPE = 'U'.
LT_RECV-EXPRESS = 'X'.
APPEND LT_RECV.
CLEAR LT_RECV.
"- 메일내용.
CLEAR LT_MAIL_BODY.
MOVE TEXT-B01 TO LT_MAIL_BODY-LINE. APPEND LT_MAIL_BODY.
MOVE TEXT-B02 TO LT_MAIL_BODY-LINE. APPEND LT_MAIL_BODY.
MOVE TEXT-B03 TO LT_MAIL_BODY-LINE. APPEND LT_MAIL_BODY.
CLEAR LT_OBJCON.
REFRESH LT_OBJCON.
MOVE LT_MAIL_BODY[] TO LT_OBJCON[].
"- 첨부파일을 PACKING LIST에 저장.
CLEAR CONTENTS_HEX.
REFRESH CONTENTS_HEX.
CLEAR LV_LINES.
DESCRIBE TABLE CONTENT_BIN LINES LV_LINES.
IF LV_LINES IS NOT INITIAL.
LT_OBJPACK-TRANSF_BIN = 'X'.
LT_OBJPACK-HEAD_START = 1.
LT_OBJPACK-HEAD_NUM = 1.
LT_OBJPACK-BODY_START = 1.
LT_OBJPACK-BODY_NUM = LV_LINES.
LT_OBJPACK-DOC_TYPE = 'PDF'.
LT_OBJPACK-OBJ_NAME = 'Attachment'.
LT_OBJPACK-OBJ_DESCR = 'PDF_File.PDF'.
LV_DOC_SIZE = LV_LINES * 255.
LT_OBJPACK-DOC_SIZE = LV_DOC_SIZE.
APPEND LT_OBJPACK.
APPEND LINES OF CONTENT_BIN TO CONTENTS_HEX.
ENDIF.
"- 메일발송 (SAP Connect Queue에 저장).
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = LS_MHEAD
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = LV_MSENDER
SENDER_ADDRESS_TYPE = LV_MSENDTP
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = LT_OBJPACK
CONTENTS_HEX = CONTENTS_HEX
CONTENTS_TXT = LT_OBJCON
RECEIVERS = LT_RECV
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7.
IF SY-SUBRC NE 0.
GV_CHECK = 'X'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"- SAP Connect 메일발송처리.
SUBMIT RSCONN01 WITH MODE = 'INT'
WITH OUTPUT = 'X'
AND RETURN.
- 끝 -