cancel
Showing results for 
Search instead for 
Did you mean: 

To send smartform o/p through email

Former Member
0 Kudos

Hi,

I have a requirement to send smartform o/p through email.I am able to send the o/p through email.But when I check in SOST transaction,it is showing 2 copies of o/p instead of one.Can anyone tell me why this is happening?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello!

Well if it is not the case of sap internal bug, i think that it might be possible that there is something wrong in coding. Try to debug Your program. Ask Your basis specialist to check smtp settings. If You need i can provide You with my coding.

Good Luck!

Former Member
0 Kudos

Hi Andrei,

Thank you.

COuld you please check my code and tell me if I gone wrong somewhere.

SELECT SINGLE * FROM tnapr WHERE kschl = C_ZUPG

AND nacha = C_5

AND kappl = C_V3.

  • IF cf_retcode = 0.

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.

IF sy-subrc <> 0.

  • error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

  • ENDIF.

ENDIF.

ls_control_param-getotf = 'X'.

ls_control_param-no_dialog = 'X'.

ls_control_param-preview = 'X'.

ls_composer_param-tdnoprev = 'X'.

ls_composer_param-tdreceiver = sy-uname.

ls_composer_param-tddest = C_LOCL.

ls_composer_param-tdcopies = 1.

CALL FUNCTION lf_fm_name "#EC *

EXPORTING

archive_index = toa_dara

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

is_bil_invoice = ls_bil_invoice

is_nast = nast

is_repeat = repeat

  • importing document_output_info =

*Uncomented the line to get the spool id or OTF formatted data -

*NY047532

IMPORTING

document_output_info = document_output_info"HD2465697

job_output_info = w_job

job_output_options = job_output_options "HD2465697

  • NY047532

EXCEPTIONS formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

lt_otf[] = w_job-otfdata[].

removing the initial and final markers from the OTF data

DELETE w_job-otfdata WHERE tdprintcom = '//'.

READ TABLE lt_otf WITH KEY tdprintcom = 'EP'.

my_tabix = sy-tabix + 1.

INSERT LINES OF w_job-otfdata INTO lt_otf INDEX my_tabix.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = lv_binfile

TABLES

otf = lt_otf[]

lines = lt_tline[].

PERFORM get_emailaddress USING ls_bil_invoice

CHANGING lv_kunnr

lv_adrnr

lv_prsnr

lv_addr.

IF lv_addr IS NOT INITIAL.

PERFORM send_email TABLES lt_tline USING lv_addr.

ELSE.

FORM get_emailaddress USING ls_bil_invoice TYPE lbbil_invoice

CHANGING lv_kunnr LIKE vbpa-kunnr

lv_adrnr LIKE vbpa-adrnr

lv_prsnr LIKE knvk-prsnr

lv_addr LIKE adr6-smtp_addr.

DATA: c_0009(4) TYPE c value '0009'.

CLEAR lv_kunnr.

SELECT SINGLE kunnr "#EC *

INTO lv_kunnr

FROM vbpa

WHERE vbeln = ls_bil_invoice-hd_gen-bil_number.

IF sy-subrc = 0.

CLEAR lv_adrnr.

SELECT SINGLE adrnr

FROM vbpa

INTO lv_adrnr

WHERE vbeln = ls_bil_invoice-hd_gen-bil_number

AND kunnr = lv_kunnr

AND posnr = 0

AND parvw = 'AG'.

IF sy-subrc = 0.

CLEAR lv_prsnr.

SELECT SINGLE prsnr "#EC *

INTO lv_prsnr

FROM knvk

WHERE kunnr = lv_kunnr

AND abtnr = c_0009.

IF sy-subrc = 0.

CLEAR lv_addr.

SELECT SINGLE smtp_addr "#EC *

INTO lv_addr

FROM adr6

WHERE addrnumber = lv_adrnr

AND persnumber = lv_prsnr.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " get_emailaddress

&----


*& Form send_email

&----


  • text

