Skip to Content

Cannot move my .XML file to SAP directory

Hi Experts,

I have done following code by which I have pass one internal table to create a .XML file and move it to SAP directory.But its not working.I couldn't find any XML file in sap directory..

My code is under....

lo_ixml = cl_ixml=>create( ).

lo_document = lo_ixml->create_document( ).

i_workorder_summarys = lo_document->create_simple_element(

name = 'I_WORKORDER_SUMMARYs'

parent = lo_document ).

LOOP AT i_order.

tcost = i_order-parts_cost.

IF tcost < 0.

SHIFT i_order-parts_cost RIGHT DELETING TRAILING '-'.

* IF i_order-parts_cost NE '0.00'.

CONCATENATE '-' i_order-parts_cost INTO i_order-parts_cost.

* ENDIF.

ENDIF.

pqty = i_order-parts_sell .

IF pqty < 0.

SHIFT i_order-parts_sell RIGHT DELETING TRAILING '-'.

* IF i_order-parts_sell NE '0.00'.

CONCATENATE '-' i_order-parts_sell INTO i_order-parts_sell.

* ENDIF.

ENDIF.

IF i_order-misc_cost IS INITIAL.

i_order-misc_cost = '0'.

ENDIF.

IF i_order-misc_sell IS INITIAL.

i_order-misc_sell = '0'.

ENDIF.

CONDENSE i_order-parts_cost NO-GAPS.

CONDENSE i_order-parts_sell NO-GAPS.

MODIFY i_order TRANSPORTING parts_cost parts_sell misc_sell misc_cost.

ENDLOOP.

SORT i_order BY workorder_number.

LOOP AT i_order.

SHIFT i_order-workorder_number LEFT DELETING LEADING '0'.

SHIFT i_order-external_source_id LEFT DELETING LEADING '0'.

SHIFT i_order-cost_centre LEFT DELETING LEADING '0'.

i_workorder_summary = lo_document->create_simple_element(

name = 'I_WORKORDER_SUMMARY'

parent = i_workorder_summarys ).

lo_document->create_simple_element( name = 'Workorder_Number'

parent = i_workorder_summary

value = i_order-workorder_number ).

lo_document->create_simple_element( name = 'Task_Number'

parent = i_workorder_summary

value = i_order-task_number ).

lo_document->create_simple_element( name = 'workorder_Desc.'

parent = i_workorder_summary

value = i_order-workorder_desc ).

lo_document->create_simple_element( name = 'Model'

parent = i_workorder_summary

value = i_order-model ).

lo_document->create_simple_element( name = 'Serial_Number'

parent = i_workorder_summary

value = i_order-serial_number ).

lo_document->create_simple_element( name = 'Func_Location'

parent = i_workorder_summary

value = i_order-func_location ).

lo_document->create_simple_element( name = 'Job_Date'

parent = i_workorder_summary

value = i_order-job_date ).

lo_document->create_simple_element( name = 'Open_Date'

parent = i_workorder_summary

value = i_order-open_date ).

lo_document->create_simple_element( name = 'Component_Code'

parent = i_workorder_summary

value = i_order-component_code ).

lo_document->create_simple_element( name = 'Modifier_Code'

parent = i_workorder_summary

value = i_order-modifier_code ).

lo_document->create_simple_element( name = 'Task_Type'

parent = i_workorder_summary

value = i_order-task_type ).

lo_document->create_simple_element( name = 'Ext_Identifier'

parent = i_workorder_summary

value = i_order-ext_identifier ).

lo_document->create_simple_element( name = 'Exchange_Rate'

parent = i_workorder_summary

value = i_order-exchange_rate ).

lo_document->create_simple_element( name = 'Currency'

parent = i_workorder_summary

value = i_order-currency ).

lo_document->create_simple_element( name = 'Job_Code'

parent = i_workorder_summary

value = i_order-job_code ).

lo_document->create_simple_element( name = 'Close_Period'

parent = i_workorder_summary

value = i_order-close_period ).

lo_document->create_simple_element( name = 'Cost_Centre'

parent = i_workorder_summary

value = i_order-cost_centre ).

