SAP Bilgi Merkezi
Ana Sayfa  ABAP   FI   CO   MM   SD   PP   QM   HR   BW 
ABAP Destek
IDOC
SAP den farklı sistemlere veya başka bir SAP sistemine veri gönderip almakta kullanılır. Gelen IDOC ve giden IDOC olmak üzere ikiye ayrılır. Aşağıda Outbound IDOC (Giden IDOC) örneği bulabilirsiniz.

Örnek Program:
FUNCTION ymaster_idoc_distribute.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(APPL_HEADER) LIKE  YTEST STRUCTURE  YTEST
*"  TABLES
*"      APPL_ITEM STRUCTURE  YTEST2
*"  EXCEPTIONS
*"      IDOC_FAILED
*"----------------------------------------------------------------------

* variables of general interest
  DATA:
*       control record for the IDoc
        idoc_control LIKE edidc,
*       data records for the IDoc
        t_idoc_data LIKE edidd OCCURS 0 WITH HEADER LINE,
*       table for the IDocs created by MASTER_IDOC_CONTROL
        t_comm_control LIKE edidc OCCURS 0 WITH HEADER LINE,
*       partner type for logical system
        c_partner_type_logical_system LIKE edidc-rcvprt,
*       help variable for the check if an IDoc has to be created
        h_create_idoc.

* variables specific for this example
  DATA:
*       field strings with IDoc segment structure
        YTEST01 LIKE YTEST01,
        YTEST02 LIKE YTEST02,
*       data to be put to the control record
        c_message_type LIKE edidc-mestyp VALUE 'ZUTST01',
        c_base_idoc_type LIKE edidc-idoctp VALUE 'YUTST01',
*       segment types to be put to the data record table
        c_header_segtyp LIKE edidd-segnam VALUE 'YTEST01',
        c_item_segtyp LIKE edidd-segnam VALUE 'YTEST02',
        c_port LIKE edidc-rcvpor VALUE 'SAPRRR',
        c_prt LIKE edidc-rcvprt VALUE 'LS',
        own_system LIKE bdi_logsys-logsys VALUE 'SD100',
        rec_system LIKE bdi_logsys-logsys VALUE 'CLNT100'.

* fill idoc control

  idoc_control-mestyp = c_message_type.
  idoc_control-idoctp = c_base_idoc_type.
  idoc_control-rcvprt = c_prt.
  idoc_control-rcvpor = c_port.
  idoc_control-rcvprn = own_system.
  idoc_control-sndprn = rec_system.
  idoc_control-sndprt = c_prt.
  idoc_control-sndpor = c_port.

* put the application header record to the IDoc
  MOVE-CORRESPONDING appl_header TO YTEST01.

* convert SAP codes to ISO codes
  PERFORM head_codes_sap_to_iso
    USING
      appl_header
    CHANGING
      YTEST01.

* append record to IDoc data table
  t_idoc_data-segnam = c_header_segtyp.
  t_idoc_data-sdata = YTEST01.
  APPEND t_idoc_data.

  LOOP AT appl_item.
*   put the application item record to the IDoc segment
    MOVE-CORRESPONDING appl_item TO YTEST02.

*   convert currency amounts from SAP internal to neutral format
    PERFORM item_currency_sap_to_idoc
      USING
        appl_header-waerk
      CHANGING
        YTEST02.

*   convert SAP codes to ISO codes
    PERFORM item_codes_sap_to_iso
      USING
        appl_item
      CHANGING
        YTEST02.

*   left justify all non character fields
    PERFORM item_condense
      CHANGING
        YTEST02.

*   append record to IDoc data table
    t_idoc_data-segnam = c_item_segtyp.
    t_idoc_data-sdata = YTEST02.
    APPEND t_idoc_data.
  ENDLOOP.

  CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
* in update task   "if application document is posted in update task
       EXPORTING
            master_idoc_control            = idoc_control
       TABLES
            communication_idoc_control     = t_comm_control
            master_idoc_data               = t_idoc_data.
*      exceptions
*           error_in_idoc_control          = 1
*           error_writing_idoc_status      = 2
*           error_in_idoc_data             = 3
*           sending_logical_system_unknown = 4
*           others                         = 5.

