How to create DTD from XML using DOM

Hi,
Is there a way to create a corrosponding DTD of a xml-file using DOM. I have a XML-file that's pretty huge I want to create a DTD for that XML-file using DOM. Can anyone plz. lead me how to do this. I tried to use XMLSpy to convert the XML into DTD but the resulting DTD is not correct. Is there a way to create the DTD using DOM.
Any help is really appreciated. Thanks

When you say you are trying to convert XML to DTD, do you mean you are trying to convert a XSD (schema) to a DTD, or that you are trying to create a schema that corresponds to a given XML document.
Realize that DTDs are not very powerful. XSD documents allow for much more detail. I don't have a proof, but I'm absolutely confident that any DTD can be expressed as a schema but not all schemas can be represented as a DTD. In other words, DTDs are not worth the trouble, in my opinion.

Similar Messages

  • How to read xml-stylesheet Processing Instruction from XML using DOM Parser

    Hi,
    I am trying to read an xml that contains xsl stylesheet PI using DOMParser. The parse() method reads the entire contents of the XML except the PI instruction. Below is the XML I am using to read
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet href="../../../lang/en-us/style0/usc_profile.xsl" type="text/xsl"?>
    <Oblix oblang="en-us" xmlns="http://www.oblix.com/" xmlns:oblix="http://www.oblix.com/">
    <ObProfile>
    </ObProfile>
    </Oblix>
    Can anyone let me know if there are any propery settings to be done for the DOM parser before parsing?. If so, what is the property to be set?.
    Thanks in Advance
    Muthu

    A COTS product builds the XML and inserts the respective xsl (xml:stylesheet) file name to be used for transforming the xml. I am trying to interrupt this xml and make some updations on an element and finally send the updated xml to the stream.
    For the above process, I parse the input XML using DOMParser and update the elements (some internal elements). While I view the final XML that would be passed to the stream, I found the <?xml-stylesheet... PI is missing.
    I somehow managed using a temp fix by doing the below. I manually pulled the PI using document.getFirstChild().getNodeValue() and reconstructed the PI and inserted it to the outgoing XML. This needs to be done every time. This might run into problems when more than one PI is used in the XML.
    If the parsed XML could get the PI along with it the above problem could be resolved.
    Is there any property that could be set on the parser (prior to parsing) to resolve the issue?.

  • How to retrieve information from XML using servlets

    Hi
    I have a scenario like this
    File-->XI-->J2ee application(HTTP Receiver adapter)
    I want to know how XI sends xml file as a query string file name?
    What ever may be the case i just need to retrieve the information from Request object and display the same in browser(JSP).How to do that, I am totally confused, please anyone help me!
    Code help is highly rewarded.
    Thanx

    Hi Rajesh!
    I have tried your code. But some where i went wrong. Please correct me: I am using NWDS2.0.9
    my web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                             "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <display-name>WEB APP</display-name>
        <description>WEB APP description</description>
        <servlet>
            <servlet-name>DisplayRes</servlet-name>
            <servlet-class>com.quinnox.DisplayRes</servlet-class>
        </servlet>
        <servlet-mapping>
              <servlet-name>DisplayRes</servlet-name>
              <url-pattern>/DisplayRes/*</url-pattern>
         </servlet-mapping>
    </web-app>
    my application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
                                 "http://java.sun.com/dtd/application_1_3.dtd">
    <application>
        <display-name>ReceiverEntpr</display-name>
        <description>EAR description</description>
        <module>
            <web>
                <web-uri>HttpReceiver.war</web-uri>
                <context-root>/HttpReceiver</context-root>
            </web>
        </module>
    </application>
    and my servlet code:
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.io.Writer;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.xml.sax.EntityResolver;
    import org.xml.sax.SAXException;
    import com.sun.java_cup.internal.parser;
    import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException
              doWork(requset, response);
         public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
              doWork(req, resp);
         private void doWork(HttpServletRequest req, HttpServletResponse resp) throws IOException
              String path = null;
              PrintWriter out = null;
              PrintWriter p2=resp.getWriter();     
              try
                   resp.setContentType("text/xml");
                   out = resp.getWriter();
                   out.println("hi");
                   path = req.getPathInfo();
                   if(req.getContentLength() != -1){
                   outputURI(req.getInputStream(), out);
              } catch (IOException ioe) {     return;     
         //private void outputURI(InputStream resultStream, Writer out) {
              private void outputURI(InputStream resultStream, PrintWriter out) {
              if (resultStream == null) {
    //             no default file
    //            logger.error("No File to return");
              return;
              try {
              DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    //            Class clazz = loader.loadClass("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
    //            DocumentBuilderFactoryImpl factory = (DocumentBuilderFactoryImpl) clazz.newInstance();
    //            DocumentBuilder parser = factory.newDocumentBuilder();
              parser.setEntityResolver(new ClassPathEntityResolver());
              printXML(parser.parse(resultStream), out);
              resultStream.close();
              } catch (Exception e) {
    //            logger.error("Trying to parse the output " , e);
         //private void printXML(Document document, Writer writer) throws Exception {
              private void printXML(Document document, PrintWriter writer) throws Exception {
              Transformer transformer = TransformerFactory.newInstance().newTransformer();
              Source source = new DOMSource(document);
              Result output = new StreamResult(System.out);
              transformer.transform(source, output);
    //             Write as XML so that entity references can be resolved.
              if (writer != null) {
              transformer.transform(source, new StreamResult(writer));
    Please tell me how to display in servlet.
    If it is better to display in a browser. Please send me the code.
    Thanks

  • Remove element from xml using dom.

    i want to remove an element from an xml file using dom.
    i remove the element but the whole content of the file is also deleted.
    how can i rewrite the file.

    vij_ay wrote:
    subject :Remove element from xml,but if empty element in input file then output should be <tag></tag>, not like <tag.xml/>I assume you mean <tag/> but why do you want this? Any application that will not accept this valid XML construct is flawed and a bug report should be raised against it.

  • How to derive DTD from XML CLOB?

    I have a CLOB containing an XML document which I would like to derive the DTD for, what API can I use to do this? sample code would be appreciated.
    FYI, the CLOB is populated from HTTP request against a remote system, therefore I don't have the SQL to execute locally - that would be too easy!
    Many Thanks

    Do you mean you like to generate DTD from the CLOB XML document? Currently, XDKs don't support this.

  • Create DTD from XML document

    Hello,
    I have a little problem creating a DTD from an XML document. The XML document looks the following:
    <data name="data1">
    <value id="abc" name="value1" />
    <value id="def" name="value2" />
    <value id="ghi" name="value3" />
    </data>
    <data name="data2">
    <value id="123" name="valueA" />
    <value id="456" name="valueB" />
    <value id="789" name="valueC" />
    </data>
    The problem concerns the attribute list of the value element,
    on the one hand I could create a DTD like this:
    <!ATTLIST value id CDATA #REQUIRED
    name CDATA #REQUIRED
    >
    On the other hand I could do it like this:
    <!ATTLIST value id (abc|def|ghi|123|456|789) #REQUIRED
    name (value1|value2|value3|valueA|valueB|valueC)
    #REQUIRED
    >
    Now I don't know what's the right way. I would be glad if anybody could give me support for my problem.
    Thank you very much,
    Findus

    No...this is not the solution for my problem. The first problem with the code you posted is that I can create a valid XML document like this:
    <data name="data2">
    <value id="123" name="value1" />
    <value id="456" name="value2" />
    <value id="789" name="value3" />
    </data>
    (Please compare to the lines below in order to recognize the difference)
    I want the user to create only documents like this:
    <data name="data2">
    <value id="123" name="valueA" />
    <value id="456" name="valueB" />
    <value id="789" name="valueC" />
    </data>
    So I want to define special attribute pairs in my DTD, like ' the value attribute id="123" works only with the attribute name="valueA"! '
    Is it possible to do so ?
    Thanx a lot,
    Findus

  • How to remove xmlns from xml using java

    Hi,
    <DLList xmlns="http://www.test.com/integration/feed" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Bagalkote</ForecastName>
    <Humidity>89.9</Humidity>
    </Weather>
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Devengiri</ForecastName>
    <Humidity>89.9</Humidity>
    </Weather>
    </DLList>
    The above xml needs to be decomposed using xsu.I am facing a small problem because the xml has namespaces.
    How to remove the namespace using java to get the below xml
    Note:I am using XSLT for the transformation.The XSLT tag is not identifying the <DLList> tag with name space
    <DLList>
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Bagalkote</ForecastName>
    <Humidity>89.9</Humidity>
    </Weather>
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Devengiri</ForecastName>
    <Humidity>89.9</Humidity>
    </Weather>
    </DLList>
    Please help.Let me know if any other information is required
    Thanks

    OK, here goes :
    For the example, I'll use a TB_DISTRICT table with the following structure :
    create table tb_district (
    sr_no number(3),
    district_name varchar2(100)
    );loaded with data from this page :
    http://india.gov.in/knowindia/districts/andhra1.php?stateid=KA
    and this XML document (one additional record compared to the one you posted) :
    <DLList xmlns="http://www.test.com/integration/feed" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Bagalkote</ForecastName>
    <Humidity>89.9</Humidity>
    </Weather>
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Devengiri</ForecastName>
    <Humidity>89.9</Humidity>
    </Weather>
    <Weather>
    <StateName>Karnataka</StateName>
    <ForecastName>Dharwad</ForecastName>
    <Humidity>70.1</Humidity>
    </Weather>
    </DLList>In order to access the XML, I'll also use this Oracle directory object :
    create directory test_dir as 'D:\ORACLE\test';Final relational tables are :
    create table BUSINESS_TABLE
      STATE         VARCHAR2(30),
      DISTRICT_NAME VARCHAR2(30),
      HUMIDITY      NUMBER
    );and
    create table REJECT_TABLE
      STATE         VARCHAR2(30),
      DISTRICT_NAME VARCHAR2(30),
      HUMIDITY      NUMBER,
      ERROR_MESSAGE VARCHAR2(500)
    );With XMLTable function, we can easily break the XML into relational rows and columns ready to use for DML :
    SQL> alter session set nls_numeric_characters=". ";
    Session altered
    SQL>
    SQL> SELECT *
      2  FROM XMLTable(
      3    XMLNamespaces(default 'http://www.test.com/integration/feed'),
      4    '/DLList/Weather'
      5    passing xmltype(bfilename('TEST_DIR','test.xml'), nls_charset_id('CHAR_CS'))
      6    columns
      7      state         varchar2(30) path 'StateName'
      8    , district_name varchar2(30) path 'ForecastName'
      9    , humidity      number       path 'Humidity'
    10  )
    11  ;
    STATE                          DISTRICT_NAME                    HUMIDITY
    Karnataka                      Bagalkote                            89.9
    Karnataka                      Devengiri                            89.9
    Karnataka                      Dharwad                              70.1
    Then with a multitable insert, we load both the business table and the reject table (if the district name does not exist in TB_DISTRICT) :
    SQL> INSERT FIRST
      2    WHEN master_district_name IS NOT NULL
      3      THEN INTO business_table (state, district_name, humidity)
      4                VALUES (state, district_name, humidity)
      5    ELSE INTO reject_table (state, district_name, humidity, error_message)
      6              VALUES (state, district_name, humidity, 'Invalid district name')
      7  WITH xml_data AS (
      8    SELECT *
      9    FROM XMLTable(
    10      XMLNamespaces(default 'http://www.test.com/integration/feed'),
    11      '/DLList/Weather'
    12      passing xmltype(bfilename('TEST_DIR','test.xml'), nls_charset_id('CHAR_CS'))
    13      columns
    14        state         varchar2(30) path 'StateName'
    15      , district_name varchar2(30) path 'ForecastName'
    16      , humidity      number       path 'Humidity'
    17    )
    18  )
    19  SELECT x.*
    20       , t.district_name as master_district_name
    21  FROM xml_data x
    22       LEFT OUTER JOIN tb_district t ON t.district_name = x.district_name
    23  ;
    3 rows inserted
    SQL> select * from business_table;
    STATE                          DISTRICT_NAME                    HUMIDITY
    Karnataka                      Dharwad                              70.1
    SQL> select * from reject_table;
    STATE                          DISTRICT_NAME                    HUMIDITY ERROR_MESSAGE
    Karnataka                      Bagalkote                            89.9 Invalid district name
    Karnataka                      Devengiri                            89.9 Invalid district name

  • How to create database from scratch using user input

    what I am trying to do is to create database via my java code (using hibernate and my sql) and based on user input.
    The details like the name of table.... or the number of columns in it are all supposed to be determined from user input (only the first time).
    On subsequent run the program should remember the previously created database and hence work with it.
    Can somebody help me through this?
    Suppose I did create it using firing queries from my program then the next problem is how my program would start up next time......?????

    Anuvrat wrote:
    what I am trying to do is to create database via my java code (using hibernate and my sql) and based on user input.
    The details like the name of table.... or the number of columns in it are all supposed to be determined from user input (only the first time).
    On subsequent run the program should remember the previously created database and hence work with it.
    Can somebody help me through this?Presumably because you want to (fun) rather than because you need to (job or project.)
    If the second then don't do it.
    >
    Suppose I did create it using firing queries from my program then the next problem is how my program would start up next time......?????You would start by learning about DDL which is the common name for the languages, which vary by database, used to create the entities that represent the structure of a database. Until you figure out the syntax of that you can't do anything in java.

  • OSMF: How to create resource from XML string

    Hello,
    I have a URL that sometimes returns a valid playmanifest.f4m and sometimes returns a string represantation of my media URL.
    On my loadComplete handler I would like to create the appropriate resource according to the returned data.
    If the data is a URL, I just create a StreamingURLResource and create the media element.
    Is there a way for me to create some resource that contains the XML? I noticed OSMF has StreamingXMLResource but its excluded, and it doesn't look like it can answer my use case.
    Do you have any suggestions?
    Thanks,
    Michal

    Hi Michal,
    The baseURL is needed since you might want to use relative urls like in a normal f4m. The parsing had to be kept simple, so we preferred to make the baseURL mandatory and to reuse the f4m parsing code.
    You should be able to provide (in the xml string) paths for the streams, bootstraps, etc relative to that base url.
    You will not be able to use multi-layer manifest through this technique, though.

  • How to Create PDF from Illustrator CS3 by using applescript?

    Hi Guys,
    Do some one knows how to create PDF from Illustrator CS3 by using apple script. If know, please give me the scripting.
    HARI

    Have you tried File>Scripts>SaveDocsAsPDF? There should be a folder of sample scripts installed in your AICS3 folder and a folder of documentation which contains an Illustrator AppleScript Reference which has examples.

  • How to remove Unicode from XML file

    I get following error when unmarshal xml:
    [java] org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x15) was found in the element content of the document.
    Anyone know how to remove Unicode from xml file? Can I remove the unicode by rebuild the file?
    Thanks

    These sort of error usually occur when you're using a different character encoding to read the file than the one you wrote it with. Perhaps if you were to post the problem section of the file and/or the code that created it in the first place.

  • Convertion of flat file to XML using DOM

    Hi!
    I need help for convert a flat file to XML using DOM and by taking the validation of a specified DTD. Can any body help me in this regard.
    Bye,
    lat

    first you have to decide how the flat file will map to xml. Will you use attributes or pcdata for your fields, or both? Will there be a hierarchy, or will it be mostly flat?
    Once decided, you'd probably just use a BufferedReader to read the lines one at a time, and generate Dom nodes as appropriate, and stick them in the tree.

  • How to retrieve value from xml file

    hi all,
    can somebody pls tell me how to retrieve value from xml file using SAXParser.
    I want to retrieve value of only one tag and have to perform some validation with that value.
    it's urgent .
    pls help me out
    thnx in adv.
    ritu

    hi shanu,
    the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
    pls have a look at the following code snippet.
    public class XMLValidator {
    static ArrayList strXXX = new ArrayList();
    public void validate(){
    factory.setValidating(true);
    parser = factory.newSAXParser();
    //all factory code is here only
    parser.parse(xmlURI, new XMLErrorHandler());     
    public void setXXX(String pstrXXX){          
    strUpn.add(pstrXXX);
    public ArrayList getXXX(){
    return strXXX;
    class XMLErrorHandler extends DefaultHandler {
    String tagName = "";
    String tagValue = "";
    String applicationRefNo = "";
    String XXXValue ="";
    String XXXNo = "";          
    XMLValidator objXmlValidator = new XMLValidator();
    public void startElement(String uri, String name, String qName, Attributes atts) {
    tagName = qName;
    public void characters(char ch[], int start, int length) {
    if ("Reference".equals(tagName)) {
    tagValue = new String(ch, start, length).trim();
    if (tagValue.length() > 0) {
    RefNo = new String(ch, start, length);
    if ("XXX".equals(tagName)) {
    XXXValue = new String(ch, start, length).trim();
    if (XXXValue.length() > 0) {
    XXXNo = new String(ch, start, length);
    public void endElement(String uri, String localName, String qName) throws SAXException {                    
    if(qName.equalsIgnoreCase("XXX")) {     
    objXmlValidator.setXXX(XXXNo);
    thnx & Regards,
    ritu

  • How to create a crystal Report using C# and SQL Server

    Hi, im new in creating crystal report using SQL Server, and im making a project.. and could someone help me how to connect your .sdf (SQL Server File) from the bin to your crystal report? thanks a lot.. i followed some instructions like this one (https://social.msdn.microsoft.com/Forums/vstudio/en-US/48c0dd48-5b23-49da-8601-878f8406125e/how-to-create-a-crystal-report-using-sql-server-visual-c?referrer=http://social.msdn.microsoft.com/Forums/vstudio/en-US/48c0dd48-5b23-49da-8601-878f8406125e/how-to-create-a-crystal-report-using-sql-server-visual-c?referrer=http://social.msdn.microsoft.com/Forums/vstudio/en-US/48c0dd48-5b23-49da-8601-878f8406125e/how-to-create-a-crystal-report-using-sql-server-visual-c?referrer=http://social.msdn.microsoft.com/Forums/vstudio/en-US/48c0dd48-5b23-49da-8601-878f8406125e/how-to-create-a-crystal-report-using-sql-server-visual-c?forum=csharpgeneral)
    but i got an error on the adding of server name and database portion.. thanks a lot in advance

    Hello,
    Crystal Reports are supported on
    http://scn.sap.com/community/crystal-reports.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • How to create the sales order using BAPI's ....?

    Hi Guru's,
    could you please provide how to create the sales order using BAPI's .....i need step by step process and please provide the details from scratch....basically  i don't have basic knowledge on this....please provide required inputs ....:)
    thanks in advance
    Srinivas......

    Hi Guru's thanks for your inouts and your valuble time...
    please find the program logic below...
    *& Report  ZAREPAS30
    REPORT  zarepas30.
    DATA : gs_vbeln                   TYPE  vbak-vbeln,
           gs_order_header_in         TYPE  bapisdhd1,
           gs_order_header_inx        TYPE  bapisdhd1x,
           gt_order_items_in          TYPE  STANDARD TABLE OF bapisditm,
           gwa_itab1                  TYPE  bapisditm,
           gt_order_items_inx         TYPE  STANDARD TABLE OF bapisditmx,
           gwa_itab2                  TYPE  bapisditmx,
           gt_order_partners          TYPE  STANDARD TABLE OF bapiparnr,
           gwa_itab3                  TYPE  bapiparnr,
           gt_return                  TYPE  STANDARD TABLE OF bapiret2,
           gwa_itab4                  TYPE  bapiret2.
    Sales document type
      PARAMETERS: p_auart TYPE auart OBLIGATORY.
    Sales organization
      PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
    Distribution channel
      PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
    Division.
      PARAMETERS: p_spart TYPE spart OBLIGATORY.
    Requested Delivery Date
      PARAMETERS: p_edatu  TYPE edatu OBLIGATORY.
    Sold-to
      PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
    Ship-to
      PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
    Material
      PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
    Quantity.
      PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
    Plant
      PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
    Start-of-selection.
      START-OF-SELECTION.
    Header data
    Sales document type
      gs_order_header_in-doc_type = p_auart.
      gs_order_header_inx-doc_type = 'X'.
    Sales organization
      gs_order_header_in-sales_org = p_vkorg.
      gs_order_header_inx-sales_org = 'X'.
    Distribution channel
      gs_order_header_in-distr_chan  = p_vtweg.
      gs_order_header_inx-distr_chan = 'X'.
    Division
      gs_order_header_in-division = p_spart.
      gs_order_header_inx-division = 'X'.
    Reguested Delivery Date
      gs_order_header_in-req_date_h = p_edatu.
      gs_order_header_inx-req_date_h = 'X'.
      gs_order_header_inx-updateflag = 'I'.
    Partner data
    Sold to
      gwa_itab3-partn_role = 'AG'.
      gwa_itab3-partn_numb = p_sold.
      APPEND gwa_itab3 TO  gt_order_partners .
    ship to
      gwa_itab3-partn_role = 'WE'.
      gwa_itab3-partn_numb = p_ship.
      APPEND gwa_itab3 TO  gt_order_partners .
    ITEM DATA
      gwa_itab2-updateflag = 'I'.
    Line item number.
      gwa_itab1-itm_number = '000010'.
      gwa_itab2-itm_number = 'X'.
    Material
      gwa_itab1-material = p_matnr.
      gwa_itab2-material = 'X'.
    Plant
      gwa_itab1-plant    = p_plant.
      gwa_itab2-plant   = 'X'.
    Quantity
      gwa_itab1-target_qty = p_menge.
      gwa_itab2-target_qty = 'X'.
      APPEND gwa_itab1 TO gt_order_items_in.
      APPEND gwa_itab2 TO gt_order_items_inx.
    Line item number.
      gwa_itab1-itm_number = '000020'.
      gwa_itab2-itm_number = 'X'.
    Material
      gwa_itab1-material = p_matnr.
      gwa_itab2-material = 'X'.
    Plant
      gwa_itab1-plant    = p_plant.
      gwa_itab2-plant   = 'X'.
    Quantity
      gwa_itab1-target_qty = p_menge.
      gwa_itab2-target_qty = 'X'.
      APPEND gwa_itab1 TO gt_order_items_in.
      APPEND gwa_itab2 TO gt_order_items_inx.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
      EXPORTING
        order_header_in               = gs_order_header_in
        ORDER_HEADER_INX              = gs_order_header_inx
      IMPORTING
        SALESDOCUMENT                 = gs_vbeln
      tables
        RETURN                        = gt_return
        ORDER_ITEMS_IN                = gt_order_items_in
        ORDER_ITEMS_INX               = gt_order_items_inx
        order_partners                = gt_order_partners.
    Check the return table.
      LOOP AT gt_return into gwa_itab4 WHERE type = 'E' OR type = 'A'.
        EXIT.
      ENDLOOP.
      IF sy-subrc = 0.
        WRITE: / 'Error occured while creating sales order '.
      ELSE.
    Commit the work.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
        WRITE: / 'Document ', gs_vbeln, ' created'.
      ENDIF.

Maybe you are looking for