Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*&---------------------------------------------------------------------*
*& Report  ZINVOICDAFPROG
*  This program extracts invoice DAF data to create IDOCs and it also
* creates a flat file of statistics summary by business area.
* =====================================================================*
* PROGRAM TYPE.. Executable Program
* DEV. CLASS.... ZRM0
* LOGICAL DB.... N/A
* AUTHOR........ Aveek Ghose
* DATE WRITTEN.. 15/09/2006
* R/3 RELEASE... 4.6C
* =====================================================================*
* SCREENS....... N/A
* GUl TITLE..... N/A
* GUl STATUS.... N/A
* TRANSACTIONS.. N/A
* USER EXITS.... N/A
* =====================================================================*
* CHANGE HISTORY                                                       *
* Date       By        Correction Number & Brief Description  Release  *
*----------------------------------------------------------------------
************************************************************************
REPORT ZRMIIN01.

*----------------------------------------------------------------------*
* Tables / Structures
*----------------------------------------------------------------------*

TABLES: EDI_DC40,   " IDoc control record
        EDI_DD40,   " IDoc detail records
        EDIDD,      " Data record (IDoc)
        EDIDC,      " Control record (IDoc)
        KNA1,
        KNVV,
        KONV,
        VBRK,
        VBRP,
        VBAK,
        VBAP,
        VBPA,
        T001W,
        T001,
        LIKP,
        LIPS,
        VBKD,
        VBFA.

DATA:   " Table of IDoc data records
        T_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE,
        " Table of IDoc control records
        T_EDIDC LIKE EDIDC OCCURS 0 WITH HEADER LINE.

* ZRMDAF01 IDOC type - Segment data variables
DATA:   G_WA_Z1DAFA1   LIKE   Z1DAFA1,
        G_WA_Z1DAFA2   LIKE   Z1DAFA2,
        G_WA_Z1DAFO1   LIKE   Z1DAF01,
        G_WA_Z1DAFO2   LIKE   Z1DAF02,
        G_WA_Z1DAFD1   LIKE   Z1DAFD1,
        G_WA_Z1DAF11   LIKE   Z1DAF11,
        G_WA_Z1DAF12   LIKE   Z1DAF12,
        G_WA_Z1DAFZ1   LIKE   Z1DAFZ1,
        G_WA_Z1DAFPC   LIKE   Z1DAFPC,
        G_WA_Z1DAFTX   LIKE   Z1DAFPC."Holds Sum of Taxes
* ZRMDAF01 IDOC type - Pricing Conditions Segment data
DATA:   LT_Z1DAFPC LIKE Z1DAFPC OCCURS 16 WITH HEADER LINE.
*
** Pricing Conditions for Header Charge Record.
DATA:   LT_HDRPC   LIKE Z1DAFPC OCCURS 16 WITH HEADER LINE.

* Header Charg record fields
TYPES: BEGIN OF TY_HEADER,
          HEADF      LIKE   Z1DAFA1-HEADF,
          MATNR      LIKE   Z1DAF02-MATNR,
          NETPR      LIKE   Z1DAF02-NETPR,
          NETWR      LIKE   Z1DAF02-NETWR,
          BUS_AREA   LIKE   Z1DAF02-BUS_AREA,
          INVNUM     LIKE   Z1DAF11-INVNUM,
          INVDAT     LIKE   Z1DAF11-INVDAT,
       END OF TY_HEADER.

* Invoice Header - VBRK
TYPES: BEGIN OF TY_VBRK,
          VBELN      LIKE   VBRK-VBELN,
          ERDAT      LIKE   VBRK-ERDAT,
          ERZET      LIKE   VBRK-ERZET,
          SFAKN      LIKE   VBRK-SFAKN,
          VBTYP      LIKE   VBRK-VBTYP,
          FKTYP      LIKE   VBRK-FKTYP,
          VKORG      LIKE   VBRK-VKORG,
          VTWEG      LIKE   VBRK-VTWEG,
          FKDAT      LIKE   VBRK-FKDAT,
          FKART      LIKE   VBRK-FKART,
          knumv      like   vbrk-knumv,                     "PPR0341+
          ZTERM      like   vbrk-zterm,
       END OF TY_VBRK.

* Invoice Detail - VBRP
TYPES: BEGIN OF TY_VBRP,
       VBELN         LIKE   VBRP-VBELN,
       POSNR         LIKE   VBRP-POSNR,
       FKLMG         LIKE   VBRP-FKLMG,
       AUBEL         LIKE   VBRP-AUBEL,
       AUPOS         LIKE   VBRP-AUPOS,
       VGPOS         LIKE   VBRP-VGPOS,
       VGBEL         LIKE   VBRP-VGBEL,
       MATNR         LIKE   VBRP-MATNR,
       VRKME         LIKE   VBRP-VRKME,
       MEINS         LIKE   VBRP-MEINS,
       kzwi2         like   vbrp-kzwi2,                     "PPR0341+
       END OF TY_VBRP.

