SAP R 3 IDoc Cookbook For EDI and Interf PDF
SAP R 3 IDoc Cookbook For EDI and Interf PDF
htm#_Toc8400369
7 IDocs Customising
7.1 Basic Customising Settings
7.2 Creating an IDoc Segment WE31
7.3 Defining the Message Type (EDMSG)
7.4 Define Valid Combination of Message and IDoc Types
7.5 Assigning a Processing Function (Table EDIFCT )
7.6 Processing Codes
7.7 Inbound Processing Code
9 IDoc Recipes
9.1 How the IDoc Engine Works
9.2 How SAP Standard Processes Inbound IDocs
9.3 How to Create the IDoc Data
9.4 Interface Structure of IDoc Processing Functions
9.5 Recipe to Develop an Outbound IDoc Function
9.6 Converting Data into IDoc Segment Format
10 IDoc Recipes
10.1 How the IDoc Engine Works
10.2 How SAP Standard Processes Inbound IDocs
10.3 How to Create the IDoc Data
10.4 Interface Structure of IDoc Processing Functions
10.5 Recipe to Develop an Outbound IDoc Function
10.6 Converting Data into IDoc Segment Format
13 Workflow Technology
13.1 Workflow in R/3 and Its Use for Development
13.2 Event Coupling (Event Linkage)
13.3 Workflow from Change Documents
13.4 Trigger a Workflow from Messaging
13.5 Example, How to Create a Sample Workflow Handler
18 EDI Converter
18.1 Converter
Alphabetic Index
Last Page
SAP R/3 made an old dream come true: enter your business data once in your computer and trigger all the following activities
automatically, send the data to another computer without typing them in again.
Facts, Know-how and recipes, that is all you can except from this book.
· Establish EDI communication with your clients or suppliers
· communicate in real-time with your legacy and satellite systems
· send and receive data to and from your production machine
· integrate PC or UNIX applications directly in R/3 with RFC
· automate your business from order entry to invoicing
· survey your purchase orders for goods receipt to clearing payments
The authors know, that nobody will believe them: but it is so imple and easy with R/3 to set up an automated business scenario
with IDocs, ALE and Workflow
This book teaches you how SAP R/3 approaches in a coherent concept the electronic data exchange with another computer. With
this know-how
Paper is out - EDI is in
No modern global playing company will allow their suppliers any more, to deliver their order, delivery, transport and invoice
information on paper. They require
Read in this book, why
· EDI will be unevitable in future global business
· EDI projects with R/3 would often cost five to ten times as much as necessary?
· IDocs and ALE are the ideal bridge between R/3 and legacy systems
· IDocs are the framework for a fully automated business workflow
In the technical part of the book you will learn, how to
· customize the R/3 IDoc engine
· interface IDocs with standard converters for X.12, EDIFACT, VDA etc.
· design your own IDoc structures
· write IDoc handler programs in an hour
· trigger IDocs from any R/3 application via messages or workflow
· set up automated workflow based on IDocs
· set up ALE scenarios for automated data replications
Preface
Proper Know-How Saves Costs
We always believed, what has been confirmed over and over again in manifold projects: The main source to cutting project costs, is
a proper education of the team. Giving the team members the same book to read homogenizes the knowledge and sharpens a
common sense within the group.
A Frequently Given Answers Book
This book is the result of thousands of hours of discussion and work with R/3 consultants, developer and clients about interface
development from and to R/3. When we started a new big project in autumn 1998 at the Polar Circle, which involved a big number
of interfaces, I observed curiously, that my developers were ordering numerous books, all being related to EDI.
Well, those books did not say any word about R/3 and it was obvious that they were not very helpful for our team. I consequently
searched the directories for books on R/3 IDocs, but there was nothing. So I started to compile my material on IDocs and ALE with
the intent to publish it in the WWW. Since I submit the site http://idocs.de to some search engines I got an astonishing amount of
hits. Emails asked for a written version of the stuff on the web. So – here it is.
Mystery EDI Unveiled
EDI and e-commerce are miracle words in today’s IT world. Like any other mystery it draws its magic from the ignorance of the
potential users. It is true that there are many fortune making companies in the IT world who specialize on EDI. They sell software
and know-how for giant sums of money. Looking behind the scenes reveals, that the whole EDI business can simply be reduced to
writing some conversion programs. This is not too easy, but the secret of EDI companies is, that the so-called standards are sold for
a lot of money. As soon as you get hold of the documentation, things turn out to be easy.
IDocs, A Universal Tool for Interface Programming
Although R/3 IDocs had been introduced as a tool to implement EDI solution for R/3, it is now accepted as a helpful tool for any kind
of interface programming. While this is not taught clearly in SAP’s learning courses, we put our focus on writing an interface quickly
and easily.
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.
Axel Angeli in December 1999
Logos! Informatik GmbH
email us š [email protected]
or visit http://idocs.de
Table Of Contents
1 Where Has the Money Gone?
1.1 Communication
1.2 Psychology of Communication
1.3 Phantom SAP Standards and a Calculation
1.4 Strategy
1.5 Who Is on Duty?
1.6 Marcus T. Cicero
7 IDocs Customising
7.1 Basic Customising Settings
7.2 Creating an IDoc Segment WE31
7.3 Defining the Message Type (EDMSG)
7.4 Define Valid Combination of Message and IDoc Types
7.5 Assigning a Processing Function (Table EDIFCT )
7.6 Processing Codes
7.7 Inbound Processing Code
9 IDoc Recipes
9.1 How the IDoc Engine Works
9.2 How SAP Standard Processes Inbound IDocs
9.3 How to Create the IDoc Data
9.4 Interface Structure of IDoc Processing Functions
9.5 Recipe to Develop an Outbound IDoc Function
9.6 Converting Data into IDoc Segment Format
10 IDoc Recipes
10.1 How the IDoc Engine Works
10.2 How SAP Standard Processes Inbound IDocs
10.3 How to Create the IDoc Data
10.4 Interface Structure of IDoc Processing Functions
10.5 Recipe to Develop an Outbound IDoc Function
10.6 Converting Data into IDoc Segment Format
13 Workflow Technology
13.1 Workflow in R/3 and Its Use for Development
13.2 Event Coupling (Event Linkage)
13.3 Workflow from Change Documents
13.4 Trigger a Workflow from Messaging
13.5 Example, How to Create a Sample Workflow Handler
18 EDI Converter
18.1 Converter
Alphabetic Index
Last Page
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 language EDI means to exchange information between a sender and a receiver. Both communication partners need to speak the
same language to understand each other.
The language for EDI is comprised of 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.
The time spent on finding an agreement of a common format wastes a great deal of money. 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 at it and remains
quiet. Then he starts programming and tries to squeeze his own data into the structure.
Waiting for a response If it becomes too tedious, a first humble approach takes place 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 meaning It can be even worse: one party proposes a format and the other party does not understand the meaning of some
of a field fields.
Echoing Another field cannot be filled, because the sender does not have the information. Looking closer you find out, that
the information originated 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 term for A real disaster happens if both parties use the same expression for different items. A classic case is the term
different objects “delivery”: What is known as an SD transport in R/3 is known as a delivery in many legacy systems.
There are many other situation where one thing always happens: time is wasted. And time is money.
Face to face The solution is quite simple: bring the people together. Developers of both parties need to sit together, physically face
to face. If each can see what the other person does, they understand each other.
1.4 Strategy
Do not loose your time in plans. Have prototypes developed and take them as a basis.
You cannot predict all Do not stick to the illusion, that a proper design in the beginning will lead to a good result. It is the age old error in
eventualities 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 his uncertainty theorem has proven, that even knowing
uncertainty everything about now, does not allow to predict the future deterministically.
You do not know the If you want to know all the eventualities of a project, you have to be gone through similar projects. It is only your
premises before experience that allows you to make a good plan. However, you usually do a project only once, unless you are a
consultant.
The question is: If you have never been through an EDI project, how will you obtain the necessary experience?
Prototypes The answer is: make a prototype, a little project. Do not loose your time in writing plans and detailed development
requests. Rather start writing a tiny prototype. Introduce this prototype and maintain your solution. Listen to the
arguments and improve the prototype steadily.
This is how you learn.
This is how you succeed.
The illustration above displays a sketch for a typical IDoc communication scenario. The steps are just the same as
with every communication scenario. There is a requesting application, a request handler and a target.
The sketch shows the communication outbound R/3. Data is leaving the R/3 system.
R/3 application creates An R/3 application creates data and updates the database appropriately. An application can be a transaction, a
data stand-alone ABAP Report or any tool that can update a database within R/3.
IDoc engine picks up the If the application thinks that data needs to be distributed to a foreign system, it triggers the IDoc mechanism, usually
request by leaving a descriptive message record in the message table NAST.
The application then either directly calls the IDoc engine or a collector job eventually picks up all due IDoc
messages and determines what to do with them.
IDoc engine determines If the engine believes that data is ready to be sent to a partner system, then it determines the function module which
a handler function from can collect and wrap the required IDoc data into an IDoc.
customising
In IDoc customising, you specify the name of the function module to use. This can either be one which is
predefined by R/3 standard or a user-written one.
IDoc is backup up in R/3 When the IDoc is created it is stored in an R/3 table and from there it is sent to the foreign system.
and sent out
Conversion to standards If the foreign system requires a special conversion, e.g. to XML, EDIFACT or X.12 then
is done by external this job needs to be done by an external converter, like the Seeburger ELKE™ system.
program These converters are not part of R/3.
If you have to decide on a converter solution, we strongly recommend using a plain PC based solution. Conversion
usually requires a lot of fine tuning which stands and falls with the quality of the provided tools.
Sender The sender's identification PROCLNT100 tells the receiver who sent the IDoc. This serves the purpose of filtering
unwanted data and also provides the opportunity to process IDocs differently with respect to the sender.
Receiver The receiver's identification DEVCLNT100 should be included in the IDoc header to make sure that the data has
reached the intended recipient.
IDoc Type The name of the IDoc type MATMAS01 is the key information for the IDoc processor. It is used to interpret the data
in the IDoc records, which otherwise would be nothing more than a sequence of meaningless characters.
Material
...E1MARAM ....00000001234567… base
segment
Plant
...E1MARCM ....PL01…
Segment
Storage
...E1MARDM ....SL01 location
data
Another
...E1MARDM ....SL02 storage
location
Another
...E1MARCM ....PL02
plant
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 same database tables EDID4 for release 4.x and EDID3
are stored in EDID4 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 structures reflects mainly the changes in the R/3 repository, which allow
longer names starting from release 4.x.
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.
eep
imple and
mart
*"----------------------------------------------------------------------
*"*"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
*" VALUE(E_THEAD) LIKE THEAD STRUCTURE THEAD
*" TABLES
*" IDOC_DATA STRUCTURE EDIDD OPTIONAL
*" IDOC_CONTRL STRUCTURE EDIDC OPTIONAL
*" TLINES STRUCTURE TLINE OPTIONAL
*"----------------------------------------------------------------------
* *** --- Reading the application Data --- ****
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = T_HEAD-TDID
LANGUAGE = T_HEAD-TDSPRAS
NAME = T_HEAD-TDNAME
OBJECT = T_HEAD-TDOBJECT
IMPORTING
HEADER = E_THEAD
TABLES
LINES = TLINES.
* *** --- Packing the application data into IDoc
MOVE E_THEAD TO IDOC_DATA-SDATA.
MOVE 'YAXX_THEAD' TO IDOC_DATA-SEGNAM.
APPEND IDOC_DATA.
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.
* *** --- Packing the IDoc control record --- ****
CLEAR IDOC_CONTRL.
IDOC_CONTRL-IDOCTP = 'YAXX_TEXT'.
* *** -- we still should fill more control record info
APPEND IDOC_CONTRL.
ENDFUNCTION.
Figure 1: Sample IDoc outbound function module
We will show a short example that packs SAP R/3 SapScript standard text elements into IDocs and stores them back
to texts in a second routine. The text elements can be edited with SO10.
Text from READ_TEXT Each R/3 standard text element has a header record which is stored in table STXH. The text lines themselves are
stored in a special cluster table. To retrieve the text from the cluster, you will use the standard function module
function READ_TEXT.
Outbound processing The program below will retrieve a text document from the text pool, convert the text lines into IDoc format, and
create the necessary control information.
The first step is reading the data from the application database by calling the function module READ_TEXT.
* *** --- Reading the application Data --- ****
Our next duty is to pack the data into the IDoc record. This means moving the application data to the data part of the
IDoc record structure EDIDD and filling the corresponding segment information.
* *** --- Packing the application data into Idoc
Finally, we have to provide a correctly filled control record for this IDoc. If the IDoc routine is used in a standard
automated 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.
Figure 4: Filling control record information
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWFAP_PAR-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWFAP_PAR-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*"----------------------------------------------------------------------
DATA: XTHEAD LIKE THEAD .
LOOP AT IDOC_DATA.
CASE IDOC_DATA-SEGNAM.
WHEN 'YAXX_THEAD'.
MOVE IDOC_DATA-SDATA TO XTHEAD.
WHEN 'YAXX_TLINE'.
MOVE IDOC_DATA-SDATA TO TLINES.
ENDCASE.
ENDLOOP.
* *** --- Calling the application to process the received data --- ***
EXPORTING
HEADER = XTHEAD
SAVEMODE_DIRECT = 'X'
TABLES
LINES = TLINES.
ADD SY-SUBRC TO OK.
* füllen IDOC_Status
* fill IDOC_Status
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-MSGV1 = IDOC_CONTRL-IDOCTP.
IDOC_STATUS-MSGV2 = XTHEAD.
IDOC_STATUS-MSGID = '38'.
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.
Figure 5: Sample IDoc outbound function module
Inbound processing This example of a simple inbound function module expects as input an IDoc with rows of plain text as created in the
function module outbound example above. The procedure will extract the text name and the text line from the IDoc and hand over the
text data to the function module SAVE_TEXT which will store the text in the text pool.
Unpacking the IDoc data The received IDoc data is processed record by record and data is sorted out according to the segment type.
* *** --- Unpacking the IDoc --- ***
LOOP AT IDOC_DATA.bb
CASE IDOC_DATA-SEGNAM.
WHEN 'YAXX_THEAD'.
PERFORM UNPACK_IDOC TABLES IDOC_DATA USING XTHEAD.
WHEN 'YAXX_TLINE'.
PERFORM UNPACK_TAB TABLES IDOC_DATA TLINES.
ENDCASE.
ENDLOOP.
Finally the processing routine needs to pass a status record to the IDoc processor. This status indicates successful or
unsuccessful processing and will be added as a log entry to the table EDIDS.
* fill IDOC_Status
IF OK NE 0.
IDOC_STATUS-STATUS = '51'.
* IDOC_STATUS-.. = . fill the other fields to log information
ELSE.
IDOC_STATUS-STATUS = '53'.
ENDIF.
APPEND IDOC_STATUS.
Figure 7: Writing a status log
The status value '51' indicates a general error during application processing and the status '53' indicates everything is
OK.
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 with different message types. E.g. The same IDoc structure which is used for a
purchase order can also be used for transmitting a sales order. Imagine the situation that you receive a sales order
from your clients and in addition you receive copies of sales orders sent by an subsidiary of your company.
IDoc Type An IDoc type defines the syntax of the IDoc data. It tells which segments are found in an Idoc and what fields the
segments are made of.
Processing Code The processing code is a logical name that determines the processing routine. This points usually to a function
module, but the processing routine can also be a workflow or an event.
The use of a logical processing code makes it easy to modify the processing routine for a series of partner profiles at
once.
Partner profile Every sender-receiver relationship needs a profile defined. This one determines
· the processing code
· the processing times and conditions
· and in the case of outbound IDocs
· the media port used to send the IDoc and
· the triggers used to send the IDoc
Partner Type The IDoc partners are classified in logical groups. Up to release 4.5 there were the following standard partner types
defined: LS, KU, LI.
LS - Logical Systems The logical system is meant to be a different computer and was primarily introduced for use with the ALE
functionality. You would use a partner type of LS, when linking with a different computer system, e.g. a legacy or
subsystem.
KU - Customer [ger.: The partner type customer is used in classical EDI transmission to designate a partner, that requires a service from
Kunde] your company or is in the role of a debtor with respect to your company, e.g. the payer, sold-to-party, ship-to-party.
LI - Supplier [Ger.: The partner type supplier is used in classical EDI transmission to designate a partner, that delivers a service to your
Lieferant] company. This is typically the supplier in a purchase order. In SD orders you also find LI type partners, e.g. the
shipping agent.
2.2 Terminology
Define the semantic The message type defines the semantic context of an IDoc. The message type tells the receiverhow the message has
context to be interpreted.
Messages are The term message is commonly used in communication, be it EDI or telecommunication. Any stream of data sent to
information for a foreign a receiver with well-defined information in itis known as a message. EDIFACT, ANSI/X.12, XML and others use
partner message the same way.
The term message is Unfortunately, the term message is used in many contexts other than EDI as well. Even R/3 uses the word message
also used for R/3’s for the internal communication between applications. While this is totally OK from the abstract point of view of data
internal communication modelling, it may sometimes cause confusion if it is unclear whether we are referring to IDoc messages or internal
between applications 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. They usually set up a universal file format for
an arbitrary kind of declaration, e.g. Intrastat, Extrastat, Export declarations, monthly reports etc. Depending on the
message type, only applicable fields are filled with valid data. The message type tells the receiver which fields are of
interest at all.
Supplier MAK_CO
sends the message SHIPPING_ADVISE
via the port named INTERNET
using IDoc type SHPADV01
processed with code SHIPMENTLEFT
The Idoc type is defined with transaction WE30, the respective segments are defined with transaction WE31.
Processing Codes
The processing code is a pointer to an algorithm to process an IDoc. It is used to allow more flexibility in assigning the
processing function to an IDoc message.
The logical processing The processing code is a logical name for the algorithm used to process the IDoc. The processing code points itself to
code determines the a method or function, which is capable of processing the IDoc data.
algorithm in R/3 used to
process the IDoc A processing code can point to an SAP predefined or a self-written business object or
function module as long as they comply with certain interface standards.
Allows changing the The processing codes allow you to easily change the processing algorithm. Because the process code can be used for
algorithm easily more than one partner profile, the algorithm can be easily changed for every concerned IDoc.
The processing code The IDoc engine will call a function module or a business object which is expected to perform the application
defines a method or processing for the received IDoc data. The function module must provide exactly the interface parameters which are
function to process an needed to call it from the IDoc engine.
IDoc
3 IDocs Customising
In addition to the writing of the processing function modules, IDoc development requires the definition of the segment
structures and a series of customising settings to control the flow of the IDoc engine.
Summary
Customise basic installation parameters
Define segment structures
Define message types, processing codes
Copy the segment To facilitate our work, we will use the "copy-from-template-tool", which reads the definition of a DDIC structure and
structure from a DDic inserts the field and the matching definitions as rows in the IDoc editor. You could, of course, define the structure
object completely manually, but using the template makes it easier.
The tool in release 4.0b lets you use both DDIC structures or another IDoc segment definition as a template.
The definition The thus created structure can be edited any time. When saving, it will create a data dictionary structure based on the
autpmatically creates a definition in WE31. The DDIC structure will retain the same name. You can view the structure as a table definition
corresponding DDic with SE11 and use it in an ABAP the same way.
structure
EDMSG used as check The entry is only a base entry which tells the system that the message type is allowed. Other transactions will use that
table table as a check table to validate the entry.
Figure 17: EDIMSG: Define valid combination of message and IDoc types
The definition for inbound and outbound IDocs is analogous. Of course, the function module will be different.
Processing with ALE This is the option you would usually choose. It allows processing via the ALE scenarios.
Validate allowed After defining the processing code you have to assign it to one or several logical message types. This declaration is
message types used to validate, if a message can be handled by the receiving system.
Figure 21: Define if the processing can be done in dialog via call transaction
Validate allowed After defining the processing code, you have to assign it to one or several logical message types. This declaration is
message types used to validate, if a message can be handled by the receiving system.
The examples above show only the association with a function module. You can also define business objects with
transaction SWO1 and define them as a handler. For those familiar with the object model of R/3, it may be a design
decision. In this book, we will deal with the function modules only.
NAST messages are Creating NAST messages is a standard functionality in most of the SAP core applications. Those applications - e.g.
created by application by VA01, ME21 - perform calls to the central function module MESSAGING of group V61B. The function module uses
calling function module customizing entries, mainly those of the tables T681* to T685*.
MESSAGING
NAST contains object A NAST output message is stored as a single record in the table NAST. The record
key, sender and receiver stores all information that is necessary to create an IDoc. This includes mainly an object
key to identify the processed object and application to the message handler and the sender and receiver information.
Programs RSNAST00 The messages are typically processed by
and RSNASTED provide
versatile subroutines for FORM ENTRY in PROGRAM RSNAST00.
NAST processing
If we are dealing with printing or faxing and
FORM EDI_PROCESSING in PROGRAM RSNASTED.
The following piece of code does principally the same thing as RSNAST00 does and makes full use of all
customizing settings for message handling.
FORM einzelnachricht IN TABLES: NAST.
PROGRAM RSNAST00
SELECT * FROM NAST ...
PERFORM einzelnachricht IN PROGRAM RSNAST00
Programs are The processing routine for the respective media and message is customized in the table TNAPR. This table records
customized in table the name of a FORM routine, which processes the message for the chosen media and the name of an ABAP where
TNAPR this FORM is found.
NAST-MANDT = SY-MANDT.
NAST-KSCHL = 'ZEDIK'.
NAST-KAPPL = 'V1'.
NAST-OBJKY = '0012345678'.
NAST-PARNR = 'D012345678'.
PERFORM einzelnachricht_screen(RSNAST00).
Calling einzelnachricht_screen determines how the message is processed. If you want to force the
IDoc-processing you can call it directly:
TNAPR-PROGN = ''.
TNAPR-ROUTN = 'ENTRY'.
PERFORM edi_processing(RSNASTED).
SWLD lets install and log You can check if an application fires events by activating the event log from transaction SWLD. Calling and saving a
workflows 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 Every application that writes change documents triggers a workflow event from within the function module
fired from change CHANGEDOCUMENT_CLOSE, which is called form the update processing upon writing the change document. This
document 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 find in the workflow linkage tables. swe_event_create will look in
incompatible but work table SWETYPECOU while swe_event_create_changedocument would look in SWECDOBJ for the name of the
according the same function module.
principal
The workflow handler will If a name is found, the function module will then be called dynamically. This is all to say
be called dynamically 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.
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, can be read with a function module.
pointers which are not
yet processed Call Function 'CHANGE_POINTERS_READ'
RBDMIDOC The ABAP RBDMIDOC will process all open change pointers and distribute the matching IDocs.
Use Change Documents When you want to send out an IDoc unconditionally every time a transaction updates, you better use the workflow
Instead Of Change from the change documents.
Pointers
Example A complex example for a function module, which collects the change pointers, can be examined in:
MASTERIDOC_CREATE_SMD_DEBMAS .
This one reads change pointers for debtors (customer masters). During the processing, it calls the actual IDoc
creating module MASTERIDOC_CREATE_DEBMAS .
To summarize the change pointer concept
· Change pointers record relevant updates of transaction data
· Change pointers are written separate from the change documents, while at the same time
· Change pointers are evaluated by a collector run
BDCPS Change pointer: Status
BDCP Change pointer
BDCPV A view with BDCP and BDCPS combined: Change pointer with status
TBDA2 Declare activate message types for change pointers with view V_TBDA2.or transaction BD50 or .
SALE -> Activate change pointers for message types
TBD62 The view V_TBD62 defines those fields which are relevant for change pointer creation. The table is evaluated by the
CHANGE_DOCUMENT_CLOSE function. The object is the same used by the change document. To find out the
object name, look for CHANGE_DOCUMENT_CLOSE in the transaction you are inspecting or see table CDHDR for
traces.
Figure 26: Tables involved in change pointers processing
5 IDoc Recipes
This chapter will show you how an IDoc function is principally designed and how R/3 processes the IDocs. I cannot stop
repeating, that writing IDoc processing routines is a pretty simple task. With a number of recipes on hand, you can easily
build your own processors.
*" IMPORTING
*" IMPORTING
*"----------------------------------------------------------------------
*"*"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
*" VALUE(E_THEAD) LIKE THEAD STRUCTURE THEAD
*" TABLES
*" IDOC_DATA STRUCTURE EDIDD OPTIONAL
*" IDOC_CONTRL STRUCTURE EDIDC OPTIONAL
*" TLINES STRUCTURE TLINE OPTIONAL
*" EXCEPTIONS
*" FUNCTION_NOT_EXIST
*" VERSION_NOT_FOUND
*"----------------------------------------------------------------------
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = ID
LANGUAGE = LANGUAGE
NAME = NAME
OBJECT = OBJECT
TABLES
LINES = LINES.
* now stuff the data into the Idoc record format
LOOP AT LINES.
PERFORM PACK_LINE TABLES IDOC_DATA USING 'THEAD' LINES.
ENDLOOP.
ENDFUNCTION.
TABLES: THEAD.
MOVE-CORRESPONDING E:THEAD to Z1THEAD.
MOVE ‚Z1THEAD’ TO IDOC_DATA-SEGNAM.
MOVE Z1THEAD TO IDOC_DATA-SDATA.
APPEND IDOC_DATA.
ENDFORM.“
Figure 31: Routine to move the translate to IDoc data
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.
6 IDoc Recipes
This chapter will show you how an IDoc function is principally designed and how R/3 processes the IDocs. I cannot stop
repeating, that writing IDoc processing routines is a pretty simple task. With a number of recipes on hand, you can easily
build your own processors.
*" IMPORTING
*" IMPORTING
*"----------------------------------------------------------------------
*"*"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
*" VALUE(E_THEAD) LIKE THEAD STRUCTURE THEAD
*" TABLES
*" IDOC_DATA STRUCTURE EDIDD OPTIONAL
*" IDOC_CONTRL STRUCTURE EDIDC OPTIONAL
*" TLINES STRUCTURE TLINE OPTIONAL
*" EXCEPTIONS
*" FUNCTION_NOT_EXIST
*" VERSION_NOT_FOUND
*"----------------------------------------------------------------------
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = ID
LANGUAGE = LANGUAGE
NAME = NAME
OBJECT = OBJECT
TABLES
LINES = LINES.
* now stuff the data into the Idoc record format
LOOP AT LINES.
PERFORM PACK_LINE TABLES IDOC_DATA USING 'THEAD' LINES.
ENDLOOP.
ENDFUNCTION.
TABLES: THEAD.
MOVE-CORRESPONDING E:THEAD to Z1THEAD.
MOVE ‚Z1THEAD’ TO IDOC_DATA-SEGNAM.
MOVE Z1THEAD TO IDOC_DATA-SDATA.
APPEND IDOC_DATA.
ENDFORM.“
Figure 36: Routine to move the translate to IDoc data
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.
The example shows you that sales orders can be exchanged in different file formats. There may be some customers
who accept the latest IDoc format ORDERS02, while others still insist on receiving the old format ORDERS01.
The IDoc format for sales orders would also be used to transfer a purchase requisition. While the format remains the
same, the different message type signals that it is not an actual order but a request.
Port versions differ in The difference between the port types is mainly the length of some fields. E.g. does port type 3 allow segment names
length of fields up to 30 characters in length, while port type 3 is constrained to a maximum segment name of 8 characters.
*"----------------------------------------------------------------------
*"*"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.
Figure 39: Z_READ_TEXT, a copy of function READ_TEXT with RFC enabled
REPORT Z_RFC_COPYTEXT.
************************************************************************
EXPORTING
ID = THEADS-TDID
LANGUAGE = THEADS-TDSPRAS
NAME = THEADS-TDNAME
OBJECT = THEADS-TDOBJECT
IMPORTING
HEADER = THEAD
TABLES
LINES = TLINES
EXCEPTIONS
OTHERS = 8.
************************************************************************
* RFC call to function in partner system that stores the text there *
************************************************************************
CALL FUNCTION 'Z_RFC_SAVE_TEXT'
DESTINATION ’PROCLNT100’
EXPORTING
HEADER = THEAD
TABLES
LINES = TLINES.
EXCEPTIONS
OTHERS = 5.
Figure 40: Program to copy text modules into a remote system via RFC
DESTINATION ‘RFC_EXEC’
EXPORTING COMMAND = ’dir c:\sapgui >input’
The example call above would execute the following when run on a DOS system.
command.com /c copy c:\config.sys c:\temp
rfc_remote_pipe rfc_remote_pipe will call RFCEXEC, execute the command line interpreter with the parameter string and catch the
output into an internal table.
CALL FUNCTION ‘RFC_REMOTE_PIPE’
DESTINATION ‘RFC_EXEC’
EXPORTING COMMAND = ’dir c:\sapgui >input’
The example call above would execute the following when run on a DOS system,
command.com /c dir c:\sapgui >input
while the file input is caught by rfc_remote_pipe and returned to the calling system.
Process incoming files A common application for the use of rfc_remote_pipe is to automatically check a file system for newly arrived files
and process them. For that purpose, you would create three directories, e.g. the following.
x:\incoming
x:\work
x:\processed
The statement retrieves the file list with rfc_remote_pipe into an R/3 internal table.
dir x:\incoming /b
Then the files are move into a working directory.
move x:\incoming\file x:\work
Finally the files are processed and moved into an archive directory.
9 Workflow Technology
There are two faces of workflow in R/3. One is the business oriented workflow design as it is taught in universities. This is
implemented by the SAP Business Workflow™. However, the workflow is also a tool to link transactions easily. It can be
used to easily define execution chains of transactions or to trigger user actions without the need to modify the SAP
standard code. This can even be achieved without laboriously customising the HR related workflow settings.
Summary
Workflow event linkage allows the execution of another program when a transaction finishes.
The workflow event linkage mechanism can be easily used without customising 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.
Americans work hard because they are optimists.
EXPORTING
objtype = typecou-objtype
objkey = objkey
event = event
generic_rectype = typecou-rectype
IMPORTING
rectype = typecou-rectype
TABLES
event_container = event_container
EXCEPTIONS
OTHERS = 1.
Figure 41: This is the call of the type coupled event in release 40B
Figure 42: This is the call of the change doc event in release 40B
In addition, change Change pointers are created by calling FUNCTION CHANGEDOCUMENT_CLOSE which writes the usual change
pointers for ALE are documents into table CDHDR and CDPOS. This function then calls the routine CHANGE_POINTERS_CREATE,
written which creates the change pointers.
CALL FUNCTION 'CHANGE_POINTERS_CREATE'
EXPORTING
change_document_header = cdhdr
TABLES
change_document_position = ins_cdpos.
Figure 43: This is the call of the type coupled event in release 40B
TABLES: NAST.
FORM ENTRY USING RETURN_CODE US_SCREEN.
* Here you go
na call your workflow action
RETURN_CODE = 0.
SY-MSGID = '38'.
SY-MSGNO = '000'.
SY-MSGNO = 'I'.
SY-MSGV1 = 'Workflow called via NAST'.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
MSG_ARBGB = SYST-MSGID
MSG_NR = SYST-MSGNO
MSG_TY = SYST-MSGTY
MSG_V1 = SYST-MSGV1
MSG_V2 = SYST-MSGV2
MSG_V3 = SYST-MSGV3
MSG_V4 = SYST-MSGV4
EXCEPTIONS
OTHERS = 1.
ENDFORM.
NAST must be declared In addition, you need to declare the table NAST with a tables statement public in the ABAP where the form routinely
public in the called resides. When the form is called, the variable NAST is filled with the values of the calling NAST message.
program
EXPORTING
objtype = typecou-objtype
objkey = objkey
event = event
generic_rectype = typecou-rectype
IMPORTING
rectype = typecou-rectype
TABLES
event_container = event_container
EXCEPTIONS
OTHERS = 1.
Listing 1: Call of the type coupled event in release 40B
Template for workflow Release 40B provides the function module WF_EQUI_CHANGE_AFTER_ASSET which could be used as a template
handler for the interface. So we will copy it and put our coding in instead..
FUNCTION Z_WORKFLOW_HANDLER.
*"*"Lokale Schnittstelle:
*" 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
*" EXCEPTIONS
*" NO_WORKFLOW
RECEIVERS-EXPRESS = ' '.
RECEIVERS-RECEIVER = SY-SUBRC.
APPEND RECEIVERS.
DOCUMENT_DATA-OBJ_DESCR = OBJ_KEY.
CONTENT = OBJ_KEY.
APPEND CONTENT.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
Link handler to caller The function can be registered as a handler for an event. This is done with transaction SWLD.
Event logging If you do not know the object type that will trigger the event, you can use the event log. You have to activate it from
SWLD and then execute the event firing transaction. When the event has been fired, it will trace it in the event log.
Figure 44: Transaction SWLD to define event linkage and see event log
All workflow handlers are called via RFC to a dummy destination WORKFLOW_LOCAL_000 where 000 is to be
replaced by the client number.
Most errors are caused by following reasons:
Hit list of common errors · You forgot to set the RFC flag in the interface definition of your event handling function module.
· There is a syntax error in your function module (check with generate function group).
· You mistyped something when defining the coupling.
· The internal workflow destination WORKFLOW_LOCAL_000 is not defined.
SM58 to display what If you think your handler did not execute at all, you can check the list of pending background tasks with transaction
happened to your event SM58. If your event is not there, it has either never been triggered (so your tables SWETYPEENA and
SSWETYPEOBJ may have the wrong entries) or your event handler executed indeed and probably may have done
something other than you expected. Ergo: your mistake.
Read carefully the help Your event handler function is called IN BACKGROUND TASK. You may want to read carefully the help on this
for CALL FUNCTION .. topic in the SAP help. (help for “call function” from the editor command line)
IN BACKGROUND TASK
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 also lists all current enqueue locks
DATA: ENQ LIKE SEQG3 OCCURS 0 WITH HEADER LINE.
*----------------------------------------------------------------------*
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.
IF ENQ[] IS INITIAL.
MAIL-LINE = ‚*** NONE ***’.
APPEND MAIL.
ENDIF.
*----------------------------------------------------------------------*
· fill the receiver list
REFRESH RECLIST.
RECLIST-RECEIVER = ‚USERXYZ’.
RECLIST-REC_TYPE = ‚B’.
RECLIST-EXPRESS = ‚ ‚.
· reclist-express = ‚X’. „will pop up a notification on receiver screen
APPEND RECLIST.
*----------------------------------------------------------------------*
CLEAR DOC_DATA.
DOC_DATA-OBJ_NAME = ‚WF-EVENT’.
DOC_DATA-OBJ_DESCR = ‚Event triggered by workflow type coupling’.
DOC_DATA-OBJ_SORT = ‚WORKFLOW’.
· doc_data-obj_expdat
· doc_data-sensitivty
· doc_data-obj_prio
· doc_data-no_change
*----------------------------------------------------------------------*
EXPORTING
DOCUMENT_DATA = DOC_DATA
* DOCUMENT_TYPE = ‚RAW’
* PUT_IN_OUTBOX =‚‚
· IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
* OBJECT_HEADER =
OBJECT_CONTENT = MAIL
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS =1
DOCUMENT_NOT_SENT =2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR =5
X_ERROR =6
ENQUEUE_ERROR =7
OTHERS = 8.
*----------------------------------------------------------------------*
ENDFUNCTION.
Listing 3: Send an SAP office mail triggered by a workflow event (full example)
Data Object
Sender
Receiver
MATMAS
Material Master
R3NYX
New York Office
R3VEN
Venice Office
MATMAS
Material Master
R3NYX
New York Office
R3PAR
Paris Office
MATMAS
Material Master
R3NYX
New York Office
R3LAX
Los Angeles
MATMAS
Material Master
R3PAR
Paris Office
R3VEN
Venice Office
MATMAS
Material Master
R3LAX
Los Angeles
R3VEN
Venice Office
DEBMAS
Debitor Master
R3PAR
Paris Office
R3VEN
Venice Office
DEBMAS
Debitor Master
R3PAR
Paris Office
R3LAX
Los Angeles
CREMAS
Creditor Master
R3NYX
New York Office
R3VEN
Venice Office
CREMAS
Creditor Master
R3PAR
Paris Office
R3VEN
Venice Office
CREMAS
Creditor Master
R3LAX
Los Angeles
R3VEN
Venice Office
Figure 46: Scenario in tabular form
WEDI - IDoc Here you define all the IDoc related parts, which make up most of the work related to ALE.
Administration
Figure 48: WEDI menu
BALE – Central menu This is a menu which combines most functions necessary for ALE distribution, especially the triggering of manual
distribution of master data or variant configuration or classification.
BDBG - Automatically Good stuff for power developers. It allows you to generate all IDoc definitions including segments and IDoc types
generate IDocs From A
Logical System Before we start, we need to maintain some logical systems. These are names for the RFC destinations which are used
as communication partners. An entry for the logical system is created in the table TBDLS.
Assign logical system to Finally. you will have to assign a logical system to the clients involved in ALE or IDoc distribution. This is done in
a client 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 may also want to put everything in a single
scenario per scenario. As a rule of thumb, it proved as successful that you create one scenario per administrator. If you have only
administration area one ALE administrator, there is no use having more than one scenario. If you have several departments with
different requirements, then it might be helpful to create one scenario per department.
distr_02b_mestyp_added.gif (5202
bytes)
Now go on defining The model view displays graphically the from-to relations between logical systems. You now have to generate the
partner profiles partner profiles which are used to identify the physical means of data transportation between the partners.
The values give here are not really important. The partner class is only a classification value. You can give an
arbitrary name in order to group the type of partners, e.g. EDI for external ones, ALE for internal ones, and IBM for
connection with IBM OS/390 systems.
There have been two profiles generated. The one is for MATMAS, which we explicitly assigned in the distribution
scenario. The second one is a mandatory IDoc type with the name SYNCH ,which is used for RFC control
information and synchronisation. This one is only created if it does not yet exist.
Here is a detail view of the parameters generated. The receiver port is the RFC destination that had been created for
TESTTARGET with SM59.
Data goes to table EDP13.
Figure 68: Specify a name for the created message type. The message type will be created in table EDMSG .
Figure 69: Define the names of the processing function modules and the associated IDoc types.
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.
Result report Click on generated objects to see what was generated in detail.
A detailed report is shown. The report is clickable so that you can directly view the generated objects. The hotspot
will appearwhen you move over a clickable object.
The transaction has generated an IDoc type.
The IDoc type is generated with a header section containing the interface values of the object and a data section with
the remaining fields of the object data structure.
The BAPIs interface definition looks like that.
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 BAPI's interface, the generator created a segment for the IDoc type. Some segments
structure from BAPI are used for IDoc inbound only; others for IDoc outbound instead. Parameter fields that are not structured will be
function interface combined in a single segment which is placed as first segment of the IDoc type and contains all these fields. This
parameter 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. those which are single fields. For example, . 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 its own IDoc segment.
Figure 74: Tell where the value for a field should come from
Figure 77: 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>
Figure 78: JavaScript example to call an R/3 function module via OLE/RFC
Now the transaction is The following screens will show the usual transaction screens. All entries that you make are recorded together with
played and all entries the screen name and eventual cursor positions.
recorded
From the recorded After you finished the recording, you have the possibility to generate ABAP coding from it. This will be a sequence
session, you can of statements which can generate a batch input session, which is an exact replay of the recorded one.
generate an ABAP
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 programs, you should make a function module out of it. Starting with
function module release 4.5A the recorded code provides a feature to automatically generate such a function module. For earlier
releases, we give the coding of a program which fulfils this task further down.
* INCLUDE ZZBDCRECXX *
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
REFRESH BDCDATA.
ENDFORM.
*---------------------------------------------------------------------*
FORM CLOSE_GROUP.
ENDFORM.
*----------------------------------------------------------------------*
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
FIELD-SYMBOLS: <FLD>.
ASSIGN (FNAM) TO <FLD>.
CLEAR BDCDATA.
DESCRIBE FIELD FVAL TYPE SY-FTYPE.
CASE SY-FTYPE.
WHEN 'C'.
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
FORMAT RESET.
ULINE.
SELECT SINGLE * FROM TLIBG WHERE AREA EQ FUGR.
IF SY-SUBRC NE 0.
MESSAGE I000(38) WITH 'Function Pool' FUGR 'does not exit'.
EXIT.
ENDIF.
MOVE 'PERFORM OPEN_GROUP.' TO TABAP.
APPEND TABAP.
*----------------------------------------------------------------------*
XCONST-FNAM = 'INPUT_METHOD'.
XCONST-FREF = 'BDWFAP_PAR-INPUTMETHD'.
XCONST-FVAL = 'A'.
APPEND XCONST.
ENDFORM.
*---------------------------------------------------------------------*
FORM CLOSE_GROUP.
LOOP AT XCONST.
IMPORT_PARAMETER-PARAMETER = XCONST-FNAM.
IMPORT_PARAMETER-DBFIELD = XCONST-FREF.
CONCATENATE '''' XCONST-FVAL '''' INTO
IMPORT_PARAMETER-DEFAULT.
IMPORT_PARAMETER-OPTIONAL = 'X'.
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.
WRITE: / TABAP COLOR COL_KEY.
ENDLOOP.
*----------------------------------------------------------------------*
REPLACE '##' WITH XTCODE INTO SHORT_TEXT.
WRITE: / FUNCNAME COLOR COL_NEGATIVE.
WRITE: / SHORT_TEXT.
SELECT SINGLE * FROM TFDIR WHERE FUNCNAME EQ FUNCNAME.
IF SY-SUBRC EQ 0.
MESSAGE I000(38) WITH 'Function' FUNCNAME 'already exists'.
PERFORM SUCCESS_MESSAGE
USING 'Function' FUNCNAME 'already exists' SPACE ' '.
EXIT.
ENDIF.
CALL FUNCTION 'RPY_FUNCTIONMODULE_INSERT'
EXPORTING
FUNCNAME = FUNCNAME
FUNCTION_POOL = FUGR
SHORT_TEXT = SHORT_TEXT
TABLES
IMPORT_PARAMETER = IMPORT_PARAMETER
EXPORT_PARAMETER = EXPORT_PARAMETER
TABLES_PARAMETER = TABLES_PARAMETER
CHANGING_PARAMETER = CHANGING_PARAMETER
EXCEPTION_LIST = EXCEPTION_LIST
PARAMETER_DOCU = PARAMETER_DOCU
SOURCE = TABAP
EXCEPTIONS
OTHERS = 7.
IF SY-SUBRC NE 0.
MESSAGE I000(38) WITH 'Error creating' 'Function ' FUNCNAME.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
APPEND '*' TO TABAP.
MOVE 'PERFORM BDC_TRANSACTION_MODE USING I_TCODE INPUT_METHOD.'
TO TABAP.
APPEND TABAP.
*----------------------------------------------------------------------*
XTCODE = TCODE.
STR255 = FUNCNAME.
REPLACE '$1' WITH XTCODE INTO STR255.
CONDENSE STR255 NO-GAPS.
FUNCNAME = STR255.
*----------------------------------------------------------------------*
XCONST-FNAM = 'I_TCODE'.
XCONST-FREF = 'SYST-TCODE'.
XCONST-FVAL = TCODE.
XCONST-FIDX = SPACE.
INSERT XCONST INDEX 1.
*----------------------------------------------------------------------*
MOVE 'PERFORM GET_RESULTS TABLES TMESSTAB' TO TABAP.
APPEND TABAP.
MOVE ' RETURN_VARIABLES' TO TABAP.
APPEND TABAP.
MOVE ' USING ''1'' ' TO 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'.
XCONST-FREF = 'BDWFRETVAR'.
XCONST-FVAL = SPACE.
XCONST-FIDX = '*'.
INSERT XCONST INDEX 1.
*----------------------------------------------------------------------*
XCONST-FNAM = 'WORKFLOW_RESULT'.
XCONST-FREF = 'BDWF_PARAM-RESULT'.
XCONST-FVAL = SPACE.
XCONST-FIDX = 'E'.
INSERT XCONST INDEX 1.
*----------------------------------------------------------------------*
XCONST-FNAM = 'APPLICATION_VARIABLE'.
XCONST-FREF = 'BDWF_PARAM-APPL_VAR'.
XCONST-FIDX = 'E'.
INSERT XCONST INDEX 1.
*----------------------------------------------------------------------*
XCONST-FNAM = 'DOC_NUMBER'.
XCONST-FREF = SPACE.
XCONST-FIDX = 'E'.
INSERT XCONST INDEX 1.
ENDFORM.
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
TABAP = '*'.
APPEND TABAP.
CONCATENATE
'PERFORM BDC_DYNPRO USING ''' PROGRAM '''' ' ''' DYNPRO '''.'
INTO TABAP.
APPEND TABAP.
ENDFORM.
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
DATA: XFVAL LIKE BDCDATA-FVAL.
CLEAR XCONST.
CASE FNAM.
WHEN 'BDC_OKCODE' OR 'BDC_CURSOR' OR 'BDC_SUBSCR'.
CONCATENATE '''' FVAL '''' INTO XFVAL.
PERFORM ADD_BDCFIELD USING FNAM XFVAL.
WHEN OTHERS.
SPLIT FNAM AT '(' INTO XCONST-FREF XCONST-FIDX.
CONCATENATE 'I_' FNAM INTO XCONST-FNAM.
TRANSLATE XCONST-FNAM USING '-_(_) '." No dashes allowed
MOVE FVAL TO XCONST-FVAL.
TRANSLATE XCONST-FVAL TO UPPER CASE.
APPEND XCONST.
PERFORM ADD_BDCFIELD USING FNAM XCONST-FNAM.
ENDCASE.
ENDFORM. " BDC_FIELD
*---------------------------------------------------------------------*
FORM ADD_BDCFIELD USING FNAM XFNAM.
CONCATENATE
'PERFORM BDC_FIELD USING ''' FNAM ''' ' INTO TABAP.
STRL1 = STRLEN( TABAP ) + STRLEN( XFNAM ).
IF STRL1 GT 76.
APPEND TABAP.
CLEAR TABAP.
ENDIF.
CONCATENATE TABAP XFNAM '.' INTO TABAP SEPARATED BY SPACE.
APPEND TABAP.
ENDFORM. " add_bdcfield usinf fnam fval.
*----------------------------------------------------------------------*
FORM SUCCESS_MESSAGE USING V1 V2 V3 V4 OK.
CONCATENATE V1 V2 V3 V4 INTO SY-LISEL SEPARATED BY SPACE.
REPLACE '##' WITH FUNCNAME INTO SY-LISEL.
MODIFY LINE 1.
IF OK EQ SPACE.
MODIFY LINE 1 LINE FORMAT COLOR COL_NEGATIVE.
ELSE.
Test the function module The created function module should work without modification for testing at least. However, you probably will need
and add eventual loops to modify it, e.g. by adding a loop for processing multiple entries in a table control (scroll area).
for detail processing.
EDIFACT/UN EDIFACT was originally a European standard. It became popular when chosen by the UNO for their EDI
transactions. EDIFACT is a document description language. EDIFACT is very similar to ANSI X.12 and differs
merely in syntactical details and the meaning of tags.
XML XML and the internet page description language HTML are both subsets derived from the super standard SGML...
The patent and trademark holder of XML (W3C, http://w3c.org) describes the advantages of XML very precisely as
follows.
1. XML is a method for putting structured data in a text file.
2. XML looks a bit like HTML but isn't HTML.
3. XML is text, but isn't meant to be read.
4. XML is verbose, but that is not a problem.
5. XML is license-free and platform-independent.
And XML is fully integrated in the world wide web. It can be said briefly: XML sends the form just as the customer
entered the data.
13.3 XML
This is an excerpt of an XML EDI message. The difference from 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
<!DOCTYPE Sales-Order PUBLIC>
Figure 86: XML Order form as displayed in a browser after interpretation by a JAVA applet
XML plug-ins exist often The example shows an XML sales order. In order to be displayed with a standard browser like Internet Explorer 5,
as JAVA applets for plug-ins and JAVA applets exist that interpret the XML and translate the XML specific data tags into HTML form.
standard browsers
ST01
ST02
Transaction 850 = Purchase Order
Set control number 453
Signal begin of transaction and identifies sender
BEG*00*NE*123456789**991125**AC~
BEG01
BEG02
BEG03
BEG04
BEG05
BEG07
00 - Original transaction, not a resend
NE - New Order
PO Number 123456789
VOID
PO Date 25/NOV/1999
Client requests an acknowledgment with details and changes
Bill-to party and Ship-to party
N1*BT***0111213~
N101
N104
Bill to (VBPA-PARVW)
0111213 number of bill-to-party ( VBPA-PARNR)
N1*ST***5566789~
N101
N104
Ship to (VBPA-PARVW)
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
PO102
PO103
PO104
PO106
PO107
Line item 1 – VBAP-POSNR
Quantity 250 - VBAP-KWMENG
Units Kilogram VBAP-MEINS
$15.30 - VBAP-PREIS
EAN – Material number
MY1001 (VBAP-MATNR)
Summary information to verify completeness
CTT*1*2~
CTT01
CTT02
1 PO1 segments
2 some of quantities (ignore unit)
SE*7*000000101~
SE01
SE02
7 segments altogether
Control number 453. This is the same as ST02
14 EDI Converter
R/3 does not provide any tool to convert IDocs into international EDI format like ANSI X.12, EDIFACT or XML. This
conversion needs to be done by an external add-on product which is provided by a variety of companies who specialize in
general EDI and e-commerce solutions.
Summary
R/3 does not provide conversion to EDI standard formats like X.12, EDIFACT or XML.
Converters exist on UNIX and PC platforms.
Many converters are simple PC programs.
R/3 certification only guarantees that the converter complies to RFC technology and works fine with standard IDoc scenarios.
Real life situations require a flexible and easily adaptable converter program.
14.1 Converter
SAP R/3 has foregone implementing routines to convert IDocs into international EDI standard formats and forwards those
requests to the numerous third party companies who specialize in commercial EDI and e-commerce solutions..
Numerous EDI standards Nearly every standard organization defined an own EDI standard for their members. So there is X.12 by ANSI for
the US, EDIFACT/UN adopted by the United Nations Organization UNO or XML as proposed by the internet
research gurus of W3C.
Big companies define But there is still more about it. All major industry companies define an additional file format standard for their EDI
their own standards or partners. Even if they adhere officially to one of the big standards, they yet issue interpretation guidelines with their
dialects own modifications according to their needs.
If a company does not play in the premier league of industry or banking companies, it will have to comply with the
demands of the large corporations.
A converter needs to be As this leads to the insight that there are as many different EDI formats as companies, it is evident that an EDI
open and flexible converter needs to have at least one major feature, which is flexibility in the sense of openness towards modification
of the conversion rules.
There are hundreds of converter solutions on the market not counting the individual in-house programming solutions
done by many companies.
EDI is a market on its own. Numerous companies specialize in providing EDI solutions and services. The majority
of those companies also provide converters.
Many of the converters are certified by SAP to be used with R/3. However, this does not tell anything about the
usability or suitability to task of the products.
Alphabetic Index
Last Page
There is no new knowledge in this world.
And yet you thought to find it in these pages?
Arthur Schnitzler