Skip to Content
author's profile photo Former Member
Former Member

Refining AT NEW statements #2, NOTE: pls ignore my previous thread

Pls ignore the previous thread i created earlier.

Could you guys have a look at the AT NEW statement i wrote. I only want a new PR Doc Type to be written if the next line of output belongs a different PR Doc Type than the previous line.

REPORT ZRMME006 NO STANDARD PAGE HEADING
                MESSAGE-ID 38
                LINE-SIZE 255
                LINE-COUNT 65.

TABLES: EBAN,        "Purchase Requisition
        EBKN,        "Purchase Requisition Account Assignment
        EKKO,        "Purchasing Document Header
        EKPO,        "Purchasing Document Item
        EKBE,        "History of Purchasing Document
        EKET,        "Scheduling Agreement Delivery Schedules
        CDPOS,       "Change document items
        CDHDR,       "Change document header
        PRPS,        "WBS (Work Breakdown Structure) Element Master Data
        T161T.       "Text for Purchasing Document Types

************************************************************************
*    DATA DECLARATION
************************************************************************
DATA: BEGIN OF T_PR OCCURS 0,
        KNTTP        LIKE EBAN-KNTTP,      "Account assignment category
        KOSTL        LIKE EBKN-KOSTL,      "Cost center
        POSID        LIKE PRPS-POSID,      "Project code name
        PS_PSP_PNR   LIKE EBKN-PS_PSP_PNR, "WBS element
        ERNAM        LIKE EBAN-ERNAM,      "User ID
        BANFN        LIKE EBAN-BANFN,      "PR number
        BNFPO        LIKE EBAN-BNFPO,      "PR item number
        MATNR        LIKE EBAN-MATNR,      "Material number
        TXZ01        LIKE EBAN-TXZ01,      "Material description
        BSART        LIKE EBAN-BSART,      "PR document type
        BATXT        LIKE T161T-BATXT,     "Desc of purchasing doc type
        EBELN        LIKE EBAN-EBELN,      "PO number - eban
        EKKO_EBELN   LIKE EKKO-EBELN,      "PO number - ekko
        EKET_EBELN   LIKE EKET-EBELN,      "PO number - eket
        EBELP        LIKE EBAN-EBELP,      "PO item number - eban
        EKPO_EBELP   LIKE EKPO-EBELP,      "PO item number - ekpo
        EKET_EBELP   LIKE EKET-EBELP,      "PO item number - eket
        BADAT        LIKE EBAN-BADAT,      "PR creation date
        CHANGENR_PR  LIKE CDPOS-CHANGENR,  "PR changenr
        UDATE_PR     LIKE CDHDR-UDATE,     "PR approval date
        ANFNR        LIKE EKPO-ANFNR,      "RFQ number
        ANFPS        LIKE EKPO-ANFPS,      "RFQ item number
        CHANGENR_RFQ LIKE CDPOS-CHANGENR,  "RFQ changenr
        UDATE_RFQ    LIKE CDHDR-UDATE,     "RFQ maintained date
        AEDAT        LIKE EKPO-AEDAT,      "PO creation date
        EINDT        LIKE EKET-EINDT,      "PO required (dev date)
        CHANGENR_PO  LIKE CDPOS-CHANGENR,  "PO changenr
        UDATE_PO     LIKE CDHDR-UDATE,     "PO approval date
        DATVR_PO     LIKE NAST-DATVR,      "PO printed date
        CPUDT        LIKE EKBE-CPUDT,      "GRN delivered date
        FRGZU        LIKE EBAN-FRGZU,      "Release status
        EKKO_FRGZU   LIKE EKKO-FRGZU,      "Release status
        RFQ_AEDAT    LIKE EKPO-AEDAT,      "RFQ creation date
        VSTAT        LIKE NAST-VSTAT,      "Processing status of message
        EKGRP        LIKE EBAN-EKGRP,      "Purchasing group
      END OF T_PR.

DATA: BEGIN OF T_DATE OCCURS 0,
        CPUDT LIKE EKBE-CPUDT,
        EBELN LIKE EKKO-EBELN,
        EBELP LIKE EKPO-EBELP,
      END OF T_DATE.

DATA: BEGIN OF T_PUR OCCURS 0.
      INCLUDE STRUCTURE T_PR.
DATA: END OF T_PUR.

DATA: V_PRDAY(10)  TYPE C,           "PR days
      V_RFQDAY(10) TYPE C,           "RFQ days
      V_PODAY(10)  TYPE C,           "PO days
      V_GRNDAY(10) TYPE C,           "GRN days
      V_STADAY     TYPE I,           "Standard days
      V_ACTDAY     TYPE I,           "Actual days
      V_VARDAY(10) TYPE C,           "Variance
      V_RELPR      TYPE I,           "Release pr days
      V_RELPO      TYPE I,           "Release po days
      V_PRTEMP(10),
      V_RFQTEMP(10),
      V_POTEMP(10),
      V_GRNTEMP(10),
      V_FLAG(1)    TYPE C,
      V_FLAG2(1)   TYPE C,
      V_FLAG3(1)   TYPE C,
      V_COUNT      TYPE I,
      V_COUNT_MOD  TYPE I,
      V_SDATE      LIKE SY-DATUM,
      V_EDATE      LIKE SY-DATUM,
      V_LEN        TYPE I,
      V_LEN2       TYPE I.
DATA: CHECK(1) TYPE C.                                       "DEVK951017
************************************************************************
* selection screen                                                     *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_WERKS  FOR EBAN-WERKS DEFAULT '6001' to '6002', "Plant
                S_EKORG  FOR EBAN-EKORG DEFAULT '6001' NO INTERVALS,
                "Purch Org
                S_BSART  FOR EBAN-BSART,
                "PR type
                S_BANFN  FOR EBAN-BANFN,
                "PR number
                S_BADAT  FOR EBAN-BADAT.
                "PR date
SELECTION-SCREEN END OF BLOCK BLK1.

SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS: S_KOSTL  FOR EBKN-KOSTL,                   "Cost ctr
                S_PS_PNR FOR EBKN-PS_PSP_PNR NO-DISPLAY,   "Project code
                S_ERNAM  FOR EBAN-ERNAM.                   "User ID
PARAMETERS:     P_ASSET AS CHECKBOX DEFAULT 'X',  "Acct Assign - A
                P_KOSTL AS CHECKBOX DEFAULT 'X',  "Acct Assign - K
                P_ERNAM AS CHECKBOX DEFAULT 'X',  "Acct Assign - Z
                P_BSI AS CHECKBOX DEFAULT 'X',    "Acct Assign - H
                P_MOI AS CHECKBOX DEFAULT 'X',    "Acct Assign - F
                P_STA AS CHECKBOX DEFAULT 'X'.    "Acct Assign - <blank>