* VBAK TYPE
TYPES: BEGIN OF TY_VBAK,
          VBELN      LIKE   VBAK-VBELN,
          VBTYP      LIKE   VBAK-VBTYP,
          BUKRS_VF   LIKE   VBAK-BUKRS_VF,
          KUNNR      LIKE   VBAK-KUNNR,
          AUGRU      LIKE   VBAK-AUGRU,
          AUART      LIKE   VBAK-AUART,
          ERDAT      LIKE   VBAK-ERDAT,
          BSARK      LIKE   VBAK-BSARK,
          ZZDEA_NUM(10) TYPE C,
          ZZFORM_222(9) TYPE C,
          ZZEXPIRY(8) TYPE C,
          AUFNR      LIKE   VBAK-AUFNR,
          KVGR2      LIKE   VBAK-KVGR2,
          VKORG      LIKE   VBAK-VKORG,
          VTWEG      LIKE   VBAK-VTWEG,
          LIFSK      LIKE   VBAK-LIFSK,
          KNUMV      LIKE   VBAK-KNUMV,
          VDATU      LIKE   VBAK-VDATU,
       END OF TY_VBAK.

* VBAP TYPE
TYPES: BEGIN OF TY_VBAP,
          VBELN      LIKE   VBAP-VBELN,
          POSNR      LIKE   VBAP-POSNR,
          WERKS      LIKE   VBAP-WERKS,
          MATNR      LIKE   VBAP-MATNR,
          MVGR1      LIKE   VBAP-MVGR1,
          ERDAT      LIKE   VBAP-ERDAT,
          KZTLF      LIKE   VBAP-KZTLF,
          KWMENG     LIKE   VBAP-KWMENG,
          UMVKZ      LIKE   VBAP-UMVKZ,
          MEINS      LIKE   VBAP-MEINS,
          VRKME      LIKE   VBAP-VRKME,
          ZIEME      LIKE   VBAP-ZIEME,
          KZWI2      LIKE   VBAP-KZWI2,
          LPRIO      LIKE   VBAP-LPRIO,
          ROUTE      LIKE   VBAP-ROUTE,
          ZMENG      LIKE   VBAP-ZMENG,
          NETPR      LIKE   VBAP-NETPR,
       END OF TY_VBAP.
* LIKP TYPE
TYPES: BEGIN OF TY_LIKP,
          VBELN      LIKE   LIKP-VBELN,
          VBTYP      LIKE   LIKP-VBTYP,
          ERDAT      LIKE   LIKP-ERDAT,
          LPRIO      LIKE   LIKP-LPRIO,
       END OF TY_LIKP.
* LIPS TYPE
TYPES: BEGIN OF TY_LIPS,
          VBELN      LIKE   LIPS-VBELN,
          POSNR      LIKE   LIPS-POSNR,
          LFIMG      LIKE   LIPS-LFIMG,
          CHARG      LIKE   LIPS-CHARG,
          UECHA      LIKE   LIPS-UECHA,
          MATNR      LIKE   LIPS-MATNR,
          MEINS      LIKE   LIPS-MEINS,
          VRKME      LIKE   LIPS-VRKME,

       END OF TY_LIPS.
* ADRC TYPE
TYPES: BEGIN OF TY_ADRC,
          ADDRNUMBER LIKE   ADRC-ADDRNUMBER,
          NAME1      LIKE   ADRC-NAME1,
          NAME2      LIKE   ADRC-NAME2,
          NAME3      LIKE   ADRC-NAME3,
          NAME4      LIKE   ADRC-NAME4,
          STREET     LIKE   ADRC-STREET,
          CITY1      LIKE   ADRC-CITY1,
          REGION     LIKE   ADRC-REGION,
          POST_CODE1 LIKE   ADRC-POST_CODE1,
       END OF TY_ADRC.
* KNA1 TYPE
TYPES: BEGIN OF TY_KNA1,
          KUNNR      LIKE   KNA1-KUNNR,
          STCD1      LIKE   KNA1-STCD1,
          NAME1      LIKE   KNA1-NAME1,
          NAME2      LIKE   KNA1-NAME2,
          NAME3      LIKE   KNA1-NAME3,
          NAME4      LIKE   KNA1-NAME4,
          STRAS      LIKE   KNA1-STRAS,
          ORT01      LIKE   KNA1-ORT01,
          REGIO      LIKE   KNA1-REGIO,
          PSTLZ      LIKE   KNA1-PSTLZ,
          CITYC      LIKE   KNA1-CITYC,
          COUNC      LIKE   KNA1-COUNC,
          BRSCH      LIKE   KNA1-BRSCH,
       END OF TY_KNA1.
* MARA TYPE
TYPES: BEGIN OF TY_MARA,
          MATNR      LIKE   MARA-MATNR,
          MTART      LIKE   MARA-MTART,
       END OF TY_MARA.
* MVKE TYPE
TYPES: BEGIN OF TY_MVKE,
          MATNR      LIKE   MVKE-MATNR,
          VKORG      LIKE   MVKE-VKORG,
          VTWEG      LIKE   MVKE-VTWEG,
          VMSTA      LIKE   MVKE-VMSTA,
       END OF TY_MVKE.
* VBKD TYPE
TYPES: BEGIN OF TY_VBKD,
          VBELN      LIKE   VBKD-VBELN,
          BSTKD      LIKE   VBKD-BSTKD,
          PLTYP      LIKE   VBKD-PLTYP,
       END OF TY_VBKD.
* VBEP TYPE
TYPES: BEGIN OF TY_VBEP,
          VBELN      LIKE   VBEP-VBELN,
          POSNR      LIKE   VBEP-POSNR,
          MBDAT      LIKE   VBEP-MBDAT,
          LIFSP      LIKE   VBEP-LIFSP,
       END OF TY_VBEP.
