In ideal scenario your middle-ware should have a listener for your outbound IDOC port. In case you don’t have and you need to expose your outbound IDOC as a service then you can use it. The idea is similar to inbound IDOC as service

It is a dynamic program to expose any outbound IDOC as web service. Data can be retrieved either in XML or JSON (String withing a tag). It can be used for any other outbound IDOC interface without any development.

Please follow the steps from inbound IDOC as service for step by step help. The idea is exactly similar. Some of the code reused here. You need

Steps:

  • Download the WSDL from tcode: ZIDOCWSDL_OB (TCode assigned)
  • Consume the WSDL as a “Service Provider”
  • Plug in FM: ZCA_OB_IDOC in the interface & activate the service provider
  • Create an endpoint for the Service provider, service is ready to be used

Advantages over RFC web services:

  • IDOC gets created in the runtime so we can avoid making all the DB queries to build the business logic (like we do in RFC’s).
  • It will be faster than RFC’s as all the data is already staged in IDOC. It gets the data from IDOC and sends it as response
  • No empty tags as we see in RFC based web services. It will reduce the payload significantly
  • JSON will reduce the payload even further making the overall performance better

OUTPUT example

 

JSON

 

 

This part is to generate the WSDL, please follow the steps from inbound IDOC as service and replace below code for outbound IDOC.

*----------------------------------------------------------------------*
***INCLUDE MSEDIDOCUF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  read_setget_param
*&---------------------------------------------------------------------*
FORM read_setget_param.
  DATA: l_type LIKE sed5struc-objecttype,
        l_object(30) TYPE c,
        l_recsel(3) TYPE c.

  GET PARAMETER ID 'SEG' FIELD seddocustr-segtyp.
  GET PARAMETER ID 'IDC' FIELD seddocustr-idoctyp.
  GET PARAMETER ID 'CIM' FIELD seddocustr-cimtyp.
  GET PARAMETER ID 'EDIDEF_OBJTYP' FIELD l_type. "settings from we30
  GET PARAMETER ID 'EDD' FIELD l_object.
  GET PARAMETER ID 'EDI_SELDOCU' FIELD l_recsel. "record selection

  IF sy-tcode EQ 'WE62'.               " segment documentation
    CLEAR seddocustr-bassel.
    CLEAR seddocustr-cimsel.
    seddocustr-segsel = 'X'.
  ELSEIF sy-tcode EQ 'WE61'.           "record types
    seddocustr-controlrec = 'X'.
    seddocustr-datarec = 'X'.
    seddocustr-statusrec = 'X'.
  ELSEIF sy-tcode EQ 'WE60' OR sy-tcode EQ 'WE63'.
    IF l_type EQ c_ext.
      CLEAR seddocustr-bassel.
      CLEAR seddocustr-segsel.
      seddocustr-cimsel = 'X'.
      IF NOT l_object IS INITIAL.
        seddocustr-cimtyp = l_object.
      ENDIF.
    ELSE.
      seddocustr-bassel = 'X'.
      CLEAR seddocustr-segsel.
      CLEAR seddocustr-cimsel.
      IF NOT l_object IS INITIAL.
        seddocustr-idoctyp = l_object.
      ENDIF.
    ENDIF.
  ENDIF.

* selection for record types suggested via SET/GET-parameter
* afterthat clear SET/GET-parameter, because the transaction itself
* does not support the SET/GET-parameter for selection of record types
  IF NOT l_recsel IS INITIAL.
    seddocustr-controlrec = l_recsel(1).
    seddocustr-datarec    = l_recsel+1(1).
    seddocustr-statusrec = l_recsel+2(1).
    SET PARAMETER ID 'EDI_SELDOCU' FIELD '   '.
  ENDIF.

ENDFORM.                               " read_setget_param
*&---------------------------------------------------------------------*
*&      Form  check_and_set_descrp
*&---------------------------------------------------------------------*
FORM check_and_set_descrp.
  DATA: l_attributes TYPE edi_iapi01,
        l_seghead    TYPE edisegmhd.

  CLEAR seddocustr-idoctdescr.
  CLEAR seddocustr-cimdescrp.
  CLEAR seddocustr-segdescrp.
  IF  seddocustr-idoctyp NE space.
* basic type selected
* existence check
    CALL FUNCTION 'IDOCTYPE_EXISTENCE_CHECK'
      EXPORTING
        pi_idoctyp    = seddocustr-idoctyp
        pi_read_devc  = ' '
      IMPORTING
        pe_attributes = l_attributes
      EXCEPTIONS
        OTHERS        = 1.
    IF sy-subrc <> 0      AND
       g_init_flag EQ 'X' AND
       okcode_100 NE 'TYPSEL' AND
       seddocustr-bassel NE space.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
* set description
    seddocustr-idoctdescr = l_attributes-descrp.
  ENDIF.
  IF seddocustr-cimtyp NE space.
* extension selected
* existence check
    CLEAR l_attributes.
    CALL FUNCTION 'EXTTYPE_EXISTENCE_CHECK'
      EXPORTING
        pi_cimtyp     = seddocustr-cimtyp
        pi_read_devc  = ' '
      IMPORTING
        pe_attributes = l_attributes
      EXCEPTIONS
        OTHERS        = 1.
    IF sy-subrc <> 0 AND g_init_flag EQ 'X'
       AND okcode_100 NE 'TYPSEL'
       AND seddocustr-cimsel NE space.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
* set description
    seddocustr-cimdescrp = l_attributes-descrp.
  ENDIF.
  IF seddocustr-segtyp NE space.