SELECTION-SCREEN END OF BLOCK BLK2.

SELECTION-SCREEN BEGIN OF BLOCK BLK3 WITH FRAME TITLE TEXT-003.
PARAMETERS:     P_CON RADIOBUTTON GROUP PGRP,               "Overseas
                P_LCL RADIOBUTTON GROUP PGRP,               "Local
                P_ALL RADIOBUTTON GROUP PGRP DEFAULT 'X'.   "All
SELECTION-SCREEN END OF BLOCK BLK3.

*--> range of knttp that the report will only select
RANGES: S_KNTTP FOR EBAN-KNTTP,
*--> range of tcode that approval obtained from
        S_TCODE FOR CDHDR-TCODE.

TOP-OF-PAGE.
*  perform write_rpttop using sy-title v_sdate v_edate.      "DEVK951017
*PERFORM WRITE_RPTTOP USING SY-TITLE S_BADAT-LOW S_BADAT-
*HIGH."DEVK951017

************************************************************************
*    START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
  PERFORM INITIALISATION.
  IF P_ASSET IS INITIAL AND
     P_KOSTL IS INITIAL AND
     P_ERNAM IS INITIAL AND
     P_BSI IS INITIAL AND
     P_MOI IS INITIAL AND
     P_STA IS INITIAL.
    MESSAGE S000 WITH TEXT-E02.
    EXIT.
  ELSE.
    PERFORM SELECT_DATA.
    IF V_FLAG NE 'X'.
      PERFORM WRITE_REPORT.
*      PERFORM GET_TPAGENO.
*      PERFORM WRITE_RPTEND.
    ELSE.
      MESSAGE S000 WITH TEXT-E01.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
FORM SELECT_DATA.
IF P_CON EQ 'X'.
  SELECT X~KNTTP Y~KOSTL X~ERNAM X~BANFN X~BNFPO X~MATNR
         X~TXZ01 X~BSART X~EBELN X~EBELP X~BADAT X~FRGZU
    FROM ( EBAN AS X
             INNER JOIN EBKN AS Y
               ON X~BANFN EQ Y~BANFN AND
                  X~BNFPO EQ Y~BNFPO )
  APPENDING CORRESPONDING FIELDS OF TABLE T_PR
    WHERE X~BANFN IN S_BANFN AND
          X~LOEKZ EQ '' AND
          X~KNTTP IN S_KNTTP AND
          X~WERKS IN S_WERKS AND
          X~BADAT IN S_BADAT AND
          X~ERNAM IN S_ERNAM AND
          X~BSART IN S_BSART AND
          X~EKORG IN S_EKORG AND
          Y~KOSTL IN S_KOSTL AND
          EKGRP = 'OVS' AND
          EKGRP = 'CON'.

ELSEIF P_LCL EQ 'X'.
  SELECT X~KNTTP Y~KOSTL X~ERNAM X~BANFN X~BNFPO X~MATNR
         X~TXZ01 X~BSART X~EBELN X~EBELP X~BADAT X~FRGZU
    FROM ( EBAN AS X
             INNER JOIN EBKN AS Y
               ON X~BANFN EQ Y~BANFN AND
                  X~BNFPO EQ Y~BNFPO )
  APPENDING CORRESPONDING FIELDS OF TABLE T_PR
    WHERE X~BANFN IN S_BANFN AND
          X~LOEKZ EQ '' AND
          X~KNTTP IN S_KNTTP AND
          X~WERKS IN S_WERKS AND
          X~BADAT IN S_BADAT AND
          X~ERNAM IN S_ERNAM AND
          X~BSART IN S_BSART AND
          X~EKORG IN S_EKORG AND
          Y~KOSTL IN S_KOSTL AND
          EKGRP = 'LCL'.

ELSE.
  SELECT X~KNTTP Y~KOSTL X~ERNAM X~BANFN X~BNFPO X~MATNR
         X~TXZ01 X~BSART X~EBELN X~EBELP X~BADAT X~FRGZU
    FROM ( EBAN AS X
             INNER JOIN EBKN AS Y
               ON X~BANFN EQ Y~BANFN AND
                  X~BNFPO EQ Y~BNFPO )
  APPENDING CORRESPONDING FIELDS OF TABLE T_PR
    WHERE X~BANFN IN S_BANFN AND
          X~LOEKZ EQ '' AND
          X~KNTTP IN S_KNTTP AND
          X~WERKS IN S_WERKS AND
          X~BADAT IN S_BADAT AND
          X~ERNAM IN S_ERNAM AND
          X~BSART IN S_BSART AND
          X~EKORG IN S_EKORG AND
          Y~KOSTL IN S_KOSTL.

ENDIF.

*  SELECT * FROM ZEPURDAY INTO T_PRDAY.
*  APPEND T_PRDAY.
*  ENDSELECT.

  READ TABLE T_PR INDEX 1.
  IF SY-SUBRC NE 0.
    V_FLAG = 'X'.
  ENDIF.
ENDFORM.                    " SELECT_DATA

*&---------------------------------------------------------------------*
*&      Form  WRITE_REPORT
*&---------------------------------------------------------------------*
FORM WRITE_REPORT.
DATA: V_ERNAM LIKE EBKN-ERNAM,
      V_KOSTL LIKE EBKN-KOSTL.

*--> get from and to date for report header
  PERFORM GET_TITLE_DATE.

*--> get header and line item data
  PERFORM GET_HEADER_ITEM.

*--> check data entries of table zepurday.
*  PERFORM CHECK_TZEPURDAY.

*--> identify sort key for sorting
  PERFORM SORT.

  CLEAR T_PUR.
  LOOP AT T_PUR.

*--> get further data from tables against t_pr
    PERFORM PROCESS_DATA.

*--> get standard day
    PERFORM GET_STAND_DAY.

*--> get latest grn date
    PERFORM GET_LATEST_GRNDATE.

*--> get actual day = GRN date - PR creation date
    PERFORM GET_ACT_DAY.

*--> get variance days = Standard days - Actual days
    PERFORM GET_VAR_DAY.

    V_COUNT = V_COUNT + 1.
    MOVE: T_PUR-ERNAM TO V_ERNAM,
          T_PUR-KOSTL TO V_KOSTL.

    AT NEW KNTTP.
      IF V_FLAG3 NE 'X'.
*        NEW-PAGE.
      ENDIF.
      V_FLAG3 = 'X'.
      SKIP 1.
     WRITE:/2 'Account Assignment:', 22(10) T_PUR-KNTTP COLOR COL_GROUP.
    ENDAT.