* VBFA TYPE
TYPES: BEGIN OF TY_VBFA,
          VBELV      LIKE   VBFA-VBELV,
          POSNV      LIKE   VBFA-POSNV,
          VBELN      LIKE   VBFA-VBELN,
          POSNN      LIKE   VBFA-POSNN,
          VBTYP_N    LIKE   VBFA-VBTYP_N,
          RFMNG      LIKE   VBFA-RFMNG,
       END OF TY_VBFA.
* VBPA TYPE
TYPES: BEGIN OF TY_VBPA,
          VBELN      LIKE   VBPA-VBELN,
          POSNR      LIKE   VBPA-POSNR,
          ADRNR      LIKE   VBPA-ADRNR,
          PARVW      LIKE   VBPA-PARVW,
          KUNNR    LIKE     VBPA-KUNNR,
       END OF TY_VBPA.

* KONV - TPR0286 added additional fields
TYPES: BEGIN OF TY_KONV,
          KNUMV    TYPE  KONV-KNUMV,
          KPOSN    TYPE  KONV-KPOSN,
          STUNR    TYPE  KONV-STUNR, "new field for proper sorting
          ZAEHK    TYPE  KONV-ZAEHK, "new field
          KAPPL    TYPE  KONV-KAPPL, "new field
          KSCHL    TYPE  KONV-KSCHL,
          KNUMH    TYPE  KONV-KNUMH,
          KINAK    TYPE  KONV-KINAK,
          KOAID    TYPE  KONV-KOAID,
          KWERT    TYPE  KONV-KWERT,
          KGRPE    TYPE  KONV-KGRPE,
          KRECH    TYPE  KONV-KRECH,
       END OF TY_KONV.

* KONH
TYPES: BEGIN OF TY_KONH,
          KNUMH    TYPE  KONH-KNUMH,
          KOSRT    TYPE  KONH-KOSRT,
          KNUMA_AG TYPE  KONH-KNUMA_AG,
       END OF TY_KONH.

* KONV
TYPES: BEGIN OF TY_VBUP,
          VBELN    TYPE  VBUP-VBELN,
          POSNR    TYPE  VBUP-POSNR,
          LFSTA    TYPE  VBUP-LFSTA,
          GBSTA    TYPE  VBUP-GBSTA,
          ABSTA    TYPE  VBUP-ABSTA,
       END OF TY_VBUP.

* KONH
TYPES: BEGIN OF TY_VBUK,
          VBELN    TYPE  VBUK-VBELN,
          VBTYP    TYPE  VBUK-VBTYP,
          CMGST    TYPE  VBUK-CMGST,
       END OF TY_VBUK.

* INTERNAL TABLES FOR ALL THE DB TABLES USED IN THIS PROGRAM.
DATA:   LT_VBRK   TYPE TY_VBRK OCCURS 0 WITH HEADER LINE,
        LT_CANCEL TYPE TY_VBRK OCCURS 0 WITH HEADER LINE,
        LT_VBRP   TYPE TY_VBRP OCCURS 0 WITH HEADER LINE,
        LT_LIKP   TYPE TY_LIKP OCCURS 0 WITH HEADER LINE,
        LT_LIPS   TYPE TY_LIPS OCCURS 0 WITH HEADER LINE,
        LT_BSPLIT TYPE TY_LIPS OCCURS 0 WITH HEADER LINE,
        LT_VBAK   TYPE TY_VBAK OCCURS 0 WITH HEADER LINE,
        LT_VBAP   TYPE TY_VBAP OCCURS 0 WITH HEADER LINE,
        LT_VBFA   TYPE TY_VBFA OCCURS 0 WITH HEADER LINE,
        LT_KNA1   TYPE TY_KNA1 OCCURS 0 WITH HEADER LINE,
        LT_ADRC   TYPE TY_ADRC OCCURS 0 WITH HEADER LINE,
        LT_MARA   TYPE TY_MARA OCCURS 0 WITH HEADER LINE,
        LT_VBEP   TYPE TY_VBEP OCCURS 0 WITH HEADER LINE,
        LT_VBKD   TYPE TY_VBKD OCCURS 0 WITH HEADER LINE,
        LT_VBPA   TYPE TY_VBPA OCCURS 0 WITH HEADER LINE,
*       LT_ATP    LIKE ZATPXTR OCCURS 0 WITH HEADER LINE,
        LT_MVKE   TYPE TY_MVKE OCCURS 0 WITH HEADER LINE,
        LT_KONV   TYPE TY_KONV OCCURS 0 WITH HEADER LINE,
        LT_KONV_PR  TYPE TY_KONV OCCURS 0 WITH HEADER LINE, "tpr0373
        LT_KONV_ZR00 TYPE TY_KONV OCCURS 0 WITH HEADER LINE, "FCR0322
        LT_KONH   TYPE TY_KONH OCCURS 0 WITH HEADER LINE,
        LT_VBUK   TYPE TY_VBUK OCCURS 0 WITH HEADER LINE,
        LT_VBUP   TYPE TY_VBUP OCCURS 0 WITH HEADER LINE,
        LT_VBUK_TMP   TYPE TY_VBUK OCCURS 0 WITH HEADER LINE,
        LT_VBUP_TMP   TYPE TY_VBUP OCCURS 0 WITH HEADER LINE.

