Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

converting xml nodes and values to abap internal table fields and values

Former Member
0 Likes
5,405

Hi ,

I have a requirement to convert xml to abap internal table . But the requirement is that i need to create internal table according to the XML .

Ex : If my XML is :
 
<?xml version="1.0" ?> 
- <flights>
- <airline code="AA" name="American Airlines">
- <flight number="0017">
  <from airport="JFK">NEW YORK,US</from> 
  <to airport="SFO">SAN FRANCISCO,US</to> 
  <departure>110000</departure> 
  <arrival>140100</arrival> 
  <type>Scheduled</type> 
  </flight>
- <flight number="0064">
  <from airport="SFO">SAN FRANCISCO,US</from> 
  <to airport="JFK">NEW YORK,US</to> 
  <departure>090000</departure> 
  <arrival>172100</arrival> 
  <type>Scheduled</type> 
  </flight>
  </airline>

So after conversion my abap internal table shoul have fields as :

airline_code     Name      flight_number   from_airport    to_airport      departure         arrival      type

and the field values should be corresponding field values .

Thanks in advance .

Regards .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,766

Hi Max ,

The problem is not solved . Please suggest something . ...

Regards.

Hi ,

I have a requirement to convert xml to abap internal table . But the requirement is that i need to create internal table according to the XML .

Ex : If my XML is :
 
<?xml version="1.0" ?> 
- <flights>
- <airline code="AA" name="American Airlines">
- <flight number="0017">
  <from airport="JFK">NEW YORK,US</from> 
  <to airport="SFO">SAN FRANCISCO,US</to> 
  <departure>110000</departure> 
  <arrival>140100</arrival> 
  <type>Scheduled</type> 
  </flight>
- <flight number="0064">
  <from airport="SFO">SAN FRANCISCO,US</from> 
  <to airport="JFK">NEW YORK,US</to> 
  <departure>090000</departure> 
  <arrival>172100</arrival> 
  <type>Scheduled</type> 
  </flight>
  </airline>

So after conversion my abap internal table shoul have fields as :

airline_code     Name      flight_number   from_airport    to_airport      departure         arrival      type

and the field values should be corresponding field values .

Thanks in advance .

Regards .

26 REPLIES 26
Read only

brad_bohn
Active Contributor
0 Likes
3,766

See the help files on CALL TRANSFORMATION. You can use ST (Simple Transformations) or XSLT to write a transformation template in transaction XSLT_TOOL to transform your XML. The Application Help for the transaction will take you to the appropriate location in the help files as well.

Read only

Former Member
0 Likes
3,766

Hi ,

There is not such problem of converting data into internal table the problem im facing is with runtime creation of dynamic table .

Plz help me in this problem .

Edited by: ujjwal dharmak on Jan 11, 2010 4:01 PM

Read only

0 Likes
3,766

But the source XML is formed according to a schema definition - why do you have to react dynamically to that?

Read only

0 Likes
3,766

After converting the XML data into internal table u can create a new one based on the data loaded in the internal table, perhaps this sample can help you:

DATA: BEGIN OF ITAB OCCURS 0,
        FIELD_NAME(30),
      END OF ITAB.

ITAB-FIELD_NAME = 'AIRLINE_CODE'.  APPEND ITAB.
ITAB-FIELD_NAME = 'NAME'.          APPEND ITAB.
ITAB-FIELD_NAME = 'FLIGHT_NUMBER'. APPEND ITAB.
ITAB-FIELD_NAME = 'FROM_AIRPORT'.  APPEND ITAB.
ITAB-FIELD_NAME = 'TO_AIRPORT'.    APPEND ITAB.

DATA: LR_VALUE_DESCR  TYPE REF TO CL_ABAP_ELEMDESCR,
      LR_STRUCT_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR,
      LR_TAB_DESCR    TYPE REF TO CL_ABAP_TABLEDESCR,
      COMPONENT       TYPE CL_ABAP_STRUCTDESCR=>COMPONENT,
      LT_COMPONENTS   TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.


