Vous êtes sur la page 1sur 32

Define and setup for user developed IDOC

1. Define segments: WE31


2. Create new basic idoc type: WE30
3. Create message type: WE81
4. Link message type to IDOC basis type: WE82
5. Create RDC destination: SM59
6. Create logical system: SALE
7. Create port: WE21
8. Create partner profile: WE20
9. Set up distribution model (If necessary): BD64

1. WE31: Define segments


Transaction code: WE31

Create segment Z1ACTIV

Own segments should start with Z1..Z2….. instead of E1..E2…..

Segments must be released before they are transported

2. WE30: Create new IDOC


Transaction: WE30

Create new idoc ZHRACT01. The idoc uses segment Z1ACTIV

Note: Same idoc can exist in different versions e.g. ORDERS01, ORDERS02…..
The difference between versions is that tehre are more segments in newer versions.

3. WE81: Create message type


Transaction WE80

Create new message type ZHRACT01


4. WE82: Link message type to IDOC basis type
Link message type ZHRACT01 to idoc baisi type ZHRACT01

5. SM59: Create RDC destination


6. SALE: Create logical system
7. WE21: Create port

8. WE20: Create partner profile


9. BD64: Set up distribution model (If necessary)
Generate IDOCs from a report
*&---------------------------------------------------------------------*
*& Report ZHR_PERMITTED_ACT_TO_SCANNERS *
*& *
*&---------------------------------------------------------------------*
*
* This report reads permitted activities from table ZHR_AKTIVITITER,
* generates idocs of basis type ZHRACT01 and message type ZHRACT01
* and sends them to XI.
*
*
* Functionality/program flow:
* ============================
* - Read data from tables ZHR_AKTIVITITER and PRPS
* - Create IDoc control record
* - Create IDoc segments
* - Distribute IDoc using function module MASTER_IDOC_DISTRIBUTE
* - Show report
*
*---------------------------------------------------------------------

REPORT zhr_permitted_act_to_scanners.

TABLES: zhr_aktivititer.

TYPES:
BEGIN OF t_activities,
orgeh LIKE zhr_aktivititer-orgeh,
actid LIKE zhr_aktivititer-actid,
descr LIKE zhr_aktivititer-descr,
posid LIKE prps-posid,
post1 LIKE prps-post1,
END OF t_activities.

DATA:
gt_activities TYPE STANDARD TABLE OF t_activities,
wa_activities TYPE t_activities,
* Number of idoc created
g_num_of_idocs TYPE i,
* IDOC control record
g_idoc_control LIKE edidc,
* Return data from MASTER_IDOC_DISTRIBUTE
gt_comm_idocs TYPE STANDARD TABLE OF edidc,
wa_comm_idocs TYPE edidc,
* IDOC data record
gt_idoc_data TYPE STANDARD TABLE OF edidd,
wa_idoc_data TYPE edidd,
* Structure for idoc segment Z!ACTIV
g_z1activ LIKE z1activ.

*------------------------------------------------------------------------------
* SELECTION SCREEN
*------------------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK SELECTION WITH FRAME TITLE text-001.

* Data selection
SELECT-OPTIONS:
s_orgeh FOR zhr_aktivititer-orgeh.
PARAMETERS:
p_date LIKE sy-datum DEFAULT sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK SELECTION.

* Communication parameters
SELECTION-SCREEN BEGIN OF BLOCK COMMUNICATION WITH FRAME TITLE text-002.
PARAMETERS:
p_idoctp LIKE edidc-idoctp OBLIGATORY DEFAULT 'ZHRACT01', "Idoc type
p_mestyp LIKE edidc-mestyp OBLIGATORY DEFAULT 'ZHRACT01', "Message type
p_rcvpor LIKE edidc-rcvpor OBLIGATORY DEFAULT 'SAPUXI', "Receiver port
p_rcvprt LIKE edidc-rcvprt OBLIGATORY DEFAULT 'LS', "Receiver partner type
p_rcvprn LIKE edidc-rcvprn OBLIGATORY DEFAULT 'UXICLNT100'. "Receiver partner
SELECTION-SCREEN END OF BLOCK COMMUNICATION.