*--> Having trouble with this part
IF T_PUR-KNTTP EQ 'Z' OR
   T_PUR-KNTTP EQ 'A' OR
   T_PUR-KNTTP EQ 'K' OR
   T_PUR-KNTTP EQ 'H' OR
   T_PUR-KNTTP EQ 'F'.
 AT NEW BSART.
    SELECT SINGLE * FROM T161T
    WHERE SPRAS = 'EN' AND
          BSART = T_PUR-BSART AND
          BSTYP = 'B'.
    T_PUR-BATXT = T161T-BATXT.

  IF V_FLAG3 NE 'X'.
  ENDIF.
  V_FLAG3 = 'X'.
  WRITE:/2 'PR Doc Type Desc:',
         22(3) T_PUR-BSART COLOR COL_GROUP.
  WRITE: 26 T_PUR-BATXT NO-GAP COLOR COL_GROUP.
  PERFORM WRITE_HEADER.
ENDAT.

ELSE.
  AT NEW BSART.
    SELECT SINGLE * FROM T161T
    WHERE SPRAS = 'EN' AND
          BSART = T_PUR-BSART AND
          BSTYP = 'B'.
    T_PUR-BATXT = T161T-BATXT.
  IF V_FLAG3 NE 'X'.
  ENDIF.
  V_FLAG3 = 'X'.
  WRITE:/2 'PR Doc Type Desc:',
         22(3) T_PUR-BSART COLOR COL_GROUP.
  WRITE: 26 T_PUR-BATXT NO-GAP COLOR COL_GROUP.
  PERFORM WRITE_HEADER.
ENDAT.

ENDIF.

*    IF T_PUR-KNTTP EQ 'Z'.
*      AT NEW ERNAM.
*        IF SY-LINNO >= 60.
*          NEW-PAGE.
*        ENDIF.
*         WRITE:/2 'User ID:', 22(10) V_ERNAM COLOR COL_GROUP.
*          PERFORM WRITE_HEADER. "write contents header
*      ENDAT.
*    ELSEIF T_PUR-KNTTP EQ 'A' OR T_PUR-KNTTP EQ 'K'.
*      AT NEW KOSTL.
*        IF SY-LINNO >= 60.
*          NEW-PAGE.
*        ENDIF.
*         WRITE:/2 'Cost Center:', 22(10) V_KOSTL COLOR COL_GROUP.
*          PERFORM WRITE_HEADER. "write contents header
*      ENDAT.
*
*    ELSEIF T_PUR-KNTTP EQ 'P'.
*      AT NEW POSID.
*        IF SY-LINNO >= 60.
*          NEW-PAGE.
*        ENDIF.
*     WRITE:/2 'Project Code:', 22(10) T_PUR-POSID COLOR COL_GROUP.
*          PERFORM WRITE_HEADER. "write contents header
*      ENDAT.
*    ENDIF.

*--> write report details
    IF SY-LINNO >= 60.
      ULINE (255).
      NEW-PAGE.
      PERFORM WRITE_HEADER.
    ENDIF.
      PERFORM INVERT_LINE_ITEMS_COLOR.
      PERFORM WRITE_DETAILS.

*--> display data ordered by User ID/Cost Center/Project ID.
    IF T_PUR-KNTTP EQ 'Z'.
      AT END OF ERNAM.
        ULINE (236).
        SKIP 1.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        CLEAR: V_COUNT_MOD, V_COUNT.
      ENDAT.

    ELSEIF T_PUR-KNTTP EQ 'A' OR T_PUR-KNTTP EQ 'K'.
      AT END OF KOSTL.
        ULINE (236).
        SKIP 1.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        CLEAR: V_COUNT_MOD, V_COUNT.
    ENDAT.

    ELSEIF T_PUR-KNTTP EQ 'H'.
      AT END OF KOSTL.
        ULINE (236).
        SKIP 1.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        CLEAR: V_COUNT_MOD, V_COUNT.
      ENDAT.

    ELSEIF T_PUR-KNTTP EQ 'F'.
      AT END OF KOSTL.
        ULINE (236).
        SKIP 1.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        CLEAR: V_COUNT_MOD, V_COUNT.
      ENDAT.

    ELSEIF T_PUR-KNTTP EQ ' '.
      AT END OF KOSTL.
        ULINE (236).
        SKIP 1.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        CLEAR: V_COUNT_MOD, V_COUNT.
      ENDAT.
    ENDIF.

  CLEAR: V_PRDAY,
         V_PRTEMP,
         V_RFQDAY,
         V_RFQTEMP,
         V_PODAY,
         V_POTEMP,
         V_GRNDAY,
         V_GRNTEMP,
         V_ACTDAY,
         V_STADAY,
         V_RELPR,
         V_RELPO,
         V_FLAG3.
  ENDLOOP.
ENDFORM.                    " WRITE_REPORT

*&---------------------------------------------------------------------*
*&    FORM INITIALISATION
*&---------------------------------------------------------------------*
*&      Initialize value for s_knttp                                   *
*&---------------------------------------------------------------------*
FORM INITIALISATION.

S_KNTTP-SIGN = 'I'.
S_KNTTP-OPTION = 'EQ'.

*--> BUDGETED ASSET
IF P_ASSET = 'X'.
  S_KNTTP-LOW = 'A'.
  APPEND S_KNTTP.
ENDIF.

*--> COST CENTER
IF P_KOSTL = 'X'.
  S_KNTTP-LOW = 'K'.
  APPEND S_KNTTP.
ENDIF.

*--> Project
*IF P_PCODE = 'X'.
*  S_KNTTP-LOW = 'P'.
*  APPEND S_KNTTP.f
*ENDIF.

*--> NON-BUDGETED ASSET
IF P_ERNAM = 'X'.
  S_KNTTP-LOW = 'Z'.
  APPEND S_KNTTP.
ENDIF.

*--> BALANCE SHEET ITEM
IF P_BSI = 'X'.
  S_KNTTP-LOW = 'H'.
  APPEND S_KNTTP.
ENDIF.

*--> MO ITEM
IF P_MOI = 'X'.
  S_KNTTP-LOW = 'F'.
  APPEND S_KNTTP.
ENDIF.

*--> STANDARD
IF P_STA = 'X'.
  S_KNTTP-LOW = ' '.
  APPEND S_KNTTP.
ENDIF.

S_TCODE-SIGN = 'I'.
S_TCODE-OPTION = 'EQ'.

S_TCODE-LOW = 'ZME55'.
  APPEND S_TCODE.

S_TCODE-LOW = 'ME54'.
  APPEND S_TCODE.

S_TCODE-LOW = 'ME28'.
  APPEND S_TCODE.

