현재 abap 데이터를 XML형태로 변환하여 보내고자 합니다.
XML형태로 만들어주는 펑션이나 기타 키워드가 있는지 궁금합니다..
그리고 한가지 더 XString이란 자료형이 있는데 String이랑 어떤 차이가 있는지도
궁금하네요.... 더운 날씨 모두 힘내시고 좋은 하루 되세요~~
댓글 3
-
ID
2009.06.26 23:16
-
썬바바
2009.06.27 01:57
아래 프로그램 참고하세요.
REPORT ZDOWNXML LINE-SIZE 132 NO STANDARD PAGE HEADING.
* Databases
TABLES: MAKT, "Mat description
MARC, "Material / plant
T001W, "plant name
BHDGD. "Batch heading
* Internal tables
DATA: BEGIN OF I_MARC OCCURS 0,
WERKS LIKE MARC-WERKS,
MATNR LIKE MARC-MATNR.
DATA: END OF I_MARC.
* Table to be downloaded as xml. Each line stores start and end tags
* and the value
DATA: BEGIN OF XML OCCURS 0,
LINE(80) TYPE C.
DATA: END OF XML.
* 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 I_MARC BY WERKS MATNR.
LOOP AT I_MARC.
AT FIRST. "First tag must be root
CLEAR XML.
XML-LINE = '<LOCATIONS>'.
APPEND XML.
CLEAR XML.
ENDAT.
AT NEW WERKS. "At new plant
PERFORM READ_PLANT.
FORMAT COLOR 4 ON.
SKIP 1.
WRITE :/ I_MARC-WERKS, T001W-NAME1.
FORMAT COLOR 4 OFF.
CLEAR XML.
XML-LINE = ' <PLANT>'.
APPEND XML.
CLEAR XML.
CONCATENATE ' <NUMBER>' I_MARC-WERKS '</NUMBER>'
INTO XML-LINE.
APPEND XML.
CLEAR XML.
CONCATENATE ' <NAME>' T001W-NAME1 '</NAME>' INTO XML-LINE.
APPEND XML.
CLEAR XML.
XML-LINE = ' </PLANT>'.
APPEND XML.
CLEAR XML.
ENDAT.
PERFORM READ_DESCRIPTION.
CLEAR XML.
XML-LINE = ' <MATERIAL>'.
APPEND XML.
CLEAR XML.
CONCATENATE ' <NAME>' MAKT-MAKTX '</NAME>'
INTO XML-LINE.
APPEND XML.
CLEAR XML.
CONCATENATE ' <NUMBER>' I_MARC-MATNR '</NUMBER>'
INTO XML-LINE.
APPEND XML.
CLEAR XML.
XML-LINE = ' </MATERIAL>'.
APPEND XML.
CLEAR XML.
* display data
FORMAT COLOR 2 ON.
WRITE :/ I_MARC-MATNR, MAKT-MAKTX.
FORMAT COLOR 2 OFF.
ENDLOOP.
*-- The last tag must be the root closing tag --*
XML-LINE = '<LOCATIONS>'.
APPEND XML.
CLEAR XML.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
FILENAME = 'C:PLANT1.XML'
FILETYPE = 'ASC'
TABLES
DATA_TAB = 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 I_MARC-WERKS.
ENDFORM. " READ_PLANT
*&---------------------------------------------------------------------*
*& Form MAIN_PROCESSING
*&---------------------------------------------------------------------*
FORM MAIN_PROCESSING.
* Material and plant basic data
SELECT WERKS MATNR
INTO TABLE I_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 MAKT.
SELECT SINGLE MAKTX
INTO MAKT-MAKTX
FROM MAKT
WHERE MATNR EQ I_MARC-MATNR
AND SPRAS EQ 'E'.
ENDFORM. " READ_DESCRIPTION -
정군
2009.06.29 07:39
위의 두분의 방법을 사용해도 되고, parsing하는 class가 있습니다.
xml로 검색해서 찾아보세요. 예전에 다른 분이 올리신 글이 있습니다.
string은 문자열이고, xstring은 binary 값입니다.
길이 제한은 둘 다 없습니다.
대략이렇게 하시면 될 것 같은데요...
DATA : BEGIN OF ITAB OCCURS 0,
A(100) TYPE C,
END OF ITAB.
DATA: XML_OUT TYPE STRING .
*------------------- XML
CALL TRANSFORMATION ('ID')
SOURCE TAB = T001[] <-- xml로 형태로 바꾸고 싶은 인터널데이터
RESULT XML XML_OUT.
*------------- Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
I_STRING = XML_OUT
I_TABLINE_LENGTH = 100
TABLES
ET_TABLE = ITAB. <-- 인터널 xml데이타