SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

ALE, EDI, IDocs



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Function Modules | Функциональные модули
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Sep 17, 2007 8:24 pm    Post subject: ALE, EDI, IDocs Reply with quote

I. Opening Idoc to process:
EDI_DOCUMENT_OPEN_FOR_CREATE - EDI interface: Open IDoc for create
Initiates the generation of an IDoc.
<-- IDENTIFIER - temporary Id for referring in following FMs (multiprocessing allowed)

EDI_DOCUMENT_OPEN_FOR_FORCE - EDI interface: Open IDoc for create with few/no checks
If the EDI_DOCUMENT_OPEN_FOR_CREATE failed but the IDoc must be passed to the database (multiprocessing allowed)

EDI_DOCUMENT_OPEN_FOR_TRACE - EDI interface: Open IDoc for trace
Simulates the creation of an IDoc. No number specification and database operations (multiprocessing allowed).

EDI_DOCUMENT_OPEN_FOR_EDIT - open in edit mode with locking of the IDoc

EDI_DOCUMENT_OPEN_FOR_PROCESS - Open IDoc for processing
To change status records and control record (multiprocessing allowed)

EDI_DOCUMENT_OPEN_FOR_READ - EDI interface: Open IDoc for reading
Status of the IDoc cannot be changed (multiprocessing allowed)

II. Processing Idoc (after step I):
EDI_SEGMENT_GET_NEXT - EDI interface: Sequential accesses to data record
can be called in READ and PROCESS modes

EDI_SEGMENT_GET - EDI Interface: Direct Access to Data Record

EDI_SEGMENTS_GET_ALL - EDI interface: Read all data records for IDoc

EDI_SEGMENTS_GET_RANGE - EDI interface: Read part of section from data records for IDoc

EDI_DOCUMENT_READ_ALL_STATUS - IDoc interface: Read all status records for one IDoc

EDI_DOCUMENT_READ_LAST_STATUS - IDoc interface: Read last/current status record for IDoc

EDI_DOCUMENT_STATUS_SET - EDI interface: Set status in CREATE or PROCESS mode

EDI_STATUS_ADD_BLOCK - EDI interface: Insert block of status records

EDI_SEGMENT_ADD_NEXT - EDI interface: Sequential insertion of data record
can only be called in CREATE mode

EDI_SEGMENTS_ADD_BLOCK - EDI interface: Add block of data records

III. Closing IDoc after Processing (after step II):

EDI_DOCUMENT_CLOSE_CREATE - EDI interface: Close IDoc after insertion

EDI_DOCUMENT_CLOSE_CREATE_TAB - EDI interface: Close IDocs after insertion with EDIDD table
Returns data of the created IDoc in the TABLES EDIDD parameter for furhter processing in parent program.

EDI_DOCUMENT_CLOSE_FORCE - EDI interface: Close IDoc after open for force
Stored with the status 'Created incorrectly'

EDI_DOCUMENT_CLOSE_TRACE - EDI interface: Close IDoc after insertion
No IDoc number is specified nor is the IDoc written onto the database.

EDI_DOCUMENT_CLOSE_EDIT - closes the idoc to editing

EDI_DOCUMENT_CLOSE_PROCESS - EDI interface: Close IDoc after processing
New status records and a new status value in the control record - are passed on to the database

EDI_DOCUMENT_CLOSE_PROCESS_UPD - EDI interface: Close IDoc after processing in update task

EDI_DOCUMENT_CLOSE_READ - EDI interface: Close IDoc after reading

IV. Standalone function modules:
IDOC_READ_COMPLETELY - Read all control, data and status records for the IDoc

EDI_DOCUMENT_STATUS_DISPLAY - Display last status record for current IDoc
like in WE02

IDOC_STATUS_WRITE_TO_DATABASE Writes one or more status records for an IDoc
Calls in order:
- EDI_DOCUMENT_OPEN_FOR_PROCESS
- IDOC_STATUS_CONVERT
- EDI_STATUS_ADD_BLOCK
- EDI_DOCUMENT_CLOSE_PROCESS

Example:
Updating IDoc data in segments (By Kevin Wilson)

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.

Getting IDocs linked to Application documents (By Kevin Wilson)

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
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)
*** 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)
*** 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)

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 function module. Note that the function module below can be replaced with EDI_DATA_INCOMING if you are using the EDI File Port 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.


API for IDoc processing

File interface
EDI_DATA_INCOMING - EDI: Call inbound processing for IDoc file
Code:

Example
The function module is used in the test program for IDoc inbound processing.
Usage example:

data: complete_filename like edi_path-pthnam,
portname like edipo-port.

* Assign values to an actual parameter
complete_filename = '/usr/sap/C11/SYS/idoc/idocs.inb'.
portname = 'EDIPORT'.
* Call FM
call function 'EDI_DATA_INCOMING'
exporting
pathname = complete_filename
port = portname
exceptions
others = 1.


EDI_STATUS_INCOMING - EDI call for inbound processing for file with status records
Code:
data: complete_filename like edi_path-pthnam,
portname like edipo-port.
* value assignment to actual parameter
complete_filename = '/usr/sap/C11/SYS/idoc/status.inb'. portname = 'EDIPORT'.
* call function module
call function 'EDI_STATUS_INCOMING'
exporting
pathname = complete_filename
port = portname
exceptions others = 1.


RFC interface

IDOC_INBOUND_SYNCHRONOUS - Call inbound processing for transferred IDoc

INBOUND_IDOC_PROCESS (3.x mode) standard in tRFC, batch of IDocs allowed/recommended

IDOC_INBOUND_SINGLE (4.x mode) single IDoc per call

IDOC_INBOUND_ASYNCHRONOUS (4.x mode) standard in tRFC, batch of IDocs allowed/recommended

API for IDoc Types and Segment Definitions

A wide range of function modules is available for developing segments and IDoc types automatically. This programming interface (API) is also used by the IDoc type editor and the segment editor.
The API is subdivided into three function groups: the function modules which operate on segments are located in function group EDIJ, while those which operate on basic types and extensions are located in function group EDIM. The third function group contains RFC-compatible function modules which can be used from external developments. One example is the IDoc Class Library (the documentation is only available in English), which is written in C.
Function modules in the EDIJ group (segments)
Function modules in the EDIM group (basic types and extensions)
Function modules in the EDIMEXT group (API for external programs)

See also OSS note #212011.

IDOCTYPES_LIST_WITH_MESSAGES
Returns a list of all Basis types (IDoc types), Extensions (IDoc types) and all messages related with their respective IDoc types.
since release 4.0B, Hotpackage 48

IDOCTYPES_FOR_MESTYPE_READ
Reads all IDoc types assigned to a message type (logical message).
since release 4.0B, Hotpackge 42

IDOCTYPE_READ_COMPLETE
Reads the structure and attributes (segments), as well as the segment 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.
since release 4.0B, Hotpackge 42

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

IDOC_RECORD_READ
Reads the structure of the record types for the specified version.
since release 4.0B, Hotpackge 42
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Function Modules | Функциональные модули All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.