on 11-13-2007 6:42 PM
Hello all,
I have a smartform for the cotation that is sent via e-mail.
My requirement is to add some other attachments that are in a file to that same mail.
Is this possible?
Thanks in advance.
Nuno Silva
Hi
Wrote a function module to get the DMS document attachments in 2 internal tables.
Code given below:
FUNCTION z_pm_doc_email.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(DOKAR) TYPE DOKAR
*" REFERENCE(DOKNR) TYPE DOKNR
*" REFERENCE(DOKVR) TYPE DOKVR
*" TABLES
*" DATATAB1 STRUCTURE SOLISTI1
*" DATATAB2 STRUCTURE SOLISTI1
*"----
************************************************************************
Constants
************************************************************************
CONSTANTS: c_print TYPE apptp VALUE '3', "Print option
c_pc TYPE typdt VALUE 'PC', "Type
c_def TYPE ntadr VALUE 'DEFAULT', "Hostname
c_sys TYPE char4 VALUE 'WN32', "System
c_x TYPE char1 VALUE 'X'. "Value: X
************************************************************************
Variables
************************************************************************
DATA: l_appname TYPE tdwx-appfd,
l_apptype TYPE tdwd-typdt,
l_app TYPE tdwd-typdt,
l_tabix TYPE syindex,
lf_cont_provide LIKE mcdok-content_provide,
l_dttrg TYPE dttrg, "Name of data carrier
l_dappl TYPE dappl. "Application
DATA: prc_curr_dest_offset TYPE i VALUE 0,
prc_src_record_length TYPE i VALUE 0,
prc_src_data_rest TYPE i VALUE 0,
prc_dest_data_rest TYPE i VALUE 0,
prc_dest_record_length TYPE i VALUE 0,
prc_src_file_length TYPE i VALUE 0,
prc_error TYPE i VALUE 0,
prc_get_header TYPE c,
par_filesize TYPE i,
par_header_length TYPE i,
par_header TYPE xstring.
************************************************************************
Structures
************************************************************************
DATA: wa_draw TYPE draw,
wa_docfile TYPE dms_doc_file,
wa_frontend TYPE dms_frontend_data,
wa_cout TYPE dms_checkout_def.
DATA: BEGIN OF hex_record,
myhex(2550) TYPE x,
END OF hex_record.
DATA: wa_solisti1 LIKE solisti1.
************************************************************************
Internal Tables
************************************************************************
DATA: t_draz TYPE STANDARD TABLE OF draz.
DATA: t_drao LIKE drao OCCURS 0 WITH HEADER LINE,
t_draoz LIKE draoz OCCURS 0 WITH HEADER LINE.
DATA: prc_hex_tab LIKE hex_record OCCURS 1 WITH HEADER LINE.
DATA: BEGIN OF par_data_tab OCCURS 0,
mytex(255),
END OF par_data_tab.
************************************************************************
Field Symbols
************************************************************************
FIELD-SYMBOLS: <f_src> TYPE ANY,
<f_dest> TYPE ANY.
************************************************************************
Processing logic
************************************************************************
Get document data
SELECT SINGLE *
FROM draw
INTO wa_draw
WHERE dokar = dokar
AND doknr = doknr
AND dokvr = dokvr.
CHECK sy-subrc = 0.
l_app = c_pc.
CALL FUNCTION 'CV120_GET_APPL_TYPE'
EXPORTING
pf_dappl = wa_draw-dappl
pf_apptp = c_print
pf_typdt = l_app
IMPORTING
pfx_appl_name = l_appname
pfx_appl_type = l_apptype
EXCEPTIONS
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.
wa_frontend-frontend_type = c_pc. "'PC'.
wa_frontend-hostname = c_def. "'DEFAULT'.
wa_frontend-winsys = c_sys. "'WN32'.
wa_frontend-platform = 0.
Print the original documents (upto 2) attached to the Document
DO 2 TIMES.
l_tabix = sy-index.
CLEAR wa_docfile.
CASE l_tabix.
WHEN 1.
l_dappl = wa_draw-dappl.
l_dttrg = wa_draw-dttrg.
WHEN 2.
l_dappl = wa_draw-dappl1.
l_dttrg = wa_draw-dttrg1.
ENDCASE.
wa_docfile-fileno = l_tabix.
wa_docfile-dappl = l_dappl.
wa_docfile-dttrg = l_dttrg.
wa_cout-comp_get = c_x. "'X'.
REFRESH: t_draz, t_drao, t_draoz.
clear: prc_curr_dest_offset,
prc_src_record_length,
prc_src_data_rest,
prc_dest_data_rest,
prc_dest_record_length,
prc_src_file_length,
prc_error,
prc_get_header,
par_filesize,
par_header_length,
par_header.
Read the document from DMS, document content will be available in
int. table t_drao
CALL FUNCTION 'CV120_DOC_CHECKOUT'
EXPORTING: ps_cout_def = wa_cout
ps_draw = wa_draw
ps_doc_file = wa_docfile
IMPORTING: pfx_cont_provide = lf_cont_provide
TABLES: pt_draz = t_draz
ptx_drao = t_drao
ptx_draoz = t_draoz
EXCEPTIONS: error = 1
OTHERS = 2.
CHECK t_drao[] IS NOT INITIAL.
REFRESH: prc_hex_tab.
CLEAR: prc_hex_tab.
Move it an int. table for conversion
LOOP AT t_drao.
prc_hex_tab-myhex = t_drao-orblk.
APPEND prc_hex_tab.
CLEAR prc_hex_tab.
IF sy-tabix = 1.
par_filesize = t_drao-orln.
ENDIF.
ENDLOOP.
DESCRIBE FIELD par_data_tab LENGTH prc_dest_record_length
IN BYTE MODE.
DESCRIBE FIELD prc_hex_tab LENGTH prc_src_record_length
IN BYTE MODE.
prc_dest_data_rest = prc_dest_record_length.
ASSIGN par_data_tab TO <f_dest> TYPE 'X'.
prc_src_file_length = par_filesize.
IF par_header_length > 0.
prc_get_header = 'X'.
ELSE.
CLEAR prc_get_header.
ENDIF.
LOOP AT prc_hex_tab.
ASSIGN prc_hex_tab TO <f_src> TYPE 'X'.
IF prc_src_file_length < prc_src_record_length.
prc_src_data_rest = prc_src_file_length.
ELSE.
prc_src_data_rest = prc_src_record_length.
ENDIF.
prc_src_file_length = prc_src_file_length - prc_src_record_length.
Check if we need the header
IF prc_get_header IS NOT INITIAL.
CLEAR prc_get_header.
IF par_header_length >= prc_dest_record_length.
MESSAGE ID 'FES' TYPE 'E' NUMBER '010' RAISING HEADER_TOO_LONG
*.
ENDIF.
MOVE <f_src>(par_header_length) TO par_header.
prc_src_data_rest = prc_src_data_rest - par_header_length.
<f_src> = <f_src>+par_header_length(prc_src_data_rest).
par_filesize = par_filesize - par_header_length.
ENDIF.
DO.
IF prc_src_data_rest < prc_dest_data_rest.
MOVE <f_src>(prc_src_data_rest)
TO <f_dest>+prc_curr_dest_offset.
prc_curr_dest_offset =
prc_curr_dest_offset + prc_src_data_rest.
prc_dest_data_rest = prc_dest_data_rest - prc_src_data_rest.
prc_src_data_rest = 0.
EXIT.
ELSE.
MOVE <f_src>(prc_dest_data_rest)
TO <f_dest>+prc_curr_dest_offset.
APPEND par_data_tab.
ASSIGN par_data_tab TO <f_dest> TYPE 'X'.
prc_curr_dest_offset = 0.
prc_src_data_rest = prc_src_data_rest - prc_dest_data_rest.
IF prc_src_data_rest > 0.
ASSIGN <f_src>+prc_dest_data_rest(prc_src_data_rest)
TO <f_src> TYPE 'X'.
prc_dest_data_rest = prc_dest_record_length.
ELSE.
prc_dest_data_rest = prc_dest_record_length.
EXIT.
ENDIF.
ENDIF.
ENDDO.
ENDLOOP.
IF prc_curr_dest_offset > 0.
APPEND par_data_tab.
ENDIF.
Move the contents of converted internal table
IF par_data_tab[] IS NOT INITIAL.
CASE l_tabix.
WHEN 1.
datatab1[] = par_data_tab[].
WHEN 2.
datatab2[] = par_data_tab[].
ENDCASE.
REFRESH par_data_tab.
ENDIF.
IF <f_src> IS ASSIGNED.
UNASSIGN <f_src>.
ENDIF.
IF <f_dest> IS ASSIGNED.
UNASSIGN <f_dest>.
ENDIF.
ENDDO.
ENDFUNCTION.
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Here is the code...
*&---------------------------------------------------------------------*
*& Report ZTEST_PDF_MAIL
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_PDF_MAIL.
* Internal Table declarations
DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,
I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,
I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,
I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
* Objects to send mail.
I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
* Work Area declarations
WA_OBJHEAD TYPE SOLI_TAB,
W_CTRLOP TYPE SSFCTRLOP,
W_COMPOP TYPE SSFCOMPOP,
W_RETURN TYPE SSFCRESCL,
WA_DOC_CHNG TYPE SODOCCHGI1,
W_DATA TYPE SODOCCHGI1,
WA_BUFFER TYPE STRING, "To convert from 132 to 255
* Variables declarations
V_FORM_NAME TYPE RS38L_FNAM,
V_LEN_IN LIKE SOOD-OBJLEN,
V_LEN_OUT LIKE SOOD-OBJLEN,
V_LEN_OUTN TYPE I,
V_LINES_TXT TYPE I,
V_LINES_BIN TYPE I.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZTEST'
IMPORTING
FM_NAME = V_FORM_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.
ENDIF.
W_CTRLOP-GETOTF = 'X'.
W_CTRLOP-NO_DIALOG = 'X'.
W_COMPOP-TDNOPREV = 'X'.
CALL FUNCTION V_FORM_NAME
EXPORTING
CONTROL_PARAMETERS = W_CTRLOP
OUTPUT_OPTIONS = W_COMPOP
USER_SETTINGS = 'X'
IMPORTING
JOB_OUTPUT_INFO = W_RETURN
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.
ENDIF.
I_OTF[] = W_RETURN-OTFDATA[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
IMPORTING
BIN_FILESIZE = V_LEN_IN
TABLES
OTF = I_OTF
LINES = I_TLINE
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
ENDIF.
LOOP AT I_TLINE.
TRANSLATE I_TLINE USING '~'.
CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.
ENDLOOP.
TRANSLATE WA_BUFFER USING '~'.
DO.
I_RECORD = WA_BUFFER.
APPEND I_RECORD.
SHIFT WA_BUFFER LEFT BY 255 PLACES.
IF WA_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
* Attachment
REFRESH: I_RECLIST,
I_OBJTXT,
I_OBJBIN,
I_OBJPACK.
CLEAR WA_OBJHEAD.
I_OBJBIN[] = I_RECORD[].
* Create Message Body Title and Description
I_OBJTXT = 'test with pdf-Attachment!'.
APPEND I_OBJTXT.
DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.
READ TABLE I_OBJTXT INDEX V_LINES_TXT.
WA_DOC_CHNG-OBJ_NAME = 'smartform'.
WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.
WA_DOC_CHNG-OBJ_DESCR = 'smartform'.
WA_DOC_CHNG-SENSITIVTY = 'F'.
WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.
* Main Text
CLEAR I_OBJPACK-TRANSF_BIN.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
I_OBJPACK-BODY_NUM = V_LINES_TXT.
I_OBJPACK-DOC_TYPE = 'RAW'.
APPEND I_OBJPACK.
* Attachment (pdf-Attachment)
I_OBJPACK-TRANSF_BIN = 'X'.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
READ TABLE I_OBJBIN INDEX V_LINES_BIN.
I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .
I_OBJPACK-BODY_NUM = V_LINES_BIN.
I_OBJPACK-DOC_TYPE = 'PDF'.
I_OBJPACK-OBJ_NAME = 'smart'.
I_OBJPACK-OBJ_DESCR = 'test'.
APPEND I_OBJPACK.
CLEAR I_RECLIST.
I_RECLIST-RECEIVER = 'nareshreddy.k@gmail.com'.
I_RECLIST-REC_TYPE = 'U'.
APPEND I_RECLIST.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = I_OBJPACK
OBJECT_HEADER = WA_OBJHEAD
CONTENTS_BIN = I_OBJBIN
CONTENTS_TXT = I_OBJTXT
RECEIVERS = I_RECLIST
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
OTHERS = 8.
IF SY-SUBRC <> 0.
WRITE:/ 'Error When Sending the File', SY-SUBRC.
ELSE.
WRITE:/ 'Mail sent'.
ENDIF.
If you want to send some text as Body of the Mail then follow this once
when u r callin the FM'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember
1.u have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. suppose i have appended 11 records to the table CONTENTS_TXT .
2.PACKING_LIST(iam usign I_OBJPACK) table u ahve to append a redord as follows
I_OBJPACK-TRANSF_BIN = ' '.
I_OBJPACK-HEAD_START = 000000000000001.
I_OBJPACK-HEAD_NUM = 000000000000001.
I_OBJPACK-BODY_START = 000000000000002
I_OBJPACK-BODY_NUM = 000000000000010.
I_OBJPACK-DOC_TYPE = 'RAW'.
append I_OBJPACK-.
by the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = I_OBJPACK
OBJECT_HEADER = WA_OBJHEAD
CONTENTS_BIN = I_OBJBIN
CONTENTS_TXT = I_OBJTXT
RECEIVERS = I_RECLIST
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
OTHERS = 8.
<b>Reward Points if it helps,</b>
Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.