HI All,
Please find the end to end solution of converting an IDOC XML into an SAP IDOC format. Thanks.
To convert an IDOC XML into an SAP IDOC, there is no need of middleware conversion like PI. In general, port will be defined in the partner profile configuration for the outbound IDOCS. But for the Inbound there will not be a provision to define port at the partner profile level.
You can just create an inbound port of type XML file port and do the necessary IDOC Inbound configuration which will suffice your need.
The file port is used to determine the file type of the input file whether is flat or XML file.
The receiver port is the port of the receiving system. In this case, your R/3 system is receiving the Idoc, thus the SAP<SID> is correct for the
receiver. The sender port would represent the source system (your file port).
There is a standard function module ('IDOC_XML_FROM_FILE') which will convert the IDOC XML into an SAP IDOC.
Here the files are placed in the application server in a folder having the file port as XML port. Files will be picked from AL11 and triggered the SAP IDOC as an inbound.
Port Configuration:
AL11 folder:
Please find the sample Logic for the same.
REPORT Z_XML_TO_IDOC MESSAGE-ID zfieu.
TYPE-POOLS: SLIS.
TYPES: BEGIN OF GTY_OUTPUT,
FILENAME TYPE CHAR80,
STATUS TYPE CHAR120,
END OF GTY_OUTPUT,
BEGIN OF GTY_ERROR,
ERR_MSG TYPE CHAR120,
END OF GTY_ERROR.
DATA: GT_FIELDCATELOG TYPE SLIS_T_FIELDCAT_ALV,
GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
GT_OUTPUT TYPE STANDARD TABLE OF GTY_OUTPUT,
GS_OUTPUT TYPE GTY_OUTPUT,
GT_FILENAME TYPE STANDARD TABLE OF RSFILLST,
GS_FILENAME TYPE RSFILLST,
LV_FILENAME TYPE EDI_PATH-PTHNAM,
GS_ERROR TYPE GTY_ERROR,
LV_FNAME TYPE RSMRGSTR-PATH.
CONSTANTS: GC_FILE TYPE RSMRGSTR-NAME VALUE 'SHPMNT_*',
GC_OUTPUT TYPE SLIS_TABNAME VALUE 'GT_OUTPUT',
GC_FILENAME TYPE SLIS_FIELDNAME VALUE 'FILENAME',
GC_STATUS TYPE SLIS_FIELDNAME VALUE 'STATUS',
GC_XML TYPE EDIPO-PORT VALUE 'XML',
LC_FILE(50) TYPE C VALUE '/tmp'.
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1.
PARAMETERS:
* Put this in input file
P_FNAME TYPE IBIPPARMS-PATH OBLIGATORY DEFAULT LC_FILE,
P_PORT TYPE EDIPO-PORT OBLIGATORY DEFAULT GC_XML ,
p_file TYPE RSMRGSTR-NAME OBLIGATORY DEFAULT GC_FILE.
SELECTION-SCREEN END OF BLOCK BL1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
DIRECTORY = ' '
FILEMASK = ' '
IMPORTING
SERVERFILE = P_FNAME
EXCEPTIONS
CANCELED_BY_USER = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE E048 .
EXIT.
ENDIF.
START-OF-SELECTION.
LV_FNAME = P_FNAME.
* This FM is to get the list of files in the specified directory.
* with the name starting 'SHPMNT_*'.
CALL FUNCTION 'SUBST_GET_FILE_LIST'
EXPORTING
DIRNAME = LV_FNAME
FILENM = p_file
PATTERN = '*'
TABLES
FILE_LIST = GT_FILENAME
EXCEPTIONS
ACCESS_ERROR = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE E010 WITH LV_FNAME.
EXIT.
ENDIF.
LOOP AT GT_FILENAME INTO GS_FILENAME.
LV_FILENAME = GS_FILENAME-NAME.
CONCATENATE P_FNAME '/' LV_FILENAME INTO LV_FILENAME.
* This FM is called to create IDOC from the XML files fetched.
CALL FUNCTION 'IDOC_XML_FROM_FILE'
EXPORTING
FILE_NAME = LV_FILENAME
PORT = P_PORT
EXCEPTIONS
FILE_OPEN_FAILED = 1
READ_FILE_FAILED = 2
FILE_DELETE_FAILED = 3
EVENT_CREATE_FAILED = 4
SEGMENT_ERROR = 5
TAG_ERROR = 6
CONTROL_RECORD_ERROR = 7
IDOC_NOT_STORED = 8
MARKER_TO_BE_DELETED = 9
MARKER_MODIFY_FAILED = 10
OTHERS = 11.
CLEAR LV_FILENAME.
IF SY-SUBRC <> 0.
* This FM is called to capture the error messages from above FM.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = SY-MSGID
MSGNR = SY-MSGNO
MSGV1 = GS_FILENAME-NAME
MSGV2 = SY-MSGV2
MSGV3 = SY-MSGV3
MSGV4 = SY-MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT = GS_ERROR.
GS_OUTPUT-FILENAME = GS_FILENAME-NAME.
GS_OUTPUT-STATUS = GS_ERROR.
APPEND GS_OUTPUT TO GT_OUTPUT.
CLEAR: GS_OUTPUT, GS_FILENAME.
ENDIF.
ENDLOOP.
REFRESH GT_FILENAME.
* Preparing field catelog.
IF GT_OUTPUT IS NOT INITIAL.
REFRESH :GT_FIELDCATELOG[].
CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 1.
GS_FIELDCAT-FIELDNAME = GC_FILENAME.
GS_FIELDCAT-TABNAME = GC_OUTPUT.
GS_FIELDCAT-OUTPUTLEN = 80.
GS_FIELDCAT-SELTEXT_M = TEXT-001.
APPEND GS_FIELDCAT TO GT_FIELDCATELOG.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 2.
GS_FIELDCAT-FIELDNAME = GC_STATUS.
GS_FIELDCAT-TABNAME = GC_OUTPUT.
GS_FIELDCAT-OUTPUTLEN = 120.
GS_FIELDCAT-SELTEXT_M = TEXT-002.
APPEND GS_FIELDCAT TO GT_FIELDCATELOG.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = GT_FIELDCATELOG[]
TABLES
T_OUTTAB = GT_OUTPUT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
REFRESH GT_OUTPUT.
ENDIF.
Regards,
Durga