lo_document->create_simple_element( name = 'Cost_Bearer'

parent = i_workorder_summary

value = i_order-cost_bearer ).

lo_document->create_simple_element( name = 'Labour_Hours'

parent = i_workorder_summary

value = i_order-labour_hours ).

lo_document->create_simple_element( name = 'Parts_Cost'

parent = i_workorder_summary

value = i_order-parts_cost ).

lo_document->create_simple_element( name = 'Parts_Sell'

parent = i_workorder_summary

value = i_order-parts_sell ).

lo_document->create_simple_element( name = 'Labor_Cost'

parent = i_workorder_summary

value = i_order-labor_cost ).

lo_document->create_simple_element( name = 'Labor_Sell'

parent = i_workorder_summary

value = i_order-labor_sell ).

lo_document->create_simple_element( name = 'Misc_Cost'

parent = i_workorder_summary

value = i_order-misc_cost ).

lo_document->create_simple_element( name = 'Misc_Sell'

parent = i_workorder_summary

value = i_order-misc_sell ).

lo_document->create_simple_element( name = 'External_Source_ID'

parent = i_workorder_summary

value = i_order-external_source_id ).

lo_document->create_simple_element( name = 'System_Source'

parent = i_workorder_summary

value = i_order-system_source ).

lo_document->create_simple_element( name = 'Planning_Status'

parent = i_workorder_summary

value = i_order-planning_status ).

lo_document->create_simple_element( name = 'Planned_Start_Time'

parent = i_workorder_summary

value = i_order-planned_start_time ).

lo_document->create_simple_element( name = 'Planned_End_Time'

parent = i_workorder_summary

value = i_order-planned_end_time ).

ENDLOOP.

CREATE OBJECT m_xmldoc.

m_xmldoc->create_with_dom( document = lo_document ).

* m_xmldoc->export_to_file( fname ).

DATA:

lo_streamfactory TYPE REF TO if_ixml_stream_factory,

lo_ostream TYPE REF TO if_ixml_ostream,

lo_renderer TYPE REF TO if_ixml_renderer,

lv_rc TYPE i,

lv_xml_size TYPE i.

* Create Stream Factory

lo_streamfactory = lo_ixml->create_stream_factory( ).

SELECT SINGLE dirname FROM user_dir INTO p_fname WHERE ALIASS = 'DIR_LOG'."SVRNAME = 'SAPDEV_SR3_01'.

* REPLACE ALL OCCURRENCES OF '/' IN fname WITH '\' .

* CONCATENATE fname '\ZAMT03' sy-datum '.xml' INTO fname.

* Crate Output Stream

CONCATENATE 'ImportWorkorderSettlement_' sy-datum '_' sy-uzeit '.xml' INTO p_fname.

OPEN DATASET 'P_FNAME' FOR OUTPUT IN TEXT MODE ENCODING UTF-8 ."NON-UNICODE .

lo_ostream = lo_streamfactory->create_ostream_uri( system_id = p_fname ).

* Craete renderer

lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream

document = lo_document ).

* Set Pretty Print

lo_ostream->set_pretty_print('X').

* Render

lv_rc = lo_renderer->render( ).

CLOSE DATASET 'P_FNAME'.

* Get XML file size

lv_xml_size = lo_ostream->get_num_written_raw( ).

COMMIT WORK.


Please help me on that matter..

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on May 21, 2015 at 09:34 PM

    Hello,

    Did you try

    OPEN DATASET P_FNAME FOR OUTPUT IN TEXT MODE ENCODING UTF-8 .

    instead of

    OPEN DATASET 'P_FNAME' FOR OUTPUT IN TEXT MODE ENCODING UTF-8 .


    by the way, I never worked with streams, but something in

    lo_ostream = lo_streamfactory->create_ostream_uri( system_id = p_fname ).

    does not smell good to me, are you sure it is the file name that you have to pass as argument here?


    Do you really need to use this way to generate your XML? Can't you use a Simple Transformation (http://help.sap.com/abapdocu_70/en/ABENSIMPLE_TRANSFORMATION_GLOSRY.htm)?


    BR,

    Guilherme.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

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

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