cancel
Showing results for 
Search instead for 
Did you mean: 

PO Smartform as mail attachment

Former Member
0 Kudos

Hi All,

We would like to send PO smartform to the Buyer as mail attachment at the time of releasing PO. User can release PO using ME29N as well as ME28 transaction codes. We tried BADi ME_PROCESS_PO_CUST but it is getting called only when user releases PO using ME29N Tcode. Is there any configuration for directly sending the smartform as pdf attachment through mail?

Regards,

Sibin

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

hi,

  Use this code format.  reward if helpful. Thank you.


* Need for the macro to build Mail_Appl_Obj.
INCLUDE <cntn01>.

DATA : w_formname        TYPE tdsfname ,
        w_funcname        TYPE tdsfname ,
        w_borkey          TYPE swo_typeid ,
        w_year            TYPE so_doc_yr ,
        w_number          TYPE so_doc_no ,

        is_control_param  TYPE ssfctrlop ,
        is_params         TYPE pri_params ,
        is_recipient      TYPE swotobjid ,
        is_sender         TYPE swotobjid ,
        is_mailobj        TYPE swotobjid ,
        is_folder         TYPE swc_object ,
        is_sofmk          TYPE sofmk .

START-OF-SELECTION.


* My Smartforms.
   MOVE 'ZMY_SMARTFORMS' TO w_formname.


* Get the function module name corresponding of the Smartform.
   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
     EXPORTING
       formname = w_formname
     IMPORTING
       fm_name  = w_funcname
     EXCEPTIONS
       OTHERS  = 3.
   CHECK sy-subrc EQ space.


* Set the parameters of the forms.
   MOVE : 'X'            TO is_control_param-no_dialog ,
          ' '            TO is_control_param-preview ,
          ' '            TO is_control_param-getotf ,
          sy-langu        TO is_control_param-langu ,
          'MAIL'          TO is_control_param-device.

* Create the Recipient.
   CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
     EXPORTING
       ip_mailaddr       = 'frederic.girod@everywhere.com'
     IMPORTING
       ep_recipient_id   = is_recipient
     EXCEPTIONS
       invalid_recipient = 1
       OTHERS            = 2.

* Create the Sender
   CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
     EXPORTING
       ip_sender      = sy-uname
     IMPORTING
       ep_sender_id   = is_sender
     EXCEPTIONS
       invalid_sender = 1
       OTHERS        = 2.

* Create the Mail Obj.
   SELECT SINGLE inbyr inbno
          INTO (w_year, w_number)
          FROM soud
          WHERE sapnam EQ sy-uname.
   CHECK sy-subrc EQ space.
   MOVE : 'FOL'    TO is_sofmk-doctp ,
          w_number TO is_sofmk-docyr ,
          w_year   TO is_sofmk-docno .
   MOVE is_sofmk TO w_borkey.
   swc_create_object is_folder 'SOFMFOL' w_borkey.
   swc_object_to_persistent is_folder is_mailobj.

   CALL FUNCTION w_funcname
     EXPORTING
*     ARCHIVE_INDEX              =
*     ARCHIVE_INDEX_TAB          =
*     ARCHIVE_PARAMETERS         =
       control_parameters         = is_control_param
       mail_appl_obj              = is_mailobj
       mail_recipient             = is_recipient
       mail_sender                = is_sender
*     output_options             =
       user_settings              = ' '
*   IMPORTING
*     DOCUMENT_OUTPUT_INFO       =
*     JOB_OUTPUT_INFO            =
*     JOB_OUTPUT_OPTIONS         =
     EXCEPTIONS
       formatting_error           = 1
       internal_error             = 2
       send_error                 = 3
       user_canceled              = 4
       OTHERS                    = 5.

   IF sy-subrc EQ space.
     COMMIT WORK AND WAIT.
   ENDIF.

END-OF-SELECTION.

Thanks,

Samir


Former Member
0 Kudos

Hi Sibin,

No need to write code  in user exit. Please check with your ABAPer and do some changes in your custom driver program for smartforms.

when you call your smartform through driver program then you can add some code before calling smartform.

Please see the below code for MAIL  activation .

lf_formname = tnapr-sform.
  IF cf_retcode = 0.
    IF wa_ekko-frgke = 'R' OR wa_ekko-frgke = ' '.
      CASE nast-nacha.
        WHEN '5'.
          DATA:  lvs_comm_type     TYPE   ad_comm,
                 lvs_comm_values   TYPE   szadr_comm_values.
          IF ent_screen NE 'X'.
            READ TABLE it_lfa1 INTO ls_lfa1 INDEX 1.
            CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'
              EXPORTING
               strategy                 = 'CS01'
*   ADDRESS_TYPE             =
                address_number           = ls_lfa1-adrnr
*   PERSON_NUMBER            =
*   IV_SEARCH_TIME           = ' '
             IMPORTING
               comm_type                = lvs_comm_type
               comm_values              = lvs_comm_values