* Work Areas to read data from Internal tables.
DATA:   G_WA_VBRK       TYPE TY_VBRK,
        G_WA_CANCEL     TYPE TY_VBRK,
        G_WA_VBRP       TYPE TY_VBRP,
        G_WA_VBFA       TYPE TY_VBFA,
        G_WA_VBKD       TYPE TY_VBKD,
        G_WA_KNA1       TYPE TY_KNA1,
        G_WA_VBPA       TYPE TY_VBPA,
        G_WA_ADRC       TYPE TY_ADRC,
        G_WA_MARA       TYPE TY_MARA,
        G_WA_VBEP       TYPE TY_VBEP,
        G_WA_LIKP       TYPE TY_LIKP ,
        G_WA_LIPS       TYPE TY_LIPS ,
        G_WA_BSPLIT     TYPE TY_LIPS ,
        G_WA_VBAK       TYPE TY_VBAK ,
        G_WA_VBAP       TYPE TY_VBAP,
        G_WA_MVKE       TYPE TY_MVKE,
        G_WA_KONV       TYPE TY_KONV,
        G_WA_KONV_PR    TYPE TY_KONV,
        G_WA_KONV_ZR00  TYPE TY_KONV,
        G_WA_KONH       TYPE TY_KONH,
*       G_WA_ATP        LIKE ZATPXTR,
        G_WA_VBUK       TYPE TY_VBUK,
        G_WA_VBUP       TYPE TY_VBUP,
        G_WA_ORD_VBUK   TYPE TY_VBUK,
        G_WA_ORD_VBUP   TYPE TY_VBUP,
        G_WA_DELV_VBUK  TYPE TY_VBUK,
        G_WA_DELV_VBUP  TYPE TY_VBUP,
        G_WA_HEADER     TYPE TY_HEADER.

* Internal table to hold Statistics Summary Data
TYPES:  BEGIN OF TY_STATISTICS_SUMMARY,
          BUS_AREA(2)   TYPE C,
          NO_ITEMS(10)  TYPE P DECIMALS 0,
          NET_VALUE(15) TYPE P DECIMALS 2,
        END OF TY_STATISTICS_SUMMARY.

* Internal Table - Statistics Summary to write to Flat file
TYPES:  BEGIN OF TY_SUMMARY_TARGET_FILE,
          DATE_EXT          LIKE SY-DATUM,
          BUS_AREA(2)       TYPE C,
          FS_NO_ITEMS(10)   TYPE N,
          FS_SIGN(1)        TYPE C,
          FS_NET_VALUE(17)  TYPE N,
          FILLER(16)        TYPE C,
        END OF TY_SUMMARY_TARGET_FILE.

* Internal Tables - Mapping & Writing into Flat file
DATA:   T_ITAB    TYPE TY_STATISTICS_SUMMARY OCCURS 0 WITH HEADER LINE,
        T_FILE    TYPE STANDARD TABLE OF TY_SUMMARY_TARGET_FILE,
* Work Areas for Flat file
        G_ITAB_WA LIKE LINE OF T_ITAB,
        G_FILE_WA LIKE LINE OF T_FILE.
* Work Area - TVARV Table
DATA:   S_TVARV   LIKE TVARV.
DATA:   S_TVARV_Date like tvarv,                           "+PPR1734
        S_TVARV_TIME like tvarv.                           "+PPR1734

*----------------------------------------------------------------------*
* Constants
*----------------------------------------------------------------------*
CONSTANTS: C_FILETYPE_PHYSICAL    VALUE 'P',
        C_FILETYPE_LOGICAL        VALUE 'L',
        C_SPACE TYPE LOEVM        VALUE ' ',
        C_SHIP_TO TYPE PARVW      VALUE 'WE',
        C_SALES_FORCE TYPE PARVW  VALUE 'ZS'.

CONSTANTS: C_TVARV_NAME1(17)  TYPE C   VALUE 'ZRMIIN01_INVDAF01',
        C_TVARV_NAME2(17)     TYPE C   VALUE 'ZRMIIN01_INVDAF02',
        C_TYPE_PARAM          LIKE     TVARV-TYPE   VALUE 'P'.

CONSTANTS:
        G_I_COMPANY_CODE  TYPE I VALUE 9000,
        " Overlay of zeroes to 9-char
        C_ZERO_OVERLAY9_2(10) VALUE '0000000.00',
        C_ZERO_OVERLAY2(2) VALUE '00',
        C_ZERO_OVERLAY6(6) VALUE '000000',
        C_ZERO_OVERLAY8(8) VALUE '00000000',
        C_ZERO_OVERLAY10(10) VALUE '0000000000',
        C_ZERO_OVERLAY9_3(10) VALUE '000000.000',

        C_DIRECT(1)    VALUE '1',            " IDoc direction (outbound)
        C_DOCTYP(8)    VALUE 'ZRMDAF01',     " IDoc type
        C_IDOCTP(8)    VALUE 'ZRMDAF01',     " IDoc type
        C_MESTYP(6)    VALUE 'ZRMDAF',       " Message type
        C_Z1DAFA1(7)   VALUE 'Z1DAFA1',      " Header segment name
        C_Z1DAFA2(7)   VALUE 'Z1DAFA2',      " Header segment name
        C_Z1DAFO1(7)   VALUE 'Z1DAFO1',      " Header segment name
        C_Z1DAFO2(7)   VALUE 'Z1DAFO2',      " Header segment name
        C_Z1DAFD1(7)   VALUE 'Z1DAFD1',      " Header segment name
        C_Z1DAF11(7)   VALUE 'Z1DAF11',      " Header segment name
        C_Z1DAF12(7)   VALUE 'Z1DAF12',      " Header segment name
        C_Z1DAFPC(7)   VALUE 'Z1DAFPC',  " Hdr Segment occurs 16 times
        C_Z1DAFZ1(7)   VALUE 'Z1DAFZ1',      " Miscellaneous Fields

        C_SAMPLE TYPE MTART VALUE 'ZSMP',  " Sample material type
        C_TRADE TYPE MTART VALUE 'ZTRD',   " Trade material type
        C_DELIVERY(1) TYPE C VALUE 'J',
        C_DBCRMEMO(4) TYPE C VALUE 'KLOP'. " K, L, O, P

