You are on page 1of 9

customer Ageing Report

Sample report is developed for sd for customer ageing


*&---------------------------------------------------------------------*
*& Report ZFI_VENDOR_AGEING
*
*&
*
*&---------------------------------------------------------------------**&
Title - customer Ageing Report days
*
*&
*
*& Module - sd
*
*&---------------------------------------------------------------------*
REPORT

zsd_customer_ageing.

TYPE-POOLS: SLIS.
DATA: G_REPID LIKE SY-REPID,
GS_PRINT
TYPE SLIS_PRINT_ALV,
T_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_EVENTS
TYPE SLIS_T_EVENT,
I_SORT TYPE SLIS_T_SORTINFO_ALV,
GS_LAYOUT
TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT
TYPE SLIS_T_FIELDCAT_ALV,
GS_CELL TYPE SLIS_LINEINFO,
FIELDCAT_LN LIKE LINE OF GT_FIELDCAT.
DATA : GS_VARIANT LIKE DISVARIANT,
G_SAVE.
DATA : IT_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA : L_LIST(105) TYPE C.
"Store the Top-of-page headings
DATA : T_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA : LS_SORT TYPE TABLE OF SLIS_SORTINFO_ALV.
DATA : WA_SORT
LIKE LINE OF LS_SORT.
TABLES : BSID ,
BSAD,
J_1IEXCDTL.
DATA : BEGIN OF ITAB OCCURS 0 ,
KUNNR LIKE BSID-KUNNR,
BUDAT LIKE BSID-BUDAT,
VBELN LIKE BSID-VBELN,
BLDAT LIKE BSID-BLDAT,
BELNR LIKE BSID-BELNR,
WRBTR LIKE BSID-WRBTR,
SHKZG LIKE BSID-SHKZG,
AUGBL LIKE BSID-AUGBL,

AUGDT LIKE BSID-AUGDT,


NAME1 LIKE KNA1-NAME1,
ORT01 LIKE KNA1-ORT01,
BZIRK LIKE KNVV-BZIRK,
DMBTR LIKE BSID-DMBTR,
EXNUM LIKE J_1IEXCDTL-EXNUM,
DAY1 LIKE VTBBEWE-ATAGE,
DD TYPE I,
A_45 LIKE BSID-WRBTR,
A_90 LIKE BSID-WRBTR,
A_120 LIKE BSID-WRBTR,
A_150 LIKE BSID-WRBTR,
A_180 LIKE BSID-WRBTR,
A_365 LIKE BSID-WRBTR,
A_366 LIKE BSID-WRBTR,
TOTAL LIKE BSID-WRBTR,
END OF ITAB.
DATA : ITAB1 LIKE ITAB OCCURS 0 WITH HEADER LINE.
*
*
*

SELECT-OPTIONS : KUNNR FOR BSID-KUNNR.


PARAMETERS : BUDAT TYPE BSID-BUDAT DEFAULT SY-DATUM.
PARAMETERS : BUKRS TYPE BSID-BUKRS .

DATA : FOR_1ST_AGE(17) TYPE C,


FOR_2ND_AGE(17) TYPE C,
FOR_3RD_AGE(17) TYPE C,
FOR_4TH_AGE(17) TYPE C,
FOR_5TH_AGE(17) TYPE C,
FOR_6TH_AGE(18) TYPE C,
FOR_7TH_AGE(18) TYPE C.

SELECTION-SCREEN:BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS : KUNNR FOR BSID-KUNNR.
SELECTION-SCREEN : BEGIN OF LINE.
SELECTION-SCREEN : COMMENT (31) TEXT-003.
PARAMETERS: AGEDAYS1(3) TYPE N OBLIGATORY DEFAULT '45'.
PARAMETERS: AGEDAYS2(3) TYPE N OBLIGATORY DEFAULT '90'.
PARAMETERS: AGEDAYS3(3) TYPE N OBLIGATORY DEFAULT '120'.
PARAMETERS: AGEDAYS4(3) TYPE N OBLIGATORY DEFAULT '150'.
PARAMETERS: AGEDAYS5(3) TYPE N OBLIGATORY DEFAULT '180'.
PARAMETERS: AGEDAYS6(3) TYPE N OBLIGATORY DEFAULT '365'.
SELECTION-SCREEN : END OF LINE.
SELECT-OPTIONS:BLDAT FOR BSID-BLDAT NO INTERVALS NO-EXTENSION
OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK BLK1.
CONCATENATE '0 -' AGEDAYS1 'days' INTO FOR_1ST_AGE SEPARATED BY SPACE.
CONCATENATE AGEDAYS1 '-' AGEDAYS2 'days' INTO FOR_2ND_AGE SEPARATED BY
SPACE.

