Hi All,
Today I am going to write a new program to generate XML format file output.
It's a report program with some input selection parameters and brings out a XML file in output.
I used this program to create XML file for 'Company Sales Data', which is used to upload on government portal. I hope this will help others for creating the similar requirement.
Selection Screen
******************* Downloaded XML File Output format
REPORT ZSD_XML_DOWNLOAD.
************************************************************************
* Data Declaration *
************************************************************************
TYPE-POOLS: IXML.
TABLES: VBRK,VBRP,KNA1.
TYPES: BEGIN OF TY_DATA,
VBELN TYPE VBRK-VBELN,
VBTYP TYPE VBRK-VBTYP,
FKDAT TYPE VBRK-FKDAT,
KUNRG TYPE VBRK-KUNRG,
BUKRS TYPE VBRK-BUKRS,
POSNR TYPE VBRP-POSNR,
FKIMG TYPE VBRP-FKIMG,
VRKME TYPE VBRP-VRKME,
VGBEL TYPE VBRP-VGBEL,
MATNR TYPE VBRP-MATNR,
MATKL TYPE VBRP-MATKL,
END OF TY_DATA.
TYPES: BEGIN OF TY_OUTPUT,
BUKRS TYPE CHAR6,"VBRK-BUKRS, "Company Code
VBELN TYPE VBRK-VBELN, "Invoice
FKDAT TYPE STRING, "Invoice Date
REGIO TYPE KNA1-REGIO, "State Id
BZIRK TYPE KNVV-BZIRK, "Sales District
WHID TYPE STRING, "WareHouse Id
KUNRG TYPE VBRK-KUNRG, "Payer "Dealer Id
MATNR TYPE VBRP-MATNR, "Product
VRKME TYPE VBRP-VRKME, "Sales Unit
FKIMG TYPE VBRP-FKIMG, "Quantity
END OF TY_OUTPUT.
TYPES: BEGIN OF TY_KUNNR,
VBELN TYPE LIKP-VBELN,
KUNNR TYPE LIKP-KUNNR,
END OF TY_KUNNR.
DATA: IT_DATA TYPE STANDARD TABLE OF TY_DATA,
IT_KUNNR TYPE STANDARD TABLE OF TY_KUNNR,
IT_KNA1 TYPE STANDARD TABLE OF KNA1,
IT_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT,
WA_OUTPUT TYPE TY_OUTPUT,
WA_OUTPUT1 TYPE TY_OUTPUT,
WA_DATA TYPE TY_DATA,
WA_KUNNR TYPE TY_KUNNR,
WA_KNA1 TYPE KNA1.
DATA: IT_ZFMSCC TYPE STANDARD TABLE OF ZFMSCC,
IT_ZFMSCUST TYPE STANDARD TABLE OF ZFMSCUST,
IT_ZFMSDIST TYPE STANDARD TABLE OF ZFMSDIST,
IT_ZFMSSTATE TYPE STANDARD TABLE OF ZFMSSTATE,
IT_ZFMSWH TYPE STANDARD TABLE OF ZFMSWH,
IT_ZFMSUNIT TYPE STANDARD TABLE OF ZFMSUNIT,
WA_ZFMSCC TYPE ZFMSCC,
WA_ZFMSCUST TYPE ZFMSCUST,
WA_ZFMSSTATE TYPE ZFMSSTATE,
WA_ZFMSDIST TYPE ZFMSDIST,
WA_ZFMSWH TYPE ZFMSWH,
WA_ZFMSUNIT TYPE ZFMSUNIT.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_FKDAT FOR VBRK-FKDAT,
S_WERKS FOR VBRP-WERKS,
S_LGORT FOR VBRP-LGORT,
S_MATKL FOR VBRP-MATKL,
S_SPART FOR VBRK-SPART.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY .
SELECTION-SCREEN END OF BLOCK B2.
************************************************************************
* At Selection Screen *
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
************************************************************************
* Start of Selection *
************************************************************************
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM BUILD_OUTPUT.
PERFORM BUILD_XML_FILE.
* PERFORM DOWNLOAD_FILE.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT K~VBELN K~VBTYP K~FKDAT K~KUNRG K~BUKRS P~POSNR P~FKIMG P~VRKME P~VGBEL P~MATNR P~MATKL
INTO TABLE IT_DATA
FROM VBRK AS K
INNER JOIN VBRP AS P ON P~VBELN = K~VBELN
WHERE ( K~VBTYP = 'M' OR K~VBTYP = 'U' ) "AND ( K~VBTYP = 'M' AND P~WERKS NOT LIKE 'DP%' ) )
AND K~FKDAT IN S_FKDAT
AND K~FKSTO = SPACE
AND K~RFBSK <> 'E'
AND K~SPART IN S_SPART "Inserted 02-03-2012
AND P~WERKS IN S_WERKS
AND P~LGORT IN S_LGORT
AND P~MATKL IN S_MATKL.
IF SY-SUBRC EQ 0.
SORT IT_DATA BY VBELN POSNR.
*Get Ship to party details
SELECT VBELN KUNNR INTO TABLE IT_KUNNR
FROM LIKP
FOR ALL ENTRIES IN IT_DATA
WHERE VBELN = IT_DATA-VGBEL.
SELECT * FROM KNA1 INTO TABLE IT_KNA1
FOR ALL ENTRIES IN IT_KUNNR
WHERE KUNNR = IT_KUNNR-KUNNR.
ENDIF.
DATA: L_TABIX TYPE SY-TABIX,
L_WERKS TYPE LIKP-WERKS.
CLEAR: L_TABIX,L_WERKS.
LOOP AT IT_DATA INTO WA_DATA.
L_TABIX = SY-TABIX. CLEAR L_WERKS.
IF WA_DATA-VBTYP = 'U'.
SELECT SINGLE WERKS INTO L_WERKS
FROM LIKP
WHERE VBELN = WA_DATA-VGBEL
AND WERKS LIKE 'DP%'.
IF L_WERKS IS INITIAL.
DELETE IT_DATA INDEX L_TABIX.
CONTINUE.
ENDIF.
ELSEIF WA_DATA-VBTYP = 'M'.
SELECT SINGLE WERKS INTO L_WERKS
FROM LIPS "LIKP
WHERE VBELN = WA_DATA-VGBEL
AND WERKS NOT LIKE 'DP%'.
IF L_WERKS IS INITIAL.
DELETE IT_DATA INDEX L_TABIX.
CONTINUE.
ENDIF.
ENDIF.
MOVE-CORRESPONDING WA_DATA TO WA_OUTPUT.
READ TABLE IT_KUNNR INTO WA_KUNNR WITH KEY VBELN = WA_DATA-VGBEL.
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_KUNNR-KUNNR.
IF WA_KNA1-REGIO IS NOT INITIAL.
WA_OUTPUT-REGIO = WA_KNA1-REGIO.
ENDIF.
SELECT SINGLE BZIRK FROM KNVV INTO WA_OUTPUT-BZIRK
WHERE KUNNR = WA_KUNNR-KUNNR
AND BZIRK <> SPACE.
COLLECT WA_OUTPUT INTO IT_OUTPUT.
CLEAR WA_OUTPUT.
ENDLOOP.
IF IT_OUTPUT IS INITIAL.
MESSAGE 'No Records exist' TYPE 'I'.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_FILE .
** DATA: L_XML TYPE REF TO CL_XML_DOCUMENT.
**
*** CREATE THE XML OBJECT
** CREATE OBJECT L_XML.
**
*** CONVERT THE DATA TO XML
** CALL METHOD L_XML->CREATE_WITH_DATA( DATAOBJECT = IT_OUTPUT[] ).
**
*** CALL METHOD L_XML->CREATE_WITH_TABLE( TABLE = IT_OUTPUT[] ).
**
*** DATA IS CONVERTED TO XML; DISPLAY THE XML-DOCUMENT
** CALL METHOD L_XML->DISPLAY.
* CALL FUNCTION 'GUI_DOWNLOAD'
* EXPORTING
* FILENAME = 'C:\DATA\company_sales_data.txt'
* FILETYPE = 'ASC'
* WRITE_FIELD_SEPARATOR = ' '
* TABLES
* DATA_TAB = IT_OUTPUT
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22.
* IF SY-SUBRC <> 0.
** Implement suitable error handling here
* ELSE.
* MESSAGE 'File Downloaded successfully' TYPE 'S'.
* ENDIF.
ENDFORM. " DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*& Form BUILD_XML_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_XML_FILE .
DATA L_FILENAME TYPE STRING.
L_FILENAME = P_FILE.
TYPES: BEGIN OF XML_LINE,
DATA(256) TYPE X,
END OF XML_LINE.
DATA: L_IXML TYPE REF TO IF_IXML,
L_STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
L_OSTREAM TYPE REF TO IF_IXML_OSTREAM,
L_RENDERER TYPE REF TO IF_IXML_RENDERER,
L_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.
DATA: L_ELEMENT_COMPANYSALESLIST TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_COMPANYSALE TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_COMPANYID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_INVOICENUMBER TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_INVOIEDATE TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_STATEID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_DISTRICTID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_WAREHOUSEID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_DEALERID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_CMP_SD_LIST TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_CMP_SD TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_PRDID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_UNITID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_QUANTITY TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_FLIGHT TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_FROM TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_TO TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_DUMMY TYPE REF TO IF_IXML_ELEMENT,
L_VALUE TYPE STRING.
DATA: L_XML_TABLE TYPE TABLE OF XML_LINE,
L_XML_SIZE TYPE I,
L_RC TYPE I.
CHECK IT_OUTPUT IS NOT INITIAL.
DELETE IT_OUTPUT WHERE MATNR = SPACE.
SORT IT_OUTPUT BY VBELN REGIO BZIRK.
LOOP AT IT_OUTPUT INTO WA_OUTPUT1.
CLEAR WA_OUTPUT.
WA_OUTPUT = WA_OUTPUT1.
AT FIRST.
* Creating a ixml factory
L_IXML = CL_IXML=>CREATE( ).
* Creating the dom object model
L_DOCUMENT = L_IXML->CREATE_DOCUMENT( ).
* Fill root node with value CompanySalesList
L_ELEMENT_COMPANYSALESLIST = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySalesList'
PARENT = L_DOCUMENT ).
ENDAT.
AT NEW BZIRK.
* Fill root node with value CompanySale
L_ELEMENT_COMPANYSALE = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySale'
PARENT = L_ELEMENT_COMPANYSALESLIST ).
* Create element 'CompanyId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-BUKRS.
L_ELEMENT_COMPANYID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'companyId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'InvoiceNumber ' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-VBELN.
L_ELEMENT_INVOICENUMBER = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'invoiceNumber'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'InvoiceDate ' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-FKDAT.
L_ELEMENT_INVOIEDATE = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'invoiceDate'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'StateID' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-REGIO.
L_ELEMENT_STATEID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'stateId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'DistrictId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-BZIRK.
L_ELEMENT_DISTRICTID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'districtId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'WarehouseId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-WHID.
L_ELEMENT_WAREHOUSEID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'warehouseId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'dealerId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-KUNRG.
L_ELEMENT_DEALERID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'dealerId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'CompanySaleDetailsList' as child of 'CompanySale'
L_ELEMENT_CMP_SD_LIST = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySaleDetailsList'
PARENT = L_ELEMENT_COMPANYSALE ).
* ENDAT.
*
* AT NEW MATNR.
* Create element 'CompanySaleDetails' as child of 'CompanySale'
L_ELEMENT_CMP_SD = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySaleDetails'
PARENT = L_ELEMENT_CMP_SD_LIST ).
* Create element 'companyId' as child of 'CompanySaleDetails'
L_VALUE = WA_OUTPUT-BUKRS.
L_ELEMENT_COMPANYID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'companyId'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
L_VALUE = WA_OUTPUT-MATNR.
L_ELEMENT_PRDID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'productId'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
L_VALUE = WA_OUTPUT-VRKME.
L_ELEMENT_UNITID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'unitId'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
L_VALUE = WA_OUTPUT-FKIMG.
L_ELEMENT_PRDID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'quantity'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
ENDAT.
ENDLOOP.
* Creating a stream factory
L_STREAMFACTORY = L_IXML->CREATE_STREAM_FACTORY( ).
* Connect internal XML table to stream factory
L_OSTREAM = L_STREAMFACTORY->CREATE_OSTREAM_ITABLE( TABLE = L_XML_TABLE ).
* Rendering the document
L_RENDERER = L_IXML->CREATE_RENDERER( OSTREAM = L_OSTREAM
DOCUMENT = L_DOCUMENT ).
L_RC = L_RENDERER->RENDER( ).
* Saving the XML document
L_XML_SIZE = L_OSTREAM->GET_NUM_WRITTEN_RAW( ).
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = L_XML_SIZE
FILENAME = L_FILENAME "'c:\data\companysalesdata.xml'
FILETYPE = 'BIN'
CHANGING
DATA_TAB = L_XML_TABLE
EXCEPTIONS
OTHERS = 24.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
MESSAGE 'File Downloaded successfully' TYPE 'S'.
ENDIF.
ENDFORM. " BUILD_XML_FILE
*&---------------------------------------------------------------------*
*& Form BUILD_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_OUTPUT .
CHECK IT_OUTPUT IS NOT INITIAL.
* SELECT * FROM ZFMSCC INTO TABLE IT_ZFMSCC
* FOR ALL ENTRIES IN IT_OUTPUT
* WHERE SAP_COMPANY_CODE = IT_OUTPUT-BUKRS.
SELECT * FROM ZFMSCUST INTO TABLE IT_ZFMSCUST
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_CUSTOMER = IT_OUTPUT-KUNRG
AND DISTRICT = IT_OUTPUT-BZIRK. "Inserted 01-03-2012
SELECT * FROM ZFMSSTATE INTO TABLE IT_ZFMSSTATE
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_STATE = IT_OUTPUT-REGIO.
SELECT * FROM ZFMSDIST INTO TABLE IT_ZFMSDIST
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_DISTRICT = IT_OUTPUT-BZIRK.
SELECT * FROM ZFMSUNIT INTO TABLE IT_ZFMSUNIT
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_UNIT = IT_OUTPUT-VRKME.
SELECT * FROM ZFMSWH INTO TABLE IT_ZFMSWH
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_MATERIAL = IT_OUTPUT-MATNR.
DATA: L_DATE TYPE CHAR10.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-VBELN CHANGING WA_OUTPUT-VBELN.
CLEAR L_DATE.
L_DATE+0(2) = WA_OUTPUT-FKDAT+6(2).
L_DATE+2(1) = '/'.
L_DATE+3(2) = WA_OUTPUT-FKDAT+4(2).
L_DATE+5(1) = '/'.
L_DATE+6(4) = WA_OUTPUT-FKDAT+0(4).
WA_OUTPUT-FKDAT = L_DATE.
* READ TABLE IT_ZFMSCC INTO WA_ZFMSCC
* WITH KEY SAP_COMPANY_CODE = WA_OUTPUT-BUKRS.
* IF SY-SUBRC EQ 0.
* WA_OUTPUT-BUKRS = WA_ZFMSCC-FMS_COMPANY_CODE.
* PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-BUKRS CHANGING WA_OUTPUT-BUKRS.
* ELSE.
* CLEAR WA_OUTPUT-BUKRS.
* ENDIF.
SELECT SINGLE FMS_COMPANY_CODE INTO WA_OUTPUT-BUKRS
FROM ZFMSCC
WHERE SAP_COMPANY_CODE = WA_OUTPUT-BUKRS.
IF SY-SUBRC EQ 0.
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-BUKRS CHANGING WA_OUTPUT-BUKRS.
ENDIF.
READ TABLE IT_ZFMSCUST INTO WA_ZFMSCUST
WITH KEY SAP_CUSTOMER = WA_OUTPUT-KUNRG
DISTRICT = WA_OUTPUT-BZIRK. "Inserted 01-03-2012
IF SY-SUBRC EQ 0.
WA_OUTPUT-KUNRG = WA_ZFMSCUST-FMS_CUSTOMER.
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-KUNRG CHANGING WA_OUTPUT-KUNRG.
ELSE.
CLEAR WA_OUTPUT-KUNRG.
ENDIF.
READ TABLE IT_ZFMSSTATE INTO WA_ZFMSSTATE
WITH KEY SAP_STATE = WA_OUTPUT-REGIO.
IF SY-SUBRC EQ 0.
WA_OUTPUT-REGIO = WA_ZFMSSTATE-FMS_STATE.
ELSE.
CLEAR WA_OUTPUT-REGIO.
ENDIF.
READ TABLE IT_ZFMSDIST INTO WA_ZFMSDIST
WITH KEY SAP_DISTRICT = WA_OUTPUT-BZIRK.
IF SY-SUBRC EQ 0 .
WA_OUTPUT-BZIRK = WA_ZFMSDIST-FMS_DISTRICT.
ELSE.
CLEAR WA_OUTPUT-BZIRK.
ENDIF.
READ TABLE IT_ZFMSUNIT INTO WA_ZFMSUNIT
WITH KEY SAP_UNIT = WA_OUTPUT-VRKME.
IF SY-SUBRC EQ 0.
WA_OUTPUT-VRKME = WA_ZFMSUNIT-FMS_UNIT.
ELSE.
CLEAR WA_OUTPUT-VRKME.
ENDIF.
READ TABLE IT_ZFMSWH INTO WA_ZFMSWH
WITH KEY SAP_MATERIAL = WA_OUTPUT-MATNR.
IF SY-SUBRC EQ 0.
WA_OUTPUT-MATNR = WA_ZFMSWH-FMS_MAT_ID. "FMS_MATERIAL. "Changed 02-03-2012
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-MATNR CHANGING WA_OUTPUT-MATNR.
ELSE.
CLEAR WA_OUTPUT-MATNR.
ENDIF.
CONCATENATE WA_OUTPUT-BUKRS WA_OUTPUT-BZIRK INTO
WA_OUTPUT-WHID.
MODIFY IT_OUTPUT FROM WA_OUTPUT.
ENDLOOP.
ENDFORM. " BUILD_OUTPUT
*&---------------------------------------------------------------------*
*& Form CONVERSION_EXIT_ALPHA_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_OUTPUT_BUKRS text
* <--P_WA_OUTPUT_BUKRS text
*----------------------------------------------------------------------*
FORM CONVERSION_EXIT_ALPHA_OUTPUT USING P_IN
CHANGING P_OUT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = P_IN
IMPORTING
OUTPUT = P_OUT.
ENDFORM. " CONVERSION_EXIT_ALPHA_OUTPUT
Today I am going to write a new program to generate XML format file output.
It's a report program with some input selection parameters and brings out a XML file in output.
I used this program to create XML file for 'Company Sales Data', which is used to upload on government portal. I hope this will help others for creating the similar requirement.
Selection Screen
******************* Downloaded XML File Output format
REPORT ZSD_XML_DOWNLOAD.
************************************************************************
* Data Declaration *
************************************************************************
TYPE-POOLS: IXML.
TABLES: VBRK,VBRP,KNA1.
TYPES: BEGIN OF TY_DATA,
VBELN TYPE VBRK-VBELN,
VBTYP TYPE VBRK-VBTYP,
FKDAT TYPE VBRK-FKDAT,
KUNRG TYPE VBRK-KUNRG,
BUKRS TYPE VBRK-BUKRS,
POSNR TYPE VBRP-POSNR,
FKIMG TYPE VBRP-FKIMG,
VRKME TYPE VBRP-VRKME,
VGBEL TYPE VBRP-VGBEL,
MATNR TYPE VBRP-MATNR,
MATKL TYPE VBRP-MATKL,
END OF TY_DATA.
TYPES: BEGIN OF TY_OUTPUT,
BUKRS TYPE CHAR6,"VBRK-BUKRS, "Company Code
VBELN TYPE VBRK-VBELN, "Invoice
FKDAT TYPE STRING, "Invoice Date
REGIO TYPE KNA1-REGIO, "State Id
BZIRK TYPE KNVV-BZIRK, "Sales District
WHID TYPE STRING, "WareHouse Id
KUNRG TYPE VBRK-KUNRG, "Payer "Dealer Id
MATNR TYPE VBRP-MATNR, "Product
VRKME TYPE VBRP-VRKME, "Sales Unit
FKIMG TYPE VBRP-FKIMG, "Quantity
END OF TY_OUTPUT.
TYPES: BEGIN OF TY_KUNNR,
VBELN TYPE LIKP-VBELN,
KUNNR TYPE LIKP-KUNNR,
END OF TY_KUNNR.
DATA: IT_DATA TYPE STANDARD TABLE OF TY_DATA,
IT_KUNNR TYPE STANDARD TABLE OF TY_KUNNR,
IT_KNA1 TYPE STANDARD TABLE OF KNA1,
IT_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT,
WA_OUTPUT TYPE TY_OUTPUT,
WA_OUTPUT1 TYPE TY_OUTPUT,
WA_DATA TYPE TY_DATA,
WA_KUNNR TYPE TY_KUNNR,
WA_KNA1 TYPE KNA1.
DATA: IT_ZFMSCC TYPE STANDARD TABLE OF ZFMSCC,
IT_ZFMSCUST TYPE STANDARD TABLE OF ZFMSCUST,
IT_ZFMSDIST TYPE STANDARD TABLE OF ZFMSDIST,
IT_ZFMSSTATE TYPE STANDARD TABLE OF ZFMSSTATE,
IT_ZFMSWH TYPE STANDARD TABLE OF ZFMSWH,
IT_ZFMSUNIT TYPE STANDARD TABLE OF ZFMSUNIT,
WA_ZFMSCC TYPE ZFMSCC,
WA_ZFMSCUST TYPE ZFMSCUST,
WA_ZFMSSTATE TYPE ZFMSSTATE,
WA_ZFMSDIST TYPE ZFMSDIST,
WA_ZFMSWH TYPE ZFMSWH,
WA_ZFMSUNIT TYPE ZFMSUNIT.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_FKDAT FOR VBRK-FKDAT,
S_WERKS FOR VBRP-WERKS,
S_LGORT FOR VBRP-LGORT,
S_MATKL FOR VBRP-MATKL,
S_SPART FOR VBRK-SPART.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY .
SELECTION-SCREEN END OF BLOCK B2.
************************************************************************
* At Selection Screen *
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
************************************************************************
* Start of Selection *
************************************************************************
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM BUILD_OUTPUT.
PERFORM BUILD_XML_FILE.
* PERFORM DOWNLOAD_FILE.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT K~VBELN K~VBTYP K~FKDAT K~KUNRG K~BUKRS P~POSNR P~FKIMG P~VRKME P~VGBEL P~MATNR P~MATKL
INTO TABLE IT_DATA
FROM VBRK AS K
INNER JOIN VBRP AS P ON P~VBELN = K~VBELN
WHERE ( K~VBTYP = 'M' OR K~VBTYP = 'U' ) "AND ( K~VBTYP = 'M' AND P~WERKS NOT LIKE 'DP%' ) )
AND K~FKDAT IN S_FKDAT
AND K~FKSTO = SPACE
AND K~RFBSK <> 'E'
AND K~SPART IN S_SPART "Inserted 02-03-2012
AND P~WERKS IN S_WERKS
AND P~LGORT IN S_LGORT
AND P~MATKL IN S_MATKL.
IF SY-SUBRC EQ 0.
SORT IT_DATA BY VBELN POSNR.
*Get Ship to party details
SELECT VBELN KUNNR INTO TABLE IT_KUNNR
FROM LIKP
FOR ALL ENTRIES IN IT_DATA
WHERE VBELN = IT_DATA-VGBEL.
SELECT * FROM KNA1 INTO TABLE IT_KNA1
FOR ALL ENTRIES IN IT_KUNNR
WHERE KUNNR = IT_KUNNR-KUNNR.
ENDIF.
DATA: L_TABIX TYPE SY-TABIX,
L_WERKS TYPE LIKP-WERKS.
CLEAR: L_TABIX,L_WERKS.
LOOP AT IT_DATA INTO WA_DATA.
L_TABIX = SY-TABIX. CLEAR L_WERKS.
IF WA_DATA-VBTYP = 'U'.
SELECT SINGLE WERKS INTO L_WERKS
FROM LIKP
WHERE VBELN = WA_DATA-VGBEL
AND WERKS LIKE 'DP%'.
IF L_WERKS IS INITIAL.
DELETE IT_DATA INDEX L_TABIX.
CONTINUE.
ENDIF.
ELSEIF WA_DATA-VBTYP = 'M'.
SELECT SINGLE WERKS INTO L_WERKS
FROM LIPS "LIKP
WHERE VBELN = WA_DATA-VGBEL
AND WERKS NOT LIKE 'DP%'.
IF L_WERKS IS INITIAL.
DELETE IT_DATA INDEX L_TABIX.
CONTINUE.
ENDIF.
ENDIF.
MOVE-CORRESPONDING WA_DATA TO WA_OUTPUT.
READ TABLE IT_KUNNR INTO WA_KUNNR WITH KEY VBELN = WA_DATA-VGBEL.
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_KUNNR-KUNNR.
IF WA_KNA1-REGIO IS NOT INITIAL.
WA_OUTPUT-REGIO = WA_KNA1-REGIO.
ENDIF.
SELECT SINGLE BZIRK FROM KNVV INTO WA_OUTPUT-BZIRK
WHERE KUNNR = WA_KUNNR-KUNNR
AND BZIRK <> SPACE.
COLLECT WA_OUTPUT INTO IT_OUTPUT.
CLEAR WA_OUTPUT.
ENDLOOP.
IF IT_OUTPUT IS INITIAL.
MESSAGE 'No Records exist' TYPE 'I'.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_FILE .
** DATA: L_XML TYPE REF TO CL_XML_DOCUMENT.
**
*** CREATE THE XML OBJECT
** CREATE OBJECT L_XML.
**
*** CONVERT THE DATA TO XML
** CALL METHOD L_XML->CREATE_WITH_DATA( DATAOBJECT = IT_OUTPUT[] ).
**
*** CALL METHOD L_XML->CREATE_WITH_TABLE( TABLE = IT_OUTPUT[] ).
**
*** DATA IS CONVERTED TO XML; DISPLAY THE XML-DOCUMENT
** CALL METHOD L_XML->DISPLAY.
* CALL FUNCTION 'GUI_DOWNLOAD'
* EXPORTING
* FILENAME = 'C:\DATA\company_sales_data.txt'
* FILETYPE = 'ASC'
* WRITE_FIELD_SEPARATOR = ' '
* TABLES
* DATA_TAB = IT_OUTPUT
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22.
* IF SY-SUBRC <> 0.
** Implement suitable error handling here
* ELSE.
* MESSAGE 'File Downloaded successfully' TYPE 'S'.
* ENDIF.
ENDFORM. " DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*& Form BUILD_XML_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_XML_FILE .
DATA L_FILENAME TYPE STRING.
L_FILENAME = P_FILE.
TYPES: BEGIN OF XML_LINE,
DATA(256) TYPE X,
END OF XML_LINE.
DATA: L_IXML TYPE REF TO IF_IXML,
L_STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
L_OSTREAM TYPE REF TO IF_IXML_OSTREAM,
L_RENDERER TYPE REF TO IF_IXML_RENDERER,
L_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.
DATA: L_ELEMENT_COMPANYSALESLIST TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_COMPANYSALE TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_COMPANYID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_INVOICENUMBER TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_INVOIEDATE TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_STATEID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_DISTRICTID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_WAREHOUSEID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_DEALERID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_CMP_SD_LIST TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_CMP_SD TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_PRDID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_UNITID TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_QUANTITY TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_FLIGHT TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_FROM TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_TO TYPE REF TO IF_IXML_ELEMENT,
L_ELEMENT_DUMMY TYPE REF TO IF_IXML_ELEMENT,
L_VALUE TYPE STRING.
DATA: L_XML_TABLE TYPE TABLE OF XML_LINE,
L_XML_SIZE TYPE I,
L_RC TYPE I.
CHECK IT_OUTPUT IS NOT INITIAL.
DELETE IT_OUTPUT WHERE MATNR = SPACE.
SORT IT_OUTPUT BY VBELN REGIO BZIRK.
LOOP AT IT_OUTPUT INTO WA_OUTPUT1.
CLEAR WA_OUTPUT.
WA_OUTPUT = WA_OUTPUT1.
AT FIRST.
* Creating a ixml factory
L_IXML = CL_IXML=>CREATE( ).
* Creating the dom object model
L_DOCUMENT = L_IXML->CREATE_DOCUMENT( ).
* Fill root node with value CompanySalesList
L_ELEMENT_COMPANYSALESLIST = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySalesList'
PARENT = L_DOCUMENT ).
ENDAT.
AT NEW BZIRK.
* Fill root node with value CompanySale
L_ELEMENT_COMPANYSALE = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySale'
PARENT = L_ELEMENT_COMPANYSALESLIST ).
* Create element 'CompanyId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-BUKRS.
L_ELEMENT_COMPANYID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'companyId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'InvoiceNumber ' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-VBELN.
L_ELEMENT_INVOICENUMBER = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'invoiceNumber'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'InvoiceDate ' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-FKDAT.
L_ELEMENT_INVOIEDATE = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'invoiceDate'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'StateID' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-REGIO.
L_ELEMENT_STATEID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'stateId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'DistrictId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-BZIRK.
L_ELEMENT_DISTRICTID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'districtId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'WarehouseId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-WHID.
L_ELEMENT_WAREHOUSEID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'warehouseId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'dealerId' as child of 'CompanySale'
L_VALUE = WA_OUTPUT-KUNRG.
L_ELEMENT_DEALERID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'dealerId'
VALUE = L_VALUE
PARENT = L_ELEMENT_COMPANYSALE ).
* Create element 'CompanySaleDetailsList' as child of 'CompanySale'
L_ELEMENT_CMP_SD_LIST = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySaleDetailsList'
PARENT = L_ELEMENT_COMPANYSALE ).
* ENDAT.
*
* AT NEW MATNR.
* Create element 'CompanySaleDetails' as child of 'CompanySale'
L_ELEMENT_CMP_SD = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'CompanySaleDetails'
PARENT = L_ELEMENT_CMP_SD_LIST ).
* Create element 'companyId' as child of 'CompanySaleDetails'
L_VALUE = WA_OUTPUT-BUKRS.
L_ELEMENT_COMPANYID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'companyId'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
L_VALUE = WA_OUTPUT-MATNR.
L_ELEMENT_PRDID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'productId'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
L_VALUE = WA_OUTPUT-VRKME.
L_ELEMENT_UNITID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'unitId'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
L_VALUE = WA_OUTPUT-FKIMG.
L_ELEMENT_PRDID = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(
NAME = 'quantity'
VALUE = L_VALUE
PARENT = L_ELEMENT_CMP_SD ).
ENDAT.
ENDLOOP.
* Creating a stream factory
L_STREAMFACTORY = L_IXML->CREATE_STREAM_FACTORY( ).
* Connect internal XML table to stream factory
L_OSTREAM = L_STREAMFACTORY->CREATE_OSTREAM_ITABLE( TABLE = L_XML_TABLE ).
* Rendering the document
L_RENDERER = L_IXML->CREATE_RENDERER( OSTREAM = L_OSTREAM
DOCUMENT = L_DOCUMENT ).
L_RC = L_RENDERER->RENDER( ).
* Saving the XML document
L_XML_SIZE = L_OSTREAM->GET_NUM_WRITTEN_RAW( ).
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = L_XML_SIZE
FILENAME = L_FILENAME "'c:\data\companysalesdata.xml'
FILETYPE = 'BIN'
CHANGING
DATA_TAB = L_XML_TABLE
EXCEPTIONS
OTHERS = 24.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
MESSAGE 'File Downloaded successfully' TYPE 'S'.
ENDIF.
ENDFORM. " BUILD_XML_FILE
*&---------------------------------------------------------------------*
*& Form BUILD_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_OUTPUT .
CHECK IT_OUTPUT IS NOT INITIAL.
* SELECT * FROM ZFMSCC INTO TABLE IT_ZFMSCC
* FOR ALL ENTRIES IN IT_OUTPUT
* WHERE SAP_COMPANY_CODE = IT_OUTPUT-BUKRS.
SELECT * FROM ZFMSCUST INTO TABLE IT_ZFMSCUST
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_CUSTOMER = IT_OUTPUT-KUNRG
AND DISTRICT = IT_OUTPUT-BZIRK. "Inserted 01-03-2012
SELECT * FROM ZFMSSTATE INTO TABLE IT_ZFMSSTATE
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_STATE = IT_OUTPUT-REGIO.
SELECT * FROM ZFMSDIST INTO TABLE IT_ZFMSDIST
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_DISTRICT = IT_OUTPUT-BZIRK.
SELECT * FROM ZFMSUNIT INTO TABLE IT_ZFMSUNIT
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_UNIT = IT_OUTPUT-VRKME.
SELECT * FROM ZFMSWH INTO TABLE IT_ZFMSWH
FOR ALL ENTRIES IN IT_OUTPUT
WHERE SAP_MATERIAL = IT_OUTPUT-MATNR.
DATA: L_DATE TYPE CHAR10.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-VBELN CHANGING WA_OUTPUT-VBELN.
CLEAR L_DATE.
L_DATE+0(2) = WA_OUTPUT-FKDAT+6(2).
L_DATE+2(1) = '/'.
L_DATE+3(2) = WA_OUTPUT-FKDAT+4(2).
L_DATE+5(1) = '/'.
L_DATE+6(4) = WA_OUTPUT-FKDAT+0(4).
WA_OUTPUT-FKDAT = L_DATE.
* READ TABLE IT_ZFMSCC INTO WA_ZFMSCC
* WITH KEY SAP_COMPANY_CODE = WA_OUTPUT-BUKRS.
* IF SY-SUBRC EQ 0.
* WA_OUTPUT-BUKRS = WA_ZFMSCC-FMS_COMPANY_CODE.
* PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-BUKRS CHANGING WA_OUTPUT-BUKRS.
* ELSE.
* CLEAR WA_OUTPUT-BUKRS.
* ENDIF.
SELECT SINGLE FMS_COMPANY_CODE INTO WA_OUTPUT-BUKRS
FROM ZFMSCC
WHERE SAP_COMPANY_CODE = WA_OUTPUT-BUKRS.
IF SY-SUBRC EQ 0.
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-BUKRS CHANGING WA_OUTPUT-BUKRS.
ENDIF.
READ TABLE IT_ZFMSCUST INTO WA_ZFMSCUST
WITH KEY SAP_CUSTOMER = WA_OUTPUT-KUNRG
DISTRICT = WA_OUTPUT-BZIRK. "Inserted 01-03-2012
IF SY-SUBRC EQ 0.
WA_OUTPUT-KUNRG = WA_ZFMSCUST-FMS_CUSTOMER.
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-KUNRG CHANGING WA_OUTPUT-KUNRG.
ELSE.
CLEAR WA_OUTPUT-KUNRG.
ENDIF.
READ TABLE IT_ZFMSSTATE INTO WA_ZFMSSTATE
WITH KEY SAP_STATE = WA_OUTPUT-REGIO.
IF SY-SUBRC EQ 0.
WA_OUTPUT-REGIO = WA_ZFMSSTATE-FMS_STATE.
ELSE.
CLEAR WA_OUTPUT-REGIO.
ENDIF.
READ TABLE IT_ZFMSDIST INTO WA_ZFMSDIST
WITH KEY SAP_DISTRICT = WA_OUTPUT-BZIRK.
IF SY-SUBRC EQ 0 .
WA_OUTPUT-BZIRK = WA_ZFMSDIST-FMS_DISTRICT.
ELSE.
CLEAR WA_OUTPUT-BZIRK.
ENDIF.
READ TABLE IT_ZFMSUNIT INTO WA_ZFMSUNIT
WITH KEY SAP_UNIT = WA_OUTPUT-VRKME.
IF SY-SUBRC EQ 0.
WA_OUTPUT-VRKME = WA_ZFMSUNIT-FMS_UNIT.
ELSE.
CLEAR WA_OUTPUT-VRKME.
ENDIF.
READ TABLE IT_ZFMSWH INTO WA_ZFMSWH
WITH KEY SAP_MATERIAL = WA_OUTPUT-MATNR.
IF SY-SUBRC EQ 0.
WA_OUTPUT-MATNR = WA_ZFMSWH-FMS_MAT_ID. "FMS_MATERIAL. "Changed 02-03-2012
PERFORM CONVERSION_EXIT_ALPHA_OUTPUT USING WA_OUTPUT-MATNR CHANGING WA_OUTPUT-MATNR.
ELSE.
CLEAR WA_OUTPUT-MATNR.
ENDIF.
CONCATENATE WA_OUTPUT-BUKRS WA_OUTPUT-BZIRK INTO
WA_OUTPUT-WHID.
MODIFY IT_OUTPUT FROM WA_OUTPUT.
ENDLOOP.
ENDFORM. " BUILD_OUTPUT
*&---------------------------------------------------------------------*
*& Form CONVERSION_EXIT_ALPHA_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_OUTPUT_BUKRS text
* <--P_WA_OUTPUT_BUKRS text
*----------------------------------------------------------------------*
FORM CONVERSION_EXIT_ALPHA_OUTPUT USING P_IN
CHANGING P_OUT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = P_IN
IMPORTING
OUTPUT = P_OUT.
ENDFORM. " CONVERSION_EXIT_ALPHA_OUTPUT
No comments:
Post a Comment