Copyright 2022 - BV TallVision IT

When an eCatt script requires actions to be performed on e.g. a Purchase Order which is normally created via an inbound Idoc - why not make eCatt create your example PO... This article describes the approach of using inbound Idoc processing to produce your test data. Before the Idoc can be set up, main data should be gathered from import parameters. The example creates a Purchase Order in the following steps:

  1. First the control record of the Idoc should be set up (in ABAP memory), at least the following information should be supplied: Message type (MESTYP), Idoc type (IDOCTP), Extension (if applicable) (CIMTYP), Direction (DIRECT) which should be set to 2 - Inbound, Receiver Port/Partner type=LS/Partner (RCVPOR/RCVPRT/RCVPRN), Sender Port/Partner type=LS/Partner (SNDPOR/SNDPRT/SNDPRN).
  2. Then the segments need to be populated, with the actual data with which the PO should be created, e.g. document type, material and quantity on the PO are passed to the segments.
  3. With the above preperation, the Idoc can be created with function module IDOC_INBOUND_WRITE_TO_DB. Make sure you pick up the Idoc number here. It will store the Idoc to the database in status 64 - Ready to be processed.
  4. To actually process the Idoc, call function module IDOC_START_INBOUND.
  5. Idoc has now been created and processed, but which Purchase Order has just been created ? Check this by selecting the Idoc processing status on EDIDC (control record) which should be 53, and also check table EDIDS for your Idoc to find the message that actually states which PO number has been created. There's always a message on Idoc processing informing you what happened..

The example:

The following 2 blocks are to be inserted in an eCatt script: do make sure the hardcoded settings are changed to suitable values for your system (a bit of Idoc knowledge is important here). Also note that V_EKKO and V_EKPO are to be populated by the script. This script also sets a V_MESSAGE (error message) variabele to be picked up by the script.

ABAP. 
*----------------------------------------------------
* Data Declaration
*----------------------------------------------------
DATA: i_edidc type table of EDIDC with header line,
      i_IDOC_DATA type table of EDIDD with header line,
      v_docnum like edidc-docnum,
      v_system(6),
      v_deliv_date like sy-datum,
      l_e1bpekkoc like e1bpekkoc, "PO Header
      l_e1bpekpoc like e1bpekpoc, "Create/List - PO Item
      l_e1bpekpoa like e1bpekpoa, "PO Item Additional Data
      l_e1bpeket like e1bpeket. "Display/List PO Schedule

*----------------------------------------------------
* Fill control record and Idoc data (per segment)
*----------------------------------------------------
concatenate 'SAP' sy-sysid into v_system.
CLEAR i_edidc.
i_edidc-MESTYP = 'ZUMPOC'.
i_edidc-IDOCTP = 'PORDCR04'.
i_edidc-CIMTYP = 'ZUMPORDCR04'.
i_edidc-rcvpor = v_system.
i_edidc-direct = 2.
i_edidc-rcvprt = 'LS'.
i_edidc-rcvprn = 'USAP'.
i_edidc-sndpor = 'TRFC'.
i_edidc-sndprt = 'LS'.
i_edidc-sndprn = 'UXELUS'.

* Fill Data segments - E1PORDCR -
CLEAR i_IDOC_DATA.
REFRESH i_IDOC_DATA.
i_IDOC_DATA-MANDT   = SY-MANDT.
i_idoc_data-segnum  = 1.
i_IDOC_DATA-SEGNAM  = 'E1PORDCR'.
i_idoc_data-psgnum  = 0.
i_idoc_data-hlevel  = 01.
i_IDOC_DATA-DTINT2  = 1000.
APPEND i_IDOC_DATA.
* Fill Data segments - E1BPEKKOC - Header data
CLEAR i_IDOC_DATA.
i_IDOC_DATA-MANDT   = SY-MANDT.
i_idoc_data-segnum  = 2.
i_IDOC_DATA-SEGNAM  = 'E1BPEKKOC'.
i_idoc_data-psgnum  = 0.
i_idoc_data-hlevel  = 02.
i_IDOC_DATA-DTINT2  = 1000.
move: sy-datum                to l_e1bpekkoc-doc_date,
      v_ekko-bsart            to l_e1bpekkoc-doc_type,
      v_ekko-ekorg            to l_e1bpekkoc-purch_org,
      v_ekko-lifnr            to l_e1bpekkoc-vendor.
move l_e1bpekkoc to i_idoc_data-sdata.
append i_idoc_data.
* Fill Data segments - E1BPEKPOC - Create/List - PO Item
CLEAR i_IDOC_DATA.
i_IDOC_DATA-MANDT   = SY-MANDT.
i_idoc_data-segnum  = 3.
i_IDOC_DATA-SEGNAM  = 'E1BPEKPOC'.
i_idoc_data-psgnum  = 0.
i_idoc_data-hlevel  = 02.
i_IDOC_DATA-DTINT2  = 1000.
move: v_ekpo-matnr   to l_e1bpekpoc-material,
      v_ekpo-lgort   to l_e1bpekpoc-store_loc,
      v_ekpo-werks   to l_e1bpekpoc-plant,
      'PCE'          to l_e1bpekpoc-po_unit_iso,
      'XELUS'        to l_e1bpekpoc-preq_name.