* Output
SELECTION-SCREEN BEGIN OF BLOCK OUTPUT WITH FRAME TITLE text-010.
PARAMETERS:
p_idoc AS CHECKBOX, "Create idoc
p_report AS CHECKBOX. "Show report
SELECTION-SCREEN END OF BLOCK OUTPUT.

*------------------------------------------------------------------------------
* SELECTION SCREEN OUTPUT
*------------------------------------------------------------------------------
AT SELECTION-SCREEN OUTPUT.
* Protect parameters for idoc type and message type
LOOP AT SCREEN.
IF screen-name = 'P_IDOCTP' OR screen-name = 'P_MESTYP'.
screen-input = '0'.
MODIFY SCREEN.

ENDIF.
ENDLOOP.

*------------------------------------------------------------------------------
* START OF SELECTION
*------------------------------------------------------------------------------

START-OF-SELECTION.
PERFORM read_data.

*------------------------------------------------------------------------------
* END OF SELECTION
*------------------------------------------------------------------------------

END-OF-SELECTION.
PERFORM create_control_record.

PERFORM create_data_records.

IF p_idoc = 'X'.
PERFORM distribute_idoc.
ENDIF.

IF p_report = 'X'.
PERFORM show_report.
ENDIF.

*&---------------------------------------------------------------------*
*& Form read_data
*&---------------------------------------------------------------------*
* Read activities from ZHR_AKTIVITITER and the corresponding
* WSB-elements and texts from PRPS
*----------------------------------------------------------------------*
FORM read_data.

REFRESH gt_activities.

SELECT zhr_aktivititer~orgeh
zhr_aktivititer~actid
zhr_aktivititer~descr
prps~posid
prps~post1
INTO CORRESPONDING FIELDS OF TABLE gt_activities
FROM zhr_aktivititer LEFT OUTER JOIN prps
ON prps~pspnr = zhr_aktivititer~pspnr
WHERE zhr_aktivititer~orgeh IN s_orgeh AND
zhr_aktivititer~begda <= p_date AND
zhr_aktivititer~endda >= p_date.

SORT gt_activities BY orgeh actid.

ENDFORM. " read_data


*&---------------------------------------------------------------------*
*& Form create_control_record
*&---------------------------------------------------------------------*
* Create control record for IDOC - The values for the control
* are taken from the selection screen
*
*----------------------------------------------------------------------*
FORM create_control_record.
CLEAR g_idoc_control.

g_idoc_control-mestyp = p_mestyp.
g_idoc_control-idoctp = p_idoctp.
g_idoc_control-rcvpor = p_rcvpor.
g_idoc_control-rcvprt = p_rcvprt.
g_idoc_control-rcvprn = p_rcvprn.

ENDFORM. " create_control_record


*&---------------------------------------------------------------------*
*& Form create_data_records
*&---------------------------------------------------------------------*
* Create segment data records for idoc segment Z1ACTIV
*
*----------------------------------------------------------------------*
FORM create_data_records.
DATA:
l_old_orgeh LIKE zhr_aktivititer-orgeh.

REFRESH gt_idoc_data.
CLEAR:
wa_activities,
l_old_orgeh.

SORT gt_activities BY orgeh.

LOOP AT gt_activities INTO wa_activities.


CLEAR:
wa_idoc_data,
g_z1activ.

wa_idoc_data-segnam = 'Z1ACTIV'.
g_z1activ-orgeh = wa_activities-orgeh.
g_z1activ-actid = wa_activities-actid.
g_z1activ-descr = wa_activities-descr.
g_z1activ-posid = wa_activities-posid.
g_z1activ-post1 = wa_activities-post1.

MOVE g_z1activ TO wa_idoc_data-sdata.

APPEND wa_idoc_data TO gt_idoc_data.


ENDLOOP.

ENDFORM. " create_data_records


