Extracting xmltype from table into xml output:  redundant nodes

Hi guys - see the below example.  (edit:   sorry, haven't used these forums for a while and can't seem to figure out how to format code.....)
[code]SQL> select *
  2    from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
[/code]
[/code]
SQL> create table mytesttable (item_id number, x_data xmltype);
Table created.
SQL>
SQL> insert into mytesttable
  2  with dat as (select 'blah' item from dual
  3               union all
  4               select 'more blah' from dual)
  5  ,t as (select xmlelement("x_data"
  6                              ,xmlattributes(1 as "dummyattr")
  7                              ,xmlagg(xmlelement("item"
  8                                                ,item))
  9                              ) x_data
10              from dat
11              )
12  select 1,x_data
13    from t    ;
1 row created.
SQL>
SQL> select *
  2    from mytesttable;
   ITEM_ID
X_DATA
         1
<x_data dummyattr="1">
  <item>blah</item>
  <item>more blah</item>
</x_data>
1 row selected.
SQL>
SQL> select xmlelement("outerelement"
  2                   ,xmlelement("itemID", item_id)
  3                   ,xmlelement("x_data",x_data)
  4                   )
  5     from mytesttable;
XMLELEMENT("OUTERELEMENT",XMLELEMENT("ITEMID",ITEM_ID),XMLELEMENT("X_DATA",X_DATA))
<outerelement><itemID>1</itemID><x_data><x_data dummyattr="1">
<item>blah</item>
<item>more blah</item>
</x_data>
</x_data></outerelement>
1 row selected.
[/code]
As the above, I have an xmltype in a table which has other non-xmltype columns.   I have a requirement to extract them out into a single xml document in a similar way to the last SQL there.
the problem is if I do it as per the above, I artificially add a redundant node.  the first <x_data> node is not necessary, but how do I go and add the xmltype column to the result without having to qualify it with another element around it?
i.e. how do I get the following:
<outerelement><itemID>1</itemID><x_data dummyattr="1">
<item>blah</item>
<item>more blah</item>
</x_data></outerelement>

