Google

REPORT FOR SALES CURRENT MONTH

* Request RQ0072(FI)-Sales current month report

*----------------------------------------------------------------------*

* LB01 03/2001 Modify passage des libellés en texte

*----------------------------------------------------------------------*

REPORT ZFUS0038

NO STANDARD PAGE HEADING

LINE-COUNT 58

LINE-SIZE 72.

PARAMETERS:

SCOMP LIKE BSID-BUKRS DEFAULT '0814',

SALE-YR(04) DEFAULT '2000',

SALE-MTH(02) DEFAULT '01'.

TABLES: KNA1, KNKK, T024B, T005T, BSID, BSAD, BSEG,

FAEDE, KNB1.

* Data area for selections from BSID Accounts Receivable Open Items

*

DATA: BEGIN OF BSIDSEL OCCURS 0,

KUNNR LIKE BSID-KUNNR, " Customer No.

BUKRS LIKE BSID-BUKRS, " Company Cd.

BELNR LIKE BSID-BELNR, " Document No.

WRBTR LIKE BSID-WRBTR, " Amount

ZFBDT LIKE BSID-ZFBDT, " Baseline Date

AUGDT LIKE BSID-AUGDT, " Clearing date

ZTERM LIKE BSID-ZTERM, " Terms

ZBD1T LIKE BSID-ZBD1T, " Days for 1st Discount

ZBD2T LIKE BSID-ZBD2T, " Days for 2nd Discount

ZBD3T LIKE BSID-ZBD3T, " Net Payment Terms Period

REBZG LIKE BSID-REBZG, " No of the Invoice

SHKZG LIKE BSID-SHKZG, " Debit/Credit Indicator

GJAHR LIKE BSID-GJAHR, " Fiscal Year

BUZEI LIKE BSID-BUZEI, " Line Item No.

KKBER LIKE BSID-KKBER, " Credit Control Area

XREF2 LIKE BSID-XREF2, " salesorg,dist ch, div

AUGBL LIKE BSAD-AUGBL, " clearing doc no.

BLART LIKE BSID-BLART, " document type

ZUONR LIKE BSID-ZUONR, " allocation

END OF BSIDSEL.

* Miscellaneous counters, dtes, etc.

DATA: DATE_FORMAT(10) VALUE ' ',

CURRENT_YRMON(6) VALUE ' ',

CURRENT_MON(2) VALUE ' ',

CURRENT_DAY(2) VALUE ' ',

DAYS_DIFF(4) TYPE P DECIMALS 0 VALUE 0,

BEGIN_YYMD(8) VALUE ' ',

REPT_DATE(7) VALUE ' ',

HOLD-DAYS(2) VALUE ' ',

HOLD_KVERM LIKE KNB1-KVERM,

HOLD_BUS(4) VALUE '0814',

END_YYMD(8) VALUE ' ',

HEAD_SWITCH(1) VALUE 'Y',

BEGIN_SWITCH(1) VALUE 'Y',

ITEM_AMOUNT(11) TYPE P DECIMALS 2 VALUE 0,

ACCUM_AMOUNT(11) TYPE P DECIMALS 2 VALUE 0,

SALES_ACCUM_AMOUNT(11) TYPE P DECIMALS 2 VALUE 0,

REC_ACCUM_AMOUNT(11) TYPE P DECIMALS 2 VALUE 0,

TOTAL_NET(11) TYPE P DECIMALS 2 VALUE 0,

SALES_REPT_AMOUNT(11) TYPE P DECIMALS 2 VALUE 0,

REC_REPT_AMOUNT(11) TYPE P DECIMALS 2 VALUE 0,

REPT_NET(11) TYPE P DECIMALS 2 VALUE 0,

SAVE_XREF2 LIKE BSID-XREF2.

DATA: BEGIN OF TOT_AMTS,

FILL1(2) VALUE ' ',

XREF2(15),

FILL2(5) VALUE ' ',

AMOUNT1(15),

END OF TOT_AMTS.

FIELD-GROUPS: HEADER, STMTITEMS.

INSERT: BSIDSEL-XREF2 " sales org, dist ch, div

