2008 Jan 21 5:32 AM
Hi everyone,
I am working on smartforms and i require smartforms and its output in XML format, if its possible then please let me know the procedure to transmit smartforms output in XML format. Please reply, its urgent.
Thanks & Regards
V.B.
2008 Jan 21 5:44 AM
In transaction SE80 browse menu Workbench -> Edit Object. In the popup window enter XSLT Program name (e.g. ZXSLT) and click on create button.
Enter the following code into the editor
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<!xsl:output encoding="utf-8" indent="yes"/>
<xsl:template match="D2CXML">
<PurchaseOrders>
<xsl:apply-templates/>
</PurchaseOrders>
</xsl:template>
<xsl:template match="item">
<PONO>
<xsl:attribute name="no">
<xsl:value-of select="EBELN"/>
</xsl:attribute> 1
<PORDNO>
<xsl:apply-templates select="EBELN"/>
</PORDNO>
<Vendor>
<xsl:apply-templates select="LIFNR"/>
</Vendor>
<PurchaseOrg>
<xsl:apply-templates select="EKORG"/>
</PurchaseOrg>
<PurchaseGrp>
<xsl:apply-templates select="EKGRP"/>
</PurchaseGrp>
<xsl:apply-templates select="X-MLSTRUCT"/>
</PONO>
</xsl:template>
<xsl:template match="X-MLSTRUCT">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="X-MLSTRUCT/item">
<Product>
<ItemNo>
<xsl:apply-templates select="EBELP"/>
</ItemNo>
<Material>
<xsl:apply-templates select="MATNR"/>
</Material>
<Qty>
<xsl:apply-templates select="MENGE"/>
</Qty>
<Price>
<xsl:apply-templates select="NETPR"/>
</Price>
</Product>
</xsl:template>
</xsl:transform>
Create Extraction Program
Create a report program using ABAP Workbench and the code of the extracting program will be as follows.
REPORT ZXML_EXTRACTION .
----
- - - - - - - - - - DATA DECLARATION - - - - - - - - --*
----
TYPE-POOLS: ABAP.
TYPES: BEGIN OF TY_XML,
EBELP TYPE STRING,
MATNR TYPE STRING,
MENGE TYPE STRING,
NETPR TYPE STRING,
END OF TY_XML.
TYPES: BEGIN OF TY_FINAL_XML,
EBELN TYPE STRING,
EKORG TYPE EKKO-EKORG,
EKGRP TYPE EKKO-EKGRP,
LIFNR TYPE EKKO-LIFNR,
XMLSTRUCT TYPE TY_XML,
END OF TY_FINAL_XML.
TYPES: BEGIN OF TY_EKPO,
EBELN TYPE EKPO-EBELN,
LIFNR TYPE EKKO-LIFNR,
EKORG TYPE EKKO-EKORG,
EKGRP TYPE EKKO-EKGRP,
EBELP TYPE EKPO-EBELP,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
NETPR TYPE EKPO-NETPR,
END OF TY_EKPO.
TYPES: TY_TSRCLIN(1024) TYPE X,
TY_TSRCTAB TYPE STANDARD TABLE OF TY_TSRCLIN.
Global Data for XML Creation
DATA: G_XML_STRING TYPE STRING,
G_XML_STRING1 TYPE STRING,
G_FILENAME TYPE STRING,
G_PATH TYPE STRING,
G_FULLPATH TYPE STRING,
G_TITLE TYPE STRING,
G_LEN TYPE I.
DATA: G_XSLTP TYPE REF TO CL_XSLT_PROCESSOR,
G_IXML TYPE REF TO IF_IXML,
G_STREAM_FACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
G_ENCODING TYPE REF TO IF_IXML_ENCODING,
RESSTR TYPE REF TO IF_IXML_OSTREAM,
HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT,
G_SRCSTR TYPE REF TO IF_IXML_ISTREAM,
G_GEN_EX TYPE REF TO CX_XSLT_EXCEPTION,
G_MESSAGE TYPE STRING,
G_PROGNAME TYPE CXSLTDESC VALUE 'ID'.
Work Area
DATA: WA_XML TYPE TY_XML,
WA_EKPO TYPE TY_EKPO,
WA_EKPO1 TYPE TY_EKPO,
WA_SOURCE TYPE ABAP_TRANS_SRCBIND.
DATA: BEGIN OF WA_FINAL_XML,
EBELN TYPE STRING,
LIFNR TYPE STRING,
EKGRP TYPE STRING,
EKORG TYPE STRING,
XMLSTRUCT TYPE TABLE OF TY_XML,
END OF WA_FINAL_XML.
----
INTERNAL TABLES
----
DATA: T_XML TYPE TABLE OF TY_XML,
T_FINAL_XML LIKE TABLE OF WA_FINAL_XML,
T_EKPO TYPE TABLE OF TY_EKPO,
T_SOURCE TYPE ABAP_TRANS_SRCBIND_TAB,
T_SRCTAB TYPE TY_TSRCTAB.
----
- - - - - - - - - - SELECTION-SCREEN - - - - - - - - - - - - - - *
----
---Select options/Parameters--
SELECTION-SCREEN BEGIN OF BLOCK DOWNLOAD
WITH FRAME TITLE TEXT-002.
PARAMETERS: P_COMP TYPE CHAR1 AS CHECKBOX.
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK DOWNLOAD.
AT SELECTION-SCREEN.
IF NOT P_COMP IS INITIAL AND
P_FILE IS INITIAL.
MESSAGE E000(38) WITH 'Please enter the file name'(E01).
ENDIF.
IF NOT P_COMP IS INITIAL AND
NOT P_FILE IS INITIAL.
TRANSLATE P_FILE TO UPPER CASE.
G_LEN = STRLEN( P_FILE ) - 4.
IF P_FILE+G_LEN(4) NE '.XML'.
MESSAGE E000(38) WITH 'Please use the extension as .XML'(E02).
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
G_TITLE = 'Result Document'(I01).
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = G_TITLE
FILE_FILTER = '*.XML'
CHANGING
FILENAME = G_FILENAME
PATH = G_PATH
FULLPATH = G_FULLPATH.
IF SY-SUBRC = 0.
P_FILE = G_FULLPATH.
ENDIF.
----
- - - - - - - - - - LOGIC SECTION - - - - - - - - - - - - *
----
START-OF-SELECTION.
PERFORM CLEAR_VARIABLES.
PERFORM START_SELECTION.
END-OF-SELECTION.
WA_FINAL_XML-XMLSTRUCT[] = T_XML[].
APPEND WA_FINAL_XML TO T_FINAL_XML.
PERFORM CREATE_XML.
IF NOT P_COMP IS INITIAL.
PERFORM DOWNLOAD_FILE.
ENDIF.
&----
*& Form START_SELECTION
&----
Select all the Guids
----
FORM START_SELECTION .
SELECT HEBELN HLIFNR HEKORG HEKGRP
IEBELP IMENGE INETPR IMATNR
INTO CORRESPONDING FIELDS OF TABLE T_EKPO
FROM EKKO AS H INNER JOIN EKPO AS I
ON HEBELN = IEBELN.
LOOP AT T_EKPO INTO WA_EKPO.
WA_EKPO1 = WA_EKPO.
AT NEW EBELN.
REFRESH T_XML.
CLEAR WA_XML.
WA_FINAL_XML-EBELN = WA_EKPO-EBELN.
WA_FINAL_XML-LIFNR = WA_EKPO1-LIFNR.
WA_FINAL_XML-EKORG = WA_EKPO1-EKORG.
WA_FINAL_XML-EKGRP = WA_EKPO1-EKGRP.
ENDAT.
MOVE-CORRESPONDING WA_EKPO TO WA_XML.
APPEND WA_XML TO T_XML.
AT END OF EBELN.
WA_FINAL_XML-XMLSTRUCT[] = T_XML[].
APPEND WA_FINAL_XML TO T_FINAL_XML.
ENDAT.
ENDLOOP.
ENDFORM. " START_SELECTION
&----
*& Form CREATE_XML
&----
Create XML
----
FORM CREATE_XML .
Prepare for Transformation
WA_SOURCE-NAME = 'D2CXML'.
GET REFERENCE OF T_FINAL_XML INTO WA_SOURCE-VALUE.
APPEND WA_SOURCE TO T_SOURCE.
CLEAR G_XML_STRING.
CALL TRANSFORMATION ZXSLT
SOURCE (T_SOURCE)
RESULT XML G_XML_STRING.
IF SY-SUBRC <> 0.
*
ELSE.
G_XML_STRING1 = G_XML_STRING.
REPLACE 'utf-16' WITH 'utf-8' INTO G_XML_STRING.
ENDIF.
ENDFORM. " CREATE_XML
&----
*& Form DOWNLOAD_FILE
&----
Download the XML into a file
----
FORM DOWNLOAD_FILE .
Local Data
DATA: L_FILENAME TYPE STRING.
TRY.
CREATE OBJECT G_XSLTP.
CATCH CX_XSLT_EXCEPTION.
ENDTRY.
G_IXML = CL_IXML=>CREATE( ).
G_STREAM_FACTORY = G_IXML->CREATE_STREAM_FACTORY( ).
G_SRCSTR = G_STREAM_FACTORY->CREATE_ISTREAM_CSTRING(
STRING = G_XML_STRING1 ).
XML source is specified by stream
CALL METHOD G_XSLTP->SET_SOURCE_STREAM
EXPORTING
STREAM = G_SRCSTR.
CALL METHOD G_XSLTP->SET_RESULT_TABLE
EXPORTING
TABLE = T_SRCTAB.
RUN
TRY.
CALL METHOD G_XSLTP->RUN
EXPORTING
PROGNAME = G_PROGNAME.
CATCH CX_XSLT_EXCEPTION INTO G_GEN_EX.
G_XML_STRING = G_GEN_EX->GET_TEXT( ).
ENDTRY.
L_FILENAME = P_FILE.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = L_FILENAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = T_SRCTAB.
IF SY-SUBRC = 0.
G_MESSAGE = 'File downloaded successfully'(I03).
ELSE.
G_MESSAGE = 'Error in downloading file'(I04).
ENDIF.
MESSAGE I000(38) WITH G_MESSAGE.
ENDFORM. " DOWNLOAD_FILE
&----
*& Form CLEAR_VARIABLES
&----
Clear the values of Global Variables
----
FORM CLEAR_VARIABLES .
CLEAR: G_TITLE,
G_FILENAME,
G_PATH,
G_FULLPATH,
G_LEN,
G_SRCSTR,
Work Areas
WA_SOURCE,
WA_XML,
WA_FINAL_XML.
REFRESH: T_XML,
T_SOURCE,
T_SRCTAB,
T_FINAL_XML.
ENDFORM. " CLEAR_VARIABLES
Edited by: Minal Nampalliwar on Jan 21, 2008 6:44 AM
2008 Jan 21 5:58 AM
Hi Minal
I have invoice in form of smartforms, and i need the transmision of my forms in XML format with whole data (like Header and Item) so any FM. or this program will help me out in this process, because APMK for repots we can use ur program and we will get our output in our required manner.
Thanks & Regards
V.B.