0% found this document useful (0 votes)
72 views24 pages

Simple Step by Step Procedure For Text File To Email With File Conversion in PI 7.1

Uploaded by

fziwen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views24 pages

Simple Step by Step Procedure For Text File To Email With File Conversion in PI 7.1

Uploaded by

fziwen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

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: Bince Mathew C


Company: Applexus Technologies
Created on: 03 October 2011

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

Sample Text file format is shown below

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.

STEP 2 - ESR side configurations


We need to make the following configurations on the Enterprise Service Builder in Software Component.
1. Create a new namespace for the file to email scenario

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.

3. Create a message type for the data type we created above.

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

4. Create two service interfaces for Inbound and Outbound service.

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

A sample code for .xml file is shown below

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

6. Create the Operation Mapping to complete the ESR side configurations.

STEP 3 – Integration Builder side configurations


1. Create a configuration Scenario for file to email.

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

2. Create the business component for both receiver and sender.


Business Component Receiver Side

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

Business Component Sender Side

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

3. Define Communication Channel Parameters to pick and send the file.


The sender communication channel side Transport protocol should be NFS and adapter type as FILE.

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

4. Create the receiver determination for the scenario

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

7. Create the Receiver Agreement with the receiver parameters.

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

ABAP SIDE Configuration(Optional)


ABAP Program Output

Mail in gmail inbox

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

Report Program Code


DATA: io_to(30) TYPE c,
io_from(30) TYPE c,
io_sub(30) TYPE c,
io_content(100) TYPE c,
path TYPE string.
*DATA: BEGIN OF itab OCCURS 0,
* to(100) TYPE c,
* from(100) TYPE c,
* sub(100) TYPE c,
* content(100) TYPE c,
* END OF itab.
DATA: BEGIN OF itab OCCURS 0,
Key(2) TYPE c,
to(30) TYPE c,
from(30) TYPE c,
sub(30) TYPE c,
content(100) TYPE c,
* data(100) TYPE c,
END OF itab.
CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_0100 output.
SET PF-STATUS 'PF'.
* SET TITLEBAR 'xxx'.

endmodule. " STATUS_0100 OUTPUT


*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module USER_COMMAND_0100 input.
DATA : save_ok TYPE sy-ucomm,
ok_code TYPE sy-ucomm.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'MAIL'.
PERFORM write_file.
PERFORM Push_file.
MESSAGE 'Sent' TYPE 'I'.
CLEAR itab.
ENDCASE.
endmodule. " USER_COMMAND_0100 INPUT

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.

CALL FUNCTION 'GUI_DOWNLOAD'


EXPORTING
* BIN_FILESIZE =
filename = 'C:\Documents and Settings\Bince\Desktop
\MAIL.TXT'
* FILETYPE = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* IMPORTING
* FILELENGTH =
tables
data_tab = itab
* FIELDNAMES =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7

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

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 24

You might also like