LOOP AT ITAB.
  COMPONENT-NAME = ITAB-FIELD_NAME.
  MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = 10 )
                                            TO LR_VALUE_DESCR.
  COMPONENT-TYPE = LR_VALUE_DESCR.
  INSERT COMPONENT INTO TABLE LT_COMPONENTS.
ENDLOOP.

DATA: DYN_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <FS_TAB> TYPE TABLE.

* Create line type
LR_STRUCT_DESCR
      = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS
                                     P_STRICT     = 'X' ).
* Create table
LR_TAB_DESCR = CL_ABAP_TABLEDESCR=>CREATE(
                                   P_LINE_TYPE = LR_STRUCT_DESCR ).
*
CREATE DATA DYN_TAB TYPE HANDLE LR_TAB_DESCR.
ASSIGN DYN_TAB->* TO <FS_TAB>.

Max

Read only

Former Member
0 Likes
3,766

hi Brad ,

the source XML is formed according to a schema definition , but what about internal table to be created according to the xml data ?

Edited by: ujjwal dharmak on Jan 12, 2010 10:18 AM

Read only

Former Member
0 Likes
3,766

Hi Max ,

Your answer is helpful .Could you please explain how i can fill the created dynamic table with values .

EX :

airline_code        Name                     flight_number          from_airport                to_airport       departure         arrival      type

       AA               American                         4101                    newyork                  london                17:15            16:15         E

Read only

0 Likes
3,766

Hi

Can u say us how the internal table of XML data is?

Max

Read only

Former Member
0 Likes
3,766

Hi Max,

Im using this following code . Its in dom structure .

DATA: node      TYPE REF TO if_ixml_node,
          iterator  TYPE REF TO if_ixml_node_iterator,
          nodemap   TYPE REF TO if_ixml_named_node_map,
          attr      TYPE REF TO if_ixml_node,
          name      TYPE string,
          prefix    TYPE string,
          value     TYPE string,
          indent    TYPE i,
          count     TYPE i,
          index     TYPE i.


    node ?= document.

    CHECK NOT node IS INITIAL.

    ULINE.
    WRITE: /.
    WRITE: /' DOM-TREE'.
    WRITE: /.
    IF node IS INITIAL. EXIT. ENDIF.
*   create a node iterator
    iterator  = node->create_iterator( ).
*   get current node
    node = iterator->get_next( ).

*   loop over all nodes
    WHILE NOT node IS INITIAL.
      indent = node->get_height( ) * 2.
      indent = indent + 20.

      CASE node->get_type( ).
        WHEN if_ixml_node=>co_node_element.
*         element node
          name    = node->get_name( ).
          nodemap = node->get_attributes( ).
          WRITE: / 'ELEMENT  :'.
          WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
          IF NOT nodemap IS INITIAL.
*           attributes
            count = nodemap->get_length( ).
            DO count TIMES.
              index  = sy-index - 1.
              attr   = nodemap->get_item( index ).
              name   = attr->get_name( ).
              prefix = attr->get_namespace_prefix( ).
              value  = attr->get_value( ).
              WRITE: / 'ATTRIBUTE:'.
              WRITE: AT indent name  COLOR COL_HEADING INVERSE, '=',
                               value COLOR COL_TOTAL   INVERSE.
            ENDDO.
          ENDIF.
        WHEN if_ixml_node=>co_node_text OR
             if_ixml_node=>co_node_cdata_section.
*         text node
          value  = node->get_value( ).
          WRITE: / 'VALUE     :'.
          WRITE: AT indent value COLOR COL_GROUP INVERSE.
      ENDCASE.
*     advance to next node
      node = iterator->get_next( ).
    ENDWHILE.

I atleast got that methods attr->get_name() and attr->get_value() will give me the names of fields and corresponding values .