* segment is selected
    l_seghead-segtyp = seddocustr-segtyp.
    CALL FUNCTION 'SEGMENT_READ'
      EXPORTING
        segmenttyp    = l_seghead-segtyp
      IMPORTING
        segmentheader = l_seghead
      EXCEPTIONS
        OTHERS        = 1.
    IF sy-subrc <> 0 AND g_init_flag EQ 'X'
       AND okcode_100 NE 'TYPSEL'
       AND seddocustr-segsel NE space.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
* set description
    seddocustr-segdescrp = l_seghead-descrp.
  ENDIF.
ENDFORM.                               " check_and_set_descrp
*&---------------------------------------------------------------------*
*&      Form  read_version_descrp
*&---------------------------------------------------------------------*
FORM read_version_descrp.
  CALL FUNCTION 'DDIF_DOMA_GET'
    EXPORTING
      name      = 'EDI_VERSIO'
      langu     = sy-langu
    TABLES
      dd07v_tab = gt_version_descrp.
**       exceptions
**            illegal_input = 1
**            others        = 2.
* ignore exceptions
  LOOP AT gt_version_descrp WHERE domvalue_l EQ seddocustr-version.
    seddocustr-verdescrp = gt_version_descrp-ddtext.
    EXIT.
  ENDLOOP.
ENDFORM.                               " read_version_descrp
*&---------------------------------------------------------------------*
*&      Form  start_html_docu
*&---------------------------------------------------------------------*
FORM start_html_docu.
  DATA: l_type TYPE char1,
        l_segment TYPE edilsegtyp,
        l_object TYPE edi_docobj.


* basic type or extension
  IF NOT seddocustr-bassel IS INITIAL.
    l_type = 'B'.
    CONCATENATE text-100 seddocustr-idoctyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-idoctyp.
  ELSEIF NOT seddocustr-cimsel IS INITIAL.
    l_type = 'E'.
    CONCATENATE text-101 seddocustr-cimtyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-cimtyp.
  ELSEIF NOT seddocustr-segsel IS INITIAL.
    l_segment = seddocustr-segtyp.
    IF l_segment IS INITIAL.
      MESSAGE s653(e0). EXIT.
    ENDIF.
  ENDIF.

* check selection
  IF l_object              IS INITIAL AND
     seddocustr-segsel     IS INITIAL AND
     seddocustr-controlrec IS INITIAL AND
     seddocustr-datarec    IS INITIAL AND
     seddocustr-statusrec  IS INITIAL.
    MESSAGE s346.
    EXIT.
  ENDIF.


* fill global tables with html sources
  REFRESH gt_frameset. REFRESH gt_index. REFRESH gt_docu.
  REFRESH gt_formated_docu.
  g_basisurl = l_object.
  IF g_basisurl EQ space.
    g_basisurl = l_segment.
  ENDIF.
  WHILE g_basisurl CS '/'.
    REPLACE '/' WITH '' INTO g_basisurl.
  ENDWHILE.
  CONDENSE g_basisurl NO-GAPS.

  IF NOT seddocustr-bassel IS INITIAL OR
     NOT seddocustr-cimsel IS INITIAL.
    IF l_object IS INITIAL.   "only record types
      g_titel = text-103.
    ENDIF.
    CALL FUNCTION 'IDOC_TYPE_GENERATE_HTML'
      EXPORTING
        struct_type         = l_type
        idoctype            = l_object
        release             = g_released
        applrel             = gd_applrel
        version             = seddocustr-version
        basisurl            = g_basisurl
        with_control_record = seddocustr-controlrec
        with_data_record    = seddocustr-datarec
        with_status_record  = seddocustr-statusrec
      IMPORTING
        tab_frame           = gt_frameset
        tab_index           = gt_index
        tab_docu            = gt_docu
        htmlext             = g_htmlext
      EXCEPTIONS
        OTHERS              = 1.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ELSEIF NOT seddocustr-segsel IS INITIAL.
* segment type
    CONCATENATE text-102 l_segment INTO g_titel
                  SEPARATED BY space.
    CALL FUNCTION 'IDOC_SEGMENT_GENERATE_HTML'
      EXPORTING
        segment   = l_segment
        release   = g_released
        applrel   = gd_applrel
        version   = seddocustr-version
        basisurl  = g_basisurl
      IMPORTING
        tab_frame = gt_frameset
        tab_index = gt_index
        tab_docu  = gt_docu
        htmlext   = g_htmlext
      EXCEPTIONS
        OTHERS    = 1.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.
* display docu
  CALL SCREEN 200.
ENDFORM.                               " start_html_docu
*&---------------------------------------------------------------------*
*&      Form  start_user_settings
*&---------------------------------------------------------------------*

FORM start_user_settings.
  CALL FUNCTION 'IDOC_MAINTAIN_USER'
    EXCEPTIONS
      OTHERS = 1.


  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                               " start_user_settings

*&---------------------------------------------------------------------*
*&      Form  check_unicode
*&---------------------------------------------------------------------*

FORM ask_unicode CHANGING unicode_flag.
  DATA l_answer TYPE char1.

  IF  seddocustr-version = '3'
      AND save_okcode100 = 'SCHEMA'.
    CLEAR unicode_flag.
    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
      EXPORTING
        defaultoption  = 'Y'
        textline1      = text-106
        titel          = syst-title
        cancel_display = space
      IMPORTING
        answer         = l_answer.
    IF l_answer = 'J'.
      MOVE 'X' TO unicode_flag.
    ENDIF.
  ENDIF.
ENDFORM.                               " check_unicode

*&---------------------------------------------------------------------*
*&      Form  start_cheader_docu
*&---------------------------------------------------------------------*

FORM start_cheader_docu.
  DATA: l_type TYPE char1,
        l_object TYPE edi_docobj.