----


  • -->P_LT_TLINE text

  • -->P_LV_ADDR text

----


FORM send_email TABLES P_LT_TLINE STRUCTURE tline

USING P_LV_ADDR.

CONSTANTS: c_raw TYPE so_obj_tp VALUE 'RAW',

c_pdf TYPE so_obj_tp VALUE 'PDF',

c_x TYPE c VALUE 'X'.

DATA: lv_lines TYPE i.

  • v1 TYPE i,

  • v2 TYPE i,

  • v3 TYPE i.

  • Internal table declarations

DATA: lt_otf TYPE TABLE OF itcoo WITH HEADER LINE, "#EC *

lt_tline TYPE TABLE OF tline WITH HEADER LINE, "#EC *

lt_record TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_doctab_archive TYPE TABLE OF docs WITH HEADER LINE."#EC *

  • Objects to send mail.

DATA: lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE, "For

"packing list for main document

lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE, "To hold the

"message body of the email

lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE, "To hold

"the attachment data text of the email

lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE. "For

"reciever information

  • Variables declaration

DATA: lv_binfile TYPE i. "#EC *

  • Work area declarations

DATA: ls_doc_chng TYPE sodocchgi1, "Structure to hold the

"attributes of new document

ls_buffer TYPE string. "To convert from 132 to 255

LOOP AT p_lt_tline.

TRANSLATE p_lt_tline USING '~'.

CONCATENATE ls_buffer p_lt_tline INTO ls_buffer.

ENDLOOP.

TRANSLATE ls_buffer USING '~'.

DO.

lt_record = ls_buffer.

APPEND lt_record.

SHIFT ls_buffer LEFT BY 255 PLACES.

IF ls_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

REFRESH: lt_reclist,

lt_objtxt,

lt_objbin,

lt_objpack.

lt_objbin[] = lt_record[].

lt_objtxt = TEXT-004.

APPEND lt_objtxt.

DESCRIBE TABLE lt_objtxt LINES lv_lines.

READ TABLE lt_objtxt INDEX lv_lines.

ls_doc_chng-obj_name = TEXT-004.

ls_doc_chng-obj_descr = TEXT-004.

ls_doc_chng-sensitivty = 'F'.

ls_doc_chng-doc_size = lv_lines * 255 .

CLEAR lt_objpack-transf_bin.

lt_objpack-head_start = 1.

lt_objpack-head_num = 0.

lt_objpack-body_start = 1.

lt_objpack-body_num = lv_lines.

lt_objpack-doc_type = c_raw.

lt_objpack-doc_size = ls_doc_chng-doc_size.

APPEND lt_objpack.

APPEND lt_objbin.

CLEAR lt_objbin.

DESCRIBE TABLE lt_objbin LINES lv_lines.

READ TABLE lt_objbin INDEX lv_lines.

lt_objpack-transf_bin = c_x.

lt_objpack-head_start = 1.

lt_objpack-head_num = 1.

lt_objpack-body_start = 1.

lt_objpack-body_num = lv_lines.

lt_objpack-doc_type = c_pdf.

lt_objpack-obj_name = 'text1'.

lt_objpack-obj_descr = TEXT-004.

*lt_objpack-doc_size = lv_lines * 255 + STRLEN( lt_objbin ).

lt_objpack-doc_size = lv_lines * 255.

APPEND lt_objpack.

lt_reclist-receiver = p_lv_addr.

lt_reclist-rec_type = 'U'.

lt_reclist-com_type = 'INT'.

lt_reclist-notif_del = c_x.

lt_reclist-notif_ndel = c_x.

APPEND lt_reclist.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1' "#EC *

EXPORTING

document_data = ls_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = lt_objpack

contents_bin = lt_objbin

contents_txt = lt_objtxt

receivers = lt_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.

ENDFORM. " send_email

Former Member
0 Kudos

On the first sight the problem might be here:

CALL FUNCTION lf_fm_name "#EC *
EXPORTING
archive_index = toa_dara
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