*----------------------------------------------------------------------*
* Global Variables
*----------------------------------------------------------------------*
DATA:   G_LOG_FILENAME TYPE FILEINTERN,
        G_FILENAME     TYPE FILEEXTERN.

DATA:   G_ORD_DATA_FLG(1) TYPE C, "Order DATA flag
        G_DELV_DATA_FLG(1) TYPE C, "Delivery Data flag
        G_HDR_CHARG_FLG(1) TYPE C. "Header Charge Flag

* Date Variables
DATA:   G_PREV_DATE   TYPE SYDATUM, "Previous Job run Date
        G_PREV_TIME   TYPE SYTIME,  "Previous Job run Time

        G_CUR_DATE   TYPE SYDATUM,  "Current Date
        G_CUR_TIME   TYPE SYTIME,   "Current Time

        g_extdt      like syst-datum,                       "PPR0079+

        G_PREV_DATE_TIME(14) TYPE N, "Previous Job run Date&Time
        G_CUR_DATE_TIME(14)  TYPE N, "Current Job run Date&Time
        G_REC_DATE_TIME(14)  TYPE N, "Inv Create Date&Time

        G_ERR_EXIT(1)        TYPE C.

DATA:   G_LINE_COUNT         TYPE I. "Line count of internal table
DATA:   G_I_ROUTE_DAYS       TYPE I. "routing days
DATA:   G_I_IDOC_COUNT       TYPE I. "IDOC count
DATA:   G_I_IDOC_TOT         TYPE I. "IDOC count

* VARIABLE DECLARATIONS ---------------------------------------

DATA:   G_D_QTY      LIKE VBAP-ZMENG,
        G_D_AMT      LIKE VBAP-NETWR.

*FCR0322 -- ZR00 CONDITION OR ZP01-ZP10 CONDITIONS -- BEGIN
DATA: L_FLG_ZR00 TYPE C, "FCR0322 - ZR00 FLAG
        L_FLG_ZPXX TYPE C. "FCR0322 - ZP01-ZP10 FLAG
*FCR0322 -- END

* Temp. qty variables
DATA: L_D_QTY1 LIKE VBRP-FKLMG.
DATA: L_D_QTY2 LIKE VBAP-KWMENG.

DATA:   G_I_COMPCODE LIKE BAPI0002_2-COMP_CODE VALUE '9000', "Co code
        G_I_YEAR     LIKE BAPI0002_4-FISCAL_YEAR, "Fiscal Year
        G_I_PERIOD   LIKE BAPI0002_4-FISCAL_PERIOD, "Fiscal Period
        G_I_ACC_PERIOD(6) TYPE N. "Period in YYYYMM format

DATA:   CDATE1(8)         TYPE C.
*DATA:   L_FS_VBTYP(1) TYPE C.
DATA:   G_FLG_DATA(1) TYPE C.
DATA:   G_FLG_BSPLIT(1) TYPE C. "Batch Split flag

DATA:   G_FLG_LAST_REC(1) TYPE C. "For Trailer Record

* BAPI - Function Return Variables
DATA:   STRETURN  LIKE BAPIRETURN.
DATA:   STRETURN1  LIKE BAPIRETURN1.

** Includes - Subroutines only                           "-PPR1894
*INCLUDE ZRMDIN01.                                       "-PPR1894
*INCLUDE ZRMDIN02.                                       "-PPR1894

*----------------------------------------------------------------------*
* Initialization
*----------------------------------------------------------------------*
*INITIALIZATION.  "PPR0079-
*----------------------------------------------------------------------*
* Selection Screen
*----------------------------------------------------------------------*
* Date and Time Block
*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK FLDATE WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS:  S_KUNNR  FOR KNA1-KUNNR OBLIGATORY.
SELECT-OPTIONS:S_VKORG  FOR VBAK-VKORG OBLIGATORY.
PARAMETERS:     P_VTWEG  LIKE  KNVV-VTWEG,
                P_SPART  LIKE  KNVV-SPART.
SELECTION-SCREEN END OF BLOCK B1.
parameter: p_extdt   like syst-datum obligatory.            "PPR0079+
PARAMETER: P_ERDAT   LIKE VBRK-ERDAT. " Job Run Date
PARAMETER: P_ERZET   LIKE VBRK-ERZET. " Job Run Time
"PPR1894
SELECTION-SCREEN END OF BLOCK FLDATE.

