Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SO_NEW_DOCUMENT_ATT_SEND_API1 vs. SO_DOCUMENT_SEND_API1

Former Member
0 Likes
1,005

Hi All!

I've been using FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send an email with a SmartForm attached.

The thing is that I want to change the sender_address but in this function I'm not able.

Investigating the code of this FM, I've founded out that this one calls SO_DOCUMENT_SEND_API1. That's all the things it does. At this point I am able to change the sender

I really don't know why I can not make the FM work.

Can anybody help me?

Regards,

Alejandro.

2 REPLIES 2
Read only

Former Member
0 Likes
643

Hi Alejandro,

It is not possible to fill in the sender email address in the function module SO_NEW_DOCUMENT_ATT_SEND_API1 as parameter SENDER_ADDRESS is hard coded as SPACE.

Instead, why not call FM SO_DOCUMENT_SEND_API1 directly in your code, along with the sender_address? This will solve your problem.

Read only

Former Member
0 Likes
643

hi check this..

&----


*& Report : ZPDF_FORMAT

*& Description : Conversion of Purchase Order into PDF format

*& used in the workflow (Do Not Change or Delete).

&----


REPORT zpdf .

&----


*& Tables used

&----


TABLES: nast, tsp01, t024, spop, lfa1, tnapr.

&----


*& Data declaration

&----


DATA: spoolno LIKE tsp01-rqident.

DATA: rcode LIKE sy-subrc.

*data: doc_auth like zoutput-ztag.

DATA: cancel.

DATA: pdf LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: numbytes TYPE i,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

DATA: dir_loc(3).

DATA: t_docno LIKE vbak-vbeln..

DATA: spoolreq1 LIKE tsp01sys.

DATA: spoolreq LIKE rsporq OCCURS 0 WITH HEADER LINE.

DATA: t_frgke LIKE ekko-frgke.

DATA: okcode(10),

flag,

t_ekgrp LIKE ekko-ekgrp,

t_lifnr LIKE ekko-lifnr,

s_mail.

Data Declartion for mailing system - Start.

DATA: objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: reclist1 LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: itab LIKE somlreci1 OCCURS 50 WITH HEADER LINE."RKU 220802

DATA: doc_chng LIKE sodocchgi1.

DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA: tab_lines LIKE sy-tabix.

DATA: verkf LIKE ekko-verkf.

DATA: bemail(250), vemail(250).

&----


Data acceptance

&----


SELECTION-SCREEN BEGIN OF BLOCK blk0_input WITH FRAME .

PARAMETERS: docno LIKE ekko-ebeln OBLIGATORY LOWER CASE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK blk0_input.

&----


Initialisation

&----


*initialization.

&----


Screen Parameters Validation

&----


*at selection-screen.

AT SELECTION-SCREEN.

SELECT SINGLE frgke INTO t_frgke FROM ekko

WHERE ebeln = docno

AND frgke = 'R'.

IF sy-subrc 0.

MESSAGE 'DOCUMENT NOT RELEASED' TYPE 'E'.

ENDIF.

&----


Execution Part

&----


START-OF-SELECTION.

For PO related operation

Dislay Buyer Group, Name and Email id

SELECT SINGLE

ekgrp

lifnr

verkf

INTO (t_ekgrp, t_lifnr, verkf)

FROM ekko

WHERE ekko~mandt = sy-mandt

AND ebeln = docno.

IF sy-subrc = 0.

SELECT SINGLE * FROM lfa1

WHERE lfa1~mandt = sy-mandt

AND lifnr = t_lifnr.

ENDIF.

Get message status from NAST or assign msg status NAST stru

Pass the message status and get spool data

PERFORM check_output_create_spool.

IF rcode NE 0.

IF rcode = 9.

message s185 with text-e04.

ELSE.

message s185 with text-e01.

ENDIF.

EXIT.

ENDIF.

find the spool

PERFORM find_spool_request_id.

IF sy-subrc 0.

message s185 with text-003.

EXIT.

ENDIF.

READ TABLE spoolreq