So im thinking of statement like

itab-field_name = attr->get_name()

for getting fieldname . The main thing is to arrange the order of these statements so as to get a correct internal table structure filled with corresponding values .

Read only

0 Likes
3,766

Hi

This is my modification:

A) Create the internal table:

DATA: DOCUMENT  TYPE REF TO CL_XML_DOCUMENT,
      NODE      TYPE REF TO IF_IXML_NODE,
      ITERATOR  TYPE REF TO IF_IXML_NODE_ITERATOR,
      NODEMAP   TYPE REF TO IF_IXML_NAMED_NODE_MAP,
      ATTR      TYPE REF TO IF_IXML_NODE,
      NAME      TYPE STRING,
      PREFIX    TYPE STRING,
      VALUE     TYPE STRING,
      INDENT    TYPE I,
      COUNT     TYPE I,
      INDEX     TYPE I,
      ID_TREE(9)   TYPE N,
      LEN       TYPE I.

DATA: RETCODE TYPE SYSUBRC.

DATA: BEGIN OF T_XML_1 OCCURS 0,
        FIELD(30),
        LEN  TYPE I,
      END OF T_XML_1.

DATA: L_XML_1 LIKE T_XML_1.
*
CREATE OBJECT DOCUMENT.
RETCODE = DOCUMENT->IMPORT_FROM_FILE(
          'C:\Users\Administrator\Documents\test.xml' ).
CHECK RETCODE = 0.

NODE ?= DOCUMENT->M_DOCUMENT.

CHECK NOT NODE IS INITIAL.

ULINE.
WRITE: /.
WRITE: /' DOM-TREE'.
WRITE: /.
IF NODE IS INITIAL. EXIT. ENDIF.
*   create a node iterator
ITERATOR  = NODE->CREATE_ITERATOR( ).
*   get current node
NODE = ITERATOR->GET_NEXT( ).

*   loop over all nodes
WHILE NOT NODE IS INITIAL.
  INDENT = NODE->GET_HEIGHT( ).
  ID_TREE = INDENT.
  INDENT  = INDENT * 2.
  INDENT = INDENT + 20.

  CASE NODE->GET_TYPE( ).
    WHEN IF_IXML_NODE=>CO_NODE_ELEMENT.
*         element node
      NAME    = NODE->GET_NAME( ).

      T_XML_1-FIELD = NAME.
      LEN = STRLEN( T_XML_1-FIELD ).

      NODEMAP = NODE->GET_ATTRIBUTES( ).
      WRITE: / 'ELEMENT  :'.
      WRITE: AT INDENT NAME COLOR COL_POSITIVE INVERSE.
      IF NOT NODEMAP IS INITIAL.
*           attributes
        COUNT = NODEMAP->GET_LENGTH( ).
        DO COUNT TIMES.
          INDEX  = SY-INDEX - 1.
          ATTR   = NODEMAP->GET_ITEM( INDEX ).
          NAME   = ATTR->GET_NAME( ).
          PREFIX = ATTR->GET_NAMESPACE_PREFIX( ).
          VALUE  = ATTR->GET_VALUE( ).
*
          T_XML_1-FIELD+LEN(1) = '_'.
          LEN = LEN + 1.
          T_XML_1-FIELD+LEN    = NAME.
          T_XML_1-LEN          = STRLEN( VALUE ).

          READ TABLE T_XML_1 INTO L_XML_1
             WITH KEY FIELD = T_XML_1-FIELD.
          IF SY-SUBRC <> 0.
            APPEND T_XML_1.
          ELSE.
            IF T_XML_1-LEN > L_XML_1-LEN.
              L_XML_1-LEN = T_XML_1-LEN.
              MODIFY T_XML_1 FROM T_XML_1 INDEX SY-TABIX.
            ENDIF.
          ENDIF.
        ENDDO.
      ENDIF.

To be continue.....

Read only

