SAP R3 Guide To EDI IDocs and Interfaces
SAP R3 Guide To EDI IDocs and Interfaces
The
SAP R/3 Guide to
EDI, IDocs and Interfaces
Robi Gonfalonieri,
born in 1965 is a senior ABAP IV developer and R/3 consultant for SD and MM. He
is a learned economist turned ABAP IV developer. He specializes in international,
multi-language projects both as developer and SD consultant. He speaks fluently
several languages including German, French, English and Italian.
! [email protected]
Ulrich Streit,
born in 1975 is ABAP IV developer and interface specialist. He developed a
serious of legacy system interfaces and interface monitors for several clients of the
process industry. ! [email protected]
logosworld.com
is a group of loosely related freelance R/3 consultants and consulting companies.
Current members of the logosworld.com bond are the following fine companies:
• Logos! Informatik GmbH, Brühl, Germany: R/3 technical troubleshooting
• OSCo GmbH, Mannheim, Germany: SAP R/3 implementation partner
• UNILAN Corp., Texas: ORACLE implementation competence
1999 Axel Angeli et al. - SAP R/3 Guide to EDI, IDocs and ALE
For Doris, Paul, Mini
1999 Axel Angeli et al. - SAP R/3 Guide to EDI, IDocs and ALE
cook.doc Total pages 177; Print date: 16.01.00; Page ii
Danke, Thank You, Graçias,
Tack så mycket, Merci, Bedankt,
Grazie, Danjawad, Nandri, Se-Se
I due special thanks to a variety of people, clients, partners and friends. Their
insistence in finding a solution and their way to ask the right questions made this
book only possible.
I want especially honour Francis Bettendorf, who has been exactly that genre of
knowledgeable and experienced IT professionals I had in mind, when writing this
Thanks to Detlef and Ingolf Streit for doing the great cartoons.
Thanks also to Pete Kellogg of UNILAN Corp., Texas, Juergen Olbricht, Wolfgang
Seehaus and his team of OSCo, Mannheim for continuously forming such perfect
project teams. It is joy working with them.
Plans are fundamentally ineffective because the "circumstances of our actions are
never fully anticipated and are continuously changing around us". Suchman does not
deny the existence or use of plans but implies that deciding what to do next in the
pursuit of some goal is a far more dynamic and context-dependent activity than
the traditional notion of planning might suggest.
1999 Axel Angeli et al. - SAP R/3 Guide to EDI, IDocs and ALE
Who Would Read This Book?
This book was written for the experienced R/3 consultants, who wants to know
more about interface programming and data migration. It is mainly a compilation
of scripts and answers who arose during my daily work as an R/3 coach.
Quid – What is that The R/3 Guide is a Frequently Given Answers book. It is a
book about? collection of answers, I have given to questions regarding EDI
over and over again, both from developers, consultants and
client’s technical staff. It is focussed on the technical aspect of
SAP R/3 IDoc technology. It is not a tutorial, but a supplement
to the R/3 documentation and training courses.
Quis – Who should The R/3 Guide has been written with the experienced
3.4 Interpreting An IDoc Segment Info ........... Fehler! Textmarke nicht definiert.
All IDoc data records are exchanged in a fixed format, regardless of the
segment type. The segment’s true structure is stored in R/3’s repository as a
DDic structure of the same name. Fehler! Textmarke nicht definiert.
3.5 IDoc Base - Database Tables Used to Store IDocs .. Fehler! Textmarke nicht
definiert.
When R/3 processes an IDoc via the standard inbound or outbound
mechanism, the IDoc is stored in the tables. The control record goes to table
EDIDC and the data goes to table EDID4. Fehler! Textmarke nicht definiert.
Monitoring IDocs 24
Sample Processing Routines 25
6.1 Sample Processing Routines .........................................................................26
Creating and processing IDocs are a widely mechanical task, as it is true for
all interface programming. We will show a short example that packs SAP R/3
SAPscript standard text elements into IDocs and stores them back. 26
6.2 Sample Outbound Routines .........................................................................27
The most difficult work when creating outbound IDocs is the retrieval of the
application data which needs sending. Once the data is well retrieved, the
data needs to be converted to IDoc format, only. 27
6.3 Sample Inbound Routines .............................................................................30
Inbound processing is widely the reverse process of an outbound.. The
received IDoc has to be unpacked, interpreted and transferred to an
application for further processing. 30
IDocs Terminology 32
7.1 Basic Terms .....................................................................................................33
There are a couple of expressions and methods that you need to know,
when dealing with IDoc. 33
7.2 Terminology....................................................................................................34
7.2.1 Message Type – How to Know What the Data Means 34
Data exchanged by an IDoc and EDI is known as messages. Message of the
same kind belong to the same message type. 34
7.2.2 Partner Profiles – How to Know the Format of the Partner 34
Different partners may speak different languages. While the information
remains the same, different receivers may require completely different file
formats and communication protocols. This information is stored in a partner
profile. 34
ii
IDocs Customizing 37
8.1 Basic Customizing Settings ........................................................................... 38
Segments define the structure of the records in an IDoc. They are defined
with transaction WE31. 38
8.2 Creating An IDoc Segment WE31 ............................................................. 40
9.5 Sending IDocs Via RSNAST00 .................... Fehler! Textmarke nicht definiert.
Here is the principle flow how RSNAST00 processes messages for IDocs.Fehler! Textmarke nicht definiert.
9.6 Workflow Based Outbound IDocs ............. Fehler! Textmarke nicht definiert.
Unfortunately, there are application that do not create messages. This is
especially true for master data applications. However, most applications fire
a workflow event during update, which can easily be used to trigger the
IDoc distribution. Fehler! Textmarke nicht definiert.
9.7 Workflow Event From Change Document Fehler! Textmarke nicht definiert.
Instead of waiting for a polling job to create IDocs, they can also be created
immediately after a transaction finishes. This can be done by assigning an
action to an workflow event. Fehler! Textmarke nicht definiert.
9.8 ALE Change Pointers.................................. Fehler! Textmarke nicht definiert.
Applications which write change documents will also try to write change
pointers for ALE operations. These are log entries to remember all modified
data records relevant for ALE. Fehler! Textmarke nicht definiert.
9.9 Activation of change pointer update ...... Fehler! Textmarke nicht definiert.
Change pointers are log entries to table BDCP which are written every time
a transaction modifies certain fields. The change pointers are designed for
ALE distribution and written by the function CHANGE_DOCUMENT_CLOSE.Fehler! Textmarke nicht definie
9.10 Dispatching ALE IDocs for Change Pointers............. Fehler! Textmarke nicht
definiert.
Change pointers must be processed by an ABAP, e.g. RBDMIDOC.Fehler! Textmarke nicht definiert.
IDoc Recipes 65
10.1 How the IDoc Engine Works ..........................................................................66
IDocs are usually created in a four step process. These steps are: retrieving
the data, converting them to IDoc format, add a control record and
delivering the IDoc to a port. 66
10.2 How SAP Standard Processes Inbound IDocs..............................................67
When you receive an IDoc the standard way, the data is stored in the IDoc
base and a function module is called, which decides how to process the
received information. 67
10.3 How To Create the IDoc Data .......................................................................68
R/3 provides a sophisticated IDoc processing framework. This framework
determines a function module, which is responsible for creating or
processing the IDoc. 68
10.4 Interface Structure of IDoc Processing Functions ........................................70
To use the standard IDoc processing mechanism the processing function
module must have certain interface parameters, because the function is
called dynamically from a standard routine. 70
10.5 Recipe To Develop An Outbound IDoc Function ........................................71
This is an individual coding part where you need to retrieve the information
from the database and prepare it in the form the recipient of the IDoc will
expect the data 71
10.6 Converting Data Into IDoc Segment Format ...............................................72
The physical format of the IDocs records is always the same. Therefore the
application data must be converted into a 1000 character string. 72
iv
vi
vii
Appendix 147
19.1 Overview of Relevant Transactions ............................................................147
There is a couple of transactions which you should know when working with
IDocs in any form. I suggest to call each transaction at least once to see,
what is really behind. 147
19.2 Useful Routines for IDoc Handling...............................................................148
These are some very useful routines, that can be used in IDoc processing. 148
19.3 ALE Master Data Distribution .......................................................................149
The ALE functionality comes with a set of transaction which allow the
distribution of important master data between systems. The busiest argument
for installing ALE might be the distribution of the classification from
development to production and back. 149
19.4 WWW Links ....................................................................................................150
These is a random listing of interesting web sites dealing with the EDI topic.
They are accurate as of November 1999. 150
19.5 Questionnaire for Starting an IDoc Project.................................................151
This is a sample questionnaire with important questions that need to be
cleared before any development can be started. 151
Index 153
viii
Table of Illustrations
Illustration 1: A typical EDI scenario from the viewpoint of R/3 .............................9
Illustration 2: Simplified Example of an IDoc control record for sales orders ...... 12
Illustration 3: Simplified Example of an IDoc data record for sales orders .......... 12
Illustration 5: Example of an IDoc with one segment per line, an info tag to the left
Illustration 17: Visual Basic code with macros to call R/3 from WORD 97 ............. 90
Illustration 20: Seeburger™ graphical EDI converter editor with R/3 linkage ..... 146
ix
Directory of Programs
Program 8: Program to copy text modules into a remote system via RFC ...... 83
Program 10: This is the call of the type coupled event in release 40B ............. 117
Program 11: This is the call of the change doc event in release 40B ............... 118
Program 12: This is the call of the type coupled event in release 40B ............. 118
Program 13: A workflow handler that sends an Sap Office mail ...................... 120
Program 14: Send a SAPoffice mail triggered by a workflow event (full example)
123
http://idocs.de
We praise cutting edge technology. So this book takes advantage of the modern
multimedia hype. Latest updates, corrections and more sophisticated and
detailed examples are found on our web site.
Summary
1.1 Communication
More than 80% of the time of an EDI project is lost in waiting for answers,
trying to understand proposals and retrieving data nobody actually needs.
A common EDI means to exchange information between a sender and a
language receiver. Both communication partners need to speak the
same language to understand each other.
The language for EDI are the file formats and description
languages used in the EDI data files. In the simple case of
exchanging plain data files, the partners need to agree on a
common file format.
Finding the common agreement, that is it, where most of the
money gets lost. See a common scenario:
The receiving party defines a file structure in which it likes to
receive the data. This is usually an image of the data structure
of the receiving computer installation.
This is a good approach for the beginning, because you have
to start somewhere. But now the disaster takes course.
The proposal is sent to the other end via email. The developer
of the sender system takes a look on it and remains quiet. Then
he starts programming and tries to squeeze his own data into
the structure.
Waiting for a If it becomes too tedious, a first humble approach takes place
response to convince the other party to change the initial file format.
Again it is sent via email and the answer comes some days
later. Dead time, but the consultant is paid.
Badly described It can be even worse: one party proposes a format and the
meaning of a field other party does not understand the meaning of some fields.
Echoing Another field cannot be filled, because the sender does not
have the information. Looking closer you find out, that the
information originates from the receiving partner anyway. The
programmer who proposed the format wanted it filled just for
his personal ease. This is known as Echoing and it is always a
nice to have feature.
Using the same A real disaster happens if both parties use the same expression
term for different for different items. A classy case is the term “delivery”: many
objects legacy systems call a delivery what is known as an SD transport
in R/3.
There are many other situation where always one thing
happens: time is spoiled. And time is money.
Face to face The solution is more than easy: bring the people together.
Developers of both parties need to sit together, physically face
to face. If they can see what the other person does, they
understand each other.
It is reported that SAP R/3 delivers standard EDI programs and that they
should not be manipulated and no circumstances. Because this is not true,
much project is lost in chasing the phantom.
Predefined not SAP R/3 is delivered with a serious of predefined IDoc types
standard and corresponding handler function modules.
Some of the handler programs had been designed with user-
exits where a developer could implemented some data post-
processing or add additional information to an IDoc.
You must always see those programs as examples for IDoc
handling. If the programs do already what you want, it is just
fine. But you should never stick too long to those programs, if
you need different data to send.
R/3 IDocs were The R/3 standard IDoc programs had been designed with the
primarily designed German association of automobile manufacturers (VDA) in
for the automotive mind. The VDA is a committee which defines EDI standards for
industry their members, e.g. Volkwagen, BMW, Daimler-Benz-Chrysler.
Not every car manufacturer, e.g. FORD uses these
recommendations. Other industries define their own standards
which are not present in R/3.
If there already exists a file exchange format for your company
or your industry, you may want to use this one. This means to
type in the file format, writing the program that fills the structure
and customize the new IDoc and message types.
A simple calculation:
Calculation Discussing the solutions 5 days
Typing in the file formats 1/2 day
Writing the program to fill the segments 1 days
Adjust the customizing 1/2 day
Testing and correcting everything 3 days
Travel time 2 days
Total 12 days
This is not an optimistic calculation. You will mind that eight out
of the twelve days are accounting for non IT related tasks like
discussing solutions, educating each other and testing.
If a project takes longer than that, it always adds to the
account of discussion and adapting solutions, because things
have changed or turned out to be different as initially planned.
1.4 Strategy
Do not loose your time in plans. Have prototypes developed and take them
as a basis.
You cannot predict Do not stick to the illusion, that a proper design in the
all eventualities beginning will lead to a good result. It is the age old error in
trusting the theorem of Laplace:
Laplace “Tell me all the facts of the world about the presence
and I will predict the future for you.”
Heisenberg and Let aside the fact, that modern physics since Heisenberg and
uncertainty his uncertainty theorem has proven, that even knowing
Some may have learned it in school: the basic rules of rhetoric according
to Cicero. You will know the answers, when your program is at its end. Why
don’t you ask the questions in the beginning? Ask the right question, then
you will know.
Summary
• IDocs are an ASCII file format to exchange data
IDocs are structured ASCII files (or a virtual equivalent). They are the file
format used by SAP R/3 to exchange data with foreign systems.
IDocs Are SAP's IDocs are simple ASCII data streams. When they are
implementation of stored to a disk file, the IDocs are simple flat files with
structured text files lines of text, where the lines are structured into data
fields. The typical structured file has records, where
each record starts with a leading string, which identifies
the record type. Their specification is stored in the data
dictionary.
Electronic Interchange IDocs is the acronym for Interchange Document. This
Document indicates a set of (electronic) information which build a
logical entity. An IDoc is e.g. all the data of a single
customer in your customer master data file. Or the IDoc
is all the data of a single invoice.
Data Is transmitted in ASCII IDoc data is usually exchanged between systems and
format, i.e. human readable partners who are completely independent. Therefore
form the data should be transmitted in a format, that can
easily be corrected by the humans who operate the
computers. It is therefore mandatory to post the data in
a human readable form.
Nowadays, this means that data is coded in ASCII
format, including number, which are sent as string of
figures 0 to 9. Such data can easily be read with any
text editor on any computer, be it a PC, Macintosh,
UNIX System, S/390 or any internet browser.
IDocs exchange messages The information which is exchanged by IDocs is called
a message and the IDoc is the physical representation
of such a message. The name “messages” for the
information sent via IDocs is used in the same ways as
other EDI standards do.
IDocs are used like classical Everybody who ever dealt with interface programming,
interface files will find IDocs very much like the hierarchical data files
used in traditional data exchange.
International standards like the ODETTE or VDA formats
are designed in the same way as IDocs are.
XML, ANSI X:12 or EDIFACT Other EDI standards like XML, ANSI X.12 or EDIFACT/UN
use a description language are based on a data description language. They differ
principally from the IDocs concept, because they use a
programming language syntax (e.g. like Postscript or
HTML) to embed the data.
A typical EDI/IDoc
1 Application writes
scenario in R/3 data to R/3
database tables
R/3 Application
IDoc Creating
Function Module
2 An Application
request sending
IDoc of an IDoc
Document 3 An Idoc handler
Structured creates the Idoc and
ASCII File converts data to
ASCII format
XML, X.12.
EDIFACT ...
Converter
(PC program)
5 Data is sent
optional to receiver,
4 An external program e.g. via FTP,
ISDN protocol
(e.g. running on NT)
converts to international
standards
Summary
For the beginning we want to give you a feeling of what IDocs are and how
they may look like, when you receive it as a plain text file.
IDocs are plain ASCII files IDocs are basically a small number of records in ASCII
(resp. a virtual equivalent) format, building a logical entity. It makes sense to see
an IDoc as a plain and simple ASCII text file, even if it
might be transported via other means.
Control record plus many Any IDoc consists of two sections
data records = 1 IDoc • The control record
which is always the first line of the file and provides the
administrative information.
The rest of the file is made up by
• the data record
which contain the application dependent data, in our
example below the material master data.
For an example, we will discuss the exchange of the
material master IDoc MATMAS in the paragraphs below.
IDocs are defined in WE31 The definition of the IDoc structure MATMAS01 is
deposited in the data dictionary and can be viewed
with WE30 .
Illustration 1: Part of the content of an IDoc file for IDoc type MATMAS02
The very first record of an IDoc package is always a control record. The
structure of this control record is the DDic structure EDIDC and describes the
contents of the data contained in the package.
Control record serves The control record carries all the administrative information
as cover slip for the of the IDoc, such as its origin and its destination and a
transport categorical description of the contents and context of the
attached IDoc data. This is very much like the envelope or
cover sheet that would accompany any paper document
sent via postal mail.
Control record is used For R/3 inbound processing, the control record is used by the
by the receiver to standard IDoc processing mechanism, to determine the
determine the method how to process the IDoc. This method is usually a
processing algorithm function module, but may be a business object as well. The
processing method can be fully customized.
Control record not Once the IDoc data is handed over to a processing function
necessary to process module, you will no longer need the control record
the IDoc Data information. The function modules are aware of the
individual structure of the IDoc type and the meaning of the
data. In other words: for every context and syntax of an
IDoc, you would write an individual function module or
business object (note: a business object is also a function
module in R/3) to deal with.
Control Record The control record has a fixed pre-defined structure, which
structure is defined as is defined in the data dictionary as EDIDC and can viewed
EDIDC in DDic with SE11 in the R/3 data dictionary. The header of our
example will tell us, that the IDoc has been received from a
sender with the name PROCLNT100 and sent to the system
with the name DEVCLNT100 . It further tells us that the IDoc is
to be interpreted according to the IDoc definition called
MATMAS01 .
MATMAS01 ... DEVCLNT100 PROCLNT100 ...
Illustration 4: Schematic example of an IDoc control record
All records in the IDoc, which come after the control record are the IDoc
data. They are all structured alike, with a segment information part and a
data part which is 1000 character in length, filling the rest of the line.
All IDoc data record All records of an IDoc are structured the same way,
have a segment info regardless of their actual content. They are records with a
part and 1000 fixed length segment info part to the left, which is followed
characters for data by the segment data, which is always 1000 characters long.
IDoc type definition We will have a look on an IDoc of type MATMAS01 . The IDoc
can be edited with type MATMAS01 is used for transferring material master data
WE30 via ALE. You can view the definition of any IDoc data
structure directly within R/3 with transaction WE30.
Illustration 5: Example of an IDoc with one segment per line, an info tag to
the left of each segment and the IDoc data to the right
Data and segment info Regardless of the used IDoc type all IDocs are stored in the
is stored in EDID4 same database tables EDID4 for release 4.x and EDID3 for
release 2.x and 3.x. Both release formats are slightly different
with respect to the lengths of some fields. Please read the
chapter on port types for details.
Depending on the R/3 release the IDoc data records are
formatted either according the DDic structure EDID3 or
EDID3. The difference between the two structure reflect
mainly the changes in the R/3 repository, which allow longer
names staring from release 4.x.
All IDoc data records are exchanged in a fixed format, regardless of the
segment type. The segment’s true structure is stored in R/3’s repository as a
DDic structure of the same name.
R/3 is only interested in The segment info tells the IDoc processor how the current
the segment name segment data is structure and should be interpreted. The
information, which is usually of only interest is the name of
the segment EDID4-SEGNAM.
Segment name tells The segment name corresponds to a data dictionary
the data structure structure with the same name, which has been created
automatically when defining the IDoc segment definition
with transaction WE31 .
Remaining information For most applications, the remaining information in the
is only for foreign segment info can be ignored as being redundant. Some
systems older, non-SAP-compliant partners may require it. E.g. the
IDoc segment info will also store the unique segment
number for systems, which require numeric segment
identification.
To have the segment made up for processing in an ABAP, it
is usually wise to move the segment data into a structure,
which matches the segment definition.
For a segment of type e1maram the following coding is
commonly used:
Data in EDID4-SDATA TABLES: e1maram.
. . .
MOVE edidd-sdata TO e1maram.
Then you can access the fields of the IDoc segment EDIDD-
SDATA as fields of the structure e1maram .
Data in EDID4-SDATA WRITE: e1maram-matnr.
Sample coding The following coding sample, shows how you may read a
MATMAS IDoc and extract the data for the MARA and MARC
segments to some internal variables and tables.
DATA: xmara LIKE e1maram.
DATA: tmarc AS STANDARD TABLE OF e1marcm
WITH HEADER LINE.
LOOP AT edidd.
CASE edidd-segnam.
WHEN 'E1MARAM'.
MOVE edidd-sdata TO xmara.
WHEN 'E1MARCM'.
MOVE edidd-sdata TO tmarc.
APPEND tmarc.
ENDCASE.
ENDLOOP.
now do something with xmara and tmarc.
All inbound and All IDoc, whether sent or received are stored in the table
outbound Docs are EDID4. The corresponding control file header go into EDIDC.
stored in EDID4
There are standard programs who read and write the data
to and from the IDoc base. These programs and transaction
are heavily dependent on the customizing, where rules are
defined which tell how the IDocs are to be processed.
Of course, as IDocs are nothing than structured ASCII data,
The best way of learning is doing it. This chapter tells you
how to set up your R/3 system that it can send IDocs to
itself. When sending IDocs to your own system you can test
the procedures without the need for a second client or
installation.
If you have a naked system, you cannot send IDocs immediately. This
chapter will guide you through the minimum steps to see how the IDoc
engine works.
You can access most of the transactions used in the
example below in the menu WEDI and SALE.
Check EDID4 with SE16 We will assume, that we want to send material master
data from the current system to a remote system. To
simulate this scenario we do not need to have a
second system. With a little trick, we can set up the
system to send an IDoc back to sending client.
We will set up the system to use an RFC call to itself.
Therefore we need to define an RFC remote
destination, which points back to our own client. There
is a virtual RFC destination called NONE which always
refers to the calling client.
1. Declare the RFC RFC destinations are installed with the transaction
destination to receive SM59. Create a new R/3 destination of type "L"
the IDoc (Logical destination) with the name INTERNAL and the
destination NONE.
Note: Do not use RFC type internal. Although you could
create them manually, they are reserved for being
automatically generated. However, there is the internal
connection "NONE" or "BACK" which would do the
same job as the destination we are creating now.
2. Define a data port for The next step is defining a data port, which is
INTERNAL referenced by the IDoc sending mechanism to send
the IDoc through. Declaring the port is done by
transaction WE21.
3. Declare a new ALE We will now declare an ALE connection from our client
model with SALE . to the partner INTERNAL. ALE uses IDocs to send data
to a remote system. There is a convenient transaction
to send material master as IDocs via the ALE.
4. Declare MATMAS01 as The set up is done in transaction SALE. You first create
a valid ALE object to a new ALE model, to avoid interfering with eventual
be sent to INTERNAL existing definitions. Then you simply add the IDoc
message MATMAS as a valid path from your client to
INTERNAL.
5. Send the IDoc with In order to send the IDoc, you call the transaction
transaction BALE. BALE and choose the distribution of material master
data (BD10). Choose a material, enter INTERNAL as
receiver and go.
6. Display IDocs with To see, which IDocs have been sent, you can use the
WE05 transaction WE05. If you did everything as described
above, you will find the IDocs with an error status of 29,
meaning that there is no valid partner profile. This is
true, because we have not defined one yet.
Illustration 3: Part of the content of an IDoc file for IDoc type MATMAS02
Monitoring IDocs
There are some utilities in R/3 that help monitoring all the
IDocs in the system. They allow viewing them, analysing
eventual cause of error and retrying IDoc processing in
case of failure.
Summary
K eep
The most difficult work when creating outbound IDocs is the retrieval of the
application data which needs sending. Once the data is well retrieved, the
data needs to be converted to IDoc format, only.
FUNCTION
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_TDOBJECT) LIKE THEAD-TDOBJECT DEFAULT 'TEXT'
*" VALUE(I_TDID) LIKE THEAD-TDID DEFAULT 'ST'
*" VALUE(I_TDNAME) LIKE THEAD-TDNAME
*" VALUE(I_TDSPRAS) LIKE THEAD-TDSPRAS DEFAULT SY-LANGU
*" EXPORTING
LOOP AT TLINES.
MOVE E_THEAD TO IDOC_DATA-SDATA.
* *** -- we still need to fill more segment info
MOVE 'YAXX_TLINE' TO IDOC_DATA-SEGNAM.
APPEND IDOC_DATA.
ENDLOOP.
ENDFUNCTION.
LOOP AT TLINES.
MOVE E_THEAD TO IDOC_DATA-SDATA.
* *** -- we still need to fill more segment info
MOVE 'YAXX_TLINE' TO IDOC_DATA-SEGNAM.
APPEND IDOC_DATA.
ENDLOOP.
Filling control Finally we have to provide a correctly filled control record for this
record IDoc. If the IDoc routine is used in a standard automated
information environment, it is usually sufficient to fill the field EDIDC-IDOCTP
with the IDoc type, EDIDC-MESTYP with the context message type
and the receiver name. The remaining fields are automatically
filled by the standard processing routines if applicable.
* *** --- Packing the IDoc control record --- ****
CLEAR IDOC_CONTRL.
IDOC_CONTRL-IDOCTP = 'YAXX_TEXT'.
* *** -- we still need to fill more control rec info
APPEND IDOC_CONTRL.
CLEAR XTHEAD.
REFRESH TLINES.
* *** --- Calling the application to process the received data --- ***
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
HEADER = XTHEAD
SAVEMODE_DIRECT = 'X'
TABLES
LINES = TLINES.
IDOC_STATUS-MSGNO = '000'.
IF OK NE 0.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
ELSE.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'S'.
CALL_TRANSACTION_DONE = 'X'.
ENDIF.
APPEND IDOC_STATUS.
ENDFUNCTION.
IDocs Terminology
There are a couple of expressions and methods that you need to know,
when dealing with IDoc.
Message Type The message type defines the semantic context of an IDoc.
The message type tells the processing routines, how the
message has to be interpreted.
The same IDoc data can be sent under different message
types. E.g. can the same IDoc structure which is used for a
purchase order also be used for transmitting sales order.
Imagine the situation that you receive sales order either from
your clients and also copies of sales orders for information
purposes sent by a subsidiary
7.2 Terminology
Define the semantic The message type defines the semantic context of an IDoc.
context The message type tells the receiver, how the message has to
be interpreted.
Messages is The term message is commonly used in communication, be it
information aimed for EDI or telecommunication. Any stream of data sent to a
communicating with a receiver with a well-defined information in it, is known as a
foreign partner message. EDIFACT, ANSI/X.12, XML and others use message
the same way.
The term message is Unfortunately, the term message is used in many contexts
also used for R/3’s other than EDI as well. Even R/3 uses the word message for
internal the internal communication between applications. While this
communication is totally OK from the abstract point of view of data
between applications
modelling, it may sometimes cause confusion, if it is unclear
whether we talk about IDoc messages or internal messages.
The specification of the message type along with the sent
IDoc package is especially important, when the physical
IDoc type (the data structure of the IDoc file) is used for
different purposes.
A classical ambiguity arises in communication with customs
via EDI. The usually set up a universal file format for any kind
of declarations, e.g. Intrastat, Extrastat, Export declarations,
monthly reports etc. Depending on the message type, only
applicable fields are field with valid data. The message type
tells the receiver, which fields are of interest at all.
The IDoc type is the name of the data structure used to describe the file
format of a specific IDoc.
IDoc type defines the An IDoc is a segmented data file. It has typically several segments.
structure of the The segments are usually structured into fields, however different
segments segments use different fields.
The IDoc type is defined with transaction WE30, the respective
segments are defined with transaction WE31.
IDocs Customizing
Summary
Segments define the structure of the records in an IDoc. They are defined
with transaction WE31.
Check first, whether the client you are working in, has
already a logical system name assigned.
T000 – name of own logical The logical system name is stored in table T000 as
system T000-LOGSYS. This is the table of installed clients.
TBDLS – list of known logical If there is no name defined, yet, you need to create a
destinations logical system name before. This means simply
adding a line to table TBDLS. You can edit the table
directly or access the table from transaction SALE.
Naming conventions like: The recommended naming convention is
DEVCLNT100
sysid + "CLNT" + client
PROCLNT123
TSTCLNT999 If your system is DEV and client 100, then the logical
system name should be: DEVCLNT100.
System PRO with client 123 would be PROCLNT123 etc.
SM59 – define physical The logical system needs also be defined as a target
destination and within the R/3 network. Those definitions are done with
characteristics of a logical transaction SM59 and are usually part of the work of
system the R/3 basis team.
The segment defines the structure of the records in an IDoc. They are
defined with transaction WE31 . We will define a structure to send a text
from the text database.
Define a DDic structure Transaction WE31 calls the IDoc segment editor. The
with WE31 editor defines the fields of a single segment structure. The
thus defined IDoc segment is then created as a data
dictionary structure. You can view the created structure
with SE11 and use it in an ABAP as any TABLES
declaration.
Example: To demonstrate the use of the IDoc segment editor we will
set up an example, which allows to send a single text from
the text pool (tables STXH and STXL) as an IDoc. These are
the texts that you can see with SO10 or edit from within
many applications.
We will show the steps to define an IDoc segment
YAXX_THEAD with the DDic structure of THEAD.
Copy the segment To facilitate our work, we will use the "copy-from-template-
structure from a DDic tool", which reads the definition of a DDIC structure and
object inserts the field and the matching definitions as rows in the
IDoc editor. You could of course define the structure
completely manually, but using the template makes it
easier.
The tool in release 4.0b lets you to use both DDIC structures
or another IDoc segment definition as a template.
The definition creates The thus created structure can be edited any time. When
automatically a saving, it will create a data dictionary structure based on
corresponding DDic the definition in WE31. The DDIC structure will retain the
structure same name. You can view the structure as a table
definition with SE11 and use it in an ABAP the same way.
The message type defines the context under which an IDoc is transferred to
its destination. It allows to use the same IDoc file format to use for several
different applications.
Sales order becomes Imagine the situation of sending a purchase order to a
purchase order for supplier. When the IDoc with the purchase order reaches
receiver the supplier, it will be interpreted as a sales order received
from a customer, namely you.
Sales order can be Simultaneously you want to send the IDoc data to the
forwarded and suppliers warehouse to inform it, that a purchase order has
remains a sales order been issued and is on the way.
The valid combinations of message type and IDoc type are stored in table
EDIMSG.
Used for validation The declaration of valid combinations is done to allow
validation, if the system can handle a certain combination.
Illustration 10: EDIMSG: Define Valid Combination Of Message and IDoc Types
The combination of message type and IDoc type determine the processing
algorithm. This is usually a function module with a well defined interface or
a SAP business object and is set up in table EDIFCT.
The entry made her points to a function module, which will
be called when the IDoc is to be processed.
The entries for message code and message function are
usually left blank. They can be used to derive sub types of
messages together with the partner profile used.
R/3 uses the method of logical process codes to detach the IDoc
processing and the processing function module. They assign a logical
name to function instead of specifying the physical function name.
Logical pointer to a The IDoc functions are often used for a serious of message
processing method type/IDoc type combination. It happens that you need to
replace the processing function by a different one. E.g.
when you make a copy of a standard function to avoid
modifying the standard.
Easy replacing of the The combination message type/IDoc will determine the
processing method logical processing code, which itself points to a function. If
the function changes, only the definition of the processing
codes will be changed and the new function will be
immediately effective for all IDocs associated with the
process code.
For inbound processing codes you have to specify the
method to use for the determination of the inbound
function.
Table TBD51 to define For inbound processing you need to tell. whether the
if visible BTCI is function will be capable of dialog processing. This is meant
allowed for those functions, which process the inbound data via call
transaction. Those functions can be replayed in visible batch
input mode to check why the processing might have failed.
The simplest way to create IDocs, is to write an ABAP which simply does it.
The individual ABAP can either be a triggering ABAP
which runs at certain events, e.g. every night, or it
can be an ABAP which does the compete IDoc
creation from scratch.
Triggering ABAP A triggering ABAP would simply try to determine
which IDocs need sending and call the appropriate
IDoc creation routines.
ABAP creates the whole IDoc You may also imagine the ABAP to do all the job. As
this is mostly reinventing the wheel, it is not really
recommended and should be reserved to situation,
where the other solution do not provide an
appropriate mean.
You can use the R/3 message concept to trigger IDocs the same way as
you trigger SapScript printing.
One of the key tables in R/3 is the table NAST. This table
records reminders written by applications. Those reminders
are called messages.
Applications write Every time when an applications sees the necessity to pass
messages to NAST, information to a third party. a message is written to NAST. A
which will be message handler will eventually check the entries in the
processed by a table and cause an appropriate action.
message handler
EDI uses the same The concept of NAST messages has originally been designed
mechanism as printing for triggering SapScript printing. The very same mechanism is
used for IDocs, where the IDoc processor replaces the print
task, as an IDoc is only the paperless form of a printed
document.
Condition technique The messages are usually be created using the condition
can mostly be used technique, a mechanism available to all major R/3
applications.
Printing, EDI and ALE The conditions are set up the same way for any output
use the same trigger media. So you may define a condition for printing a
document and then just change the output media from
printer to IDoc/EDI or ALE.
Standard R/3 provides you with powerful routines, to trigger, prepare and
send out IDocs in a controlled way. There is only a few rare cases, where
you do not want to send IDocs the standard way.
The ABAP RSNAST00 is the standard routine to send
IDocs from entries in the message control. This
program can be called directly, from a batch routine
with variant or you can call the FORM
einzelnachricht_screen(RSNAST00) from any other
program, while having the structure NAST correctly
filled with all necessary information.
RSNAST00 determines if it is If there is an entry in table NAST, RSNAST00 looks up
Here is the principle flow how RSNAST00 processes messages for IDocs.
Instead of waiting for a polling job to create IDocs, they can also be
created immediately after a transaction finishes. This can be done by
assigning an action to an workflow event.
Workflow events are usually Most application fire a workflow event from the
fired from an update routine update routine by calling the function
FUNCTION swe_event_create
SWLD lets install and log You can check if an application fires events by
workflows activating the event log from transaction SWLD.
Calling and saving a transaction will write the event’s
name and circumstances into the log file.
If an application does not fire workflow events
directly, there is still another chance that a workflow
may be used without touching the R/3 original
programs.
Workflow Events are also fired Every application that writes change documents
from change document triggers a workflow event from within the function
module CHANGEDOCUMENT_CLOSE, which is called form
the update processing upon writing the change
document. This will call the workflow processor
FUNCTION swe_event_create_changedocument
Both workflow types are not compatible with each
other with respect to the function modules used to
handle the event.
The workflow types are Both will call a function module whose name they
incompatible but work find in the workflow linkage tables.
according the same principal swe_event_create will look in table SWETYPECOU
while swe_event_create_changedocument would
look in SWECDOBJ for the name of the function
module.
The workflow handler will be If a name is found, the function module will then be
called dynamically called dynamically. This is all to say about the linkage
of the workflow.
The dynamic call looks like the following.
CALL FUNCTION swecdobj-objtypefb
EXPORTING
changedocument_header = changedocument_header
objecttype = swecdobj-objtype
IMPORTING
objecttype = swecdobj-objtype
TABLES
changedocument_position =
changedocument_position.
Applications which write change documents will also try to write change
pointers for ALE operations. These are log entries to remember all modified
data records relevant for ALE.
Most applications write change documents. These
are primarily log entries in the tables CDHDR and
CDPOS.
Change docs remember Change documents remember the modified fields
changes in transaction made to the database by an application. They also
remember the user name and the time when the
modification took place.
Change pointers are log entries to table BDCP which are written every time
a transaction modifies certain fields. The change pointers are designed for
ALE distribution and written by the function CHANGE_DOCUMENT_CLOSE.
Change pointers are written for use with ALE. There are
ABAPs like RBDMIDOC which can read the change pointers
and trigger an IDoc for ALE distribution.
The change pointers are mainly the same as change
documents. They however can be set up differently, so fields
which trigger change documents are not necessarily the
same that cause change pointers to be written.
In order to work with change pointers there are two steps to
be performed
1. Turn on change pointer update generally
2. Decide which message types shall be included for
change pointer update
Activate Change R3 allows to activate or deactivate the change pointer
Pointer Generally update. For this purpose it maintains a table TBDA1. The
decision whether the change pointer update is active is
done with a
Function Ale_Component_Check
Currently (release 40B) this check does nothing else than to
check, if this table has an entry or not. If there is an entry in
TBDA1, the ALE change pointers are generally active. If this
table is empty, change pointers are turned off for everybody
and everything, regardless of the other settings.
The two points read like you had the choice between
turning it on generally or selectively. This is not the case: you
always turn them on selectively. The switch to turn on
generally is meant to activate or deactivate the whole
mechanism.
reading the change The change pointers which have not been processed yet,
pointers which are not can be read with a function module.
yet processed
Call Function 'CHANGE_POINTERS_READ'
RBDMIDOC The ABAP RBDMIDOC will process all open change pointers
and distribute the matching IDocs.
Use Change When you want to send out an IDoc unconditionally every
Documents Instead Of time a transaction updates, you better use the workflow
Change Pointers from the change documents.
IDoc Recipes
IDocs are usually created in a four step process. These steps are: retrieving
the data, converting them to IDoc format, add a control record and
delivering the IDoc to a port.
Collect data from R/3 This is the most individual task in outbound processing.
database You have to identify the database tables and data
dependencies, which are needed in the IDoc to be
sent. The smartest way is usually to select the data
from database into an internal table using SELECT *
FROM dbtable INTO itab ... WHERE ...
Wrap data in IDoc format The collected data must be transformed into ASCII
data and filled into the predefined IDoc segment
structures. The segment definitions are done with
transaction WE31 and the segments allowed in an
IDoc type are set up in transaction WE30. Segment
once defined with WE31 are automatically created
as SAP DDIC structures. They can be viewed with
SE11, however they cannot be edited
Create the IDoc control Every IDoc must be accompanied by a control
record record. This record must contain at least the IDoc
type to identify the syntactical structure of the data
and it must contain the name and role of the sender
and the receiver. This header information is checked
against the partner definitions for outbound. Only if a
matching partner definition exists, the IDoc can be
sent. Partner definitions are set up with transaction
WE20.
Send data to port When the partner profile check passes, the IDoc is
forwarded to a logical port, which is also assigned in
the partner profile. This port is set up with transaction
WE21 and defines the medium to transport the IDoc,
e.g. file or RFC. The RFC destinations are set up with
transaction SM57 and must also be entered in table
TBDLS with an SM31 view. Directories for outbound
locations of files are set up with transaction FILE and
directly in WE21. It also allows to use a function
module which generate file names. Standard
functions for that purpose begin like EDI_FILE*.
When you receive an IDoc the standard way, the data is stored in the IDoc
base and a function module is called, which decides how to process the
received information.
EDID4 - Data Data is stored in table EDID4 (EDID3 up to release 3.xx, EDIDD
up to release 2.xx)
EDIDC - Control An accompanying control record with important context
Record and administrative information is stored in table EDIDC.
Event signals readiness After the data is stored in the IDoc base tables, an event is
fired to signal that there is an IDoc waiting for processing.
This event is consumed by the IDoc handler, which decides,
This is an individual coding part where you need to retrieve the information
from the database and prepare it in the form the recipient of the IDoc will
expect the data
Read data to send The first step is reading the data from the database,
the one you want to send.
FUNCTION Y_AXX_COOKBOOK_TEXT_IDOC_OUTB.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_TDOBJECT) LIKE THEAD-TDOBJECT DEFAULT 'TEXT'
*" VALUE(I_TDID) LIKE THEAD-TDID DEFAULT 'ST'
The physical format of the IDocs records is always the same. Therefore the
application data must be converted into a 1000 character string.
Fill the data segments An IDocs is a file with a rigid formal structure. This allows the
which make up the correspondents to correctly interpret the IDoc information.
IDoc Were it for data exchange between SAP-systems only, the
IDoc segments could be simply structured like the
correspondent DDIC structure of the tables whose data is
sent.
However, IDocs are usually transported to a variety of
legacy systems which do not run SAP. Both correspondents
therefore would agree an IDoc structure which is known to
the sending and the receiving processes.
Transfer the whole All data needs to be compiled in an internal table with the
IDoc to an internal structure of the standard SAP table EDIDD. The records for
table, having the EDIDD are principally made up of a header string describing
structure of EDIDD the segment and a variable length character field (called
SDATA) which will contain the actual segment data.
FORM PACK_LINE TABLES IDOC_DATA USING 'THEAD' E_THEAD.
TABLES: THEAD.
MOVE-CORRESPONDING E:THEAD to Z1THEAD.
MOVE ‚Z1THEAD’ TO IDOC_DATA-SEGNAM.
MOVE Z1THEAD TO IDOC_DATA-SDATA.
APPEND IDOC_DATA.
ENDFORM.“
Fill control record Finally the control record has to be filled with meaningful
data, especially telling the IDoc type and message type.
IF IDOC_CONTRL-SNDPRN IS INITIAL.
SELECT SINGLE * FROM T000 WHERE MANDT EQ SY-MANDT.
MOVE T000-LOGSYS TO IDOC_CONTRL-SNDPRN.
ENDIF.
IDOC_CONTRL-SNDPRT = 'LS'.
* Trans we20 -> Outbound Controls muss entsprechend gesetzt werden.
* 2 = Transfer IDoc immediately
* 4 = Collect IDocs
IDOC_CONTRL-OUTMOD = '2'. "1=imediately, subsystem
CLEAR IDOC_CONTRL.
IDOC_CONTRL-IDOCTP = 'YAXX_TEXT'.
APPEND IDOC_CONTRL.
Summary
• Partner profiles declare the communication medium to
IDoc data can be sent and received through a multitude of different media.
In order to decouple the definition of the media characteristics from the
application using it, the media is accessed via ports.
A port is a logical A port is a logical name for an input/output device. A
name to access a program talks to a port which is presented to it with a
physical input/output common standard interface. The port takes care of the
device translation between the standard interface format and the
device dependent format.
Communication Instead of defining the communication path directly in the
media is defined via a partner profile, a port number is assigned rather. The port
port definition number then designates the actual medium. This allows to
There's a story about some frogs that teaches us all a valuable lesson about life.
RFC provides interface shims for different operating systems and platforms,
which provide the communication APIs for doing RFC from and to R/3.
SAP R/3 is designed as a multi server architecture. Therefore
R/3 is equipped with a communication architecture that
allows data exchange and communication between
individual R/3 application and database servers. This
communication channel also enables R/3 to execute
programs running on a remotely connected server using RFC
technology.
SAP R/3 provides special routines to enable RFC from and to
R/3 for several operation systems. For NT and WINDOWS the
This example demonstrates the use of RFC functions to send data from one
SAP system to a remote destination. The example is a simple
demonstration, how to efficiently and quickly use RFC in your installation.
A text in SAP is an ordinary document, not a customizing or
development object. Therefore texts are never
automatically transported from development system to a
production system. This example helps to copy text into a
remote system.
Step 1: Reading the The ABAP Z_RFC_COPYTEXT selects texts from the text
text documents in the databases STXH and STXL. The ABAP reads the STXH
sending system database only to retrieve the names of the text documents
that match the selection screen. The text itself is read using
the standard SAP function module READ_TEXT.
Step 2: Sending the Then the ABAP calls the function module Y_RFC_SAVE_TEXT
text and saving it in remotely in the destination system. The function runs
the destination system completely on the other computer. The function needs not
to exist in the calling system.
FUNCTION Z_RFC_SAVE_TEXT.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(CLIENT) LIKE SY-MANDT DEFAULT SY-MANDT
*" VALUE(HEADER) LIKE THEAD STRUCTURE THEAD
*" EXPORTING
*" VALUE(NEWHEADER) LIKE THEAD STRUCTURE THEAD
*" TABLES
*" LINES STRUCTURE TLINE
*" EXCEPTIONS
*" ID
*" LANGUAGE
*" NAME
*" OBJECT
*"----------------------------------------------------------------------
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
* CLIENT = SY-MANDT
HEADER = HEADER
* INSERT = ' '
SAVEMODE_DIRECT = 'X'
* OWNER_SPECIFIED = ' '
IMPORTING
* FUNCTION =
NEWHEADER = NEWHEADER
TABLES
LINES = LINES.
ENDFUNCTION.
Program 7: Z_READ_TEXT, a copy of function READ_TEXT with RFC enabled
REPORT Z_RFC_COPYTEXT.
TABLES: THEAD, STXH, RSSCE.
START-OF-SELECTION.
************************************************************************
Summary
• R/3 can exchange its IDoc by calling a program that
resides on the server
• The programs can be written in any language that
supports OLE-2/Active-X technology
• Programming skills are mainly required on the PC side,
e.g. you need to know Delphi, JavaScript or Visual
Basic well
The Microsoft Office suite incorporates with Visual Basic for Applications
(VBA) a fully object oriented language. JavaScript and JAVA are naturally
object oriented. Therefore you can easily connect from JavaScript, JAVA,
WORD, EXCEL and all the other VBA compliant software to R/3 via the
CORBA compatible object library (in WINDOWS known also DLLs or ACTIVE-
X (=OLE/2) components).
Visual Basic is a DCOM Visual Basic is finally designed as an object oriented
compliant programming language compliant to DCOM standard.
language
JavaScript or JAVA are JavaScript is a typical object oriented language which is
naturally object compliant to basic CORBA, DCOM and other popular
languages object standards.
SAP R/3 provides a set of object libraries, which can be
registered with Visual Basic. The library adds object types
to VBA which allow RFC calls to R/3.
DLLs installed with SAPGUI The libraries are installed to the workstation with the
SAPGUI installation. They are technically public linkable
objects, in WINDOWS these are DLLs or ACTIVE-X controls
(which are DLLs themselves).
Object library SAP The object library SAP contains among others the object
provides a method CALL type FUNCTIONS whose basic method CALL performs an
which will call a function RFC call to a specified R/3 function module. With the call
module with all interface you can pass object properties which will be interpreted
parameters
as the interface parameters of the called function
module.
If the RFC call appear not to be working, you should first
try out to call one of the standard R/3 RFC function like
RFC_CALL_TRANSACTION_USING (calls a specified
transaction or RFC_GET_TABLE (returns the content of a
specified R/3 database table).
SAP R/3 provides a set of object libraries, which can be
registered with JavaScript to allow RFC calls to R/3.
The object library SAP contains among others the object
type FUNCTIONS whose basic method CALL performs an
RFC call to a specified R/3 function module.
Try to call standard If the RFC call appears to be not working, you should first
routines for testing try out to call one of the standard R/3 RFC functions like
RFC_CALL_TRANSACTION_USING (calls a specified
transaction) or RFC_GET_TABLE (returns the content of a
specified R/3 database table).
This is a little WORD 97 macro, that demonstrates how R/3 can be called
with a mouse click directly from within WORD 97.
The shown macro calls the function module
RFC_CALL_TRANSACTIION_USING . This function executes
a dynamic call transaction using the transaction code
specified as the parameter.
You can call the macro from within word, by attaching it
to a pseudo-hyperlink. This is done by adding a
MACROBUTTON field to the WORD text. The macrobutton
statement must call the VBA macro R3CallTransaction
and have as the one and only parameter the name of
This WORD 97 document contains a Visual Basic Project which allows to call SAP
R/3 transaction using the SAP automation GUI. The call is done via the WORD field
insertion MACROBUTTON. You must have the SAP Automation GUI or SAP RFC
Development Kit installed on your workstation to give SAP the required OLE
functionality.
Example:
Click to start transaction { MACROBUTTON R3CallTransaction VA02 }
and another call to { MACROBUTTON R3CallTransaction VA02 } .
Illustration 17: Visual Basic code with macros to call R/3 from WORD 97
Illustration 17: HTML Page with a button to call a transaction via RFC
<script language="JavaScript">
<!--
retcd = 0;
exceptions = 0;
// *** SAPLogon() creates an object that has the methods to
// execute a call to an SAP function module
function SAPlogon()
{ fns = new ActiveXObject("SAP.Functions");
trans = fns.Transactions;
conn = fns.connection; /* get a new connection
object */
conn.System = "DEV"; /* Set the system ID (see: SY-SYSID)
*/
conn.user = "userid"; /* set userid (blank for dialog) */
conn.password = ""; /* set password (blank for dialog) */
conn.Client = "100"; /* set password (blank for dialog) */
conn.Language = "E"; /* set language (blank for default)
*/
conn.tracelevel = 6; /* set password (blank for dialog) */
conn.RFCWithDialog = 1; /* true: opens visible session window */
exceptions = 0;
conn.logon(0, 0); /* *** this call creates the object *** */
};
function SAPlogoff()
{ conn.logoff(0, 0);
exceptions = 0;
};
// *** execute the SAP function MODULE "RFC_CALL_TRANSACTION_USING"
// as a method execution of object type SAP.functions
function SAPcallTransaction(tcode)
{ exceptions = 0;
callta = fns.add("RFC_CALL_TRANSACTION_USING");
callta.exports("TCODE") = "VA02";
callta.exports("MODE") = "E";
retcd = callta.call;
conn.logoff();
alert(retcd);
SAPcallTransaction = retcd;
};
// --></script>
<body>
<!—Create an HTML button with a JavaScript call attached -->
Call VA02
<input TYPE = "submit"
VALUE = "VA02"
OnClick = "SAPlogon();
SAPcallTransaction("VA02");
SAPlogoff()"
>
</body>
Problems connecting via RFC can usually be solved by reinstalling the full
SAPGUI and/or checking your network connection with R/3.
Reinstall the full SAPGUI If you have problems to connect to R/3 via the RFC DLLs
then you should check your network installation. It would
be out of the reach of this publication to detail the
causes and solutions when an RFC connection does not
work.
I may say, that in most cases a full install of the SAPGUI
on the computer which runs the calling program will
secure a reliable connection, provided that you can
login to R/3 problem-free with this very same SAPGUI
ALE has become very famous in business circles. While it sounds mysterious
and like a genial solution, it is simply a mean to automate data exchange
between SAP systems. It is mainly meant to distribute data from one SAP
system to the next. ALE is a mere enhancement of SAP-EDI and SAP-RFC
technology.
ALE is an SAP designed Imagine your company has several sister companies in
concept to automatically different countries. Each company uses its own local SAP
distribute and replicate data installation. When one company creates master data eg.
between webbed and material or customer master it is much likely that these data
mutually trusting systems should be known to all associates. ALE allows to
immediately trigger an IDoc sent to all associates as soon
as the master record is created in one system.
Another common scenario is, that a company uses
different installations for company accounting and
production and sales. In that case ALE allows you to copy
the invoices created in SD immediately to the accounting
installation.
ALE defines the logic and the ALE defines a set of database entries, which are called the
triggering events who ALE scenario. These tables contain the information which
describe how and when IDocs IDocs shall be automatically replicated to one or more
are exchanged between the connected R/3-compatible data systems.
systems
ALE is an application put upon To be clear: ALE is not a new technology. It is only a
the IDoc and RFC handful of customizing settings and background routines
mechanisms of SAP that allow timed and triggered distribution of data to and
from SAP or RFC-compliant systems. ALE is thus a mere
enhancement of SAP-EDI and SAP-RFC technology.
ALE is a simple add-on application propped upon the IDoc concept of SAP
R/3. It consists on a couple of predefined ABAPs which rely on the
customisable distribution scenario. These scenarios simple define the IDoc
types and the pairs of partners which exchange data.
ALE defines the logic and the triggering events which describe
how and when IDocs are exchanged between the systems. If the
ALEE engine has determined which data to distribute, it will call
an appropriate routine to create an IDoc. The actual distribution
is then performed by the IDoc layer.
The predefined ALE is of course not restricted to the data types which are already
distribution predefined in the BALE transaction. You can write your ALE
ABAPs can be distribution handlers, which should only comply with some formal
used as standards, e.g. not bypassing the ALE scenarios.
templates for
own
development
ALE uses IDocs All ALE distribution uses IDocs to replicate the data to the target
to transmit data system. The ALE applications check with the distribution scenario
between and do nothing more than calling the matching IDoc function
systems module, which is alone responsible for gathering the requested
data and bringing them to the required data port. You need to
thoroughly understand the IDoc concept of SAP beforehand, in
order to understand ALE
The process is extremely simple: Every time a data object, which
is mentioned in an ALE scenario, changes an IDoc is triggered
form one of the defined triggering mechanisms. These are usually
an ABAP or a technical workflow event.
ABAPs can be Distribution ABAPs are started manually or can be set up as a
used in batch triggered or timed batch job. Sample ABAPs for ALE distribution
routine are those used for master data distribution in transaction BALE, like
the ones behind the transaction BD10, BD12 etc.
Workflow is The workflow for ALE is based on change pointers. Change
triggered from pointers are entries in a special database entity, which record the
change creation or modification of a database object. These change
document pointers are very much like the SAP change documents. They are
also written from within a change document, i.e. from the
function CHANGEDOCUMENT_CLOSE. The workflow is also
triggered from within this function.
Relevance for SAP writes those ALE change pointers to circumvent a major draw
change pointers back of the change documents. Change documents are and
is defined in IMG only are written, if a value of a table column changes, if this
column is associated with a data element which is marked as
relevant for change documents (see SE11). ALE change pointers
use a customized table, which contains the names of those table
fields, which are relevant for change pointers.
ALE is customized via three main transaction. These are SALE , WEDI and
BALE .
This is the core transaction for SALE customizing. Here you find
everything ALE related, which is not already covered by the other
customizing transactions.
WEDI menu
BALE – Central menu This is a menu, which combines most function necessary for ALE
distribution, especially the triggering of manual distribution of
master data or variant configuration or classification.
BALE menu
BDBG - Automatically Good stuff for power developers. It allows to generate all IDoc
Generate IDocs From definitions including segments and IDoc types from the DDIC
A BAPI entries for a BAPI definition.
ALE customizing is relatively staright forward. The only mandatory task is the
definition of the ALE distribution scenario. The other elements did not prove
as being very helpful in practical applications.
SALE All ALE special customizing is done from within the
transaction SALE, which links you to a subset of the
SAP IMG.
Distribution Scenarios The scenario defines the IDoc types and the pairs of
IDoc partners which participate in the ALE distribution.
The distribution scenario is the reference for all ABAPs
and functionality to determine, which data is to be
replicated and who could be the receiving
Basic settings have do be adjusted before you can start working with ALE.
Assign logical system You will finally have to assign a logical system to the clients
to a client involved in ALE or IDoc distribution. This is done in table T000, which
can be edited via SM31 or via the respective SALE tree element.
Suggestion: One You can have many scenarios for eventual different purposes. You
scenario per may also want to put everything in a single scenario. As a rule of
administration area thumb it proved as successful, that you create one scenario per
administrator. If you have only one ALE administrator, there is no use
of having more than one scenario. If you have several departments
with different requirements, that it might be helpful to create one
scenario per department.
Now go on defining The model view display graphically the fro-to relations between logical
partner profiles systems. You now have to generate the partner profiles which are used to
identify the physical means of data transportation between the partners.
A very useful utility is the automatic generation of partner profiles out of the
ALE scenario. Even if you do not use ALE in your installation, it could be only
helpful to define the EDI partners as ALE scenario partners and generate the
partner profiles.
WE20 If you define the first profile for a partner, you have to
create the profile header first. Click an the blank paper
sheet.
There is a very powerful utility which allows to generate most IDoc and ALE
interface objects directly from a BAPI’s method interface.
BDBG The transaction requires a valid BAPI object and method as it
is defined with SWO1. You will also have to specify a
development class and a function to store the generated
IDoc processing function.
Every time BAPI is executed, I will demonstrate the use with the object KNA1 and method
the ALE distribution is CHANGEFROMDATA. This object is executed every time
checked when the data of a customer (table KNA1) is modified, eg.
via transactions XD01 or XD02. This object will automatically
trigger a workflow event after its own execution, which can
Now you can specify the required IDoc types and the
names of the function module and function group for
the processing routines. Note, that the development
class (Entwicklungsklasse) and the function group
(Funktionsgruppe) need to be in your customer name
space, i.e. should begin with Y or Z. The values
proposed on this screen are usually inappropriate.
FUNCTION bapi_customer_changefromdata.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(PI_ADDRESS) LIKE BAPIKNA101 STRUCTURE BAPIKNA101
*" VALUE(PI_SALESORG) LIKE BAPIKNA102-SALESORG
*" VALUE(PI_DISTR_CHAN) LIKE BAPIKNA102-DISTR_CHAN OPTIONAL
*" VALUE(PI_DIVISION) LIKE BAPIKNA102-DIVISION OPTIONAL
*" VALUE(CUSTOMERNO) LIKE BAPIKNA103-CUSTOMER
*" EXPORTING
*" VALUE(PE_ADDRESS) LIKE BAPIKNA101 STRUCTURE BAPIKNA101
*" VALUE(RETURN) LIKE BAPIRETURN STRUCTURE BAPIRETURN
*"----------------------------------------------------------------------
Generated segment For each of the parameters in the BAPIs interface, the
structure from BAPI generator created a segment for the IDoc type. Some
function interface segments are used for IDoc inbound only, others for IDoc
parameter outbound instead. Parameter fields that are not structured
will be combined in a single segment which is placed as first
segment of the IDoc type and contains all these fields. This
collection segment receives the name of the IDoc type. In
our example this is the generated segment
Z1ZAXX_KNA1_CHANGED.
The segment below has been created as a header level
segment and combines all function module parameters,
which do not have a structure, i.e. which are single fields. E.g.
if the BAPI has parameters a parameter i_material LIKE mara-
matnr then it will be placed in the control segment. However
if it is declared i_material STRUCTURE mara then it will create
an own IDoc segment.
ALE allows to define simple filter and transformation rules. These are table
entries, which are processed every time the IDoc is handed over to the
port. Depending on the assigned path this happens either on inbound or
outbound.
SALE Rules are defined with the SALE transaction.
Illustration 40: Tell, where the value for a field should come fromt
Workflow Technology
Summary
• Workflow event linkage allows the execution of
another program when a transaction finishes
• The workflow event linkage mechanism can be easily
used without customizing the full workflow scenarios
• This way we use the workflow engine to chain the
execution of transaction and circumvent the setup of
the SAP Business Workflow™
• There are several independent ways to trigger the
workflow event linkage
Contrary to what you mostly hear about R/3 workflow, it is relatively easy
and mechanical to define a function module as a consecutive action after
another routine raised a workflow event. This can e.g. be used to call the
execution of a transaction after another one has finished.
Every workflow enabled The whole workflow mechanism is based on a very
transaction will call simple principle. Every workflow enabled transaction will
SWE_EVENT_CREATE call directly or indirectly the function module during
SWE_EVENT_CREATE update.
SWE_EVENT_CREATE will The function module SWE_EVENT_CREATE will then
look in a table, e.g. consult a customizing table. For a simple workflow
SWETYPECOU to get the coupling, the information is found in the table
Program 10: This is the call of the type coupled event in release 40B
Every time a change document is written a workflow event for the change
document object is triggered. This can be used to chain unconditionally an
action from a transaction.
CHANGEDOCUMENT_CLOSE The most interesting chaining point for workflow events
is the creation of the change document. Nearly every
transaction writes change documents to the
database. This document is committed to the
database with the function module
CHANGEDOCUMENT_CLOSE. This function will also trigger a
workflow event.
The workflow handler triggered by an event which is
fired from change documents is defined in table
SWECDOBJ . For every change document type a
different event handler can be assigned. This is usually
a function module and the call for it is the following
CALL FUNCTION swecdobj-objtypefb
EXPORTING
changedocument_header = changedocument_header
objecttype = swecdobj-objtype
IMPORTING
objecttype = swecdobj-objtype
TABLES
changedocument_position = changedocument_position.
Program 11: This is the call of the change doc event in release 40B
Program 12: This is the call of the type coupled event in release 40B
Link handler to The function can be registered as a handler for an event. This is
FUNCTION YAXXWF_MAIL_ON_EVENT.
*" IMPORTING
*" VALUE(OBJKEY) LIKE SWEINSTCOU-OBJKEY
*" VALUE(EVENT) LIKE SWETYPECOU-EVENT
*" VALUE(RECTYPE) LIKE SWETYPECOU-RECTYPE
*" VALUE(OBJTYPE) LIKE SWETYPECOU-OBJTYPE
*" TABLES
*" EVENT_CONTAINER STRUCTURE SWCONT
************************************************************************
* This example sends a mail to the calling user and tells
* about the circumstances when the event was fired.
* Just for fun, it lists also all current enqueue locks
************************************************************************
DATA: ENQ LIKE SEQG3 OCCURS 0 WITH HEADER LINE.
DATA: DOC_DATA LIKE SODOCCHGI1.
DATA: MAIL LIKE STANDARD TABLE OF SOLISTI1 WITH HEADER LINE.
DATA: RECLIST LIKE STANDARD TABLE OF SOMLRECI1 WITH HEADER LINE.
MAIL-LINE = 'Event fired by user: &'.
REPLACE '&' WITH SY-UNAME INTO MAIL-LINE.
APPEND MAIL.
*----------------------------------------------------------------------*
MAIL-LINE = 'Object Key: &'.
REPLACE '&' WITH OBJKEY INTO MAIL-LINE.
APPEND MAIL.
*----------------------------------------------------------------------*
MAIL-LINE = 'Event Name: &'.
REPLACE '&' WITH EVENT INTO MAIL-LINE.
APPEND MAIL.
*----------------------------------------------------------------------*
MAIL-LINE = 'Rectype: &'.
REPLACE '&' WITH RECTYPE INTO MAIL-LINE.
APPEND MAIL.
*----------------------------------------------------------------------*
MAIL-LINE = 'Object Type: &'.
REPLACE '&' WITH OBJTYPE INTO MAIL-LINE.
APPEND MAIL.
*----------------------------------------------------------------------*
MAIL-LINE = 'Container contents:'.
APPEND MAIL.
*----------------------------------------------------------------------*
LOOP AT EVENT_CONTAINER.
CONCATENATE EVENT_CONTAINER-ELEMENT EVENT_CONTAINER-VALUE
INTO MAIL-LINE SEPARATED BY SPACE.
APPEND MAIL.
ENDLOOP.
*----- write the current enqueues into the message -(for demo)---------*
MAIL-LINE = 'Active enqueue locks when event was triggered:'.
APPEND MAIL.
CALL FUNCTION 'ENQUEUE_READ' TABLES ENQ = ENQ.
LOOP AT ENQ.
CONCATENATE ENQ-GNAME ENQ-GARG ENQ-GMODE ENQ-GUSR ENQ-GUSRVB
ENQ-GOBJ ENQ-GCLIENT ENQ-GUNAME ENQ-GTARG ENQ-GTCODE
INTO MAIL-LINE SEPARATED BY '/'.
APPEND MAIL.
ENDLOOP.
The BTCI recorder lets you record the screen sequences and values entered
during a transaction. It is one of the most precious tools in R/3 since release
3.1. It allows a fruitful cooperation between programmer and application
consultant.
The section below will show you an example of, how the
transaction SHDB works. With the recording you can easily
create an ABAP, which is able to create BTCI files.
Record a session with You will be asked for a session name and the name of the
transaction SHDB transaction to record. Then you can enter the data into the
transaction as usual.
Now the transaction is The following screens will show the usual transaction screens.
played and all entries All entries that you make are recorded together with the
recorded screen name and eventual cursor positions.
From the recorded After you finished the recording you have the possibility to
session, you can generate ABAP coding from it. This will be a sequence of
generate an ABAP statements which can generate a batch input session,
which is an exact replay of the recorded one.
The generated program contains an include BDCRECXX
which contains all the FORM routines referenced.
Put the coding into a To make the recorded code usable for other program, you
function module should make a function module out of it. Start9ing with
release 4.5A the recorded provides a feature to
automatically generate such a function module. For earlier
release we give the coding of a program which fulfils this
task further down.
*----------------------------------------------------------------------*
FORM GET_MESSAGES TABLES P_MESSTAB STRUCTURE BDCMSGCOLL.
P_MESSTAB[] = BDCMESS[].
LOOP AT P_MESSTAB.
AT LAST.
READ TABLE P_MESSTAB INDEX SY-TABIX.
MOVE-CORRESPONDING P_MESSTAB TO SYST.
ENDAT.
ENDLOOP.
ENDFORM. " GET_MESSAGES
*----------------------------------------------------------------------*
FORM GET_RESULTS TABLES MESSTAB STRUCTURE BDCMSGCOLL
RETURN_VARIABLES STRUCTURE BDWFRETVAR
CHANGING WORKFLOW_RESULT LIKE BDWF_PARAM-RESULT.
PERFORM GET_MESSAGES TABLES MESSTAB.
CASE XCONST-FIDX.
WHEN 'E'.
MOVE-CORRESPONDING IMPORT_PARAMETER TO EXPORT_PARAMETER.
APPEND EXPORT_PARAMETER.
WHEN '*'.
WHEN OTHERS.
APPEND IMPORT_PARAMETER.
ENDCASE.
* --make table parameters for obvious loop fields (fields with index)
IF XCONST-FIDX CA ')*'.
MOVE-CORRESPONDING IMPORT_PARAMETER TO TABLES_PARAMETER.
TABLES_PARAMETER-DBSTRUCT = IMPORT_PARAMETER-DBFIELD.
IF XCONST-FIDX NE '*'.
TABLES_PARAMETER-PARAMETER(1) = 'T'.
ENDIF.
IF XCONST-FIDX CA '*'.
APPEND TABLES_PARAMETER.
ENDIF.
FORMAT COLOR COL_POSITIVE.
ENDIF.
WRITE: / XCONST-FNAM COLOR COL_TOTAL, (60) XCONST-FVAL.
ENDLOOP.
* SORT import_parameter BY parameter.
* DELETE ADJACENT DUPLICATES FROM import_parameter COMPARING parameter.
* SORT tables_parameter BY parameter.
* DELETE ADJACENT DUPLICATES FROM tables_parameter COMPARING parameter.
*----------------------------------------------------------------------*
LOOP AT TABAP.
APPEND TABAP.
MOVE ' CHANGING WORKFLOW_RESULT .' TO TABAP.
APPEND TABAP.
MOVE ' READ TABLE RETURN_VARIABLES INDEX 1.' TO TABAP.
APPEND TABAP.
MOVE ' DOC_NUMBER = RETURN_VARIABLES-DOC_NUMBER.' TO TABAP.
APPEND TABAP.
*----------------------------------------------------------------------*
XCONST-FNAM = 'TMESSTAB'.
XCONST-FREF = 'BDCMSGCOLL'.
XCONST-FVAL = SPACE.
XCONST-FIDX = '*'.
INSERT XCONST INDEX 1.
*----------------------------------------------------------------------*
XCONST-FNAM = 'RETURN_VARIABLES'.
This is an example of how an ANSI X.12 EDI message for a sales order looks
like. The examples do not show the control record (the “envelope”).
EDIFACT looks very much the same.
The example describes a sales order from customer 0111213 for 250
KGM. The fields of a segment are separated by an asterisk (*).
We start with a header record describing the type of message (850). IDocs would
store this information in the control record.
ST*850*000000101~
ST01 Transaction 850 = Purchase Order
ST02 Set control number 453
Signal begin of transaction and identifies sender
BEG*00*NE*123456789**991125**AC~
BEG01 00 - Original transaction, not a resend
BEG02 NE - New Order
BEG03 PO Number 123456789
BEG04 VOID
BEG05 PO Date 25/NOV/1999
BEG07 Client requests an acknowledgment with details and changes
Bill-to party and Ship-to party
N1*BT***0111213~
N101 Bill to (VBPA-PARVW)
N104 0111213 number of bill-to-party ( VBPA-PARNR)
N1*ST***5566789~
N101 Ship to (VBPA-PARVW)
N104 5566789 (VBPA-PARNR)
The item segments for item 01 – 250 kg of material MY1001 for $15.3 per kg
PO1*1*250*KGM*15.3*SR*EAN*MY1001~
PO101 Line item 1 – VBAP-POSNR
PO102 Quantity 250 - VBAP-KWMENG
PO103 Units Kilogram VBAP-MEINS
PO104 $15.30 - VBAP-PREIS
PO106 EAN – Material number
PO107 MY1001 (VBAP-MATNR)
Summary information to verify completeness
CTT*1*2~
CTT01 1 PO1 segments
CTT02 2 some of quantities (ignore unit)
SE*7*000000101~
SE01 7 segments altogether
SE02 Control number 453. This is the same as ST02
17.4 XML
This is an excerpt of an XML EDI message. The difference to all other EDI
standards is, that the message information is tagged in a way, that it can be
displayed in human readable form by a browser.
XML differs from the other standards. It is a document
markup language like its sister and subset HTML.
XML defines additional tags to HTML, which are specially
designed to mark up formatted data information.
The advantage is, that the XML message has the same
information as an EDIFACT or X.12 message. In addition it
can be displayed in an XML capable web browser
XML plug-ins exist often The example shows some XML sales order. In order to be
as JAVA applets for displayed with a standard browser like Internet Explorer 5,
standard browsers there exist plug-ins and JAVA applets that interpret the
XML and translate the XML specific data tags into HTML
form.
EDI Converter
18.1 Converter
Illustration 20: Seeburger™ graphical EDI converter editor with R/3 linkage
Appendix
19.1 Overview of Relevant Transactions
There is a couple of transactions which you should know when working with
IDocs in any form. I suggest to call each transaction at least once to see,
what is really behind.
SALE – ALE and EDI Originally the main menu for ALE operations. However,
Customizing you find here some activities which would belong to
WEDI as well.
These are some very useful routines, that can be used in IDoc processing.
Function IDOC_CTRL_INBOUND_CONVERT
Convert an IDoc control Convert an IDoc control record with structure EDIDD
record into internal format into the version dependent format EDI_DC or EDI
DC40.
Function IDOC_DATA_INBOUND_CONVERT
Convert an IDoc control Convert an IDoc control record from the version
record into internal format dependent format EDI_DC or EDI_DC40 into the version
independent format with structure EDIDD.
Function IDOC_INBOUND_FROM_FILE
Read a file and treat it as an This function reads a specified file and handles it as an
IDoc IDoc package. It stores the IDoc to the IDoc base and
processes it according the preset customizing.
Function EDI_DATA_INCOMING
Read a file and treat it as an Same as Function IDOC_INBOUND_FROM_FILE . This one
IDoc has additional parameters, especially it allows using
logical names instead of a physical filename
Read a file and treat it as an This function reads a specified file and handles it as an
IDoc IDoc package. It stores the IDoc to the IDoc base and
processes it according the preset customizing.
Function IDOC_INBOUND_SINGLE
Central IDoc processing This is an RFC capable function module, which takes an
routine IDoc and its control record as a parameter, stores the
IDoc to the IDoc base and processes it according the
preset customizing.
Function IDOC_INBOUND_SYNCHRONOUS
Predecessor of IDOC_INBOUND_SINGLE for version 3.x.
Function OWN_LOGICAL_SYSTEM_GET
The routine reads the name of the logical system, on
which the program is running. This is currently the entry
found in table T000-LOGSYS. .
Function MASTERIDOC_DISTRIBUTE
Sends an IDoc immediately to the port according while
making use of the appropriate customizing settings.
The ALE functionality comes with a set of transaction which allow the
distribution of important master data between systems. The busiest
argument for installing ALE might be the distribution of the classification
from development to production and back.
R/3 comes with many ALE is only a mean to distribute IDocs in a controlled
predefined ALE scenarios for and event based manner. Here is a collection of the
master data transaction which come already with R/3 and can be
used to distribute data via ALE.
You can always create own If your master data is not with the standard functionality
ALE IDoc routines you can of course create your own function module to
add on to the ALE mechanism.
These is a random listing of interesting web sites dealing with the EDI topic.
They are accurate as of November 1999.
The home page associated with this publication;
http://idocs.de updated program codes and FAQ related to EDI and
SAP.
Data Interchange Standards http://polaris.disa.org/; A page that reads about the
Organisation multiple e-commerce standards with excellent links.
ANSI X12 http://www.x12.org/; Home page of ANSI X.12 standard
with good glossaries and reference section
UN/EDIFACT http://www.unece.org/trade/untdid/: the UN
reference page on EDIFACT; just as chaotic as the
whole standard
XML reference from W3C http://www.w3.org/; the only reference to XML
XML/EDI http://www.geocities.com/WallStreet/Floor/5815/ ; a
good site on XML for use with EDI
More on XML and e- http://www.commerce.net/; deals with EDI for e-
commerce commerce
BISAC X12 EDI Cookbook http://lbbc.lb.com/bisac/ ; gives you an idea of what
X.12 is
IMA Links page http://mlarchive.ima.com/ ; many links to related issues
and a discussion forum