Posted: Mon Sep 10, 2007 8:21 pm Post subject: Show EDI status
Code:
*Includes: ZFORMS
*&---------------------------------------------------------------------*
*& Report Z_REPORT_ZTABLE *
*&---------------------------------------------------------------------*
* Author: Kevin Wilson Date: 15th September, 2000
* Detail: This program loops through the sales order table, taking
* relevant data and storing it in the ZTABLE table. The
* ZTABLE table stores the status of an order in the EDI
* process.
*&---------------------------------------------------------------------*
REPORT Z_REPORT_ZTABLE LINE-SIZE 160.
*--- INTERNAL TABLE DEFINITIONS ----------------------------------------
* ITAB_SO_EXTRA stores the key of ITAB_SO as well as additional fields
* that may be required down the line. eg. Material number and billing
* block.
TYPES: BEGIN OF ITAB_SO_EXTRA_TYPE,
VBELN LIKE VBAK-VBELN, "Sales Order #
BSTNK LIKE VBAK-BSTNK, "PO #
POSNR LIKE VBAP-POSNR, "Sales Order Line #
FAKSP LIKE VBAP-FAKSP, "Line Item Billing block
MATNR LIKE VBAP-MATNR, "Material number
END OF ITAB_SO_EXTRA_TYPE.
* Create an internal table to store the invoice numbers
* of those invoices that do not have INVOIC Idocs attached to them.
* i.e. The ZD01 output was not created for some reason.
TYPES: BEGIN OF TITAB_TYPE,
O810 LIKE ZTABLE-O810NO,
END OF TITAB_TYPE.
* Internal table definitions containing the data entries for ZTABLE
DATA: ITAB_SO LIKE ZTABLE OCCURS 20000 WITH HEADER LINE,
ITAB_SO_EXTRA TYPE ITAB_SO_EXTRA_TYPE
OCCURS 20000 WITH HEADER LINE.
* Internal table definitions containing invoice numbers that need to be
* saved in order to generate the ZD01 output.
DATA: TITAB TYPE TITAB_TYPE OCCURS 100 WITH HEADER LINE.
* Column names required for file download.
DATA: BEGIN OF T_COLNAMES OCCURS 10,
NAME(15), "Column names for download
END OF T_COLNAMES.
*--- DATA DEFINITIONS --------------------------------------------------
DATA: E1EDP26 TYPE E1EDP26,
E1EDP01 TYPE E1EDP01, "Line item segment
T_POSNR LIKE VBAP-POSNR, "Line item number
INVOICE_FLAG(1), "Is there an invoice? Y/N
DELIVERY_FLAG(1), "Is there a delivery? Y/N
FIELD_NAME(30), "Check for line selection on field
T_IDOC LIKE EDIDC-DOCNUM, "Store IDoc number for line selectn
T_STAT LIKE ZTABLE-I824856STAT."Temporary 824 status
*--- CONSTANT DEFINITIONS --- FOR CO. A -------------------------------
CONSTANTS: C_SPART_12 LIKE VBAK-SPART VALUE '12', "Division 12
C_AUART_ZEDI LIKE VBAK-AUART VALUE 'ZEDI'. "Doc type ZEDI
*--- SELECTION OPTIONS -------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK SO WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,"Sales order number
S_ERDAT FOR VBAK-ERDAT,"Sales order date
S_KUNNR FOR VBPA-KUNNR."Ship to partner
SELECTION-SCREEN END OF BLOCK SO.
SELECTION-SCREEN BEGIN OF BLOCK UP WITH FRAME TITLE TEXT-002.
PARAMETERS: P_UPD_Y RADIOBUTTON GROUP UPD, "Update table
P_UPD_N RADIOBUTTON GROUP UPD. "Don't update table
SELECTION-SCREEN END OF BLOCK UP.
SELECTION-SCREEN BEGIN OF BLOCK G2 WITH FRAME TITLE TEXT-011.
PARAMETERS: P_VIEW RADIOBUTTON GROUP L1, "View
P_DOWN RADIOBUTTON GROUP L1, "Download
P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\ZTABLE.XLS'.
SELECTION-SCREEN END OF BLOCK G2.
AT SELECTION-SCREEN ON P_FILE.
* If download is checked, but no file name is entered, error
IF P_DOWN EQ 'X' AND P_FILE EQ SPACE.
MESSAGE E999(B1) WITH TEXT-014.
ENDIF.
*--- INCLUDES ----------------------------------------------------------
INCLUDE Z_FORMS.
*--- SELECTION ---------------------------------------------------------
START-OF-SELECTION.
IF P_UPD_Y EQ 'X'. "Update ZTABLE table
SELECT VBELN ERDAT BSTNK FROM VBAK
INTO (VBAK-VBELN, VBAK-ERDAT, VBAK-BSTNK)
WHERE VBELN IN S_VBELN
AND ERDAT IN S_ERDAT
AND SPART = C_SPART_12
AND AUART = C_AUART_ZEDI.
* Populate the internal table with the relevant data
PERFORM UPDATE_ITAB_SO
USING VBAK-VBELN
VBAK-ERDAT
VBAK-BSTNK.
ENDSELECT. "Loop through selected orders for updating itab
IF SY-SUBRC NE 0.
MESSAGE I999(B1) WITH TEXT-003. "No sales orders found in range
ELSE.
* Perform an update on the database table ZTABLE using ITAB_SO
PERFORM UPDATE_ZTABLE
TABLES ITAB_SO.
* Print ITAB_SO and ITAB_SO_EXTRA contents to the screen filtering out
* customers not selected via the selection screen
PERFORM PRINT_ITAB
TABLES ITAB_SO
ITAB_SO_EXTRA.
ENDIF. "sy-subrc check on sales order selection
ELSE. "The user has requested to view the table and not do update
REFRESH: ITAB_SO_EXTRA, ITAB_SO.
CLEAR: ITAB_SO_EXTRA, ITAB_SO.
SELECT * INTO TABLE ITAB_SO FROM ZTABLE
WHERE VBELN IN S_VBELN AND
DATUM IN S_ERDAT.
IF SY-SUBRC = 0.
LOOP AT ITAB_SO.
* We need to see if the order we have is a CO. A order. A CO. A order
* is uniquely identified with Division = 12 and Order type = ZEDI
SELECT SINGLE SPART AUART FROM VBAK INTO (VBAK-SPART, VBAK-AUART)
WHERE VBELN = ITAB_SO-VBELN.
IF SY-SUBRC = 0.
* Check for CO. A order
IF VBAK-SPART = C_SPART_12 AND VBAK-AUART = C_AUART_ZEDI.
T_POSNR = ITAB_SO-POSNR DIV 10.
SELECT MATNR FAKSP FROM VBAP
INTO (ITAB_SO_EXTRA-MATNR,
ITAB_SO_EXTRA-FAKSP)
WHERE VBELN = ITAB_SO-VBELN AND
POSNR = T_POSNR.
ITAB_SO_EXTRA-VBELN = ITAB_SO-VBELN.
ITAB_SO_EXTRA-POSNR = ITAB_SO-POSNR.
ITAB_SO_EXTRA-BSTNK = ITAB_SO-BSTKD.
APPEND ITAB_SO_EXTRA.
ENDSELECT. "Update extra details
ENDIF. "Check for CO. A orders with DIV=12 & Ord Type=ZEDI
ENDIF. "Sy-subrc check on lookup for DIV and Ord Type
ENDLOOP. "ITAB_SO internal table loop
* Print ITAB_SO and ITAB_SO_EXTRA contents to the screen filtering out
* customers not selected via the selection screen
PERFORM PRINT_ITAB
TABLES ITAB_SO
ITAB_SO_EXTRA.
ELSE. "No entries were found in ITAB_SO
MESSAGE I999(B1) WITH TEXT-005. "No entries in ITAB_SO!
ENDIF.
ENDIF.
* Loop through the internal table set up to store the invoice numbers
* of those invoices that do not have INVOIC Idocs attached to them.
PERFORM SAVE_BILLING_DOC TABLES TITAB.
END-OF-SELECTION.
* --- EVENT : AT LINE SELECTION ---
AT LINE-SELECTION.
* Return the field that the user clicked on
GET CURSOR FIELD FIELD_NAME.
CASE FIELD_NAME.
* Clicked on message from 824
WHEN 'ITAB_SO-I824810NOTE' OR 'ITAB_SO-I824856NOTE'.
IF T_IDOC <> ''.
IF T_STAT = 'R'.
* Return the full detail of the error using report Z_LIST_IDOC_824
SUBMIT Z_LIST_IDOC_824 WITH I_DOCN = T_IDOC AND RETURN.
ELSE.
MESSAGE I999(B1) WITH TEXT-013."IDoc not rejected
ENDIF.
ELSE.
MESSAGE I999(B1) WITH TEXT-012."No IDoc
ENDIF.
* Clicked on Invoice number
WHEN 'ITAB_SO-O810NO'.
IF ITAB_SO-O810NO <> ''.
SET PARAMETER ID 'VF' FIELD ITAB_SO-O810NO.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN. "View Invoice
ELSE.
MESSAGE I999(B1) WITH TEXT-008."Click on invoice
ENDIF.
* Clicked on delivery number
WHEN 'ITAB_SO-O856NO'.
IF ITAB_SO-O856NO <> ''.
SET PARAMETER ID 'VL' FIELD ITAB_SO-O856NO.
CALL TRANSACTION 'VL03' AND SKIP FIRST SCREEN. "View delivery
ELSE.
MESSAGE I999(B1) WITH TEXT-010."Click on Delivery
ENDIF.
* Clicked on Sales Order number
WHEN 'ITAB_SO-VBELN'.
SET PARAMETER ID 'AUN' FIELD ITAB_SO-VBELN.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. "View Sales Order
* DESADV Idoc # clicked
WHEN 'ITAB_SO-O856DOCNUM'.
IF ITAB_SO-O856DOCNUM <> ''.
MOVE ITAB_SO-O856DOCNUM TO T_IDOC.
CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Dsiplay Idoc
EXPORTING
DOCNUM = T_IDOC
TREE_DISPLAY = 'Y'
EXCEPTIONS
NO_DATA_RECORD_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc.
ENDIF.
ELSE.
MESSAGE I999(B1) WITH TEXT-007."Click on IDoc.
ENDIF.
* INVOIC Idoc # clicked
WHEN 'ITAB_SO-O810DOCNUM'.
IF ITAB_SO-O810DOCNUM <> ''.
MOVE ITAB_SO-O810DOCNUM TO T_IDOC.
CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display an IDoc.
EXPORTING
DOCNUM = T_IDOC
TREE_DISPLAY = 'Y'
EXCEPTIONS
NO_DATA_RECORD_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc.
ENDIF.
ELSE.
MESSAGE I999(B1) WITH TEXT-007."Click on IDoc.
ENDIF.
* ZAPPADV810 IDoc # clicked
WHEN 'ITAB_SO-I824810DOCNUM'.
IF ITAB_SO-I824810DOCNUM <> ''.
MOVE ITAB_SO-I824810DOCNUM TO T_IDOC.
CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display IDoc
EXPORTING
DOCNUM = T_IDOC
TREE_DISPLAY = 'Y'
EXCEPTIONS
NO_DATA_RECORD_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc.
ENDIF.
ELSE.
MESSAGE I999(B1) WITH TEXT-007."Click on IDoc.
ENDIF.
* ZAPPADV856 IDoc # clicked
WHEN 'ITAB_SO-I824856DOCNUM'.
IF ITAB_SO-I824856DOCNUM <> ''.
MOVE ITAB_SO-I824856DOCNUM TO T_IDOC.
CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display IDoc
EXPORTING
DOCNUM = T_IDOC
TREE_DISPLAY = 'Y'
EXCEPTIONS
NO_DATA_RECORD_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc.
ENDIF.
ELSE.
MESSAGE I999(B1) WITH TEXT-007."Click on IDoc.
ENDIF.
ENDCASE. "Evaluation of field names
Include: ZFORMS
*----------------------------------------------------------------------*
***INCLUDE Z_FORMS .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form UPDATE_ITAB_SO
*&---------------------------------------------------------------------*
* Loop through VBAP and update the table ZTABLE
*----------------------------------------------------------------------*
* -->VBAK_VBELN Sales Order Number
* -->VBAK_ERDAT Sales Order Date
* -->VBAK_BSTNK Purchase Order Number
*----------------------------------------------------------------------*
FORM UPDATE_ITAB_SO USING VBAK_VBELN
VBAK_ERDAT
VBAK_BSTNK.
* --- LOCAL VARIABLES ---
DATA: T_POSNR LIKE VBAP-POSNR,
T_VBELN_DOCNUM LIKE EDIDC-DOCNUM,
T_VBELN_DATE LIKE EDIDC-CREDAT,
T_PRICE LIKE ZTABLE-O810PRICE,
T_SEGNUM LIKE EDID4-SEGNUM,
T_824_DOCNUM LIKE EDIDC-DOCNUM,
T_824_NOTE LIKE ZTABLE-I824856NOTE,
T_824_STAT LIKE ZTABLE-I824856STAT,
T_824_DATE LIKE EDIDC-CREDAT,
N1 TYPE I.
* --- LOCAL INTERNAL TABLES ---
DATA: ITAB_LINKED_IDOCS LIKE SWW_CONTOB OCCURS 5 WITH HEADER LINE.
* Initialization
CLEAR: ITAB_SO, ITAB_SO_EXTRA.
* Store Sales Order Header Data
MOVE: VBAK_VBELN TO ITAB_SO-VBELN,
VBAK_ERDAT TO ITAB_SO-DATUM,
VBAK_BSTNK TO ITAB_SO-BSTKD.
MOVE: VBAK_VBELN TO ITAB_SO_EXTRA-VBELN,
VBAK_BSTNK TO ITAB_SO_EXTRA-BSTNK.
* Get ship to customer number from VBPA
SELECT SINGLE KUNNR FROM VBPA INTO ITAB_SO-KUNNR
WHERE VBELN = VBAK_VBELN
AND POSNR = '000000'
AND PARVW = 'WE'. "Ship to partner function
* Loop through the sales order line items.
SELECT * FROM VBAP WHERE VBELN = VBAK_VBELN.
T_POSNR = VBAP-POSNR * 10.
MOVE: T_POSNR TO ITAB_SO-POSNR.
MOVE: T_POSNR TO ITAB_SO_EXTRA-POSNR,
VBAP-FAKSP TO ITAB_SO_EXTRA-FAKSP, "Billing block
VBAP-MATNR TO ITAB_SO_EXTRA-MATNR. "Material #
* Get delivery and invoice number
CLEAR: ITAB_SO-O856NO,
ITAB_SO-O856DATE,
ITAB_SO-O856DOCNUM.
CLEAR: ITAB_SO-O810NO,
ITAB_SO-O810DATE,
ITAB_SO-O810PRICE,
ITAB_SO-O810DOCNUM.
INVOICE_FLAG = ''.
DELIVERY_FLAG = ''.
SELECT VBELN VBTYP_N FROM VBFA INTO (VBFA-VBELN,
VBFA-VBTYP_N)
WHERE VBELV = VBAK_VBELN
AND POSNV = VBAP-POSNR.
CASE VBFA-VBTYP_N.
WHEN 'J'. "Delivery
DELIVERY_FLAG = 'X'.
MOVE VBFA-VBELN TO ITAB_SO-O856NO.
IF ITAB_SO-O856NO <> ''.
* Return the list of IDocs linked to the delivery
CALL FUNCTION 'EDI_GET_LINKED_IDOCS'
EXPORTING
OBJTYPE = 'LIKP'
OBJKEY = ITAB_SO-O856NO
TABLES
LINKED_IDOCS = ITAB_LINKED_IDOCS
EXCEPTIONS
OBJECT_NOT_FOUND = 1
NO_IDOCS_LINKED = 2
OBJECT_TYPE_UNKNOWN = 3
INTERNAL_ERROR = 4
OTHERS = 5.
IF SY-SUBRC = 0.
CLEAR: T_VBELN_DOCNUM, T_824_DOCNUM.
CLEAR: T_VBELN_DATE, T_824_DATE.
* FILTER OUT ALL BUT THE LATEST IDOCS
PERFORM GET_IDOC_MESTYP TABLES ITAB_LINKED_IDOCS
USING 'LIKP' T_POSNR
CHANGING T_VBELN_DOCNUM
T_VBELN_DATE
T_824_STAT
T_824_NOTE
T_824_DATE
T_824_DOCNUM.
MOVE T_VBELN_DOCNUM TO ITAB_SO-O856DOCNUM.
MOVE T_VBELN_DATE TO ITAB_SO-O856DATE.
MOVE T_824_DOCNUM TO ITAB_SO-I824856DOCNUM.
MOVE T_824_STAT TO ITAB_SO-I824856STAT.
MOVE T_824_NOTE TO ITAB_SO-I824856NOTE.
MOVE T_824_DATE TO ITAB_SO-I824856DATE.
REFRESH: ITAB_LINKED_IDOCS[], ITAB_LINKED_IDOCS.
CLEAR: ITAB_LINKED_IDOCS.
ELSE. "No IDocs were linked to Delivery
MOVE '' TO ITAB_SO-O856DOCNUM.
MOVE '' TO ITAB_SO-O856DATE.
MOVE '' TO ITAB_SO-I824856DOCNUM.
MOVE 'N' TO ITAB_SO-I824856STAT.
MOVE 'No 824 received' TO ITAB_SO-I824856NOTE.
MOVE '' TO ITAB_SO-I824856DATE.
ENDIF.
ELSE. "In case the delivery is not there...
MOVE '' TO ITAB_SO-O856DOCNUM.
MOVE '' TO ITAB_SO-O856DATE.
MOVE '' TO ITAB_SO-I824856DOCNUM.
MOVE 'N' TO ITAB_SO-I824856STAT.
MOVE 'No 824 received' TO ITAB_SO-I824856NOTE.
MOVE '' TO ITAB_SO-I824856DATE.
ENDIF.
WHEN 'M'. "Invoice
INVOICE_FLAG = 'X'.
MOVE VBFA-VBELN TO ITAB_SO-O810NO.
IF ITAB_SO-O810NO <> ''.
* Return the list of IDocs linked to the invoice
CALL FUNCTION 'EDI_GET_LINKED_IDOCS'
EXPORTING
OBJTYPE = 'VBRK'
OBJKEY = ITAB_SO-O810NO
TABLES
LINKED_IDOCS = ITAB_LINKED_IDOCS
EXCEPTIONS
OBJECT_NOT_FOUND = 1
NO_IDOCS_LINKED = 2
OBJECT_TYPE_UNKNOWN = 3
INTERNAL_ERROR = 4
OTHERS = 5.
IF SY-SUBRC = 0.
CLEAR: T_VBELN_DOCNUM, T_824_DOCNUM, T_824_NOTE, T_824_STAT.
CLEAR: T_VBELN_DATE, T_824_DATE.
* FILTER OUT ALL BUT THE LATEST IDOCS
PERFORM GET_IDOC_MESTYP TABLES ITAB_LINKED_IDOCS
USING 'VBRK' T_POSNR
CHANGING T_VBELN_DOCNUM
T_VBELN_DATE
T_824_STAT
T_824_NOTE
T_824_DATE
T_824_DOCNUM.
MOVE T_VBELN_DOCNUM TO ITAB_SO-O810DOCNUM.
MOVE T_VBELN_DATE TO ITAB_SO-O810DATE.
MOVE T_824_DOCNUM TO ITAB_SO-I824810DOCNUM.
MOVE T_824_STAT TO ITAB_SO-I824810STAT.
MOVE T_824_NOTE TO ITAB_SO-I824810NOTE.
MOVE T_824_DATE TO ITAB_SO-I824810DATE.
* Get invoice price
IF T_VBELN_DOCNUM IS INITIAL.
CLEAR T_PRICE.
ELSE.
SELECT * FROM EDID4 WHERE DOCNUM = T_VBELN_DOCNUM AND
SEGNAM = 'E1EDP01'.
MOVE EDID4-SDATA TO E1EDP01.
IF E1EDP01-POSEX = VBAP-POSNR.
T_SEGNUM = EDID4-SEGNUM.
SELECT * FROM EDID4 WHERE DOCNUM = T_VBELN_DOCNUM AND
SEGNAM = 'E1EDP26' AND
PSGNUM = T_SEGNUM.
MOVE EDID4-SDATA TO E1EDP26.
IF E1EDP26-QUALF = '010'. "Price qualifier
T_PRICE = E1EDP26-BETRG.
EXIT.
ENDIF.
ENDSELECT.
MOVE T_PRICE TO ITAB_SO-O810PRICE.
EXIT.
ENDIF.
ENDSELECT.
ENDIF.
REFRESH: ITAB_LINKED_IDOCS[], ITAB_LINKED_IDOCS.
CLEAR: ITAB_LINKED_IDOCS.
ELSE. "Didn't find any linked IDocs to the invoice
* Save invoice number for those invoices without IDocs. Later we will
* submit these numbers for saving.
TITAB-O810 = ITAB_SO-O810NO.
APPEND TITAB.
* SUBMIT ZVF02SAVE WITH BILLING = ITAB_SO-O810NO AND RETURN.
MOVE '' TO ITAB_SO-O810DOCNUM.
MOVE '' TO ITAB_SO-O810DATE.
MOVE '' TO ITAB_SO-I824810DOCNUM.
MOVE 'N' TO ITAB_SO-I824810STAT.
MOVE 'No 824 received' TO ITAB_SO-I824810NOTE.
MOVE '' TO ITAB_SO-I824810DATE.
MOVE '' TO ITAB_SO-O810PRICE.
ENDIF.
ELSE.
MOVE '' TO ITAB_SO-O810DOCNUM.
MOVE '' TO ITAB_SO-O810DATE.
MOVE '' TO ITAB_SO-I824810DOCNUM.
MOVE 'N' TO ITAB_SO-I824810STAT.
MOVE 'No 824 received' TO ITAB_SO-I824810NOTE.
MOVE '' TO ITAB_SO-I824810DATE.
MOVE '' TO ITAB_SO-O810PRICE.
MOVE '' TO ITAB_SO-O810NO.
ENDIF.
ENDCASE.
ENDSELECT.
IF SY-SUBRC = 0.
ELSE.
MOVE '' TO ITAB_SO-O856DOCNUM.
MOVE '' TO ITAB_SO-O856DATE.
MOVE '' TO ITAB_SO-O856NO.
MOVE '' TO ITAB_SO-I824856DOCNUM.
MOVE 'N' TO ITAB_SO-I824856STAT.
MOVE 'No 824 received' TO ITAB_SO-I824856NOTE.
MOVE '' TO ITAB_SO-I824856DATE.
MOVE '' TO ITAB_SO-O810DOCNUM.
MOVE '' TO ITAB_SO-O810DATE.
MOVE '' TO ITAB_SO-O810PRICE.
MOVE '' TO ITAB_SO-O810NO.
MOVE '' TO ITAB_SO-I824810DOCNUM.
MOVE 'N' TO ITAB_SO-I824810STAT.
MOVE 'No 824 received' TO ITAB_SO-I824810NOTE.
MOVE '' TO ITAB_SO-I824810DATE.
ENDIF. "Subsequent documents
IF DELIVERY_FLAG <> 'X'.
MOVE '' TO ITAB_SO-I824856DOCNUM.
MOVE 'N' TO ITAB_SO-I824856STAT.
MOVE 'No 824 received' TO ITAB_SO-I824856NOTE.
MOVE '' TO ITAB_SO-I824856DATE.
ELSE. "Delivery was found.
DELIVERY_FLAG = ''.
ENDIF.
IF INVOICE_FLAG <> 'X'.
MOVE '' TO ITAB_SO-I824810DOCNUM.
MOVE 'N' TO ITAB_SO-I824810STAT.
MOVE 'No 824 received' TO ITAB_SO-I824810NOTE.
MOVE '' TO ITAB_SO-I824810DATE.
ELSE. "Invoice was found.
INVOICE_FLAG = ''.
ENDIF.
APPEND: ITAB_SO, ITAB_SO_EXTRA.
ENDSELECT.
IF SY-SUBRC NE 0. "Sales Order has no line items
CLEAR ITAB_SO-POSNR.
ENDIF.
ENDFORM. " UPDATE_ITAB_SO
*&---------------------------------------------------------------------*
*& Form UPDATE_ZTABLE
*&---------------------------------------------------------------------*
* Update ZTABLE table with internal table data
*----------------------------------------------------------------------*
* -->P_ITAB_SO Internal table text containing data to be updated
*----------------------------------------------------------------------*
FORM UPDATE_ZTABLE TABLES P_ITAB_SO STRUCTURE ITAB_SO.
MODIFY ZTABLE FROM TABLE P_ITAB_SO.
IF SY-SUBRC NE 0. "Some items not updated
MESSAGE I999(B1) WITH SY-DBCNT TEXT-004.
ELSE.
IF SY-DBCNT EQ 0. "No entries in itab_so
MESSAGE I999(B1) WITH TEXT-005.
ELSE. "& entries added to ZTABLE
MESSAGE I999(B1) WITH SY-DBCNT TEXT-006.
ENDIF.
ENDIF.
ENDFORM. " UPDATE_ZTABLE
*&---------------------------------------------------------------------*
*& Form PRINT_ITAB
*&---------------------------------------------------------------------*
* Print out the 2 internal tables
*----------------------------------------------------------------------*
* -->P_ITAB_SO ZTABLE information
* -->P_ITAB_SO_EXTRA Additional information with the same key
*----------------------------------------------------------------------*
FORM PRINT_ITAB TABLES ITAB_SO STRUCTURE ITAB_SO
ITAB_SO_EXTRA STRUCTURE ITAB_SO_EXTRA.
SORT ITAB_SO BY VBELN POSNR.
LOOP AT ITAB_SO.
IF ITAB_SO-KUNNR IN S_KUNNR. "Only print out Customers in range
SELECT SINGLE SPART AUART FROM VBAK INTO (VBAK-SPART, VBAK-AUART)
WHERE VBELN = ITAB_SO-VBELN.
IF SY-SUBRC = 0.
IF VBAK-SPART = C_SPART_12 AND VBAK-AUART = C_AUART_ZEDI.
READ TABLE ITAB_SO_EXTRA WITH KEY
VBELN = ITAB_SO-VBELN
POSNR = ITAB_SO-POSNR
BSTNK = ITAB_SO-BSTKD.
IF ITAB_SO-POSNR = '000010'.
FORMAT COLOR COL_KEY.
IF SY-TABIX <> 1. ULINE. ENDIF.
* Sales Order number
WRITE:/1 ITAB_SO-VBELN.
HIDE ITAB_SO-VBELN.
* PO Number
WRITE: ITAB_SO-BSTKD,
* PO Date
ITAB_SO-DATUM,
* Customer Number
ITAB_SO-KUNNR.
* Sales order header billing block
SELECT SINGLE FAKSK FROM VBAK INTO VBAK-FAKSK
WHERE VBELN = ITAB_SO-VBELN.
IF SY-SUBRC = 0.
WRITE: VBAK-FAKSK.
ENDIF.
FORMAT COLOR OFF.
ENDIF.
* Line item number
IF ITAB_SO-POSNR <> '000010'.
SKIP 1.
ENDIF.
FORMAT COLOR COL_GROUP.
WRITE:/5 ITAB_SO-POSNR,
* Material Number
ITAB_SO_EXTRA-MATNR,
* Billing block at the line item level
ITAB_SO_EXTRA-FAKSP.
FORMAT COLOR COL_NORMAL.
* Delivery Number
WRITE:/5 'Delivery:', ITAB_SO-O856NO.
HIDE ITAB_SO-O856NO.
* DESADV IDoc number
WRITE: ITAB_SO-O856DOCNUM.
HIDE ITAB_SO-O856DOCNUM.
* DESADV Date
WRITE: ITAB_SO-O856DATE.
IF ITAB_SO-I824856STAT = 'R' OR ITAB_SO-I824856STAT = 'X'.
FORMAT COLOR COL_NEGATIVE.
ELSEIF ITAB_SO-I824856STAT = 'N'.
FORMAT COLOR COL_NEGATIVE.
ELSEIF ITAB_SO-I824856STAT = 'A'.
FORMAT COLOR COL_POSITIVE.
ELSE.
FORMAT COLOR COL_TOTAL.
ENDIF.
* 824 for 856 Status
WRITE:/10 '824 for 856:', ITAB_SO-I824856STAT.
MOVE ITAB_SO-I824856STAT TO T_STAT.
HIDE T_STAT.
* 824 for 856 IDoc Number
WRITE: ITAB_SO-I824856DOCNUM.
HIDE ITAB_SO-I824856DOCNUM.
* 824 for 856 IDoc Date
WRITE: ITAB_SO-I824856DATE,
* 824 for 856 Error Text Detail
ITAB_SO-I824856NOTE.
MOVE ITAB_SO-I824856DOCNUM TO T_IDOC.
HIDE T_IDOC.
FORMAT COLOR COL_NORMAL.
* Invoice number
WRITE:/5 'Invoice: ', ITAB_SO-O810NO.
HIDE ITAB_SO-O810NO.
* INVOIC IDoc Number
* If there is an invoice number but no IDoc number then highlight
IF ITAB_SO-O810DOCNUM = '' AND ITAB_SO-O810NO <> ''.
FORMAT COLOR COL_TOTAL.
WRITE: 'NO INVOIC IDoc!'.
FORMAT COLOR OFF.
ELSE.
WRITE: ITAB_SO-O810DOCNUM.
ENDIF.
HIDE ITAB_SO-O810DOCNUM.
* INVOIC IDoc Date
WRITE: ITAB_SO-O810DATE,
* INVOIC IDoc Price
ITAB_SO-O810PRICE.
IF ITAB_SO-I824810STAT = 'R' OR ITAB_SO-I824810STAT = 'X'.
FORMAT COLOR COL_NEGATIVE.
ELSEIF ITAB_SO-I824810STAT = 'N'.
FORMAT COLOR COL_NEGATIVE.
ELSEIF ITAB_SO-I824810STAT = 'A'.
FORMAT COLOR COL_POSITIVE.
ELSE.
FORMAT COLOR COL_TOTAL.
ENDIF.
* 824 for 810 Status
WRITE:/10 '824 for 810:', ITAB_SO-I824810STAT.
MOVE ITAB_SO-I824856STAT TO T_STAT.
HIDE T_STAT.
* 824 for 810 IDoc Number
WRITE: ITAB_SO-I824810DOCNUM.
HIDE ITAB_SO-I824810DOCNUM.
* 824 for 810 IDoc Date
WRITE: ITAB_SO-I824810DATE,
* 824 for 810 Error Text
ITAB_SO-I824810NOTE.
MOVE ITAB_SO-I824810DOCNUM TO T_IDOC.
HIDE T_IDOC.
FORMAT COLOR OFF.
ENDIF.
ENDIF.
CLEAR ITAB_SO.
ENDIF.
ENDLOOP.
ULINE.
* Perform the download of the file
IF P_DOWN = 'X'.
PERFORM DOWNLOAD_FILE TABLES ITAB_SO
USING P_FILE.
ENDIF.
ENDFORM. " PRINT_ITAB
*&---------------------------------------------------------------------*
*& Form GET_IDOC_MESTYP
*&---------------------------------------------------------------------*
* Loop through the internal table and check the message type
* returning only the latest ones.
*----------------------------------------------------------------------*
* -->ITAB_LINKED_IDOCS List of IDocs linked to Document
*----------------------------------------------------------------------*
FORM GET_IDOC_MESTYP TABLES ITAB_LINKED_IDOCS STRUCTURE SWW_CONTOB
USING VALUE(OBJECT_TYPE)
T_LINE LIKE VBAP-POSNR
CHANGING T_VBELN_DOCNUM T_VBELN_DATE
T_824_STAT T_824_NOTE
T_824_DATE T_824_DOCNUM.
* Temporary local data
DATA: T_DOCNUM LIKE EDIDC-DOCNUM,
Z1824HD TYPE Z1824HD,
Z1824TH TYPE Z1824TH,
Z1824DT TYPE Z1824DT,
Z1824TD TYPE Z1824TD,
T_SEGNUM LIKE EDID4-SEGNUM,
H_MESSAGE LIKE ZTABLE-I824856NOTE, "Header text
L_MESSAGE LIKE ZTABLE-I824856NOTE, "Line item text
T_MESSAGE LIKE ZTABLE-I824856NOTE,
T_STATUS LIKE ZTABLE-I824856STAT,
N1 TYPE I.
DESCRIBE TABLE ITAB_LINKED_IDOCS LINES N1.
IF N1 > 1.
SORT ITAB_LINKED_IDOCS BY OBJKEY.
ENDIF.
CASE OBJECT_TYPE.
WHEN 'LIKP'. "Delivery
LOOP AT ITAB_LINKED_IDOCS WHERE OBJTYPE = 'IDOC'.
T_DOCNUM = ITAB_LINKED_IDOCS-OBJKEY.
SELECT SINGLE DOCNUM CREDAT MESTYP FROM EDIDC
INTO (EDIDC-DOCNUM,
EDIDC-CREDAT,
EDIDC-MESTYP)
WHERE DOCNUM = T_DOCNUM.
IF SY-SUBRC = 0.
CASE EDIDC-MESTYP.
WHEN 'DESADV'. "Outbound delivery
T_VBELN_DOCNUM = EDIDC-DOCNUM.
T_VBELN_DATE = EDIDC-CREDAT.
WHEN 'ZAPPADV856' OR 'ZAPPADV'. "824 Signal repsonse to 856
SELECT * FROM EDID4 WHERE DOCNUM = EDIDC-DOCNUM
AND SEGNAM = 'Z1824DT'.
MOVE EDID4-SDATA TO Z1824DT.
IF Z1824DT-POLINE <> T_LINE. "Not relevant for this line
CONTINUE.
ELSE. "Found 824 for this line item
T_824_DOCNUM = EDIDC-DOCNUM.
T_824_DATE = EDIDC-CREDAT.
ENDIF.
ENDSELECT.
ENDCASE.
ENDIF.
ENDLOOP.
WHEN 'VBRK'. "Invoice
LOOP AT ITAB_LINKED_IDOCS WHERE OBJTYPE = 'IDOC'.
T_DOCNUM = ITAB_LINKED_IDOCS-OBJKEY.
SELECT SINGLE DOCNUM CREDAT MESTYP FROM EDIDC
INTO (EDIDC-DOCNUM,
EDIDC-CREDAT,
EDIDC-MESTYP)
WHERE DOCNUM = T_DOCNUM.
IF SY-SUBRC = 0.
CASE EDIDC-MESTYP.
WHEN 'INVOIC'. "Outbound delivery
T_VBELN_DOCNUM = EDIDC-DOCNUM.
T_VBELN_DATE = EDIDC-CREDAT.
WHEN 'ZAPPADV810' OR 'ZAPPADV'. "824 Signal repsonse to 810
SELECT * FROM EDID4 WHERE DOCNUM = EDIDC-DOCNUM
AND SEGNAM = 'Z1824DT'.
MOVE EDID4-SDATA TO Z1824DT.
IF Z1824DT-POLINE <> T_LINE. "Not relevant for this line
CONTINUE.
ELSE. "Found 824 for this line item
T_824_DOCNUM = EDIDC-DOCNUM.
T_824_DATE = EDIDC-CREDAT.
ENDIF.
ENDSELECT.
ENDCASE.
ENDIF.
ENDLOOP.
ENDCASE.
* Check status of the 824 IDocs
IF T_824_DOCNUM IS INITIAL. "No 824 linked to Document
T_824_NOTE = 'No 824 received'.
T_824_STAT = 'N'.
ELSE.
SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND
SEGNAM = 'Z1824HD'.
IF SY-SUBRC = 0.
MOVE EDID4-SDATA TO Z1824HD.
CASE Z1824HD-ACKCODE.
WHEN 'TA'. "Transaction accepted
H_MESSAGE = 'OK'.
L_MESSAGE = 'OK'.
T_STATUS = 'A'.
WHEN 'TR'. "Transaction rejected
* Header text
SELECT SINGLE * FROM EDID4 WHERE
DOCNUM = T_824_DOCNUM AND
SEGNAM = 'Z1824TH'.
IF SY-SUBRC = 0.
MOVE EDID4-SDATA TO Z1824TH.
H_MESSAGE = Z1824TH-LINE.
ELSE.
H_MESSAGE = 'No header error text segment Z1824TH'.
ENDIF. "Search for Text header
SELECT * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND
SEGNAM = 'Z1824DT'.
MOVE EDID4-SDATA TO Z1824DT.
IF Z1824DT-POLINE = T_LINE.
T_SEGNUM = EDID4-SEGNUM.
IF Z1824DT-ACKCODE = 'IA'. "Item accepted
L_MESSAGE = 'OK'.
T_STATUS = 'A'.
EXIT.
ELSEIF Z1824DT-ACKCODE = 'IC'. "Item accepted but changed
T_STATUS = 'C'.
* Line item text for that line item number
SELECT SINGLE * FROM EDID4 WHERE
DOCNUM = T_824_DOCNUM AND
PSGNUM = T_SEGNUM AND
SEGNAM = 'Z1824TD'.
IF SY-SUBRC = 0.
MOVE EDID4-SDATA TO Z1824TD.
L_MESSAGE = Z1824TD-LINE.
ELSE.
L_MESSAGE = 'No error text for line item in Z1824TD'.
ENDIF.
EXIT.
ELSE.
T_STATUS = 'R'.
* Line item text for that line item number
SELECT SINGLE * FROM EDID4 WHERE
DOCNUM = T_824_DOCNUM AND
PSGNUM = T_SEGNUM AND
SEGNAM = 'Z1824TD'.
IF SY-SUBRC = 0.
MOVE EDID4-SDATA TO Z1824TD.
L_MESSAGE = Z1824TD-LINE.
ELSE.
L_MESSAGE = 'No error text for line item in Z1824TD'.
ENDIF.
EXIT.
ENDIF. "Item accepted
ELSE. "Wrong line item
CONTINUE.
ENDIF.
ENDSELECT. "Select on Z1824TD
IF SY-SUBRC <> 0.
L_MESSAGE = 'No item details in 824!'.
* Header text
SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND
SEGNAM = 'Z1824TH'.
IF SY-SUBRC = 0.
MOVE EDID4-SDATA TO Z1824TH.
H_MESSAGE = Z1824TH-LINE.
ELSE.
H_MESSAGE = 'No header error text'.
ENDIF.
ENDIF.
* T_STATUS = 'R'.
ENDCASE.
CONCATENATE H_MESSAGE '|' L_MESSAGE INTO T_MESSAGE.
T_824_NOTE = T_MESSAGE.
T_824_STAT = T_STATUS.
ELSE.
T_824_NOTE = 'No Line item detail segment in 824'.
T_STATUS = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_IDOC_MESTYP
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FILE
*&---------------------------------------------------------------------*
* Update column headings and perform download to file.
*----------------------------------------------------------------------*
* -->ITAB_SO ZTABLE table
* -->P_FILE File name for download
*----------------------------------------------------------------------*
FORM DOWNLOAD_FILE TABLES ITAB_SO STRUCTURE ITAB_SO
USING P_FILE.
*** Populate Itabs for download
* Column names
MOVE 'Client' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'PO Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'PO Line Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'SO Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'PO Date' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Customer' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Delivery Date' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Delivery IDoc Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Delivery Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 Status for 856' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 Date for 856' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 IDoc for 856' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 Note for 856' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Invoice Date' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Invoice IDoc Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Invoice Number' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE 'Invoice Price' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 Status for 810' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 Date for 810' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 IDoc for 810' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
MOVE '824 Note for 810' TO T_COLNAMES-NAME.
APPEND T_COLNAMES.
* Write data in internal table ITAB_SO to file specified in parameters
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = ITAB_SO
FIELDNAMES = T_COLNAMES
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
GUI_REFUSE_FILETRANSFER = 8
OTHERS = 9.
IF SY-SUBRC = 0.
ELSEIF SY-SUBRC = 1.
MESSAGE I027(Z3) WITH P_FILE.
ELSEIF SY-SUBRC = 2.
MESSAGE I028(Z3) WITH P_FILE.
ELSEIF SY-SUBRC = 3.
MESSAGE I001(Z4) WITH P_FILE.
ELSEIF SY-SUBRC = 4.
MESSAGE I002(Z4) WITH P_FILE.
ELSEIF SY-SUBRC = 5.
MESSAGE I003(Z4) WITH P_FILE.
ELSEIF SY-SUBRC = 6.
MESSAGE I004(Z4) WITH P_FILE.
ELSEIF SY-SUBRC = 7.
MESSAGE I005(Z4) WITH P_FILE.
ELSEIF SY-SUBRC = 8.
MESSAGE I006(Z4) WITH P_FILE.
ELSE.
MESSAGE I007(Z4) WITH P_FILE.
ENDIF.
ENDFORM. " DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*& Form SAVE_BILLING_DOC
*&---------------------------------------------------------------------*
* Loop through the internal table set up to store the invoice numbers
* of those invoices that do not have INVOIC Idocs attached to them.
* i.e. The ZD01 output was not created for some reason.
* By saving the invoice (which is what this program does) the output
* should be generated.
*----------------------------------------------------------------------*
* -->TITAB Stores invoice numbers of those invoices that do not
* have INVOIC IDocs linked to them.
*----------------------------------------------------------------------*
FORM SAVE_BILLING_DOC TABLES TITAB STRUCTURE TITAB.
DATA: N TYPE I.
LOOP AT TITAB.
SUBMIT ZVF02SAVE WITH BILLING = TITAB-O810 AND RETURN.
MESSAGE I009(Z4) WITH TITAB-O810.
ENDLOOP.
IF SY-SUBRC = 0.
DESCRIBE TABLE TITAB LINES N.
MESSAGE I008(Z4) WITH N.
ENDIF.
ENDFORM. " SAVE_BILLING_DOC
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.