* basic type or extension
  IF NOT seddocustr-bassel IS INITIAL.
    l_type = 'B'.
    CONCATENATE text-100 seddocustr-idoctyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-idoctyp.
  ELSEIF NOT seddocustr-cimsel IS INITIAL.
    l_type = 'E'.
    CONCATENATE text-101 seddocustr-cimtyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-cimtyp.
  ELSEIF NOT seddocustr-segsel IS INITIAL.
    MESSAGE s345.
    EXIT.
  ENDIF.

* check selection
  IF l_object              IS INITIAL AND
     seddocustr-controlrec IS INITIAL AND
     seddocustr-datarec    IS INITIAL AND
     seddocustr-statusrec  IS INITIAL.
    MESSAGE s346.
    EXIT.
  ENDIF.

* generate c-header-declarations
  REFRESH gt_formated_docu.
  CALL FUNCTION 'IDOC_TYPE_GENERATE_C_HEADER'
    EXPORTING
      release               = g_released
      applrel               = gd_applrel
      struct_type           = l_type
      idoctype              = l_object
      with_control_record   = seddocustr-controlrec
      with_data_record      = seddocustr-datarec
      with_status_record    = seddocustr-statusrec
      version               = seddocustr-version
    TABLES
      text                  = gt_formated_docu
    EXCEPTIONS
      definition_read_error = 1
      format_error          = 2
      OTHERS                = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* output the table with C-Declarations
  PERFORM write_docu.


ENDFORM.                               " start_cheader_docu
*&---------------------------------------------------------------------*
*&      Form  write_docu
*&---------------------------------------------------------------------*
FORM write_docu.
  DATA: wa_docu TYPE LINE OF sedidoculine.
  LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 100.
  IF save_okcode100 EQ 'PARSER'.
    SET PF-STATUS 'DISPLAY_DOCU'.
  ELSE.
    SET PF-STATUS 'DISPLAY_DOCU' EXCLUDING 'PINFO'.
  ENDIF.
  SET TITLEBAR  'DISPLAY_DOCU' WITH g_titel.
  NEW-PAGE NO-TITLE LINE-SIZE 255.
  LOOP AT gt_formated_docu INTO wa_docu.
    IF wa_docu IS INITIAL.
      WRITE /.
    ELSE.
      WRITE wa_docu.
    ENDIF.
  ENDLOOP.
ENDFORM.                               " write_docu
*&---------------------------------------------------------------------*
*&      Form  start_dtd_docu
*&---------------------------------------------------------------------*
FORM start_dtd_docu USING conv_version TYPE edi_unicod.
  DATA:  l_idoctyp LIKE  edi_iapi00-idoctyp,
         l_cimtyp  LIKE  edi_iapi00-cimtyp,
         l_cimattr LIKE  edi_iapi01.


* check selection
  IF NOT seddocustr-segsel IS INITIAL.
    MESSAGE s345.
    EXIT.
  ELSEIF NOT seddocustr-bassel IS INITIAL AND
         seddocustr-idoctyp IS INITIAL .
    MESSAGE s653(e0).
    EXIT.
  ELSEIF NOT seddocustr-cimsel IS INITIAL AND
         seddocustr-cimtyp IS INITIAL.
    MESSAGE s653(e0).
    EXIT.
  ENDIF.

* basic type or extension
  IF NOT seddocustr-bassel IS INITIAL.
    l_idoctyp = seddocustr-idoctyp.
    CONCATENATE text-100 seddocustr-idoctyp INTO g_titel
                SEPARATED BY space.
  ELSEIF NOT seddocustr-cimsel IS INITIAL.
* read related basic type
    CALL FUNCTION 'EXTTYPE_READ'
      EXPORTING
        pi_cimtyp     = seddocustr-cimtyp
        pi_read_devc  = ' '
      IMPORTING
        pe_attributes = l_cimattr
      EXCEPTIONS
        OTHERS        = 1.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    l_idoctyp = l_cimattr-idoctyp.
    l_cimtyp = seddocustr-cimtyp.
    CONCATENATE text-101 seddocustr-cimtyp INTO g_titel
                SEPARATED BY space.
  ENDIF.

* generate dtd-definition
  REFRESH gt_formated_docu.
  CALL FUNCTION 'IDOC_TYPE_DTD_TABLE'
    EXPORTING
      pi_idoctype    = l_idoctyp
      pi_cimtype     = l_cimtyp
      pi_dtd_type    = 'E'
      unicode_format = conv_version
    TABLES
      pt_dtd         = gt_formated_docu
    EXCEPTIONS
      OTHERS         = 1.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  IF seddocustr-docurel NE space OR seddocustr-version NE '3'.
    CALL FUNCTION 'POPUP_DISPLAY_TEXT'
      EXPORTING
        popup_title = text-105
        text_object = 'SED_DTD_INFO'
      EXCEPTIONS
        OTHERS      = 0.
  ENDIF.
* output the table with dtd-definition
  PERFORM write_docu.
ENDFORM.                               " start_dtd_docu
*&---------------------------------------------------------------------*
*&      Form  start_idoc
*&---------------------------------------------------------------------*
FORM start_idoc.
  DATA: l_type TYPE char1,
        l_docnum TYPE edi_docnum,
        l_object TYPE edi_docobj.
  RANGES lt_idocs FOR edidc-docnum OCCURS 2.


* basic type or extension
  IF NOT seddocustr-bassel IS INITIAL.
    l_type = 'B'.
    CONCATENATE text-100 seddocustr-idoctyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-idoctyp.
  ELSEIF NOT seddocustr-cimsel IS INITIAL.
    l_type = 'E'.
    CONCATENATE text-101 seddocustr-cimtyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-cimtyp.
  ELSEIF NOT seddocustr-segsel IS INITIAL.
    MESSAGE s345.
    EXIT.
  ENDIF.

