Skip to Content

I find irresistible to demonstrate the exercise using XI “WebService” since the utility is useful to any XI developers across the globe. But unfortunately I don’t have access for installing the SAP developer Netweaver studio that implies I cannot demonstrate the exercise using a “WebService”. After all XI developers who are familiar SAP NW studio can use this piece and implement it as webservice.

“Why the heck I need to create all the 50 fields of BSEG Table in the XI editor? Is there any one around who is smarter enough to solve the problem with a different solution?” –SDN forum.


This is very common scenario when either the outbound or inbound interface is BAPI/RFC.

Ex: File – RFC scenario.

I need to create a file structure that is in line with the RFC structure. This is very common when we deal with any SAP systems on one end.
Yes. There are ways out. With WAS > 6.0 we can convert any ABAP structures to XSD format.

Existing Solutions:

1.Blog from Michal:[ XI: Importing an R/3 structure or table into Repository not possible? | The specified item was not found.]

Gaps:

1.Michal showed really a nice way but we need to manually export table structure and moreover we should have Microsoft SQL Server experience to work with it.
2.XI developer would not even have had a chance to look at sanjay’s article as it is posted as an article and a minor draw back is that we need to execute the report and the output is displayed on a XML editor, which has to be then downloaded manually.
I was successful in finding out the function group SDIXML during my R & D process. ‘R & D’ turned to be “Re-Search” option the moment I found out the article whilst googling the documentation for SDIXML FM :).Otherwise I would not have even known that the article is existent. Not many XI developers are friendly with reports and ABAP XML editors.

Proposed Solutions (by Me):

The article is upgraded as an RFC (It is a report originally) and some new API’s are used for exporting the R/3 structures as XSD-String Format instead of transferring the raw data into a ABAP XML Editor.

Code Sample: RFC Z_CONVERT_ABAPTABLE_TO_XSD takes the table name I_ABAP_TABLE_NAME and target name space I_XI_NAMESPACE and exports XSD E_XSD in string format.Create the RFC and try it any SAP system with WAS > 6.0 and bounce back in the XI forum for any errors.

FUNCTION Z_CONVERT_ABAPTABLE_TO_XSD.

*”—-


“Local Interface:

*”  IMPORTING

*”     VALUE(I_ABAP_TABLE_NAME) TYPE  DCXMLTYPNM-TABNAME

*”     VALUE(I_XI_NAMESPACE) TYPE  DCXMLSCHCL-TARGETNS

*”  EXPORTING

*”     VALUE(E_XSD) TYPE  STRING

*”—-


************DATA DECLARATION***********************

  DATA ls_control TYPE dcxmlddscl.

  DATA ls_elements TYPE dcxmlelems.

  DATA: document TYPE REF TO if_ixml_document.

  DATA ls_types TYPE dcxmltypns.

  DATA ls_dcxmltypnm TYPE dcxmltypnm.

  DATA xsd TYPE xstring.

  DATA xml_schema TYPE REF TO if_ixml_element.

  DATA lv_rc TYPE sy-subrc.

  DATA ls_schema_control TYPE    dcxmlschcl.

  FIELD-SYMBOLS  TYPE REF TO if_ixml_element.

*********************************************************

***********Feed the Header information for forming XSD****

  ls_control-langu = sy-langu.

  ls_control-atom_text = ls_control-stru_text

                       = ls_control-ttyp_text

                       = ls_control-num1extr = ‘X’.

  .

  ls_control-xsdnsp = ‘xsd’.

  ls_control-targetns = i_xi_namespace.

*************ABAP Table Name that has to be converted*****

  ls_dcxmltypnm-tabname = i_abap_table_name.

************************************************************

  APPEND ls_dcxmltypnm TO ls_types.

  MOVE-CORRESPONDING ls_control TO ls_schema_control.

********************Create Schema Object*********************

  CALL FUNCTION ‘SDIXML_SCHEMA_CREATE’

    EXPORTING

      control        = ls_schema_control

    IMPORTING

      schema         = xml_schema

    CHANGING

      document       = document

    EXCEPTIONS

      internal_error = 1

      OTHERS         = 2.

