Processing Inbound Custom Idocs With Custom Function Modules in Sap

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

PROCESSING INBOUND CUSTOM IDocs WITH CUSTOM

FUNCTION MODULES IN SAP.

Author: Tony Cecchini, SAP America


ALE LAYER APPLICATION LAYER

Inbound Posting Function Module


READ IDOCS

Process Message Type

LOCK IDOCS Direct Input Or Call TRAN

Return Results

CALL POSTING PGM

WRITE STATUS RECORDS

Application
Document

COMMIT WORK

UNLOCK IDOCS

The Interface for the function Module is preset by SAP. The various parameters for the interface are
described below.

IMPORTING parameters.

INPUT_METHOD. Specifies the mode in which the posting program will be executed and is
valid only for call transactions.

MASS_PROCESSING. Please leave as space.

EXPORTING parameters.

WORKFLOW_RESULT. Indicates whether the posting was successful and whether workflow
should be started.

APPLICATION_VARIABLE. Please leave as space.

IN_UPDATE_TASK. Indicates how you intend to perfom the update. Blank indicates the
update task was not used, while an X indicates that it was. This would delay the posting until a
commit was done.

CALL_TRANSACTION_DONE. Please leave as space.


TABLES parameters.

IDOC_CONTRL. Contains the control record(s)

IDOC_DATA. Contains the data segments.

IDOC_STATUS. Contains the status records

RETURN_VARIABLES. The ALE layer will use this for workflow processing.

SERIALIZATION_INFO. Needed if you are doing mass processing and need to


serialize you processing

EXCEPTIONS. Convey problems with processing.

General Program Flow.

1. Read and verify Control Record, if message type is incorrect raise exception

2. Read IDoc Data.

3. Parse the segments and build BDC data if using call transaction, or internal tables if using
a direct input function module.

4. Call the Transaction

5. Populate Return variables

6. Append Status Records

7. Return to ALE
Workflow Configuration:

Create a new IDoc application object in BOR with triggering and terminating
events(SWO1).
Create a new task based on the application object(PFTC_COP)
Create the event linkage(SWE2)
Create new IDoc packet object in BOR(SWO1).

Process Configuration:

Create a new Message type(WE81)


Link Message type to IDoc type(WE82)
Allocate FM to Logical Message(WE57)
Define Characteristics of Inbound FM(BD51)
Create new Process Code((WE42)
Assign Input Methods(BD67)
Create or change Partner Profile(WE20)
1. SAMPLE INBOUND PROGRAM.

FUNCTION Z_idoc_input_<MESSAGE>.
*"----------------------------------------------------------------------
*"*"LOCAL Interface:
*" 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
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

INCLUDE MBDCONWF.

*-----------------------------------------------------------------------
* PUT ANY DATABSE TABLE DELCARATIONS HERE
*-----------------------------------------------------------------------
TABLES: TTTTT.
*-----------------------------------------------------------------------
* DATA DELCARATIONS and INTERNAL TABLES
*-----------------------------------------------------------------------
DATA: I_TAB.
*-----------------------------------------------------------------------
* Program Logic
*-----------------------------------------------------------------------
*
*Initialize workflow result
*
WORKFLOW_RESULT = C_WF_RESULT_OK.

LOOP AT IDOC_CONTRL.

* Verify the correct message was passed to the program


IF IDOC_CONTRL-MESTYP NE <MESSAGE>.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.

* Process all data records in an IDoc and transfer them to


* application buffers

LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.

CASE IDOC_DATA-SEGNAM.

WHEN ZZZZZZ.
<Build BDC_DATA>
WHEN ZZZZZZ.
<Build BDC_DATA>

ENDCASE.
ENDLOOP.

* Call Transaction to achieve posting of document

CALL TRANSACTION 'ZZZZ'


USING BDCDATA
MODE input_method
MESSAGES INTO ITAB.

CASE SY-SUBRC.

WHEN 0.

* Populate Return variable for success

RETURN_VARIABLES-WF_PARAM = Processed_IDOCs.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
RETURN_VARIABLES-WF_PARAM = Appl_Objects.
RETURN_VARIABLES-DOC_NUMBER = <Number of document just created>.
APPEND RETURN_VARIABLES.

* Add IDOC_Status for success.


idoc_status-docnum = idoc_contrl-docnum.
idoc_status-status = 53.
idoc_status-msgty = 'I'.
idoc_status-msgid = '<ZZ>'.
idoc_status-msgno = '<999>'.
idoc_status-msgv1 = Any text or variable.
idoc_status-msgv2 = Any Text or variable.
APPEND idoc_status.

WHEN OTHERS.

* Populate Return variable for failure.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = Error_IDOCs.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.

* Add IDOC_Status for failure..


idoc_status-docnum = idoc_contrl-docnum.
idoc_status-status = 51.
idoc_status-msgty = 'E'.
idoc_status-msgid = '<ZZ>'.
idoc_status-msgno = '<999>'.
idoc_status-msgv1 = Any text or variable.
idoc_status-msgv2 = Any Text or variable.
APPEND idoc_status.

.
ENDCASE.

ENDLOOP.

ENDFUNCTION.

You might also like