Anda di halaman 1dari 8

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

* * * * *
* PROGRAM
: ZSPT_JO_REAL_TIME2
*
*
* AUTHOR
: SPRAO
*
* PURPOSE
: TO IDENTIFY THE CUSTOMER AGING OF ACCOUNT RECEIVABLE
*
*
BASED ON BASE LINE DATE
*
* START DATE : 21/08/2014
*
* FINISH DATE : 26/08/2014
*
* PACKAGE
:
*
* REQUEST NO :
*
* TCODE
:
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * *
REPORT ZSPT_JO_REAL_TIME2.
*DECLARING THE VARIABLES,TABLES AND TYPE-POOLS
TABLES BSID.
TYPE-POOLS SLIS.
DATA V_DAYS TYPE I.
DATA V_CPOS TYPE I.
*DECLARE ALL THE TYPES
SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-001.
PARAMETER PR_BUDAT TYPE BSID-BUDAT DEFAULT SY-DATUM OBLIGATORY.
SELECT-OPTIONS : SO_BUKRS FOR BSID-BUKRS,
SO_KUNNR FOR BSID-KUNNR,
SO_HKONT FOR BSID-HKONT.
SELECTION-SCREEN END OF BLOCK A.
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT.
DATA WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
TYPES : BEGIN OF TY_FINAL1,
KUNNR TYPE BSID-KUNNR,
NAME1 TYPE KNA1-NAME1,
NAME2 TYPE KNA1-NAME2,
BUKRS TYPE BSID-BUKRS,
AKONT TYPE KNB1-AKONT,
RDES TYPE SKAT-TXT50,
UMSKZ TYPE BSID-UMSKZ,
NYD TYPE BSID-DMBTR,
AGE30 TYPE BSID-DMBTR,
AGE60 TYPE BSID-DMBTR,
AGE90 TYPE BSID-DMBTR,
AGE120 TYPE BSID-DMBTR,

AGE180 TYPE BSID-DMBTR,


AGE365 TYPE BSID-DMBTR,
AGE2Y TYPE BSID-DMBTR,
AGE3Y TYPE BSID-DMBTR,
AGE3YA TYPE BSID-DMBTR,
TOTAL TYPE BSID-DMBTR,
END OF TY_FINAL1.
DATA : WA_FINAL1 TYPE TY_FINAL1,
IT_FINAL1 TYPE TABLE OF TY_FINAL1.
DATA : BEGIN OF WA_FINAL,
BUKRS TYPE BSID-BUKRS,
KUNNR TYPE BSID-KUNNR,
HKONT TYPE BSID-HKONT,
NYD TYPE BSID-DMBTR,
AGE30 TYPE BSID-DMBTR,
AGE60 TYPE BSID-DMBTR,
AGE90 TYPE BSID-DMBTR,
AGE120 TYPE BSID-DMBTR,
AGE180 TYPE BSID-DMBTR,
AGE365 TYPE BSID-DMBTR,
AGE2Y TYPE BSID-DMBTR,
AGE3Y TYPE BSID-DMBTR,
AGE3YA TYPE BSID-DMBTR,
END OF WA_FINAL.
DATA : IT_FINAL LIKE HASHED TABLE OF WA_FINAL
WITH UNIQUE KEY BUKRS KUNNR HKONT.
*DECLARE ALL THE WORK AREAS AND INTERNAL TABLES
DATA : BEGIN OF WA_BSID,
BUKRS TYPE BSID-BUKRS,
KUNNR TYPE BSID-KUNNR,
UMSKZ TYPE BSID-UMSKZ,
BELNR TYPE BSID-BELNR,
BUZEI TYPE BSID-BUZEI,
BUDAT TYPE BSID-BUDAT,
SHKZG TYPE BSID-SHKZG,
DMBTR TYPE BSID-DMBTR,
HKONT TYPE BSID-HKONT,
ZFBDT TYPE BSID-ZFBDT,
END OF WA_BSID.
DATA IT_BSID LIKE TABLE OF WA_BSID.
DATA : BEGIN OF WA_KNA1,
KUNNR TYPE KNA1-KUNNR,
NAME1 TYPE KNA1-NAME1,
NAME2 TYPE KNA1-NAME2,
END OF WA_KNA1.
DATA IT_KNA1 LIKE TABLE OF WA_KNA1.
DATA : BEGIN OF WA_KNB1,
KUNNR TYPE KNB1-KUNNR,
BUKRS TYPE KNB1-BUKRS,
AKONT TYPE KNB1-AKONT,
END OF WA_KNB1.

