cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos
183

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Srinivas,

You were right about BSART being the 6th or 7th line in my internal table. I didn't look at the original coding properly as i should have, couldn't believe i missed that.

Thank you so much.

I won't close this thread yet, i still might have some problems with the ammendments i made to the original program. I'll post it here is there are any that i can't solve.

Thank you again

Former Member
0 Kudos

I have managed to almost complete most of what is required in the specification document but i only have 1 thing remaining which i am unable to figure out how to do.

Assuming that there is 100 lines of output. 40 of the lines belong to 1 PR Doc Type, 30 of them belong to another and the remaining also belongs to another.

My question is, i want to COUNT/DESCRIBE the lines belonging to their own particular PR Doc Type. I've been playing around with DESCRIBE but i always end up counting all 100 lines instead of counting the lines belonging to their particular PR Doc Type (meaning that when i use the AT END OF... statement, instead of giving me value of 40 for the first group of lines, i get 100).

Any hints on how to solve it?

Former Member
0 Kudos

Hi,

I think you can do this by using the ON CHANGE OF PR no.

ON CHNGE OF ...

ENDON.

With this you can use DESCRIBE TABLE.....

Thanks.

If this helps you make sure to award points.

andreas_mann3
Active Contributor
0 Kudos

Hi,

you've to clear your counter after

AT END OF and ouput the result

a better way is to handle this with a pivot-table

and the collect command

Andreas

Former Member
0 Kudos

thanks, but i managed to do it finally in a different way.


<b>    AT NEW BANFN.
      ADD 1 TO COUNT_LINES.
    ENDAT.</b>

*--> DISPLAY PR DOC TYPE
  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.
<b>      CLEAR COUNT_LINES.
      ADD 1 TO COUNT_LINES.</b>
      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'.
    SKIP 1.
    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.

Right now i'm trying to figure out how to write the final COUNT_LINES value after all the lines belonging to that particular PR Doc Type has been written.

I tried using AT END OF BSART, but instead of writing after/below the last line, it appear between the second last and last line. Any comments on this?

Former Member
0 Kudos

Hi,

I hope this is what you are trying...

WRITE:/2 'PR Doc Type Desc: 'T_PUR-BSART COLOR COL_GROUP,

************************

22(3) T_PUR-BSART COLOR COL_GROUP.

***************************

WRITE: 26 T_PUR-BATXT NO-GAP COLOR COL_GROUP.

PERFORM WRITE_HEADER.

Thanks.

If it is not plzz revert to forum or else award points if it satisfies you.

Former Member
0 Kudos

Actually i'm not trying to do that.

I'll explain what i'm trying to do actually.

I've managed to do a count of the lines of output belonging to their corresponding PR Doc Type. So let's assume there's 40 lines to PR Doc Type 'A', so it would mean COUNT_LINES would have a value of 40.

Then i did a SUM of all the values in field V_ACTDAY, so total is 2000. So, SUM_ACTDAY would have a total value of 2000

Since i want to find out the average days, i did a COMPUTE V_AVGDAY = SUM_ACTDAY / COUNT_LINES, therefore 2000 / 40 = 50

So what i actually meant to ask was how do i write the result of V_AVGDAY (50) in the next line after the 40 lines have been written using the END OF ... statement.

I'm asking this because when i wrote:


  AT END OF BSART.
    COMPUTE V_AVGDAY = SUM_ACTDAY / COUNT_LINES.
    NEW-LINE.
    WRITE: V_AVGDAY UNDER V_ACTDAY.
  ENDAT.

For some reason, V_AVGDAY appeared in the 40th line and in doing so, it pushed the original line 40 to the 41st line. I can't figure out what is wrong and i want to know why it happened.

Former Member
0 Kudos

Hi,

I think it is because of this...

WRITE: V_AVGDAY UNDER V_ACTDAY.

you have to insert.

write:/ v_avgday under v_actday.

/ it goes to new line.

if not it will print in same line.

***************

Try this...

ON CHANGE OF....

write:/ v_avgay under v_actday.

ENDON.

***************

See this it is working for me ...

********

at end of racct+4(3).

sum.

uline.

format color col_group intensified on.

write:/ a, (5) it_out-bukrs,

a, it_out-racct+5(2) no-gap, 14 text-t27,

45 a, 47(15) it_out-usd currency 'USD' no-gap,

a, (15) it_out-eur currency 'EUR' no-gap,

a, (15) it_out-gbp currency 'GBP' no-gap,

a, (15) it_out-jpy currency 'JPY' no-gap,

a, (15) it_out-cad currency 'CAD' no-gap,

a, (15) it_out-sgd currency 'SGD' no-gap,

a, (15) it_out-ntd currency 'NTD' no-gap,

a, (15) it_out-ils currency 'ILS' no-gap,

a, (15) it_out-sek currency 'SEK' no-gap,

a, (15) it_out-dkk currency 'DKK' no-gap,

a, (15) it_out-dem currency 'DEM' no-gap,

a, (15) it_out-kor currency 'KOR' no-gap,

a, (15) it_out-aed currency 'AED' no-gap,

a.

format color off.

uline.

endat.

at end of bukrs.

sum.

  • uline.

format color col_group intensified on.

write 😕 a, text-t20 no-gap,

19 it_out-bukrs no-gap,

45 a, 47(15) it_out-usd currency 'USD' no-gap,

a, (15) it_out-eur currency 'EUR' no-gap,

a, (15) it_out-gbp currency 'GBP' no-gap,

a, (15) it_out-jpy currency 'JPY' no-gap,

a, (15) it_out-cad currency 'CAD' no-gap,

a, (15) it_out-sgd currency 'SGD' no-gap,

a, (15) it_out-ntd currency 'NTD' no-gap,

a, (15) it_out-ils currency 'ILS' no-gap,

a, (15) it_out-sek currency 'SEK' no-gap,

a, (15) it_out-dkk currency 'DKK' no-gap,

a, (15) it_out-dem currency 'DEM' no-gap,

a, (15) it_out-kor currency 'KOR' no-gap,

a, (15) it_out-aed currency 'AED' no-gap,

a.

format color off.

uline.

endat.

*********************

Thanks.

If it helps make sure to award points.

Message was edited by: Deepak333 k

Message was edited by: Deepak333 k

Message was edited by: Deepak333 k

Former Member
0 Kudos

It didn't budge from it's original position. It's still at line 40

Former Member
0 Kudos

I tried the ON CHANGE OF... END ON statement, didn't work, in fact, the entire write statement disappeared. Could it caused by the sorting of the internal table?

Former Member
0 Kudos

Can you please post the new LOOP ... ENDLOOP portions of your code here?

Former Member
0 Kudos

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.