nevermind.. I was having a dumb moment:
select xmlelement("outerelement"
                 ,xmlelement("itemID", item_id)
                 ,x_data
   from mytesttable;

Similar Messages

  • Error while downloading data from internal table into XML file

    hi all,
    i developed a program to download data from into internal table to xml file like this.
    tables: mara.
    parameters: p_matnr like mara-matnr.
    data: begin of itab_mara occurs 0,
                matnr like mara-matnr,
                ernam like mara-ernam,
                aenam like mara-aenam,
                vpsta like mara-vpsta,
          end of itab_mara.
    data: lv_field_seperator type c,     " value 'X',
          lv_xml_doc_name(30) type c,    " string value ‘my xml file’,
          lv_result type i.
          lv_field_seperator = 'x'.
          lv_xml_doc_name = 'my xml file'.
    types: begin of truxs_xml_line,
              data(256) type x,
          end of truxs_xml_line.
    types:truxs_xml_table type table of truxs_xml_line.
    data:lv_tab_converted_data type truxs_xml_line,
         lt_tab_converted_data type truxs_xml_table.
    data: lv_xml_file type rlgrap-filename value 'c:\simp.xml'.
    select matnr ernam aenam vpsta from mara into table itab_mara up to 5
           rows where matnr = p_matnr.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
       I_FIELD_SEPERATOR          = lv_field_seperator
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       I_XML_DOC_NAME             = lv_xml_doc_name
    IMPORTING
       PE_BIN_FILESIZE            = lv_result
      TABLES
        I_TAB_SAP_DATA             = itab_mara
    CHANGING
       I_TAB_CONVERTED_DATA       = lt_tab_converted_data
    EXCEPTIONS
      CONVERSION_FAILED          = 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.
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
    transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file.
    this program is syntactically correct and getting executed, but when i open the target xml file it is showing the following error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'file:///C:/simp.xml'.
    will anyone show me the possible solution to rectify this error
    thanks and regards,
    anil.

    Hi,
    Here is a small sample program to convert data in an internal table into XML format and display it.
    DATA: itab  TYPE TABLE OF spfli,
          l_xml TYPE REF TO cl_xml_document.
    * Read data into a ITAB
    SELECT * FROM spfli INTO TABLE itab.
    * Create the XML Object
    CREATE OBJECT l_xml.
    * Convert data in ITAB to XML
    CALL METHOD l_xml->create_with_data( name = 'Test1'
                                         dataobject = t_goal[] ).
    * Display XML Document
    CALL METHOD l_xml->display.
    Here are some other sample SAP programs to handle XML in ABAP:
    BCCIIXMLT1, BCCIIXMLT2, and BCCIIXMLT3.
    Hope this helps,
    Sumant.

  • After generating a table into xml how can i save the result in a XML table?

    Hello everyone,
    I’ve used this function to generate a table into XML schema :
    example :
    SELECT xmlelement("State", xmlattributes( 'http://www.opengis.net/gml' as "xmlns:gml"),
    xmlforest(name as "Name", population as "Population")) from state;
    result:
    <Statexmlns:gml="http://www.opengis.net/gml">
    <Name>Wilkopolska</Name>
    <Population>35000</Population>
    </State>
    Now I need to insert the result into a XML table, because i need to save the result to use it latter ,I hope that someone can help and if there's other solution to do this it would be great.
    Thanks a ot and best regards,
    Lama.

    Just insert into a table....
    insert into t
    SELECT xmlelement("State", xmlattributes( 'http://www.opengis.net/gml' as "xmlns:gml"),
    xmlforest(name as "Name", population as "Population")) from state; and a complete example:
    SQL> create table t (test xmltype)
      2  /
    Table created.
    SQL>
    SQL> create table state
      2  (name varchar2(10)
      3  ,population number
      4  )
      5  /
    Table created.
    SQL>
    SQL> insert into state values ('WI', 35000)
      2  /
    1 row created.
    SQL>
    SQL> SELECT xmlelement("State", xmlattributes( 'http://www.opengis.net/gml' as "xmlns:gml"),
      2  xmlforest(name as "Name", population as "Population")) from state;
    XMLELEMENT("STATE",XMLATTRIBUTES('HTTP://WWW.OPENGIS.NET/GML'AS"XMLNS:GML"),XMLFOREST(NAMEAS"NAME",P
    <State xmlns:gml="http://www.opengis.net/gml"><Name>WI</Name><Population>35000</
    SQL>
    SQL>
    SQL> insert into t
      2  SELECT xmlelement("State", xmlattributes( 'http://www.opengis.net/gml' as "xmlns:gml"),
      3  xmlforest(name as "Name", population as "Population")) from state;
    1 row created.
    SQL> select *
      2    from t
      3  /
    TEST
    <State xmlns:gml="http://www.opengis.net/gml"><Name>WI</Name><Population>35000</

  • Time Out Dump while extracting data from table CKIS

    Dear Friends,
    I am getting TIme Out dump for the below code, while extracting data from table CKIS.
    Table CKIS doesn't have any Indexes. Please guide me to resolve this.
    Regards,
    Viji.
    form get_keko_ckis.
      SELECT kalnr kalka kadky tvers bwvar matnr werks kokrs
             FROM keko
             INTO TABLE i_keko1
             FOR ALL ENTRIES IN i_final_modify
                 WHERE matnr = i_final_modify-main_f
                   AND werks = p_werks
                   AND kokrs = p_kokrs
                   AND kadat = p_kadat
                   AND bidat = p_bidat
                   AND bwdat = p_bwdat.
      IF sy-subrc = 0.
        SORT i_keko1 BY kalnr kalka kadky tvers bwvar.
        SELECT kalnr kalka kadky tvers bwvar posnr typps kstar
               matnr menge gpreis
               FROM ckis
               INTO TABLE i_ckis_temp
               FOR ALL ENTRIES IN i_keko1
               WHERE kalnr = i_keko1-kalnr
                 AND kalka = i_keko1-kalka
                 AND kadky = i_keko1-kadky
                 AND tvers = i_keko1-tvers
                 AND bwvar = i_keko1-bwvar.
            IF sy-subrc = 0.
              SORT i_ckis_temp BY kalnr kalka kadky tvers bwvar.
              LOOP AT i_ckis_temp INTO wa_ckis_temp.
                wa_ckis-kalnr  = wa_ckis_temp-kalnr.
                wa_ckis-kadky  = wa_ckis_temp-kadky.
                wa_ckis-posnr  = wa_ckis_temp-posnr.
                wa_ckis-typps  = wa_ckis_temp-typps.
                wa_ckis-kstar  = wa_ckis_temp-kstar.
                wa_ckis-matnr1 = wa_ckis_temp-matnr1.
                wa_ckis-menge  = wa_ckis_temp-menge.
                wa_ckis-gpreis = wa_ckis_temp-gpreis.
              CLEAR wa_keko1.
              READ TABLE i_keko1 INTO wa_keko1
                                 WITH KEY kalnr = wa_ckis_temp-kalnr
                                          kalka = wa_ckis_temp-kalka
                                          kadky = wa_ckis_temp-kadky
                                          tvers = wa_ckis_temp-tvers
                                          bwvar = wa_ckis_temp-bwvar
                                          BINARY SEARCH.
                 IF sy-subrc = 0.
                    wa_ckis-matnr = wa_keko1-matnr.
                    wa_ckis-werks = wa_keko1-werks.
                 ENDIF.
                 APPEND wa_ckis TO i_ckis.
                 CLEAR: wa_ckis_temp, wa_ckis.
              ENDLOOP.
            ENDIF.
        REFRESH: i_keko1, i_ckis_temp.
      ENDIF.
    endform.                    " get_keko_ckis

    Hi Try minimising the conditions in where clause
         SELECT fields..... FROM CKIS
         WHERE KALNR = KEKO-KALNR AND
                      KADKY = KEKO-KADKY AND
                      TVERS = KEKO-TVERS AND
                      TYPPS = 'M'.
        after this, deleting unwanted records from internal table as per pending conditions...
    Regds,
    Anil

  • Can we change table into XML through OWB

    Hi everyone,
    Is it possible to change table into XML through OWB?
    Can anybody help me.
    just send me the steps to do
    Thanks in advance
    Rachit

    Hello, Rachit
    As far as I understand our question – you need to export data from the table into XML file.
    I don’t think you have direct operator within OWB (at least for ver. 9.2.0.4). But anyway, you could write PLSQL procedure using DBMS_XMLQUERY to perform XML generation and transform it with your stylesheet.
    Unfortunately, this package uses DOM to work with XML, so could have a serious memory consumption while trying to export large tables this way.

  • How to populate data from table into datagrid in form

    hi there. may i know how to populate data from a table into a datagrid? i have created a datagrid in a form using OLE's microsoft datagrid. i'm having problem to populate data from table into the grid. can i know how to do that? thanks

    Not exactly. I want to enter input from form and the user can have all options to choose i.e. HIGH, MEDIUM or so on.
    Suppose, you have option to select HIGH, MEDIUM or LOW and you can see all these options together. You select LOW and when you save, it is saves in the table as a value. So when you view the table again, it will show LOW as active and HIGH and MEDIUM are null.

  • How to convert database table into xml file

    Hi.
    How to convert database table into XML file in Oracle HTML DB.
    Please let me know.
    Thanks.

    This not really a specific APEX question... but I search the database forum and found this thread which I think will help
    Exporting Oracle table to XML
    If it does not I suggest looking at the database forum or have a look at this document on using the XML toolkit
    http://download-east.oracle.com/docs/html/B12146_01/c_xml.htm
    Hope this helps
    Chris

  • Data from table in xml Format and Inserting it into  Table

    Hi All
    I have table where xml data is stored in long format with xml tag know i have read the entire xml xoulmn which is xml tag and insert it into diffrent table can any suggest me the code
    Thanks & Regards

    I believe you are on the wrong forum. You want the XML DB forum.
    See:
    XML DB

  • Generate Insert Statement Script to Extract Data from Table in Oracle 7i

    Hi all, I have an old Oracle legacy system that is running for over 15 years.Every now and then we need to extract data from this table@ ORacle 7i to be imported back to Oracle 10G.
    My thoughts are to create a script of Insert statements in oracle 7 and that to be deployed back to Oracle 10G.
    I found this scripts in Google and not sure how exactly this works.Any explanation on thsi scripts , would be greatly appreciated.I find this scripst may help to generate a set of insert statements from that table to the latest table at 10G.
    <pre>
    -- Step 1: Create this procedure:
    create or replace Function ExtractData(v_table_name varchar2) return varchar2 As
    b_found boolean:=false;
    v_tempa varchar2(8000);
    v_tempb varchar2(8000);
    v_tempc varchar2(255);
    begin
    for tab_rec in (select table_name from user_tables where table_name=upper(v_table_name))
    loop
    b_found:=true;
    v_tempa:='select ''insert into '||tab_rec.table_name||' (';
    for col_rec in (select * from user_tab_columns
    where
    table_name=tab_rec.table_name
    order by
    column_id)
    loop
    if col_rec.column_id=1 then
    v_tempa:=v_tempa||'''||chr(10)||''';
    else
    v_tempa:=v_tempa||',''||chr(10)||''';
    v_tempb:=v_tempb||',''||chr(10)||''';
    end if;
    v_tempa:=v_tempa||col_rec.column_name;
    if instr(col_rec.data_type,'CHAR') > 0 then
    v_tempc:='''''''''||'||col_rec.column_name||'||''''''''';
    elsif instr(col_rec.data_type,'DATE') > 0 then
    v_tempc:='''to_date(''''''||to_char('||col_rec.column_name||',''mm/dd/yyyy hh24:mi'')||'''''',''''mm/dd/yyyy hh24:mi'''')''';
    else
    v_tempc:=col_rec.column_name;
    end if;
    v_tempb:=v_tempb||'''||decode('||col_rec.column_name||',Null,''Null'','||v_tempc||')||''';
    end loop;
    v_tempa:=v_tempa||') values ('||v_tempb||');'' from '||tab_rec.table_name||';';
    end loop;
    if Not b_found then
    v_tempa:='-- Table '||v_table_name||' not found';
    else
    v_tempa:=v_tempa||chr(10)||'select ''-- commit;'' from dual;';
    end if;
    return v_tempa;
    end;
    show errors
    -- STEP 2: Run the following code to extract the data.
    set head off
    set pages 0
    set trims on
    set lines 2000
    set feed off
    set echo off
    var retline varchar2(4000)
    spool c:\t1.sql
    select 'set echo off' from dual;
    select 'spool c:\recreatedata.sql' from dual;
    select 'select ''-- This data was extracted on ''||to_char(sysdate,''mm/dd/yyyy hh24:mi'') from dual;' from dual;
    -- Repeat the following two lines as many times as tables you want to extract
    exec :retline:=ExtractData('dept');
    print :retline;
    exec :retline:=ExtractData('emp');
    print :retline;
    select 'spool off' from dual;
    spool off
    @c:\t1
    -- STEP3: Run the spooled output c:\recreatedata.sql to recreate data.
    Source:http://www.idevelopment.info/data/Oracle/DBA_tips/PL_SQL/PLSQL_5.shtml
    </pre>

    Thanks Justin.
    I get what you are saying,i really wanted to see the output of the codes, because the furtherst i could get from that code is
    SELECT EXTRACTDATA('MYTABLE') FROM MYTABLE;
    and it generated this:
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    I was expecting a string of
    insert into mytable values (19/1/2009,1,1);
    insert into mytable values (19/10/2008,5,10);
    Thanks for the explanation .

  • Converting an sap file output program into xml output

    Hi,
    I have developed a program from which i am able to generate outptut as a file. Since this file is going to be used by the third party system, user has come back asking me to generate an conversion program into xml of the file output.
    Since i have not handled previously about generating the xml conversion program. Please let me know how to do this or if you could provide me the sample program it will be great.
    Thanks in advance.
    Sunil Kumar

    Hello
    Just for example:
    data: itab type standard table of sflight.
    data: xml_out type string,xmltab type swbhtmltable.
    select * from sflight into table itab.
    call transformation ('ID')
    source tab = itab[]
    result xml xml_out.
    call function 'SWA_STRING_TO_TABLE'
    exporting
    character_string = xml_out
    importing
    character_table = xmltab.
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    call function 'GUI_DOWNLOAD'
    exporting
    filetype = 'BIN'
    filename = 'C:\xmlfile.xml'
    tables
    data_tab = xmltab.
    P.s. search SDN for CALL TRANSFORMATION

  • Extract SAP BW Data into XML

    Hi Gurus,
    Could anyone please tell me
    How to extract data in SAP BW (ODS or Infocube) into XML File.

    Hi All,
    thanx alot for your help.
    finally i got my solution.
    I have written ABAP code and converted ODS data into XML.
    Hope  it will help you all.....
    REPORT  ZCONVERT_TO_XML                         .
    TABLES: /BIC/AZHSO0400.
    PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME .
    DATA: ITAB LIKE /BIC/AZHSO0400 OCCURS 1 WITH HEADER LINE.
    DATA: L_DOM TYPE REF TO IF_IXML_ELEMENT,
          M_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT,
          G_IXML TYPE REF TO IF_IXML,
          W_STRING TYPE XSTRING,
          W_SIZE TYPE I,
          W_RESULT TYPE I,
          W_LINE TYPE STRING,
          IT_XML TYPE DCXMLLINES,
          S_XML LIKE LINE OF IT_XML,
          W_RC LIKE SY-SUBRC.
    DATA: XML TYPE DCXMLLINES.
    DATA: RC TYPE SY-SUBRC.
    DATA: BEGIN OF XML_TAB OCCURS 0,
              D LIKE LINE OF XML,
          END OF XML_TAB.
    START-OF-SELECTION.
      PERFORM GET_DATA.
      PERFORM CONVERT_XML.
    *PERFORM CONVERT_XML.
    *&      Form  GET_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM GET_DATA .
      SELECT * FROM /BIC/AZHSO0400 INTO TABLE ITAB.
    ENDFORM.                    " GET_DATA
    *&      Form  CONVERT_XML
          text
    -->  p1        text
    <--  p2        text
    FORM CONVERT_XML .
      CLASS CL_IXML DEFINITION LOAD.
      G_IXML = CL_IXML=>CREATE( ).
      CHECK NOT G_IXML IS INITIAL.
      M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
      CHECK NOT M_DOCUMENT IS INITIAL.
      WRITE: / 'Converting DATA TO DOM 1:'.
      CALL FUNCTION 'SDIXML_DATA_TO_DOM'
        EXPORTING
          NAME               = 'ITAB'
          DATAOBJECT         = ITAB[]
      CONTROL            =
       IMPORTING
         DATA_AS_DOM        = L_DOM
       CHANGING
         DOCUMENT           = M_DOCUMENT
      TYPE_HANDLE        =
       EXCEPTIONS
         ILLEGAL_NAME       = 1
         OTHERS             = 2
      IF SY-SUBRC = 0.
        WRITE:/ 'OK'.
      ELSE.
        WRITE: 'ERR = ', SY-SUBRC.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CHECK NOT L_DOM IS INITIAL.
      W_RC = M_DOCUMENT->APPEND_CHILD( NEW_CHILD = L_DOM ).
      IF W_RC IS INITIAL.
        WRITE 'Ok'.
      ELSE.
        WRITE: 'Err =',
        W_RC.
      ENDIF.
      CALL FUNCTION 'SDIXML_DOM_TO_XML'
        EXPORTING
          DOCUMENT            = M_DOCUMENT
      PRETTY_PRINT        = ' '
       IMPORTING
         XML_AS_STRING       = W_STRING
         SIZE                = W_SIZE
    TABLES
       XML_AS_TABLE        = IT_XML
       EXCEPTIONS
         NO_DOCUMENT         = 1
         OTHERS              = 2
      IF SY-SUBRC = 0.
        WRITE 'Ok'.
      ELSE.
        WRITE: 'Err =',
        SY-SUBRC.
      ENDIF.
      LOOP AT IT_XML INTO XML_TAB-D.
        APPEND XML_TAB.
      ENDLOOP.
      CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
         BIN_FILESIZE                  = W_SIZE
         FILENAME                      = GK_RUTA
         FILETYPE                      = 'BIN'
        TABLES
          DATA_TAB                      = XML_TAB
      FIELDNAMES                    =
       EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_WRITE_ERROR              = 2
      INVALID_FILESIZE              = 3
      INVALID_TYPE                  = 4
      NO_BATCH                      = 5
      UNKNOWN_ERROR                 = 6
      INVALID_TABLE_WIDTH           = 7
      GUI_REFUSE_FILETRANSFER       = 8
      CUSTOMER_ERROR                = 9
      NO_AUTHORITY                  = 10
         OTHERS                        = 10
      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.                    " CONVERT_XML
    Thanks and Regards,
    P.Madhusudhan Raju,

  • Extract program to extract data from SAP into multiple worksheets of excel

    Hi , I am currently facing an issue.
    Extracting the data during data extraction, conversion into an excel and also into multiple worksheets withing a excel file.
    What is the function which can help me. Also how do you give refernce to multiple worksheets to be created withing a excel file (which is the destination)
    Any sample program extracting data from SAP tables into a excel with multiple worksheet will be of immense help
    Please respond. Appreciate it.
    Rgds
    Madhu

    Hi Madhu,
    Here is the program for creating the excel file and creating the multiple worksheets.
    *& Report  ZEXCEL_UPLOAD2
    REPORT  ZEXCEL_UPLOAD2.
    INCLUDE ole2incl.
    DATA: application TYPE ole2_object,
           workbook TYPE ole2_object,
           sheet TYPE ole2_object,
           cells TYPE ole2_object.
    CONSTANTS: row_max TYPE i VALUE 256.
    DATA index TYPE i.
    DATA: BEGIN OF itab1 OCCURS 0, first_name(10), END OF itab1.
    DATA: BEGIN OF itab2 OCCURS 0, last_name(10), END OF itab2.
    DATA: BEGIN OF itab3 OCCURS 0, formula(50), END OF itab3.
    *START-OF-SELECTION
    START-OF-SELECTION.
      APPEND: 'Peter' TO itab1, 'Ivanov' TO itab2,
                                  '=Sheet1!A1 & " " & Sheet2!A1' TO itab3,
                'John' TO itab1, 'Smith' TO itab2,
                                  '=Sheet1!A2 & " " & Sheet2!A2' TO itab3.
      CREATE OBJECT application 'excel.application'.
      SET PROPERTY OF application 'visible' = 0.
      CALL METHOD OF application 'Workbooks' = workbook.
      CALL METHOD OF workbook 'Add'.
    Create first Excel Sheet
      CALL METHOD OF application 'Worksheets' = sheet
                                   EXPORTING #1 = 1.
      CALL METHOD OF sheet 'Activate'.
      SET PROPERTY OF sheet 'Name' = 'Sheet1'.
      LOOP AT itab1.
        index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
        CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
        SET PROPERTY OF cells 'Value' = itab1-first_name.
      ENDLOOP.
    Create second Excel sheet
      CALL METHOD OF application 'Worksheets' = sheet
                                   EXPORTING #1 = 2.
      SET PROPERTY OF sheet 'Name' = 'Sheet2'.
      CALL METHOD OF sheet 'Activate'.
      LOOP AT itab2.
        index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
        CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
        SET PROPERTY OF cells 'Value' = itab2-last_name.
      ENDLOOP.
    Create third Excel sheet
      CALL METHOD OF application 'Worksheets' = sheet
                                   EXPORTING #1 = 3.
      SET PROPERTY OF sheet 'Name' = 'Sheet3'.
      CALL METHOD OF sheet 'Activate'.
      LOOP AT itab3.
        index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
        CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
        SET PROPERTY OF cells 'Formula' = itab3-formula.
        SET PROPERTY OF cells 'Value' = itab3-formula.
      ENDLOOP.
    Save excel speadsheet to particular filename
      CALL METHOD OF sheet 'SaveAs'
                      EXPORTING #1 = 'c:\temp\exceldoc1.xls'     "filename
                                #2 = 1.                          "fileFormat
    Closes excel window, data is lost if not saved
    SET PROPERTY OF application 'visible' = 0.
    **Quick guide to some of the OLE statements for OLE processing in this program as well as a few other ones.
    Save Excel speadsheet to particular filename
    CALL METHOD OF sheet 'SaveAs'
                    EXPORTING #1 = 'C:\Users\dprasad\Desktop\excel_sheet.xls'     "filename
                              #2 = 1.                          "fileFormat
    Save Excel document
    CALL METHOD OF sheet 'SAVE'.
    Quits out of Excel document
    CALL METHOD OF sheet 'QUIT'.
    Closes visible Excel window, data is lost if not saved
    SET PROPERTY OF application 'visible' = 0.

  • Export Advanced Recordset from Database into XML

    I don't think I was clear on my previous post about my goal
    with Exporting an advanced MySQL query to an XML file.
    Simple example: I have a photo gallery that has pictures of
    various Architect Projects. The main page shows distinct images of
    various projects (like an index). When one clicks on this image to
    view the rest of the Project details, a detail page opens with more
    information and additional images within this project.
    I want to use Spry/Ajax to give the images nice dynamic
    effects on the detail page. Normally to get from an index page to a
    detail page using normal server-side procedures, one would have to
    set up a dynamic link to the detail page by passing the recordID
    thru a URL Parameter. The detail page would have a recordset query
    that would call the URL Parameter so that the distinct record
    chosen will be the only record displayed.
    When exporting this query from the database to XML, for some
    reason the following query only displays the <row> node in
    the schema when creating a Dataset. See the following sql query
    that I am trying to use on the detail page to create the dataset
    via XML:
    SELECT*
    FROM project_tbl
    WHERE projectID = [URL PARAM] projectID
    Why, when creating a dataset in Spry and exporting it into
    XML, will this query NOT work?
    What can I do to make this work? URGENT HELP will be kindly
    appreciated.

    Danilo,
    I do not have a link yet as the files are on my remote
    server. I have implemented the code you sent me but still no luck.
    Please see the code I have below:
    The XML Generating Page:
    <?php require_once('../Connections/plymouth.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType,
    $theDefinedValue = "", $theNotDefinedValue = "")
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue)
    : $theValue;
    $theValue = function_exists("mysql_real_escape_string") ?
    mysql_real_escape_string($theValue) :
    mysql_escape_string($theValue);
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) .
    "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue :
    $theNotDefinedValue;
    break;
    return $theValue;
    ?>
    <?php
    // Query the database and get the selected records from
    Project & Images
    $colname_rsProject = "-1";
    if (isset($_GET['projectID'])) {
    $colname_rsProject = (get_magic_quotes_gpc()) ?
    $_GET['projectID'] : addslashes($_GET['projectID']);
    mysql_select_db($database_plymouth, $plymouth);
    $query_rsProject = sprintf("SELECT * FROM projects_tbl WHERE
    projectID = %s", GetSQLValueString($colname_rsProject, "int"));
    $rsProject = mysql_query($query_rsProject, $plymouth) or
    die(mysql_error());
    $row_rsProject = mysql_fetch_assoc($rsProject);
    $totalRows_rsProject = mysql_num_rows($rsProject);
    // Send the headers
    header('Content-type: text/xml');
    header('Pragma: public');
    header('Cache-control: private');
    header('Expires: -1');
    ?>
    <?php echo('<?xml version="1.0"
    encoding="utf-8"?>'); ?>
    <root>
    <?php if ($totalRows_rsProject > 0) { // Show if
    recordset not empty ?>
    <?php do { ?>
    <row>
    <?php foreach ($row_rsProject as $column=>$value) {
    ?>
    <<?php echo $column; ?>><?php echo
    $row_rsProject[$column]; ?></<?php echo $column; ?>>
    <?php } ?>
    </row>
    <?php } while ($row_rsProject =
    mysql_fetch_assoc($rsProject)); ?>
    <?php } // Show if recordset not empty ?>
    </root>
    <?php
    mysql_free_result($rsProject);
    ?>
    --------------------------------------------here is the
    source code to the projecct_detail page to display the
    content--------
    The projectID from the category page is being passed via a
    URL parameter. When I pull up the Spry Dataset in this page to
    display the nodes, this is the error I received (Unable to locate
    or parse the XML source (-1,-1). No nodes are being displayed.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml"><!--
    InstanceBegin template="/Templates/temp.dwt.php"
    codeOutsideHTMLIsLocked="false" -->
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Untitled Document</title>
    <!-- InstanceEndEditable -->
    <link href="global.css" rel="stylesheet" type="text/css"
    />
    <!-- InstanceBeginEditable name="head" -->
    <script src="SpryAssets/xpath.js"
    type="text/javascript"></script>
    <script src="SpryAssets/SpryData.js"
    type="text/javascript"></script>
    <script type="text/javascript">
    <!--
    var ds1 = new
    Spry.Data.XMLDataSet("xml/detail.php><?php echo(
    isset($_GET['projectID'])?$_GET['projectID']:'' ); ?>", "row");
    //-->
    </script>
    <!-- InstanceEndEditable -->
    </head>
    <body class="oneColFixCtr">
    <div id="container"><!-- InstanceBeginEditable
    name="Main Content" -->
    <div id="mainContent">
    <h1> </h1>
    <p> </p>
    <!-- end #mainContent -->
    </div>
    <!-- InstanceEndEditable -->
    <div id="footer">
    <img src="images/banner.gif" width="500" height="66"
    alt="Plymouth Road Architects" />
    <br />
    <div id="nav">
    <table width="500" border="0" cellspacing="2"
    cellpadding="2">
    <tr>
    <td><div align="center"><a href="
    http://plymouthroadarchitects.com">HOME</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="company_info.php">ABOUT/CONTACT
    US</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" alt="" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="new_homes.php">NEW HOMES</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" alt="" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="additions.php">ADDITIONS</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" alt="" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="main_street.php">MAIN
    STREET</a></div></td>
    </tr>
    </table>
    </div>
    </div>
    <!-- end #container --></div>
    </body>
    <!-- InstanceEnd --></html>
    Sorry for all the confusion and not submitting this code to
    you earlier on this forum. I really do appreciate your feedback and
    assistance

  • Reading any value from table into a string (Especially date etc..)

    How would I read any value from a table into a string?
    Currently doing the following...
    data ret_val type string.
    select single (wa_map-qes_field) from z_qekko into ret_val
    where
    angnr = _angnr.
    When the source field is a date it bombs though.
    The result goes into a BDCDATA-fval.
    regards
    Dylan.

    Tried...
    1    DATA: lp_data TYPE REF TO DATA.
    2    FIELD-SYMBOLS: <value> TYPE ANY.
    3    CREATE DATA lp_data LIKE (wa_map-qes_field).
    4    ASSIGN lp_data->* TO <value>.
    5    SELECT SINGLE (wa_map-qes_field) FROM zquadrem_qekko INTO <value> WHERE angnr = _angnr.
    Complains that (wa_map-qes_field) is not defined in line 3.
    Think that the bracket thing is only available via SQL.
    What about CREATE DATA lp_data type ref to object. ?
    Would the above declaration work?
    regards

  • Financial Statement hierarchy not extracted correctly from ECC into BW.

    Recently, one of my clients modified a FS hierarchy in production environment by moving some nodes from revenue to expenses, but BW is not picking up the change.
    In ECC via transaction FSE3, one of our Financial Statement hierarchies shows three nodes - (Group Life_, Vehicle Plan only_, and Cost of Removal_) as Expenses. However, the BW extractor still shows these three nodes as Revenue and loads the hierarchy into BW that way as well.
    DataSource is 0GL_ACCOUNT_T011_HIER with field HIENM = AE03. When running RSA3 Extractor Checker in ECC, the displayed data still shows the three nodes in question as Revenue and not correctly as Expenses.
    Found SAP note 1061847 - Ind. For reversing plus/minus signs not extracted correctly. Applied note in ECC development environment, tested the extractor, and checked the load into BW, but the error regarding the nodes still exists after applying the fix.
    Appreciate any suggestions or thoughts from the community.
    Thanks!
    SAP landscape is as follows:
    SAP_BW     700     0009     SAPKW70009     SAP NetWeaver BI 7.0
    SAP_AP     700     0007     SAPKNA7007     SAP Application Platform
    SAP_BASIS     700     SAPKB70010     SAP Basis Component

    Thanks SDNBI. I reviewed the suggested OSS note 1037447, but I am not sure how it applies in my situation. The suggested note seems to address a problem with the display of transfer structure in BW. Our problem seems to be that the extractor on ECC is incorrectly extracting the hierarchy structure. When viewing the data in RSA3 extract checker in ECC, I see the three nodes in question incorrectly positioned in the hierarchy. Thus loaded the same incorrect way into BW. Yet, when I display the hierarchy through transaction FSE2, the three nodes are displayed correctly.

Maybe you are looking for

  • Vendor balance

    Hi Friends, my client wants to know, what is the other side of the entry made to vendors balance. I couldnt find any field in vendor reports which tells me what is other side of the entry, if I pull GL account number it gives me the recon. account fo

  • Corporate Group field in Customer master - Control data

    If the customer or the vendor belongs to a group, you can enter a group key here. The group key is freely assignable. If you create a matchcode using this group key, group evaluations are possible. How this field can be best used. Can some body highl

  • Apache Beehive support plug-in

    Hi,, is these a plug-in for JDeveloper to support Apache Beehive framework ? Thanks & Rgds, Ram

  • How can I sync new friends from Facebook?

    Hi guys, I have Nokia N9 with the latest firmware version. I configured my Facebook account and set it to show my friend list in my Contacts. I can see all my friends from Facebook and they have merged with my contacts list. But when I add new friend

  • How can we lock Benefit Infotype record of an Employee

    Hi, We want to make sure that one employee through portal not be able to make any change in his benefit records. How can we do this?.. I think it is related to employee's individual data, we need to block or something with his benefit infotype. Pleas