* check selection
  IF l_object              IS INITIAL AND
     seddocustr-controlrec IS INITIAL AND
     seddocustr-datarec    IS INITIAL AND
     seddocustr-statusrec  IS INITIAL.
    MESSAGE s346.
    EXIT.
  ENDIF.


  IF NOT l_object IS INITIAL.
* basic type or extension selected ->
* create idoc for log. message SYIDOC
    CALL FUNCTION 'EDI_CREATE_SYIDOC01'
      EXPORTING
        object         = l_object
        object_type    = l_type
        object_release = g_released
        object_applrel = gd_applrel
        pi_rec_version = seddocustr-version
      IMPORTING
        docnum         = l_docnum
      EXCEPTIONS
        OTHERS         = 1.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    IF l_docnum NE 0.
      lt_idocs-sign = 'I'.
      lt_idocs-option = 'EQ'.
      lt_idocs-low = l_docnum.
      APPEND lt_idocs.
    ENDIF.
  ENDIF.
  IF NOT seddocustr-controlrec IS INITIAL OR
     NOT seddocustr-datarec    IS INITIAL OR
     NOT seddocustr-statusrec  IS INITIAL.
* create idoc for log.Message SYRECD
    CALL FUNCTION 'EDI_CREATE_SYRECD01'
      EXPORTING
        version             = seddocustr-version
        with_control_record = seddocustr-controlrec
        with_data_record    = seddocustr-datarec
        with_status_record  = seddocustr-statusrec
      IMPORTING
        docnum              = l_docnum
      EXCEPTIONS
        OTHERS              = 1.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    IF l_docnum NE 0.
      lt_idocs-sign = 'I'.
      lt_idocs-option = 'EQ'.
      lt_idocs-low = l_docnum.
      APPEND lt_idocs.
    ENDIF.
  ENDIF.
* display idocs (if created)
  IF NOT lt_idocs[] IS INITIAL.
    SUBMIT rseidoc2 WITH docnum IN lt_idocs AND RETURN.
  ENDIF.
ENDFORM.                               " start_idoc
*&---------------------------------------------------------------------*
*&      Form  start_parser_docu
*&---------------------------------------------------------------------*
FORM start_parser_docu.
  DATA: l_type TYPE char1,
        l_object TYPE edi_docobj.


* basic type or extension
  IF NOT seddocustr-bassel IS INITIAL.
    l_type = 'B'.
    CONCATENATE text-100 seddocustr-idoctyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-idoctyp.
  ELSEIF NOT seddocustr-cimsel IS INITIAL.
    l_type = 'E'.
    CONCATENATE text-101 seddocustr-cimtyp INTO g_titel
                SEPARATED BY space.
    l_object = seddocustr-cimtyp.
  ELSEIF NOT seddocustr-segsel IS INITIAL.
    MESSAGE s345.
    EXIT.
  ENDIF.

* check selection
  IF l_object              IS INITIAL AND
     seddocustr-controlrec IS INITIAL AND
     seddocustr-datarec    IS INITIAL AND
     seddocustr-statusrec  IS INITIAL.
    MESSAGE s346.
    EXIT.
  ENDIF.



* generate c-header-declarations
  REFRESH gt_formated_docu.
  CALL FUNCTION 'EDI_IDOC_PARSER'
    EXPORTING
      object                = l_object
      object_type           = l_type
      object_release        = g_released
      object_applrel        = gd_applrel
      version               = seddocustr-version
      with_control_record   = seddocustr-controlrec
      with_data_record      = seddocustr-datarec
      with_status_record    = seddocustr-statusrec
    IMPORTING
      parser_docu           = gt_formated_docu
    EXCEPTIONS
      definition_read_error = 1
      OTHERS                = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* output the table with parser docu
  PERFORM write_docu.
ENDFORM.                               " start_parser_docu
*----------------------------------------------------------------------*
*       start_schema_docu                                              *
*----------------------------------------------------------------------*
FORM start_schema_docu USING unicode_flag TYPE char1.
* wenn unicode_flag = 'X', hat TABNAME den Wert 'EDI_DC40_U'
* hier muß seddocustr-bassel gefüllt sein
* in seddocustr-idoctyp steht Basis-IDoctyp
  DATA: document TYPE REF TO if_ixml_document,
        xml_schema TYPE REF TO if_ixml_element,             "#EC NEEDED
        schema_control TYPE dcxmlschcl,
        mestyp TYPE edi_mestyp ,
        idoctyp TYPE edi_idoctp,
        control TYPE dcxmlidscl,
        elements TYPE dcxmlelems,
        e TYPE REF TO if_ixml_element,
        i TYPE REF TO if_ixml_node_iterator,
        d TYPE REF TO if_ixml_node,
        m TYPE REF TO if_ixml_named_node_map,
        rc TYPE sy-subrc,
        idoctypdescr TYPE dcxmlidocd.

  DATA: xml(3) VALUE 'XML',
        xml_non_released.

  FIELD-SYMBOLS:
    <element> TYPE REF TO if_ixml_element.

  IF g_released IS INITIAL AND gd_applrel IS INITIAL.
    xml_non_released = 'X'.
  ENDIF.
  EXPORT xml_non_released TO MEMORY ID xml.

* namespace xsd for FUNCTION SDIXML_SCHEMA_CREATE:
  schema_control-xsdnsp = 'xsd'.

  CALL FUNCTION 'SDIXML_SCHEMA_CREATE'
    EXPORTING
      control        = schema_control
    IMPORTING
      schema         = xml_schema
    CHANGING
      document       = document
    EXCEPTIONS
      internal_error = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.

  mestyp = ' '.
  control-idoc_text = 'X'.
  control-langu = sy-langu.
  control-atom_text = 'X'.
  control-stru_text = 'X'.
  control-ttyp_text = 'X'.
