Simple Step by Step Procedure For Text File To Email With File Conversion in PI 7.1
Simple Step by Step Procedure For Text File To Email With File Conversion in PI 7.1
Applies to:
SAP PI (7.1,File To Email)
Summary
This article is about sending a text file from SAP system to a third-party as email with file conversion of text
file to xml in PI 7.1.An optional ABAP program is used to automate the process.
Author Bio
Bince Mathew C is working as an SAP ABAP/PI consultant in Applexus Technologies.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 1
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
Table of Contents
Prerequisites: ...................................................................................................................................................... 3
PI Configurations. ............................................................................................................................................... 4
STEP 1- Import or Create External Mail Definition ......................................................................................... 4
STEP 2 - ESR side configurations .................................................................................................................. 5
STEP 3 – Integration Builder side configurations ......................................................................................... 10
ABAP SIDE Configuration(Optional) ............................................................................................................. 19
Related Content ................................................................................................................................................ 23
Disclaimer and Liability Notice .......................................................................................................................... 24
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 2
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
Prerequisites:
We need to put a text file in the SAP input directory using the al11 t-code.I have created an abap program to
place the text file inside the Input directory without manually using the function module
ARCHIVFILE_CLIENT_TO_SERVER.I will explain the steps for that at the end of the tutorial.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 3
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
PI Configurations.
STEP 1- Import or Create External Mail Definition
First we need to import an external mail definition or create your own data type for receiving the email.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 4
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
The imported mail definition will be of the type .xsd.alternatively you need to just create an inbound datatype
with the following fields
1. From
2. To
3. Content
You can use this datatype instead of External Mail Defintion.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 5
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
2. Create a new data type for picking the email text file from SAP.
This data type contains the email parameters along with the content and subject.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 6
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
Note: In here for the inbound service interface I have used the External Mail definition, alternatively you can use the data
type that you created for inbound scenario
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 7
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
5. Create the message mappings for the data reach the target email.
In case of multiple targets, you can make multiple target structures using multi mapping in the signature tab.
In order to get a sample xml code (i.e. if your input file is .xml and not .txt) then you can get the code from the
test tab.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 8
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 9
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 10
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 11
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 12
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 13
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
File conversion parameters are defined in this section.(File conversion parameters are defined in the Content
conversion tab)
Mail.fieldFIxedLengths (here mail is the record structure name) is used to specify the length of each data in
the communication channel.
Mail.endseperator is used to specify where the next entry in the text file is.
Mail.fieldNames is used to specify the fields of the message type to which we are picking the entries from the
text file.
Mail.lastFieldOptional and Mail.keepIncompleteFields is set to YES to keep the system from generating an
error if the data in the text file contains additional fields.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 14
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
The receiver communication channel uses SMTP transport protocol and XIPAYLOAD as message protocol.
In connection parameters uses the SMTP server address of your corresponding email provider, this can be
obtained from your mail provider website.
Check Configure user authentication and provide the username and password of your email.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 15
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
5. Create the interface determination with the sender and receiver communication component,here the
operation mapping from the ESR is also provided.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 16
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
6. Create the Sender Agreement with parameters such as communication channel of the sender,
sender communication component etc
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 17
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
Additionally if you want to set you sender communication channel(Outbound) to listen for every 2 second or
so and also delete the file after picking it up once. You need to do the following settings in the Processing tab
in the communication channel. I made this change to automate the email sending process which is done by
an abap program which I created separately. This is an alternative method for using ABAP PROXY, but it’s a
non standard method. The abap program I created, basically picks up the to,from,subject and message from
the user via screen inputs, then creates an .TXTfiles into a predefined directory and then places the file to
the SAP input directory, this process helps in skipping the manual process of putting the email text file every
time into the SAP input directory.
Communication channel processing.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 18
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 19
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_0100 output.
SET PF-STATUS 'PF'.
* SET TITLEBAR 'xxx'.
FORM write_file.
* itab-Key = '1'.
* itab-to = 'To'.
* itab-from = 'From'.
* itab-sub = 'Sub'.
* itab-content = 'Content'.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 20
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
* APPEND itab.
itab-Key = '1'.
itab-to = io_to.
itab-from = io_from.
itab-sub = io_sub.
itab-content = io_content.
APPEND itab.
* itab-data = '1'.
* APPEND itab.
* itab-data = io_to.
* APPEND itab.
* itab-data = io_from.
* APPEND itab.
* itab-data = io_sub.
* APPEND itab.
* itab-data = io_content.
* APPEND itab.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 21
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
FORM Push_file.
CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'
EXPORTING
path = 'C:\Documents and Settings\Bince\Desktop\MAIL.TXT'
TARGETPATH = '\\SERVER\PI_Exercise\PI_Input\MAIL.TXT'
* EXCEPTIONS
* ERROR_FILE = 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.
ENDFORM.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 22
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
Related Content
File2Email
MailAdapterScenarios
XML as Email
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 23
Simple Step By Step Procedure for Text File To Email with File Conversion in PI 7.1
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 24