*&---------------------------------------------------------------------*
*& Form distribute_idoc
*&---------------------------------------------------------------------*
* Create and distribute idoc
*----------------------------------------------------------------------*
FORM distribute_idoc .

REFRESH gt_comm_idocs.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'


EXPORTING
master_idoc_control = g_idoc_control
* OBJ_TYPE = ''
* CHNUM = ''
TABLES
communication_idoc_control = gt_comm_idocs
master_idoc_data = gt_idoc_data
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
OTHERS = 5.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
COMMIT WORK.
ENDIF.
ENDFORM. " distribute_idoc
*&---------------------------------------------------------------------*
*& Form show_report
*&---------------------------------------------------------------------*
* Show report
*----------------------------------------------------------------------*
FORM show_report .
IF p_idoc = 'X'.

* Generated IDOCs
WRITE : / text-003 COLOR COL_HEADING INTENSIFIED ON.
LOOP AT gt_comm_idocs INTO wa_comm_idocs.
WRITE : / wa_comm_idocs-docnum.
ENDLOOP.
SKIP 2.
ENDIF.

* Show selected activities


SKIP 1.
FORMAT COLOR COL_HEADING.
WRITE AT 2 text-004. "Team
WRITE AT 12 text-005. "Aktivitets ID'.
WRITE AT 22 text-006. "Aktivitets beskrivelse'.
WRITE AT 59 text-007. "PSP-element'.
WRITE AT 79 text-008. "PSP kort tekst'.
FORMAT RESET.

LOOP AT gt_activities INTO wa_activities.


WRITE: /
wa_activities-orgeh UNDER text-004,
wa_activities-actid UNDER text-005,
wa_activities-descr UNDER text-006,
wa_activities-posid UNDER text-007,
wa_activities-post1 UNDER text-008.
ENDLOOP.

ENDFORM. " show_report

Updating IDoc data in segments


By Kevin Wilson - From ErpGenie.com

STEP 1 - Open document to edit

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'


EXPORTING
document_number = t_docnum
IMPORTING
idoc_control = itab_edidc
TABLES
idoc_data = itab_edidd
EXCEPTIONS
document_foreign_lock = 1
document_not_exist = 2
document_not_open = 3
status_is_unable_for_changing = 4
OTHERS = 5.

STEP 2 - Loop at itab_edidd and change data

LOOP AT itab_edidd WHERE segnam = 'E1EDKA1'.


e1edka1 = itab_edidd-sdata.
IF e1edka1-parvw = 'LF'.
e1edka1-partn = t_eikto.
itab_edidd-sdata = e1edka1.
MODIFY itab_edidd.
EXIT.
ENDIF.
ENDLOOP.

STEP 3 - Change data segments

CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'


TABLES
idoc_changed_data_range = itab_edidd
EXCEPTIONS
idoc_not_open = 1
data_record_not_exist = 2
OTHERS = 3.

STEP 3a - Change control record

CALL FUNCTION 'EDI_CHANGE_CONTROL_RECORD'


EXPORTING
idoc_changed_control = itab_edidc
EXCEPTIONS
idoc_not_open = 1
direction_change_not_allowed = 2
OTHERS = 3.

STEP 4 - Close Idoc

* Update IDoc status

CLEAR t_itab_edids40.
t_itab_edids40-docnum = t_docnum.
t_itab_edids40-status = '51'.
t_itab_edids40-repid = sy-repid.
t_itab_edids40-tabnam = 'EDI_DS'.
t_itab_edids40-mandt = sy-mandt.
t_itab_edids40-stamqu = 'SAP'.
t_itab_edids40-stamid = 'B1'.
t_itab_edids40-stamno = '999'.
t_itab_edids40-stapa1 = 'Sold to changed to '.
t_itab_edids40-stapa2 = t_new_kunnr.
t_itab_edids40-logdat = sy-datum.
t_itab_edids40-logtim = sy-uzeit.
APPEND t_itab_edids40.

CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'


