10-07-2007 12:55 PM
Hi
i am uploading xml file data from apps to ztable.
In foreground the program is working perfectly. but when i read in background, i am not getting full file hence creating dump.. how to over come this..
Looks like the problem lies in reading the full file.
Does anyone faced this scenario before. Please help me overcome this problem.
In background code is like this:
PARAMETERS: pa_file TYPE PATHINTERN.
l_filename = pa_file.
upload a file from the apps
OPEN DATASET l_filename FOR INPUT IN BINARY MODE.
IF sy-subrc <> 0.
write:/ 'Invalid File Path'.
ENDIF.
DO.
READ DATASET l_filename INTO l_xml_line.
IF sy-subrc EQ 0.
APPEND l_xml_line TO l_xml_table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
and in foreground like below:
PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:\BP.xml'.
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.
10-07-2007 1:51 PM
10-07-2007 2:02 PM
Hi,
It's not the dump i am getting now..
I am not able to read the full length file in background..
erro rmessage
<b>unclosed element tag; '>' or '/>' expected</b>
In foreground i am able to read the full length file..
catching the sy-subrc = 4 at the last record of
READ DATASET l_filename INTO l_xml_line.
10-07-2007 2:16 PM
How is l_xml_line is defined?
Define it as a string type.
Regards,
Atish
10-07-2007 2:23 PM
Hi,
I defined it as like Below..
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
10-07-2007 2:28 PM
Hi All,
this is the full code of the program. which is good for forground xml reading application....
In background having problem with the length..
REPORT ZNPP711.
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.
DATA:
Internal table
it_zpp13 TYPE TABLE OF zpp13,
Work area
wa_zpp13 TYPE zpp13.
selection screen
SELECTION-SCREEN BEGIN OF block b1 WITH FRAME TITLE text-001.
PARAMETERS: pa_file TYPE PATHINTERN LOWER CASE DEFAULT '/apps/B2B/B2Bprog/BP.XML'.
PARAMETERS: pa_file TYPE char1024 LOWER CASE DEFAULT '/apps/B2B/B2Bprog/BP.XML'.
Validation of XML file: Only DTD included in xml document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK B1.
*&----
&
*& selection screen validation
*&----
&
AT SELECTION-SCREEN.
to validate pa_file is not initial
PERFORM sub_validate_file.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR PA_FILE.
Request for filename for xml file from the application server
PERFORM sub_get_filename_appl USING pa_file.
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 apps
OPEN DATASET l_filename FOR INPUT IN BINARY MODE.
IF sy-subrc <> 0.
write:/ 'Invalid File Path'.
ENDIF.
DO.
READ DATASET l_filename INTO l_xml_line.
IF sy-subrc EQ 0.
APPEND l_xml_line TO l_xml_table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
DESCRIBE TABLE l_xml_table.
l_xml_table_size = ( sy-tleng ) * ( sy-tfill ).
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.
IF node IS INITIAL. EXIT. ENDIF.
create a node iterator
iterator = node->create_iterator( ).
get current node
node = iterator->get_next( ).
break sbomm.
refresh it_zpp13.
clear wa_zpp13.
field-symbols <fs_field> type any.
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( ).
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( ).
ENDDO.
ENDIF.
WHEN if_ixml_node=>co_node_text OR
if_ixml_node=>co_node_cdata_section.
text node
value = node->get_value( ).
*break sbomm.
if name = 'ORDER_NUM'.
assign component 2 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_VER'.
assign component 3 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_CO_CD'.
assign component 4 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'VENDOR_CD'.
assign component 10 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'VENDOR_NAME'.
assign component 11 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_WAFER_QTY'.
assign component 12 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_DIE_QTY'.
assign component 13 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_DATE'.
assign component 5 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_CMT'.
assign component 41 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_TYPE'.
assign component 6 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ORDER_SUB_TYPE'.
assign component 14 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'CUST_CD'.
assign component 15 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'FLOW'.
assign component 16 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_ID'.
assign component 7 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'PARENT_LOT_ID'.
assign component 8 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ITEM_NO'.
assign component 17 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'PART_ID'.
assign component 18 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'NTBD_VER'.
assign component 19 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'WAFER_SIZE'.
assign component 20 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_WAFER_QTY'.
assign component 21 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_DIE_QTY'.
assign component 22 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_SHIP_DATE'.
assign component 23 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_REQ_DATE'.
assign component 24 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_REQ_DESC'.
assign component 25 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_SPECIAL_REQ'.
assign component 26 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_PRTY'.
assign component 27 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'LOT_TYPE'.
assign component 28 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'WAFER_ID'.
assign component 29 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'DROP_TEXT'.
assign component 9 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'BIZ_TYPE'.
assign component 30 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'CUST_REGION'.
assign component 31 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ACTL_3RD_LOT_ID'.
assign component 32 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ACTL_3RD_PART_ID'.
assign component 33 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'ACTL_3RD_CO'.
assign component 34 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'SHIP_ID'.
assign component 35 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'VENDOR_LOC'.
assign component 36 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'TECH_CODE'.
assign component 37 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'SPEED_BIN_FLAG'.
assign component 38 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'DATE_CD'.
assign component 39 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'BLIND_ASSY_FLAG'.
assign component 40 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'SHIP_FROM'.
assign component 42 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'SHIP_TO'.
assign component 43 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'REMARK'.
assign component 44 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'CANCEL_REASON'.
assign component 45 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'COMP_TYPE'.
assign component 46 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'COMP_TYPE_ID'.
assign component 47 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'COMP_LOT_ID'.
assign component 48 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'COMP_QTY'.
assign component 49 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'PRICE_IND_FLAG'.
assign component 50 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'PROC_STAGE_NAME'.
assign component 51 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
endif.
if name = 'PROC_STAGE_ID'.
assign component 52 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
append wa_zpp13 to it_zpp13.
endif.
if name = 'PROC_DESC'.
assign component 53 of structure wa_zpp13 to <fs_field>.
<fs_field> = value.
if wa_zpp13-proc_desc IS NOT INITIAL.
append wa_zpp13 to it_zpp13.
endif.
endif.
ENDCASE.
advance to next node
node = iterator->get_next( ).
ENDWHILE.
DELETE FROM zpp13.
MODIFY zpp13 FROM TABLE it_zpp13.
ENDFORM. "process_dom
&----
*& Form sub_validate_file
&----
text
----
--> p1 text
<-- p2 text
----
form sub_validate_file .
IF pa_file IS INITIAL.
*MESSAGE e000. "specify the file path
write:/ 'specify file'.
ENDIF.
endform. " sub_validate_file
&----
*& Form sub_get_filename_appl
&----
text
----
-->P_PA_FILE text
----
form sub_get_filename_appl using l_fname TYPE any.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = l_fname
filemask = '*'
IMPORTING
serverfile = l_fname
EXCEPTIONS
canceled_by_user = 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.
endform. " sub_get_filename_appl
10-08-2007 5:47 AM
Hi srini,
I guess you should maintain complete file path.In the file path you have given
'/apps/B2B/B2Bprog/BP.XML'.Find out in which drive the file is residing.It might be E:/ OR C:/.Prefix E:/ OR C:/ to file name.
Regards,
Raghu.
Message was edited by:
Raghu Reddy
10-08-2007 8:48 AM
Hi Raghu,
this is reading from Application server not frontend reading
10-08-2007 9:50 AM
Hi guys,
I solved the problem in reading the length file from APPS.
no need to use either string or Xstring. following code made wonders
just simple statements while reading the file as below:
<b>OPEN DATASET l_filename FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
DO.
READ DATASET l_filename INTO l_xml_line.
APPEND l_xml_line TO l_xml_table.
CLEAR l_xml_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET l_filename.</b>