*----------------Database Declaration-----------------------------*
TABLES: LFA1,ADR6.
*-----------------Internal Table Declaration----------------------*
*----------------Work VAriables ----------------------------------*
DATA: S_DOC_CHNG LIKE SODOCCHGI1.
DATA: L_TAB_LINES LIKE SY-TABIX.
DATA: COUNT1 TYPE I.
DATA: COUNT2(4) TYPE N.
DATA: W_ITCPO LIKE ITCPO,W_DIALOG,W_ITCPP LIKE ITCPP.
DATA: W_BIN_FILESIZE(10) TYPE C.
DATA: L_FILENAME LIKE RLGRAP-FILENAME .
DATA: OK_CODE LIKE SY-UCOMM.
DATA: SAV_OK_CODE LIKE SY-UCOMM.
DATA: LINE_COUNT TYPE I.
DATA: FLAG(1) VALUE 'X'.
DATA: WRK_LINES LIKE SY-TABIX.
DATA: WRK_REMNO LIKE ZDUNNING_EMAIL-REMNO.
DATA: T_OTFDATA LIKE ITCOO OCCURS 0 WITH HEADER LINE.
DATA: T_ASCII LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA: T_PDF LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA: T_OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: T_OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: T_OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: T_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: T_RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: T_TEXT1 LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA: WRK_DAT LIKE SY-DATUM.
CONTROLS: TBCTL_EMAIL TYPE TABLEVIEW USING SCREEN 9000.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
APPLICATION = 'DS'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DIALOG = W_DIALOG
FORM = 'ZRP_DUNNING1'
LANGUAGE = SY-LANGU
OPTIONS = W_ITCPO
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
RESULT = W_ITCPP
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
MAIL_OPTIONS = 6
ARCHIVE_ERROR = 7
INVALID_FAX_NUMBER = 8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS = 10.
ENDFORM. " OPEN_SCRIPT
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_IN_TXT_MODE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_IN_TXT_MODE.
REFRESH T_PDF.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 255
IMPORTING
BIN_FILESIZE = W_BIN_FILESIZE
TABLES
OTF = T_OTFDATA
LINES = T_PDF
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
ENDFORM. " DOWNLOAD_IN_TXT_MODE
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_TO_PRES_SERV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_TO_PRES_SERV.
COUNT2 = IT_REQ1-COUNT.
CONCATENATE 'C:RFQ_' COUNT2 '.PDF' INTO L_FILENAME .
CALL FUNCTION 'DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_BIN_FILESIZE
FILENAME = L_FILENAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = T_PDF
EXCEPTIONS
INVALID_FILESIZE = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
CUSTOMER_ERROR = 7
OTHERS = 8.
CLEAR COUNT2.
ENDFORM. " DOWNLOAD_TO_PRES_SERV
*&---------------------------------------------------------------------*
*& Form SEND_MAIL_INSUR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SEND_MAIL_INSUR.
DATA : L_CHRLEN TYPE I,
L_FILENAME LIKE RLGRAP-FILENAME ,
L_LENGTH LIKE T_OBJPACK-DOC_SIZE .
CLEAR : T_OBJPACK,T_OBJTXT,T_OBJBIN,T_OBJHEAD,T_RECLIST,S_DOC_CHNG.
REFRESH : T_OBJPACK,T_OBJTXT,T_OBJBIN,T_OBJHEAD,T_RECLIST.
S_DOC_CHNG-OBJ_NAME = 'RFQ Referrals'.
S_DOC_CHNG-OBJ_DESCR = 'RFQ Referrals'.
DESCRIBE TABLE T_OBJTXT LINES L_TAB_LINES.
READ TABLE T_OBJTXT INDEX L_TAB_LINES.
S_DOC_CHNG-DOC_SIZE = ( L_TAB_LINES - 1 ) * 255 + STRLEN( T_OBJTXT ).
CLEAR T_OBJPACK-TRANSF_BIN.
T_OBJPACK-HEAD_START = 1.
T_OBJPACK-HEAD_NUM = 0.
T_OBJPACK-BODY_START = 1.
T_OBJPACK-BODY_NUM = L_TAB_LINES.
T_OBJPACK-DOC_TYPE = 'RAW'.
APPEND T_OBJPACK.
PERFORM CONVERT_TABLE.
DESCRIBE TABLE T_OBJBIN LINES L_TAB_LINES.
T_OBJHEAD = L_FILENAME.
APPEND T_OBJHEAD.
T_OBJPACK-TRANSF_BIN = 'X'.
T_OBJPACK-HEAD_START = 1.
T_OBJPACK-HEAD_NUM = 1.
T_OBJPACK-BODY_START = 1.
T_OBJPACK-BODY_NUM = L_TAB_LINES.
T_OBJPACK-DOC_TYPE = 'PDF'.
T_OBJPACK-OBJ_NAME = 'RFQ REFERRAL'.
T_OBJPACK-OBJ_DESCR = 'RFQ REFERRALS : PDF Format'.
T_OBJPACK-DOC_SIZE = L_TAB_LINES * 255.
W_BIN_FILESIZE = L_TAB_LINES * 255.
MOVE W_BIN_FILESIZE TO L_LENGTH+3(9).
TRANSLATE L_LENGTH USING ' 0'.
T_OBJPACK-DOC_SIZE = L_LENGTH .
APPEND T_OBJPACK.
T_RECLIST-RECEIVER = IT_REQ-EMAIL.
T_RECLIST-REC_TYPE = 'U'.
APPEND T_RECLIST.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = S_DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = T_OBJPACK
OBJECT_HEADER = T_OBJHEAD
CONTENTS_BIN = T_OBJBIN
CONTENTS_TXT = T_OBJTXT
RECEIVERS = T_RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
IF SY-SUBRC EQ 0.
MESSAGE S501(ZF).
CLEAR IT_REQ2. REFRESH IT_REQ2.
LOOP AT IT_REQ WHERE SEL = 'X'.
MOVE-CORRESPONDING IT_REQ TO IT_REQ2.
APPEND IT_REQ2.
DELETE IT_REQ WHERE SEL = 'X'.
CLEAR IT_REQ.
ENDLOOP.
FLAG = ' '.
ELSE.
MESSAGE E502(ZF).
ENDIF.
ENDFORM. " SEND_MAIL_INSUR
*&---------------------------------------------------------------------*
*& Form CONVERT_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CONVERT_TABLE.
DATA: HLTLINES TYPE I.
DATA: FLE1(2) TYPE P.
DATA: FLE2(2) TYPE P.
DATA: HFELD(500) TYPE C.
DATA: OFF1 TYPE P.
DATA: HTABIX LIKE SY-TABIX.
DESCRIBE TABLE T_PDF LINES HLTLINES.
DESCRIBE FIELD T_PDF LENGTH FLE1.
DESCRIBE FIELD T_OBJBIN LENGTH FLE2.
CLEAR T_OBJBIN. REFRESH T_OBJBIN.
CLEAR OFF1. CLEAR HFELD.
LOOP AT T_PDF.
HTABIX = SY-TABIX.
MOVE T_PDF TO HFELD+OFF1.
IF HTABIX = HLTLINES.
FLE1 = STRLEN( T_PDF ).
ENDIF.
OFF1 = OFF1 + FLE1.
IF OFF1 GE FLE2.
CLEAR T_OBJBIN.
T_OBJBIN = HFELD(FLE2).
APPEND T_OBJBIN.
SHIFT HFELD BY FLE2 PLACES.
OFF1 = OFF1 - FLE2.
ENDIF.
IF HTABIX = HLTLINES.
IF OFF1 GT 0.
CLEAR T_OBJBIN.
T_OBJBIN = HFELD(OFF1).
APPEND T_OBJBIN.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " CONVERT_TABLE
*&---------------------------------------------------------------------*
*& Form OPEN_SCRIPT1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM OPEN_SCRIPT1.
IF W_ITCPP IS INITIAL.
W_DIALOG = 'X'.
IF SAV_OK_CODE = 'PRNPRV'.
W_ITCPO-TDGETOTF = ' '.
ENDIF.
IF SAV_OK_CODE = 'PDFD' OR SAV_OK_CODE = 'PDFM'.
W_DIALOG = 'X'.
W_ITCPO-TDGETOTF = 'X'.
ENDIF.
ELSE. " if w_itcpp is initial.
CLEAR W_DIALOG.
MOVE-CORRESPONDING W_ITCPP TO W_ITCPO.
ENDIF. " if w_itcpp is initial.
IF SAV_OK_CODE = 'PRNPRV'.
W_DIALOG = 'X'.
ENDIF.
*changed
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'DS'
* DIALOG = W_DIALOG
FORM = 'ZRP_DUNNING1'
LANGUAGE = SY-LANGU
* OPTIONS = W_ITCPO
* IMPORTING
* RESULT = W_ITCPP
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
MAIL_OPTIONS = 6
ARCHIVE_ERROR = 7
INVALID_FAX_NUMBER = 8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS = 10.
ENDFORM. " OPEN_SCRIPT1