on 08-28-2009 8:07 PM
Hi all,
could anybody tell me how it is possible to export an idoc from a sap system as xsd.
I know that transaction WE60 -> Export XSD does exactly the same, so could anybody tell me, how to perform this task with abap coding ?
Thanks in advance!
BR
BR,
Check out below code ( From SAP Include : MSEDIDOCUF01 ), if you set a break-point while generating XSD thru WE60 will give you better idea of what parameters value you need to pass to below functions )
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.
FIELD-SYMBOLS:
TYPE REF TO if_ixml_element.
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
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.
Display the XML schema.
CALL FUNCTION 'SDIXML_DOM_TO_SCREEN'
EXPORTING
DOCUMENT = document
EXCEPTIONS
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.
Hope this will help.
Thanks,
Nilesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.