Actually You don't need any mail parameters here if You send mail later via FM. Try to comment them.

As offtopic: i would reccomend You to use another mailing method. In my opinion it's not so complicated. Read for further information:

Good Luck!

Former Member
0 Kudos

Hi,

Could you please tell me which part of the code I have to comment.

Former Member
0 Kudos

Sure

CALL FUNCTION lf_fm_name "#EC *
EXPORTING
archive_index = toa_dara
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

Former Member
0 Kudos

Hi,

I have commented that part of the code.But still it is sending mail with 2 copies

Former Member
0 Kudos

Ok then try this

CALL FUNCTION lf_fm_name "#EC *
EXPORTING
archive_index = toa_dara
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
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = repeat

    * importing document_output_info =

*Uncomented the line to get the spool id or OTF formatted data -
*NY047532
IMPORTING
document_output_info = document_output_info"HD2465697
job_output_info = w_job
job_output_options = job_output_options "HD2465697

    * NY047532

EXCEPTIONS formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

Former Member
0 Kudos

As i see you send messages either from FM where You create a smartform and from the Fm that sends mails. If my solution will not work try to comment Your mail sending procedure. What we will get - if after You comment the call of this procedure we still get 1 message - it means that FM that creates smartform sends it. If 0 messages - it means there is something wrong with FM that sends mails

Former Member
0 Kudos

Hi Andrei,

I have tried in all the ways.But still the smartform is sending mail with 2 copies.Could you please suggest me some other solution.

Former Member
0 Kudos

Strange....

Well as i said You can try this:

To determine which FM is sending mails You can for example comment the call of procedure which sends mail.

PERFORM send_email TABLES lt_tline USING lv_addr.

Possible variants:

a) there is no messages - it means that something wrong in form send_email.

b) 1 or 2 messages the problem is in the creating of the smartform

Actually after you have commented those lines (which i mentioned in previous messages) i can make conclusion that something wrong with the form send_email. Please try to do this actions in any case to be sure. And also while debugging try to watch the table with names may be there is more than one name.

Former Member
0 Kudos

Also in send_emails table lt_objpack has two records is it nessesary? try to check coding in this form step by step.

Former Member
0 Kudos

Hi,

lt_objpack should have 2 records.One for raw data and the other for PDF data.

Former Member
0 Kudos

Here is my code. Everything is working well. Sends only one message. May be something wrong in smtp settings? Write test program or contact Your basis specialist.

FORM DISP_SMART_2 .
  DATA: g_output type ssfcompop,
        g_cont_par type ssfctrlop.
  g_cont_par-device = 'MAIL'.


  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           = 'Z_ALV_SMF'
    IMPORTING
      fm_name            = func_mod_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 func_mod_name
    EXPORTING
      CONTROL_PARAMETERS = W_CTRLOP
      OUTPUT_OPTIONS     = W_COMPOP
      USER_SETTINGS      = 'X'
      iv_werks           = pa_werks
      iv_datum           = '01.01.2001'
    IMPORTING
      JOB_OUTPUT_INFO    = W_RETURN
    TABLES
      im_matnr           = gt_matnr
    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.
  PERFORM translate_to_code_page  CHANGING I_TLINE.
* 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 = 'mailadress'.
  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.
ENDFORM.

Former Member
0 Kudos

Hi,

I have checked every line of my code with yours.Everything is same.Could you please tell me how to check the smtp settings?

Former Member
0 Kudos

As i said basis specialist should handle this. I gathered my information from this blog:

But somehow it's not your case. Try to find something on help.sap.com.

Former Member
0 Kudos

Here i found a standart SAP program with same FM - SCMAMAIL try to run it and see the result.

Former Member
0 Kudos

Hi,

please refer the below sample code which iwll send smartfrom output through mail.

&----


*& Report YSMARTFORM_EMAIL

*&

&----


*&

*&

&----


REPORT YSMARTFORM_EMAIL.