EXPORTING
document_number = t_docnum
do_commit = 'X'
do_update = 'X'
write_all_status = 'X'
TABLES
status_records = t_itab_edids40
EXCEPTIONS
idoc_not_open = 1
db_error = 2
OTHERS = 3.

Master data distribution using IDOCs


Transaction codes
 BD21 : Generate idocs from change pointers
 BD50 : Activate and deactivate change pointers for message type
 BD61 : Activate and deactivate change pointers generally
 BD64 : Distribution model

Step by Step example


This example demonstrates how to distribute changes to the material master.

 Sender system: C46 client 30


 Receiver system: C46 client 200
 Idoc message type: MATMAS
Activate change pointers

If not done allready, activate change pointers generally (Transaction BD61) and for the message
type ( Transaction BD50 )

ALE configuration in the sender system

These step should be carried out in client 030

Create RFC destination

Go to transaction SM59, select R/3 Connections create RFC destination that points to client 200:

Create port
Go to transaction WE21 and create port for client 200. The port should point to the RFC
destination created above

Create partner profile

Go to trsansaction WE20 and create partner profile C46CLNT200. Add outbound message type
messsag type MATMAS:

Use receiver port Z000000002 and idoc basic type MATMAS03:


ALE configuration in the receiver system

As in the sender system a RFC destination, port and partner profile should be created in the
receiver system cielnt 200. In the partner profile add message type MATMAS:
Set up distribution model

In client C30 set up distribution model to distribute MATMAS idocs to client 200

Go to trsnaction BD64

Create model view My Test

Press the Add message type button and fill out the dialog box:

Your model should now look like this:


Testing the data distrbution
 In the sender system client 030 go to trsnaction MM02 and change a material
 In sender system client 030 Go to transaction BD21 and select message type MATMAS
and execute the program
 In the sender system client 030 go to transaction WE02 and check that an outbound idoc of
basis type MATMAS03 and message type MATMAS has been sent without errors
 In the receiver system client 200 go to transaction WE02 and check that an inbound idoc
of basis type MATMAS03 and message type MATMAS has been received without errors
 In the receiver system client 200 go to transaction MM02 and check that the material has
been changed
How to create a function module for an
IDOC
1. Create new function module
2. BD51 ALE Attributes: Add an entry for the function module
3. WE81 Message types: Create a new messagetype
4. WE82 Idoc Type/Message: Create Entry to link the above defined message type with the
IDOC
5. WE57 Message/Application object: Create entry for Functionmodule/IDOC
type/Messagetype/Object
6. WE42 Inbound process code: Create a new code that refers to the function module
7. WE20 Partner profile: Define the message type in the partner profile

Distributing material master idoc using


changepointers
Note: To create material master idocs without the use change pointers execute transaction BD10

The step to distribute material master idocs to other systems using change pointers are:

 Create logical system for the receiver system: BD54


 Create distribution model: BD64
 Activate change pointers for message type MATMAS: Transaction BD50
 Add MATMAS message type to the Outbound parameters for the partner profile for the
receiver system: WE20
 After the a material has been changed - Creater idocs from change pointers: BD21

Program RBDMIDOC which generates idocs from changepointers, can be schedules to run
automatically
Example of distribution model that distributes MATMAS from logical system C46CLNT30L to
XDTCLNT500:

Inbound IDOC Development


 Create Idoc segments (WE31)
 Create Idoc (WE30)
 Create message type (WE81)
 Assign Message type to Idoc type (WE82)
 Develop posting program.
 Configure the function to handle one or more idocs in the same call (BD51)
 Assign function module to Idoc and message type (WE57)
 Create inbound process code (WE42)
 Add message type to inbound parameters for partner (WE20)

Develop posting program


The posting program is implemented as a function module that handles posting of the inbound
idoc (For eaxmple by suing batch input). Naming convetion: ZIDOC_INPUT_<message type>

Posting programs have a standard interface for there input, output and table parameters (See
example below).

Note that IDoc status codes can be found in transaction WE47.

Example of posting program:

