on 10-05-2007 3:46 AM
hi guys,
need your advise here on the above issue. i can generate the form in spool, send out and receive the email, however empty contain in the attach pdf file.
code
-
&----
*& Report ZTEST20070702001 *
*& *
&----
*& *
*& *
&----
REPORT ZTEST20070702001 .
*----
INCLUDE: z_kbr_abap.
*----
TABLES: sflight,toa_dara,arc_params.
types: t_zflight type zflightv2.
data: i_zflight type t_zflight.
types: t_zflightitem type ZFLIGHTITEM_TYPE,
t_zflightheader type ZFLIGHTHEADER_TYPE.
data: i_zflightitem type ZFLIGHTITEM,
i_zflightheader type table of t_zflightheader,
w_zflightheader type t_zflightheader,
w_zflightitem type t_zflightitem,
w_zflighthd_type type ZFLIGHTHD_TYPE.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
******************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME.
SELECT-OPTIONS: s_carrid for sflight-carrid OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK a.
******************************************************************
TOP-OF-PAGE.
START-OF-SELECTION.
perform data_extraction.
perform get_print_data.
END-OF-SELECTION.
perform call_smarforms.
perform send_mail.
&----
*& Form data_extraction
&----
text
----
--> p1 text
<-- p2 text
----
FORM data_extraction .
*item
select carrid connid fldate price seatsmax seatsocc paymentsum
into table i_zflightitem
from sflight
where carrid in s_carrid.
*READ TABLE i_zflightitem INTO w_zflightitem INDEX 1.
*header
select carrid into table i_zflightheader
from sflight
where carrid in s_carrid.
DELETE ADJACENT DUPLICATES FROM i_zflightheader.
*select single carrid into w_zflighthd_type-carrid
*from sflight
*where carrid = w_zflightitem-carrid.
*assign to individual component
i_zflight-z_flight_hd = i_zflightheader.
i_zflight-z_flight_item = i_zflightitem.
ENDFORM. " data_extraction
&----
*& Form call_smarforms
&----
text
----
--> p1 text
<-- p2 text
----
FORM call_smarforms .
IF NOT i_zflight IS INITIAL.
DATA: lf_formname TYPE tdsfname.
DATA: lf_fm_name TYPE rs38l_fnam.
lf_formname = 'ZSFLIGHTV2'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING formname = lf_formname
variant = ' '
direct_call = ' '
IMPORTING fm_name = lf_fm_name
EXCEPTIONS no_form = 1
no_function_module = 2
OTHERS = 3.
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
ARCHIVE_INDEX_TAB =
archive_parameters = arc_params
control_parameters = ls_control_param
MAIL_APPL_OBJ =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = space
zflight = i_zflight
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.
ENDIF.
ENDFORM. " CALL_SMARFORMS
&----
*& Form GET_PRINT_DATA
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_print_data .
ls_control_param-device = 'PRINTER'.
ls_control_param-no_dialog = 'X'.
ls_control_param-preview = ''.
ls_control_param-langu = 'E'.
ls_composer_param-tdarmod = '1'.
ls_composer_param-tdcovtitle = 'Access Type for Print Parameter'.
ls_composer_param-tddest = 'LOCL'.
ls_composer_param-tdimmed = ''.
ls_composer_param-tdreceiver = sy-uname.
ls_composer_param-tdcopies = 001.
ENDFORM. " GET_PRINT_DATA
&----
*& Form send_mail
&----
text
----
--> p1 text
<-- p2 text
----
FORM send_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 = 'ZSFLIGHTV2'
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'
zflight = i_zflight
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 = 'boonkiat.tey@smartm.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.
ENDFORM. " send_mail
Hi,
Try the following code to send the email.
&----
*& Report ZEMAIL_GM
*&
&----
REPORT zemail_gm.
*********Variable Declarations *****************************
DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform
gv_bin_filesize TYPE i, " Store the file size
gv_pos TYPE i,
gv_len TYPE i,
gv_tab_lines TYPE i.
********Constants *******************************************
Data : gc_text(11) type c value 'Form Output',
gc_tst(3) type c value 'TST',
gc_testing(7) type c value 'Testing'.
*********Work Area Declarations *****************************
DATA: gs_docdata TYPE sodocchgi1, " Data of an object which can be changed
gs_ctrlop TYPE ssfctrlop, " Smart Forms: Control structure
gs_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options
gs_otfdata TYPE ssfcrescl, " Smart Forms: Return value at end of form printing
gs_reclist TYPE somlreci1, " SAPoffice: Structure of the API Recipient List
gs_pdf_tab TYPE tline, " Workarea for SAP Script Text Lines
gs_objbin TYPE solisti1, " SAPoffice: Single List with Column Length 255
gs_objpack TYPE sopcklsti1. " SAPoffice: Description of Imported Object Components
*********Internal tables Declarations *****************************
DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List
gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines
gt_otf TYPE TABLE OF itcoo, " OTF Structure
gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List with Column Length 255
gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components
CLEAR : gv_form_name,
gs_ctrlop,
gs_outopt,
gs_otfdata,
gv_bin_filesize,
gv_pos,
gv_len,
gv_tab_lines.
START-OF-SELECTION.
Generate Function Module name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZPDF_G'
IMPORTING
fm_name = gv_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.
Assigning values to Form Control Structure and Form Composer
gs_ctrlop-getotf = 'X'.
gs_ctrlop-no_dialog = 'X'.
gs_outopt-tdnoprev = 'X'.
Getting the OTFDATA
CALL FUNCTION gv_form_name
EXPORTING
control_parameters = gs_ctrlop
output_options = gs_outopt
user_settings = 'X'
IMPORTING
job_output_info = gs_otfdata
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.
Assigning the OTFDATA to OTF Structure table
CLEAR gt_otf.
gt_otf[] = gs_otfdata-otfdata[].
Convert the OTF DATA to SAP Script Text lines
CLEAR gt_pdf_tab.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = gv_bin_filesize
TABLES
otf = gt_otf
lines = gt_pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 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.
ENDIF.
Assigning the Description of the object sent in the mail
CLEAR gs_docdata.
gs_docdata-obj_name = gc_tst.
gs_docdata-obj_descr = gc_testing.
Assigning the email id to Structure of the API Recipient List table
CLEAR : gt_reclist, gs_reclist.
gs_reclist-receiver = 'minal.nampalliwar@wipro.com'.
gs_reclist-rec_type = 'U'.
APPEND gs_reclist TO gt_reclist.
Passing the SAP Script text lines to SAPoffice: Single List with Column Length 255 table
CLEAR : gs_objbin, gs_pdf_tab.
LOOP AT gt_pdf_tab INTO gs_pdf_tab.
gv_pos = 255 - gv_len.
IF gv_pos > 134. "length of pdf_table
gv_pos = 134.
ENDIF.
gs_objbin+gv_len = gs_pdf_tab(gv_pos).
gv_len = gv_len + gv_pos.
IF gv_len = 255. "length of out (contents_bin)
APPEND gs_objbin TO gt_objbin.
CLEAR: gs_objbin, gv_len.
IF gv_pos < 134.
gs_objbin = gs_pdf_tab+gv_pos.
gv_len = 134 - gv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF gv_len > 0.
APPEND gs_objbin TO gt_objbin.
ENDIF.
Filling the details in SAPoffice: Description of Imported Object Components table
DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
CLEAR gs_objbin.
READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
IF sy-subrc = 0.
gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
gs_objpack-transf_bin = 'X'.
gs_objpack-head_start = 1.
gs_objpack-head_num = 0.
gs_objpack-body_start = 1.
gs_objpack-body_num = gv_tab_lines.
gs_objpack-doc_type = 'PDF'.
gs_objpack-obj_name = 'ATTACHMENT'.
gs_objpack-obj_descr = 'test'.
APPEND gs_objpack TO gt_objpack.
ENDIF.
Sending the Form Output in the PDF format to email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gs_docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = gt_objpack
contents_bin = gt_objbin
receivers = gt_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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE 'Sent Successfully'.
ENDIF.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
END-OF-SELECTION.
Reward if useful........
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess this sample example will helpyou to close the thread.
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8cd6adbb-0301-0010-39ba-938c601d5db9">Sample example</a>
Regards,
SaiRam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
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.