TABLES: VBAK.

************************************************************************

  • Constants *

************************************************************************

CONSTANTS:

C_X TYPE C VALUE 'X', " Value X

C_0 TYPE C VALUE '0', " Value 0

C_1 TYPE C VALUE '1'. " Value 1

************************************************************************

  • Work Variables declaration *

************************************************************************

DATA:

W_UCOMM LIKE SY-UCOMM, " Function code

W_TABLN TYPE I, " Lines

W_LINE TYPE SO_TEXT255, " Line of text

W_EADDR(60) TYPE C. " FieldLength for Email

DATA: VBAP_TAB LIKE VBAP OCCURS 0 WITH HEADER LINE.

DATA: W_FUNMOD TYPE RS38L_FNAM.

  • Structure to hold the Attributes of new Document

DATA: FS_DOCDATA TYPE SODOCCHGI1.

  • Internal table for storing OTF data form Smart-Form

DATA: BEGIN OF FS_OTF_DATA.

INCLUDE STRUCTURE ITCOO.

DATA: END OF FS_OTF_DATA,

T_OTF_DATA LIKE STANDARD TABLE OF FS_OTF_DATA.

  • Internal table for storing PDF data form Smart-Form

DATA: BEGIN OF FS_PDF_DATA.

INCLUDE STRUCTURE TLINE.

DATA: END OF FS_PDF_DATA,

T_PDF_DATA LIKE STANDARD TABLE OF FS_PDF_DATA.

  • Internal table to hold the attachment data text of the email

DATA: BEGIN OF FS_ATTACH_DATA.

INCLUDE STRUCTURE SOLISTI1.

DATA: END OF FS_ATTACH_DATA,

T_ATTACH_DATA LIKE STANDARD TABLE OF FS_ATTACH_DATA.

  • Internal table to hold Message body of the email

DATA: BEGIN OF FS_MESSBODY.

INCLUDE STRUCTURE SOLISTI1.

DATA: END OF FS_MESSBODY,

T_MESSBODY LIKE STANDARD TABLE OF FS_MESSBODY.

  • Internal table for packing list for main document

DATA: BEGIN OF FS_OBJPACK.

INCLUDE STRUCTURE SOPCKLSTI1.

DATA: END OF FS_OBJPACK,

T_OBJPACK LIKE STANDARD TABLE OF FS_OBJPACK.

  • Internal table for header text of the attachment

DATA: BEGIN OF FS_OBJHEAD.

INCLUDE STRUCTURE SOLISTI1.

DATA: END OF FS_OBJHEAD,

T_OBJHEAD LIKE STANDARD TABLE OF FS_OBJHEAD.

  • Internal table receiver information

DATA: BEGIN OF FS_RECEIVER.

INCLUDE STRUCTURE SOMLRECI1.

DATA: END OF FS_RECEIVER,

T_RECEIVER LIKE STANDARD TABLE OF FS_RECEIVER.

*Internal table to store data upto 255 lines

DATA: BEGIN OF FS_OBJCONT.

INCLUDE STRUCTURE SOLI.

DATA: END OF FS_OBJCONT,

T_OBJCONT LIKE STANDARD TABLE OF FS_OBJCONT.

*DATA : P_VBELN LIKE VBAK-VBELN.

DATA: P_EADDR(60) TYPE C

VALUE 'write emailid'.

PARAMETERS : P_VBELN LIKE VBAK-VBELN.

*PARAMETERS:

  • P_EADDR(60) TYPE C. " Email address

SELECT SINGLE *

FROM VBAK

WHERE VBELN EQ P_VBELN.

SELECT *

FROM VBAP

INTO TABLE VBAP_TAB

WHERE VBELN EQ P_VBELN.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'YSMARTFORM_EMAIL'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

FM_NAME = W_FUNMOD

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

OTHERS = 3 .

IF SY-SUBRC <> 0.

  • Do nothing

ENDIF.

DATA: FS_CONT_PARM TYPE SSFCTRLOP,