CONCATENATE AGEDAYS2 '-' AGEDAYS3 'days' INTO FOR_3RD_AGE SEPARATED BY


SPACE.
CONCATENATE AGEDAYS3 '-' AGEDAYS4 'days' INTO FOR_4TH_AGE SEPARATED BY
SPACE.
CONCATENATE AGEDAYS4 '-' AGEDAYS5 'days' INTO FOR_5TH_AGE SEPARATED BY
SPACE.
CONCATENATE AGEDAYS5 '-' AGEDAYS6 'days' INTO FOR_6TH_AGE SEPARATED BY
SPACE.
CONCATENATE 'Above' AGEDAYS6 'days' INTO FOR_7TH_AGE SEPARATED BY SPACE.

***************
START-OF-SELECTION.
SELECT KUNNR BUDAT VBELN BELNR BLDAT DMBTR AUGBL AUGDT
SHKZG
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM BSID
WHERE KUNNR IN KUNNR
AND BLDAT <= BLDAT-LOW
AND UMSKZ NE 'A' AND UMSKZ NE 'E'
AND BUDAT <= BLDAT-LOW.

SELECT KUNNR BUDAT VBELN BELNR BLDAT DMBTR AUGBL AUGDT SHKZG
INTO CORRESPONDING FIELDS OF TABLE ITAB1
FROM BSAD
WHERE KUNNR IN KUNNR
AND BLDAT <= BLDAT-LOW
AND UMSKZ NE 'A' AND UMSKZ NE 'E'
AND AUGDT > BLDAT-LOW
AND BUDAT <= BLDAT-LOW .
LOOP AT ITAB1 WHERE AUGDT > BLDAT-LOW.
APPEND ITAB1 TO ITAB..
ENDLOOP..
LOOP AT ITAB.
IF ITAB-SHKZG = 'H'.
ITAB-DMBTR = ITAB-DMBTR * -1.
MODIFY ITAB.
ELSE.
ITAB-DMBTR = ITAB-DMBTR * 1.
MODIFY ITAB.
ENDIF.
SELECT DISTINCT KNA1~NAME1 KNA1~ORT01 KNVV~BZIRK
INTO (ITAB-NAME1,ITAB-ORT01,ITAB-BZIRK)
FROM KNB1 INNER JOIN KNA1 ON KNB1~KUNNR = KNA1~KUNNR
INNER JOIN KNVV ON KNVV~KUNNR = KNA1~KUNNR
WHERE KNA1~KUNNR = ITAB-KUNNR
AND KNA1~SPRAS = 'EN'.
MODIFY ITAB.

ENDSELECT.
*SELECT EXNUM INTO (ITAB-EXNUM) FROM J_1IEXCDTL
* WHERE RDOC2 = ITAB-VBELN.
* MODIFY ITAB.
* ENDSELECT.
ENDLOOP.
LOOP AT ITAB.
SELECT EXNUM INTO ITAB-EXNUM FROM J_1IEXCDTL
WHERE RDOC2 = ITAB-VBELN.
MODIFY ITAB.
ENDSELECT.
ENDLOOP.
SORT ITAB BY BLDAT.
LOOP AT ITAB.
CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
I_DATE_FROM
= ITAB-BLDAT
* I_KEY_DAY_FROM
=
I_DATE_TO
= BLDAT-LOW
* I_KEY_DAY_TO
=
* I_FLG_SEPARATE
=''
IMPORTING
E_DAYS
= ITAB-DAY1
* E_MONTHS
=
* E_YEARS
=
.
MOVE ITAB-DAY1 TO ITAB-DD.
MODIFY ITAB.
ENDLOOP.
BREAK BASIS.
LOOP AT ITAB.
IF ITAB-DD > AGEDAYS6.
MOVE ITAB-DMBTR TO ITAB-A_366.
*
ITAB-ANS_Q7 = ITAB-ANS_Q7 + ITAB-Q7 .
MODIFY ITAB.
ENDIF.
IF ITAB-DD <= AGEDAYS6 AND ITAB-DD > AGEDAYS5.
MOVE ITAB-DMBTR TO ITAB-A_365.
MODIFY ITAB.
ENDIF.
IF ITAB-DD <= AGEDAYS5 AND ITAB-DD > AGEDAYS4.
MOVE ITAB-DMBTR TO ITAB-A_180.
MODIFY ITAB.
ENDIF.
IF ITAB-DD <= AGEDAYS4 AND ITAB-DD > AGEDAYS3.
MOVE ITAB-DMBTR TO ITAB-A_150.
MODIFY ITAB.