* End of Date and Time Block ------------------------------------------*

* Filename Block ------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK FLNAME WITH FRAME TITLE TEXT-002.
PARAMETER:   P_FILE  LIKE DXFILE-FILENAME. " FILENAME
SELECTION-SCREEN SKIP 1.
PARAMETER : P_FLTYP.         " FILE TYPE
SELECTION-SCREEN END OF BLOCK FLNAME.

* End of Filename Block ------------------------------------------------

* Testing Invoice DAF
SELECTION-SCREEN BEGIN OF BLOCK TESTRUN WITH FRAME TITLE TEXT-007.
PARAMETER: P_TSTRUN   AS CHECKBOX DEFAULT ' '. "Screen Check Box
PARAMETER: P_TST_D1   LIKE VBRK-ERDAT. " Prev Date
PARAMETER: P_TST_T1   LIKE VBRK-ERZET. " Prev Time
PARAMETER: P_TST_D2   LIKE VBRK-ERDAT. " Current Date
PARAMETER: P_TST_T2   LIKE VBRK-ERZET. " Current Time
SELECT-OPTIONS S_INV_NO FOR LT_VBRK-VBELN. "Inv# Range
SELECTION-SCREEN END OF BLOCK TESTRUN.

* Includes - Subroutines only                           "+PPR1894
*include ZRMDIN011.
include ZRMDIN01.                                       "+PPR1894
*include ZRMDIN022.
include ZRMDIN02.                                       "+PPR1894
*----------------------------------------------------------------------*
* At Selection-Screen
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.

* Check if values are valid -- TPR0196
* PERFORM SUB_CHECK_SELECT_OPTIONS.

*----------------------------------------------------------------------*
*----------------------Start of selection----------------------------*
*----------------------------------------------------------------------*
START-OF-SELECTION.

*  PERFORM CHECK_TVARV.
*
**  Get Misc Values
** Get Accounting Period
** If the Period is not common for all the invoices for that job run,
**   Move this logic from here to Inv Header.
*
*   PERFORM GET_PERIOD.
*
*  IF G_I_ACC_PERIOD = 0.
*    "Period Not Found - This should not happen
*    MESSAGE E113(Z001) WITH G_I_COMPCODE.
*  ENDIF.

* Get Daf Extract
  PERFORM SUB_GET_DAFEXTRACT.

*----------------------------------------------------------------------*
*-----------------------End of selection-----------------------------*
*----------------------------------------------------------------------*
END-OF-SELECTION.
* TPR0196 - Invoice DAF Statistics Summary file
* Move data to output structure.
   PERFORM SUB_MAP_FILE.

*  PERFORM SUB_WRITE_FILE.

   PERFORM SUB_MODIFY_TVARV.                               "+PPR1734
*----------------------------------------------------------------------*
*-------------------------Subroutines--------------------------------*
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CHECK_TVARV
*&---------------------------------------------------------------------*
*       Get Previous Job Start Time and Date and
*       Update TVARV entries with Curren Job Start time and Date
*----------------------------------------------------------------------*
FORM CHECK_TVARV.

* Get Current Date and Time.
  G_CUR_DATE = SY-DATUM.
  G_CUR_TIME = SY-UZEIT.
  g_extdt = p_extdt.                                        "PPR0079+

* Skip if it is a test run
  IF P_TSTRUN <> SPACE.
    EXIT. "Exit from the subroutine.
  ENDIF.

* Get Previous Job Run's Date
  CLEAR S_TVARV.

  SELECT SINGLE LOW FROM TVARV INTO S_TVARV-LOW
              WHERE NAME = C_TVARV_NAME1 AND TYPE = C_TYPE_PARAM.
  IF SY-SUBRC <> 0.
    "Exit the process ... Record Should be found
    MESSAGE E110(Z001).
  ENDIF.

* Take Previous Day if data is blank.
  IF S_TVARV-LOW IS INITIAL.
    G_PREV_DATE = G_CUR_DATE - 1.
  ELSE.
    SHIFT S_TVARV-LOW LEFT DELETING LEADING SPACE.
    G_PREV_DATE = S_TVARV-LOW.
  ENDIF.

* If Re running the job - Take Parameter date as previous date
* The job runs from previous date to the current job run date and time.
  IF P_ERDAT <> 0 AND P_ERZET <> 0.
    G_PREV_DATE = P_ERDAT.
  ENDIF.

  "Store Current Job Run Date in Low value and Previous Job's Run
  "  date in High value. High value is for reference only.
  S_TVARV-NAME = C_TVARV_NAME1. "Key
  S_TVARV-TYPE = C_TYPE_PARAM. "Key
  S_TVARV-LOW  =  G_CUR_DATE.
  S_TVARV-HIGH =  G_PREV_DATE.
  move s_tvarv to s_tvarv_date.                        "+PPR1734
*  MODIFY TVARV FROM S_TVARV.                          "-PPR1734

* Get Previous Job Run's Time
  CLEAR S_TVARV.

  SELECT SINGLE LOW FROM TVARV INTO S_TVARV-LOW
              WHERE NAME = C_TVARV_NAME2 AND TYPE = C_TYPE_PARAM.
  IF SY-SUBRC <> 0.
    "Exit the process ... Record Should be found
    MESSAGE E110(Z001).
  ENDIF.

  "Take Current Time if Previous Job's Time is blank.
  IF S_TVARV-LOW IS INITIAL.
    G_PREV_TIME = G_CUR_TIME.
  ELSE.
    SHIFT S_TVARV-LOW LEFT DELETING LEADING SPACE.
    G_PREV_TIME = S_TVARV-LOW.
  ENDIF.