T_JOB_INFO TYPE SSFCRESCL.

CLEAR FS_CONT_PARM.

FS_CONT_PARM-GETOTF = 'X'.

FS_CONT_PARM-NO_DIALOG = 'X'.

FS_CONT_PARM-PREVIEW = ''.

CALL FUNCTION W_FUNMOD

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

CONTROL_PARAMETERS = FS_CONT_PARM

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • OUTPUT_OPTIONS =

  • USER_SETTINGS = 'X'

VBAK = VBAK

IMPORTING

    • DOCUMENT_OUTPUT_INFO =

JOB_OUTPUT_INFO = T_JOB_INFO

    • JOB_OUTPUT_OPTIONS =

TABLES

VBAP = VBAP_TAB

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.

PERFORM CONVERT_OTF_TO_PDF.

&----


*& Form convert_otf_to_pdf

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CONVERT_OTF_TO_PDF .

DATA: LV_BYTES TYPE P.

IF FS_CONT_PARM-GETOTF EQ 'X'.

REFRESH T_OTF_DATA.

CLEAR FS_OTF_DATA.

LOOP AT T_JOB_INFO-OTFDATA INTO FS_OTF_DATA.

APPEND FS_OTF_DATA TO T_OTF_DATA.

CLEAR FS_OTF_DATA.

ENDLOOP. " LOOP AT t_outtab-otfdata

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 255

IMPORTING

BIN_FILESIZE = LV_BYTES

TABLES

OTF = T_OTF_DATA

LINES = T_PDF_DATA

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

IF SY-SUBRC EQ 0 AND LV_BYTES IS NOT INITIAL.

PERFORM TABLE_SHIFT.

  • To send the output by email

PERFORM SET_UP_EMAIL.

PERFORM SEND_MAIL.

ENDIF. " IF sy-subrc EQ space.

ENDIF. " IF gs_control_pars-getotf

ENDFORM. " convert_otf_to_pdf

----


  • Form set_up_email *

----


  • This subroutine is used to set mail attributes *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM SET_UP_EMAIL .

  • To setup attributes of the document

PERFORM SET_EMAIL_HEADER.

  • To set body of email

PERFORM SET_EMAILBODY.

  • To convert output table data with tab delimiter

PERFORM PREPARE_OUTPUT_DATA_FOR_ATTACH.

  • To set the Receipents

PERFORM SET_RECEIPENTS.

ENDFORM. " Set_up_email

----


  • Form set_email_header *

----


  • This subroutine is used to Setup the attributes of the Document *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM SET_EMAIL_HEADER.

CONSTANTS :

LC_P TYPE C VALUE 'P', " Production system name

LC_F TYPE C VALUE 'F', " Sensitivity

LC_OBJNAME(6) TYPE C " Object name

VALUE 'SAPRPT'.

CLEAR FS_DOCDATA.

  • Populate the subject/generic message attributes

FS_DOCDATA-DOC_SIZE = 1.

FS_DOCDATA-OBJ_LANGU = SY-LANGU.

FS_DOCDATA-OBJ_NAME = LC_OBJNAME.

FS_DOCDATA-SENSITIVTY = LC_F.

IF SY-SYSID+0(1) NE LC_P.

CONCATENATE 'Test mail'(003)

'Sales Order Details'(002)

INTO FS_DOCDATA-OBJ_DESCR

SEPARATED BY SPACE.

ELSE.

MOVE TEXT-002 TO FS_DOCDATA-OBJ_DESCR.

ENDIF. " IF sy-sysid+0(1)...

ENDFORM. " Set_email_header

----


  • Form set_emailbody *

----


  • This subroutine is used to set body of an email *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM SET_EMAILBODY.

CONSTANTS:

LC_DOC_TYPE(3) TYPE C VALUE 'RAW'. " Document type

REFRESH : T_OBJPACK,

T_MESSBODY.

CLEAR : FS_OBJPACK,

FS_MESSBODY.

