Assign Output Types

Assign the output types to represent the following conditions. These output types then result in the creation of IDocs – EDI 870.

  • Change in Delivery date
  • Delivery drop
  • Post Goods Issue
  • Order Cancellation

View the Sample Program

REPORT ZNDCOUT NO STANDARD PAGE HEADING LINE-SIZE 132.
 
************************************************************************
* Program :  Assign the output types to represent the following
*            conditions. These output types then result in the creation
*            of IDocs - EDI 870.
*             - Change in Delivery date
*             - Delivery drop
*             - Post Goods Issue 
*             - Order Cancellation
* Author  :    Arnigs
*
********************************Tables**********************************
TABLES: ZNOPENORD,
        VBAK,
        VBAP,
        VBEP,
        VBFA,
        LIKP,
*       mkpf,                                              
        NAST,
        KNVP,
        VBUV.                                             
 
************************************************************************
 
*************************Selection-Screen*******************************
 
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS     : P_KUNN2 LIKE KNVP-KUNN2 OBLIGATORY.
* select-options : s_kunnr for knvp-kunnr.                  C:NDVK932932
PARAMETERS     : P_ORDMET LIKE VBAK-BSARK.
SELECTION-SCREEN END OF BLOCK B1.
 
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN  COMMENT (31) TEXT-015 FOR FIELD P_KS_OCR.
PARAMETERS: P_KS_OCR LIKE TNAPR-KSCHL.
SELECTION-SCREEN POSITION 47.
SELECTION-SCREEN  COMMENT (10) TEXT-016 FOR FIELD P_KS_OCR.
PARAMETERS: TIME LIKE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
PARAMETERS: P_KS_IO  LIKE TNAPR-KSCHL,                     "I:NDVK932735
            P_KS_R LIKE TNAPR-KSCHL,
            P_KS_DCH LIKE TNAPR-KSCHL,
            P_KS_DCR LIKE TNAPR-KSCHL,
            P_KS_GI LIKE TNAPR-KSCHL.
 
SELECTION-SCREEN END OF BLOCK B2.
 
 
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.
SELECT-OPTIONS: S_ERDAT FOR SY-DATUM,
                S_ERZET FOR LIKP-ERZET OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B3.
 
SELECTION-SCREEN BEGIN OF BLOCK B5 WITH FRAME TITLE TEXT-005.
PARAMETERS : P_DIFF TYPE I.
SELECTION-SCREEN END OF BLOCK B5.
 
SELECTION-SCREEN BEGIN OF BLOCK B6 WITH FRAME TITLE TEXT-006.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN  COMMENT (31) TEXT-007 FOR FIELD UP_OCR.
PARAMETERS: UP_OCR AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN  COMMENT (31) TEXT-008 FOR FIELD UP_REJ.
PARAMETERS: UP_REJ AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN  COMMENT (31) TEXT-009 FOR FIELD UP_DCH.
PARAMETERS: UP_DCH AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN  COMMENT (31) TEXT-010 FOR FIELD UP_DCR.
PARAMETERS: UP_DCR AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN  COMMENT (31) TEXT-011 FOR FIELD UP_GI.
PARAMETERS: UP_GI AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B6.
 
************************************************************************
 
************************Internal Tables*********************************
 
DATA: BEGIN OF ITAB_OPEN_ORDERS OCCURS 0,
      VBELN LIKE VBAK-VBELN,
      MAHDT LIKE VBAK-MAHDT,
      END OF ITAB_OPEN_ORDERS.
 
DATA : BEGIN OF TEMP_ITAB_ORDERS OCCURS 0,
       VBELN LIKE VBAK-VBELN,
       MAHDT LIKE VBAK-MAHDT,
       END OF TEMP_ITAB_ORDERS.
 
DATA : BEGIN OF ITAB_REJ_ORDERS OCCURS 0,
       VBELN LIKE VBAK-VBELN,
       END OF ITAB_REJ_ORDERS.
 
DATA : ITAB_DCH_ORDERS LIKE ITAB_REJ_ORDERS OCCURS 0 WITH HEADER LINE.
 
DATA : ITAB_DCR_ORDERS LIKE ITAB_REJ_ORDERS OCCURS 0 WITH HEADER LINE.
 
DATA : ITAB_GI_ORDERS LIKE ITAB_REJ_ORDERS OCCURS 0 WITH HEADER LINE.
 
 
  DATA : ITAB_NEW_ORDERS LIKE ITAB_REJ_ORDERS OCCURS 0 WITH HEADER LINE.
*NDVK932735 begins
  DATA : BEGIN OF ITAB_ORDERS OCCURS 0,
           VBELN LIKE VBAK-VBELN,
           KSCHL LIKE TNAPR-KSCHL,
         END OF ITAB_ORDERS.
 
  DATA : TEMP_INC_ORDERS LIKE ITAB_REJ_ORDERS OCCURS 0 WITH HEADER LINE.
 
  DATA : ITAB_INC_ORDERS LIKE ITAB_REJ_ORDERS OCCURS 0 WITH HEADER LINE.
* NDVK932735 ends
 
DATA : BEGIN OF ITAB_FINAL_ORDERS OCCURS 0,
         VBELN LIKE VBAK-VBELN,
         KSCHL LIKE TNAPR-KSCHL,
         PSTATUS TYPE C,
       END OF ITAB_FINAL_ORDERS .
 
DATA : BEGIN OF ITAB_NAST OCCURS 0,
         OBJKY LIKE NAST-OBJKY,
         VSTAT LIKE NAST-VSTAT,
       END OF ITAB_NAST.
 
DATA : BEGIN OF ITAB_KNVP OCCURS 0,
        KUNNR LIKE KNVP-KUNNR,
       END OF ITAB_KNVP.
 
* NDVK932932 Begins
DATA : BEGIN OF TEMP_OPEN_ORDERS OCCURS 0,
           OBJKY LIKE NAST-OBJKY,
       END OF TEMP_OPEN_ORDERS.
* NDVK932932 Ends
 
DATA:  I_TLINE LIKE TLINE OCCURS 1 WITH HEADER LINE.
 
************************************************************************
***************************Variables************************************
 
DATA : DAT LIKE SY-DATUM, DIFF TYPE I, OBJ_NAME LIKE THEAD-TDNAME.
* data : time like sy-uzeit value '003000'.
DATA : DATE LIKE SY-DATUM.
 
************************************************************************
 
 
start-of-selection.
 
*  if s_kunnr is initial.                                  "C:NDVK932932
    PERFORM GET_SOLD-TO.
*  endif.                                                  "C:NDVK932932
 
* NDVK932932 Begins
*  IF UP_OCR <> SPACE.
*   PERFORM GET_ORDERS.                                    "I:NDVK932735
*   PERFORM GET_INC_ORDERS.                                "I:NDVK932735
*    PERFORM GET_ITAB_NEW_ORDERS.
**  perform del_inc_orders.                                "I:NDVK932735
*  ENDIF.
* NDVK932932 Ends
 
* if up_dch <> space or up_dcr <> space.                   "C:NDVK932932
  IF UP_DCH <> SPACE OR UP_DCR <> SPACE OR UP_OCR <> SPACE."I:NDVK932932
    PERFORM GET_ITAB_OPEN_ORDERS.
    IF NOT ITAB_OPEN_ORDERS[] IS INITIAL.
* NDVK932932 Begins
      IF UP_OCR <> SPACE.
         PERFORM GET_ORDERS.
         PERFORM GET_INC_ORDERS.
         PERFORM GET_ITAB_NEW_ORDERS.
      ENDIF.
* NDVK932932 Ends
      IF UP_DCH <> SPACE.
        PERFORM GET_PROMISED_DDATES.
        PERFORM GET_ITAB_DCH_ORDERS.
      ENDIF.
      IF UP_DCR <> SPACE.
        PERFORM GET_ITAB_DCR_ORDERS.
      ENDIF.
    ELSE.
      WRITE:/ 'NO NEW DELIVERIES OR DELIVERY CHANGE TO SEND ACKNLGEMNT'.
    ENDIF.
 ENDIF.
 
  IF UP_GI <> SPACE.
    PERFORM GET_ITAB_GI_ORDERS.
  ENDIF.
 
  IF UP_REJ <> SPACE.
    PERFORM GET_ITAB_REJ_ORDERS.
  ENDIF.
 
  PERFORM GET_ITAB_FINAL_ORDERS.
 
  IF NOT ITAB_FINAL_ORDERS[] IS INITIAL.
    PERFORM SEND_ACK.
  ELSE.
    WRITE:/ 'NO ORDERS AVAILABLE TO SEND ACKNOWLEDGEMENT'.
  ENDIF.
 
 
*---------------------------------------------------------------------*
*       FORM SEND_ACKNOWLEDGEMENT                                     *
*---------------------------------------------------------------------*
*       This form sends the acknowledgement to the Sold-to party      *
*---------------------------------------------------------------------*
FORM SEND_ACK.
  DATA: TMP_KSCHL LIKE NAST-KSCHL.
  WRITE:/35 'Error Report'.
  SKIP.
  WRITE:/10 ' Orders', 35 'Message Type', 55 'Status'.
  SKIP.
  LOOP AT ITAB_FINAL_ORDERS.
 
 
 IF ( ITAB_FINAL_ORDERS-KSCHL NE P_KS_OCR AND              "I:NDVK932735
      ITAB_FINAL_ORDERS-KSCHL NE P_KS_IO ).                "I:NDVK932735
    SELECT OBJKY
           VSTAT
           INTO TABLE ITAB_NAST
           FROM NAST
           WHERE KAPPL = 'V1'                    AND
                 OBJKY = ITAB_FINAL_ORDERS-VBELN AND
                 KSCHL = ITAB_FINAL_ORDERS-KSCHL AND
                 SPRAS = 'E'                     AND
                 PARNR = P_KUNN2                 AND
                 PARVW = 'RE'.
 
    IF ITAB_NAST[] IS INITIAL.
      ITAB_FINAL_ORDERS-PSTATUS = 'E'.
      MODIFY ITAB_FINAL_ORDERS.
    ELSE.
      READ TABLE ITAB_NAST WITH KEY VSTAT = '0'.
      IF SY-SUBRC <> 0.
        ITAB_FINAL_ORDERS-PSTATUS = 'A'.
        MODIFY ITAB_FINAL_ORDERS.
      ENDIF.
    ENDIF.
 
    REFRESH ITAB_NAST.
ENDIF.                                                     "I:NDVK932735
 
    IF ITAB_FINAL_ORDERS-PSTATUS = SPACE.
      MOVE ITAB_FINAL_ORDERS-KSCHL TO TMP_KSCHL.
      EXPORT  TMP_KSCHL TO MEMORY ID 'OUTPUT_TYPE_STATUS1'.
      SUBMIT RSNAST00
           WITH   S_KAPPL EQ 'V1'
           WITH   S_OBJKY EQ ITAB_FINAL_ORDERS-VBELN
           WITH   S_KSCHL EQ ITAB_FINAL_ORDERS-KSCHL
           WITH   S_NACHA EQ '6'
           AND RETURN.
    ELSEIF ITAB_FINAL_ORDERS-PSTATUS = 'E'.
      WRITE:/10 ITAB_FINAL_ORDERS-VBELN, 35 ITAB_FINAL_ORDERS-KSCHL,
             55 'ENTRY NOT AVAILABLE IN NAST'.
    ELSE.
      WRITE:/10 ITAB_FINAL_ORDERS-VBELN, 35 ITAB_FINAL_ORDERS-KSCHL,
             55 'ALREADY PROCESSED'.
    ENDIF.
 
  ENDLOOP.
ENDFORM.
 
 
 
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_DCR_ORDERS
*&---------------------------------------------------------------------*
*  This form creates the list of lowes special order for which delivery
*  has been created within the specified time period. If the period is
*  not specified, this form will select the orders for which the
*  delivery has been created either yesterday or today.
*----------------------------------------------------------------------*
FORM GET_ITAB_DCR_ORDERS.
 
  IF S_ERDAT IS INITIAL.
 
    DAT = SY-DATUM - 1.
 
    SELECT A~VBELV
           INTO TABLE ITAB_DCR_ORDERS
           FROM VBFA AS A
           INNER JOIN LIKP AS B ON A~VBELN = B~VBELN
           FOR ALL ENTRIES IN ITAB_OPEN_ORDERS
           WHERE A~VBELV = ITAB_OPEN_ORDERS-VBELN AND
                 A~VBTYP_N = 'J' AND
               ( ( B~ERDAT => DAT AND B~ERZET => S_ERZET-LOW ) AND
                ( B~ERDAT <= SY-DATUM AND B~ERZET <= S_ERZET-HIGH ) ).
 
  ELSE.
    SELECT A~VBELV
           INTO TABLE ITAB_DCR_ORDERS
           FROM VBFA AS A
           INNER JOIN LIKP AS B ON A~VBELN = B~VBELN
           FOR ALL ENTRIES IN ITAB_OPEN_ORDERS
           WHERE A~VBELV = ITAB_OPEN_ORDERS-VBELN AND
                 A~VBTYP_N = 'J' AND
               ( ( B~ERDAT => S_ERDAT-LOW
                                        AND B~ERZET => S_ERZET-LOW ) AND
                ( B~ERDAT <= S_ERDAT-HIGH
                                      AND B~ERZET <= S_ERZET-HIGH ) ).
 
  ENDIF.
 
  SORT ITAB_DCR_ORDERS.
  DELETE ADJACENT DUPLICATES FROM ITAB_DCR_ORDERS.
 
ENDFORM.                               " GET_ITAB_DCR_ORDERS
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_REJ_ORDERS
*&---------------------------------------------------------------------*
*       This form selects orders which were rejected either yesterday or
*       today. It can also select order which were rejected during a
*       specific period if the period is entered on the selection
*       screen.
*----------------------------------------------------------------------*
FORM GET_ITAB_REJ_ORDERS.
  IF S_ERDAT IS INITIAL.
 
    DAT = SY-DATUM - 1.
 
    SELECT A~VBELN
           FROM VBAK AS A
                INNER JOIN VBAP AS B ON A~VBELN = B~VBELN
                INTO TABLE ITAB_REJ_ORDERS
                FOR ALL ENTRIES IN ITAB_KNVP               "I:NDVK932932