* namespace xsd for FUNCTION SDIXML_IDOC_TO_SCHEMA:
  control-xsdnsp    = 'xsd'.
  control-version = '02'.

  IF seddocustr-bassel = 'X'.
    IF NOT seddocustr-idoctyp IS INITIAL.
      idoctyp = seddocustr-idoctyp.
      control-is_cim = ' '.
      CALL FUNCTION 'SDIXML_IDOC_TO_SCHEMA'
        EXPORTING
          mestyp          = mestyp
          idoctyp         = idoctyp
          control         = control
        IMPORTING
          elements        = elements
        CHANGING
          idocdescr       = idoctypdescr
          document        = document
        EXCEPTIONS
          idoc_not_exists = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
    ELSE.
      MESSAGE s346(ea).
      EXIT.
    ENDIF.
  ELSEIF seddocustr-cimsel = 'X'.
    IF NOT seddocustr-cimtyp IS INITIAL.
      idoctyp = seddocustr-cimtyp.
      control-is_cim = 'X'.
      CALL FUNCTION 'SDIXML_IDOC_TO_SCHEMA'
        EXPORTING
          mestyp          = mestyp
          idoctyp         = idoctyp
          control         = control
        IMPORTING
          elements        = elements
        CHANGING
          idocdescr       = idoctypdescr
          document        = document
        EXCEPTIONS
          idoc_not_exists = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
    ELSE.
      MESSAGE s346(ea).
      EXIT.
    ENDIF.
  ELSE. " es muß eins der beiden ausgewählt worden sein
  ENDIF.

* creation of the document
* --> creation of the header
  CALL METHOD document->append_child
    EXPORTING
      new_child = xml_schema
    RECEIVING
      rval      = rc.
  CHECK rc = 0.
* --> creation of the body
  LOOP AT elements ASSIGNING <element>.
    IF NOT <element> IS INITIAL.
      CALL METHOD xml_schema->append_child
        EXPORTING
          new_child = <element>
        RECEIVING
          rval      = rc.
      IF rc NE 0.
        EXIT.
      ENDIF.
    ENDIF.
  ENDLOOP.

* Change the value of the field TABNAME, if unicode_flag = 'X'.
  IF NOT unicode_flag IS INITIAL.
    i = document->create_iterator( 10 ).
    d = i->get_next( ).
    WHILE NOT d IS INITIAL.
      IF d->get_name( ) = 'element'.                        "#EC NOTEXT
        m = d->get_attributes( ).
        IF NOT m IS INITIAL.
          d = m->get_named_item( 'name' ).                  "#EC NOTEXT
          IF NOT d IS INITIAL
              AND d->get_value( ) = 'TABNAM'.               "#EC NOTEXT
            d = m->get_named_item( 'fixed' ).               "#EC NOTEXT
            IF d->get_value( ) = 'EDI_DC40'.                "#EC NOTEXT
              d->set_value( value = 'EDI_DC40_U' ).         "#EC NOTEXT
              EXIT.
            ENDIF.
          ENDIF.
        ENDIF.
      ELSE.
        d = i->get_next( ).
      ENDIF.
    ENDWHILE.
  ENDIF.

  DATA: cwsdl TYPE string.
  DATA: xwsdl          TYPE  xstring.

  CALL METHOD zcl_proxy_utils_ob=>get_wsdl
    EXPORTING
      document = document
      idoctyp  = idoctyp
    IMPORTING
      cwsdl    = cwsdl.

  PERFORM xml_download USING cwsdl idoctyp.
ENDFORM.                    "start_schema_docu
*&---------------------------------------------------------------------*
*&      Form  Xml_download
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->XML        text
*      -->SIZE       text
*----------------------------------------------------------------------*
FORM xml_download USING wsdl TYPE string
                        idoctyp type any.
  "SIZE TYPE I.

  DATA: t_wsdl TYPE TABLE OF string.

  DATA: filename TYPE string,
        rc TYPE sy-subrc.
  PERFORM get_filename USING 'S' CHANGING filename rc idoctyp.
  CHECK rc = 0.

  APPEND wsdl TO t_wsdl.
  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
*      BIN_FILESIZE              =
      filename                  = filename
    CHANGING
      data_tab                  = t_wsdl
    EXCEPTIONS
      file_write_error          = 1
      no_batch                  = 2
      gui_refuse_filetransfer   = 3
      invalid_type              = 4
      no_authority              = 5
      unknown_error             = 6
      header_not_allowed        = 7
      separator_not_allowed     = 8
      filesize_not_allowed      = 9
      header_too_long           = 10
      dp_error_create           = 11
      dp_error_send             = 12
      dp_error_write            = 13
      unknown_dp_error          = 14
      access_denied             = 15
      dp_out_of_memory          = 16
      disk_full                 = 17
      dp_timeout                = 18
      file_not_found            = 19
      dataprovider_exception    = 20
      control_flush_error       = 21
      not_supported_by_gui      = 22
      error_no_gui              = 23
      OTHERS                    = 24
          .
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.


ENDFORM.                    " Xml_download

*&---------------------------------------------------------------------*
*&      Form  Get_filename
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->MODE       text
*      -->FILENAME   text
*      -->RC         text
*----------------------------------------------------------------------*
FORM get_filename USING mode TYPE c
                  CHANGING filename TYPE string
                           rc TYPE sy-subrc
                           idoctyp type any.

  DATA: fname TYPE string,
        path TYPE string,
        action TYPE i,
        filetable TYPE filetable,
        file_line TYPE file_table,
        rc_lok TYPE sy-subrc,
        file_name type string,
        file_filter TYPE string.

  CLASS cl_gui_frontend_services DEFINITION LOAD.
  CONCATENATE cl_gui_frontend_services=>filetype_xml
              cl_gui_frontend_services=>filetype_all
              INTO file_filter.
  file_name = idoctyp.
  IF mode = 'S'.

    CALL METHOD cl_gui_frontend_services=>file_save_dialog
      EXPORTING
        WINDOW_TITLE      = 'Download WSDL file'
        default_extension = 'wsdl'                           "#EC NOTEXT
        DEFAULT_FILE_NAME = file_name
        file_filter       = file_filter