S_TCODE-LOW = 'ME47'.
  APPEND S_TCODE.

ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM SORT
*&---------------------------------------------------------------------*
FORM SORT.

CLEAR T_PUR.

LOOP AT T_PUR.
  IF T_PUR-KNTTP EQ 'A' OR
     T_PUR-KNTTP EQ 'K' OR
     T_PUR-KNTTP EQ 'Z' OR
     T_PUR-KNTTP EQ 'H' OR
     T_PUR-KNTTP EQ 'F' OR
     T_PUR-KNTTP EQ ' '.
    SORT T_PUR BY BSART EBELN EBELP.
    EXIT.

  ENDIF.
ENDLOOP.

ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM PROCESS_DATA
*&---------------------------------------------------------------------*
FORM PROCESS_DATA.
DATA: V_TABKEY  LIKE CDPOS-TABKEY,
      V_TABKEY2 LIKE CDPOS-TABKEY,
      V_TABKEY3 LIKE CDPOS-TABKEY.

  CONCATENATE SY-MANDT T_PUR-BANFN T_PUR-BNFPO INTO V_TABKEY.
  CONCATENATE SY-MANDT T_PUR-EBELN INTO V_TABKEY2.
  CONCATENATE SY-MANDT T_PUR-ANFNR T_PUR-EKPO_EBELP INTO V_TABKEY3.

*--> get po history data
  REFRESH T_DATE.
  SELECT CPUDT EBELN EBELP
    INTO CORRESPONDING FIELDS OF T_DATE
    FROM EKBE
    WHERE EBELN EQ T_PUR-EBELN AND EBELP EQ T_PUR-EBELP
      AND BEWTP EQ 'E' AND BWART EQ '101'.
  APPEND T_DATE.
  ENDSELECT.

*-->get scheduling agreement delivery schedules data
  SELECT EINDT INTO T_PUR-EINDT FROM EKET
    WHERE EBELN EQ T_PUR-EBELN AND EBELP EQ T_PUR-EBELP.
  MODIFY T_PUR TRANSPORTING EINDT
         WHERE EBELN EQ T_PUR-EBELN AND EBELP EQ T_PUR-EBELP.
  ENDSELECT.

*--> PR approval date
  SELECT CHANGENR INTO T_PUR-CHANGENR_PR
         FROM CDPOS
         WHERE OBJECTCLAS EQ 'BANF' AND OBJECTID EQ T_PUR-BANFN
           AND TABNAME EQ 'EBAN' AND TABKEY EQ V_TABKEY
           AND FNAME EQ 'FRGKZ' AND CHNGIND EQ 'U'
           AND VALUE_NEW EQ '2'.
  MODIFY T_PUR TRANSPORTING CHANGENR_PR WHERE BANFN EQ T_PUR-BANFN.
  ENDSELECT.
  SELECT UDATE INTO T_PUR-UDATE_PR
         FROM CDHDR
         WHERE OBJECTCLAS EQ 'BANF' AND OBJECTID EQ T_PUR-BANFN
         AND TCODE IN S_TCODE AND CHANGE_IND EQ 'U'
         AND CHANGENR EQ T_PUR-CHANGENR_PR.
  MODIFY T_PUR TRANSPORTING UDATE_PR WHERE BANFN EQ T_PUR-BANFN.
  ENDSELECT.

*--> PO approval date
  SELECT CHANGENR INTO T_PUR-CHANGENR_PO
         FROM CDPOS
         WHERE OBJECTCLAS EQ 'EINKBELEG' AND OBJECTID EQ T_PUR-EBELN
           AND TABNAME EQ 'EKKO' AND TABKEY EQ V_TABKEY2
           AND FNAME EQ 'FRGKE' AND CHNGIND EQ 'U'
           AND VALUE_NEW EQ 'A'.
  MODIFY T_PUR TRANSPORTING CHANGENR_PO WHERE EBELN EQ T_PUR-EBELN.
  ENDSELECT.
  SELECT UDATE INTO T_PUR-UDATE_PO
         FROM CDHDR
         WHERE OBJECTCLAS EQ 'EINKBELEG' AND OBJECTID EQ T_PUR-EBELN
         AND TCODE IN S_TCODE AND CHANGE_IND EQ 'U'
         AND CHANGENR EQ T_PUR-CHANGENR_PO.
  MODIFY T_PUR TRANSPORTING UDATE_PO WHERE EBELN EQ T_PUR-EBELN.
  ENDSELECT.

*--> PO printed date
  SELECT DATVR VSTAT INTO (T_PUR-DATVR_PO, T_PUR-VSTAT)
         FROM NAST
         WHERE KAPPL EQ 'EF' AND OBJKY EQ T_PUR-EBELN.
*           and vstat eq '1'.
  MODIFY T_PUR TRANSPORTING DATVR_PO VSTAT
                                     WHERE EBELN EQ T_PUR-EBELN.
  ENDSELECT.

*--> RFQ maintained date
  IF NOT T_PUR-ANFNR IS INITIAL.
    SELECT CHANGENR INTO T_PUR-CHANGENR_RFQ
           FROM CDPOS
           WHERE OBJECTCLAS EQ 'EINKBELEG' AND OBJECTID EQ T_PUR-ANFNR
             AND TABNAME EQ 'EKPO' AND TABKEY EQ V_TABKEY3
             AND FNAME EQ 'NETPR' AND CHNGIND EQ 'U'.
    MODIFY T_PUR TRANSPORTING CHANGENR_RFQ WHERE ANFNR EQ T_PUR-ANFNR.
    ENDSELECT.
    SELECT UDATE INTO T_PUR-UDATE_RFQ
           FROM CDHDR
           WHERE OBJECTCLAS EQ 'EINKBELEG' AND OBJECTID EQ T_PUR-ANFNR
             AND TCODE IN S_TCODE AND CHANGE_IND EQ 'U'
             AND CHANGENR EQ T_PUR-CHANGENR_RFQ.
    MODIFY T_PUR TRANSPORTING UDATE_RFQ WHERE ANFNR EQ T_PUR-ANFNR.
    ENDSELECT.
  ELSE.
    T_PUR-UDATE_RFQ = '00000000'.
  ENDIF.

*--> get RFQ creation date
  SELECT AEDAT INTO T_PUR-RFQ_AEDAT FROM EKPO
    WHERE EBELN EQ T_PUR-ANFNR.
  MODIFY T_PUR TRANSPORTING RFQ_AEDAT.
  ENDSELECT.

*--> PR Days = PR release date - PR creation date
  IF T_PUR-UDATE_PR IS INITIAL OR T_PUR-BADAT IS INITIAL.
    V_PRDAY = '0'.
  ELSE.