*   UNDELIVER                =
* TABLES
*   STRATEGY_TABLE           =
             EXCEPTIONS
               address_not_exist        = 1
               person_not_exist         = 2
               no_comm_type_found       = 3
               internal_error           = 4
               parameter_error          = 5
               OTHERS                   = 6
                      .
            IF sy-subrc <> 0.
* Implement suitable error handling here
            ENDIF.

* Convert communication data
            MOVE-CORRESPONDING nast TO gs_intnast.
            MOVE sy-repid           TO gv_xprogramm.
            CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'
              EXPORTING
                pi_comm_type              = lvs_comm_type
                pi_comm_values            = lvs_comm_values
                pi_country                = 'CN'
                pi_repid                  = gv_xprogramm
                pi_snast                  = gs_intnast
              IMPORTING
                pe_itcpo                  = ls_itcpo
                pe_device                 = gv_xdevice
                pe_mail_recipient         = ls_recipient
                pe_mail_sender            = ls_sender
              EXCEPTIONS
                comm_type_not_supported   = 1
                recipient_creation_failed = 2
                sender_creation_failed    = 3
                OTHERS                    = 4.
            IF sy-subrc <> 0.
              IF 1 = 2.
                MESSAGE s740(me).
              ENDIF.
              EXIT.
            ENDIF.

            IF gv_xdevice = 'MAIL'.
              CALL FUNCTION 'SX_ADDRESS_TO_DEVTYPE'
                EXPORTING
                  recipient_id      = ls_recipient
                  sender_id         = ls_sender
                EXCEPTIONS
                  err_invalid_route = 1
                  err_system        = 2
                  OTHERS            = 3.
              IF sy-subrc <> 0.
                EXIT.
              ENDIF.
            ENDIF.
            ls_control_param-device = 'MAIL'.
            ls_control_param-langu  = 'A'.
            ls_control_param-getotf = ''.
            ls_control_param-preview = ''.

            CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
              EXPORTING
                ip_sender      = sy-uname
              IMPORTING
                ep_sender_id   = ls_sender
              EXCEPTIONS
                invalid_sender = 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.
            SELECT SINGLE  * FROM soud INTO ls_soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
            IF sy-subrc NE 0.
              CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT'
                EXPORTING
                  sapname        = sy-uname
                EXCEPTIONS
                  no_insert      = 1
                  sap_name_exist = 2
                  x_error        = 3
                  OTHERS         = 4.
              IF sy-subrc NE 0.
                CLEAR ls_soud.
              ELSE.
                SELECT SINGLE * FROM soud INTO ls_soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
              ENDIF.
            ENDIF.

            CLEAR sofmfol_key.
            sofmfol_key-type   = 'FOL'.
            sofmfol_key-year   = ls_soud-inbyr.
            sofmfol_key-number = ls_soud-inbno.
            bor_key = sofmfol_key.
            IF NOT bor_key IS INITIAL.
              swc_create_object folder 'SOFMFOL' bor_key.
              IF sy-subrc = 0.

                swc_object_to_persistent folder g_mail_app_obj.
                IF sy-subrc NE 0.
                  CLEAR g_mail_app_obj.
                ENDIF.
              ENDIF.
            ELSE.
              CLEAR g_mail_app_obj.
            ENDIF.
        
        WHEN OTHERS.
         
      ENDCASE.
      IF nast-nacha NE 1.
        MOVE-CORRESPONDING ls_itcpo TO ls_composer_param.
      ENDIF.
*--Determine smartform function module for invoice
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = lf_formname
        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.
*End of changes
  ENDIF.
  IF cf_retcode = 0.
    PERFORM check_repeat.
    IF nast-kschl+2(1) = '0'.
      CLEAR repeat.
    ELSE.
      repeat = 'x'.
    ENDIF.
    IF ls_composer_param-tdcopies EQ 0.
      nast_anzal = 1.
    ELSE.
      nast_anzal = ls_composer_param-tdcopies.
    ENDIF.
    DO nast_anzal TIMES.
      IF sy-index NE 1 AND repeat IS INITIAL.
        repeat = 'x'.
      ENDIF.

      CALL FUNCTION lf_fm_name
        EXPORTING
          archive_index      = toa_dara
          archive_parameters = arc_params
          control_parameters = ls_control_param
          mail_recipient     = ls_recipient
          mail_sender        = ls_sender
          mail_appl_obj      = g_mail_app_obj
          output_options     = ls_composer_param
          user_settings      = space
          is_nast            = nast
          is_repeat          = repeat
        IMPORTING
          job_output_info    = job_output_info
        TABLES
          it_ekko            = it_ekko
          it_ekpo            = it_ekpo
          it_t001w           = it_t001w
          it_lfa1            = it_lfa1
          it_adrc            = it_adrc
          it_adr6            = it_adr6
          it_konv            = it_konv
          it_makt            = it_makt
          it_tline           = it_tline
          it_tline1          = it_tline1
          it_tline2          = it_tline2
        EXCEPTIONS
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4
          OTHERS             = 5.
      IF sy-subrc <> 0.