MOVE:

'Hi,'(004) TO FS_MESSBODY-LINE.

APPEND FS_MESSBODY TO T_MESSBODY.

CLEAR FS_MESSBODY.

MOVE:

  • 'The attachment contains sales order details.'(005)

'www.google.com'

TO FS_MESSBODY-LINE.

APPEND FS_MESSBODY TO T_MESSBODY.

CLEAR W_TABLN.

DESCRIBE TABLE T_MESSBODY LINES W_TABLN.

CLEAR FS_MESSBODY.

READ TABLE T_MESSBODY INTO FS_MESSBODY INDEX W_TABLN.

FS_DOCDATA-DOC_SIZE = ( W_TABLN - 1 ) * 255 + STRLEN( W_LINE ).

MOVE:

SPACE TO FS_OBJPACK-TRANSF_BIN,

C_1 TO FS_OBJPACK-HEAD_START,

C_0 TO FS_OBJPACK-HEAD_NUM,

C_1 TO FS_OBJPACK-BODY_START,

W_TABLN TO FS_OBJPACK-BODY_NUM,

LC_DOC_TYPE TO FS_OBJPACK-DOC_TYPE.

APPEND FS_OBJPACK TO T_OBJPACK.

ENDFORM. " Set_emailbody

----


  • Form prepare_output_data_for_attach *

----


  • To convert the output table data with comma delimiter *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM PREPARE_OUTPUT_DATA_FOR_ATTACH.

CONSTANTS:

LC_DOC_TYPE(3) TYPE C VALUE 'PDF', " Document type

LC_OBJNAME(6) TYPE C VALUE 'SAPRPT'. " Object name

REFRESH T_OBJHEAD.

REFRESH T_ATTACH_DATA[].

CLEAR FS_ATTACH_DATA.

T_ATTACH_DATA[] = T_OBJCONT[].

DESCRIBE TABLE T_ATTACH_DATA LINES W_TABLN.

FS_DOCDATA-DOC_SIZE = ( W_TABLN - 1 ) * 255 + STRLEN( W_LINE ).

FS_OBJPACK-BODY_NUM = W_TABLN.

FS_OBJPACK-DOC_SIZE = W_TABLN * 255.

FS_OBJPACK-TRANSF_BIN = C_X.

FS_OBJPACK-HEAD_START = C_1.

FS_OBJPACK-HEAD_NUM = C_1.

FS_OBJPACK-BODY_START = C_1.

FS_OBJPACK-DOC_TYPE = LC_DOC_TYPE.

FS_OBJPACK-OBJ_NAME = 'Attachment'.

FS_OBJPACK-OBJ_DESCR = 'Sales Order Details.PDF'(007).

APPEND FS_OBJPACK TO T_OBJPACK.

ENDFORM. " Prepare_output_data_for_attach

----


  • Form set_receipents *

----


  • This subroutine is used to set the Receipents *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM SET_RECEIPENTS .

CONSTANTS

LC_REC_TYPE TYPE C VALUE 'U'. " Receipent type

REFRESH T_RECEIVER.

IF P_EADDR IS NOT INITIAL.

MOVE:

P_EADDR TO FS_RECEIVER-RECEIVER,

LC_REC_TYPE TO FS_RECEIVER-REC_TYPE.

APPEND FS_RECEIVER TO T_RECEIVER.

ENDIF. " IF P_EMAIL IS NOT.....

ENDFORM. " Set_receipents

----


  • Form send_mail *

----


  • This subroutine is used to send output by email *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM SEND_MAIL.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = FS_DOCDATA

PUT_IN_OUTBOX = C_X

  • SENDER_ADDRESS = SY-UNAME

  • SENDER_ADDRESS_TYPE = 'B'

COMMIT_WORK = C_X

TABLES

PACKING_LIST = T_OBJPACK

OBJECT_HEADER = T_OBJHEAD

CONTENTS_BIN = T_ATTACH_DATA