*    v_prday = t_pur-udate_pr - t_pur-badat.
*    v_prtemp = t_pur-udate_pr - t_pur-badat.               " DEVK951017
    PERFORM CALC_ACT_WORKDAY                                 "DEVK951017
           USING T_PUR-BADAT T_PUR-UDATE_PR V_PRTEMP.        "DEVK951017
    PERFORM CONVERT_NEG_TO_BRACKET USING V_PRTEMP
                                   CHANGING V_PRDAY.
  ENDIF.

*--> RFQ Days = RFQ quotation date - PR release date
* if t_pur-rfq_aedat is initial or t_pur-udate_pr is initial."DEVK951017
  IF T_PUR-UDATE_RFQ IS INITIAL OR T_PUR-UDATE_PR IS INITIAL."DEVK951017
   V_RFQDAY = '0'.
  ELSE.
*    v_rfqday = t_pur-rfq_aedat - t_pur-udate_pr.
*    v_rfqtemp = t_pur-rfq_aedat - t_pur-udate_pr.           "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-UDATE_PR T_PUR-UDATE_RFQ V_RFQTEMP.      "DEVK951017
PERFORM CONVERT_NEG_TO_BRACKET USING V_RFQTEMP
                                   CHANGING V_RFQDAY.
  ENDIF.

*--> PO days
*--> RFQ number not exist (PO Days = PO printed date - PR released date)
  IF T_PUR-ANFNR IS INITIAL.
*    if t_pur-datvr_po is initial or t_pur-udate_pr is initial.
*      v_poday = '0'.u
*    else.
      IF T_PUR-VSTAT = 1.
        IF T_PUR-DATVR_PO IS INITIAL OR T_PUR-UDATE_PR IS INITIAL.
          V_PODAY = '0'.
        ELSE.
*          v_poday = t_pur-datvr_po - t_pur-udate_pr.
*         v_potemp = t_pur-datvr_po - t_pur-udate_pr.        "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-UDATE_PR T_PUR-DATVR_PO V_POTEMP.        "DEVK951017
          PERFORM CONVERT_NEG_TO_BRACKET USING V_POTEMP
                                         CHANGING V_PODAY.
        ENDIF.
      ELSEIF T_PUR-VSTAT = 2 OR T_PUR-VSTAT = 0.
        IF T_PUR-AEDAT IS INITIAL OR T_PUR-UDATE_PR IS INITIAL.
          V_PODAY = '0'.
        ELSE.
*          v_poday = t_pur-aedat - t_pur-udate_pr.
*          v_potemp = t_pur-aedat - t_pur-udate_pr.          "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-UDATE_PR T_PUR-AEDAT V_POTEMP.           "DEVK951017
          PERFORM CONVERT_NEG_TO_BRACKET USING V_POTEMP
                                         CHANGING V_PODAY.
        ENDIF.
      ELSEIF T_PUR-VSTAT IS INITIAL.
        V_PODAY = '0'.
      ENDIF.
*    endif.
  ELSE.
*--> RFQ number exist (PO Days = PO printed date - Quotation date)
*    if t_pur-datvr_po is initial or t_pur-rfq_aedat is initial.
*      v_poday = '0'.
*    else.
    IF T_PUR-VSTAT = 1.
      IF T_PUR-DATVR_PO IS INITIAL OR T_PUR-RFQ_AEDAT IS INITIAL.
        V_PODAY = '0'.
      ELSE.
*        v_poday = t_pur-datvr_po - t_pur-rfq_aedat.
*       v_potemp = t_pur-datvr_po - t_pur-rfq_aedat.         "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-RFQ_AEDAT T_PUR-DATVR_PO V_POTEMP.       "DEVK951017
        PERFORM CONVERT_NEG_TO_BRACKET USING V_POTEMP
                                       CHANGING V_PODAY.
      ENDIF.
    ELSEIF T_PUR-VSTAT = 2 OR T_PUR-VSTAT = 0.
      IF T_PUR-AEDAT IS INITIAL OR T_PUR-RFQ_AEDAT IS INITIAL.
        V_PODAY = '0'.
      ELSE.
*        v_poday = t_pur-aedat - t_pur-rfq_aedat.
*        v_potemp = t_pur-aedat - t_pur-rfq_aedat.           "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-RFQ_AEDAT T_PUR-AEDAT V_POTEMP.          "DEVK951017
        PERFORM CONVERT_NEG_TO_BRACKET USING V_POTEMP
                                       CHANGING V_PODAY.
      ENDIF.
    ELSEIF T_PUR-VSTAT IS INITIAL.
      V_PODAY = '0'.
    ENDIF.
  ENDIF.
  CLEAR: V_TABKEY,
         V_TABKEY2,
         V_TABKEY3.
ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM WRITE_HEADER
*&---------------------------------------------------------------------*
FORM WRITE_HEADER.
  ULINE (255).
  FORMAT COLOR COL_HEADING INTENSIFIED ON.
  WRITE:/    '|', 9   'PR',
         21  '|', 48  'Material',
         83  '|', 92  'PO',
         103 '|', 107 'Purchase Requisition',
         131 '|', 143 'RFQ',
         159 '|', 176 'Purchase Order',
         209 '|', 210 'S',
         211 '|', 217 'GRN',
         228 '|', 229 'Standard',
         237 '|', 238 'Actual',
         244 '|', 255 '|'.
  ULINE (228).
  FORMAT COLOR OFF.
  WRITE: 237 '|', 244 '|', 255 '|'.
  FORMAT COLOR COL_HEADING INTENSIFIED ON.
  WRITE:/    '|', 2   'Number',
         12  '|', 13  'Item No.',
         21  '|', 22  'Number',
         41  '|', 42  'Description',
         83  '|', 84  'Number',
         94  '|', 95  'Item No.',
         103 '|', 104 'Created',
         114 '|', 115 'Released',
         125 '|', 126 'Days',
         131 '|', 132 'Created',
         142 '|', 143 'Maintained',
         153 '|', 154 'Days',
         159 '|', 160 'Created',
         170 '|', 171 'Required',
         181 '|', 182 'Approved',
         192 '|', 193 'Printed',
         203 '|', 204 'Days',
         209 '|',
         211 '|', 212 'Delivered',
         222 '|', 223 'Days',
         228 '|', 229 'Days',
         237 '|', 238 'Days',
         244 '|', 245 'Variance',
         255 '|'.
  FORMAT COLOR OFF.
  ULINE (255).
ENDFORM.                    " WRITE_HEADER

*&---------------------------------------------------------------------*
*&      Form  INVERT_LINE_ITEMS_COLOR
*&---------------------------------------------------------------------*
FORM INVERT_LINE_ITEMS_COLOR.
  V_COUNT_MOD = V_COUNT MOD 2.
  IF V_COUNT_MOD EQ '0'.
    FORMAT COLOR COL_KEY INTENSIFIED OFF.
  ELSE.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
  ENDIF.