ENDIF.
IF ITAB-DD <= AGEDAYS3 AND ITAB-DD > AGEDAYS2.
MOVE ITAB-DMBTR TO ITAB-A_120.
MODIFY ITAB.
ENDIF.
IF ITAB-DD <= AGEDAYS2 AND ITAB-DD > AGEDAYS1.
MOVE ITAB-DMBTR TO ITAB-A_90.
MODIFY ITAB.
ENDIF.
IF ITAB-DD <= AGEDAYS1 AND ITAB-DD => 0.
MOVE ITAB-DMBTR TO ITAB-A_45.
MODIFY ITAB.
ENDIF.
ENDLOOP.
LOOP AT ITAB.
ITAB-TOTAL = ITAB-A_45 + ITAB-A_90 + ITAB-A_120 + ITAB-A_150
+ ITAB-A_180 + ITAB-A_365 + ITAB-A_366.
MODIFY ITAB.
ENDLOOP.
PERFORM BUILD.
PERFORM GET_EVENTS.
PERFORM SUB_COMMENT_BUILD USING T_LIST_TOP_OF_PAGE.
PERFORM CALL_ALV.
*&------------Form BUILD
FORM BUILD.
DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.
REFRESH GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'KUNNR'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Customer Code'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'NAME1'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Customer Name'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'VBELN'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Invoice No'.
FIELDCAT_LN-NO_ZERO = 'X'.

* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'BUDAT'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Invoice date'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'BELNR'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Doc No'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'BLDAT'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Doc. Date'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'EXNUM'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'Ex. Invoice no'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'BZIRK'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'ZONE'.
FIELDCAT_LN-NO_ZERO = 'X'.
* FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_45'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '0 - 45'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_90'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '45 - 90'.

FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_120'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '90 - 120'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_150'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '120 - 150'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_180'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '150 - 180'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_365'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '180 - 365'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'A_366'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = '> 365'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-FIELDNAME = 'TOTAL'.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-SELTEXT_L = 'OUTSTANDING AMT'.
FIELDCAT_LN-NO_ZERO = 'X'.
FIELDCAT_LN-DO_SUM = 'X'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
G_REPID = SY-REPID.
GS_VARIANT-REPORT = G_REPID.
G_SAVE
= 'A'.

ENDFORM.

"BUILD

*&---------------Form CALL_ALV
DATA T_LAYOUT TYPE SLIS_LAYOUT_ALV.
*&---------------------------------------------------------------------*
*&
Form CALL_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM CALL_ALV.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_SAVE
= G_SAVE
IS_VARIANT
= GS_VARIANT
IT_FIELDCAT
= GT_FIELDCAT[]
IT_EVENTS
= IT_EVENTS[]
TABLES
T_OUTTAB
= ITAB
EXCEPTIONS
PROGRAM_ERROR
=1
OTHERS
= 2.
ENDFORM.
"CALL_ALV
*&
Form GET_EVENTS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS
= IT_EVENTS[]
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS
= 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE IT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO IT_EVENTS.
IF SY-SUBRC = 0.
MOVE T_FORMNAME_TOP_OF_PAGE TO IT_EVENTS-FORM.
APPEND IT_EVENTS.

ENDIF.
ENDFORM.

" get_events

*&---------------------------------------------------------------------*
*&
Form sub_comment_build
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_T_LIST_TOP_OF_PAGE text
*----------------------------------------------------------------------*
FORM SUB_COMMENT_BUILD USING I_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
LS_LINE-INFO = 'ABC Bearings Limited'.
APPEND LS_LINE TO I_TOP_OF_PAGE.
LS_LINE-TYP = 'H'.
LS_LINE-INFO = 'Customer Ageing'.
APPEND LS_LINE TO I_TOP_OF_PAGE.
CLEAR: LS_LINE, L_LIST.
LS_LINE-TYP = 'S'.
LS_LINE-INFO = L_LIST.
APPEND LS_LINE TO I_TOP_OF_PAGE.
ENDFORM.
" sub_comment_build
*&---------------------------------------------------------------------*
*&
Form top_of_page
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = T_LIST_TOP_OF_PAGE.
ENDFORM.

"TOP_OF_PAGE