0 Likes
3,766
WHEN IF_IXML_NODE=>CO_NODE_TEXT OR
         IF_IXML_NODE=>CO_NODE_CDATA_SECTION.
*         text node
      VALUE  = NODE->GET_VALUE( ).

      T_XML_1-LEN          = STRLEN( VALUE ).

      READ TABLE T_XML_1 INTO L_XML_1
         WITH KEY FIELD = T_XML_1-FIELD.
      IF SY-SUBRC <> 0.
        APPEND T_XML_1.
      ELSE.
        IF T_XML_1-LEN > L_XML_1-LEN.
          L_XML_1-LEN = T_XML_1-LEN.
          MODIFY T_XML_1 FROM T_XML_1 INDEX SY-TABIX.
        ENDIF.
      ENDIF.
  ENDCASE.
*     advance to next node
  NODE = ITERATOR->GET_NEXT( ).
ENDWHILE.

DATA: LR_VALUE_DESCR  TYPE REF TO CL_ABAP_ELEMDESCR,
      LR_STRUCT_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR,
      LR_TAB_DESCR    TYPE REF TO CL_ABAP_TABLEDESCR,
      COMPONENT       TYPE CL_ABAP_STRUCTDESCR=>COMPONENT,
      LT_COMPONENTS   TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.


LOOP AT T_XML_1.
  COMPONENT-NAME = T_XML_1-FIELD.
  MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = T_XML_1-LEN )
                                            TO LR_VALUE_DESCR.
  COMPONENT-TYPE = LR_VALUE_DESCR.
  INSERT COMPONENT INTO TABLE LT_COMPONENTS.
ENDLOOP.

DATA: DYN_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <FS_TAB> TYPE TABLE.

* Create line type
LR_STRUCT_DESCR
      = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS
                                     P_STRICT     = 'X' ).
LR_TAB_DESCR = CL_ABAP_TABLEDESCR=>CREATE(
                                   P_LINE_TYPE = LR_STRUCT_DESCR ).
* Create table

CREATE DATA DYN_TAB TYPE HANDLE LR_TAB_DESCR.
ASSIGN DYN_TAB->* TO <FS_TAB>.

U need to read the xml data again in order to get the field value

Max

Read only

Former Member
0 Likes
3,766

Hi Max ,

Im using the xml mentioned in my first post . I tried yr code . when executing it very first time .

1)read table t_xml_1 into l_xml_1
             2)with key field = t_xml_1-field.
          3)if sy-subrc  eq 0.
           4) append t_xml_1.
          5)else.
            6)if t_xml_1-len > l_xml_1-len.
             7) l_xml_1-len = t_xml_1-len.
             8) modify t_xml_1 from t_xml_1 index sy-tabix.
            9)endif.

when the debugger executes line 1)-2) the data in the header of t_xml_1 is

                           field                      len

headerline        airline_code                     2

t_xml_1 contains no data in body .

Can u make some changes as it gives dump at line 😎 as ay-tabix is 0 .

Regards

Edited by: ujjwal dharmak on Jan 13, 2010 10:42 AM

Edited by: ujjwal dharmak on Jan 13, 2010 10:43 AM

Edited by: ujjwal dharmak on Jan 13, 2010 10:45 AM

Read only

0 Likes
3,766

Hi

READ TABLE T_XML_1 INTO L_XML_1
         WITH KEY FIELD = T_XML_1-FIELD.
      IF SY-SUBRC NE  0.
        APPEND T_XML_1.
      ELSE.
        IF T_XML_1-LEN > L_XML_1-LEN.
          L_XML_1-LEN = T_XML_1-LEN.
          MODIFY T_XML_1 FROM L_XML_1 INDEX SY-TABIX.
        ENDIF.

Max

Read only

Former Member
0 Likes
3,766

Hi Max ,

Thanks for your reply .

U said i need to read the xml data again in order to get the field value .

Can i also start reading data in another internal table from statement