*       INITIAL_DIRECTORY =
      CHANGING
        filename          = fname
        path              = path
        fullpath          = filename
        user_action       = action
      EXCEPTIONS
        OTHERS            = 3.
  ELSE.
    CALL METHOD cl_gui_frontend_services=>file_open_dialog
      EXPORTING
        WINDOW_TITLE            = 'Download WSDL file'
        default_extension       = 'wsdl'                     "#EC NOTEXT
        DEFAULT_FILENAME        = idoctyp
        file_filter             = file_filter
*       INITIAL_DIRECTORY       =
*       MULTISELECTION          =
      CHANGING
        file_table              = filetable
        rc                      = rc_lok
        user_action             = action
      EXCEPTIONS
        file_open_dialog_failed = 0
        OTHERS                  = 4.
  ENDIF.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  IF action = cl_gui_frontend_services=>action_cancel.
    rc = 4.
    EXIT.
  ENDIF.
  IF mode = 'O'.
    READ TABLE filetable INDEX 1 INTO file_line.
    IF sy-subrc <> 0.
      rc = 4.
      EXIT.
    ENDIF.
    filename = file_line-filename.
  ENDIF.
ENDFORM.                    " Get_filename
METHOD get_wsdl.
  DATA: xml_as_string TYPE  xstring,
        wsdl          TYPE  xstring,
        cwsdl2        TYPE  string.

  DATA: proxy	TYPE REF TO	cl_proxy.


  CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
      document      = document
*     PRETTY_PRINT  = ' '
    IMPORTING
      xml_as_string = xml_as_string
*     SIZE          =
* TABLES
*     XML_AS_TABLE  =
    EXCEPTIONS
      no_document   = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL METHOD cl_proxy_service=>xstring2cstring
    EXPORTING
      xstring = xml_as_string
    RECEIVING
      cstring = cwsdl.

  DATA: res1 TYPE string.
  CONCATENATE '<xsd:element name="' idoctyp '">' INTO res1.

  DATA: res2 TYPE string.
  CONCATENATE '<xsd:element name="O' idoctyp '.Response">' INTO res2.

  REPLACE FIRST OCCURRENCE OF '<?xml version="1.0" encoding="utf-8"?>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF res1 IN cwsdl WITH res2.

  DATA: js TYPE string.
  CONCATENATE
        '<xsd:element name="JSON" type="xsd:string" minOccurs="0">'
        '<xsd:annotation>'
        '<xsd:documentation>JSON String</xsd:documentation>'
        '</xsd:annotation>'
        '</xsd:element>'
        '<xsd:element name="IDOC">' INTO js.
  REPLACE FIRST OCCURRENCE OF '<xsd:element name="IDOC">' IN cwsdl WITH js.

  FIND '</xsd:schema>' IN cwsdl.
  IF sy-subrc = 0.
    DATA: lv_res TYPE string.
    CONCATENATE
  '<xsd:schema targetNamespace="http://SAPIdocServices.com" xmlns="http://SAPIdocServices.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
    '<xsd:element name="O' idoctyp '">'
    '<xsd:complexType>'
     '<xsd:all>'
      '<xsd:element name="DOCUMENT_NUMBER" minOccurs="0">'
       '<xsd:annotation>'
        '<xsd:documentation>Document Number</xsd:documentation>'
       '</xsd:annotation>'
       '<xsd:simpleType>'
        '<xsd:restriction base="xsd:string">'
         '<xsd:maxLength value="10"/>'
        '</xsd:restriction>'
       '</xsd:simpleType>'
      '</xsd:element>'
      '<xsd:element name="IDOC_NUMBER" minOccurs="0">'
       '<xsd:annotation>'
       '<xsd:documentation>IDOC Number</xsd:documentation>'
       '</xsd:annotation>'
       '<xsd:simpleType>'
        '<xsd:restriction base="xsd:string">'
         '<xsd:maxLength value="16"/>'
        '</xsd:restriction>'
       '</xsd:simpleType>'
      '</xsd:element>'
   '<xsd:element name="JSON" minOccurs="0">'
    '<xsd:annotation>'
     '<xsd:documentation>JSON String</xsd:documentation>'
      '</xsd:annotation>'
       '<xsd:simpleType>'
        '<xsd:restriction base="xsd:string">'
         '<xsd:maxLength value="1"/>'
        '</xsd:restriction>'
       '</xsd:simpleType>'
      '</xsd:element>'
     '</xsd:all>'
    '</xsd:complexType>'
   '</xsd:element>'
   cwsdl INTO lv_res.

  ENDIF.

*  SPLIT cwsdl AT '</xsd:schema>' INTO cwsdl cwsdl2.
*  IF sy-subrc = 0.
*    CONCATENATE cwsdl lv_res INTO cwsdl.
*  ENDIF.

  CALL METHOD cl_proxy_service=>cstring2xstring
    EXPORTING
      cstring = lv_res
    RECEIVING
      xstring = wsdl.

  TRY.
      CALL METHOD zcl_proxy_utils=>xsd2wsdl
        EXPORTING
          schema = wsdl
        RECEIVING
          wsdl   = wsdl.
    CATCH cx_proxy_gen_error .
  ENDTRY.

  CALL METHOD cl_proxy_service=>xstring2cstring
    EXPORTING
      xstring = wsdl
    RECEIVING
      cstring = cwsdl.

