Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Hello, there is a quick how-to guide that sends custom e-mail after creating PO at me21n.

Road-Map

-Find a Badi that just called after creation of PO.

-Call standart functions that print SapScript

-Pull otf data from those functions

-and the rest is clasic; convert otf to pdf and send your custom mail.



Okay if the general outline makes sense, lets get started. The Badi that i recommend is 'ME_PROCESS_PO_CUST'. Get into se18 and make a new implementation.


Done? Nice. Now get into the  close method and inspect the code below.


select single fonam from tnapr into lv_fonam where  kschl eq 'NEU' andnacha eq '5' .
*>>>init_nast and parameters for fm
   lv_header = im_header->get_data( ).
  
check lv_header-ebeln is not initial. "this check is important because badi execute when you quit from po too


   nast-mandt = sy-mandt.
   nast-kappl =
'EF' . "ToDo: check.
   nast-objky = lv_header-ebeln.
   nast-kschl =
'NEU' .
   nast-spras =
'T' .
   nast-parnr = lv_header-lifnr.

   nast-parvw = 'LF' "mali teslim alan
   nast-erdat = lv_header-aedat.
   nast-eruhr = sy-uzeit.
   nast-nacha =
'8' .
   nast-vsztp =
'4' .
   nast-manue =
'X' .
   nast-datvr = sy-datum.
   nast-uhrvr = sy-uzeit.
   nast-usnam = sy-uname.
   nast-vstat =
'1' .
   nast-tcode =
'EPST' . " ME21N
   nast-dimme =
'X' .
   nast-tdid =
'bewg' .
   nast-tdspras =
'T' .

   nast-tdcovtitle = 'sadasdasda' .
   nast-cmfpnr =
'000000098575' . " ToDo: bune?
   nast-objtype =
'BUS2012' .

ent_screen =
'X' .
l_druvo =
'1' .

call function 'ME_READ_PO_FOR_PRINTING'
       
exporting
             ix_nast        = nast
             ix_screen      = ent_screen
       
importing
             ex_retco       = ent_retco

             ex_nast        = l_nast
             doc            = l_doc
       
changing
             cx_druvo       = l_druvo
             cx_from_memory = l_from_memory.



This code get the header data of PO and prepare the printing parameters with FM 'ME_READ_PO_FOR_PRINTING'.


Now make Nast-nacha = 8 to distinguish that next FM called from this badi. As you will see we open holes in 'ME_PRINT_PO' as enhancement points to pull otf data of SAPScript.


Call the 'ME_PRINT_PO' FM.


l_NAST-NACHA = 8.
      
check ent_retco eq 0.
      
if lv_fonam is not initial. " expected ZNUH_LMM_ME
DRUCK
  
call function 'ME_PRINT_PO'
       
exporting
             ix_nast        = l_nast
             ix_druvo       = l_druvo
             doc            = l_doc
             ix_screen      = ent_screen
             ix_from_memory = l_from_memory

             ix_toa_dara    = toa_dara
             ix_arc_params  = arc_params
             ix_fonam       = lv_fonam
"tnapr-fonam          "HW 214570
       
importing
             ex_retco       = ent_retco.



Now I'll show you the spots that you need to write code in that FM.

Enter to FM.

Find subroutine named; prepare_formular

Scroll into right before open_form FM in that.

As you see we check that nast-naha eq 8.  Clear xdialog since we dont want pop-up after user clicked to save button. Also say that please get the otf data when closing form.

Now just after close_form fm called, which can be found subrotine ende in our main printing function,

we save the otf data to memory.

Okay we are done for 'ME_PRINT_PO'.

Lets get back to our badi.

We pull the otf data from memory and convert otf to pdf;

And the last thing is prepare your code and call the function 'SO_NEW_DOCUMENT_ATT_SEND_API1'.



Well done. We're done.