* If Re running the job - Take Parameter date as previous date
* The job runs from previous date to the current job run date and time.
  IF P_ERDAT <> 0 AND P_ERZET <> 0.
    G_PREV_TIME = P_ERZET.
  ENDIF.

  "Store Current Job's Run Time in Low value and Previous Job's Run
  "  time in High value. High value is for reference only.
  S_TVARV-NAME =  C_TVARV_NAME2. "Key
  S_TVARV-TYPE =  C_TYPE_PARAM. "Key
  S_TVARV-LOW  =  G_CUR_TIME.
  S_TVARV-HIGH =  G_PREV_TIME.
  move s_tvarv to s_tvarv_time.                     "+PPR1734
*  MODIFY TVARV FROM S_TVARV.                       "-PPR1734

ENDFORM.                    " CHECK_TVARV
*&---------------------------------------------------------------------*
*&      Form  sub_check_file
*&---------------------------------------------------------------------*
*       Check file name and authorization when logical file is used
*----------------------------------------------------------------------*
FORM SUB_CHECK_FILE.
* Check the file and check the authorization also.

  G_LOG_FILENAME = P_FILE.
  CALL FUNCTION 'FILE_GET_NAME' " CHECK FILE
       EXPORTING
            LOGICAL_FILENAME = G_LOG_FILENAME
       IMPORTING
            FILE_NAME        = G_FILENAME
       EXCEPTIONS
            OTHERS           = 2.
  IF SY-SUBRC <> 0.
    MESSAGE E057(Z001) WITH G_LOG_FILENAME.
  ENDIF.

* CHECK FOR PHYSICAL FILE AUTHORIZATION

  CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
       EXPORTING
            ACTIVITY         = 'WRITE'
            FILENAME         = G_FILENAME
       EXCEPTIONS
            NO_AUTHORITY     = 1
            ACTIVITY_UNKNOWN = 2
            OTHERS           = 3.

  IF SY-SUBRC <> 0.
    MESSAGE E058(Z001) WITH G_LOG_FILENAME.
  ENDIF.
*
ENDFORM.                    " sub_check_file
*&---------------------------------------------------------------------*
*&      Form  sub_check_select_options
*&---------------------------------------------------------------------*
*      Check that the values in the selection screen are valid
*----------------------------------------------------------------------*
FORM SUB_CHECK_SELECT_OPTIONS.

* Check that the filename and filetype has been entered
  IF P_FILE = SPACE OR
     P_FLTYP = SPACE.
    MESSAGE E055(Z001).
  ENDIF.

* Validate the filetype
  IF ( P_FLTYP <> C_FILETYPE_PHYSICAL ) AND
     ( P_FLTYP <> C_FILETYPE_LOGICAL ) .
    MESSAGE E056(Z001).
  ENDIF.

* Validate the filename
  IF P_FLTYP = C_FILETYPE_LOGICAL.
    PERFORM SUB_CHECK_FILE.
  ELSE.
    PERFORM SUB_CHECK_DATASET.
  ENDIF.

*
*
ENDFORM.                    " SUB_CHECK_SELECTION_OPTIONS

*&---------------------------------------------------------------------*
*&      Form  sub_write_file
*&---------------------------------------------------------------------*
*       Write data to output file
*----------------------------------------------------------------------*
FORM SUB_WRITE_FILE.
*  Transfer mapping internal table content to the flat file.

  OPEN DATASET G_FILENAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

  IF SY-SUBRC <> 0.
    MESSAGE E062(Z001) WITH G_FILENAME.
  ENDIF.

  LOOP AT T_FILE INTO G_FILE_WA.
    TRANSFER  G_FILE_WA TO G_FILENAME LENGTH 40.
    CLEAR G_FILE_WA.
  ENDLOOP.

  CLOSE DATASET G_FILENAME.
  IF SY-SUBRC <> 0.
    MESSAGE E063(Z001) WITH G_FILENAME.
  ENDIF.

ENDFORM.                    " sub_write_file
*&---------------------------------------------------------------------*
*&      Form  sub_map_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_MAP_FILE.
* Transfer Internal Table Content to mapping Internal Table.
*    Sign will be blank for +ve values and -ve for negative values.
*    Multiply net value by 100 to convert to whole number in the flat
*      file with out a decimal point.
*
  LOOP AT T_ITAB INTO G_ITAB_WA.

    G_FILE_WA-FS_SIGN = SPACE.
    IF G_ITAB_WA-NET_VALUE < 0.
      G_FILE_WA-FS_SIGN = '-'.
      G_ITAB_WA-NET_VALUE = G_ITAB_WA-NET_VALUE  *  -1 .
    ENDIF.
*    G_FILE_WA-DATE_EXT = G_CUR_DATE.                       "PPR0079-
    G_FILE_WA-DATE_EXT = g_extdt.                           "PPR0079+
    G_FILE_WA-BUS_AREA = G_ITAB_WA-BUS_AREA.
    G_FILE_WA-FS_NO_ITEMS = G_ITAB_WA-NO_ITEMS.
    G_FILE_WA-FS_NET_VALUE = G_ITAB_WA-NET_VALUE * 100.

    APPEND G_FILE_WA TO T_FILE.
    CLEAR: G_ITAB_WA,
           G_FILE_WA.

  ENDLOOP.
