Help to upload xml file to internal table
hi all,
i am still stuck at the same issue , please try to help to resolve this issue.
thanks in advance
report zmybapi1 .
data : my_order_header_in like bapisdhd1 occurs 0 with header line,
my_order_header_ix like bapisdhd1x occurs 0 with header line.
data : my_orderitemsin like bapisditm occurs 0 with header line,
my_orderitemsix like bapisditmx occurs 0 with header line.
data : my_order_partners like bapiparnr occurs 0 with header line.
data : my_return like bapiret2 occurs 0 with header line.
data : w_vbeln like bapivbeln-vbeln.
data:
my_orderschedulesin like bapischdl occurs 0 with header line,
my_orderschedulesinx like bapischdlx occurs 0 with header line.
data : my_orderconditionsin like bapicond occurs 0 with header line,
my_orderconditionsinx like bapicondx occurs 0 with header line.
start-of-selection.
this is to assign values to internal table my_order_header_in
my_order_header_in-doc_type = 'TA'.
my_order_header_in-sales_org = 'JNJ1'.
my_order_header_in-distr_chan = '02'.
my_order_header_in-division = 'J1'.
my_order_header_in-sales_off = 'JNJ1'.
my_order_header_in-purch_no_c = 'testbapipo'.
my_order_header_in-purch_date = sy-datum.
my_order_header_in-req_date_h = sy-datum.
append my_order_header_in.
this is to assign values to internal table my_orderitemsin
my_orderitemsin-material = '000000000000000727'.
my_orderitemsin-plant = 'JNJ1'.
my_orderitemsin-target_qu = 'EA'.
my_orderitemsin-target_qty = '10'.
append my_orderitemsin.
this is to assign values to internal table my_order_partners
my_order_partners-partn_role = 'AG'.
my_order_partners-partn_numb = '0000000011'.
append my_order_partners.
my_order_partners-partn_role = 'WE'.
my_order_partners-partn_numb = '0000000011'.
append my_order_partners.
This is to assign values to internal table my_orderschedulesin
my_orderschedulesin-itm_number = '10'.
my_orderschedulesin-req_qty = '10'.
my_orderschedulesin-SCHED_LINE = '0001'.
append my_orderschedulesin.
*This is to assign values to internal table my_orderconditionin
my_orderconditionsin-cond_type = 'ZPR1'.
my_orderconditionsin-cond_value = '40.00'.
append my_orderconditionsin.
my_order_header_ix-updateflag = 'I'.
my_order_header_ix-doc_type = 'X'.
my_order_header_ix-sales_org = 'X'.
my_order_header_ix-distr_chan = 'X'.
my_order_header_ix-division = 'X'.
my_order_header_ix-sales_off = 'X'.
my_order_header_ix-purch_no_c = 'X'.
my_order_header_ix-purch_date = 'X'.
my_order_header_ix-req_date_h = 'X'.
append my_order_header_ix.
my_orderitemsix-updateflag = 'I'.
my_orderitemsix-material = 'X'.
my_orderitemsix-target_qty = 'X'.
my_orderitemsix-plant = 'X'.
my_orderitemsix-target_qu = 'X'.
append my_orderitemsix.
my_orderschedulesinx-updateflag = 'I'.
my_orderschedulesinx-sched_line = '0001'.
my_orderschedulesinx-req_qty = 'x'.
append my_orderschedulesinx.
my_orderconditionsinx-updateflag = 'U'.
my_orderconditionsinx-cond_type = 'X'.
my_orderconditionsinx-cond_value = 'X'.
append my_orderconditionsinx.
call function 'BAPI_SALESORDER_CREATEFROMDAT2'
exporting
SALESDOCUMENTIN =
order_header_in = my_order_header_in
order_header_inx = my_order_header_ix
SENDER =
BINARY_RELATIONSHIPTYPE =
INT_NUMBER_ASSIGNMENT =
BEHAVE_WHEN_ERROR =
LOGIC_SWITCH =
TESTRUN =
CONVERT = ' '
importing
salesdocument = w_vbeln
tables
return = my_return
order_items_in = my_orderitemsin
order_items_inx = my_orderitemsix
order_partners = my_order_partners
ORDER_SCHEDULES_IN = my_orderschedulesin
order_schedules_inx = my_orderschedulesinx
ORDER_CONDITIONS_IN = my_orderconditionsin
ORDER_CONDITIONS_INX = my_orderconditionsinx
ORDER_CFGS_REF =
if sy-subrc ne 0.
write: my_return-message, my_return-number, my_return-type.
else.
call function 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
write: my_return-message, my_return-number, my_return-type.
endif.
regards,
pavan
Hi,
is your question is related to upload xls fiel to ITAB.if so you can check this link , here you can find 3 examples..
http://www.sapdevelopment.co.uk/file/file_upexcel.htm
http://www.sapdevelopment.co.uk/file/file_upexcelalt1.htm
http://www.sapdevelopment.co.uk/file/file_upexcelalt2.htm
Regards
vijay
Similar Messages
-
Simple Transformation ST, upload xml file to internal table
Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens?Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens? -
Upload xml file to internal table only using simple transformation
Hi Friends
How to write transformation code for the following xml data.. Please let me know immedately if any one know..
I have written as following but i encountered an eror staating -
Iam facing the following error
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_ST_REF_ACCESS', was not caught in
procedure "UPLOAD_XML" "(FORM)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The goal was to access variable "ROOT1". However, this access was not
possible.
Go through my xml file , the code and code in simple transformation.. Please reply(transformation code) me as soon as possible
- <Negara>
- <item>
- <COUNTRY>
<MANDT>600</MANDT>
<ZCODE>500</ZCODE>
<ZDESC>Pening Lalat</ZDESC>
<ZSAPCD>T1</ZSAPCD>
</COUNTRY>
</item>
- <item>
- <COUNTRY>
<MANDT>600</MANDT>
<ZCODE>600</ZCODE>
<ZDESC>Pening Lalat2</ZDESC>
<ZSAPCD>T2</ZSAPCD>
</COUNTRY>
</item>
</Negara>
DATA : BEGIN OF XDATA OCCURS 0,
STR(255) TYPE C,
END OF XDATA.
DATA: XMLUPL TYPE string .
DATA : BEGIN OF ITAB OCCURS 0,
MANDT(3) TYPE C,
ZCODE(3) TYPE C,
ZDESC(15) TYPE C,
ZSAPCD(2) TYPE C,
END OF ITAB.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\country.xml'
FILETYPE = 'BIN'
TABLES
DATA_TAB = XDATA.
LOOP AT XDATA.
CONCATENATE XMLUPL XDATA-STR INTO XMLUPL.
ENDLOOP.
CALL TRANSFORMATION ('Y_XMLCTRY')
SOURCE XML XMLUPL
result xml = ITAB[].
BREAK-POINT.
<?sap.transform simple?>
<tt:transform template="temp1"
xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT1"/>
<tt:root name="ROOT2"/>
<tt:template name="temp1">
<Negara>
<tt:loop ref=".ROOT1" name="i">
<item>
<tt:loop ref=".ROOT2" name="c">
<COUNTRY>
<MANDT>
<tt:value ref="$c.nummer" />
</MANDT>
<ZCODE>
<tt:value ref="$c.nummer" />
</ZCODE>
<ZDESC>
<tt:value ref="$c.name" />
</ZDESC>
<ZSAPCD>
<tt:value ref="$c.name" />
</ZSAPCD>
</COUNTRY>
</tt:loop>
</item>
</tt:loop>
</Negara>
</tt:template>
</tt:transform>
Thanking You
DeviHi Friends
How to write transformation code for the following xml data.. Please let me know immedately if any one know..
I have written as following but i encountered an eror staating -
Iam facing the following error
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_ST_REF_ACCESS', was not caught in
procedure "UPLOAD_XML" "(FORM)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The goal was to access variable "ROOT1". However, this access was not
possible.
Go through my xml file , the code and code in simple transformation.. Please reply(transformation code) me as soon as possible
- <Negara>
- <item>
- <COUNTRY>
<MANDT>600</MANDT>
<ZCODE>500</ZCODE>
<ZDESC>Pening Lalat</ZDESC>
<ZSAPCD>T1</ZSAPCD>
</COUNTRY>
</item>
- <item>
- <COUNTRY>
<MANDT>600</MANDT>
<ZCODE>600</ZCODE>
<ZDESC>Pening Lalat2</ZDESC>
<ZSAPCD>T2</ZSAPCD>
</COUNTRY>
</item>
</Negara>
DATA : BEGIN OF XDATA OCCURS 0,
STR(255) TYPE C,
END OF XDATA.
DATA: XMLUPL TYPE string .
DATA : BEGIN OF ITAB OCCURS 0,
MANDT(3) TYPE C,
ZCODE(3) TYPE C,
ZDESC(15) TYPE C,
ZSAPCD(2) TYPE C,
END OF ITAB.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\country.xml'
FILETYPE = 'BIN'
TABLES
DATA_TAB = XDATA.
LOOP AT XDATA.
CONCATENATE XMLUPL XDATA-STR INTO XMLUPL.
ENDLOOP.
CALL TRANSFORMATION ('Y_XMLCTRY')
SOURCE XML XMLUPL
result xml = ITAB[].
BREAK-POINT.
<?sap.transform simple?>
<tt:transform template="temp1"
xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT1"/>
<tt:root name="ROOT2"/>
<tt:template name="temp1">
<Negara>
<tt:loop ref=".ROOT1" name="i">
<item>
<tt:loop ref=".ROOT2" name="c">
<COUNTRY>
<MANDT>
<tt:value ref="$c.nummer" />
</MANDT>
<ZCODE>
<tt:value ref="$c.nummer" />
</ZCODE>
<ZDESC>
<tt:value ref="$c.name" />
</ZDESC>
<ZSAPCD>
<tt:value ref="$c.name" />
</ZSAPCD>
</COUNTRY>
</tt:loop>
</item>
</tt:loop>
</Negara>
</tt:template>
</tt:transform>
Thanking You
Devi -
Problem converting data in XML file to internal table data
Hi all,
I have a requirement. I need to convert an XML file to internal table data and based on that data do Goods Receipt in SAP.
With the help of this 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
I am able to convert the XML file to data in SAP. But this blog will display the output on screen as ELELEMNT = nodename VALUE= value of that node.
But I donu2019t want in that way, I want to store all the data in XML file in an internal table so that I can make use of those values and do Goods Recipt in SAP.
Can some one suggest how should I read the data in an internal table.
Here is my code..what changes should I make?
*& Report z_xit_xml_check
REPORT z_xit_xml_check.
TYPE-POOLS: ixml.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
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 'c:\temp\orders_dtd.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( ).
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.
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.
ENDFORM. "process_dom
Any help would be highly apperciated.
regards,
Jessica SamPavel Vera,
With your example i tries doing the following .....
I tried to convert the data of XML file to internal table data. I am collecting the data in internal table to do goos recipt with that data.
Please find my XML file, ABAP pgm and XSLT pgm . I donu2019t know what I am missing I am not getting any output. I donu2019t know what is wrong please help me with this
Below is my XML file, My code and XSLT Program. In the below XML file I need to collect Vendor Number, Order Number, and Date tags which occur only once for one XML file.
I also need to collect the following tags from <Shipmentdetail>
<Shipmentdetail> has following child nodes and I need to collect them
TrackingNumber
Freight
Weight
ShipmentDate
ShipmentMethod
Need to collect to collect the following tags from <ProductInformation>
<ProductInformation> has following child nodes and I need to collect them
LineNumber
SKUNumber
OrderedQuantity
ShippedQuantity
UOM
The <Shipmentdetail> and <ProductInformation> are child nodes of <OrderShipment>
The <Shipmentdetail> occurs only ones but the <ProductInformation> can occur once or many times and will be dynamic and differs depening on the input file.
My XML file is as follows
<?xml version="1.0" encoding="iso-8859-1" ?>
- <ShipmentHeader>
<AccountID />
- <OrderShipment>
<VendorNumber>1000</VendorNumber>
<OrderNumber>P00009238</OrderNumber>
<OrderType>Stock</OrderType>
<Company />
<Division />
<Department />
<Date>20061120</Date>
<CartonCount>2</CartonCount>
<ShipAllProducts>No</ShipAllProducts>
- <ShipmentDetail>
<TrackingNumber>1ZR3W891PG47477811</TrackingNumber>
<Freight>000000010000</Freight>
<ShipmentDate>20061120</ShipmentDate>
<ShipmentMethod>UPS1PS</ShipmentMethod>
</ShipmentDetail>
- <ProductInformation>
<LineNumber>000000001</LineNumber>
<SKUNumber>110FR</SKUNumber>
<AdvSKUNumber>003 4518</AdvSKUNumber>
<SKUID />
<OrderedQuantity>00000001000000</OrderedQuantity>
<ShippedQuantity>00000001000000</ShippedQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</ProductInformation>
- <ProductInformation>
<LineNumber>000000002</LineNumber>
<SKUNumber>938EN</SKUNumber>
<AdvSKUNumber>001 7294</AdvSKUNumber>
<SKUID />
<OrderedQuantity>00000000450000</OrderedQuantity>
<ShippedQuantity>00000000450000</ShippedQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</ProductInformation>
- <CaseInformation>
<LineNumber>000000001</LineNumber>
<SKUNumber>110FR</SKUNumber>
<AdvSKUNumber>003 4518</AdvSKUNumber>
<SKUID />
<SSCCNumber>00000001668000002487</SSCCNumber>
<CaseQuantity>00000001000000</CaseQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</CaseInformation>
<CaseInformation>
<LineNumber>000000001</LineNumber>
<SKUNumber>110FR</SKUNumber>
<AdvSKUNumber>003 4518</AdvSKUNumber>
<SKUID />
<SSCCNumber>00000001668000002487</SSCCNumber>
<CaseQuantity>00000001000000</CaseQuantity>
<UOM>EA</UOM>
<Factor>1</Factor>
</CaseInformation>
- </OrderShipment>
</ShipmentHeader>
My Program
TYPE-POOLS abap.
CONSTANTS gs_file TYPE string VALUE 'C:\temp\test.xml'.
* This is the structure for the data from the XML file
TYPES: BEGIN OF ts_shipment,
VendorNumber(10) TYPE n,
OrderNumber(20) TYPE n,
OrderType(8) TYPE c,
Date(8) TYPE c,
END OF ts_shipment.
TYPES: BEGIN OF ts_shipmentdetail,
TrackingNumber(30) TYPE n,
Freight(12) TYPE n,
Weight(14) TYPE n,
ShipmentDate(8) TYPE c,
ShipmentMethod(8) TYPE c,
END OF ts_shipmentdetail.
TYPES: BEGIN OF ts_productinformation,
LineNumber(9) TYPE n,
SKUNumber(20) TYPE c,
OrderedQuantity(14) TYPE n,
ShippedQuantity(14) TYPE n,
UOM(4) TYPE c,
END OF ts_productinformation.
* Table for the XML content
DATA: gt_itab TYPE STANDARD TABLE OF char2048.
* Table and work ares for the data from the XML file
DATA: gt_shipment TYPE STANDARD TABLE OF ts_shipment,
gs_shipment TYPE ts_shipment.
DATA: gt_shipmentdetail TYPE STANDARD TABLE OF ts_shipmentdetail,
gs_shipmentdetail TYPE ts_shipmentdetail.
DATA: gt_productinformation TYPE STANDARD TABLE OF ts_productinformation,
gs_productinformation TYPE ts_productinformation.
* Result table that contains references
* of the internal tables to be filled
DATA: gt_result_xml TYPE abap_trans_resbind_tab,
gs_result_xml TYPE abap_trans_resbind.
* For error handling
DATA: gs_rif_ex TYPE REF TO cx_root,
gs_var_text TYPE string.
* Get the XML file from your client
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gs_file
CHANGING
data_tab = gt_itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
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.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "ISHIPMENT".
GET REFERENCE OF gt_shipment INTO gs_result_xml-value.
gs_result_xml-name = 'ISHIPMENT'.
APPEND gs_result_xml TO gt_result_xml.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "ISHIPDET".
GET REFERENCE OF gt_shipmentdetail INTO gs_result_xml-value.
gs_result_xml-name = 'ISHIPDET'.
APPEND gs_result_xml TO gt_result_xml.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "IPRODDET".
GET REFERENCE OF gt_productinformation INTO gs_result_xml-value.
gs_result_xml-name = 'IPRODDET'.
APPEND gs_result_xml TO gt_result_xml.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION z_xml_to_abap3
SOURCE XML gt_itab
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
* Writing the data from file for gt_shipment
*Collecting the Shipping Data from the XML file to internal table gt_shipment
*and writing the data to the screen
LOOP AT gt_shipment INTO gs_shipment.
WRITE: / 'VendorNumber:', gs_shipment-VendorNumber.
WRITE: / 'OrderNumber :', gs_shipment-OrderNumber.
WRITE: / 'OrderType :', gs_shipment-OrderType.
WRITE: / 'Date :', gs_shipment-Date.
WRITE : /.
ENDLOOP. "gt_shipment.
LOOP AT gt_shipmentdetail INTO gs_shipmentdetail.
WRITE: / 'TrackingNumber:', gs_shipmentdetail-TrackingNumber.
WRITE: / 'Freight :', gs_shipmentdetail-Freight.
WRITE: / 'Weight :', gs_shipmentdetail-Weight.
WRITE: / 'ShipmentDate :', gs_shipmentdetail-ShipmentDate.
* WRITE: / 'ShipmentMethod :' gs_shipmentdetail-ShipmentMethod
WRITE : /.
ENDLOOP. "gt_shipmentdetail.
LOOP AT gt_productinformation INTO gs_productinformation.
WRITE: / 'LineNumber:', gs_productinformation-LineNumber.
WRITE: / 'SKUNumber :', gs_productinformation-SKUNumber.
WRITE: / 'OrderedQuantity :', gs_productinformation-OrderedQuantity.
WRITE: / 'ShippedQuantity :', gs_productinformation-ShippedQuantity.
WRITE: / 'UOM :', gs_productinformation-UOM.
WRITE : /.
ENDLOOP. "gt_productinformation.
XSLT Program
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ISHIPMENT>
<xsl:apply-templates select="//OrderShipment"/>
</ISHIPMENT>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="OrderShipment">
<item>
<VENDORNUMBER>
<xsl:value-of select="VendorNumber"/>
</VENDORNUMBER>
<ORDERNUMBER>
<xsl:value-of select="OrderNumber"/>
</ORDERNUMBER>
<ORDERTYPE>
<xsl:value-of select="OrderType"/>
</ORDERTYPE>
<DATE>
<xsl:value-of select="Date"/>
</DATE>
</item>
</xsl:template>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ISHIPDET>
<xsl:apply-templates select="//OrderShipment/ShipmentDetail"/>
</ISHIPDET>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="ShipmentDetail">
<item>
<TRACKINGNUMBER>
<xsl:value-of select="TrackingNumber"/>
</TRACKINGNUMBER>
<FREIGHT>
<xsl:value-of select="Freight"/>
</FREIGHT>
<SHIPMENTDATE>
<xsl:value-of select="ShipmentDate"/>
</SHIPMENTDATE>
<SHIPMENTMETHOD>
<xsl:value-of select="ShipmentMethod"/>
</SHIPMENTMETHOD>
</item>
</xsl:template>
</xsl:transform> .
Any help is highly appreciated. If anyone encountered this situation before please let me know where i am going wrong in my XSLT transformation.
Any Help will be highly apppreciated. Thanks in advance
Regards,
Jessica Sam -
How to Download XML File to internal table
Hi Friends,
This is my urgent requirement. How to download XML File to Internal table.
regards
pauldharmaHai,
Please check this Link
http://www.sap-img.com/abap/upload-direct-excel.htm
PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
begcol TYPE i DEFAULT 1 NO-DISPLAY,
begrow TYPE i DEFAULT 1 NO-DISPLAY,
endcol TYPE i DEFAULT 100 NO-DISPLAY,
endrow TYPE i DEFAULT 32000 NO-DISPLAY.
* Tick don't append header
PARAMETERS: kzheader AS CHECKBOX.
DATA: BEGIN OF intern OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF intern.
DATA: BEGIN OF intern1 OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF intern1.
DATA: BEGIN OF t_col OCCURS 0,
col LIKE alsmex_tabline-col,
size TYPE i.
DATA: END OF t_col.
DATA: zwlen TYPE i,
zwlines TYPE i.
DATA: BEGIN OF fieldnames OCCURS 3,
title(60),
table(6),
field(10),
kz(1),
END OF fieldnames.
* No of columns
DATA: BEGIN OF data_tab OCCURS 0,
value_0001(50),
value_0002(50),
value_0003(50),
value_0004(50),
value_0005(50),
value_0006(50),
value_0007(50),
value_0008(50),
value_0009(50),
value_0010(50),
value_0011(50),
value_0012(50),
value_0013(50),
value_0014(50),
value_0015(50),
value_0016(50),
value_0017(50),
value_0018(50),
value_0019(50),
value_0020(50),
value_0021(50),
value_0022(50),
value_0023(50),
value_0024(50),
value_0025(50),
value_0026(50),
value_0027(50),
value_0028(50),
value_0029(50),
value_0030(50),
value_0031(50),
value_0032(50),
value_0033(50),
value_0034(50),
value_0035(50),
value_0036(50),
value_0037(50),
value_0038(50),
value_0039(50),
value_0040(50),
value_0041(50),
value_0042(50),
value_0043(50),
value_0044(50),
value_0045(50),
value_0046(50),
value_0047(50),
value_0048(50),
value_0049(50),
value_0050(50),
value_0051(50),
value_0052(50),
value_0053(50),
value_0054(50),
value_0055(50),
value_0056(50),
value_0057(50),
value_0058(50),
value_0059(50),
value_0060(50),
value_0061(50),
value_0062(50),
value_0063(50),
value_0064(50),
value_0065(50),
value_0066(50),
value_0067(50),
value_0068(50),
value_0069(50),
value_0070(50),
value_0071(50),
value_0072(50),
value_0073(50),
value_0074(50),
value_0075(50),
value_0076(50),
value_0077(50),
value_0078(50),
value_0079(50),
value_0080(50),
value_0081(50),
value_0082(50),
value_0083(50),
value_0084(50),
value_0085(50),
value_0086(50),
value_0087(50),
value_0088(50),
value_0089(50),
value_0090(50),
value_0091(50),
value_0092(50),
value_0093(50),
value_0094(50),
value_0095(50),
value_0096(50),
value_0097(50),
value_0098(50),
value_0099(50),
value_0100(50).
DATA: END OF data_tab.
DATA: tind(4) TYPE n.
DATA: zwfeld(19).
FIELD-SYMBOLS: <fs1>.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
mask = '*.xls'
static = 'X'
CHANGING
file_name = filename.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filename
i_begin_col = begcol
i_begin_row = begrow
i_end_col = endcol
i_end_row = endrow
TABLES
intern = intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE:/ 'Upload Error ', SY-SUBRC.
ENDIF.
END-OF-SELECTION.
LOOP AT intern.
intern1 = intern.
CLEAR intern1-row.
APPEND intern1.
ENDLOOP.
SORT intern1 BY col.
LOOP AT intern1.
AT NEW col.
t_col-col = intern1-col.
APPEND t_col.
ENDAT.
zwlen = strlen( intern1-value ).
READ TABLE t_col WITH KEY col = intern1-col.
IF sy-subrc EQ 0.
IF zwlen > t_col-size.
t_col-size = zwlen.
* Internal Table, Current Row Index
MODIFY t_col INDEX sy-tabix.
ENDIF.
ENDIF.
ENDLOOP.
DESCRIBE TABLE t_col LINES zwlines.
SORT intern BY row col.
IF kzheader = 'X'.
LOOP AT intern.
fieldnames-title = intern-value.
APPEND fieldnames.
AT END OF row.
EXIT.
ENDAT.
ENDLOOP.
ELSE.
DO zwlines TIMES.
WRITE sy-index TO fieldnames-title.
APPEND fieldnames.
ENDDO.
ENDIF.
SORT intern BY row col.
LOOP AT intern.
IF kzheader = 'X'
AND intern-row = 1.
CONTINUE.
ENDIF.
tind = intern-col.
CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
ASSIGN (zwfeld) TO <fs1>.
<fs1> = intern-value.
AT END OF row.
APPEND data_tab.
CLEAR data_tab.
ENDAT.
ENDLOOP.
CALL FUNCTION 'DISPLAY_BASIC_LIST'
EXPORTING
file_name = filename
TABLES
data_tab = data_tab
fieldname_tab = fieldnames.
*-- End of Program
http://sap.ittoolbox.com/groups/technical-functional/sap-dev/excel-file-download-to-an-internal-table-in-sap-crm-1719453#
tables: zinv_release,
zpo_release.
** decleration of data
DATA: BEGIN OF my_tab OCCURS 0.
INCLUDE STRUCTURE zinv_release.
DATA: END OF my_tab.
*DATA: hex_tab TYPE x VALUE '09'.
DATA: rec(200)."'/usr/test.dat'.
DATA:
zhours(20) TYPE c,
MINS(20) type c. "decimals.
data: coma.
coma = ','.
SELECTION-SCREEN BEGIN OF BLOCK txt
WITH FRAME TITLE text-001.
PARAMETERS: dsn(60) DEFAULT '\\sapdev01\prod\'.
SELECTION-SCREEN END
OF BLOCK txt.
*using a dataset to get text
OPEN DATASET dsn FOR INPUT IN TEXT MODE.
IF sy-subrc = 0.
DO.
READ DATASET dsn INTO rec.
IF sy-subrc <> 0.
EXIT.
ENDIF.
split rec at coma into
zpo_release-REL_GRP
zpo_release-REL_CODE
zpo_release-RESPREL
zpo_release-ALTREL
zpo_release-MANAGER
ZHOURS
MINS
zpo_release-FROMTIME
zpo_release-TOTIME
zpo_release-EXCLWKENDS.
move zpo_release-REL_GRP to my_tab-REL_GRP.
move zpo_release-REL_CODE to my_tab-REL_CODE.
move zpo_release-RESPREL to my_tab-RESPREL.
move zpo_release-ALTREL to my_tab-ALTREL.
move zpo_release-MANAGER to my_tab-MANAGER.
move ZHOURS to my_tab-ZHOURS.
move MINS to my_tab-mins.
move zpo_release-FROMTIME to my_tab-fromtime.
move zpo_release-TOTIME to my_tab-totime.
move zpo_release-EXCLWKENDS to my_tab-exclwkends.
APPEND my_tab.
ENDDO.
INSERT zpo_release FROM TABLE my_tab ACCEPTING DUPLICATE KEYS.
** DELETE zmm_ppa_cc FROM TABLE tab.
** INSERT zzzak_emp FROM TABLE my_tab ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
MESSAGE i000(zv) WITH 'File Successful stored in DB.' '' '' ''.
** ELSE.
MESSAGE i000(zv) WITH 'File already stored in DB.' '' '' ''.
endif.
ENDIF.
reward if helpful
raam -
How to convert xml file into internal table in ABAP Mapping.
Hi All,
I am trying with ABAP mapping. I have one scenario in which I'm using below xml file as a sender from my FTP server.
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:MTO_ABAP_MAPPING xmlns:ns0="http://Capgemini/Mumbai/sarsingh">
<BookingCode>2KY34R</BookingCode>
- <Passenger>
<Name>SARVESH</Name>
<Address>THANE</Address>
</Passenger>
- <Passenger>
<Name>RAJESH</Name>
<Address>POWAI</Address>
</Passenger>
- <Passenger>
<Name>CARRON</Name>
<Address>JUHU</Address>
</Passenger>
- <Flight>
<Date>03/03/07</Date>
<AirlineID>UA</AirlineID>
<FlightNumber>125</FlightNumber>
<From>LAS</From>
<To>SFO</To>
</Flight>
</ns0:MTO_ABAP_MAPPING>
AT the receiver side I wnat to concatenate the NAME & ADDRESS.
I tried Robert Eijpe's weblog (/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach)
but couldnt succeed to convert the xml file into internal table perfectly.
Can anybody help on this.
Thanks in advance!!
SarveshHi Sarvesh,
The pdf has details of ABAP mapping. The example given almost matches the xml file you want to be converted.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/3.0/how to use abap-mapping in xi 3.0.pdf
Just in case you have not seen this
regards
Vijaya -
Upload excel file to internal table in web dynpro program
Hi friend's
In web dynpro program how to upload excel file into internal table and finally data will be save Y table.hi,
See the properties of File Upload UI element..
Link: [http://help.sap.com/saphelp_nw70ehp1/helpdata/en/48/732f0510d83ff6e10000000a42189c/frameset.htm]
Goto References -> User Interface Elements -> Integration Category -> File upload..
After creating the 'FILE UPLOAD' element in a view.. Bind a datasource(a context attribute with STRING) with the data property..
Double click on ONACTION_UPLOAD method. Write a code as given below.
METHOD onactionon_upload .
TYPES : BEGIN OF str_itab,
name(10) TYPE c,
age(10) TYPE c,
END OF str_itab. DATA : t_table1 TYPE STANDARD TABLE OF str_itab,
i_data TYPE STANDARD TABLE OF string,
l_string TYPE string,
fs_table TYPE str_itab,
l_xstring TYPE xstring,
fields TYPE string_table,
lv_field TYPE string.
DATA : t_table TYPE if_main=>elements_data_tab,
data_table TYPE if_main=>elements_data_tab.
* get single attribute
wd_context->get_attribute(
EXPORTING
name = `DATASOURCE`
IMPORTING
value = l_xstring ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.
SPLIT l_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
* Bind With table Element.
LOOP AT i_data INTO l_string.
SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
READ TABLE fields INTO lv_field INDEX 1.
fs_table-name = lv_field.
READ TABLE fields INTO lv_field INDEX 2.
fs_table-age = lv_field.
APPEND fs_table TO t_table1. "Append to the internal table
ENDLOOP.
Edited by: Rameshkumar Raamasamy on Feb 9, 2010 9:39 AM -
Uploading excel file into internal table with field length more than 255
I am trying to upload the data from an excel file through function module 'TEXT_CONVERT_XLS_TO_SAP'.
I have tested by changing the field type from string, and char2000.
But it is accepting only 255 chars from the cell content.
How to get the total content of the field if it is more than 255 char.hi,
you can use any of the following procedures:
For uploading data from excel to internal table refer standard report RC1TCG3Z in se38 :
or
You can use the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' itself. Please check if you have done it this way . But, this FM can be a little time consuming if the excel has large data, so you can use the FM u2018GUI_UPLOADu2019.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file1
i_begin_col = l_b1
i_begin_row = l_c1
i_end_col = l_b2
i_end_row = l_c2
TABLES
intern = lt_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e018 DISPLAY LIKE 'i'.
ENDIF.
*---Removing the first heading fields from the file.
IF NOT lt_data[] IS INITIAL.
LOOP AT lt_data INTO lwa_data WHERE row = '0001'.
DELETE lt_data.
CLEAR lwa_data.
ENDLOOP.
*---Inserting the data from file the internal table
LOOP AT lt_data INTO lwa_data.
CASE lwa_data-col.
WHEN 1.
wa_file_wicopa-serial = lwa_data-value.
WHEN 2.
wa_file_wicopa-blart = lwa_data-value.
WHEN 3.
wa_file_wicopa-bldat = lwa_data-value.
WHEN 4.
wa_file_wicopa-budat = lwa_data-value.
ENDCASE.
AT END OF row.
APPEND wa_file_wicopa TO gt_file_wicopa.
CLEAR wa_file_wicopa.
ENDAT.
CLEAR lwa_data.
ENDLOOP.
ENDIF.
ENDIF.
or
DATA: it_test TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE.
DATA :v_start_col TYPE i VALUE '1',
v_start_row TYPE i VALUE '1',
v_end_col TYPE i VALUE '256',
v_end_row TYPE i VALUE '65536',
v_text TYPE repti.
* Funtion Module to upload values from excel to the Internal table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = v_start_col
i_begin_row = v_start_row
i_end_col = v_end_col
i_end_row = v_end_row
TABLES
intern = it_test
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Or
You can use FM u201CTEXT_CONVERT_XLS_TO_SAPu201D.
DATA : i_raw TYPE truxs_t_text_data.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_tab_raw_data = i_raw
i_filename = p_path
TABLES
i_tab_converted_data = itab
EXCEPTIONS
conversion_failed = 1
OTHERS = 2
hope it will help u
regards
rahul -
Uploading a file to internal table
Hi experts,
I have a peculiar problem with loading a file into internal table.
While loading the file the first record(line) only is getting uploaded in to the internal table, although i hve many records(lines).
what could be the problem.
thnx very much,
the code is something like this:
data: begin of t_line occurs 0,
data(150) type c,
end of t_line.
OPEN DATASET FILENAME FOR INPUT IN TEXT MODE.
if sy-subrc = 0.
perform process_file_contents.
FORM PROCESS_FILE_CONTENTS.
DO.
read dataset filename into t_line.
IF SY-SUBRC NE 0.
IF REC_READ < 1.
MESSAGE E009(ZM) WITH 'No records in the file' FILENAME.
ENDIF.
EXIT.
ELSE.
ADD 1 TO REC_READ.
ENDIF.
append t_line.
ENDDO.Hi sey ni,
check if this sample code can be of some help to u.:
TABLES: kna1.
TYPES: BEGIN OF s_file,
customer TYPE kna1-kunnr,
name TYPE kna1-name1,
country TYPE kna1-land1,
region TYPE kna1-regio,
post_code TYPE kna1-pstlz,
street TYPE kna1-stras,
END OF s_file.
DATA: it_file TYPE s_file OCCURS 0 WITH HEADER LINE.
*-- selection screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE rlgrap-filename DEFAULT 'Customer_download.txt'
OBLIGATORY.
*SELECT-OPTIONS s_cust FOR kna1-kunnr.
SELECTION-SCREEN END OF BLOCK b1.
*-- start processing
at selection-screen on value-request for p_file.
perform file_help using p_file.
START-OF-SELECTION.
**-- Extract data from DB
PERFORM extract_data.
*-- Transfer data to file
PERFORM file_transfer USING p_file.
*-- write to o/p
END-OF-SELECTION.
LOOP AT it_file.
WRITE:/ it_file-customer, it_file-name, it_file-country, it_file-region,
it_file-post_code, it_file-street.
ENDLOOP.
*& Form extract_data
FORM extract_data .
SELECT kunnr
name1
land1
regio
pstlz
stras
APPENDING TABLE it_file
FROM kna1
WHERE kunnr IN s_cust.
ENDFORM. " extract_data
*& Form file_transfer
FORM file_transfer USING p_p_file.
DATA: l_message(30).
*-- Open File for write
OPEN DATASET p_p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE
l_message.
IF sy-subrc NE 0.
MESSAGE i002 WITH p_p_file.
ENDIF.
*-- Transfer data from FILE TO internal table
DO.
READ DATASET p_p_file INTO it_file.
IF sy-subrc = 0.
APPEND it_file.
CLEAR it_file.
ELSE.
EXIT.
ENDIF.
ENDDO.
*-- Close file
CLOSE DATASET p_p_file.
endform.
*& Form file_hepl
text
-->P_P_FILE text
form file_help using p_p_file.
data:l_filepath type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = l_filepath
p_p_file = l_filepath .
endform. " file_hepl
regards,
keerthi. -
Uploading CSV file into internal table
Hi,
I want to upload a CSV file into internal table.The flat file is having values as below:
'AAAAA','2003-10-11 07:52:37','167','Argentina',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'AAAA BBBB',NULL,NULL,NULL,'1',NULL,NULL,'AR ',NULL,NULL,NULL,'ARGENT','M1V','MX1',NULL,NULL,'F','F','F','F','F',NULL,'1',NULL,'MX','MMI ',NULL
'jklhg','2004-06-25 08:01:57','456','hjllajsdk','MANAGUA ',NULL,NULL,'265-5139','266-5136 al 38','MX1',NULL,NULL,'hjgkid GRÖBER','sdfsdf dfs asdfsdf 380 ad ased,','200 as ads, sfd sfd abajao y 50 m al sdf',NULL,'1',NULL,NULL,'NI ',NULL,NULL,NULL,'sdfdfg','M1V','dds',NULL,NULL,
Here I can not even split at ',' because some of the values are having value like NULL and some have values with comma too,
The delimiter is a quote and the separator is a comma here.
Can anyone help on this?
Thanks.
Edited by: Ginger on Jun 29, 2009 9:08 AMAs long as there can be a comma in a text literal you are right that the spilt command doesn't help. However there is one possibility how to attack this under one assumption:
- A comma outside a text delimiter is always considered a separator
- A comma inside a text delimiter is always considered a comma as part of the text
You have to read you file line by line and then travel along the line string character by character and setting a flag or counter for the text delimiters:
e.g.
"Text","Text1, Text2",NULL,NULL,"Text"
String Index 1: EQ " => lv_delimiter = 'X'
String Index 2: EQ T => text literal (because lv_delimiter = 'X')
String Index 3: EQ e => text literal (because lv_delimiter = 'X')
String Index 4: EQ x => text literal (because lv_delimiter = 'X')
String Index 5: EQ t => text literal (because lv_delimiter = 'X')
String Index 6: EQ " => lv_delimiter = ' ' (because it was 'X' before)
String Index 7: EQ , => This is a separator because lv_delimiter = ' '
String Index 8: EQ " => lv_delimiter = 'X' (because it was ' ' before)
String Index 9: EQ T => text literal (because lv_delimiter = 'X')
String Index 10: EQ e => text literal (because lv_delimiter = 'X')
String Index 11: EQ x => text literal (because lv_delimiter = 'X')
String Index 12: EQ t => text literal (because lv_delimiter = 'X')
String Index 13: EQ 1 => text literal (because lv_delimiter = 'X')
String Index 14: EQ , => text literal (because lv_delimiter = 'X')
String Index 15: EQ T => text literal (because lv_delimiter = 'X')
Whenever you hit a 'real' separator (lv_delimiter = ' ') you pass the value of the string before that up to the previous separator into the next structure field.
This is not an easy way to do it, but if you might have commas in your text literal and NULL values I gues it is probably the only way to go.
Hope that helps,
Michael -
Getting Issue while uploading CSV file into internal table
Hi,
CSV file Data format as below
a b c d e f
2.01E14 29-Sep-08 13:44:19 2.01E14 SELL T+1
actual values of column A is 201000000000000
and columen D is 201000000035690
I am uploading above said CSV file into internal table using
the below coding:
TYPES: BEGIN OF TY_INTERN.
INCLUDE STRUCTURE KCDE_CELLS.
TYPES: END OF TY_INTERN.
CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT'
EXPORTING
I_FILENAME = P_FILE
I_SEPARATOR = ','
TABLES
E_INTERN = T_INTERN
EXCEPTIONS
UPLOAD_CSV = 1
UPLOAD_FILETYPE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
am getting all columns data into internal table,
getting problem is columan A & D. am getting values into internal table for both; 2.01E+14. How to get actual values without modifying the csv file format.
waiting for your reply...
thanks & regards,
abhiHi Saurabh,
Thanks for your reply.
even i can't double click on those columns.
b'se the program needs be executed in background there can lot of csv file in one folder. No manual interaction on those csv files.
regards,
abhi -
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. -
GUI_UPLOAD to upload flat file to internal table
Hi Experts,
I have to upload a flat file which has multiple records ,from a local server.The fields in records are ~ saperated.
Presently i am only looking into uploading the flat file into internal table.
I have done the following coding;
TYPES: BEGIN OF gt_frmgt ,
tablety type c length 10 ,
tablenm type c length 30,
numin type c length 2,
END OF gt_frmgt.
TYPES: begin of gt_frmgto,
rec(1000) type c,
end of gt_frmgto.
DATA: Itgt_frmgt type table of gt_frmgt with header line.
DATA: itgt_frmgto type table of gt_frmgto with header line.
DATA: lfile_path type string.
PARAMETERS: f_path type localfile.
at selection-screen on value-request for f_path.
call function 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = f_path.
start-of-selection.
lfile_path = f_path.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = lfile_path
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = itgt_frmgto
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
delete itgt_frmgto index 1.
loop at itgt_frmgto.
clear Itgt_frmgt.
split itgt_frmgto-rec at cl_abap_char_utilities=>vertical_tab
into Itgt_frmgt-tablety
Itgt_frmgt-tablenm
Itgt_frmgt-numin.
append Itgt_frmgt.
endloop.
loop at Itgt_frmgt.
write:/ Itgt_frmgt-tablety, Itgt_frmgt-tablenm, Itgt_frmgt-numin.
The input file in Local path is ;
XXXXXXX~~Export the invoice
2~19980501~19980531
// The first invoice:
0~00130698114000010004119980512059611000276233.350.1711076.66????321000789010005???????????????????130601000000000??????????18? 3352051????532611-3357211???~~~
0~????????176233.350.1711076.6676233.350~1510
// The second invoice:
0~00130698114000010007219980512059611000440482.000.175882.00????110108078901007?????????61? 68744479?????????????462088-07?????130601000000000??????????18? 3352051????532611-3357211???????????~~~
0~????????139780.000.175780.0039780.000~1510
0~????3.5"10702.000.17102.0070.20~1510
and the output is :
XXXXXXX~~
2~~1998050
// The fir
0~00~1
0~????~?
// The sec
0~00~1
0~????~?
0~????
I am unable to understand why this split is happening .According to me the first 3 fields should be displayed without field saperater.
It would be very much appreciated if any body has little idea about this.
Thankx,
Priya
Message was edited by:
Priya Parmeshwar Shiggaon
Message was edited by:
Priya Parmeshwar Shiggaonif it is one time upload then u can use transaction CG3Z n upload file on application server.
u can tno use Gui_upload in background.
Program to upload file via gui_upload in foreground -(open fiel in Excel format and then make changes and save it as text tab file and upload tht file) -
REPORT Z_AMIT_BAPI
no standard page heading line-size 255.
parameters: p_file like rlgrap-filename default 'C:\temp\emp.txt'.
data :begin of itab occurs 0,
pernr(8),
bdate(10),
edate(10),
mail(30) ,
end of itab.
Start-of-selection.
Perform read_file.
*& Form read_file
text
--> p1 text
<-- p2 text
FORM read_file .
DATA: full_file_name TYPE string.
full_file_name = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = full_file_name
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ','
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = itab
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
MESSAGE e000(000) WITH 'Upload-Error; RC:' sy-subrc.
ENDIF.
ENDFORM. " read_file
reward points if helpfull
amit -
Is it possible upload local file to internal table in background mode?
Hi, all,
Is it possbile to upload local file(not server file) to internal table in background mode.
If possbile ,please tell me detail . Thanks in advance.
Regards,
LilyHello,
This is possible.
If you report has to be executed in background using schedule Job. Then the file path should be constant and it can be hard coded in the report itself while populationg the internal table.
Then create a variant for your report and use that variant in the job.
This will solve your problem I guess.
Regards
Arindam -
How do I upload XML files into sap table?
Dear all,
I found some methods that upload xml into SAP,
but there doesnt work under 4.6c.
Can someone tell me how to upload XML files into
sap under 4.6c?
THX!hi,
You can convert XML to abap using transformations. Simple transformations is a proprietary SAP programming language that describes the transformation of ABAP data to XML (serialization) and from XML to ABAP data (deserialization).
goto SE80->workbench->edit object(or other objects)->in object selection chose more tab and then choose the transformation radio button and write a name and click create new.
Here you enter your transformation like
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/sapxsl"
>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>
You can use this transfomation in your program using call transformation. You can find more info on call transformation in help.
Hope this helps.
Regards,
Richa
Maybe you are looking for
-
Can't install without Admin login and password
I have no idea where this comment should be posted...that is a clear indication that your "HELP" has failed this user. BTW, were the previous hopeless, distraught comments helpful to me? They made me feel I am Not alone in my utter disbelief at the
-
Email attachments not being saved
Hi all, I have a site with an email enabled document library in it. It is set to save both the email and the attachment in folders based on the sender. For 99% of the emails, it works fine. But for some reason, about once a month we get an email w
-
Reverse Mass Payment created from F110
We have generated a payment using F110 but not yet printed the cheques. We would like to reverse and reset the cleared ietms from the payment. Any help would be appreciated. PS. The payment was for 400 records so we cannot do this manually!
-
ViewCriteria with Timstamp throw ORA-01843
I try to Filter Rows by Timestap with ViewCriteria: Env: jdev 10.1.3 table: create table DATE_TIMSTAMP DATE_VALUE DATE, TIMESTAMP_VALUE TIMESTAMP(3) EO, VO and AM created with the wizard EO Attribute "TimestampValue" is set to TIMSTAMP JUnitTest: pub
-
ME(middle east) phurchase
Hello, Here is South Korea. We need to 'Adobe Indesign CC ME edition' . South Korea available for purchase?