BSIDSEL-BUKRS " Company Cd.

BSIDSEL-ZFBDT " Baseline Date

INTO HEADER,

BSIDSEL-AUGDT " Clearing date

* faede-sk1dt " Due Date

ITEM_AMOUNT " Amount

INTO STMTITEMS.

* Set up dates for compares.

CURRENT_YRMON = SY-DATUM(6).

CURRENT_MON = SY-DATUM+4(2).

CURRENT_DAY = SY-DATUM+6(2).

CONCATENATE SALE-YR SALE-MTH '01' INTO BEGIN_YYMD.

CONCATENATE SALE-MTH '/' SALE-YR INTO REPT_DATE.

PERFORM CREATE_DATE.

* Table all items from BSID, the open item table.

SELECT KUNNR " customer no

BUKRS " company code

BELNR " Accounting document no

WRBTR " Amount

ZFBDT " Baseline date for due date calc

AUGDT " Clearing date

ZTERM " Terms code

ZBD1T " Days for 1st cash discount

ZBD2T " Days for 2nd cash discount

ZBD3T " Net payment terms period

REBZG " Number of the invoice

SHKZG " Debit/Credit Indicator

GJAHR " Fiscal year

BUZEI " Line Item No.

KKBER " Credit Control Area

XREF2 " sales org, dist ch, div

AUGBL " clearing doc no

BLART " document type

ZUONR " allocation

INTO TABLE BSIDSEL

FROM BSID

WHERE BUKRS = SCOMP

AND UMSKZ = ' '

AND BLART = 'RX'

AND HKONT = '0040000000'

AND ZFBDT GE BEGIN_YYMD

AND ZFBDT LE END_YYMD

AND MONAT = SALE-MTH

AND GJAHR = SALE-YR.

* Table all items from BSaD, the cleared item table.

SELECT KUNNR " customer no

BUKRS " company code

BELNR " Accounting document no

WRBTR " Amount

ZFBDT " Baseline date for due date calc

AUGDT " Clearing date

ZTERM " Terms code

ZBD1T " Days for 1st cash discount

ZBD2T " Days for 2nd cash discount

ZBD3T " Net payment terms period

REBZG " Number of the invoice

SHKZG " Debit/Credit Indicator

GJAHR " Fiscal year

BUZEI " Line Item No.

KKBER " Credit Control Area

XREF2 " sales org, dist ch, div

AUGBL " clearing doc no

BLART " document type

ZUONR " allocation

APPENDING TABLE BSIDSEL

FROM BSAD

WHERE BUKRS = SCOMP

AND UMSKZ = ' '

AND BLART = 'RX'

AND HKONT = '0040000000'

AND MONAT = SALE-MTH

AND GJAHR = SALE-YR

AND ZFBDT GE BEGIN_YYMD

AND ZFBDT LE END_YYMD.

* Loop through the selected items. Determine due date.

LOOP AT BSIDSEL.

IF BSIDSEL-BLART = 'DX'.

PERFORM FIND_OLD_BUS.

CONCATENATE HOLD_BUS ' ' BSIDSEL-ZUONR(3) INTO BSIDSEL-XREF2.

ENDIF.

IF BSIDSEL-SHKZG = 'H'. " if credit 'on'

ITEM_AMOUNT = BSIDSEL-WRBTR * ( -1 ).

ELSE.

ITEM_AMOUNT = BSIDSEL-WRBTR.

ENDIF.

* Create the final item table (Field Group)

IF BSIDSEL-AUGBL NE BSIDSEL-BELNR.

EXTRACT STMTITEMS.

ENDIF.

ENDLOOP.

* Sort STMTITEMS field group.

SORT.

* Loop through STMTITEMS field group.

LOOP.

AT NEW BSIDSEL-XREF2.

IF BEGIN_SWITCH NE 'Y'.

PERFORM OUTPUT_TOTAL_LINES.

MOVE BSIDSEL-XREF2 TO SAVE_XREF2.

ELSE.

MOVE BSIDSEL-XREF2 TO SAVE_XREF2.

ENDIF.

BEGIN_SWITCH = ' '.

TOTAL_NET = 0.