DATA IT_KNB1 LIKE TABLE OF WA_KNB1.


DATA : BEGIN OF WA_SKAT,
SAKNR TYPE SKAT-SAKNR,
TXT50 TYPE SKAT-TXT50,
END OF WA_SKAT.
DATA IT_SKAT LIKE TABLE OF WA_SKAT.
DATA : BEGIN OF WA_SKAT1,
SAKNR TYPE SKAT-SAKNR,
TXT50 TYPE SKAT-TXT50,
END OF WA_SKAT1.
DATA IT_SKAT1 LIKE TABLE OF WA_SKAT1.
*SELECTION SCREEN DESIGN
START-OF-SELECTION.
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

GET_INITIAL_DAT.
FILL_FINAL_TABLE.
FILL_FIELDCATALOG.
FILL_LAYOUT.
DISPLAY_OUTPUT.

FORM GET_INITIAL_DAT .
SELECT BUKRS KUNNR UMSKZ BELNR BUZEI BUDAT SHKZG DMBTR HKONT ZFBDT FROM BSID INT
O
TABLE IT_BSID WHERE BUDAT <= PR_BUDAT
AND BUKRS IN SO_BUKRS
AND KUNNR IN SO_KUNNR
AND HKONT IN SO_HKONT.
IF NOT IT_BSID IS INITIAL.
SELECT KUNNR NAME1 NAME2 FROM KNA1 INTO TABLE IT_KNA1 FOR ALL ENTRIES IN
IT_BSID WHERE KUNNR = IT_BSID-KUNNR.
SELECT KUNNR BUKRS AKONT FROM KNB1 INTO TABLE IT_KNB1 FOR ALL ENTRIES IN
IT_BSID WHERE KUNNR = IT_BSID-KUNNR AND BUKRS = IT_BSID-BUKRS.
SELECT SAKNR TXT50 FROM SKAT INTO TABLE IT_SKAT FOR ALL ENTRIES IN
IT_BSID WHERE SAKNR = IT_BSID-HKONT.
ENDIF.
IF NOT IT_KNB1 IS INITIAL.
SELECT SAKNR TXT50 FROM SKAT INTO TABLE IT_SKAT1 FOR ALL ENTRIES IN
IT_KNB1 WHERE SAKNR = IT_KNB1-AKONT.
ENDIF.
ENDFORM.
FORM FILL_FINAL_TABLE.

LOOP AT IT_BSID INTO WA_BSID.


WA_FINAL-BUKRS = WA_BSID-BUKRS.
WA_FINAL-KUNNR = WA_BSID-KUNNR.
WA_FINAL-HKONT = WA_BSID-HKONT.
IF WA_BSID-SHKZG = 'H'.
WA_BSID-DMBTR = 0 - WA_BSID-DMBTR.
ENDIF.
V_DAYS = PR_BUDAT - WA_BSID-ZFBDT.
IF V_DAYS <= 0.
WA_FINAL-NYD = WA_BSID-DMBTR.
ELSEIF V_DAYS > 0 AND V_DAYS <= 30.
WA_FINAL-AGE30 = WA_BSID-DMBTR.
ELSEIF V_DAYS > 30 AND V_DAYS <= 60.
WA_FINAL-AGE60 = WA_BSID-DMBTR.
ELSEIF V_DAYS > 60 AND V_DAYS <= 90.
WA_FINAL-AGE90 = WA_BSID-DMBTR.
ELSEIF V_DAYS > 90 AND V_DAYS <= 120.
WA_FINAL-AGE120 = WA_BSID-DMBTR.
ELSEIF V_DAYS > 120 AND V_DAYS <= 180.
WA_FINAL-AGE180 = WA_BSID-DMBTR.
ELSEIF V_DAYS > 180 AND V_DAYS <= 365.
WA_FINAL-AGE365 = WA_BSID-DMBTR.
ELSEIF V_DAYS > 365 AND V_DAYS <= 730.
WA_FINAL-AGE2Y = WA_BSID-DMBTR.
ELSEIF V_DAYS > 730 AND V_DAYS <= 1095.
WA_FINAL-AGE3Y = WA_BSID-DMBTR.
ELSE.
WA_FINAL-AGE3YA = WA_BSID-DMBTR.
ENDIF.
COLLECT WA_FINAL INTO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
LOOP AT IT_FINAL1 INTO WA_FINAL1.
MOVE-CORRESPONDING WA_FINAL TO WA_FINAL1.
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_FINAL-KUNNR.
IF SY-SUBRC = 0.
WA_FINAL1-NAME1 = WA_KNA1-NAME1.
WA_FINAL1-NAME2 = WA_KNA1-NAME2.
ENDIF.
READ TABLE IT_KNB1 INTO WA_KNB1 WITH KEY KUNNR = WA_FINAL-KUNNR

