on 07-27-2007 3:48 PM
Hi experts,
I need to send the PO sapscript through email to a group of people.
I found FM SO_NEW_DOCUMENT_ATT_SEND_API1 but I do not know how to populate it to indicate the specific PO number to send.
All help is appreciated.
Monica.
hi ..
why dont you hav a look on the function group of this print group...for MEDRUCK...the function group is medruck and inside this, you will find the subroutine for sending PO by mail or by PDF etc...check this.
thanks,
shamim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Purchase order printing is configured in SPRO in the Materials management>Purchasing>Messages menu area. Under Output Control-->Message types it is possible to configure various processing routines. You can set up the standard Print Output, and a separate entry for External send or fax etc.
Once this is configured, You can email the purchase order by going to the Messages button in the create / change PO transaction and selecting a different output medium. There is no coding required to set this up - talk to a MM expert.
Another very simple option is to set up a printer going to email. This is done in transaction SPAD - give the printer Device type PDF1 and Access method M. You can then print to this printer and the result is a PDF email.
If you want to write your own program to send the emails, you need to get the sapscript output and convert it to PDF to send. You can get the output off the SAP spool and convert using the CONVERT_OTFSPOOLJOB_2_PDF function if you have the spool number for the PO printed, or you can get it by using a user exit / BADI in the PO print program to return the OTF (Sapscript) data in an internal table to your program which you then convert using CONVERT_OTF_2_PDF. You need to do some manipulation of the resulting data to get it into the correct format for attaching to an email (table of 255 character lines) as the functions return the PDF in a table of 134 character lines (NB dont use concatnate in this conversion as the table contains binary data and concatenate will corrupt the data by removing spaces).
Once you have the PDF in a 255 character internal table, you can call SO_NEW_DOCUMENT_ATT_SEND_API1 to send it, or use the newer CL_BCS method instead.
You may also like to look at the documentation on SAP's Business Communication Interface (part of "Generic Business Tools for Application Developers (BC-SRV-GBT)" - see SAP Help). This may do what you want.
Hope this is of some help
Andrew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrew,
Thank you for your note. It clarifies the process very well. We do want to write our own program(BAPI) to send the emails. It will be used in an interfase with our web-system.
I have a question though. When I start, write and close a form, how or where do you enter the object related ( Purchase Order number for this specific case). I checked the form functions I do not see where to pass the object key.
Thank you so much.
Hi,
Check the following to get clear idea abt functions,
OPEN_FORM
The function module OPEN_FORM opens form printing. You must call this function module before you can use any other form function (WRITE_FORM, START_FORM, CONTROL_FORM...).
You need not specify a form name. If you omit the name, you must use the function module START_FORM to open a form before starting the output.
You must end form printing by using the function module CLOSE_FORM. Otherwise, the system does not print or display anything.
Within a program, you can use several OPEN_FORM.. CLOSE_FORM pairs. This allows you to write output to several different spool requests from within one program.
CLOSE_FORM
The function module closes the form opened using OPEN_FORM. The system executes any terminating processing steps for the last opened form.
You must use this function module to close form printing. Otherwise, no output appears on printer or screen.
START_FORM
In-between the function modules OPEN_FORM and CLOSE_FORM, you can use different forms. This allows you to combine several different forms into one print output. However, you can combine only those forms that have the same page format.
To switch forms, use the function module START_FORM. If another form is still open, you must close it first using END_FORM.
If you specify no form name when calling START_FORM, the system restarts the last open form. If after OPEN_FORM no form was activated yet, the system leaves the function module with the exception UNUSED.
WRITE_FORM
The system outputs the form element specified in parameter ELEMENT into the currently opened form.
In the parameter WINDOW you can specify the name of a window for the output. Remember that the form element must be defined in this window. The parameter FUNCTION specifies how to merge the text lines to be output with any existing contents in the window. In this case, there are differences between the different window types or areas.
WRITE_FORM_LINES
The function module outputs the text lines in table LINES into the specified form window. The text lines must have the SAPscript ITF format. From the data in the text header, the system uses only the field TDSTYLE to apply the formatting attributes defined in the specified style for this text. If the field is empty, the system uses the identically named formatting attributes (character and paragraph formats) of the form.
Use parameter WINDOW to specify into which of the windows defined in the form you want to output the text. You can specify any window used in the form. The parameter FUNCTION determines how to merge the text lines to be output with any existing contents in the window. There are differences between the different window types or areas.
END_FORM
END_FORM ends the currently open form and executes the required termination processing. After calling this function module, no more form is active. For further output, you must start a new form using START_FORM.
CONTROL_FORM
Use CONTROL_FORM to pass SAPscript control statements to the form.
READ_FORM_ELEMENTS
The function module fills a table with all text elements that appear in one form.
If you specify no form name, the system includes all elements of the currently open form. If you specify a form, the system uses the information about the active version of the form, retrieved from the database.
READ_FORM_LINES
Use this function module to transfer the lines of a form element into an internal table.
If you specify no form name, the system transfers the text lines of the currently open form. If you specify a form, the system uses the text lines of the active version of the form from the database.
http://help.sap.com/saphelp_40b/helpdata/en/d6/0dc169494511d182b70000e829fbfe/frameset.htm
<b>Reward if helpful.</b>
Hi Uma,
Thank you for the explanation.
I checked the link and there is an example for print program.
Does it mean that I only have to make a select to EKKO (in this case) in base of my Po number before calling the Sapscript FM? The form will read it? The object key (PO number) is not passed to the Sapscript FM's right?
Monica.
Monica,
Unfortunately, printing of sapscripts like the purchase order is quite complicated. The SAP supplied driver program is integrated into the PO transactions through functionality known as "Message Control" whereby the PO transactions place entries into tables once the PO is in a state to be printed (or reprinted) and has an appropriate release status. The main table in this message control is table NAST. The print program then runs and extracts details that are placed onto the sapscript in the appropriate positions. For most windows on the PO this is done by setting a lot of values in memory which can be accessed from any window on the PO and included in the text. For the Main window however, the driver program repeatedly calls the sapscript with different element tags and appropriate values in memory for that element - there are several hundred of these elements in the PO main window - they have /E in the format column if you view the main window in the older style editor.
Duplicating this functionality in a custom program where you open the Sapscript form, print the windows and elements and then close it would be a major undertaking, and would be out of date as soon as you installed the next set of SAP support packs.
The program supplied in your post by Alejandro Bindi gets around this by using SAP function modules to do all the work. The select from NAST gets the details of the relevant message control entry for the purchase order. This is then passed to 'ME_READ_PO_FOR_PRINTING' which reads the relevant data from the purchase order, and the results from this go to 'ECP_PRINT_PO' which prints the order. Because of the other parameters passed to these functions, the sapscript output is not physically printed, but is placed into memory where you can get a copy of it using function 'READ_OTF_FROM_MEMORY'. This is then converted to PDF using 'CONVERT_OTF_2_PDF' - which returns the PDF in internal table parameter "LINES". The 'GUI_DOWNLOAD' places this PDF in a directory on your PC. If you were emailing it from here you would need to convert table pdfout from its 134 character format into a new table of 255 character records suitable for the email functions.
Hope this helps
Andrew
For Sapscripts like the PO some other choices to get a printout under program control are:
- Call the change PO transaction in a BDC and fill the appropriate fields etc in the messages button screens to generate a printout.
- Call the PO reprint transaction (somewhere infollow on actions on the SAP menu) - not sure if this can be done from a BDC - I think it requires placing the cursor on the relevant PO number and pressing a button - this can be hard to get to work in a BDC.
- Call the standard PO form program from a custom ABAP and let it print the sapscript. Not sure how well documented this is - may required some debugging to find what to pass it.
- There may be a BAPI for PO print - I dont have access to a system to check at this moment.
- other options through MM config etc.
try this
*----Data for mail
DATA: object_type_raw LIKE sood-objtp VALUE 'RAW'.
DATA: BEGIN OF object_hd_change.
INCLUDE STRUCTURE sood1.
DATA: END OF object_hd_change.
DATA: BEGIN OF objcont OCCURS 2. "contents
INCLUDE STRUCTURE soli.
DATA: END OF objcont.
DATA: BEGIN OF objparb OCCURS 0.
INCLUDE STRUCTURE soop1.
DATA: END OF objparb.
DATA: BEGIN OF receivers OCCURS 2.
INCLUDE STRUCTURE soos1.
DATA: END OF receivers.
DATA: w_date(10), w_time(8).
object_hd_change-objla = 'E'.
object_hd_change-objnam = 'MESSAGE'.
object_hd_change-objdes = 'Error in refinery posting'.
object_hd_change-objpri = '1'.
object_hd_change-objsns = 'O'.
WRITE: sy-uzeit TO w_time, sy-datum DD/MM/YYYY TO w_date.
CONCATENATE 'Error in refinery posting at' w_time w_date
INTO objcont-line SEPARATED BY ' '.
APPEND objcont.
MOVE: 'TG7299' TO receivers-recnam,
'X' TO receivers-sndex.
APPEND receivers.
MOVE: sy-uname TO receivers-recnam,
'X' TO receivers-sndex.
APPEND receivers.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = object_hd_change
object_type = object_type_raw
TABLES
objcont = objcont
objparb = objparb
receivers = receivers
EXCEPTIONS
OTHERS = 01.
rgds,
sairam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Probably you need to convert form to PDF first, then send the PDF file as attachment.
Check this code for downloading PO as PDF:
DATA: l_druvo LIKE t166k-druvo,
l_nast LIKE nast,
aux_nast LIKE nast,
l_from_memory,
l_doc TYPE meein_purchase_doc_print,
ent_screen TYPE c,
ent_retco TYPE i,
toa_dara TYPE toa_dara,
arc_params LIKE arc_params,
aux_form LIKE tnapr-fonam.
DATA: otf LIKE itcoo OCCURS 0 WITH HEADER LINE,
lt_docs TYPE TABLE OF docs,
pdf_bytecount TYPE i,
nom_archivo TYPE string.
aux_form = 'ZMEDRUCK'.
l_from_memory = c_true.
SELECT *
FROM nast
INTO aux_nast
UP TO 1 ROWS
WHERE kappl = c_po " Purchase Order
AND objky = t_datos-ebeln
AND aktiv = space
ORDER BY erdat DESCENDING eruhr DESCENDING.
ENDSELECT.
aux_nast-sort1 = c_swp.
CLEAR ent_screen.
CLEAR ent_retco.
IF aux_nast-aende EQ space.
l_druvo = c_1.
ELSE.
l_druvo = c_2.
ENDIF.
* l_druvo = '2'.
CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'
EXPORTING
ix_nast = aux_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.
CHECK ent_retco EQ 0.
CALL FUNCTION 'ECP_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 = aux_form
IMPORTING
ex_retco = ent_retco.
CLEAR otf.
CALL FUNCTION 'READ_OTF_FROM_MEMORY'
EXPORTING
memory_key = l_nast-objky " PO Number
TABLES
otf = otf
EXCEPTIONS
memory_empty = 1
OTHERS = 2.
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = pdf_bytecount
TABLES
otf = otf
doctab_archive = lt_docs
lines = pdfout
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS = 3.
CONCATENATE c_dest t_datos-ebeln c_ext INTO nom_archivo.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = pdf_bytecount
filename = nom_archivo
filetype = c_bin
IMPORTING
filelength = pdf_bytecount
TABLES
data_tab = pdfout.
Then use function SO_NEW_DOCUMENT_ATT_SEND_API1, attaching PDF to contents_bin internal table parameter.
<b>Please reward points if helps.</b>
Hi Alejandro,
I appreciate your answer.
I copied the code and when checking syntax I got error
The type "MEEIN_PURCHASE_DOC_PRINT" is unknown.
I double click on the document and the SAP takes me to another screen showing the type. So it is there. Do you know why it could be giving me this error?
Regards,
Monica.
No idea really about what causes that error, however code won't work copy-pasting it since it's not complete (i.e. constants are missing). It's only for referencing what Function modules you can use for conversion.
Also, run <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/advancedsearch?query=send%20sapscript%20by%20mail&cat=sdn_all">this search</a>, there are plenty of similar requirements which can help you.
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.