CASE NODE->GET_TYPE( ).
............
...........
endcase

in the same code and not repeating the code again ?

Or i have to use the <FS_TAB> for reading table values ?

Please illustrate .

Regards

Read only

Former Member
0 Likes
3,766

Hi Max ,

Plz help the problem is not solved .

Read only

0 Likes
3,766

Perhaps something like this can help you:

WHILE NOT NODE IS INITIAL.
  INDENT = NODE->GET_HEIGHT( ).

  ID_TREE = INDENT.
  INDENT  = INDENT * 2.
  INDENT = INDENT + 20.
  CASE NODE->GET_TYPE( ).
    WHEN IF_IXML_NODE=>CO_NODE_ELEMENT.
*         element node
      NAME    = NODE->GET_NAME( ).

      T_XML_1-FIELD = NAME.
      LEN = STRLEN( T_XML_1-FIELD ).

      NODEMAP = NODE->GET_ATTRIBUTES( ).
      WRITE: / 'ELEMENT  :'.
      WRITE: AT INDENT NAME COLOR COL_POSITIVE INVERSE.
      IF NOT NODEMAP IS INITIAL.
*           attributes
        COUNT = NODEMAP->GET_LENGTH( ).
        DO COUNT TIMES.
          INDEX  = SY-INDEX - 1.
          ATTR   = NODEMAP->GET_ITEM( INDEX ).
          NAME   = ATTR->GET_NAME( ).
          PREFIX = ATTR->GET_NAMESPACE_PREFIX( ).
          VALUE  = ATTR->GET_VALUE( ).
*
          T_XML_1-FIELD+LEN(1) = '_'.
          LEN = LEN + 1.
          T_XML_1-FIELD+LEN    = NAME.
          T_XML_1-LEN          = STRLEN( VALUE ).

          TRANSLATE T_XML_1-FIELD TO UPPER CASE.

          READ TABLE T_XML_1 INTO L_XML_1
             WITH KEY FIELD = T_XML_1-FIELD.
          IF SY-SUBRC <> 0.
            APPEND T_XML_1.
          ELSE.
            IF T_XML_1-LEN > L_XML_1-LEN.
              L_XML_1-LEN = T_XML_1-LEN.
              MODIFY T_XML_1 FROM T_XML_1 INDEX SY-TABIX.
            ENDIF.
          ENDIF.

          T_XML_2-FIELD = T_XML_1-FIELD.
          T_XML_2-VALUE = VALUE.
          T_XML_2-POS   = ID_TREE.
          IF NOT T_XML_2-VALUE IS INITIAL.
            APPEND T_XML_2.
          ENDIF.
        ENDDO.
      ENDIF.
    WHEN IF_IXML_NODE=>CO_NODE_TEXT OR
         IF_IXML_NODE=>CO_NODE_CDATA_SECTION.
*         text node
      VALUE  = NODE->GET_VALUE( ).

      TRANSLATE T_XML_1-FIELD TO UPPER CASE.

      T_XML_1-LEN          = STRLEN( VALUE ).

      READ TABLE T_XML_1 INTO L_XML_1
         WITH KEY FIELD = T_XML_1-FIELD.
      IF SY-SUBRC <> 0.
        APPEND T_XML_1.
      ELSE.
        IF T_XML_1-LEN > L_XML_1-LEN.
          L_XML_1-LEN = T_XML_1-LEN.
          MODIFY T_XML_1 FROM T_XML_1 INDEX SY-TABIX.
        ENDIF.
      ENDIF.
  ENDCASE.
*     advance to next node
  NODE = ITERATOR->GET_NEXT( ).
ENDWHILE.

Max

Read only

0 Likes
3,766
DATA: LR_VALUE_DESCR  TYPE REF TO CL_ABAP_ELEMDESCR,
      LR_STRUCT_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR,
      LR_TAB_DESCR    TYPE REF TO CL_ABAP_TABLEDESCR,
      COMPONENT       TYPE CL_ABAP_STRUCTDESCR=>COMPONENT,
      LT_COMPONENTS   TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.