ENDFORM.                    " sub_map_file

*&---------------------------------------------------------------------*
*&      Form  sub_check_dataset
*&---------------------------------------------------------------------*
*       Check authorization when physical filename is used
*----------------------------------------------------------------------*
FORM SUB_CHECK_DATASET.

  G_FILENAME = P_FILE.

  CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
       EXPORTING
            ACTIVITY         = 'WRITE'
            FILENAME         = G_FILENAME
       EXCEPTIONS
            NO_AUTHORITY     = 1
            ACTIVITY_UNKNOWN = 2
            OTHERS           = 3.

  IF SY-SUBRC <> 0.
    MESSAGE E058(Z001) WITH G_FILENAME.
  ENDIF.

ENDFORM.                    " sub_check_dataset

*&---------------------------------------------------------------------*
*&      Form  sub_get_dafextract
*&---------------------------------------------------------------------*
*       DAF Extract - Main Subroutine
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM SUB_GET_DAFEXTRACT.

** If extraction is for testing
  IF P_TSTRUN <> SPACE.
    G_CUR_DATE = P_TST_D2.
    G_CUR_TIME = P_TST_T2.

    G_PREV_TIME = P_TST_T1.
    G_PREV_DATE = P_TST_D1.
  ENDIF.

* ** Begin Process ***
  WRITE:/ 'Begin of Process', SY-DATUM, SY-UZEIT.
*Get Prev and Current Job Run Date and Times into strings for comparison

  CONCATENATE G_PREV_DATE G_PREV_TIME INTO G_PREV_DATE_TIME.
  CONCATENATE G_CUR_DATE G_CUR_TIME INTO G_CUR_DATE_TIME.

  IF G_PREV_DATE_TIME > G_CUR_DATE_TIME.
    WRITE:/ 'Invalid Job Parameters', G_PREV_DATE_TIME, G_CUR_DATE_TIME.
    MESSAGE E111(Z001) WITH G_PREV_DATE_TIME G_CUR_DATE_TIME.
    EXIT.
  ENDIF.

  PERFORM GET_HEADER_DETAILS.

* For all the invoices for job run dates (Prev Job Run Date, Time to the
* current Job Run Date, Time)
  CLEAR G_WA_VBRK.
  LOOP AT LT_VBRK INTO G_WA_VBRK. "All the Invoice Numbers

*   Skip if it is a Cancelled Invoice Number
    IF G_WA_VBRK-SFAKN <> SPACE.
      CONTINUE.
    ENDIF.

*   If Invoice Extraction is for testing
    IF P_TSTRUN <> SPACE.
      IF G_WA_VBRK-VBELN IN S_INV_NO.
        "Test Invoices
      ELSE.
        CONTINUE. "Skikp if not in invoice range
      ENDIF.
    ENDIF.

*   Check Invoice Creation Time falls with in the Job Run Time
    CONCATENATE G_WA_VBRK-ERDAT G_WA_VBRK-ERZET INTO G_REC_DATE_TIME.
    IF G_REC_DATE_TIME >= G_PREV_DATE_TIME AND
       G_REC_DATE_TIME < G_CUR_DATE_TIME.

*     Clear Header Charge Data
      PERFORM CLEAR_HDR_CHARG_DATA.

*     Get Order, Delivery details for the invoice
      PERFORM GET_ORD_DELV_DETAILS.

*     Create Header Charge Record/IDOC
      IF G_WA_HEADER-HEADF <> SPACE.

*        Add tax bucket to 9th occurrence. -- tpr0424
        PERFORM PC_ADD_TAX_BUCKET.

        PERFORM CREATE_HDR_CHARG_DATA.
      ENDIF.

      CLEAR G_WA_VBRK. "Clear Invoice Header Work Area
    ENDIF.
  ENDLOOP. " of VBRK - All the invoice Numbers

* Create a blank IDOC Trailer Record with 'SS'.
  PERFORM CREATE_TRAILER_IDOC.
* Commit and Release the last set of record locks
*    because there is no trailer record.
  COMMIT WORK. " AND WAIT.
  CALL FUNCTION 'DEQUEUE_ALL'.

* ** End Process ***
  WRITE:/ 'IDOC COUNT: ', G_I_IDOC_TOT.
  WRITE:/ 'End of Process', SY-DATUM, SY-UZEIT.

ENDFORM.                    " sub_get_dafextract
** Begin of insertion for PPR1734
*&---------------------------------------------------------------------*
*&      Form  SUB_MODIFY_TVARV
*&---------------------------------------------------------------------*
*      Route to update the TVART table with the start date and time for
*      the next execution of the job
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SUB_MODIFY_TVARV.
* Write the date parameters to TVARV table.
modify TVARV from S_TVARV_DATE.
* Write the time parameters to TVARV table.
modify TVARV from S_TVARV_TIME.

endform.                    " SUB_MODIFY_TVARV

*Messages
*----------------------------------------------------------
*
* Message class: Z001
*055
*056
*057
*058
*062
*063
*110
*111

--------------------------------------------------------------------------------

  • No labels