FUNCTION zidoc_input_zprocord .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-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
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*" OTHERS
*"----------------------------------------------------------------------

DATA:
it_edidd TYPE STANDARD TABLE OF edidd,
wa_z1procord LIKE z1procord,
l_return TYPE string,
* lt_return TYPE STANDARD TABLE OF string,
l_subrc LIKE sy-subrc,
l_posting_error(1) TYPE c,
l_posting_ok(1) TYPE c.

in_update_task = ''.

* Check if the function module is called correctly *


READ TABLE idoc_contrl INDEX 1.
IF sy-subrc <> 0.
EXIT.
ELSEIF idoc_contrl-mestyp <> 'ZPROCORD'.
RAISE wrong_function_called.
ENDIF.

*----------------------------------------------------------------------
* Loop through all Idocs
*----------------------------------------------------------------------
LOOP AT idoc_contrl.

*----------------------------------------------------------------------
* Select segments belonging to the Idoc
*----------------------------------------------------------------------
REFRESH: it_edidd.
LOOP AT idoc_data WHERE docnum = idoc_contrl-docnum.
APPEND idoc_data TO it_edidd.
ENDLOOP.

*----------------------------------------------------------------------
* Loop through the segments
*----------------------------------------------------------------------
REFRESH idoc_status.
CLEAR:
l_posting_error,
l_posting_ok.

LOOP AT it_edidd INTO idoc_data.


CASE idoc_data-segnam.
WHEN 'Z1PROCORD'.
CLEAR wa_z1procord.
wa_z1procord = idoc_data-sdata.

CLEAR l_subrc.
PERFORM call_transaction
USING wa_z1procord
CHANGING l_subrc
l_return.

IF l_subrc = 0.
l_posting_ok = 'X'.

ELSE.
l_posting_error = 'X'.
* APPEND l_return TO lt_return.
ENDIF.
ENDCASE.
ENDLOOP.

*----------------------------------------------------------------------
* Set Idoc status code
*----------------------------------------------------------------------
CLEAR idoc_status.
idoc_status-docnum = idoc_contrl-docnum.
IF l_posting_ok = 'X' AND l_posting_error IS INITIAL.
* Application document posted
idoc_status-status = '53'.
ELSEIF l_posting_error = 'X' AND l_posting_ok IS INITIAL.
* Error: Application document not posted
idoc_status-status = '51'.
idoc_status-msgty = 'E'.
idoc_status-msgid = 'ZPP_SIMATIC_INTERFAC'.
idoc_status-msgno = '11'.
* idoc_status-msgv1 = l_return.

ELSEIF l_posting_ok = 'X' AND l_posting_error = 'X'.


* Application document not fully posted
idoc_status-status = '52'.
idoc_status-msgty = 'E'.
idoc_status-msgid = 'ZPP_SIMATIC_INTERFAC'.
idoc_status-msgno = '10'.
* idoc_status-msgv1 = l_return.

ENDIF.
APPEND idoc_status.

ENDLOOP.

ENDFUNCTION.
How to use a filter in a distribution model
You need to do create a filter for plant in BD64 , You can proceed with following transactions to
do so ..............

Maintain object type for message type (BD59) Client independentThe ALE objects are used to
create links between IDocs and applications objects, to control the serialisation, to filter
messages in the customer model and to use listings. For our own message type and IDoc you
must maintain object types for the links.

If you want to check the serialisation for the message type, then you must maintain object types
for the serialisation. If no serialisation object has been maintained for a given message type, then
the serialisation will not be checked for this message type.To add an object type to our message
type, follow these next few steps:

 Enter transaction BD59 (ALE -> Extensions -> ALE object maintenance -> Maintain
object types)3
 Type in your message type ZINVRV and press enter
 Click on New entries
 Enter your object type, LIFNR (We need to use the vendor as a filter object), the segment
name where LIFNR resides, Z1INVRV, a number 1 for the sequence followed by the
actual field name LIFNR
 Save and exit
 You have now created an object that we’ll use as a filter object in the customer model to
