Help needed XML to Internal table and vice versa
Hello frnds, I need to convert Internal table to XML and Vice versa.
Now I am able to most of the part except for this...
the xml which I have to generate looks something like this...
- <trade_dt>
- <![CDATA[ 20111108000000:20111108235959
]]>
</trade_dt>
its a range I think
And then the reponse which I get back the XML is like
- <lockinfo>
- <![CDATA[
TRD_HEADER 1045 1 2
ACT_CASHFLOW 1042 1
TRD_TERM 1045 2
]]>
</lockinfo>
Is there any provision in class cl_ixml or class if_ixml_element to handle this part.....
Edited by: Amit Sawant on Dec 28, 2011 3:51 PM
Hello Amit,
I would suggest you, to use the XSL-Transformations, which can be inbound used in ABAP.
For example:
DATA:
l_xml TYPE string,
lt_flights TYPE TABLE OF SFLIGHT.
SELECT * FROM SFLIGHT INTO TABLE LT_FLIGHT.
CALL TRANSFORMATION id
SOURCE DATA = lt_flights
RESULT XML l_xml.
Now, you have a XML-String which is in the ABAP-XML Notation, which means, that ABAP can move this XML-Data back into an internal table/structure.
For the backward, you have to use the following statement:
CALL TRANSFORMATION id
SOURCE XML l_xml
RESULT DATA = lt_flights.
As you will see, it is very easy. The Transformation "id" is just one example and build in. When you have to transform the data, or do not want to have the ASX-Notation in it, you should at least define your own transformations with the transaction XSLT_TOOL and use it similar to the transformation "id".
Kind Regards,
Hendrik
Similar Messages
-
Upload XML to internal table and vice versa in SAP 4.6C
Hi,
Happy New Year to you all!
We are using 46C and I am beginning to learn about XML. We have a requirement to (1) upload an XML file into an internal table as well as (2) create an XML file from an internal table.
I read some of the posted messages about this but they didn't seem to be applicable in 46C (I could be wrong).
Could someone please help me using the sample file below?
<?xml version="1.0" ?>
- <AUCTIONBLOCK>
- <ITEM>
<TITLE>Still Life / Onions</TITLE>
<ARTIST>Linda Mann</ARTIST>
<DIMENSIONS>20x30 inches</DIMENSIONS>
<MATERIALS>Oil</MATERIALS>
<YEAR>1997</YEAR>
<DESCRIPTION>Still Life</DESCRIPTION>
<TIMESTAMP>1974</TIMESTAMP>
</ITEM>
</AUCTIONBLOCK>
Many thanks,
RosemarieHi,
Yes I'm on 4.6c. I've to comment several lines. Here is an example:
*& Report z_xit_xml_check
report z_xit_xml_check.
class cl_ixml definition load.
type-pools: ixml.
types: begin of t_xml_line,
data(256) type x,
end of t_xml_line,
begin of tsfixml,
data(1024) type c,
end of tsfixml.
data: l_ixml type ref to if_ixml,
l_streamfactory type ref to if_ixml_stream_factory,
l_parser type ref to if_ixml_parser,
l_istream type ref to if_ixml_istream,
l_document type ref to if_ixml_document,
l_node type ref to if_ixml_node,
l_xmldata type string.
data: l_elem type ref to if_ixml_element,
l_root_node type ref to if_ixml_node,
l_next_node type ref to if_ixml_node,
l_name type string,
l_iterator type ref to if_ixml_node_iterator.
data: l_xml_table type table of t_xml_line,
l_xml_line type t_xml_line,
l_xml_table_size type i.
data: l_filename type string.
parameters: pa_file type char1024 default
'd:joaodesenvolvimentos i act este.xml'.
Validation of XML file: Only DTD included in xml document is supported
parameters: pa_val type char1 as checkbox.
start-of-selection.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
Regards,
Maria João Rocha
perform get_xml_table changing l_xml_table_size l_xml_table.
wrap the table containing the file into a stream
l_istream = l_streamfactory->create_istream_itable( table =
l_xml_table
size =
l_xml_table_size ).
Creating a document
l_document = l_ixml->create_document( ).
Create a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
if pa_val eq 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
endif.
Parse the stream
if l_parser->parse( ) ne 0.
if l_parser->num_errors( ) ne 0.
data: parseerror type ref to if_ixml_parse_error,
str type string,
i type i,
count type i,
index type i.
count = l_parser->num_errors( ).
write: count, ' parse errors have occured:'.
index = 0.
while index < count.
parseerror = l_parser->get_error( index = index ).
i = parseerror->get_line( ).
write: 'line: ', i.
i = parseerror->get_column( ).
write: 'column: ', i.
str = parseerror->get_reason( ).
write: str.
index = index + 1.
endwhile.
endif.
endif.
Process the document
if l_parser->is_dom_generating( ) eq 'X'.
perform process_dom using l_document.
endif.
*& Form get_xml_table
form get_xml_table changing l_xml_table_size type i
l_xml_table type standard table.
Local variable declaration
data: l_len type i,
l_len2 type i,
l_tab type tsfixml,
l_content type string,
l_str1 type string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab type table of string.
l_filename = pa_file.
upload a file from the client's workstation
call method cl_gui_frontend_services=>gui_upload
exporting
filename = l_filename
filetype = 'BIN'
importing
filelength = l_xml_table_size
changing
data_tab = l_xml_table
exceptions
others = 19.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
Writing the XML document to the screen
CLEAR l_str1.
LOOP AT l_xml_table INTO l_xml_line.
c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
*replacement = space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.
ENDLOOP.
l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
WRITE: /.
WRITE: /' XML File'.
WRITE: /.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
*IN
l_str1 WITH space.
WRITE: / l_str1.
ENDLOOP.
WRITE: /.
endform. "get_xml_table
*& Form process_dom
form process_dom using document type ref to if_ixml_document.
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.
data: name2 type string,
name_root type string,
node_parent type ref to if_ixml_node,
node_root type ref to if_ixml_node,
num_children 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.
num_children = node->num_children( ).
case node->get_type( ).
when if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
node_root = node->get_root( ).
name_root = node_root->get_name( ).
write: / 'ELEMENT :'.
write: at indent name color col_positive inverse.
write: 'NUM_CHILDREN:', num_children.
write: 'ROOT:', name_root.
node_parent = node->get_parent( ).
name2 = node_parent->get_name( ).
write: 'NAME2: ' , name2.
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 :'.
mjprocha
node_parent = node->get_parent( ).
write: at indent value color col_group inverse.
name2 = node_parent->get_name( ).
write: 'NAME2: ' , name2.
endcase.
advance to next node
node = iterator->get_next( ).
endwhile.
endform. "process_dom -
Some help needed on dynamic internal tables and field symbols
Hi,
I have a dyn internal table <dyn_table_r>.
One of its fields is kna1-kunnr.
I have another wa <fs>, with only one field alt_kunnr.
now i want to modify the data of <dyn_table_r>-kna1-kunnr from <fs>-alt_kunnr
How should i do it?
Regards ,
Harshit RungtaHarshit Rungta:
You have opened a number of related questions today. I'd like to see the other ones closed before you continue with this one.
I'll lock this but will re-open it once the others are marked as solved.
Rob -
How to transfer texts from text control to table and vice versa
Hi
if anybody can give me link or any code giving how to transfer text from text control to table and vice versa, that will be of great help to me
THanks in advanceRashmi,
Use the methods GET_TEXT_AS_R3TABLE / SET_TEXT_AS_R3TABLE and then you will have to use the SAVE_TEXT to store in the database.
The GET_TEXT_AS_R3TABLE method will give you back a internal in which text, in which text on the screen is existing. Similarly once you fetch the data from database using READ_TEXT, use the method SET_TEXT_AS_R3TABLE to put the text on the screen.
These methods belong to class CL_GUI_TEXTEDIT class.
Regards,
Ravi
note : Please mark all the helpful answers -
Urgent help needed!! Layout table and Draw layout cell dissapeared.
I need some urgent help. I'm using CS3 but for a while my
Layout Table and Draw Layout Cell icons appear greyed and can't use
them at all. Is there any kind soul out there who knows how to fix
this? I'm going nuts trying all the possible options but none seem
to work.
Help please!!!!!!> How would you about designing a page without using html?
You don't. But I don't recall suggesting that you not use
HTML. I just
suggested that you use best-practice HTML, no? Or maybe you
meant to ask
how you would go about building your site without learning
HTML? In that
case, I think you are outta luck. Using DW without knowing
HTML is a very
punishing experience, I'm afraid.
> PS: A virtual box of 12 bottles of Moet Chandon is
already on your way!!
I'd prefer Cristal, please.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"Untersberg" <[email protected]> wrote in
message
news:g4tj9a$m5o$[email protected]..
> Ahhhhhh!!!!! They came up!!!! They came up again!!
> I was on standard mode. Now going back to your
suggestion, which I really
> appreciate. How would you about designing a page without
using html? I'm
> just
> redesigning my website at the moment and need it to get
going urgently,
> hence
> the reluctance to start learning HTML at the moment.
I'll do after but I
> need
> to get this up and running fairly quickly.
>
> Cheers.
>
> PS: A virtual box of 12 bottles of Moet Chandon is
already on your way!!
> -
How to convert XML doc to string and vice versa?
Assume I have a XML doc and I want to convert it into a string (and put it into a string variable).
How can I do this?
How can I do the opposite: Convert a string content into a XML doc?
PeterUse:
ParseEscapedXML() and ora:getContentAsString()
See
http://www.codeguru.com/cpp/sample_chapter/article.php/c10789__7/
Marc -
Create XML file from internal table and vise a versa
Hi Friends,
I have requirement to create an XML string from internal table data and also read XML string data to internal table.
Can anybody tell are there any Function Modules or methods existing for this?
Thanks.
Krishna Yerram.1. Write XSLT program. T.code XSLT . e.g. XSLT name "ZTRANS".
2. Write ABAP program
Which includes declaration of internal tables
that you need "IT_DATA".
Upload XML data to an internal table "IT_XML "
use below statement to convert XML to internal table.
Call transformation ZTRANS
source XML IT_XML
result IT_DATA. -
ALV - need to sum values of internal table and display in ALV
I have data in internal table as:
Material date sum1 sum2
Mat_A 19990101 4 4
Mat_A 20080501 3 0
Mat_A 20080601 2 0
Mat_B 19990101 2 0
Mat_B 20080601 5 5
Required output is :
Material qty1 qty2 19990101 20080501 20080601
Mat_A 432 4 4 3 2
Mat_B 2+5 5 2 5
Thinking of using ALV to pass the internal table and display as classical report (and also to save as excel spreadsheet).
Counting your help on the following questions:
1) How to accomplish the sum in ALV report? Can ALV FM do that or one has to use ABAP to compute the sum from the given internal table?
2) Mat_A can have more date values. Here it got 3 distinct date values 19990101, 20080601, 20080501. If it has say 5 date values, how to create the ALV date columns (from 3 to 5 date columns) dynamically?
Thanks for the help.for the sum inalv we use generally..
it_fieldcat-do_sum = 1.
check this examples...
http://www.****************/Tutorials/ALV/Subtotals/text.htm
*& Report ZTEST_ALV_PERC_13317
REPORT ztest_alv_perc_13317.
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_events TYPE slis_t_event,
wa_events TYPE slis_alv_event,
it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
l_layout TYPE slis_layout_alv.
TYPES: BEGIN OF ty_itab,
field1(10),
qty1 TYPE i,
qty2 TYPE i,
qty3 TYPE i,
dummy TYPE c,
END OF ty_itab.
DATA: itab TYPE STANDARD TABLE OF ty_itab WITH HEADER LINE,
itab1 TYPE ty_itab.
START-OF-SELECTION.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'FIELD1'.
wa_fieldcat-tabname = 'ITAB'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'QTY1'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'QTY2'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'QTY3'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'DUMMY'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
wa_fieldcat-no_out = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = it_events
EXCEPTIONS
list_type_wrong = 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.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF. -
Hi,
can anybody explain the concepts of Internal table and work area.Thanks in advance.hai,
This may help u.
WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.
Each row in a table is a record and each column is a field.
While adding or retrieving records to / from internal table we have to keep the record temporarily.
The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
e.g.
data: begin of itab occurs 10,
ab type c,
cd type i,
end of itab. " this table will have the header line.
data: wa_itab like itab. " explicit work area for itab
data: itab1 like itab occurs 10. " table is without header line.
Internal tables are used for storing records which are obtained as a result when we use select statement on database. internal tables are run time entities and doesn't occupy any memory. they are dynamic.
internal tables are of types.
1. internal tables with header line. [header and body]
2. internal tables with out header line. [only body]
Workarea is the concept which is mainly useful when working with internal tables with out header line.
at any point of time we can access only one record through header of a internal table. every thing should be done [inserting,modifying, reading ] through header only.
ex: data: itab like standard table of mara with header line.
for internal tables with out header line we will create a work area [explicit header] as type of table for storing data into internal table.
ex: data: itab like mara,
wa like mara.
more about internal table types:
Standard table:
The key access to a standard table uses a sequential search. The time required for an access is linearly dependent on the number of entries in the internal table.
You should usually access a standard table with index operations.
Sorted table:
The table is always stored internally sorted by its key. Key access to a sorted table can therefore use a binary search. If the key is not unique, the entry with the lowest index is accessed. The time required for an access is logarithmically dependent on the number of entries in the internal table.
Index accesses to sorted tables are also allowed. You should usually access a sorted table using its key.
Hash table:
The table is internally managed with a hash procedure. All the entries must have a unique key. The time required for a key access is constant, that is it does not depend on the number of entries in the internal table.
You cannot access a hash table with an index. Accesses must use generic key operations (SORT, LOOP, etc.).
Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index.
The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always
have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for
processing large amounts of data.
TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
DATA ITAB TYPE HASHED TABLE OF SPFLI
WITH UNIQUE KEY CARRID CONNID.
with regards,
B.Sowjanya,
reward points if helpful. -
Need information about Internal Tables
Hi Every one!
I Need some information about Internal tables. Pls help be above the same.
Thanks & with Regards,
Chandra.Hi..,
<b>
Internal tables </b>
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for storing and formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program.
Like all elements in the ABAP type concept, internal tables can exist both as data types and as data objects A data type is the abstract description of an internal table, either in a program or centrally in the ABAP Dictionary, that you use to create a concrete data object. The data type is also an attribute of an existing data object.
<b>Internal Tables as Data Types</b>
Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type, key, and table type.
<b>Line type</b>
The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the structure is a column in the internal table. However, the line type may also be elementary or another internal table.
<b>Key</b>
The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.
If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.
<b>
Table type</b>
The table type determines how ABAP will access individual table entries. Internal tables can be divided into three types:
<u>Standard tables</u> have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries.
<u>
Sorted tables</u> are always saved sorted by the key. They also have an internal index. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique or non-unique. When you define the table, you must specify whether the key is to be unique or not. Standard tables and sorted tables are known generically as index tables.
<u>
Hashed tables</u> have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique. When you define the table, you must specify the key as UNIQUE.
<b>
Generic Internal Tables</b>
Unlike other local data types in programs, you do not have to specify the data type of an internal table fully. Instead, you can specify a generic construction, that is, the key or key and line type of an internal table data type may remain unspecified. You can use generic internal tables to specify the types of field symbols and the interface parameters of procedures . You cannot use them to declare data objects.
<b>Internal Tables as Dynamic Data Objects</b>
Data objects that are defined either with the data type of an internal table, or directly as an internal table, are always fully defined in respect of their line type, key and access method. However, the number of lines is not fixed. Thus internal tables are dynamic data objects, since they can contain any number of lines of a particular type. The only restriction on the number of lines an internal table may contain are the limits of your system installation. The maximum memory that can be occupied by an internal table (including its internal administration) is 2 gigabytes. A more realistic figure is up to 500 megabytes. An additional restriction for hashed tables is that they may not contain more than 2 million entries. The line types of internal tables can be any ABAP data types - elementary, structured, or internal tables. The individual lines of an internal table are called table lines or table entries. Each component of a structured line is called a column in the internal table.
<b>
Choosing a Table Type</b>
The table type (and particularly the access method) that you will use depends on how the typical internal table operations will be most frequently executed.
<b>
Standard tables</b>
This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.
<b>Sorted tables</b>
This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.
<b>
Hashed tables</b>
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.
regards,
sai ramesh -
Reading data from XML to Internal table
Hi Experts,
I got a requirement to read the data fom xml to internal table.is it possible to store deep internel table data into flat internal tables?my internel table contains 4 internel table and these 4 internel table contains 2 internel tables each...can any one help me o this...
points will be rewarded...
Regards,
RakhiHi Rakhi,
* Structure to Get the Client Details as in XML format
DATA: BEGIN OF client,
BEGIN OF Personal_Details,
kunnr like kna1-kunnr,
name1 like kna1-name1,
adrnr like kna1-adrnr,
END OF Personal_Details,
BEGIN OF Address,
street like adrc-street,
city1 like adrc-city1,
END OF Address,
BEGIN OF Communication,
fax_number like adrc-fax_number,
tel_number like adrc-tel_number,
END OF Communication,
END OF client.
DATA: it_client TYPE TABLE OF client WITH HEADER LINES,
result LIKE client.
DATA: xml_string TYPE string.
* Get the Client Details into the structure to be made as an XML string
TRY.
* Convert the Structure to XML string
CALL TRANSFORMATION ('ID')
SOURCE para = it_client
RESULT XML xml_string.
* Convert the XML string to structure - result
CALL TRANSFORMATION ('ID')
SOURCE XML xml_string
RESULT para = result.
CATCH cx_st_error.
ENDTRY.
best regards,
Thangesh -
How to convert a data set into a xml data and vice versa
i am new to oracle with xml..
my aim is to convert a data set into a xml data and vice versa..
my work is as follows...
my query:
select rggpk,rggcode,rggname from ms_regiongeo
to convert a data set into a xml*
select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual;
(this works fine and output of this query is as follows..)
<ROWSET>
<ROW>
<RGGPK>201</RGGPK>
<RGGCODE>Asia</RGGCODE>
<RGGNAME>Asia</RGGNAME>
</ROW>
<ROW>
<RGGPK>1</RGGPK>
<RGGCODE>OTH</RGGCODE>
<RGGNAME>Others</RGGNAME>
</ROW>
<ROW>
<RGGPK>21</RGGPK>
<RGGCODE>COB</RGGCODE>
<RGGNAME>Africa and Yemen</RGGNAME>
</ROW>
<ROW>
<RGGPK>2</RGGPK>
<RGGCODE>AUS</RGGCODE>
<RGGNAME>Australia</RGGNAME>
</ROW>
<ROW>
<RGGPK>23</RGGPK>
<RGGCODE>IND</RGGCODE>
<RGGNAME>Indian Sub Continent</RGGNAME>
</ROW>
<ROW>
<RGGPK>24</RGGPK>
<RGGCODE>TVM</RGGCODE>
<RGGNAME>North America</RGGNAME>
</ROW>
</ROWSET>
and to reverse this process, I tried a query like this..*
select EXTRACTVALUE (XML_DATA,'ROWSET/ROW/RGGPK') as EMP_ID
from(
select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual
)tab1but failed.. and raised with an eror: ORA-19025
help me..
regards,
johnHi-
my aim is to convert a data set into a xml data You can refer to the below posts
Adding namespace to XML output
Re: how to convert table data in xml format based on the xsd. -
Dynamic internal table and dynamic read statements.
Hi,
My Scenario :
I have two dynamic internal tables.
I am looping at one internal table and trying to read another table.
In the read statement how do I mention the key dyamically.
Example code below :
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
read second dynamic internal table.
enloop.
The key which I want use for reading say it is keyed in the selection criteria....
Also based on the value I read I want to modify the first internal table field value.
Remember I dont want to explicity mention the key
How do I do that?
Thanks
Krishna.Hi
U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA2> TO <FS>.
CHECK <FS> IN (=) .......
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA> TO <FS2>.
<FS2> = .......
EXIT.
ENDLOOP.
ENDLOOP.
Max -
Hi,
I am a beginer. I know how to create a structure and how to create an internal table using ABAP/4. My problem is, i don't understand where to use internal table and structure, also i find myself very confused about the explicit work areas.
Plese someone show me a program by explaining all of this clearly.Hi
Internal tables are the core of ABAP. They are like soul of a body. For any program we use
internal tables extensively. We can use Internal tables like normal data base tables only, but the
basic difference is the memory allocated for internal tables is temporary. Once the program is
closed the memory allocated for internal tables will also be out of memory.
But while using the internal tables, there are many performance issues to be considered. i.e which
type of internal table to be used for the program..like standard internal table, hashed internal
table or sorted internal table etc..
Internal tables
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by
line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data
objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables
whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for
storing and formatting data from a database table within a program. They are also a good way of including very complicated data
structures in an ABAP program.
Like all elements in the ABAP type concept, internal tables can exist both as data types and as data objects A data type is the abstract
description of an internal table, either in a program or centrally in the ABAP Dictionary, that you use to create a concrete data object. The
data type is also an attribute of an existing data object.
Internal Tables as Data Types
Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type,
key, and table type.
Line type
The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the
structure is a column in the internal table. However, the line type may also be elementary or another internal table.
Key
The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify
whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness
depends on the table access method.
If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves
internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type
is an internal table, the default key is empty.
The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables
with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember
this, for example, if you intend to sort the table according to the key.
Table type
The table type determines how ABAP will access individual table entries. Internal tables can be divided into three types:
Standard tables have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In
this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access
records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table.
The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled
very quickly, since the system does not have to check whether there are already existing entries.
Sorted tables are always saved sorted by the key. They also have an internal index. The system can access records either by using the
table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system
uses a binary search. The key of a sorted table can be either unique or non-unique. When you define the table, you must specify whether
the key is to be unique or not. Standard tables and sorted tables are known generically as index tables.
Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of
table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique.
When you define the table, you must specify the key as UNIQUE.
Generic Internal Tables
Unlike other local data types in programs, you do not have to specify the data type of an internal table fully. Instead, you can specify a
generic construction, that is, the key or key and line type of an internal table data type may remain unspecified. You can use generic
internal tables to specify the types of field symbols and the interface parameters of procedures . You cannot use them to declare data
objects.
Internal Tables as Dynamic Data Objects
Data objects that are defined either with the data type of an internal table, or directly as an internal table, are always fully defined in
respect of their line type, key and access method. However, the number of lines is not fixed. Thus internal tables are dynamic data objects,
since they can contain any number of lines of a particular type. The only restriction on the number of lines an internal table may contain are
the limits of your system installation. The maximum memory that can be occupied by an internal table (including its internal administration)
is 2 gigabytes. A more realistic figure is up to 500 megabytes. An additional restriction for hashed tables is that they may not contain more
than 2 million entries. The line types of internal tables can be any ABAP data types - elementary, structured, or internal tables. The
individual lines of an internal table are called table lines or table entries. Each component of a structured line is called a column in the
internal table.
Choosing a Table Type
The table type (and particularly the access method) that you will use depends on how the typical internal table operations will be most
frequently executed.
Standard tables
This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest
possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by
specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship
with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in
separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key
access, the response time is logarithmically proportional to the number of table entries.
Sorted tables
This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries
are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add
them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always
uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the
table key in the WHERE condition.
Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index.
The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always
have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for
processing large amounts of data.
Creating Internal Tables
Like other elements in the ABAP type concept, you can declare internal tables as abstract data
types in programs or in the ABAP Dictionary, and then use them to define data objects.
Alternatively, you can define them directly as data objects. When you create an internal table as a
data object, you should ensure that only the administration entry which belongs to an internal
table is declared statically. The minimum size of an internal table is 256 bytes. This is important if an
internal table occurs as a component of an aggregated data object, since even empty internal
tables within tables can lead to high memory usage. (In the next functional release, the size of the
table header for an initial table will be reduced to 8 bytes). Unlike all other ABAP data objects, you
do not have to specify the memory required for an internal table. Table rows are added to and
deleted from the table dynamically at runtime by the various statements for adding and deleting
records.
You can create internal tables in different types.
You can create standard internal table and then make it sort in side the program.
The same way you can change to hashed internal tables also.
There will be some performance issues with regard to standard internal tables/ hashed internal
tables/ sorted internal tables.
Internal table types
This section describes how to define internal tables locally in a program. You can also define internal tables globally as data types in the
ABAP Dictionary.
Like all local data types in programs , you define internal tables using the TYPES statement. If you do not refer to an existing table type
using the TYPE or LIKE addition, you can use the TYPES statement to construct a new local internal table in your program.
TYPES <t> TYPE|LIKE <tabkind> OF <linetype> [WITH <key>]
[INITIAL SIZE <n>].
After TYPE or LIKE, there is no reference to an existing data type. Instead, the type constructor occurs:
<tabkind> OF <linetype> [WITH <key>]
The type constructor defines the table type <tabkind>, the line type <linetype>, and the key <key> of the internal table <t>.
You can, if you wish, allocate an initial amount of memory to the internal table using the INITIAL SIZE addition.
Table type
You can specify the table type <tabkind> as follows:
Generic table types
INDEX TABLE
For creating a generic table type with index access.
ANY TABLE
For creating a fully-generic table type.
Data types defined using generic types can currently only be used for field symbols and for interface parameters in procedures . The generic
type INDEX TABLE includes standard tables and sorted tables. These are the two table types for which index access is allowed. You cannot
pass hashed tables to field symbols or interface parameters defined in this way. The generic type ANY TABLE can represent any table. You
can pass tables of all three types to field symbols and interface parameters defined in this way. However, these field symbols and
parameters will then only allow operations that are possible for all tables, that is, index operations are not allowed.
Fully-Specified Table Types
STANDARD TABLE or TABLE
For creating standard tables.
SORTED TABLE
For creating sorted tables.
HASHED TABLE
For creating hashed tables.
Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for
standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
Line type
For the line type <linetype>, you can specify:
Any data type if you are using the TYPE addition. This can be a predefined ABAP type, a local type in the program, or a data type from the
ABAP Dictionary. If you specify any of the generic elementary types C, N, P, or X, any attributes that you fail to specify (field length, number
of decimal places) are automatically filled with the default values. You cannot specify any other generic types.
Any data object recognized within the program at that point if you are using the LIKE addition. The line type adopts the fully-specified data
type of the data object to which you refer. Except for within classes, you can still use the LIKE addition to refer to database tables and
structures in the ABAP Dictionary (for compatibility reasons).
All of the lines in the internal table have the fully-specified technical attributes of the specified data type.
Key
You can specify the key <key> of an internal table as follows:
[UNIQUE|NON-UNIQUE] KEY <col1> ... <col n>
In tables with a structured line type, all of the components <coli> belong to the key as long as they are not internal tables or references,
and do not contain internal tables or references. Key fields can be nested structures. The substructures are expanded component by
component when you access the table using the key. The system follows the sequence of the key fields.
[UNIQUE|NON-UNIQUE] KEY TABLE LINE
If a table has an elementary line type (C, D, F, I, N, P, T, X), you can define the entire line as the key. If you try this for a table whose line
type is itself a table, a syntax error occurs. If a table has a structured line type, it is possible to specify the entire line as the key. However,
you should remember that this is often not suitable.
[UNIQUE|NON-UNIQUE] DEFAULT KEY
This declares the fields of the default key as the key fields. If the table has a structured line type, the default key contains all non-numeric
columns of the internal table that are not and do not contain references or internal tables. If the table has an elementary line type, the
default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
Specifying a key is optional. If you do not specify a key, the system defines a table type with an arbitrary key. You can only use this to
define the types of field symbols and the interface parameters of procedures . For exceptions, refer to Special Features of Standard Tables.
The optional additions UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can
accept duplicate entries. If you do not specify UNIQUE or NON-UNIQUE for the key, the table type is generic in this respect. As such, it can
only be used for specifying types. When you specify the table type simultaneously, you must note the following restrictions:
You cannot use the UNIQUE addition for standard tables. The system always generates the NON-UNIQUE addition automatically.
You must always specify the UNIQUE option when you create a hashed table.
Initial Memory Requirement
You can specify the initial amount of main memory assigned to an internal table object when you define the data type using the following
addition:
INITIAL SIZE <n>
This size does not belong to the data type of the internal table, and does not affect the type check. You can use the above addition to
reserve memory space for <n> table lines when you declare the table object.
When this initial area is full, the system makes twice as much extra space available up to a limit of 8KB. Further memory areas of 12KB each
are then allocated.
You can usually leave it to the system to work out the initial memory requirement. The first time you fill the table, little memory is used. The
space occupied, depending on the line width, is 16 <= <n> <= 100.
It only makes sense to specify a concrete value of <n> if you can specify a precise number of table entries when you create the table and
need to allocate exactly that amount of memory (exception: Appending table lines to ranked lists). This can be particularly important for
deep-structured internal tables where the inner table only has a few entries (less than 5, for example).
To avoid excessive requests for memory, large values of <n> are treated as follows: The largest possible value of <n> is 8KB divided by the
length of the line. If you specify a larger value of <n>, the system calculates a new value so that n times the line width is around 12KB.
Examples
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
The program defines a table type ITAB. It is a sorted table, with line type of the structure LINE and a unique key of the component
COLUMN1.
TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
TYPES: BEGIN OF DEEPLINE,
FIELD TYPE C,
TABLE1 TYPE VECTOR,
TABLE2 TYPE ITAB,
END OF DEEPLINE.
TYPES DEEPTABLE TYPE STANDARD TABLE OF DEEPLINE
WITH DEFAULT KEY.
The program defines a table type VECTOR with type hashed table, the elementary line type I and a unique key of the entire table line. The
second table type is the same as in the previous example. The structure DEEPLINE contains the internal table as a component. The table
type DEEPTABLE has the line type DEEPLINE. Therefore, the elements of this internal table are themselves internal tables. The key is the
default key - in this case the column FIELD. The key is non-unique, since the table is a standard table.
Internal table objects
Internal tables are dynamic variable data objects. Like all variables, you declare them using the DATA statement. You can also declare static
internal tables in procedures using the STATICS statement, and static internal tables in classes using the CLASS-DATA statement. This
description is restricted to the DATA statement. However, it applies equally to the STATICS and CLASS-DATA statements.
Reference to Declared Internal Table Types
Like all other data objects, you can declare internal table objects using the LIKE or TYPE addition of the DATA statement.
DATA <itab> TYPE <type>|LIKE <obj> [WITH HEADER LINE].
Here, the LIKE addition refers to an existing table object in the same program. The TYPE addition can refer to an internal type in the
program declared using the TYPES statement, or a table type in the ABAP Dictionary.
You must ensure that you only refer to tables that are fully typed. Referring to generic table types (ANY TABLE, INDEX TABLE) or not
specifying the key fully is not allowed (for exceptions, refer to Special Features of Standard Tables).
The optional addition WITH HEADER line declares an extra data object with the same name and line type as the internal table. This data
object is known as the header line of the internal table. You use it as a work area when working with the internal table (see Using the
Header Line as a Work Area). When you use internal tables with header lines, you must remember that the header line and the body of the
table have the same name. If you have an internal table with header line and you want to address the body of the table, you must indicate
this by placing brackets after the table name (<itab>[]). Otherwise, ABAP interprets the name as the name of the header line and not of the
body of the table. You can avoid this potential confusion by using internal tables without header lines. In particular, internal tables nested
in structures or other internal tables must not have a header line, since this can lead to ambiguous expressions.
TYPES VECTOR TYPE SORTED TABLE OF I WITH UNIQUE KEY TABLE LINE.
DATA: ITAB TYPE VECTOR,
JTAB LIKE ITAB WITH HEADER LINE.
MOVE ITAB TO JTAB. <- Syntax error!
MOVE ITAB TO JTAB[].
The table object ITAB is created with reference to the table type VECTOR. The table object JTAB has the same data type as ITAB. JTAB also
has a header line. In the first MOVE statement, JTAB addresses the header line. Since this has the data type I, and the table type of ITAB
cannot be converted into an elementary type, the MOVE statement causes a syntax error. The second MOVE statement is correct, since
both operands are table objects.
Declaring New Internal Tables
You can use the DATA statement to construct new internal tables as well as using the LIKE or TYPE addition to refer to existing types or
objects. The table type that you construct does not exist in its own right; instead, it is only an attribute of the table object. You can refer to
it using the LIKE addition, but not using TYPE. The syntax for constructing a table object in the DATA statement is similar to that for defining
a table type in the TYPES statement.
DATA <itab> TYPE|LIKE <tabkind> OF <linetype> WITH <key>
[INITIAL SIZE <n>]
[WITH HEADER LINE].
As when you define a table type , the type constructor
<tabkind> OF <linetype> WITH <key>
defines the table type <tabkind>, the line type <linekind>, and the key <key> of the internal table <itab>. Since the technical attributes of
data objects are always fully specified, the table must be fully specified in the DATA statement. You cannot create generic table types (ANY
TABLE, INDEX TABLE), only fully-typed tables (STANDARD TABLE, SORTED TABLE, HASHED TABLE). You must also specify the key and whether
it is to be unique (for exceptions, refer to Special Features of Standard Tables).
As in the TYPES statement, you can, if you wish, allocate an initial amount of memory to the internal table using the INITIAL SIZE addition.
You can create an internal table with a header line using the WITH HEADER LINE addition. The header line is created under the same
conditions as apply when you refer to an existing table type.
DATA ITAB TYPE HASHED TABLE OF SPFLI
WITH UNIQUE KEY CARRID CONNID.
The table object ITAB has the type hashed table, a line type corresponding to the flat structure SPFLI from the ABAP Dictionary, and a
unique key with the key fields CARRID and CONNID. The internal table ITAB can be regarded as an internal template for the database table
SPFLI. It is therefore particularly suitable for working with data from this database table as long as you only access it using the key. -
Simple transformation error in converting XML to internal table
Hi Team,
I have an issue, its working in Dev, QA, and Prod in PI 7.0, once we upgrade it to PI 7.1 I'm getting the below mention error,
Unknown Simple transformation error in converting XML to internal table
Application error in mapping program ZF_INT006_FILE_TO_SAP_FILE, error code: , error text: Unknown Simple transformation error in converting XML to internal table An exception has occurred.
Can any one suggest related notes are suggestion.
appericate in advance for the solutions which you all provide me
Thank you
Venkat AnilCheck the flag "use SAP XML toolkit" for the operation mapping and try, if that works then.
Check the flag for all XSLT and Java mappings which is migrated from PI 7.0
Maybe you are looking for
-
When oraInst.loc file is created during installation on linux ?
* QUES during installation :* Is this really true ? When executing orainstRoot.sh , It creates the inventory pointer file (/etc/oraInst.loc). In my case , " the file was created before executing orainstRoot.sh " + As far as I know , end of the ins
-
How to change data type from Integer to Double?
In a data set, BIP treat Oracle number type column as Integer. How to change it to double?
-
Appv package on RDS resource utilisation
are there any resource utilization advantages of using APPV Package on RDS server vs native application installation on RDS. Example: The app that requires 100K of memory. There are 30 simultaneous connection to the app. Would the memory utilization
-
ESourcing post installation problem
Hi, I am installing ESourcing 5.1 on NW04s SR2 on windows IA 32 machine. I have installed Netweaver app server and esourcing successfully. I am facing issue while running dbimport file. (as part of step 1 of post installation procedure) Script is sho
-
Value attribute of command_link
Hi, Hope someone can help me out. When you specify a value for the value attribute of the command_link tag does this value ever get sent to the user's browser or does it stay server side in a table referenced to that specific user? Sorry if this is a