LOOP AT T_XML_1.
  COMPONENT-NAME = T_XML_1-FIELD.
  MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = T_XML_1-LEN )
                                            TO LR_VALUE_DESCR.
  COMPONENT-TYPE = LR_VALUE_DESCR.
  INSERT COMPONENT INTO TABLE LT_COMPONENTS.
ENDLOOP.

DATA: DYN_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <FS_TAB> TYPE TABLE.

DATA: DYN_WA TYPE REF TO DATA.
FIELD-SYMBOLS: <FS_WA> TYPE ANY.

FIELD-SYMBOLS: <FS_VAL> TYPE ANY.

* Create line type
LR_STRUCT_DESCR
      = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS
                                     P_STRICT     = 'X' ).
CREATE DATA DYN_WA TYPE HANDLE LR_STRUCT_DESCR.
ASSIGN DYN_WA->* TO <FS_WA>.


LR_TAB_DESCR = CL_ABAP_TABLEDESCR=>CREATE(
                                   P_LINE_TYPE = LR_STRUCT_DESCR ).
* Create table

CREATE DATA DYN_TAB TYPE HANDLE LR_TAB_DESCR.
ASSIGN DYN_TAB->* TO <FS_TAB>.

DO.
  READ TABLE T_XML_2 INDEX SY-INDEX.
  IF SY-SUBRC <> 0. EXIT. ENDIF.

  IF POS_PREV > T_XML_2-POS.
    APPEND <FS_WA> TO <FS_TAB>.
  ENDIF.

  POS_PREV = T_XML_2-POS.

  ASSIGN COMPONENT T_XML_2-FIELD OF STRUCTURE <FS_WA> TO <FS_VAL>.
  IF SY-SUBRC = 0.
    <FS_VAL> = T_XML_2-VALUE.
  ENDIF.

ENDDO.

APPEND <FS_WA> TO <FS_TAB>.

LOOP AT <FS_TAB> ASSIGNING <FS_WA>.
  WRITE: / <FS_WA>.
ENDLOOP.

Max

Read only

Former Member
0 Likes
3,766

Hi Max ,

Thanks for your code .

Im using such xml file .

<?xml version="1.0" ?> 
- <flights>
- <airline code="AA" name="American Airlines">
- <flight number="0017">
  <from airport="JFK">NEW YORK,US</from> 
  <to airport="SFO">SAN FRANCISCO,US</to> 
  </flight>
- <flight number="0064">
  <from airport="SFO">SAN FRANCISCO,US</from> 
  <to airport="JFK">NEW YORK,US</to> 
  </flight>
  </airline>
- <airline code="AZ" name="Alitalia">
- <flight number="0555">
........
..........

The out is :

AAAmerican Airlines 0017JFK             SFO
AAAmerican Airlines 0064SFO             JFK
AZAlitalia          0555FCO             FRA
AZAlitalia          0788FCO             TYO
AZAlitalia          0789TYO             FCO
AZAlitalia          0790FCO             KIX
..........................
.....

Can i create a normal standard table from this <FS_TAB> ?

like

ex :

loop at itab .
         write : / itab-AIRLINE_CODE , itab-AIRLINE__NAME,itab-FLIGHT_NUMBER,itab-FROM_AIRPORT,itab-TO_AIRPORT .
         endloop .

also how can separate or give spaces between data

ex AAAmerican Airlines 0064SFO

as

AA           American Airlines        0064           SFO         JFK

. ?

Regards .

Read only

Former Member
0 Likes
3,767

Hi Max ,

The problem is not solved . Please suggest something . ...

Regards.

Read only

0 Likes
3,766

Hi

What do u need?

Max

Read only

0 Likes
3,766

hi Max ,