ENDFORM.                    " INVERT_LINE_ITEMS_COLOR

*&---------------------------------------------------------------------*
*&      Form  GET_TITLE_DATE
*&---------------------------------------------------------------------*
FORM GET_TITLE_DATE.
  IF NOT S_BADAT-LOW IS INITIAL AND NOT S_BADAT-HIGH IS INITIAL.
    V_SDATE = S_BADAT-LOW.
    V_EDATE = S_BADAT-HIGH.
  ELSE.
    SORT T_PR BY BADAT ASCENDING.
    READ TABLE T_PR INDEX 1.
    V_SDATE = T_PR-BADAT.
    SORT T_PR BY BADAT DESCENDING.
    READ TABLE T_PR INDEX 1.
    V_EDATE = T_PR-BADAT.
  ENDIF.
ENDFORM.                    " GET_TITLE_DATE

*&---------------------------------------------------------------------*
*&      Form  GET_LATEST_GRNDATE
*&---------------------------------------------------------------------*
FORM GET_LATEST_GRNDATE.
DATA: D_LINES TYPE I.

  CLEAR T_DATE.
  DESCRIBE TABLE T_DATE LINES D_LINES.
  IF D_LINES GT 0.
    SORT T_DATE BY CPUDT EBELN EBELP DESCENDING.
    READ TABLE T_DATE WITH KEY EBELN = T_PUR-EBELN.
    IF SY-SUBRC = 0.
      READ TABLE T_DATE INDEX 1.
      MOVE: T_DATE-CPUDT TO T_PUR-CPUDT.
      MODIFY T_PUR TRANSPORTING CPUDT
             WHERE EBELN = T_PUR-EBELN AND EBELP = T_PUR-EBELP.
    ENDIF.
  ENDIF.

*--> GRN Days = GRN date - PO printed date
  IF T_PUR-VSTAT = 1.
    IF T_PUR-CPUDT IS INITIAL OR T_PUR-DATVR_PO IS INITIAL.
      V_GRNDAY = '0'.
    ELSE.
*    v_grnday = t_pur-cpudt - t_pur-datvr_po.
*    v_grntemp = t_pur-cpudt - t_pur-datvr_po.               "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-DATVR_PO T_PUR-CPUDT V_GRNTEMP.          "DEVK951017
      PERFORM CONVERT_NEG_TO_BRACKET USING V_GRNTEMP
                                     CHANGING V_GRNDAY.
    ENDIF.
  ELSEIF T_PUR-VSTAT = 2 OR T_PUR-VSTAT = 0.
    IF T_PUR-CPUDT IS INITIAL OR T_PUR-AEDAT IS INITIAL.
      V_GRNDAY = '0'.
    ELSE.
*    v_grnday = t_pur-cpudt - t_pur-datvr_po.
*     v_grntemp = t_pur-cpudt - v_grntemp.                   "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-AEDAT T_PUR-CPUDT V_GRNTEMP.             "DEVK951017
      PERFORM CONVERT_NEG_TO_BRACKET USING V_GRNTEMP
                                     CHANGING V_GRNDAY.
    ENDIF.
  ENDIF.
ENDFORM.                    " GET_LATEST_GRNDATE

*&---------------------------------------------------------------------*
*&      Form  GET_HEADER_ITEM
*&---------------------------------------------------------------------*
FORM GET_HEADER_ITEM.
DATA: V_OBJNR   LIKE PRPS-OBJNR,
      V_TEMP(4) TYPE C.

  clear t_pr.
  loop at t_pr.
    SELECT EBELN EBELP FROM EKET
           INTO (EKET-EBELN, EKET-EBELP)
           WHERE BANFN EQ T_PR-BANFN AND BNFPO EQ T_PR-BNFPO.
      SELECT EBELN FRGZU FROM EKKO
             INTO (EKKO-EBELN, EKKO-FRGZU)
             WHERE EBELN EQ EKET-EBELN.
        SELECT EBELP ANFNR ANFPS AEDAT FROM EKPO
               INTO (EKPO-EBELP, EKPO-ANFNR, EKPO-ANFPS, EKPO-AEDAT)
               WHERE EBELN EQ EKET-EBELN AND EBELP EQ EKET-EBELP
               AND BSTYP EQ 'F'.
          MOVE-CORRESPONDING T_PR TO T_PUR.
          MOVE: EKET-EBELN TO T_PUR-EKET_EBELN,
                EKET-EBELP TO T_PUR-EKET_EBELP,
                EKKO-EBELN TO T_PUR-EKKO_EBELN,
                EKKO-FRGZU TO T_PUR-EKKO_FRGZU,
                EKPO-EBELP TO T_PUR-EKPO_EBELP,
                EKPO-ANFNR TO T_PUR-ANFNR,
                EKPO-ANFPS TO T_PUR-ANFPS,
                EKPO-AEDAT TO T_PUR-AEDAT.
          V_FLAG2 = 'Y'.
          APPEND T_PUR.
        ENDSELECT.
      ENDSELECT.
    ENDSELECT.

  IF V_FLAG2 NE 'Y'.
    MOVE-CORRESPONDING T_PR TO T_PUR.
    APPEND T_PUR.
  ENDIF.

*--> get project code name
  CONCATENATE 'PR' T_PR-PS_PSP_PNR INTO V_OBJNR.
  SELECT SINGLE POSID INTO T_PR-POSID FROM PRPS WHERE OBJNR EQ V_OBJNR.
  SPLIT T_PR-POSID AT '/' INTO T_PUR-POSID V_TEMP.
  MODIFY T_PUR TRANSPORTING POSID WHERE PS_PSP_PNR EQ T_PR-PS_PSP_PNR.

CLEAR V_FLAG2.
  ENDLOOP.
ENDFORM.                    " GET_HEADER_ITEM

