Skip to Content
author's profile photo Former Member
Former Member

Transition data to XML file

hi exeprt,

please help me.

Regards,

Hamadelnil

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2007 at 04:04 PM

    HI,

    Look at the Sample Program

    REPORT z_tab_file.
    
    PARAMETERS : gv_file(100) DEFAULT '.ATABTEST.TXT',
    p_csv AS CHECKBOX,
    p_xml AS CHECKBOX.
    
    *-----Types------------------------------------------------------------*
    TYPES:
    * Structure for Header File
    BEGIN OF gt_nisl_file,
    * urgent_flag(1) TYPE c,
    mat_typ(2) TYPE c,
    sales_org(4) TYPE c,
    dist_ch(2) TYPE c,
    division(2) TYPE c,
    * cont_no(1) TYPE c,
    * sold_to(4) TYPE c,
    * goods_rep(10) TYPE c,
    * delv_dt(1) TYPE c,
    * po_no(10) TYPE c,
    rep_name(40) TYPE c,
    * contact(32) TYPE c,
    * street(100) TYPE c,
    * postcode(10) TYPE c,
    * city(40) TYPE c,
    * region(1) TYPE c,
    * country(3) TYPE c,
    * phone_no(30) TYPE c,
    * fst_ln_ind(1) TYPE c,
    * order_ln_no(3) TYPE c,
    * ni_part_no(35) TYPE c,
    * cust_part(18) TYPE c,
    * quantity(3) TYPE c,
    * die_no(18) TYPE c,
    * town_circle(50) TYPE c,
    * code(1) TYPE c,
    * slogan_no(1) TYPE c,
    * head_txt(1000) TYPE c,
    * itm_txt1(32) TYPE c,
    * itm_txt2(10) TYPE c,
    END OF gt_nisl_file.
    
    
    *-----Internal Tables--------------------------------------------------*
    DATA:
    git_nisl_file TYPE TABLE OF gt_nisl_file.
    
    
    *-----Structures/Workareas---------------------------------------------*
    DATA:
    gs_nisl_file TYPE gt_nisl_file.
    * gv_dom TYPE REF TO if_ixml_element,
    * gv_document TYPE REF TO if_ixml_document,
    * gv_string TYPE xstring,
    * gv_size TYPE i,
    * git_xml TYPE dcxmllines.
    
    *FIELD-SYMBOLS: <f> TYPE ANY, <delim> TYPE ANY.
    
    * gv_file = '.ATABTEST.TXT'.
    
    *gs_nisl_file-urgent_flag = 'X'.
    DO 5000 TIMES.
    gs_nisl_file-mat_typ = 'MA'.
    gs_nisl_file-sales_org = '2000'.
    gs_nisl_file-dist_ch = '80'.
    gs_nisl_file-division = '01'.
    *gs_nisl_file-cont_no = '12345'.
    *gs_nisl_file-sold_to = '2002'.
    *gs_nisl_file-goods_rep = 'CUST ADDR'.
    *gs_nisl_file-po_no = 'PO12345'.
    *gs_nisl_file-delv_dt =
    gs_nisl_file-rep_name = 'REP NAME'.
    *gs_nisl_file-contact = 'CONTACT'.
    *gs_nisl_file-street = 'STREET'.
    *gs_nisl_file-postcode = 'POCODE'.
    *gs_nisl_file-city = 'CITY'.
    *gs_nisl_file-region =
    *gs_nisl_file-country = 'GB'.
    *gs_nisl_file-phone_no = '12234 57819'.
    *gs_nisl_file-fst_ln_ind = 'X'.
    *gs_nisl_file-order_ln_no = '010'.
    *gs_nisl_file-ni_part_no = '100110'.
    *gs_nisl_file-cust_part = '100110'.
    *gs_nisl_file-quantity = '1'.
    *gs_nisl_file-die_no = '1000032'.
    *gs_nisl_file-town_circle = '30000004'.
    *gs_nisl_file-code =
    *gs_nisl_file-slogan_no = '100110'.
    *gs_nisl_file-head_txt = 'HEADER TEXT'.
    *gs_nisl_file-itm_txt1 = 'ITEM TEXT1'.
    *gs_nisl_file-itm_txt2 = 'ITEM TEXT2'.
    APPEND gs_nisl_file TO git_nisl_file.
    ENDDO.
    DATA:
    lv_file(1000) TYPE c,
    lv_colt(5000) TYPE c,
    lv_cnt(2) TYPE c,
    lv_text(8) TYPE c.
    
    CONSTANTS:
    lc_hash TYPE x VALUE '09'.
    DATA :
    lc_hash_x TYPE xstring,
    * lc_hash_str type string.
    lc_hash_str(2) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
    
    
    FIELD-SYMBOLS:
    <lf_text> TYPE ANY.
    
    *ASSIGN lc_hash TO <delim>.
    
    * clear : lc_hash_x, lc_hash_str.
    * lc_hash_x = lc_hash.
    *
    * CALL FUNCTION 'NLS_STRING_CONVERT_TO_SYS'
    * EXPORTING
    * lang_used = sy-langu
    * SOURCE = lc_hash_x
    * IMPORTING
    * RESULT = lc_hash_str.
    
    * XML
    TYPES: BEGIN OF ttab,
    record(65535) TYPE c,
    END OF ttab.
    
    DATA: xmltable TYPE TABLE OF ttab.
    
    DATA: xml_out TYPE string,
    length LIKE sy-tabix,
    result1 LIKE gs_nisl_file.
    
    DATA wa_xmltable TYPE ttab.
    
    CHECK NOT git_nisl_file IS INITIAL.
    
    OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8. "DEFAULT.
    IF sy-subrc NE 0.
    WRITE :/ 'Unable to open file'(021),
    gv_file.
    EXIT.
    ENDIF. " sy-subrc
    
    IF p_csv = 'X'.
    PERFORM csv_download.
    ENDIF.
    
    IF p_xml = 'X'.
    PERFORM xml_download.
    ENDIF.
    
    CLOSE DATASET gv_file.
    
    END-OF-SELECTION.
    
    
    *&---------------------------------------------------------------------*
    *& Form csv_download
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM csv_download.
    * Header line 1: Transfer empty line
    TRANSFER lv_file TO gv_file.
    
    lv_file = '1'.
    lv_colt = text-h01.
    lv_cnt = '1'.
    DO.
    lv_cnt = lv_cnt + 1.
    * Generate line with all column numbers
    CONCATENATE lv_file lv_cnt INTO lv_file SEPARATED BY lc_hash_str.
    IF lv_cnt LE 9.
    CONCATENATE 'TEXT-H0' lv_cnt INTO lv_text.
    ELSE.
    CONCATENATE 'TEXT-H' lv_cnt INTO lv_text.
    ENDIF.
    ASSIGN (lv_text) TO <lf_text>.
    * Generate line with all column headers
    CONCATENATE lv_colt <lf_text> INTO lv_colt SEPARATED BY lc_hash_str.
    IF lv_cnt = 30.
    EXIT.
    ENDIF.
    ENDDO.
    * Header line 2: Line with all column numbers
    TRANSFER lv_file TO gv_file.
    * Header line 3: Line with all column headers
    TRANSFER lv_colt TO gv_file.
    
    
    
    LOOP AT git_nisl_file INTO gs_nisl_file.
    
    CLEAR lv_file.
    * CONCATENATE gs_nisl_file-urgent_flag
    * gs_nisl_file-mat_typ
    * gs_nisl_file-sales_org
    * gs_nisl_file-dist_ch
    * gs_nisl_file-division
    * gs_nisl_file-cont_no
    * gs_nisl_file-sold_to
    * gs_nisl_file-goods_rep
    * gs_nisl_file-po_no
    * gs_nisl_file-delv_dt
    * gs_nisl_file-rep_name
    * gs_nisl_file-contact
    * gs_nisl_file-street
    * gs_nisl_file-postcode
    * gs_nisl_file-city
    * gs_nisl_file-region
    * gs_nisl_file-country
    * gs_nisl_file-phone_no
    * gs_nisl_file-fst_ln_ind
    * gs_nisl_file-order_ln_no
    * gs_nisl_file-ni_part_no
    * gs_nisl_file-cust_part
    * gs_nisl_file-quantity
    * gs_nisl_file-die_no
    * gs_nisl_file-town_circle
    * gs_nisl_file-code
    * gs_nisl_file-slogan_no
    * gs_nisl_file-head_txt
    * gs_nisl_file-itm_txt1
    * gs_nisl_file-itm_txt2
    * INTO lv_file SEPARATED BY lc_hash_str.
    
    * PO details
    TRANSFER lv_file TO gv_file.
    
    ENDLOOP. " LOOP AT git_nisl_file
    
    ENDFORM. "csv_download
    
    *&---------------------------------------------------------------------*
    *& Form xml_download
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM xml_download.
    
    CALL TRANSFORMATION ('ID')
    SOURCE output = git_nisl_file
    RESULT XML xml_out.
    
    CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
    EXPORTING
    i_string = xml_out
    i_tabline_length = '65535'
    TABLES
    et_table = xmltable.
    
    LOOP AT xmltable INTO wa_xmltable.
    TRANSFER wa_xmltable-record TO gv_file.
    ENDLOOP.
    
    ENDFORM. "xml_download 

    and also look at the Blog ..

    /people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach

    Regards

    Sudheer

    Message was edited by:

    Sudheer Junnuthula

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2007 at 03:33 PM

    hi Hemadelnil,

    Try function module SAP_CONVERT_TO_XML_FORMAT.

    Hope this helps

    Sajan Joseph

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2007 at 03:38 PM

    If it is to convert IDOC data, then you can look at

    http://www.saptechnical.com/Tutorials/ALE/IDOCToXML/IDOCToXML.htm

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2007 at 12:04 AM

    If you have a 4.7 or later system, and have a web background, you can use XSLT transformations.

    Have a look at F1 help on CALL TRANSFORMATION, and search this forum.

    Michael

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.