move l_e1bpekpoc to i_idoc_data-sdata.
append i_idoc_data.
* Fill Data segments - E1BPEKPOA - PO Item Additional Data
CLEAR i_IDOC_DATA.
i_IDOC_DATA-MANDT   = SY-MANDT.
i_idoc_data-segnum  = 4.
i_IDOC_DATA-SEGNAM  = 'E1BPEKPOA'.
i_idoc_data-psgnum  = 0.
i_idoc_data-hlevel  = 02.
i_IDOC_DATA-DTINT2  = 1000.
move 'X' to l_e1bpekpoa-gr_ind.
move l_e1bpekpoa to i_idoc_data-sdata.
append i_idoc_data.
* Fill Data segments - E1BPEKET - Display/List PO Schedule
CLEAR i_IDOC_DATA.
i_IDOC_DATA-MANDT   = SY-MANDT.
i_idoc_data-segnum  = 5.
i_IDOC_DATA-SEGNAM  = 'E1BPEKET'.
i_idoc_data-psgnum  = 0.
i_idoc_data-hlevel  = 02.
i_IDOC_DATA-DTINT2  = 1000.
v_deliv_date = sy-datum + 20.
move: v_deliv_date to l_e1bpeket-deliv_date,
      v_ekpo-menge to l_e1bpeket-quantity.
move l_e1bpeket to i_idoc_data-sdata.
append i_idoc_data.

*----------------------------------------------------
CALL FUNCTION 'IDOC_INBOUND_WRITE_TO_DB'
  IMPORTING
    PE_IDOC_NUMBER    = v_docnum
  TABLES
    T_DATA_RECORDS    = i_idoc_data
  CHANGING
    PC_CONTROL_RECORD = i_edidc
  EXCEPTIONS
    IDOC_NOT_SAVED    = 1
    OTHERS            = 2.
IF SY-SUBRC <> 0.
  move-corresponding syst to wa_message.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 into
          wa_message-msgtx.
  append wa_message to v_message.
  v_subrc = sy-subrc.
ELSE.

  commit work and wait.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      TEXT = 'ABAP: call to IDOC_START_INBOUND'.
  move v_docnum to v_idoc.
  append i_edidc.
*----------------------------------------------------
  CALL FUNCTION 'IDOC_START_INBOUND'
    EXPORTING
      PI_DO_COMMIT                  = 'X'
    TABLES
      T_CONTROL_RECORDS             = i_edidc
      T_DATA_RECORDS                = i_idoc_data
    EXCEPTIONS
      INVALID_DOCUMENT_NUMBER       = 1
      ERROR_BEFORE_CALL_APPLICATION = 2
      INBOUND_PROCESS_NOT_POSSIBLE  = 3
      OLD_WF_START_FAILED           = 4
      WF_TASK_ERROR                 = 5
      SERIOUS_INBOUND_ERROR         = 6
      OTHERS                        = 7.
  IF SY-SUBRC <> 0.
    move-corresponding syst to wa_message.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 into
            wa_message-msgtx.
    append wa_message to v_message.
    v_subrc = sy-subrc.
  ELSEIF v_docnum is initial.
    wa_message-msgtx = 'Idoc number could not be determined'.
    append wa_message to v_message.
    v_subrc = sy-subrc.
  ENDIF.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      TEXT = 'ABAP: IDOC_START_INBOUND - end'.
ENDIF.

ENDABAP. 

Idoc has been prepared, saved, processed and the PO should now have been created. Find out the result:

ABAP. 
*----------------------------------------------------
* Data Declaration
*----------------------------------------------------
DATA: v_statxt like edids-statxt,
      v_stapa1 like edids-stapa1,
      v_stapa2 like edids-stapa2,
      v_status like edidc-status,
      v_docnum like edidc-docnum.

* Check if the Idoc has been processed (status 51 or 53):
select single status from edidc into v_status
  where docnum eq v_docnum.
IF sy-subrc ne 0.
  concatenate 'Idoc' v_docnum 'could not be found'
      into wa_message-msgtx separated by space.
  append wa_message to v_message.
  v_subrc = sy-subrc.
ELSE.
*----------------------------------------------------
* Is the Idoc in status 64 ? If it is it needs to 
* be processed first:
  if v_status eq '64'.
    ranges r_DOCNUM for EDIDC-DOCNUM.
    clear: r_DOCNUM, r_DOCNUM[].
    r_DOCNUM = 'IEQ'.
    r_DOCNUM-low = v_docnum.
    append r_DOCNUM.

*----------------------------------------------------
    submit RBDAPP01
      with DOCNUM in r_DOCNUM
      EXPORTING LIST TO MEMORY
      and return.
*----------------------------------------------------
    wait up to 15 seconds.
  endif.
*----------------------------------------------------
  select single statxt stapa1 stapa2 from edids
    into (v_statxt,v_stapa1,v_stapa2)
    where docnum eq v_docnum and
          status eq '53' and
          stamqu eq 'SAP' and
          stamid eq '06' and
          stamno eq 17.

  if sy-subrc eq 0.
    concatenate v_stapa1 ' created under the number: '
      v_stapa2 into v_statxt.
    wa_message-msgtx = v_statxt.
    append wa_message to v_message.
    v_po_nr = v_stapa2.
    v_subrc = sy-subrc.
  else.
    select single statxt stapa1 from edids
      into (v_statxt,v_stapa1)
      where docnum eq v_docnum and status eq '51'.
    if sy-subrc eq 0.
      replace '&' in v_statxt with v_stapa1.
      wa_message-msgtx = v_statxt.
      append wa_message to v_message.
      v_subrc = sy-subrc.
    else.
      concatenate 'Idoc' v_docnum
        'could not be found in status 53 or 51'
        into wa_message-msgtx separated by space.
      append wa_message to v_message.
      v_subrc = sy-subrc.
    endif.
  endif.
endif.

ENDABAP.