SALES_ACCUM_AMOUNT = 0.

REC_ACCUM_AMOUNT = 0.

ENDAT.

* accumulate amounts for sales org, dist ch, div

AT STMTITEMS.

IF BSIDSEL-AUGDT BETWEEN BEGIN_YYMD AND END_YYMD.

ITEM_AMOUNT = 0.

ELSE.

SALES_ACCUM_AMOUNT = SALES_ACCUM_AMOUNT + ITEM_AMOUNT.

SALES_REPT_AMOUNT = SALES_REPT_AMOUNT + ITEM_AMOUNT.

ENDIF.

ENDAT.

ENDLOOP.

PERFORM OUTPUT_TOTAL_LINES.

PERFORM OUTPUT_REPT_TOTALS.

*---------------------------------------------------------------------*

* FORM OUTPUT_TOTAL_LINES *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM OUTPUT_TOTAL_LINES.

IF HEAD_SWITCH = 'Y'.

MOVE 'N' TO HEAD_SWITCH.

SKIP.

WRITE: / 'Program: ZFUS0038'(100), "LB01

40 'Sales Current Month Report'(101). "LB01

WRITE: / 'Run:'(102), SY-DATUM , 'at'(103), SY-UZEIT , "LB01

50 'FOR '(104), REPT_DATE. "LB01

SKIP.

SKIP.

WRITE: / 'Sales Org.'(105). "LB01

* write: / 'Dist Ch, Div', 29 'Sales', 46 'Receipts', 68 'Total'.

WRITE: / 'Dist Ch, Div'(106), 29 'Sales'(107). "LB01

SKIP.

SKIP.

ENDIF.

* total_net = total_net + ( rec_accum_amount + sales_accum_amount ).

MOVE SAVE_XREF2 TO TOT_AMTS-XREF2.

WRITE: SALES_ACCUM_AMOUNT TO TOT_AMTS-AMOUNT1 ROUND 0.

WRITE TOT_AMTS.

* write: rec_accum_amount to tot_amts-amount2 round 0.

* write: total_net to tot_amts-amount3 round 0.

ENDFORM.

*---------------------------------------------------------------------*

* FORM OUTPUT_REPT_TOTALS *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM OUTPUT_REPT_TOTALS.

SKIP.

* rept_net = rept_net + ( rec_rept_amount + sales_rept_amount ).

MOVE 'REPORT TOTAL' TO TOT_AMTS-XREF2.

WRITE: SALES_REPT_AMOUNT TO TOT_AMTS-AMOUNT1 ROUND 0.

WRITE TOT_AMTS.

* write: rec_rept_amount to tot_amts-amount2 round 0.

* write: rept_net to tot_amts-amount3 round 0.

ENDFORM.

*---------------------------------------------------------------------*

* FORM CREATE_DATE *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM CREATE_DATE.

CASE SALE-MTH.

WHEN '01' OR '03' OR '05' OR '08' OR '10' OR '12'.

MOVE '31' TO HOLD-DAYS.

WHEN '02'.

MOVE '28' TO HOLD-DAYS.

WHEN OTHERS.

MOVE '30' TO HOLD-DAYS.

ENDCASE.

IF SALE-MTH = '02' AND SALE-YR = '2000'.

MOVE '29' TO HOLD-DAYS.

ENDIF.

CONCATENATE SALE-YR SALE-MTH HOLD-DAYS INTO END_YYMD.

ENDFORM.

*---------------------------------------------------------------------*

* FORM FIND_OLD_BUS *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM FIND_OLD_BUS.

HOLD_KVERM = ' '.

SELECT SINGLE KVERM

INTO HOLD_KVERM

FROM KNB1

WHERE KUNNR = BSIDSEL-KUNNR

AND BUKRS = BSIDSEL-BUKRS.

IF SY-SUBRC NE 0.

MOVE '0814' TO HOLD_BUS.

ELSE.

MOVE HOLD_KVERM(4) TO HOLD_BUS.

ENDIF.

IF HOLD_BUS EQ ' '.

MOVE '0814' TO HOLD_BUS.

ENDIF.

ENDFORM.