cancel
Showing results for 
Search instead for 
Did you mean: 

Get OTF from Smartform and send PDF by e-mail

Former Member
0 Kudos

Hi,

I created a Smartform and it works ok. Now I'm on the task of sending the printing by e-mail in PDF format. The result I get in the e-mail is an OTF document that displays correctly inside sap message system (SOST). Why this code is not converting to PDF? Z_SENDMAIL_PDF FM works fine with other smartforms and packs necessary functions like SO_DOCUMENT_SEND_API1.

Anyone could help?

*&---------------------------------------------------------------------*

*& Report

*& Smartform Pickup Order

*&---------------------------------------------------------------------*

REPORT  z35pr011.

TABLES: nast,

                  ekko.

DATA: fm_name TYPE rs38l_fnam.

DATA: control TYPE ssfctrlop,

            output  TYPE ssfcompop,

            email.

DATA: l_ebeln  LIKE ekko-ebeln.

* t_otf     TYPE tsfotf.

  DATA:  tso_smtp  LIKE ztso_smtp OCCURS 0 WITH HEADER LINE,     

               wa_info    TYPE ssfcrescl,

               it_otfdata  LIKE itcoo OCCURS 0 WITH HEADER LINE,

               lv_langu   TYPE spras.

&---------------------------------------------------------------------*

*&      Form  ENTRY

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM entry USING return_code

                 p_mail TYPE xfeld

                 us_screen.

REFRESH it_otfdata.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

      formname                 = 'Z35PR004'

*   VARIANT                  = ' '

*   DIRECT_CALL              = ' '

   IMPORTING

      fm_name                  = fm_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.

l_ebeln = nast-objky.

control-langu = nast-spras.

* If calling from entry_mail

  IF p_mail = 'X'.

    control-getotf = 'X'.

    control-no_dialog   = 'X'.

    output-tdnoprev = 'X'.

  ENDIF.

   CALL FUNCTION fm_name

    EXPORTING

*     ARCHIVE_INDEX              =

*     ARCHIVE_INDEX_TAB          =

*     ARCHIVE_PARAMETERS         =

      CONTROL_PARAMETERS         = control

*     MAIL_APPL_OBJ              =

*     MAIL_RECIPIENT             =

*     MAIL_SENDER                =

      OUTPUT_OPTIONS             = output

      USER_SETTINGS              = space

      i_ebeln                    = l_ebeln

   IMPORTING

*     DOCUMENT_OUTPUT_INFO       =

      job_output_info            = wa_info

*     JOB_OUTPUT_OPTIONS         =

   EXCEPTIONS

      formatting_error           = 1

      internal_error             = 2

      send_error                 = 3

      user_canceled              = 4

      others                     = 5.

  IF sy-subrc <> 0.

    return_code = sy-subrc.

  ELSE.

    APPEND LINES OF wa_info-otfdata TO it_otfdata.

  ENDIF.

ENDFORM.        " ENTRY

*----------------------------------------------------------------------*

* ENTRY by e-mail                                                              *

* Entry by e-mail message control   .                              *

*----------------------------------------------------------------------*

FORM entry_mail USING return_code us_screen.

DATA: p_mail TYPE xfeld.

CLEAR return_code.

l_ebeln = nast-objky.

* List of e-mail addresses to send.

  PERFORM destinatarios_email TABLES tso_smtp

                              USING l_ebeln

                              CHANGING lv_langu.

p_mail = 'X'.

* Get smartform data in JOB_OUTPUT_INFO

  PERFORM entry USING return_code

                      p_mail

                      us_screen.

* Call FM Z in order to send e-mail in PDF

  PERFORM envio_email USING l_ebeln.

ENDFORM.                    "entry_mail

*----------------------------------------------------------------------*

* destinatarios_email

* Get e-mail recipients.                                                *

*----------------------------------------------------------------------*

FORM destinatarios_email TABLES tso_smtp STRUCTURE ztso_smtp

                         USING l_ebeln

                         CHANGING lv_langu.

  DATA: respuesta(1) TYPE c,

        dp           LIKE ekpa-lifn2,

        _lifn2       LIKE ekpa-lifn2,

        lv_addr      LIKE adr6-smtp_addr.

* Buscamos las direcciones email.

* Habrá que cambiar para que funcione con compras

* Pasos a seguir:

* 1. Coger proveedor de pedido de compras ekko-lifnr

* 2. Buscar las funciones de interlocutor de ese proveedor

* 3. Elegir la DP, siempre empiezan por P

* 4. Buscar el proveedor DP en el maestro de proveedores

* 5. Para ese proveedor (DP) buscar sus direcciones de email