i need to know how can i access each element of <fs_wa> ?

LOOP AT <FS_TAB> ASSIGNING <FS_WA>.
  WRITE: / <FS_WA>.
ENDLOOP.

iN first loop <fs_wa> will contain:

AA AMERICAN AIRLINES    0017 JFK    SFO

How i can fetch separately value AA then AMERICAN AIRLINES then 0017 then JFK ? as i need to put some spaces while displaying them on screen .

also , how can i display in the form mentioned below on screen ?

format :

AIRLINE_CODE    AIRLINE__NAME     FLIGHT_NUMBER         FROM_AIRPORT       TO_AIRPORT

AA             AMERICAN AIRLINES         0017              JFK               SFO

Read only

0 Likes
3,766

By field-symbol

U should have an internal table having the list of the fields of the dynamic internal table (in my sample T_XML_1):

LOOP AT <FS_TAB> ASSIGNING <FS_WA>.
  DO.
     READ TABLE T_XML_1 INDEX SY-TABIX.
     IF SY-SUBRC <> 0. EXIT. ENDIF.
     ASSIGN COMPONENT T_XML_1-FIELD OF STRUCTURE <FS_WA> TO <FS_VALUE>.
     WRITE: <FS_VALUE.
  ENDDO.
   WRITE: / .
ENDLOOP.

Max

Read only

Former Member
0 Likes
3,766

hi max ,

need your help .

im trying to get the file path from user by function .

i have defined p_path as:

PARAMETERS: p_path TYPE LOCALFILE

.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    CHANGING
      FILE_NAME     = p_path
    EXCEPTIONS
      MASK_TOO_LONG = 1
      OTHERS        = 2.
  IF SY-SUBRC  ne 0.
    EXIT.
  ENDIF.

CONCATENATE '''' p_path '''' INTO p_path.

its giving me dump at below line .

retcode = document->import_from_file( p_path ) .
*          'C:\Temp\flights2.xml' ).

dump is :Access via 'NULL' object reference not possible.

Please mention changes required .....

Read only

0 Likes
3,766

Hi

U have to instance the object before using a method:

CREATE OBJECT DOCUMENT. 
RETCODE = DOCUMENT->IMPORT_FROM_FILE( p_path ).

Max

Read only

Former Member
0 Likes
3,766

Hi Max ,

The problem is not solved yet . Need your help .

Consider xml file given below :

<?xml version="1.0" encoding="ISO-8859-1" ?> 
- <!--  Edited by XMLSpy® 
  --> 
- <bookstore>
- <book category="cooking">
  <title lang="en">Everyday Italian</title> 
  <author>Giada De Laurentiis</author> 
  <year>2005</year> 
  <price>30.00</price> 
  </book>
- <book category="web">
  <title lang="en">XQuery Kick Start</title> 
  <author>James McGovern</author> 
  <author>Per Bothner</author> 
  <author>Kurt Cagle</author> 
<author>Vaidyanathan Nagarajan</author>
  <year>2003</year> 
  <price>49.99</price> 
  </book>

the internal table should be like given below :

book_category_ty      title_lang_ty            title_lang_val              author_val        year_val       price_val
       cooking              en             Everyday Italian      Giada De Laurentiis         2005          30.00
       web                   en             XQuery Kick start    James McGovern             2003          49.99
        web                  en             XQuery Kick start    Per Bothner                    2003          49.99
        web                  en             XQuery Kick start    Kurt Cagle                      2003          49.99
        web                  en             XQuery Kick start    Vaidyanathan Nagarajan        2003          49.99

Regards.

Read only

Former Member
0 Likes
3,766

hi Max ,

whether program statements

retcode = document->import_from_file( p_path ) .
                     node ?= document->m_document.

are executed with any type of xml files? or they have some constraints like the xml files should have internal dtd or any external dtd ?

Regards ,

Read only

Former Member
0 Likes
3,766

Thanks Max you solved the problem