*  IF idoctyp IS INITIAL.
*    idoctyp = mestyp.
*  ENDIF.

  CLEAR lv_res.
  CONCATENATE
  '<wsdl:definitions name="O' idoctyp '" targetNamespace="http://SAPIdocServices.com" xmlns:tns="http://SAPIdocServices.com" '
   'xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" '
   'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">'
    '<wsp:UsingPolicy wsdl:required="true" />'
    '<wsp:Policy wsu:Id="OP_O' idoctyp '" />' INTO lv_res RESPECTING BLANKS.

  REPLACE FIRST OCCURRENCE OF
  '<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://SAPIdocServices.com" targetNamespace="http://SAPIdocServices.com">'
   IN cwsdl WITH lv_res.

  REPLACE FIRST OCCURRENCE OF '</wsdl:operation>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '</wsdl:portType>' IN cwsdl WITH ''.
  CLEAR lv_res.
  CONCATENATE '<wsdl:part name="part1" element="tns:O' idoctyp '"/>' INTO lv_res.
  REPLACE FIRST OCCURRENCE OF lv_res IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '</wsdl:message>' IN cwsdl WITH ''.
  CLEAR lv_res.
  CONCATENATE '<wsdl:part name="part2" element="tns:O' idoctyp '.Response"/>' INTO lv_res.
  REPLACE FIRST OCCURRENCE OF lv_res IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '</wsdl:message>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:output message="tns:message1"/>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:input message="tns:message2"/>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:portType name="Http">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:operation name="op1">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:operation name="op1">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:input message="tns:message1"/>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:output message="tns:message2"/>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:message name="message1">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:message name="message2">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:operation name="op2">' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:input message="tns:message1"/>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '<wsdl:output message="tns:message2"/>' IN cwsdl WITH ''.
  REPLACE FIRST OCCURRENCE OF '</wsdl:operation>' IN cwsdl WITH ''.


  SPLIT cwsdl AT '</wsdl:definitions>' INTO cwsdl cwsdl2.
  CLEAR lv_res.
  CONCATENATE
  '<wsdl:message name="tns.O' idoctyp '_IN">'
    '<wsdl:part name="part1" element="tns:O' idoctyp '" />'
     '</wsdl:message>'
     '<wsdl:message name="tns.O' idoctyp '_OUT">'
    '<wsdl:part name="part2" element="tns:O' idoctyp '.Response" />'
  '</wsdl:message>'

  '<wsdl:portType name="O' idoctyp '">'
    '<wsdl:operation name="O' idoctyp '">'
      '<wsdl:input message="tns:tns.O' idoctyp '_IN" />'
      '<wsdl:output message="tns:tns.O' idoctyp '_OUT" />'
    '</wsdl:operation>'
  '</wsdl:portType>'

  '<wsdl:binding name="O' idoctyp 'Binding" type="tns:O' idoctyp '">'
    '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />'
    '<wsdl:operation name="O' idoctyp '">'
      '<soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />'
      '<wsdl:input>'
        '<soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />'
      '</wsdl:input>'
      '<wsdl:output>'
        '<soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />'
      '</wsdl:output>'
    '</wsdl:operation>'
  '</wsdl:binding> </wsdl:definitions>' INTO lv_res.

  CONCATENATE cwsdl lv_res INTO cwsdl.
ENDMETHOD.

 

Create FM and use the code

FUNCTION zca_ob_idoc.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT) TYPE  ANY
*"  EXPORTING
*"     REFERENCE(OUTPUT) TYPE  ANY
*"----------------------------------------------------------------------

  FIELD-SYMBOLS: <input>   TYPE any,
                 <idoc>    TYPE any,
                 <edidc>   TYPE any,
                 <idocnum> TYPE any,
                 <docnum>  TYPE any,
                 <json>    TYPE any,
                 <jsonstr>    TYPE any,
                 <output>  TYPE any.
  DATA: lcl_idoc           TYPE REF TO zcl_ca_idoc_service.
  CREATE OBJECT lcl_idoc.

  DATA: in  TYPE REF TO data,
        out TYPE REF TO data.

  lcl_idoc->get_ddic_object(
   EXPORTING
    input   = input
   IMPORTING
    tdd03   = DATA(dd03_in)
    refname = DATA(ddname_in) ).

  CREATE DATA in TYPE (ddname_in).
  ASSIGN in->* TO <input>.
  MOVE-CORRESPONDING input TO <input>.
  ASSIGN COMPONENT 'IDOC_NUMBER' OF STRUCTURE <input> TO <idocnum>.
  ASSIGN COMPONENT 'DOCUMENT_NUMBER' OF STRUCTURE <input> TO <docnum>.
  ASSIGN COMPONENT 'JSON' OF STRUCTURE <input> TO <json>.

  lcl_idoc->get_ddic_object(
   EXPORTING
    input   = output
   IMPORTING
    tdd03   = DATA(lt_dd03)
    refname = DATA(tabname) ).

  ASSIGN COMPONENT 'IDOC' OF STRUCTURE output TO <idoc>.

  DATA: idocnum TYPE num16.
  idocnum = <idocnum>.
  IF idocnum IS INITIAL.
    idocnum = zcl_ca_idoc_service_ob=>get_idoc_from_doc( <docnum> ).
  ENDIF.
  IF idocnum IS INITIAL.
    EXIT.
  ENDIF.
  zcl_ca_idoc_service_ob=>get_idoc_data(
    EXPORTING
      idocnum = idocnum
    IMPORTING
      edidc   = DATA(idoc_control)
      edidd   = DATA(lt_edidd) ).

  ASSIGN COMPONENT 'EDI_DC40' OF STRUCTURE <idoc> TO <edidc>.
  MOVE-CORRESPONDING idoc_control TO <edidc>.

  PERFORM prepare_idoc USING lt_edidd lt_dd03 '000000' <idoc>.

  IF <json> IS NOT INITIAL.
    ASSIGN COMPONENT 'JSON' OF STRUCTURE output TO <jsonstr>.
    <jsonstr> = /ui2/cl_json=>serialize( data = <idoc> compress = abap_true ).
    CLEAR <idoc>.
  ENDIF.

