You are on page 1of 5

Creating a New Function Module (Outbound

Processing Under Message Control)


This section describes how to create a function module that is identified and called from the RSNASTED
report (form routine NEW_DYN_PERFORM) via a new process code (field TEDE1-ROUTID). For this
reason, choose outbound processing under message control (NAST).

Your new function module uses the new interface (Release 3.0 onwards), i.e. it stores the application data
in an internal table. Furthermore, the path without the ALE layer (i.e. without filters) is selected. These two
settings (new FM interface and processing without ALE layer) are identified by the value 3 in the TEDE1-
EDIVRS field, which is also read from RSNASTED.

The function module is called from Purchasing (create purchase order) in the same way as
IDOC_OUTPUT_ORDERS (IDoc type ORDERS01). It fills the segments of your new IDoc type, therefore,
from a purchasing table, i.e. EKKO (purchasing document header). Note that the intention here is not to
simulate a realistic purchase order, but merely to describe how data reaches an IDoc table from an
application table via segment structures.

Procedure
1. Using transaction SE37, create a new function module with the name IDOC_OUTPUT_TEST.
Specify the function group for the module. If you choose a new function group, it will be created
(confirm queries). In this example, the function group is simply called TEST.
2. Under the administration parameters, enter:

 your application code, e.g. M for Materials Management

 Short text as a description

 Processing type "normal" and "start immediately"

3. Choose the following parameters as an interface for the function module (similar to
IDOC_OUTPUT_ORDERS). Ensure that the parameters are globalized (choose Edit 
Globalize parameters)

Interface for IDOC_OUTPUT_TEST (global interface)

Formal parameters Reference structure Explanation

Import parameters    

OBJECT NAST Current NAST (message control) record

CONTROL_RECORD_IN EDIDC Contains the receiver information


Export parameters    

OBJECT_TYPE WFAS1-ASGTP Object type for the application object in


the Business Object Repository (BOR)

CONTROL_RECORD_OUT EDIDC Then also contains the sender information


as well as date and time at which the
IDoc table was filled.

Table    

INT_EDIDD EDIDD IDoc data records (internal table)

Define ERROR_MESSAGE_RECEIVED as an exception.

Now create the following global data and form routines in the function group:

Global data Explanation

EKKO Purchasing document header (transparent table)

E1EDK01 Document header data, general (structure)

E1TEST Test segment you created (structure)

E1EDP01 Document item data, general (structure)

NAST Contains the application object data (of the


message, e.g. the purchase order)

INT_EDIDD IDoc data records (internal table)

Form routine Explanation

READ_APPLICATION_DATA Sets the correct EKKO record in the work area of


this table

FILL_ITABLE_FOR_IDOC Fills internal table for IDoc (data records) with the
data from EKKO; fills the IDoc control record with
sender data

The program code is as follows:


 

function idoc_output_test.

perform read_application_data. "Fill work area of EKKO

"with current data

perform fill_control_record. "Data for IDoc control record

perform fill_itable_for_idoc. "Data for IDoc data records

object_type = 'BUS2012'. "Business object: purchase order

endfunction.

form read_application_area.

select single * from t000 where mandt eq sy-mandt.

select single * from ekko where ebeln eq object-objky.

if sy-subrc ne 0.

message e751 with object-objky "Message ID ME in TOP include

raising error_message_received.

endif.

endform.

form fill_control_record.

move control_record_in to control_record_out.

control_record_out-direct = '1'.

control_record_out-serial = sy-datum.

control_record_out-serial+8 = sy-uzeit.

endform.

form fill_itable_for_idoc.
*----Fill item data segment with document number from EKKO

clear int_edidd. "Clear work area

clear e1edk0 "Clear structure

e1edk01-curcy = 'USD'.

move e1edk01 to int_edidd-sdata. "Data section of data record

"Fill (segment)

int_edidd-segnam = 'E1EDK01'. "Fill administration section of

"data record

append int_edidd.

*----Fill test segment with fixed value 'America'

clear int_edidd.

clear e1test.

e1test-kontinent = 'America'.

move e1test to int_edidd-sdata.

int_edidd-segnam = 'E1TEST'.

append int_edidd.

*----Set item number in E1EDP01 to 10

*----(Segment contains vendor material number)

clear int_edidd.

clear e1edp01.

e1edp01-posex = '10'.

move e1edp01 to int_edidd-sdata.

int_edidd-segnam = 'E1EDP01'.

append int_edidd.

endform.

 
The HLEVEL (hierarchy level of segment) field in the administration section is not filled. This is
carried out by the IDoc interface which receives this value from the definition of the IDoc type
TESTER01.

The segment E1TEST in the INT_EDIDD-SEGNAM field must be written in upper case letters.
Otherwise, the IDoc interface will detect a syntax error.

The Top include (global data declaration) is as follows:

function-pool test message-id me.

tables:

EKKO,

E1EDK01,

E1TEST,

E1EDP01,

NAST,

T000.

4. Do not forget to activate your function module afterwards by selecting Function module 
Activate from the initial screen of the Function Builder.

Result
You have now written a function module that fills your IDoc type with data in outbound processing. This
data is imported from the transparent table EKKO and the record in the transparent table NAST written
from Purchasing.

In the next step, this function module will be identified by a new process code which is then written to the
partner profiles. Proceed as described in the tutorial Assigning a New Process Code to a New Function
Module and Message (Outbound Processing).

You might also like