WITH KEY rq0name = nast-dsnam

rq1name = 'LP01'

rqclient = '800'

rq2name = sy-uname

rqowner = sy-uname.

IF sy-subrc 0.

CASE sy-subrc.

WHEN 1.

message s185 with text-e03.

WHEN OTHERS.

message s185 with text-e02.

ENDCASE.

EXIT.

ENDIF.

spoolno = spoolreq-rqident.

Convert SPOOL job to PDF

PERFORM convert_spool_to_pdf.

Send through mail

PERFORM assign_data_4_mail.

PERFORM send_mail_with_attachment.

Delete created spool request

spoolreq1-rqident = spoolno.

PERFORM delete_spool_job.

&----


*& Form check_output_create_spool

&----


text

-


--> p1 text

<-- p2 text

-


FORM check_output_create_spool.

SELECT SINGLE * FROM nast WHERE objky = docno

AND kappl = 'EF'

AND kschl = 'NEU'

AND aktiv = space

AND nacha = '1'.

IF sy-subrc EQ 0.

COUNT = COUNT + 1.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

ELSE.

CLEAR nast-uhrvr.

CLEAR nast-cmfpnr.

CLEAR nast-datvr.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

else.

rcode = 9.

ENDIF.

ENDFORM. " check_output_create_spool

&----


*& Form mssage_status_field_value

&----


text

-


--> p1 text

<-- p2 text

-


FORM mssage_status_field_value .

nast-mandt = '800'.

nast-kappl = 'EF'.

nast-kschl = 'NEU'.

nast-objky = docno.

nast-ldest = 'LP01'.

nast-anzal = 1.

nast-dimme = 'X'.

nast-delet = 'X'.

nast-nacha = '1'.

nast-vsztp = '2'.

nast-spras = 'E'.

nast-vstat = '0'.

nast-manue = 'X'.

nast-erdat = sy-datum.

nast-eruhr = sy-uzeit.

nast-usnam = sy-uname.

nast-tdreceiver = sy-uname.

concatenate sy-uzeit+2(4) 'PDF' into nast-dsnam.

ENDFORM. " mssage_status_field_value

&----


*& Form find_spool_request_id

&----


text

-


--> p1 text

<-- p2 text

-


FORM find_spool_request_id.

CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'

EXPORTING

allclients = '800'

authority = ' '

datatype = '*'

has_output_requests = '*'

rq0name = nast-dsnam "'*'

rq1name = '*'

rq2name = '*'

rqdest = 'LP01'

rqident = 0

rqowner = sy-uname

TABLES

spoolrequests = spoolreq

EXCEPTIONS

no_permission = 1

OTHERS = 2.

ENDFORM. " find_spool_request_id

&----


*& Form convert_spool_to_pdf

&----


text

-


--> p1 text

<-- p2 text

-


FORM convert_spool_to_pdf.

SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.

IF sy-subrc <> 0.

WRITE: / 'Spool order does not exist'

COLOR COL_NEGATIVE.

EXIT.

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

IF objtype(3) = 'OTF'.

is_otf = 'X'.

ELSE.

is_otf = space.

ENDIF.

IF is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11.

if sy-subrc 0.

case sy-subrc.

when 1.

write: / text-001 color col_positive.

when 2.

write: / text-002 color col_negative.

exit.

when 3.

write: / text-003 color col_negative.

exit.

when 4.

write: / text-004 color col_negative.

exit.

when others.

write: / text-005 color col_negative.

exit.

endcase.

endif.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

DST_DEVICE =

PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

LIST_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11.

case sy-subrc.

when 0.

*write: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich

*(successful)'.

color col_positive.

when 1.

write: / text-001 color col_positive.

when 2.

write: / text-002 color col_negative.

exit.

when 3.

write: / text-003 color col_negative.

exit.

when 4.

write: / text-004 color col_negative.

exit.

when others.

write: / text-005 color col_negative.

exit.

endcase.

ENDIF.

ENDFORM. " convert_spool_to_pdf

&----


*& Form delete_spool_job

&----


text

-


--> p1 text