BUKRS = WA_FINAL-BUKRS.
IF SY-SUBRC = 0.
WA_FINAL1-AKONT = WA_KNB1-AKONT.
READ TABLE IT_SKAT1 INTO WA_SKAT1 WITH KEY SAKNR = WA_KNB1-AKONT.
IF SY-SUBRC = 0.
WA_FINAL1-RDES = WA_SKAT-TXT50.
ENDIF.
ENDIF.
READ TABLE IT_SKAT INTO WA_SKAT WITH KEY SAKNR = WA_FINAL-HKONT.
IF SY-SUBRC = 0.
WA_FINAL1-RDES = WA_SKAT-TXT50.
READ TABLE IT_BSID INTO WA_BSID WITH KEY BUKRS = WA_FINAL-BUKRS
KUNNR = WA_FINAL-KUNNR
HKONT = WA_FINAL-HKONT.
IF SY-SUBRC = 0.
WA_FINAL1-UMSKZ = WA_BSID-UMSKZ.
ENDIF.
ENDIF.
WA_FINAL1-TOTAL = WA_FINAL-NYD + WA_FINAL-AGE30 + WA_FINAL-AGE60 + WA_FINAL-AGE9
0 +
WA_FINAL-AGE120 + WA_FINAL-AGE180 + WA_FINAL-AGE365 + WA_FINAL
-AGE2Y +
WA_FINAL-AGE3Y + WA_FINAL-AGE3YA.
APPEND WA_FINAL1 TO IT_FINAL1.
CLEAR WA_FINAL1.
ENDLOOP.
ENDFORM.
FORM FILL_FIELDCATALOG.
V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'KUNNR'.
V_CPOS.
= 'CUSTOMER'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'NAME1'.
V_CPOS.
= 'NAME1'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'NAME2'.
V_CPOS.
= 'NAME2'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M

1.
= 'BUKRS'.
V_CPOS.
= 'COMPANY CODE'.

APPEND WA_FCAT TO IT_FCAT.


CLEAR WA_FCAT.
V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AKONT'.
V_CPOS.
= 'RECON'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'RDES'.
V_CPOS.
= 'RECON DES'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'HKONT'.
V_CPOS.
= 'G/L ACCOUNT'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'TXT50'.
V_CPOS.
= 'G/L LONG DES'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'UMSKZ'.
V_CPOS.
= 'SPECIAL G/L IND'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'DMBTR'.
V_CPOS.
= 'NOT YET DUE'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE30'.
V_CPOS.
= '0-30ds'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE60'.
V_CPOS.
= '31-60ds'.
IT_FCAT.

V_CPOS = V_CPOS + 1.

WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

= 'AGE90'.
V_CPOS.
= '61-90ds'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE120'.
V_CPOS.
= '91-120ds'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE180'.
V_CPOS.
= '121-180ds'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE365'.
V_CPOS.
= '181-365ds'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE2Y'.
V_CPOS.
= '>1Y<2Y'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE3Y'.
V_CPOS.
= '>2Y<3Y'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'AGE3YA'.
V_CPOS.
= '>3Y'.
IT_FCAT.

V_CPOS = V_CPOS +
WA_FCAT-FIELDNAME
WA_FCAT-COL_POS =
WA_FCAT-SELTEXT_M
APPEND WA_FCAT TO
CLEAR WA_FCAT.

1.
= 'TOTAL'.
V_CPOS.
= 'TOTAL'.
IT_FCAT.

ENDFORM.
FORM FILL_LAYOUT.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

WA_LAYOUT-ZEBRA = 'X'.
ENDFORM.
FORM DISPLAY_OUTPUT.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= SY-CPROG
IS_LAYOUT
= WA_LAYOUT
IT_FIELDCAT
= IT_FCAT
I_SAVE
= 'X'
TABLES
T_OUTTAB
= IT_FINAL1.
ENDFORM.