* 6. Añadir en la lista de correos a enviar el del usuario ekko-ernam

  SELECT SINGLE lifn2

  INTO _lifn2

  FROM ekpa

  WHERE ebeln EQ l_ebeln AND

        parvw EQ 'BA'.

  IF sy-subrc <> 0.

    SELECT SINGLE lifn2

    INTO _lifn2

    FROM ekpa

    WHERE ebeln EQ l_ebeln.

  ENDIF.

  dp = _lifn2.

* Info from the master record

  SELECT adr6~smtp_addr

    INTO TABLE tso_smtp

    FROM lfa1 JOIN adr6

      ON lfa1~adrnr EQ adr6~addrnumber

  WHERE  lfa1~lifnr EQ dp.

  SELECT SINGLE spras

    INTO lv_langu

    FROM lfa1

  WHERE  lifnr EQ dp.

* Get mail address from user data

  SELECT SINGLE a~smtp_addr

    INTO lv_addr

    FROM usr21 AS u

    INNER JOIN adr6 AS a

    ON u~persnumber = a~persnumber

    AND u~addrnumber = a~addrnumber

    WHERE u~bname = ekko-ernam.

  IF sy-subrc = 0.

    tso_smtp = lv_addr.

  ELSE.

    CONCATENATE ekko-ernam '@domain.com' INTO tso_smtp.

  ENDIF.

  APPEND tso_smtp.

* Info from the purchase order header

  SELECT adr6~smtp_addr

  APPENDING TABLE tso_smtp

    FROM adr6

  WHERE addrnumber EQ ekko-adrnr.

  SORT tso_smtp.

  DELETE ADJACENT DUPLICATES FROM tso_smtp.

* En tabla tso_smtp se tienen los emails a enviar

* Que al menos haya algun destinatario.

IF NOT tso_smtp[] IS INITIAL.

* Antes de enviar los mails se le pregunta al usuario si las direcciones

* de correo son las correctas.

    LOOP AT tso_smtp.

      CALL FUNCTION 'FITP_POPUP_TO_CONFIRM'

        EXPORTING

          titlebar              = text-990

          text_question         = tso_smtp-so_smtp

          text_button_1         = text-991

          text_button_2         = text-992

          default_button        = '1'

          display_cancel_button = '-'

        IMPORTING

          answer                = respuesta.

      IF sy-subrc <> 0.

      ENDIF.

* Si pinchamos en no enviar lo borramos de la lista

      IF respuesta = 'N' OR respuesta = 'A'.

        DELETE tso_smtp.

        CLEAR tso_smtp.

      ENDIF.

    ENDLOOP.

  ENDIF.

ENDFORM.                    " destinatarios_email

*&---------------------------------------------------------------------*

*&      Form  send_mail

*&---------------------------------------------------------------------*

FORM send_mail USING l_vbeln.

  CHECK NOT tso_smtp[] IS INITIAL.

  DATA: l_title TYPE syprtxt.

  CONCATENATE text-001 l_vbeln INTO output-tdtitle

              SEPARATED BY SPACE.

  l_title = output-tdtitle.

   CALL FUNCTION 'Z_SENDMAIL_PDF'

    EXPORTING

      titulo   = l_title

    TABLES

      tso_smtp = tso_smtp

      otfdata  = it_otfdata

    EXCEPTIONS

      OTHERS   = 1.

 

ENDFORM.                    " envio_email

Accepted Solutions (0)

Answers (3)

Answers (3)

uppu_narayan
Active Participant
0 Kudos

Hi Salvador,

   Following thread can be useful,

http://wiki.sdn.sap.com/wiki/display/Snippets/Smartform+to+Mail+as+PDF+attachment,

you got to use CONVERT_OTF function module to convert your otf data to pdf data and pass this while sending mail..........

thanks and regards,

narayan

aidan_black
Active Contributor
0 Kudos

Hi,

For the OTF data returned from the Smart Form function module, you can use the function module CONVERT_OTF to convert this OTF data to PDF. You should use the parameter BIN_FILE when calling

CONVERT_OTF so the PDF data is returned as type XSTRING.

See SAP notes 1320163 and 1324547 about this. See also the example program BCS_EXAMPLE_8(in note 1324547) to handle the PDF data returned and send as a email.

Regards,
Aidan

eduardo_hinojosa
Active Contributor
0 Kudos

Hola Salvador,

I haven't read in your coding the function module 'CONVERT_OTF_2_PDF' used to convert the OTF to PDF. Set it after calling the function module creates the smartform (call function fm_name). For sending the email try with function module SO_NEW_DOCUMENT_ATT_SEND_API1.

I hope this helps you

Regards

Eduardo