***************Convert ABAP Table to schema elements************

  CALL FUNCTION ‘SDIXML_DDIC_TO_SCHEMA’

    EXPORTING

      control        = ls_control

    IMPORTING

      elements       = ls_elements

    CHANGING

      types          = ls_types

      document       = document

    EXCEPTIONS

      internal_error = 1

      OTHERS         = 2.

****************Add XML schema instance*************************

  CALL METHOD document->append_child

    EXPORTING

      new_child = xml_schema

    RECEIVING

      rval      = lv_rc.

  CHECK lv_rc = 0.

**************ADD xsd types to XML schema************************

  LOOP AT ls_elements ASSIGNING

        RECEIVING

          rval      = lv_rc.

      IF lv_rc NE 0. EXIT. ENDIF.

    ENDIF.

  ENDLOOP.

*************Convert XSD document to XSTRING*****************

  CALL FUNCTION ‘SDIXML_DOM_TO_XML’

    EXPORTING

      document      = document

      pretty_print  = ‘X’

    IMPORTING

      xml_as_string = xsd.

***********Convert XSTRING TO STRING****************************

  CALL FUNCTION ‘ECATT_CONV_XSTRING_TO_STRING’

    EXPORTING

      im_xstring  = xsd

      im_encoding = ‘UTF-8’

    IMPORTING

      ex_string   = e_xsd.

ENDFUNCTION.

2 cents to anyone who will develops it as a Web Service-RFC scenario with a clearly defined interface and publish it in the UDDI registry.I wish to do that but unfortunately couldn’t.

To report this post you need to login first.

7 Comments

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

  1. Anonymous
    Sravya,

    I too started on writing my self a report to convert a table into standart xsd, but just could never complete it. instead i found a quick way to do the say.

    I imported the rfc into Xi, exported the wsdl and mainpulated the wsdl into separate xsd’s using MS Visal Studio 2003.

    But having ur report is handy.

    Thanks for all the effort.

    Naveen

    (0) 
    1. Sravya Talanki Post author
      Thanks Naveen..

      While working on  ABAP proxies I found out the XSD are translated into ABAP DD and while doing the reverse engineering I found out the FM..:)
      I found out there is already one who has done the re-engineering to an extent..:)

      (0) 
  2. Anonymous
    Hi,

    Even though I couldn’t test it properly b’cuz FM ‘ECATT_CONV_XSTRING_TO_STRING’ is not avaiable in my system but I appreciate your thought on RFC for the same. But I don’t know whether you have solved the problem which was there with my last code? In case of complex structure the derived XSD can’t be used directly for importing b’cuz our definition contains parent -> child whereas it needs to be imported child -> parent .

    Anyway it’s nice effort.

    Regards,
    Sanjay

    (0) 
  3. Milosz Klosowicz
    Your code doesn’t work on my WAS 6.20 because of
    FM ‘ECATT_CONV_XSTRING_TO_STRING’ is missign.
    But there is another similar FM ‘HR_KR_XSTRING_TO_STRING’.
    Using it , your code works fine.

    Milosz

    (0) 
    1. Durairaj Athavan Raja
      if you dont find this FM in your system you can use the following code to convert xstring to string.

      data: conv type ref to cl_abap_conv_in_ce ,
            xcontent type xstring,
            content type string .

      conv = cl_abap_conv_in_ce=>create( input = xcontent ).
      conv->read( importing data = content ).

      Regards
      Raja

      (0) 
  4. Hayo Verdijk

    Hi,

    there seems to be some lines of code missing in the program/RFC above.

    I could really use your program in my project ( i am not a PI consultant),

    but i cannot get it to work.

    Problems:

    1. the field symbol name is missing

    2 . in the loop section, essential calls to methods are missing:

      LOOP AT ls_elements ASSIGNING

            RECEIVING

              rval      = lv_rc.

          IF lv_rc NE 0. EXIT. ENDIF.

        ENDIF.

      ENDLOOP.

    could you please provide me a correct version.

    thank you so much !

    (0) 

Leave a Reply