REPORT z_down_xml LINE-SIZE 132 NO STANDARD PAGE HEADING. ********************************************************************** * REPORT Z_DOWN_XML - Using an internal table (gt_marc) * * and downloading the report data as an xml file * * The xml indentation is hard coded into the file * ********************************************************************** * Databases TABLES: makt, "Mat description marc, "Material / plant t001w, "plant name bhdgd. "Batch heading * Internal tables DATA: BEGIN OF gt_marc OCCURS 0, werks LIKE marc-werks, matnr LIKE marc-matnr, END OF gt_marc, * Table to be downloaded as xml. Each line stores start and end tags * and the value BEGIN OF gt_xml OCCURS 0, line(120), END OF gt_xml, g_maktx(120). * User-input SELECT-OPTIONS: s_werks FOR marc-werks, s_matnr FOR marc-matnr. ********************************************************************** START-OF-SELECTION. * Extract all required data PERFORM main_processing. ********************************************************************** END-OF-SELECTION. SORT gt_marc BY werks matnr. LOOP AT gt_marc. AT FIRST. "First tag must be root CLEAR gt_xml. gt_xml-line = '<LOCATIONS>'. APPEND gt_xml. CLEAR gt_xml. ENDAT. AT NEW werks. "At new plant PERFORM read_plant. FORMAT COLOR 4 ON. SKIP 1. WRITE :/ gt_marc-werks, t001w-name1. FORMAT COLOR 4 OFF. CLEAR gt_xml. gt_xml-line = ' <PLANT>'. APPEND gt_xml. CLEAR gt_xml. CONCATENATE ' <NUMBER>' gt_marc-werks '</NUMBER>' INTO gt_xml-line. APPEND gt_xml. CLEAR gt_xml. CONCATENATE ' <NAME>' t001w-name1 '</NAME>' INTO gt_xml-line. APPEND gt_xml. CLEAR gt_xml. gt_xml-line = ' </PLANT>'. APPEND gt_xml. CLEAR gt_xml. ENDAT. PERFORM read_description. CLEAR gt_xml. gt_xml-line = ' <MATERIAL>'. APPEND gt_xml. CLEAR gt_xml. CONCATENATE ' <NAME>' g_maktx '</NAME>' INTO gt_xml-line. APPEND gt_xml. CLEAR gt_xml. CONCATENATE ' <NUMBER>' gt_marc-matnr '</NUMBER>' INTO gt_xml-line. APPEND gt_xml. CLEAR gt_xml. gt_xml-line = ' </MATERIAL>'. APPEND gt_xml. CLEAR gt_xml. * display data FORMAT COLOR 2 ON. WRITE :/ gt_marc-matnr, makt-maktx. FORMAT COLOR 2 OFF. ENDLOOP. * The last tag must be the root closing tag --* gt_xml-line = '</LOCATIONS>'. APPEND gt_xml. CLEAR gt_xml. CALL FUNCTION 'DOWNLOAD' EXPORTING filename = 'C:\PLANT1.XML' filetype = 'ASC' TABLES data_tab = gt_xml. ********************************************************************** TOP-OF-PAGE. MOVE sy-title TO bhdgd-line1. MOVE sy-repid TO bhdgd-repid. MOVE sy-uname TO bhdgd-uname. MOVE sy-datum TO bhdgd-datum. MOVE '0' TO bhdgd-inifl. MOVE '132' TO bhdgd-lines. FORMAT INTENSIFIED ON COLOR COL_HEADING. PERFORM batch-heading(rsbtchh0). "report header *---------------------------------------------------------------------* * Form READ_PLANT *---------------------------------------------------------------------* FORM read_plant. * Get plant name CLEAR t001w. SELECT SINGLE name1 INTO t001w-name1 FROM t001w WHERE werks EQ gt_marc-werks. ENDFORM. " READ_PLANT *---------------------------------------------------------------------* * Form MAIN_PROCESSING *---------------------------------------------------------------------* FORM main_processing. * Material and plant basic data SELECT werks matnr INTO TABLE gt_marc FROM marc WHERE werks IN s_werks AND matnr IN s_matnr. ENDFORM. " MAIN_PROCESSING *---------------------------------------------------------------------* * Form READ_DESCRIPTION *---------------------------------------------------------------------* FORM read_description. * Material name CLEAR g_maktx. SELECT SINGLE maktx INTO g_maktx FROM makt WHERE matnr EQ gt_marc-matnr AND spras EQ 'E'. * Replace special character DO. REPLACE '&' WITH '*ù%;' INTO g_maktx. IF NOT sy-subrc IS INITIAL. EXIT.ENDIF. ENDDO. DO. REPLACE '*ù%;' WITH '&' INTO g_maktx. IF NOT sy-subrc IS INITIAL. EXIT.ENDIF. ENDDO. DO. REPLACE '/' WITH '/' INTO g_maktx. IF NOT sy-subrc IS INITIAL. EXIT.ENDIF. ENDDO. ENDFORM. " READ_DESCRIPTION ******************** END OF PROGRAM Z_DOWN_XML ************************Return to :-
(c) www.sap-basis-abap.com All material on this site is
Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies. The site www.sap-basis-abap.com is in no way affiliated
with SAP AG.
Any unauthorised copying or mirroring is prohibited.