Jun 1, 2026

Sampe Prorgram of Inbound IDoc MRESCR/MRESCR01

To process the MRESCR01 inbound IDoc (used to create material reservations), SAP typically uses the standard function module IDOC_INPUT_MRESCR or a BAPI-wrapper via process code MRES or BAPI in WE42.

Below is an ABAP program sample that reads a flat file from the application server and manually forces IDoc creation using IDOC_INBOUND_ASYNCHRONOUS
abap
*&---------------------------------------------------------------------*
*& Report Z_INBOUND_IDOC_MRESCR01
*&---------------------------------------------------------------------*
*& Sample program to generate and process MRESCR01 inbound IDoc
*&---------------------------------------------------------------------*
REPORT z_inbound_idoc_mrescr01.

* DATA DECLARATIONS
DATA: lv_file     TYPE string VALUE '/usr/sap/tmp/reservation_data.txt',
      lv_lines    TYPE i,
      ls_edidc    TYPE edidc,
      lt_edidd    TYPE TABLE OF edidd,
      ls_edidd    TYPE edidd,
      lt_control  TYPE TABLE OF edidc,
      lv_msg_text TYPE string.

* SELECTION SCREEN
PARAMETERS: p_file LIKE lgpa-filepath DEFAULT '/usr/sap/tmp/reservation_data.txt'.

START-OF-SELECTION.

  " 1. Read flat file from application server
  PERFORM read_flat_file CHANGING lt_edidd.

  " 2. Build Control Record
  PERFORM build_control_record CHANGING ls_edidc.

  " 3. Call Standard Inbound Function
  CALL FUNCTION 'IDOC_INBOUND_ASYNCHRONOUS'
    EXPORTING
      pi_edidc      = ls_edidc
    TABLES
      pit_edidd     = lt_edidd
    EXCEPTIONS
      error_message = 1
      OTHERS        = 2.

  IF sy-subrc = 0.
    COMMIT WORK.
    WRITE: / 'IDoc successfully created and triggered for processing.'.
  ELSE.
    lv_msg_text = sy-msgli.
    WRITE: / 'Error creating IDoc. Message:', lv_msg_text.
  ENDIF.

*&---------------------------------------------------------------------*
*& Form BUILD_CONTROL_RECORD
*&---------------------------------------------------------------------*
FORM build_control_record CHANGING cs_edidc TYPE edidc.

  cs_edidc-mestyp = 'MRESCR'.         " Message Type
  cs_edidc-idoctp = 'MRESCR01'.       " Basic IDoc Type
  cs_edidc-direct = '2'.              " Direction: 2 = Inbound
  cs_edidc-rcvprt = 'LS'.             " Partner Type: Logical System
  cs_edidc-rcvprn = 'SAPD01'.         " Receiver Partner Number (Your SAP system)
  cs_edidc-sndprt = 'LS'.             " Sender Partner Type
  cs_edidc-sndprn = 'LEGACY_SYS'.     " Sender Partner Number (Source System)

ENDFORM.

*&---------------------------------------------------------------------*
*& Form READ_FLAT_FILE
*&---------------------------------------------------------------------*
FORM read_flat_file CHANGING ct_edidd TYPE STANDARD TABLE of edidd.

  DATA: lv_string TYPE string,
        ls_header TYPE e1bpresbc,   " Standard BAPI segment for MRESCR01 header
        ls_item   TYPE e1bpresbc.   " Standard BAPI segment for item

  OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc NE 0.
    WRITE: / 'Cannot open file:', p_file.
    EXIT.
  ENDIF.

  DO.
    READ DATASET p_file INTO lv_string.
    IF sy-subrc NE 0. EXIT. ENDIF.

    " Add file parsing logic here depending on your file structure
    " Example: Split CSV by comma and populate IDoc segments

    " Example for Header segment
    CLEAR ls_edidd.
    ls_edidd-segnam = 'E1BPRESBC'. " Segment Name
    ls_header-mov_type = '201'.
    ls_header-res_date = sy-datum.
    ls_edidd-sdata = ls_header.
    APPEND ls_edidd TO ct_edidd.

    " Example for Item segment
    CLEAR ls_edidd.
    ls_edidd-segnam = 'E1BPRESBC'.
    " Populate ls_item fields here ...
    ls_edidd-sdata = ls_item.
    APPEND ls_edidd TO ct_edidd.

  ENDDO.

  CLOSE DATASET p_file.

ENDFORM.

Next Steps for Implementation
  1. Define Message/IDoc Types: Ensure MRESCR (Message) and MRESCR01 (IDoc) are active in your system using transaction WE81 and WE30.
  2. Assign Inbound Function: Register your process code in WE42 (usually linked to IDOC_INPUT_MRESCR or BAPI_IDOC_INPUT1) so that the IDoc posts application data.
  3. Background Processing: If you set your Inbound Partner Profile (WE20) to collect IDocs instead of processing them immediately, you will need to schedule standard report RBDAPP01 to actually post the application data (status 64 to 53).

May 28, 2026

F4 Help to Get File from AL11 in Selection Screen

To provide F4 value help for files on the application server (AL11), the most effective way is to use specific SAP function modules within your ABAP code. Since standard search help doesn't automatically browse application server directories, you must implement the logic in the AT SELECTION-SCREEN ON VALUE-REQUEST event.

Recommended Function Modules
For browsing and selecting files directly from the application server, you can use these common modules:
  • /SAPDMC/LSM_F4_SERVER_FILE: This is widely used to open a pop-up that allows users to navigate the SAP AL11 directories and select a file.
  • F4_DXFILENAME_TOPRECURSION: Another standard function module specifically designed for search help on application server files.
Implementation Example
To add this help to a selection screen parameter (e.g., p_file), use the following logic in your report:

abap
PARAMETERS: p_file TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    IMPORTING
      serverfile       = p_file
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.

Key Considerations
  • Permissions: Ensure the user has the necessary authorizations (e.g., S_DATASET) to access the specific AL11 directory paths.
  • Directory-only Help: If you only need to select a directory (not a specific file), you can call the program RSWATCH0 or use F4IF_INT_TABLE_VALUE_REQUEST after fetching directory lists via EPS_GET_DIRECTORY_LISTING.
  • Presentation Server Difference: For files on your local PC (Presentation Server), use CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG instead