*&---------------------------------------------------------------------*
*&      Form  WRITE_DETAILS
*&---------------------------------------------------------------------*
FORM WRITE_DETAILS.
  WRITE:/   '|', 2   T_PUR-BANFN,                "PR no
         12 '|', 13  T_PUR-BNFPO,                "item no
         41 '|', 42  T_PUR-TXZ01,                "mat description
        103 '|', 104 T_PUR-BADAT,                "PR creation date
        125 '|', 126 V_PRDAY LEFT-JUSTIFIED,     "PR days
        131 '|',
        153 '|', 154 V_RFQDAY LEFT-JUSTIFIED,    "RFQ days
        203 '|', 204 V_PODAY LEFT-JUSTIFIED,     "PO days
        209 '|', 210 T_PUR-VSTAT,
        222 '|', 223 V_GRNDAY LEFT-JUSTIFIED,    "GRN days
        228 '|', 229 V_STADAY LEFT-JUSTIFIED,    "Standard days
        237 '|', 238 V_ACTDAY LEFT-JUSTIFIED,    "Actual days
        244 '|', 245 V_VARDAY LEFT-JUSTIFIED,    "Variance days
        255 '|'.

  IF T_PUR-MATNR IS INITIAL.
    WRITE: 21 '|', 22 '-'.
  ELSE.
    WRITE: 21 '|', 22  T_PUR-MATNR.              "mat no
  ENDIF.
  IF T_PUR-EKKO_EBELN IS INITIAL.
    WRITE: 83 '|', 84 '-'.
  ELSE.
    WRITE: 83 '|', 84  T_PUR-EKKO_EBELN.         "PO number
  ENDIF.
  IF T_PUR-EKPO_EBELP EQ '00000' OR T_PUR-EKPO_EBELP IS INITIAL.
    WRITE: 94 '|', 95 '-'.
  ELSE.
    WRITE: 94 '|', 95  T_PUR-EKPO_EBELP.         "PO item no
  ENDIF.
  IF T_PUR-UDATE_PR EQ '00000000'.
    WRITE:  114 '|', 115 '-'.
  ELSE.
    WRITE: 114 '|', 115 T_PUR-UDATE_PR.          "PR released date
  ENDIF.
  IF T_PUR-RFQ_AEDAT EQ '00000000'.
    WRITE: 132 '-', 142 '|'.
  ELSE.
    WRITE: 132 T_PUR-RFQ_AEDAT, 142 '|'.  "RFQ creation date
  ENDIF.
  IF T_PUR-UDATE_RFQ EQ '00000000'.
    WRITE: 143 '-'.
  ELSE.
    WRITE: 143 T_PUR-UDATE_RFQ.           "RFQ maintained date
  ENDIF.
  IF T_PUR-AEDAT EQ '00000000'.
    WRITE: 159 '|', 160 '-'.
  ELSE.
    WRITE: 159 '|', 160 T_PUR-AEDAT.      "PO creation date
  ENDIF.
  IF T_PUR-EINDT EQ '00000000'.
    WRITE: 170 '|', 171 '-'.
  ELSE.
    WRITE: 170 '|', 171 T_PUR-EINDT.       "PO required date
  ENDIF.
  IF T_PUR-UDATE_PO EQ '00000000'.
    WRITE: 181 '|', 182 '-'.
  ELSE.
    WRITE: 181 '|', 182 T_PUR-UDATE_PO.    "PO released date
  ENDIF.

  IF T_PUR-VSTAT = 1.
*    if t_pur-datvr_po eq '00000000'.
*      write: 192 '|', 193 '-'.
*    else.
      WRITE: 192 '|', 193 T_PUR-DATVR_PO.    "PO printed date
*    endif.
*  elseif t_pur-vstat = 2 or t_pur-vstat = 0.                "DEVK951017
   ELSEIF T_PUR-VSTAT = 2.                                   "DEVK951017
    WRITE: 192 '|', 193 T_PUR-AEDAT.         "PO creation date
   ELSEIF T_PUR-VSTAT = 0.                                   "DEVK951017
    WRITE: 192 '|', 193 '-'.     "PO printed date not shown  "DEVK951017
  ENDIF.

  IF T_PUR-CPUDT EQ '00000000'.
    WRITE: 211 '|', 212 '-'.
  ELSE.
    WRITE: 211 '|', 212 T_PUR-CPUDT.        "GRN delivered date
  ENDIF.
ENDFORM.                    " WRITE_DETAILS

*&---------------------------------------------------------------------*
*&      Form  CHECK_TZEPURDAY
*&---------------------------------------------------------------------*
FORM CHECK_TZEPURDAY.
*  CLEAR T_PRDAY.
*  READ TABLE T_PRDAY INDEX 1.
*  IF SY-SUBRC NE 0.
*    FORMAT COLOR COL_NEGATIVE ON.
*    WRITE:/ '*** No Table Entries Found in Table ZEPURDAY ***'.
*    FORMAT COLOR OFF.
*  ENDIF.
ENDFORM.                    " CHECK_TZEPURDAY

*&---------------------------------------------------------------------*
*&      Form  GET_STAND_DAY
*&---------------------------------------------------------------------*
FORM GET_STAND_DAY.

*--> PR release days
*  CLEAR T_PRDAY.
*  READ TABLE T_PRDAY WITH KEY PR_TYPE = T_PUR-BSART.
*  IF SY-SUBRC EQ 0.
*    CLEAR V_LEN.
*    CONDENSE T_PUR-FRGZU.
*    V_LEN = STRLEN( T_PUR-FRGZU ).
*    IF V_LEN EQ 0.
*      V_RELPR = 0.
*    ELSEIF V_LEN EQ '1'.
*      V_RELPR = T_PRDAY-PR_RE1.
*    ELSEIF V_LEN EQ '2'.
*      V_RELPR = T_PRDAY-PR_RE1 + T_PRDAY-PR_RE2.
*    ELSEIF V_LEN EQ '3'.
*      V_RELPR = T_PRDAY-PR_RE1 + T_PRDAY-PR_RE2 + T_PRDAY-PR_RE3.
*    ELSE.
*      V_RELPR = T_PRDAY-PR_RE1 + T_PRDAY-PR_RE2 +
*                T_PRDAY-PR_RE3 + T_PRDAY-PR_RE4.
*    ENDIF.

*--> PO release days
*    CLEAR V_LEN2.
*    CONDENSE T_PUR-EKKO_FRGZU.
*    V_LEN2 = STRLEN( T_PUR-EKKO_FRGZU ).
*    IF V_LEN2 EQ 0.
*      V_RELPO = 0.
*    ELSEIF V_LEN2 EQ '1'.
*      V_RELPO = T_PRDAY-PO_RE1.
*    ELSEIF V_LEN2 EQ '2'.
*      V_RELPO = T_PRDAY-PO_RE1 + T_PRDAY-PO_RE2.
*    ELSEIF V_LEN2 EQ '3'.
*      V_RELPO = T_PRDAY-PO_RE1 + T_PRDAY-PO_RE2 + T_PRDAY-PO_RE3.
*    ELSE.
*      V_RELPO = T_PRDAY-PO_RE1 + T_PRDAY-PO_RE2 +
*                T_PRDAY-PO_RE3 + T_PRDAY-PO_RE4.
*    ENDIF.
CHECK = ' '.                                                 "DEVK951017
IF NOT ( T_PUR-EKKO_EBELN IS INITIAL ) AND                   "DEVK951017
   T_PUR-ANFNR IS INITIAL AND T_PUR-KNTTP = 'P'.
   PERFORM CHECK_RFQ.                                        "DEVK951017