CONTENTS_TXT = T_MESSBODY

RECEIVERS = T_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 NE 0.

MESSAGE I007(CLAIM).

ELSE.

MESSAGE S592(EI).

ENDIF. " IF sy-subrc NE 0.

ENDFORM. " Send_mail

&----


*& Form table_shift

&----


  • The PDF file that is generated out of the above function module

  • cannot be transported as it needs to be of 255 chars.Hence

  • converting the file to get a 255 char single line,internal table.

----


*There are no interface parameters to be passed to this subroutine

----


FORM TABLE_SHIFT .

CONSTANTS:

CNV_HEXCONST_ZERO TYPE X VALUE '00'.

DATA:

LV_BIG_LINES(268) TYPE C

OCCURS 0 WITH HEADER LINE.

DATA:

LFL_FLAG TYPE C,

LV_LEFT_T(268) TYPE C,

LV_LEFT_I TYPE I,

TV_LEFT_I TYPE I,

LV_CURR_I TYPE I.

FIELD-SYMBOLS: <F>.

  • Get the lines into a table of 268 char as the first step to put it in

  • the pdf file of 255 chars

CLEAR LFL_FLAG.

LOOP AT T_PDF_DATA INTO FS_PDF_DATA.

IF LFL_FLAG EQ ' '.

CLEAR LV_BIG_LINES WITH CNV_HEXCONST_ZERO.

ASSIGN LV_BIG_LINES(134) TO <F>.

<F> = FS_PDF_DATA.

LFL_FLAG = 'X'.

ELSE.

LV_BIG_LINES+134 = FS_PDF_DATA.

APPEND LV_BIG_LINES.

CLEAR: LFL_FLAG.

ENDIF. " If lfl_flag = ''..

ENDLOOP. " Loop at t_pdf

IF LFL_FLAG EQ 'X'.

APPEND LV_BIG_LINES.

ENDIF. " If lflf_flag eq 'X'..

  • Next fill it into a 255 char table

CLEAR: LV_LEFT_T, LV_LEFT_I, TV_LEFT_I.

LV_CURR_I = 255.

LOOP AT LV_BIG_LINES.

IF LV_LEFT_I NE 0.

IF LV_CURR_I NE 0.

FS_OBJCONT(LV_LEFT_I) = LV_LEFT_T(LV_LEFT_I).

FS_OBJCONT+LV_LEFT_I(LV_CURR_I) = LV_BIG_LINES(LV_CURR_I).

ELSE.

FS_OBJCONT = LV_LEFT_T(LV_LEFT_I).

ENDIF. " IF lv_curr_i NE 0

ELSE.

FS_OBJCONT = LV_BIG_LINES(LV_CURR_I).

ENDIF. " IF lv_left_i NE 0

APPEND FS_OBJCONT TO T_OBJCONT.

TV_LEFT_I = 268 - LV_CURR_I.

IF TV_LEFT_I > 255.

FS_OBJCONT = LV_BIG_LINES+LV_CURR_I(255).

APPEND FS_OBJCONT TO T_OBJCONT.

LV_LEFT_I = TV_LEFT_I - 255.

TV_LEFT_I = 255 + LV_CURR_I.

LV_CURR_I = 255 - LV_LEFT_I.

LV_LEFT_T = LV_BIG_LINES+TV_LEFT_I.

ELSE.

LV_LEFT_T = LV_BIG_LINES+LV_CURR_I.

LV_LEFT_I = 268 - LV_CURR_I.

LV_CURR_I = 255 - LV_LEFT_I.

ENDIF. " IF tv_left_i > 255

ENDLOOP. " LOOP AT lv_big_lines.

CLEAR FS_OBJCONT WITH CNV_HEXCONST_ZERO.

ASSIGN FS_OBJCONT(LV_LEFT_I) TO <F>.

<F> = LV_LEFT_T(LV_LEFT_I).

APPEND FS_OBJCONT TO T_OBJCONT.

ENDFORM. " Table_shift