ENDFUNCTION.

FORM prepare_idoc USING lt_edidd TYPE idoc_data
                        lt_dd03  TYPE dd_x031l_table
                        psgnum   TYPE edi_psgnum
                        idoc     TYPE any.

  FIELD-SYMBOLS: <fs_segment>     TYPE any,
                 <fs_segnam>      TYPE any,
                 <fs_table>       TYPE any,
                 <fs_segment_tab> TYPE STANDARD TABLE.

  DATA:          lv_segnam TYPE REF TO data,
                 ls_table  TYPE REF TO data.
  DATA: lcl_idoc          TYPE REF TO zcl_ca_idoc_service.
  CREATE OBJECT lcl_idoc.


  LOOP AT lt_edidd ASSIGNING FIELD-SYMBOL(<fs_dd>) WHERE psgnum = psgnum.
    READ TABLE lt_dd03 ASSIGNING FIELD-SYMBOL(<fs_dd03>) WITH KEY fieldname = <fs_dd>-segnam.
    IF sy-subrc = 0 AND <fs_dd03>-dtyp = 'STR2'.

      ASSIGN COMPONENT <fs_dd>-segnam OF STRUCTURE idoc TO <fs_segment>.
      lcl_idoc->get_ddic_object(
       EXPORTING
        input   = <fs_segment>
       IMPORTING
        tdd03   = DATA(lt_dd03_1)
        refname = DATA(tabname_1) ).

      CREATE DATA lv_segnam TYPE (<fs_dd>-segnam).
      ASSIGN lv_segnam->* TO <fs_segnam>.
      <fs_segnam> = <fs_dd>-sdata.

      MOVE-CORRESPONDING <fs_segnam> TO <fs_segment>.

      IF lt_dd03_1 IS NOT INITIAL.
        PERFORM prepare_idoc USING lt_edidd lt_dd03_1 <fs_dd>-segnum <fs_segment>.
      ENDIF.

    ELSEIF sy-subrc = 0 AND <fs_dd03>-dtyp = 'TTAB'.

      ASSIGN COMPONENT <fs_dd>-segnam OF STRUCTURE idoc TO <fs_segment_tab>.
      lcl_idoc->get_ddic_object(
       EXPORTING
        input   = <fs_segment_tab>
       IMPORTING
        tdd03   = lt_dd03_1
        refname = tabname_1 ).

      CREATE DATA lv_segnam TYPE (<fs_dd>-segnam).
      ASSIGN lv_segnam->* TO <fs_segnam>.
      <fs_segnam> = <fs_dd>-sdata.

      CREATE DATA ls_table TYPE (tabname_1).
      ASSIGN ls_table->* TO <fs_table>.
      MOVE-CORRESPONDING <fs_segnam> TO <fs_table>.

      IF lt_dd03_1 IS NOT INITIAL.
        PERFORM prepare_idoc USING lt_edidd lt_dd03_1 <fs_dd>-segnum <fs_table>.
      ENDIF.

      APPEND <fs_table> TO <fs_segment_tab>.

    ENDIF.

  ENDLOOP.
ENDFORM.

Create a class ZCL_CA_IDOC_SERVICE_OB with below methods

 

  METHOD get_idoc_data.

    CALL FUNCTION 'IDOC_READ_COMPLETELY'
      EXPORTING
        document_number         = idocnum
      IMPORTING
        idoc_control            = edidc
      TABLES
        int_edidd               = edidd
      EXCEPTIONS
        document_not_exist      = 1
        document_number_invalid = 2
        OTHERS                  = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
  ENDMETHOD.
  METHOD get_idoc_from_doc.

    DATA: ls_object   TYPE borident,
          ls_objkey   TYPE swo_typeid,
          lv_objtype  TYPE swo_objtyp,
          lv_roletype TYPE roletype,
          lt_nr       TYPE TABLE OF neighbor.

    ls_objkey = doc.

***Based on assumption that objkeys are based SD documents with different number range
***Need to change the logic if required
    SELECT SINGLE objtype roletype FROM srrelroles INTO (lv_objtype, lv_roletype)
                              WHERE objkey = ls_objkey.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.

    ls_object-objkey  = doc.
    ls_object-objtype = lv_objtype.

    CALL FUNCTION 'SREL_GET_NEXT_NEIGHBORS'
      EXPORTING
        object         = ls_object
        roletype       = lv_roletype
      TABLES
        neighbors      = lt_nr
      EXCEPTIONS
        internal_error = 1
        no_logsys      = 2
        OTHERS         = 3.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

    DELETE lt_nr WHERE roletype NE 'OUTIDOC'.

    SORT lt_nr BY objkey DESCENDING.

    READ TABLE lt_nr ASSIGNING FIELD-SYMBOL(<fs_nr>) INDEX 1.
    IF <fs_nr> IS ASSIGNED.
      idoc = <fs_nr>-objkey.
    ENDIF.

  ENDMETHOD.
  METHOD zca_iiw_outbound_invoic02_idoc~oinvoic02.
*** **** INSERT IMPLEMENTATION HERE **** ***

    CALL FUNCTION 'ZCA_OB_IDOC'
      EXPORTING
        input  = input
      IMPORTING
        output = output.

  ENDMETHOD.

 

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply