Skip to Content
0
Former Member
Nov 24, 2005 at 12:36 PM

Making changes to date-related fields

706 Views

Hi all,

Before i continue, i'd like to thank everyone who helped me develop my first ever ABAP program. However, i am now asked to make changes to it.

Criteria: The input field for PO Date (I_BEDAT) now has to become 2 separate input fields. The first field is where the user has to input the month that they wish to query (I_MONTH1 to I_MONTH2). The second field is where the user has to input the year that they wish to query (I_YEAR).

The following is what i have done so far, without any changes made yet. I'm still reading what the F1 help has to say before i do anything...but if anyone could give me a hint or an idea where to start with, please share it with me...thanks to all in advance 😊

*&---------------------------------------------------------------------*
*& Report  ZLPUPO100                                                   *
*&                                                                     *
*& Description : Delivery Evaluation Report                            *
*&---------------------------------------------------------------------*
REPORT ZLPUPO100 NO STANDARD PAGE HEADING LINE-SIZE 135 LINE-COUNT 65.

TABLES: EKKO,
        EKPO,
        EKBE,
        EKET.

DATA: BEGIN OF ITAB OCCURS 0,
      EBELN LIKE EKKO-EBELN,  "Purchasing Document Number
      EBELP LIKE EKPO-EBELP,  "Item Number of Purchasing Document
      EINDT LIKE EKET-EINDT,  "Item delivery date
      BUDAT LIKE EKBE-BUDAT,  "Posting Date in the Document
      END OF ITAB.

DATA: BEGIN OF WTAB OCCURS 0,
      EBELN LIKE EKBE-EBELN,  "Purchasing Document Number
      EBELP LIKE EKBE-EBELP,  "Item Number of Purchasing Document
*      EINDT LIKE EKET-EINDT,  "Item delivery date
      BUDAT LIKE EKBE-BUDAT,  "Posting Date in the Document
      END OF WTAB.

DATA V_OVERDUE TYPE I.

DATA COUNT_OVERDUE TYPE I.
DATA COUNT_LINES TYPE I.

DATA V_PERCENTAGE TYPE P DECIMALS 9.

*&---------------------------------------------------------------------*
*&    SELECTION-SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:
  I_WERKS FOR EKPO-WERKS DEFAULT '6000' NO INTERVALS,  "PLANT
  I_BUKRS FOR EKKO-BUKRS DEFAULT 'GSPC' NO INTERVALS,  "COMPANY CODE
  I_EBELN FOR EKKO-EBELN DEFAULT,   "PO NUMBER
  I_LIFNR FOR EKKO-LIFNR,                              "VENDOR NUMBER
  I_MATNR FOR EKPO-MATNR.                              "MATERIAL NUMBER
  I_BEDAT FOR EKKO-BEDAT.                              "PO DATE
PARAMETERS I_MONTH(2) TYPE D.                         "YEAR
PARAMETERS I_YEAR(4) TYPE D DEFAULT SY-DATUM+0(4).    "MONTH
SELECTION-SCREEN END OF BLOCK 1.

SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE TEXT-002.
PARAMETERS:  P_ONET RADIOBUTTON GROUP RFMT DEFAULT 'X',  "ON-TIME
             P_ODUE RADIOBUTTON GROUP RFMT,  "OVERDUE
             P_ALLP RADIOBUTTON GROUP RFMT,  "BOTH (SORT BY PO NO.)
             P_ALLC RADIOBUTTON GROUP RFMT.  "BOTH (SORT BY CATEGORY)
SELECTION-SCREEN END OF BLOCK 2.

*&---------------------------------------------------------------------*
*&    START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

    PERFORM WRITE_HEADER.
    PERFORM SELECT_DATA.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&    FORM WRITE_HEADER
*&---------------------------------------------------------------------*
FORM WRITE_HEADER.

WRITE: /1 'REPORT:', SY-REPID,
         118 'PAGE:', SY-PAGNO.
  WRITE: /1 'DATE:', SY-DATUM,
         54 'DELIVERY EVALUATION REPORT',
         118 'USER:', SY-UNAME, 147 ' ' .
  WRITE: / SY-ULINE(148).

ENDFORM.

*&---------------------------------------------------------------------*
*&    SELECT_DATA
*&---------------------------------------------------------------------*
FORM SELECT_DATA.

*--> IF ON-TIME DELIVERY IS SELECTED
IF P_ONET EQ 'X'.
  PERFORM WRITE_ONET.

*--> IF OVERDUE DELIVERY IS SELECTED
ELSEIF P_ODUE EQ 'X'.
  PERFORM WRITE_ODUE.

*--> IF BOTH IS SELECTED, SORT BY PO NUMBER
ELSEIF P_ALLP EQ 'X'.
  PERFORM WRITE_ALLP.

*--> IF BOTH IS SELECTED, SORT BY CATEGORY (+/-)
ELSE.
  PERFORM WRITE_ONET.
  PERFORM WRITE_ODUE.
ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM WRITE_ONET
*&---------------------------------------------------------------------*
FORM WRITE_ONET.

SELECT A~EBELN B~EBELP C~EINDT
        INTO CORRESPONDING FIELDS OF TABLE ITAB
        FROM ( EKKO AS A
               INNER JOIN EKPO AS B
                 ON B~EBELN = A~EBELN
               INNER JOIN EKET AS C
                 ON C~EBELN = B~EBELN AND
                    C~EBELP = B~EBELP AND
                    C~ETENR = '1')
        WHERE B~WERKS IN I_WERKS AND
              B~LOEKZ = ' ' AND
              A~BUKRS IN I_BUKRS AND
              A~BSTYP = 'F' AND
              A~EBELN IN I_EBELN AND
              A~LIFNR IN I_LIFNR AND
              B~MATNR IN I_MATNR AND
              A~BEDAT IN I_BEDAT
        ORDER BY A~EBELN B~EBELP.

*DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

SELECT EBELN EBELP BUDAT
  INTO CORRESPONDING FIELDS OF TABLE WTAB
  FROM EKBE
  WHERE WERKS IN I_WERKS AND
        EBELN IN I_EBELN AND
*        EBELP = ITAB-EBELP AND
        VGABE = '1' AND
        BEWTP = 'E'
  ORDER BY EBELN EBELP.

  FORMAT COLOR 1.
  WRITE: / SY-ULINE(86).
  WRITE: /1  '|', 20 'EVALUATION REPORT FOR ON-TIME DELIVERY ITEMS',
          86 '|'.
  FORMAT COLOR OFF.

  FORMAT COLOR 4.
  WRITE: / SY-ULINE(86).
  WRITE: /1  '|', 5 'PO No.',
          14 '|', 16 'PO Item No.',
          28 '|', 'PO Delivery Date',
          47 '|', 'Actual Delivery',
          65 '|', 'Overdue Days (+/-)',
          86 '|'.
  FORMAT COLOR OFF.
  WRITE: / SY-ULINE(86).
  NEW-LINE.

LOOP AT WTAB.
MOVE WTAB-BUDAT TO ITAB-BUDAT.
MODIFY ITAB TRANSPORTING BUDAT
  WHERE EBELN = WTAB-EBELN AND
        EBELP = WTAB-EBELP.
ENDLOOP.

LOOP AT ITAB.
  IF NOT ITAB-BUDAT IS INITIAL.
*--> IF BUDAT CONTAINS A DATE
    V_OVERDUE = ITAB-BUDAT - ITAB-EINDT.
  ELSE.
*-- IF BUDAT DOES NOT CONTAIN A DATE
    CLEAR V_OVERDUE.
  ENDIF.

*--> DISPLAY ON-TIME ITEMS ONLY
*  IF V_OVERDUE LE 0.
  IF ITAB-BUDAT IS INITIAL.
    DELETE ITAB.
  ELSEIF ITAB-BUDAT > ITAB-EINDT.
    DELETE ITAB.
  ELSE.

  WRITE: /1  '|', 3 ITAB-EBELN,   "PO NO
          14 '|', 19 ITAB-EBELP,  "PO ITEM NO
          28 '|', 33 ITAB-EINDT,  "PO DELIVERY DATE
          47 '|', 51 ITAB-BUDAT,  "ACTUAL DELIVERY DATE
          65 '|', V_OVERDUE,      "OVERDUE DAYS
          86 '|'.
*  WRITE: / SY-ULINE(86).
  ENDIF.
ENDLOOP.
  WRITE: / SY-ULINE(86).

ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM WRITE_ODUE
*&---------------------------------------------------------------------*
FORM WRITE_ODUE.

SELECT A~EBELN B~EBELP C~EINDT
        INTO CORRESPONDING FIELDS OF TABLE ITAB
        FROM ( EKKO AS A
               INNER JOIN EKPO AS B
                 ON B~EBELN = A~EBELN
               INNER JOIN EKET AS C
                 ON C~EBELN = B~EBELN AND
                    C~EBELP = B~EBELP AND
                    C~ETENR = '1')
        WHERE B~WERKS IN I_WERKS AND
              B~LOEKZ = ' ' AND
              A~BUKRS IN I_BUKRS AND
              A~BSTYP = 'F' AND
              A~EBELN IN I_EBELN AND
              A~LIFNR IN I_LIFNR AND
              B~MATNR IN I_MATNR AND
              A~BEDAT IN I_BEDAT
        ORDER BY A~EBELN B~EBELP.

*DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

SELECT EBELN EBELP BUDAT
  INTO CORRESPONDING FIELDS OF TABLE WTAB
  FROM EKBE
  WHERE WERKS IN I_WERKS AND
        EBELN IN I_EBELN AND
*        EBELP = ITAB-EBELP AND
        VGABE = '1' AND
        BEWTP = 'E'
  ORDER BY EBELN EBELP.

  FORMAT COLOR 1.
  WRITE: / SY-ULINE(86).
  WRITE: /1  '|', 20 'EVALUATION REPORT FOR OVERDUE DELIVERY ITEMS',
          86 '|'.
  FORMAT COLOR OFF.

  FORMAT COLOR 4.
  WRITE: / SY-ULINE(86).
  WRITE: /1  '|', 5 'PO No.',
          14 '|', 16 'PO Item No.',
          28 '|', 'PO Delivery Date',
          47 '|', 'Actual Delivery',
          65 '|', 'Overdue Days (+/-)',
          86 '|'.
  FORMAT COLOR OFF.
  WRITE: / SY-ULINE(86).
  NEW-LINE.

LOOP AT WTAB.
MOVE WTAB-BUDAT TO ITAB-BUDAT.
MODIFY ITAB TRANSPORTING BUDAT
  WHERE EBELN = WTAB-EBELN AND
        EBELP = WTAB-EBELP.
ENDLOOP.

LOOP AT ITAB.
 ADD 1 TO COUNT_LINES.
ENDLOOP.

LOOP AT ITAB.
  IF NOT ITAB-BUDAT IS INITIAL.
*--> IF BUDAT CONTAINS A DATE
    V_OVERDUE = ITAB-BUDAT - ITAB-EINDT.
  ELSE.
*-- IF BUDAT DOES NOT CONTAIN A DATE
    CLEAR V_OVERDUE.
  ENDIF.

*--> DISPLAY OVERDUE ITEMS ONLY
  IF V_OVERDUE < 0.
*    ADD 1 TO COUNT_OVERDUE.
    DELETE ITAB.
  ELSEIF ITAB-BUDAT = ITAB-EINDT.
    DELETE ITAB.
  ELSE.
    ADD 1 TO COUNT_OVERDUE.
  WRITE: /1  '|', 3 ITAB-EBELN,   "PO NO
          14 '|', 19 ITAB-EBELP,  "PO ITEM NO
          28 '|', 33 ITAB-EINDT,  "PO DELIVERY DATE
          47 '|', 51 ITAB-BUDAT,  "ACTUAL DELIVERY DATE
          65 '|', V_OVERDUE,      "OVERDUE DAYS
          86 '|'.
*  WRITE: / SY-ULINE(86).
  ENDIF.

ENDLOOP.

  WRITE: / SY-ULINE(86).
  NEW-LINE.

  WRITE: /1  '|', 'Total Overdue Delivery Items: '.
  FORMAT COLOR 3.
  WRITE: COUNT_OVERDUE.
  FORMAT COLOR OFF.
  WRITE: 86 '|'.

COMPUTE V_PERCENTAGE = ( COUNT_OVERDUE * 100 ) / COUNT_LINES.

  WRITE: /1 '|', 'Percentage (%) Over All Deliveries: '.
    FORMAT COLOR 3.
    WRITE: V_PERCENTAGE DECIMALS 2.
  FORMAT COLOR OFF.
  WRITE: 86 '|'.

  WRITE: / SY-ULINE(86).

ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM WRITE_ALLP
*&---------------------------------------------------------------------*
FORM WRITE_ALLP.

SELECT A~EBELN B~EBELP C~EINDT
        INTO CORRESPONDING FIELDS OF TABLE ITAB
        FROM ( EKKO AS A
               INNER JOIN EKPO AS B
                 ON B~EBELN = A~EBELN
               INNER JOIN EKET AS C
                 ON C~EBELN = B~EBELN AND
                    C~EBELP = B~EBELP AND
                    C~ETENR = '1')
        WHERE B~WERKS IN I_WERKS AND
              B~LOEKZ = ' ' AND
              A~BUKRS IN I_BUKRS AND
              A~BSTYP = 'F' AND
              A~EBELN IN I_EBELN AND
              A~LIFNR IN I_LIFNR AND
              B~MATNR IN I_MATNR AND
              A~BEDAT IN I_BEDAT
        ORDER BY A~EBELN B~EBELP.

*DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

SELECT EBELN EBELP BUDAT
  INTO CORRESPONDING FIELDS OF TABLE WTAB
  FROM EKBE
  WHERE WERKS IN I_WERKS AND
        EBELN IN I_EBELN AND
*        EBELP = ITAB-EBELP AND
        VGABE = '1' AND
        BEWTP = 'E'
  ORDER BY EBELN EBELP.

  FORMAT COLOR 1.
  WRITE: / SY-ULINE(86).
  WRITE: /1  '|', 20 'EVALUATION REPORT FOR ALL DELIVERY ITEMS',
          86 '|'.
  FORMAT COLOR OFF.

  FORMAT COLOR 4.
  WRITE: / SY-ULINE(86).
  WRITE: /1  '|', 5 'PO No.',
          14 '|', 16 'PO Item No.',
          28 '|', 'PO Delivery Date',
          47 '|', 'Actual Delivery',
          65 '|', 'Overdue Days (+/-)',
          86 '|'.
  FORMAT COLOR OFF.
  WRITE: / SY-ULINE(86).
  NEW-LINE.

LOOP AT WTAB.
MOVE WTAB-BUDAT TO ITAB-BUDAT.
MODIFY ITAB TRANSPORTING BUDAT
  WHERE EBELN = WTAB-EBELN AND
        EBELP = WTAB-EBELP.
ENDLOOP.

LOOP AT ITAB.
  IF NOT ITAB-BUDAT IS INITIAL.
*--> IF BUDAT CONTAINS A DATE
    V_OVERDUE = ITAB-BUDAT - ITAB-EINDT.
  ELSE.
*-- IF BUDAT DOES NOT CONTAIN A DATE
    CLEAR V_OVERDUE.
  ENDIF.

*--> DISPLAY BOTH ON-TIME AND OVERDUE ITEMS
  WRITE: /1  '|', 3 ITAB-EBELN,   "PO NO
          14 '|', 19 ITAB-EBELP,  "PO ITEM NO
          28 '|', 33 ITAB-EINDT,  "PO DELIVERY DATE
          47 '|', 51 ITAB-BUDAT,  "ACTUAL DELIVERY DATE
          65 '|', V_OVERDUE,      "OVERDUE DAYS
          86 '|'.
*  WRITE: / SY-ULINE(86).
ENDLOOP.
  WRITE: / SY-ULINE(86).

ENDFORM.