‎2008 Feb 12 12:11 PM
Hi everyone!
I've been working since a couple of days in this report that is supposed to send my SAPscript by mail.
So far, all I could find about it was that the OPEN_FORM FM accepts a sender and a receiver parameter that should allow me to do this, but at this point I seem to be doing something wrong because it's not working properly, or at least I'm not receiving any mail.
This is how I'm scripting my OPEN_FORM:
itcpo-tdimmed = '*'. " kz sofort drucken
itcpo-tddelete = '*'. " kz freigbe nach Druck
itcpo-tdlifetime = '7'. " verfalltage
itcpo-tdpreview = 'X'. " druckansicht
CALL FUNCTION 'OPEN_FORM' " open form for output
EXPORTING form = s_form
device = 'MAIL'
MAIL_SENDER = LS_PERSISTENT_SENDER
MAIL_RECIPIENT = LS_PERSISTENT_RECIPIENT
dialog = ''
OPTIONS = itcpo.
The itcpo values were part of the original program, and since I didn't mannage to figure what they're for, I didn't change them.
The LS_PERSISTENT_SENDER and LS_PERSISTENT_RECIPIENT values are being assigned by the following include:
INCLUDE .
SWC_CONTAINER LT_CONTAINER.
DATA: LO_RECIPIENT TYPE SWC_OBJECT,
LS_PERSISTENT_RECIPIENT LIKE SWOTOBJID,
LO_SENDER TYPE SWC_OBJECT,
LS_PERSISTENT_SENDER LIKE SWOTOBJID.
create recipient
SWC_CREATE_OBJECT LO_RECIPIENT 'RECIPIENT' SPACE.
recipient's address needs to be read from master data,
this is just an example
SWC_SET_ELEMENT LT_CONTAINER 'AddressString'
'fvilla@localhost.com'.
SWC_SET_ELEMENT LT_CONTAINER 'TypeID' 'U'.
SWC_CALL_METHOD LO_RECIPIENT 'CreateAddress' LT_CONTAINER.
SWC_OBJECT_TO_PERSISTENT LO_RECIPIENT LS_PERSISTENT_RECIPIENT.
create sender (current user)
SWC_CREATE_OBJECT LO_SENDER 'RECIPIENT' SPACE.
SWC_SET_ELEMENT LT_CONTAINER 'AddressString'
SY-UNAME.
SWC_SET_ELEMENT LT_CONTAINER 'TypeID' 'B'.
SWC_CALL_METHOD LO_SENDER 'CreateAddress' LT_CONTAINER.
SWC_OBJECT_TO_PERSISTENT LO_SENDER LS_PERSISTENT_SENDER.
At this moment, I run my program, got my SAPscript displayed, have the mail button, get an ok code when sending, but no mail is queued when I enter the SCOT transaction, and I don't get any mails in my mailbox either.
¿Is there any other transaction I should execute to chech the mail queue status? ¿Is there something wrong with the program?
By the way, I'm running a local SMTP server on my computer, that's why the @localhost.com in the mail address, it's not an error.
Hope that someone can help me about this.
Thanks a lot,
Fernando.
‎2008 Feb 12 12:15 PM
check SOST tcode......
to despatch mails run the report RSCONN01
‎2008 Feb 12 12:26 PM
I guess that there should be some sort of pending mail list here, but there's none, so maybe the program is not sending properly.
Thanks anyway.
‎2008 Feb 12 12:33 PM
u hav 4 checkboxes in SOST transmitted,sent,waiting,error.......check all and refresh.....
even now if it not appearing.......den might be ur program is not working properly
‎2008 Feb 12 12:47 PM
Hi,
i am not sure about the way u are mailing......but u can always do it in another way as below......
get the otf table(see documentation) from CLOSE_FORM Fm......convert it into pdf.....and send it as attachement using SO_DOCUMENT_SEND_API1 Fm.........the foll link may guide u.............
Expert Forums » ABAP Development » Form Printing and search Mailing smartform output.......
Cheers,
jose.
‎2008 Feb 13 12:55 PM
Checked, but there's nothing either.
Any other suggestions?
Thanks.
‎2008 Feb 13 1:41 PM
Hi
Please find the below code to send PDF file, this code we have done for smartforms. so please adjsut the code for your script program.
Internal table declarations
DATA lit_mseg TYPE STANDARD TABLE OF mseg INITIAL SIZE 0.
DATA lit_temp TYPE STANDARD TABLE OF gty_gr_creat INITIAL SIZE 0.
DATA lit_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.
DATA lit_tline TYPE TABLE OF tline WITH HEADER LINE.
DATA lit_objtxt TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0.
DATA lit_objpack TYPE STANDARD TABLE OF sopcklsti1 INITIAL SIZE 0.
DATA lit_objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0.
DATA lit_receiver TYPE STANDARD TABLE OF somlreci1 INITIAL SIZE 0.
Workarea declarations
DATA lwa_ctrlop TYPE ssfctrlop .
DATA lwa_compop TYPE ssfcompop .
DATA lwa_return TYPE ssfcrescl .
DATA lwa_tline TYPE tline .
DATA lwa_objtxt TYPE solisti1 .
DATA lwa_objpack TYPE sopcklsti1.
DATA lwa_doc_data TYPE sodocchgi1.
DATA lwa_objbin TYPE solisti1 .
DATA lwa_receiver TYPE somlreci1 .
DATA lwa_temp TYPE gty_gr_creat.
Variable declarations
DATA lv_form_name TYPE tdsfname VALUE 'ZZ_PTS446_MASTER_TR_REPORT'.
DATA lv_dlist TYPE so_obj_nam VALUE 'ZPTS446'.
DATA lv_func_mod TYPE rs38l_fnam .
DATA lv_len_in LIKE sood-objlen.
DATA lv_time TYPE syuzeit .
DATA lv_time2 TYPE char8 .
DATA lv_date2 TYPE char10 .
DATA lv_info TYPE so_text255 .
DATA lv_lines TYPE i .
DATA lv_buffer TYPE string .
Constants declarations
CONSTANTS lc_x TYPE char1 VALUE 'X' .
CONSTANTS lc_c TYPE so_escape VALUE 'C' .
CONSTANTS lc_locl TYPE rspopname VALUE 'LOCL' .
CONSTANTS lc_printer TYPE tddevice VALUE 'PRINTER'.
CONSTANTS lc_raw TYPE so_obj_tp VALUE 'RAW' .
CONSTANTS lc_pdf TYPE so_obj_tp VALUE 'PDF' .
CONSTANTS lc_colon TYPE char1 VALUE ':' .
CONSTANTS lc_slash TYPE char1 VALUE '/' .
CONSTANTS lc_int TYPE char3 VALUE 'INT' .
Moving record from GIT_GR_CREAT to GIT_TEMP internal table
lit_temp[] = git_gr_creat[].
Delete record from internal table GIT_TEMP, where STAT is not initial
DELETE lit_temp WHERE NOT stat IS INITIAL.
DELETE lit_temp WHERE stat EQ 'X'.
DELETE lit_temp WHERE stat EQ 'Q'.
CLEAR lwa_temp.
LOOP AT lit_temp INTO lwa_temp.
IF lwa_temp-stat EQ 'X'
OR lwa_temp-stat EQ 'Q'.
DELETE lit_temp FROM lwa_temp.
ENDIF.
ENDLOOP.
IF NOT lit_temp[] IS INITIAL.
*-- Select data from MSEG table
SELECT matnr "Material Number
erfmg "Quantity in unit of entry
tbnum "Transfer Requirement Number
INTO CORRESPONDING FIELDS OF TABLE lit_mseg
FROM mseg "Document Segment: Material
FOR ALL ENTRIES IN lit_temp
WHERE mblnr = lit_temp-mblnr
AND mjahr = lit_temp-gjahr.
*-- If select successful
IF sy-subrc EQ 0.
*---- Get name of the function module for smartform 'ZZ_PTS446_MASTER_TR_REPORT'
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lv_form_name
IMPORTING
fm_name = lv_func_mod
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
*---- Check function module name is not initial.
IF NOT lv_func_mod IS INITIAL.
*------ Select default printer based on User settings
SELECT SINGLE spld
FROM usr01
INTO usr01-spld
WHERE bname = sy-uname.
IF sy-subrc IS INITIAL.
lwa_compop-tddest = usr01-spld. "Device type
ELSE.
lwa_compop-tddest = lc_locl. "Device type
ENDIF.
lwa_compop-tdnoprev = lc_x. "No print preview
lwa_compop-tdnoprint = lc_x. "No printing from print preview
lwa_compop-tdiexit = lc_x.
*------ Setting control parameters
lwa_ctrlop-getotf = lc_x.
lwa_ctrlop-no_dialog = lc_x.
lwa_ctrlop-device = lc_printer.
*------ Call smartform function module
CALL FUNCTION lv_func_mod
EXPORTING
control_parameters = lwa_ctrlop
output_options = lwa_compop
IMPORTING
job_output_info = lwa_return
TABLES
it_mseg = lit_mseg
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
*------ If smartform function module successful
IF sy-subrc EQ 0.
*----
Transfer OTF data to internal table LIT_OTF
lit_otf[] = lwa_return-otfdata[].
*----
Convert to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = lv_len_in
TABLES
otf = lit_otf
lines = lit_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
*----
If above function module is successful
IF sy-subrc EQ 0.
*----
Mail body
CLEAR lwa_objtxt.
CONCATENATE 'TR Report of RF Inbound Deliveries'(001)
'is attached.'(002)
INTO lwa_objtxt SEPARATED BY space.
APPEND lwa_objtxt TO lit_objtxt.
*----
Append Date and Time into Body of email.
CLEAR lwa_objtxt.
MOVE 'File is generated on'(003) TO lv_info.
lv_time = sy-uzeit.
CONCATENATE lv_time+0(2)
lv_time+2(2)
lv_time+4(2)
INTO
lv_time2 SEPARATED BY lc_colon.
CONCATENATE sy-datum+4(2)
sy-datum+6(2)
sy-datum+0(4)
INTO lv_date2 SEPARATED BY lc_slash.
CONCATENATE lv_info
lv_date2
'At'(004)
lv_time2
INTO lv_info
SEPARATED BY space.
lwa_objtxt = lv_info.
APPEND lwa_objtxt TO lit_objtxt.
*----
Document size
CLEAR: lv_lines, lwa_objtxt.
DESCRIBE TABLE lit_objtxt LINES lv_lines.
READ TABLE lit_objtxt INTO lwa_objtxt INDEX lv_lines.
*----
Populate packing list for body text
CLEAR lwa_objpack.
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 0.
lwa_objpack-body_start = 1.
lwa_objpack-body_num = lv_lines.
lwa_objpack-doc_type = lc_raw.
APPEND lwa_objpack TO lit_objpack.
CLEAR lwa_objpack.
*----
Mail subject line
CLEAR lwa_doc_data.
lwa_doc_data-obj_name = 'TR REPORT'(005).
lwa_doc_data-obj_descr = 'TR Report of RF Inbound Deliveries'(001).
lwa_doc_data-doc_size = ( lv_lines - 1 ) * 255 + STRLEN( lwa_objtxt ).
*----
Populating internal table LIT_OBJBIN
LOOP AT lit_tline INTO lwa_tline.
TRANSLATE lwa_tline USING ' ~'.
CONCATENATE lv_buffer lwa_tline INTO lv_buffer.
ENDLOOP.
TRANSLATE lv_buffer USING '~ '.
DO.
APPEND lv_buffer TO lit_objbin.
SHIFT lv_buffer LEFT BY 255 PLACES.
IF lv_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
*----
Get total no.of lines of Object table(attachment)
CLEAR lv_lines.
DESCRIBE TABLE lit_objbin LINES lv_lines.
*----
Packing list for attachment
lwa_objpack-transf_bin = lc_x .
lwa_objpack-head_start = 1 .
lwa_objpack-head_num = 1 .
lwa_objpack-body_start = 1 .
lwa_objpack-body_num = lv_lines.
lwa_objpack-doc_type = lc_pdf .
lwa_objpack-obj_name = 'TR REPORT'(005).
lwa_objpack-obj_descr = 'TR_REPORT'(006).
lwa_objpack-doc_size = lv_lines * 255.
APPEND lwa_objpack TO lit_objpack.
CLEAR lwa_objpack.
*----
Giving the receiver email-id
CLEAR lwa_receiver.
lwa_receiver-receiver = lv_dlist.
lwa_receiver-rec_type = lc_c.
APPEND lwa_receiver TO lit_receiver.
*----
Calling the function module to sending email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_data
put_in_outbox = lc_x
commit_work = lc_x
TABLES
packing_list = lit_objpack
contents_bin = lit_objbin
contents_txt = lit_objtxt
receivers = lit_receiver
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 EQ 0.
*----
Wait upto 2 secounds
WAIT UP TO 2 SECONDS.
*----
Call the RSCONN01 (SAPconnect: Start Send Process)
SUBMIT rsconn01 WITH mode = lc_int
WITH output = 'X'
AND RETURN.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
Alternative solution: If you are sending PDF file for vendor / customer mails. better use Address number and get sender and Receiver details using below FM
WFMC_PREPARE_SMART_FORM