**   IF CHECK = 'X'.
**      V_STADAY = T_PRDAY-PR_CRT + V_RELPR + T_PRDAY-PO_CRT +
*"DEVK951017
**      V_RELPO + T_PRDAY-PO_PRN + T_PRDAY-GRN_CRT.
**   ENDIF.
*ELSE.
**--> Standard Days
*    V_STADAY = T_PRDAY-PR_CRT + V_RELPR + T_PRDAY-RFQ_CRT +
*               T_PRDAY-RFQ_MAN + T_PRDAY-PO_CRT +
*               V_RELPO + T_PRDAY-PO_PRN + T_PRDAY-GRN_CRT.
**              + t_prday-pay_crt + t_prday-inv_crt.
"DEVK951017
*
*ENDIF.
  ENDIF.                                                     "DEVK951017
ENDFORM.                    " GET_STAND_DAY

*&---------------------------------------------------------------------*
*&      Form  GET_ACT_DAY
*&---------------------------------------------------------------------*
FORM GET_ACT_DAY.
DATA: V_CPUDT LIKE SY-DATUM.
*  IF T_PUR-CPUDT IS INITIAL OR T_PUR-BADAT IS INITIAL.
*    V_ACTDAY = '0'.
*  ELSE.
*    V_ACTDAY = T_PUR-CPUDT - T_PUR-BADAT.
*  ENDIF.
  V_CPUDT = SY-DATUM.
  IF T_PUR-CPUDT IS INITIAL.
*   v_actday = v_cpudt - t_pur-badat.                        "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-BADAT V_CPUDT V_ACTDAY.
  ELSEIF T_PUR-BADAT IS INITIAL.
    V_ACTDAY = '0'.
  ELSE.
*   v_actday = t_pur-cpudt - t_pur-badat.                    "DEVK951017
PERFORM CALC_ACT_WORKDAY                                     "DEVK951017
        USING T_PUR-BADAT T_PUR-CPUDT V_ACTDAY.
  ENDIF.
ENDFORM.                    " GET_ACT_DAY

*&---------------------------------------------------------------------*
*&      Form  GET_VAR_DAY
*&---------------------------------------------------------------------*
FORM GET_VAR_DAY.
DATA: V_TEMP2(8).

  V_TEMP2 = V_STADAY - V_ACTDAY.
  PERFORM CONVERT_NEG_TO_BRACKET USING V_TEMP2
                                 CHANGING V_VARDAY.

ENDFORM.                    " GET_VAR_DAY

*&---------------------------------------------------------------------*
*&      Form  CONVERT_NEG_TO_BRACKET
*&---------------------------------------------------------------------*
FORM CONVERT_NEG_TO_BRACKET USING    P_V_TEMP
                            CHANGING P_V_DAY.

  SEARCH P_V_TEMP FOR '-'.
  IF SY-SUBRC = 0.
    SHIFT P_V_TEMP RIGHT BY 1 PLACES.
    SHIFT P_V_TEMP LEFT DELETING LEADING SPACE.
    CONCATENATE '(' P_V_TEMP ')' INTO P_V_DAY.
  ELSE.
    SHIFT P_V_TEMP LEFT DELETING LEADING SPACE.
    MOVE P_V_TEMP TO P_V_DAY.
  ENDIF.

ENDFORM.                    " CONVERT_NEG_TO_BRACKET

*&---------------------------------------------------------------------*
*&      Form  CALC_ACT_WORKDAY                            -DEVK951017
*&---------------------------------------------------------------------*
*      -->lowdt  -Low Date                                             *
*      -->Highdt -High Date                                            *
*      -->days   -Total Days                                           *
*----------------------------------------------------------------------*
FORM CALC_ACT_WORKDAY USING LOWDT HIGHDT DAYS.
  DATA: DAT LIKE SY-DATUM.
  DAYS = 0.
  DAT = LOWDT.

  DO.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
     EXPORTING
          DATE                       = DAT
          FACTORY_CALENDAR_ID        = 'MY'
          MESSAGE_TYPE               = 'I'
     EXCEPTIONS
          DATE_AFTER_RANGE           = 1
          DATE_BEFORE_RANGE          = 2
          DATE_INVALID               = 3
          DATE_NO_WORKINGDAY         = 4
          FACTORY_CALENDAR_NOT_FOUND = 5
          MESSAGE_TYPE_INVALID       = 6
          OTHERS                     = 7.
    IF SY-SUBRC = 0.
      DAYS = DAYS + 1.
    ENDIF.

    DAT = DAT + 1.
    IF DAT GE HIGHDT.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.                    " CALC_ACT_WORKDAY
*&---------------------------------------------------------------------*
*&      Form  CHECK_RFQ
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CHECK_RFQ.
DATA: KONNR LIKE EKPO-KONNR,
      AEDAT LIKE EKKO-AEDAT.

SELECT SINGLE P~KONNR K~AEDAT INTO (KONNR, AEDAT)
FROM EKPO AS P INNER JOIN EKKO AS K
ON P~EBELN = K~EBELN WHERE P~EBELN = T_PUR-EKKO_EBELN
AND P~EBELP = T_PUR-EKPO_EBELP AND K~BSTYP = 'K'
AND P~KONNR = K~KONNR.

IF SY-SUBRC = 0.
IF AEDAT < T_PUR-BADAT.
  CHECK = 'X'.
ENDIF.
ENDIF.

ENDFORM.                    " CHECK_RFQ

Again, like the previous thread, i asked if there is a right way to approach an assignment where i am assigned to modify another person's program. Should i be doing something first before i go straight on and start making ammendments?

Regards,

Bernard

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Nov 30, 2005 at 03:29 AM

    My answer given to your previous one is still valid. Here it is one more time.

    Even though you think AT NEW will work on just the field that you mentioned, it is not. Your field BSART is about 6th or 7th field in your internal table. So any change in any of the field values before BSART will trigger this AT NEW BSART code.

    You have to declare your own variables to keep track of the current value of BSART and previous value of the same. Also, remember that it may not have been sorted by BSART. So your logic may not work and if you change the sort, then your previous AT NEW may not work. So be sure of what you want to do there.

    Srinivas

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Srinivas Adavi

      It's ok, i finally found out what was wrong. It seems that i inserted the AT END OF BSART...ENDAT statement before the WRITE_DETAILS, that is why the WRITE V_AVGDAY appeared just before the last line of the PR Doc Type...silly mistake of mine.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.