메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_down_xml

노름마치 2007.11.05 13:01 조회 수 : 3989

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                    *
*--------------------------------------------------------------------*
* Author : Michel PIOUD                                              *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
**********************************************************************
* 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 '*u%;' INTO g_maktx.
    IF NOT sy-subrc IS INITIAL. EXIT.ENDIF.
  ENDDO.
  DO.
    REPLACE '*u%;' WITH '&amp;' INTO g_maktx.
    IF NOT sy-subrc IS INITIAL. EXIT.ENDIF.
  ENDDO.
  DO.
    REPLACE '/' WITH '&#47;' INTO g_maktx.
    IF NOT sy-subrc IS INITIAL. EXIT.ENDIF.
  ENDDO.


ENDFORM.                               " READ_DESCRIPTION
******************** END OF PROGRAM Z_DOWN_XML ************************


 

번호 제목 글쓴이 날짜 조회 수
107 Dynamic Select 소스 [5] 떡밥 2011.06.03 17774
106 스크린에서 버튼을 tree 처럼 만들기. [32] file Jenny 2011.08.11 17658
105 Mass Download [5] file 소주와 막걸리 2009.11.13 17365
104 셀(cell) 레벨의 ALV EDIT(편집) 가능 소스 [5] sapjoy 2008.09.25 17269
103 통화단위, krw, usd 일반 필드에 변환시 로직(소수점, 자리수) [4] sapjoy 2011.07.19 15563
102 REPORT z_alv_list_block_2 [1] 노름마치 2007.11.05 15184
101 4.6c 에서 Xml 파일을 읽어오는 로직 예제 입니다. [2] woong 2009.05.11 14809
100 금액을 한글로(수표)표기 [17] file STARFISH 2009.03.17 14646
99 인터널 테이블을 사용한 구구단 출력 두가지 입니다 - WRITE, ALV 이용 [1] kofnhuge 2012.10.10 14025
98 Text(Description) 빠르게 반영하기,,, 속도개선을 위주로 [5] file 노름마치 2010.12.07 13909
97 [onepaper] 참고자료 Archiving 세팅에 필요한 파일소스입니다. [7] file 원니컴 2011.03.22 13801
96 Syntax Checker [4] file 소주와 막걸리 2009.11.13 13765
95 ALV Row Color 지정하는 소스. [3] 나침반친구 2007.05.28 12865
94 금액을 영문으로 [4] file 쥬앙 2009.04.06 12366
93 Transport Trace [4] file 소주와 막걸리 2009.11.13 12143
92 멀 어떻게 해야 하는건질 몰라 질문 드립니다 [5] 쏠라맨 2012.10.12 11666
91 [Module pool] Container에 webpage 넣기. [2] 냥냥 2013.03.19 11199
90 nugg 프로그램을 sap 에 생성하기.. [3] file MadMax 2012.10.11 10830
89 Select-Options 의 Extension 에 제한을 주는 방법 [5] icarus 2007.11.15 10829
88 Split 의 사용 [1] 양키(이경환) 2014.02.05 10740