*          where ( a~kunnr in S_KUNNR and                  "C:NDVK932932
           WHERE ( A~KUNNR =  ITAB_KNVP-KUNNR AND          "I:NDVK932932
                 A~BSARK = P_ORDMET AND
                 B~ABGRU <> SPACE AND
               (  B~AEDAT => DAT  AND
                 B~AEDAT <= SY-DATUM  ) ).
 
  ELSE.
    SELECT A~VBELN
           FROM VBAK AS A
                INNER JOIN VBAP AS B ON A~VBELN = B~VBELN
                INTO TABLE ITAB_REJ_ORDERS
                FOR ALL ENTRIES IN ITAB_KNVP               "I:NDVK932932
*          where a~kunnr in S_KUNNR and                    "C:NDVK932932
           WHERE A~KUNNR =  ITAB_KNVP-KUNNR AND            "I:NDVK932932
                 A~BSARK = P_ORDMET AND
                 B~ABGRU <> SPACE AND
               (  B~AEDAT => S_ERDAT-LOW  AND
                 B~AEDAT <= S_ERDAT-HIGH  ).
  ENDIF.
 
  SORT ITAB_REJ_ORDERS.
  DELETE ADJACENT DUPLICATES FROM ITAB_REJ_ORDERS.
 
ENDFORM.                               " GET_ITAB_REJ_ORDERS
 
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_GI_ORDERS
*&---------------------------------------------------------------------*
*       This form selects the orders belonging to a particular sold-to
*       and ordering method, which have been goods issued either
*       yesterday or today. It can also select orders which were goods
*       issued in a certain period if the period is entered on
*       the selection screen.
*----------------------------------------------------------------------*
FORM GET_ITAB_GI_ORDERS.
  IF S_ERDAT IS INITIAL.
 
    DAT = SY-DATUM - 1.
 
    SELECT A~VBELN
           INTO TABLE ITAB_GI_ORDERS
           FROM VBAK AS A
                INNER JOIN VBFA AS B ON A~VBELN = B~VBELV
*               inner join mkpf as c on b~vbeln = c~mblnr  "C:NDVK932735
           FOR ALL ENTRIES IN ITAB_KNVP                    "I:NDVK932932
*          where a~kunnr in s_kunnr and                    "C:NDVK932932
           WHERE A~KUNNR = ITAB_KNVP-KUNNR AND             "I:NDVK932932
                 A~BSARK = P_ORDMET AND
                 B~VBTYP_N = 'R' AND
* NDVK932735 Begins
*               ( ( c~cpudt => dat and c~cputm => s_erzet-low ) and
*                ( c~cpudt <= sy-datum and c~cputm <= s_erzet-high ) ).
                ( ( B~ERDAT => DAT AND B~ERZET => S_ERZET-LOW ) AND
                 ( B~ERDAT <= SY-DATUM AND B~ERZET <= S_ERZET-HIGH ) ).
* NDVK932735 Ends
 
  ELSE.
    SELECT A~VBELN
           INTO TABLE ITAB_GI_ORDERS
           FROM VBAK AS A
                INNER JOIN VBFA AS B ON A~VBELN = B~VBELV
*               inner join mkpf as c on b~vbeln = c~mblnr  "C:NDVK932735
           FOR ALL ENTRIES IN ITAB_KNVP                    "I:NDVK932932
*          where a~kunnr in S_KUNNR and                    "C:NDVK932932
           WHERE A~KUNNR = ITAB_KNVP-KUNNR AND             "I:NDVK932932
                 A~BSARK = P_ORDMET AND
                 B~VBTYP_N = 'R' AND
* NDVK932735 Begins
*           ( ( c~cpudt => s_erdat-low and c~cputm => s_erzet-low ) and
*             ( c~cpudt <= s_erdat-high and c~cputm <= s_erzet-high ) ).
            ( ( B~ERDAT => S_ERDAT-LOW AND B~ERZET => S_ERZET-LOW ) AND
            ( B~ERDAT <= S_ERDAT-HIGH AND B~ERZET <= S_ERZET-HIGH ) ).
* NDVK932735 Ends
 
  ENDIF.
 
  SORT ITAB_GI_ORDERS.
  DELETE ADJACENT DUPLICATES FROM ITAB_GI_ORDERS.
 
 
ENDFORM.                               " GET_ITAB_GI_ORDERS
 
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_DCH_ORDERS
*&---------------------------------------------------------------------*
*      This form first stores all the orders for which the difference
*      between the promised delivery date and the current date is less
*      than the number of days specified in the selection screen in an
*      internal table (temp_itab_orders).
*      Then if there is a change in the delivery dates for those orders
*      the orders are selected to send acknowledgement.
*----------------------------------------------------------------------*
FORM GET_ITAB_DCH_ORDERS.
 
  LOOP AT ITAB_OPEN_ORDERS.
    DIFF = ITAB_OPEN_ORDERS-MAHDT - SY-DATUM .
    IF DIFF >= 0 AND DIFF <= P_DIFF.
      TEMP_ITAB_ORDERS = ITAB_OPEN_ORDERS.
      APPEND TEMP_ITAB_ORDERS.
    ENDIF.
  ENDLOOP.
 
* Check for the change in the delivery date. If this date is different
* from the promised date, we need to send the acknowledgement.
  IF NOT TEMP_ITAB_ORDERS[] IS INITIAL.
    SELECT VBELN
           INTO TABLE ITAB_DCH_ORDERS
           FROM VBEP
           FOR ALL ENTRIES IN TEMP_ITAB_ORDERS
           WHERE VBELN = TEMP_ITAB_ORDERS-VBELN AND
*                edatu <> temp_itab_orders-mahdt.          "C:NDVK933006
                 EDATU  > TEMP_ITAB_ORDERS-MAHDT.          "I:NDVK933006
 
    SORT ITAB_DCH_ORDERS BY VBELN.
    DELETE ADJACENT DUPLICATES FROM ITAB_DCH_ORDERS.
  ENDIF.
 
ENDFORM.                               " GET_ITAB_DCH_ORDERS
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_OPEN_ORDERS
*&---------------------------------------------------------------------*
*       This Forms retrieves all the open orders for a given sold-to,
*       ordering method. It only selects the orders that have not been
*       rejected.
*----------------------------------------------------------------------*
FORM GET_ITAB_OPEN_ORDERS.
 
  SELECT B~VBELN
         INTO TABLE ITAB_OPEN_ORDERS
         FROM ZNOPENORD AS A
         INNER JOIN VBAK AS B ON A~VBELN = B~VBELN
         INNER JOIN VBAP AS C ON A~VBELN = C~VBELN
* NDVK932932 begins
          FOR ALL ENTRIES IN ITAB_KNVP
*        where a~kunnr in s_kunnr and                      "I:NDVK932735
           WHERE A~KUNNR = ITAB_KNVP-KUNNR AND
* NDVK932932 ends
               B~BSARK = P_ORDMET AND
               C~ABGRU = SPACE.
  SORT ITAB_OPEN_ORDERS BY VBELN.
  DELETE ADJACENT DUPLICATES FROM ITAB_OPEN_ORDERS COMPARING VBELN.
  CLEAR ITAB_OPEN_ORDERS.
 
ENDFORM.                               " GET_ITAB_OPEN_ORDERS
 
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_FINAL_ORDERS
*&---------------------------------------------------------------------*
*       This form collects all the orders which were selected earlier  *
*       into an final internal table.                                  *
*----------------------------------------------------------------------*
FORM GET_ITAB_FINAL_ORDERS.
 
  LOOP AT ITAB_NEW_ORDERS.
    ITAB_FINAL_ORDERS-VBELN = ITAB_NEW_ORDERS-VBELN.
    ITAB_FINAL_ORDERS-KSCHL = p_ks_ocr.
    APPEND ITAB_FINAL_ORDERS.
  ENDLOOP.
 
* NDVK932735 Begins
  LOOP AT ITAB_INC_ORDERS.
    ITAB_FINAL_ORDERS-VBELN = ITAB_INC_ORDERS-VBELN.
    ITAB_FINAL_ORDERS-KSCHL = P_KS_IO.
    APPEND ITAB_FINAL_ORDERS.
  ENDLOOP.
* NDVK932735 Ends
 
  LOOP AT ITAB_DCH_ORDERS.
    ITAB_FINAL_ORDERS-VBELN = ITAB_DCH_ORDERS-VBELN.
    ITAB_FINAL_ORDERS-KSCHL = P_KS_DCH.
    APPEND ITAB_FINAL_ORDERS.
  ENDLOOP.
 
  LOOP AT ITAB_DCR_ORDERS.
    ITAB_FINAL_ORDERS-VBELN = ITAB_DCR_ORDERS-VBELN.
    ITAB_FINAL_ORDERS-KSCHL = P_KS_DCR.
    APPEND ITAB_FINAL_ORDERS.
  ENDLOOP.
 
  LOOP AT ITAB_REJ_ORDERS.
    ITAB_FINAL_ORDERS-VBELN = ITAB_REJ_ORDERS-VBELN.
    ITAB_FINAL_ORDERS-KSCHL = P_KS_R.
    APPEND ITAB_FINAL_ORDERS.
  ENDLOOP.
 
  LOOP AT ITAB_GI_ORDERS.
    ITAB_FINAL_ORDERS-VBELN = ITAB_GI_ORDERS-VBELN.
    ITAB_FINAL_ORDERS-KSCHL = P_KS_GI.
    APPEND ITAB_FINAL_ORDERS.
  ENDLOOP.
 
  SORT ITAB_FINAL_ORDERS BY VBELN.
 
ENDFORM.                               " GET_ITAB_FINAL_ORDERS
*&---------------------------------------------------------------------*
*&      Form  GET_ITAB_NEW_ORDERS
*&---------------------------------------------------------------------*
*       This section of the code is to retrieve all the new Lowe's
*       Special orders. It can retrieve the orders which were created in
*       last 30 minutes or during a specific time period.
*----------------------------------------------------------------------*
FORM GET_ITAB_NEW_ORDERS.
 
*  IF S_ERDAT IS INITIAL.
*
*    TIME = SY-UZEIT - TIME.
*
*    IF SY-UZEIT < '120000' AND TIME > '120000'.
*      DATE = SY-DATUM - 1.
*    ELSE.
*      DATE = SY-DATUM.
*    ENDIF.
*
*    SELECT B~VBELN
*           INTO TABLE ITAB_NEW_ORDERS
*           FROM ZNOPENORD AS A
*           INNER JOIN VBAK AS B ON A~VBELN = B~VBELN
*           INNER JOIN VBAP AS C ON A~VBELN = C~VBELN
*          WHERE A~KUNNR IN S_KUNNR AND                      "NDVK932735
*                 B~BSARK = P_ORDMET AND
*                 B~ERDAT => DATE AND
*                 B~ERZET =>  TIME AND
*                 C~ABGRU = SPACE.
*
*  ELSE.
*    SELECT B~VBELN
*           INTO TABLE ITAB_NEW_ORDERS
*           FROM ZNOPENORD AS A
*           INNER JOIN VBAK AS B ON A~VBELN = B~VBELN
*           INNER JOIN VBAP AS C ON A~VBELN = C~VBELN
*          WHERE A~KUNNR IN S_KUNNR AND                      "NDVK932735
*                 B~BSARK = P_ORDMET AND
*            ( ( B~ERDAT => S_ERDAT-LOW AND B~ERZET => S_ERZET-LOW ) AND
*          ( B~ERDAT <= S_ERDAT-HIGH AND B~ERZET <= S_ERZET-HIGH ) ) AND
*                C~ABGRU = SPACE.
*
*  ENDIF.
*  SORT ITAB_NEW_ORDERS.
*
*  DELETE ADJACENT DUPLICATES FROM ITAB_NEW_ORDERS.
 
LOOP AT ITAB_ORDERS WHERE KSCHL = P_KS_OCR.
       READ TABLE TEMP_INC_ORDERS WITH KEY VBELN = ITAB_ORDERS-VBELN
                                                         BINARY SEARCH.
       IF SY-SUBRC <> 0.
         ITAB_NEW_ORDERS-VBELN = ITAB_ORDERS-VBELN.
         APPEND ITAB_NEW_ORDERS.
       ENDIF.
ENDLOOP.
 
 
ENDFORM.                               " GET_ITAB_NEW_ORDERS
 
*&---------------------------------------------------------------------*
*&      Form  GET_PROMISED_DDATES
*&---------------------------------------------------------------------*
*       This form reads the Text field (Z222) 'Reuested delivery date'
*       of sales orders and gets the promised delivery dates.
*----------------------------------------------------------------------*
FORM GET_PROMISED_DDATES.
  LOOP AT ITAB_OPEN_ORDERS.
    OBJ_NAME = ITAB_OPEN_ORDERS-VBELN.
    CALL FUNCTION 'READ_TEXT'
      EXPORTING
*         CLIENT                  = SY-MANDT
           ID                      = 'Z222'
           LANGUAGE                = 'E'
           NAME                    = OBJ_NAME
           OBJECT                  = 'VBBK'
*         ARCHIVE_HANDLE          = 0
*    IMPORTING
*        header                   =
      TABLES
           LINES                   = I_TLINE
      EXCEPTIONS
           ID                      = 1
           LANGUAGE                = 2
           NAME                    = 3
           NOT_FOUND               = 4
           OBJECT                  = 5
           REFERENCE_CHECK         = 6
           WRONG_ACCESS_TO_ARCHIVE = 7
           OTHERS                  = 8.
 
    READ TABLE I_TLINE INDEX 1.
    ITAB_OPEN_ORDERS-MAHDT = I_TLINE-TDLINE.
    MODIFY ITAB_OPEN_ORDERS.
    CLEAR OBJ_NAME.
    CLEAR I_TLINE.
    REFRESH I_TLINE.
  ENDLOOP.
 
ENDFORM.                               " GET_PROMISED_DDATES
*&---------------------------------------------------------------------*
*&      Form  GET_SOLD-TO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_SOLD-TO.
 
  SELECT KUNNR
          INTO TABLE ITAB_KNVP
          FROM KNVP
          WHERE KUNN2 = P_KUNN2 AND
                PARVW = 'RE' AND
                VKORG = '0300'.
 
*  sort itab_knvp.                                         "C:NDVK932735
*  delete adjacent duplicates from itab_knvp.              "C:NDVK932735
 
  IF SY-SUBRC = 0.
    SORT ITAB_KNVP  BY KUNNR.
    DELETE ADJACENT DUPLICATES FROM ITAB_KNVP.
* NDVK932932 Begins
*    loop at itab_knvp.
*      s_kunnr-sign = 'I'.
*      s_kunnr-option = 'EQ'.
*      s_kunnr-low = itab_knvp-kunnr.
*      append s_kunnr.
*    endloop.
* NDVK932932 Ends
  ENDIF.
 
ENDFORM.                               " GET_SOLD-TO
*&---------------------------------------------------------------------*
*&      Form  GET_INC_ORDERS
*&---------------------------------------------------------------------*
*       This form gets the incomplete orders
*----------------------------------------------------------------------*
FORM GET_INC_ORDERS.
 
* NDVK932932 Begins
*loop at itab_orders where kschl = p_ks_io.
*  temp_inc_orders-vbeln = itab_orders-vbeln.
*  append temp_inc_orders.
* endloop.
* NDVK932932 Ends
 
SELECT VBELN
*      into table itab_inc_orders                          "C:NDVK932932
       INTO TABLE TEMP_INC_ORDERS                          "I:NDVK932932
       FROM VBUV
*      for all entries in temp_inc_orders                  "C:NDVK932932
       FOR ALL ENTRIES IN ITAB_ORDERS                      "I:NDVK932932
*      where vbeln = temp_inc_orders-vbeln.                "C:NDVK932932
       WHERE VBELN = ITAB_ORDERS-VBELN.                    "I:NDVK932932
 
 
* NDVK932932 Begins
  SORT TEMP_INC_ORDERS.
LOOP AT ITAB_ORDERS WHERE KSCHL = P_KS_IO.
  READ TABLE TEMP_INC_ORDERS WITH KEY VBELN = ITAB_ORDERS-VBELN
                                                      BINARY SEARCH.
  IF SY-SUBRC = 0.
    ITAB_INC_ORDERS-VBELN = ITAB_ORDERS-VBELN.
    APPEND ITAB_INC_ORDERS.
  ENDIF.
ENDLOOP.
* NDVK932932 Begins
 
 
ENDFORM.                    " GET_INC_ORDERS
 
*&---------------------------------------------------------------------*
*&      Form  DEL_INC_ORDERS
*&---------------------------------------------------------------------*
*       Deletes incomplete orders from the new orders internal table
*----------------------------------------------------------------------*
FORM DEL_INC_ORDERS.
 
 LOOP AT ITAB_INC_ORDERS.
  READ TABLE ITAB_NEW_ORDERS WITH KEY VBELN = ITAB_INC_ORDERS-VBELN
                                               BINARY SEARCH.
  IF SY-SUBRC = 0.
     DELETE ITAB_NEW_ORDERS WHERE VBELN = ITAB_INC_ORDERS-VBELN.
  ENDIF.
 ENDLOOP.
 
ENDFORM.                    " DEL_INC_ORDERS
*&---------------------------------------------------------------------*
*&      Form  GET_ORDERS
*&---------------------------------------------------------------------*
*       This form gets all the orders from NAST entries for which we
*       need to send either the order creation acknowledgement or
*       incomplete order acknowledgement
*----------------------------------------------------------------------*
FORM GET_ORDERS.
 
* Open order internal table cannot be used in the select statement
* below because of type mismatch between nast-objky and vbak-vbeln.
 
LOOP AT ITAB_OPEN_ORDERS.
 TEMP_OPEN_ORDERS-OBJKY = ITAB_OPEN_ORDERS-VBELN.          "I:NDVK932932
 APPEND TEMP_OPEN_ORDERS.                                  "I:NDVK932932
ENDLOOP.
 
SELECT OBJKY
       KSCHL
       INTO TABLE ITAB_ORDERS
       FROM NAST
       FOR ALL ENTRIES IN TEMP_OPEN_ORDERS                 "I:NDVK932932
       WHERE KAPPL = 'V1'                    AND
             OBJKY = TEMP_OPEN_ORDERS-OBJKY  AND           "I:NDVK932932
             KSCHL IN (P_KS_OCR, P_KS_IO)    AND
             SPRAS = 'E'                     AND
             PARNR = P_KUNN2                 AND
             PARVW = 'RE'                    AND
             VSTAT = '0'.
 
SORT ITAB_ORDERS.
ENDFORM.                    " GET_ORDERS
Comments