direct the flow of messages to the various logical systems based on the vendors in the filter
of the message type ZINVRV.

We now need to add our new message type to the distribution model.

Configuring the Distribution Model. This task is performed on your ALE reference client.

Manual Configuration (BD64) Client dependent. To manually configure the customer


distribution model, read the ALE configuration procedure, and follow these steps:

 Perform the Maintain customer distribution model directly function. (ALE -> Distribution
customer model -> Maintain customer distribution model directly)
 Specify the customer model you want to maintain and the logical system that is to be the
sender of the messages OR create a new model. (Create model ALE with logical system
ALELS1C400)
 Choose the receiving systems to which the sending system must forward message type
ZINVRV to.
 For each receiving logical system allocate the message type necessary for communication
to the receiving systems as per ALE configuration procedure.
 Create filter objects (in our case LIFNR as the object type with the associated vendor
number, 0000018001 with leading zeros, in the object area) for the message types.
 Save the entries.

Miscellanous Tips part 1


 How to debug an outbound IDOC
 Usefull function modules
 Usefull standard programs
 Usefull tables

How to debug an outbound IDOC

 Set the appropriate breakpoins


 Go to the tramnsaction from which ypoy generate the IDOC (E.g. ME22 or VL02)
 Go to the messages for the document you select ( In ME22 use menu Header-
>Messages). In other transactioncodes the mneu for messages may be palced somewhere
else.
 In the Output window choose an existing message and press Repeat output (Or create a
new message)
 Select menu Further data and change the dspatch time to 1 Send with periodically
scheduled job
 Submit pogram RSNAT00. In the selection screen choose transmission medium 6 EDI and
enter any further selection criterias
 Enter debug mode ( Type /H in the command line)
 Execute RSNAT00

Usefull function modules


By Kevin Wilson - From ErpGenie.com
IDOCTYPES_LIST_WITH_MESSAGES Returns a list of all Basis types (IDoc since release 4.0B,
types), Extensions (IDoc types) and all Hotpackage 48
messages related with their respective
IDoc types.

IDOCTYPES_FOR_MESTYPE_READ Reads all IDoc types assigned to a since release 4.0B,


message type (logical message). Hotpackge 42

IDOCTYPE_READ_COMPLETE Reads the structure and attributes since release 4.0B,


(segments), as well as the segment Hotpackge 42
attributes (fields and fixed values), for
an IDoc type. In this case, the version
of the record types and segments must
be sent to the function module.

SEGMENT_READ_COMPLETE Reads the structure and attributes for a since release 4.0B,
segment. In this case, the version of the Hotpackge 42
record types and the release for the
segments must be sent to the function
module.

IDOC_RECORD_READ Reads the structure of the record types since release 4.0B,
for the specified version. Hotpackge 42

Usefull standard programs

RSNAST00 Processes messages that has not bees sendt (processing <>
immediate)
RSNASTED Program, som kaldes fra Output Message Control ved "udskrift" af
ordrer m.v. Indeholder 2 entry points: EDI_PROCESSING og
ALE_PROCESSING. Herfra kaldes det function module, som er
tildelt via partner profilen og process koden.
RBDMIDOC Generates IDOC's from change pointers (You can also use
transaction BD21)
RSEOUT00 Processes outbound IDOC's with status 30, ( IDOC's mass
processing)
RBDAPP01 Processes inbound IDOC's.
RSECHK07 Check if partner profiler is valid

Use program RSNAST00 to process the IDOCs

Usefull tables

Table Discription
NAST Message Status
Miscellanous Tips part 2
Getting IDocs linked to Application documents
Displaying and IDoc in a report
Read IDoc from Database
Creating and sending an IDoc
ALE Inbound Pre-Processing

Getting IDocs linked to Application documents


By Kevin Wilson - From ErpGenie.com
REFRESH: t_roles.
* VBRK = Invoice
* LIKP = Delivery
* BUS2032 = Sales Order
* BUS2035 = Scheduling Agreement
* objkey - Application document number appended with line if applicable