* A commit work has to be done. It could also be done in the calling
* application.
  CALL FUNCTION 'DB_COMMIT'.
  CALL FUNCTION 'DEQUEUE_ALL'.
  COMMIT WORK.

  READ TABLE t_comm_control INDEX 1.
  IF sy-subrc <> 0.
    RAISE idoc_failed.
  ENDIF.

ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  ITEM_CONDENSE
*&---------------------------------------------------------------------*
FORM item_condense
  CHANGING
    idoc_segment LIKE YTEST02.

* left justify all non character fields
  CONDENSE: idoc_segment-fkimg,
            idoc_segment-netwr,
            idoc_segment-tstmp.

ENDFORM.                               " ITEM_CONDENSE
*&---------------------------------------------------------------------*
*&      Form  ITEM_CURRENCY_SAP_TO_IDOC
*&---------------------------------------------------------------------*
FORM item_currency_sap_to_idoc
  USING
    currency_code LIKE tcurc-waers
  CHANGING
    idoc_segment LIKE YTEST02.

  CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_IDOC'
    EXPORTING
      currency    = currency_code
      sap_amount  = idoc_segment-netwr
    IMPORTING
      idoc_amount = idoc_segment-netwr.
*      exceptions
*           others      = 1.

ENDFORM.                               " ITEM_CURRENCY_SAP_TO_IDOC
*&---------------------------------------------------------------------*
*&      Form  HEAD_CODES_SAP_TO_ISO
*&---------------------------------------------------------------------*
FORM head_codes_sap_to_iso
  USING
    appl_data LIKE YTEST
  CHANGING
    idoc_segment LIKE YTEST01.

* convert a currency code from SAP code to ISO code
  IF NOT appl_data-waerk IS INITIAL.
    CALL FUNCTION 'CURRENCY_CODE_SAP_TO_ISO'
      EXPORTING
        sap_code = appl_data-waerk
      IMPORTING
        iso_code = idoc_segment-waerk.
*      exceptions
*           not_found = 1
*           others    = 2.
  ELSE.
    idoc_segment-waerk = appl_data-waerk.
  ENDIF.

* convert a country from SAP code to ISO code
  IF NOT appl_data-land1 IS INITIAL.
    CALL FUNCTION 'COUNTRY_CODE_SAP_TO_ISO'
      EXPORTING
        sap_code = appl_data-land1
      IMPORTING
        iso_code = idoc_segment-land1.
*      exceptions
*           not_found = 1
*           others    = 2.
  ELSE.
    idoc_segment-land1 = appl_data-land1.
  ENDIF.

ENDFORM.                               " HEAD_CODES_SAP_TO_ISO
*&---------------------------------------------------------------------*
*&      Form  ITEM_CODES_SAP_TO_ISO
*&---------------------------------------------------------------------*
FORM item_codes_sap_to_iso
  USING
    appl_data LIKE YTEST2
  CHANGING
    idoc_segment LIKE YTEST02.

* convert a unit of measure from SAP code to ISO code
  IF NOT appl_data-vrkme IS INITIAL.
    CALL FUNCTION 'UNIT_OF_MEASURE_SAP_TO_ISO'
      EXPORTING
        sap_code = appl_data-vrkme
      IMPORTING
        iso_code = idoc_segment-vrkme.
*      exceptions
*           not_found   = 1
*           no_iso_code = 2
*           others      = 3.
  ELSE.
    idoc_segment-vrkme = appl_data-vrkme.
  ENDIF.

* convert a package type from SAP code to ISO code
  IF NOT appl_data-evers IS INITIAL.
    CALL FUNCTION 'SAP_TO_ISO_PACKAGE_TYPE_CODE'
      EXPORTING
        sap_code = appl_data-evers
      IMPORTING
        iso_code = idoc_segment-evers.
*      exceptions
*           not_found = 1
*           others    = 2.
  ELSE.
    idoc_segment-evers = appl_data-evers.
  ENDIF.

ENDFORM.                               " ITEM_CODES_SAP_TO_ISO
ABAP Destek
SAP Chain
SAP NetWeaver
ticket sistemimize katılın ve ücretsiz
10 adam gün kazanın >>
 Ana Sayfa  |  ABAP  |  FI  |  CO  |  MM  |  SD  |  PP  |  QM  |  HR  |  BW 
ykomut@gmail.com