<-- p2 text

-


FORM delete_spool_job .

CALL FUNCTION 'RSPO_IDELETE_SPOOLREQ'

EXPORTING

spoolreq = spoolreq1

IMPORTING

RC =

STATUS =

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.

ENDFORM. " delete_spool_job

*

&----


*& Form ASSIGN_DATA_4_MAIL

&----


text

-


--> p1 text

<-- p2 text

-


FORM assign_data_4_mail .

Text content of the mail

move 'Purchase order: ' to objtxt.

append objtxt.

move verkf to objtxt.

append objtxt.

move lfa1-name1 to objtxt.

append objtxt.

concatenate lfa1-ort01 lfa1-pstlz

into objtxt separated by space.

append objtxt.

clear: objtxt.

append objtxt.

append objtxt.

*

CLEAR objtxt.

CONCATENATE 'Purchase Order - ' docno

' has been released.'

INTO objtxt SEPARATED BY space.

APPEND objtxt.

clear: objtxt.

append objtxt.

append objtxt.

*

MOVE ' ' TO objtxt.

APPEND objtxt.

clear: objtxt.

append objtxt.

append objtxt.

concatenate 'Note:- This is an automatic mail sender.'

' Please do not reply to this mail ID.'

into objtxt.

append objtxt.

concatenate

' Any query, please send the mail to the respective buyer'''

's mail id.' into objtxt.

append objtxt.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = docno

IMPORTING

output = docno.

TLINE format will be coverted as 255 char foramt

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = pdf

t_target_tab = objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

DESCRIBE TABLE objtxt LINES tab_lines.

creation of the entry for the compressed document

CLEAR objpack.

objpack-transf_bin = ''.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

APPEND objpack.

creation of the entry for the Attachemnt

DESCRIBE TABLE objbin LINES tab_lines.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'PDF'.

CONCATENATE docno '.PDF' INTO objpack-obj_name.

objpack-obj_descr = objpack-obj_name.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

APPEND objpack.

For Object Header

CONCATENATE docno '.PDF' INTO objhead.

APPEND objhead.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

CONCATENATE 'Purchase Order - ' docno ' has been released'

INTO doc_chng-obj_descr.

doc_chng-obj_prio = 1.

recipient Details

CLEAR reclist1.

CLEAR reclist.

REFRESH reclist1.

REFRESH reclist.

SELECT SINGLE * FROM t024

WHERE t024~mandt = sy-mandt

AND ekgrp = t_ekgrp.

reclist1-receiver = t024-smtp_addr.

reclist1-rec_type = 'U'.

reclist1-com_type = 'INT'.

reclist1-receiver = 'mail address.

modify table reclist transporting rec_type receiver COM_TYPE .

where rec_type is initial.

APPEND reclist1 TO reclist.

ENDFORM. " ASSIGN_DATA_4_MAIL

&----


*& Form send_mail_with_attachment

&----


text

-


--> p1 text

<-- p2 text

-


FORM send_mail_with_attachment.

sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

CASE sy-subrc.

WHEN 0.

PERFORM flush_mail.

message 'Mail sent successfully' type 'I'.

when 1.

message 'No authorization for sending to the specified number'

*type 'E'.

when 2.

message 'Document could not be sent to any recipient' type 'E'.

when 4.

message 'No send authorization' type 'E'.

when others.

message 'Error occurred while sending' type 'E'.

ENDCASE.

ENDFORM. " send_mail_with_attachment

-


Start new screen *

-


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "bdc_dynpro

-


Insert field *

-


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "bdc_field

&----


*& Form AUTOMATE

&----


text

-


--> p1 text

<-- p2 text

-


FORM flush_mail .

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=PDIA'.

PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=FURT'.

PERFORM bdc_field USING 'BDC_CURSOR'

'SVALD-VALUE(01)'.

PERFORM bdc_field USING 'SVALD-VALUE(01)'

'int'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

CALL TRANSACTION 'SCOT' USING bdcdata

MODE 'N'

UPDATE 'S'.

ENDFORM. " AUTOMATE