t_object-objkey = itab_data-objky.
t_object-objtype = 'VBRK'.
CALL FUNCTION 'SREL_GET_NEXT_RELATIONS'
EXPORTING
object = t_object
TABLES
roles = t_roles
EXCEPTIONS
internal_error = 1
no_logsys = 2
OTHERS = 3.

LOOP AT t_roles WHERE objtype = 'IDOC'.


t_idoc_docnum = t_roles-objkey.
ENDLOOP.

Displaying and IDoc in a report

By Kevin Wilson - From ErpGenie.com


AT LINE-SELECTION.
GET CURSOR FIELD field_name.
CASE field_name.
WHEN 'ITAB_DATA-DOCNUM'. "IDoc number

CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY'


EXPORTING
docnum = itab_data2-docnum
EXCEPTIONS
no_data_record_found = 1
OTHERS = 2.

Read IDoc from Database

By Kevin Wilson - From ErpGenie.com

*** Read the IDoc detail from the database

CALL FUNCTION 'IDOC_READ_COMPLETELY'


EXPORTING
document_number = p_docnum
IMPORTING
idoc_control = s_edidc
TABLES
int_edidd = itab_edidd
EXCEPTIONS
document_not_exist = 1
document_number_invalid = 2
OTHERS = 3.

Creating and sending an IDoc

By Kevin Wilson - From ErpGenie.com

*** STEP 1 - Create IDoc internal table entries

*** STEP 2 - Call the function to distribute the IDoc

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'


EXPORTING
master_idoc_control = s_edidc
obj_type = 'BUS2032'
TABLES
communication_idoc_control = itab_edidc
master_idoc_data = itab_edidd
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
OTHERS = 5.

*** STEP 3 - Update IDoc status - If you wish to send additional status messages through

REFRESH: itab_edids.

itab_edids-status = c_idoc_status_ok.
itab_edids-msgty = c_info_msg.
itab_edids-msgid = c_msgid.
itab_edids-msgno = c_msgno.
itab_edids-msgv1 = itab_edidc-docnum.
itab_edids-msgv2 = s_edidc-sndprn.

*** Call the function to update the ORDCHG IDoc status

CALL FUNCTION 'IDOC_STATUS_WRITE_TO_DATABASE'


EXPORTING
idoc_number = s_edidc-docnum
TABLES
idoc_status = itab_edids
EXCEPTIONS
idoc_foreign_lock = 1
idoc_not_found = 2
idoc_status_records_empty = 3
idoc_status_invalid = 4
db_error = 5
OTHERS = 6.

ALE Inbound Pre-Processing

By Kevin Wilson - From ErpGenie.com

Sometimes it's necessary to change an Idoc before it is processed. One way to achieve this
is to call a function module that updates the IDoc tables before calling the appropriate f
Note that the function module below can be replaced with EDI_DATA_INCOMING if you are usin
method to load IDocs to SAP.

FUNCTION Z_IDOC_INBOUND_ASYNCHRONOUS.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" IDOC_CONTROL_REC_40 STRUCTURE EDI_DC40
*" IDOC_DATA_REC_40 STRUCTURE EDI_DD40
*"----------------------------------------------------------------------
data e1edp16 type e1edp16.

loop at idoc_control_rec_40
where mestyp = 'DELINS'.

loop at IDOC_DATA_REC_40
where docnum = idoc_control_rec_40-docnum and

segnam = 'E1EDP16'.
move IDOC_DATA_REC_40-sdata to e1edp16.
IF not E1EDP16-PRGRS CA 'DWMI'.
delete IDOC_DATA_REC_40.
ENDIF.
endloop.

endloop.

CALL FUNCTION 'IDOC_INBOUND_ASYNCHRONOUS'


TABLES
idoc_control_rec_40 = IDOC_CONTROL_REC_40
idoc_data_rec_40 = IDOC_DATA_REC_40.

ENDFUNCTION.

Vous aimerez peut-être aussi