*--Error handling
        cf_retcode = sy-subrc.
        PERFORM protocol_update.
      Endif.

I was used in my previous project and its working fine .

Thanks,

Prasenjit Mishra

Former Member
0 Kudos

We want to send this smartform attachment at the time of releasing PO. Driver program is called only when we press PO Print preview button. For this reason only we are using user exit to call smartform. Do we need to copy driver program into this user exit and do the coding here to send email?

Regards,

Sibin

Former Member
0 Kudos


Hi Sibin,

  If PO output trigger configuration completed as a E-Mail from NACE and output procedure having correct configuration then my logic only send mail when PO release manually or automatically.

Before PO release you can see PO Print Preview but output not send as a attachement but when PO is rleased from system then Mail trigger and your mail should be come in SOST tcode.

you can check SOST log details and In production you can set job for SOST then it will be automatically trigger otherwise you can do the manually.

Thanks,

Prasenjit Mishra

Former Member
0 Kudos

In user exit EXIT_SAPMM06E_013 we have called driver program functions to call PO smartform.

CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'

     EXPORTING

       IX_NAST        = IV_NAST

       IX_SCREEN      = ENT_SCREEN

     IMPORTING

       EX_RETCO       = ENT_RETCO

       EX_NAST        = L_NAST

       DOC            = L_DOC

     CHANGING

       CX_DRUVO       = IV_DRUVO

       CX_FROM_MEMORY = L_FROM_MEMORY.

   CHECK ENT_RETCO EQ 0.


After executing above function, we are getting following error message:


Type conflict when calling a function module.

The function module interface allows you to specify only

fields of a particular type under "DOC".

The field "L_DOC" specified here is a different

field type

The same code snippet is working fine in test server, but when we execute this in DEV client, we are getting this error:

we have declared l_doc as follows:

DATA:L_DOC   TYPE MEEIN_PURCHASE_DOC_PRINT

Florian
Active Contributor
0 Kudos

Just check on the parameter in the function stone to the structure you used for declaring the import-parameter.

~Florian

Former Member
0 Kudos

Using user exit EXIT_SAPMM06E_013, final release is not getting updated ie. tables CDPOS and CDHDR values are not getting updated. We want to capture release id from these tables at the time of releasing PO. Rest of the things are working fine. Is there any other user exit which gets called after final release of PO?

Regards,

Sibin

Florian
Active Contributor
0 Kudos

Hi sibin,

because you are really using the user-exit for a reason I think your only solution will be to assign the necessary data from the stack.

~Florian

Florian
Active Contributor
0 Kudos

Why not create a message via nace with a proper messaging? I do not see your problem here?

You needn't to activate an badi.

If you need a specific routine you can develop all these things in your driver program...

Otherwise you have to provide more details, perhaps you can work through this blog here:

~Florian

Former Member
0 Kudos

Hi Florian,

Can we send the smartform as an attachment using NACE? Can you please explain it in detail? Once the PO is fully released, this attachment has to be sent to the buyer.

Florian
Active Contributor
0 Kudos

Sure,

why not, you have to choose sending-mode 5 (external sending). Please use the SAP-help. Ask a consultant which is familiar with it, he/she will explain it to you. It is not just two clicks away.

Here is the link:

Message Control (CA-GTF-BS) - SAP Library

~Florian

Former Member
0 Kudos

Hi Florian,

Thanks for your inputs. Our ABAPer had already developed a smartform and linked this in NACT tcode. A new zprogram has been created for modifying and calling the smartform. We need to send this smartform without generating the preview and has to be sent through mail. How can we achieve this? In BADi can we call this smartform directly so that we can convert this smartform to pdf and send it through mail.

Regards,

Sibin

VenkatRamesh_V
Active Contributor
0 Kudos

Hi,

declare:

      lv_output_options TYPE TABLE OF ssfcompop WITH HEADER LINE,


lv_control_parameters-preview = ' '.




CALL FUNCTION    fnam                           "'/1BCDWB/SF00000020'
EXPORTING
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
CONTROL_PARAMETERS         =   lv_control_parameters


this syntex will not Display preview.


Regards,

VEnkat



Florian
Active Contributor
0 Kudos

Hi sibin,

As I told you before, use the online help SAP provides you. Here is exact the link you need

SAP Library - Smart Forms

and another with a sample program in

Took me a minute to use the search.

As I provided you in my first answer, please work through the referred blog.

~Florian

Former Member
0 Kudos

Hi Florian,

We got user exit EXIT_SAPMM06E_013 which gets triggered while releasing PO. How to call driver program for PO smartform from this user exit?

Regards,

Sibin