SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: so_bukrs FOR t001-bukrs OBLIGATORY,
so_gsber FOR bsid-gsber,
so_prctr FOR bsid-prctr.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) text-s01.
PARAMETERS: p_cust RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND rad.
SELECTION-SCREEN COMMENT 37(20) text-r01 FOR FIELD p_cust.
PARAMETERS: p_vendor RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 65(15) text-r02 FOR FIELD p_vendor.
SELECTION-SCREEN END OF LINE.
SELECT-OPTIONS: so_kunnr FOR kna1-kunnr MODIF ID m1 ,
so_ktokd FOR kna1-ktokd MODIF ID m1.
SELECT-OPTIONS: so_lifnr FOR lfa1-lifnr MODIF ID m2 ,
so_ktokk FOR lfa1-ktokk MODIF ID m2.
PARAMETERS: p_date TYPE bsid-budat OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
PARAMETERS: cb1 AS CHECKBOX,
cb2 AS CHECKBOX,
cb3 AS CHECKBOX,
cb4 AS CHECKBOX,
cb5 AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK bl1.
* End of addition by Vijaya as on 13.10.2015 / DV1K928226
AT SELECTION-SCREEN OUTPUT.
IF p_cust = 'X'.
LOOP AT SCREEN.
IF screen-group1 = 'M1'.
screen-active = '1'.
ENDIF.
IF screen-group1 = 'M2'.
screen-active = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ELSEIF p_vendor = 'X'.
LOOP AT SCREEN.
IF screen-group1 = 'M1'.
screen-active = '0'.
ENDIF.
IF screen-group1 = 'M2'.
screen-active = '1'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN.
IF p_vendor IS NOT INITIAL AND cb3 IS NOT INITIAL.
IF sy-ucomm IS NOT INITIAL.
MESSAGE 'Ageing from Invoice date for Customer Only' TYPE 'E'.
ENDIF.
ENDIF.
IF p_vendor IS NOT INITIAL AND cb4 IS NOT INITIAL .
IF sy-ucomm IS NOT INITIAL.
MESSAGE 'Ageing from Invoice date -line item for Customer Only' TYPE 'E'.
ENDIF.
ENDIF.
IF p_cust IS NOT INITIAL AND cb5 IS NOT INITIAL.
IF sy-ucomm IS NOT INITIAL.
MESSAGE 'Ageing from Document date -for Vendor Only' TYPE 'E'.
ENDIF.
ENDIF.
INITIALIZATION .
layout-colwidth_optimize = 'X'.
AT SELECTION-SCREEN ON so_bukrs .
SELECT SINGLE * FROM t001 WHERE bukrs IN so_bukrs .
IF sy-subrc IS NOT INITIAL.
MESSAGE 'Company Code Invalid' TYPE 'E'.
ENDIF.
START-OF-SELECTION.
wa_date-sign = 'I'.
wa_date-option = 'BT'.
wa_date-high = p_date.
APPEND wa_date TO s_date.
CLEAR wa_date.
IF p_date LT sy-datum.
wa_date-sign = 'I'.
wa_date-option = 'BT' .
* pn_date = p1_date-high.
pn_date = p_date + 1.
wa_date-low = pn_date .
wa_date-high = sy-datum.
APPEND wa_date TO r_date.
CLEAR wa_date.
ENDIF.
IF p_cust = 'X'.
PERFORM customer_ageing.
ELSEIF p_vendor = 'X'.
PERFORM vendor_ageing.
ENDIF.
FORM customer_ageing.
SELECT kunnr name1 ktokd FROM kna1 INTO TABLE it_kna1
WHERE kunnr IN so_kunnr
AND ktokd IN so_ktokd.
IF it_kna1[] IS NOT INITIAL.
SELECT bukrs kunnr umsks umskz augdt augbl zuonr gjahr belnr buzei budat bldat xblnr blart shkzg gsber dmbtr zfbdt rebzg
prctr
FROM bsid
INTO TABLE it_bsid
FOR ALL ENTRIES IN it_kna1
WHERE bukrs IN so_bukrs
AND kunnr EQ it_kna1-kunnr
AND budat IN s_date.
SELECT bukrs kunnr umsks umskz augdt augbl zuonr gjahr belnr buzei budat bldat xblnr blart shkzg gsber dmbtr zfbdt
prctr
FROM bsad
APPENDING CORRESPONDING FIELDS OF TABLE it_bsid
FOR ALL ENTRIES IN it_kna1
WHERE bukrs IN so_bukrs
AND kunnr EQ it_kna1-kunnr
AND augdt IN r_date
AND budat IN s_date.
IF it_bsid[] IS NOT INITIAL.
it_tbsid[] = it_bsid[].
SORT it_tbsid BY prctr.
DELETE it_tbsid WHERE prctr NE ' '.
IF it_tbsid[] IS NOT INITIAL.
SELECT ryear docnr rldnr rbukrs docln prctr rbusa belnr buzei
FROM faglflexa
INTO TABLE it_faglflexa
FOR ALL ENTRIES IN it_tbsid
WHERE ryear = it_tbsid-gjahr
* AND docnr = it_tbsid-belnr
AND rldnr = '0L'
AND rbukrs = it_tbsid-bukrs
AND prctr IN so_prctr
AND rbusa IN so_gsber
AND belnr = it_tbsid-belnr
AND buzei = it_tbsid-buzei.
IF it_faglflexa[] IS NOT INITIAL.
SORT it_faglflexa BY ryear docnr rbukrs.
DELETE ADJACENT DUPLICATES FROM it_faglflexa COMPARING ryear docnr rbukrs.
DELETE it_faglflexa WHERE prctr IS INITIAL.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
gt_bsid[] = it_bsid[].
SORT gt_bsid BY blart.
* DELETE gt_bsid WHERE blart <> 'AB'.
DELETE gt_bsid WHERE zuonr IS INITIAL.
t_bsid[] = gt_bsid[].
SORT t_bsid BY zuonr.
DELETE ADJACENT DUPLICATES FROM t_bsid COMPARING zuonr.
LOOP AT t_bsid INTO ts_bsid.
CONDENSE: ts_bsid-zuonr.
tts_bsid-vbeln = ts_bsid-zuonr.
APPEND tts_bsid TO tt_bsid.
CLEAR tts_bsid.
ENDLOOP.
DELETE tt_bsid WHERE vbeln IS INITIAL.
IF tt_bsid[] IS NOT INITIAL.
SELECT vbeln fkdat
FROM vbrk
INTO TABLE gt_vbrk
FOR ALL ENTRIES IN tt_bsid
WHERE vbeln = tt_bsid-vbeln.
ENDIF.
SORT gt_vbrk BY vbeln.
LOOP AT it_bsid INTO wa_bsid .
CLEAR w_days.
wa_final-blart = wa_bsid-blart.
CASE wa_final-blart.
WHEN 'RV'.
wa_final-xblnr = wa_bsid-xblnr.
WHEN 'RS'.
wa_final-xblnr = wa_bsid-zuonr.
WHEN OTHERS.
READ TABLE gt_vbrk INTO gs_vbrk WITH KEY vbeln = wa_bsid-zuonr BINARY SEARCH.
IF sy-subrc = 0.
wa_final-xblnr = gs_vbrk-vbeln. "ls_bseg-zuonr.
ELSE.
wa_final-xblnr = wa_bsid-xblnr.
ENDIF.
ENDCASE.
CASE wa_final-blart.
WHEN 'RS' OR 'RV'.
wa_final-invdate = wa_bsid-budat.
WHEN 'AB'.
CONDENSE: wa_bsid-zuonr.
IF wa_bsid-zuonr IS INITIAL.
READ TABLE gt_bsid INTO gs_bsid WITH KEY belnr = wa_bsid-belnr
gjahr = wa_bsid-gjahr.
IF sy-subrc = 0.
READ TABLE gt_vbrk INTO gs_vbrk WITH KEY vbeln = gs_bsid-zuonr BINARY SEARCH.
IF sy-subrc = 0.
wa_final-invdate = gs_vbrk-fkdat.
ENDIF.
ENDIF.
ELSE.
READ TABLE gt_vbrk INTO gs_vbrk WITH KEY vbeln = wa_bsid-zuonr BINARY SEARCH.
IF sy-subrc = 0.
wa_final-invdate = gs_vbrk-fkdat.
ENDIF.
ENDIF.
WHEN OTHERS.
wa_final-invdate = wa_bsid-budat.
ENDCASE.
IF wa_bsid-bukrs = 'SEPC'.
CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
EXPORTING
beg_da = wa_bsid-zfbdt
end_da = p_date
IMPORTING
no_cal_day = w_days
EXCEPTIONS
dateint_error = 1
OTHERS = 2.
ELSE.
IF cb3 = 'X' OR cb4 = 'X'.
CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
EXPORTING
beg_da = wa_final-invdate
end_da = p_date
IMPORTING
no_cal_day = w_days
EXCEPTIONS
dateint_error = 1
OTHERS = 2.
ELSE.
CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
EXPORTING
beg_da = wa_bsid-budat
end_da = p_date
IMPORTING
no_cal_day = w_days
EXCEPTIONS
dateint_error = 1
OTHERS = 2.
ENDIF.
ENDIF.
w_days = w_days - 1 .
wa_final-kunnr = wa_bsid-kunnr.
wa_final-umskz = wa_bsid-umskz.
wa_final-prctr = wa_bsid-prctr.
wa_final-gsber = wa_bsid-gsber.
READ TABLE it_faglflexa INTO wa_faglflexa WITH KEY ryear = wa_bsid-gjahr
docnr = wa_bsid-belnr
rbukrs = wa_bsid-bukrs BINARY SEARCH.
IF sy-subrc = 0.
wa_final-prctr = wa_faglflexa-prctr.
wa_final-gsber = wa_faglflexa-gsber.
ENDIF.
IF wa_bsid-shkzg = 'H'.
wa_final-pend_credit = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'S'.
wa_final-pend_debit = wa_bsid-dmbtr .
ENDIF.
wa_final-total = wa_final-pend_debit - wa_final-pend_credit.
IF w_days < 30.
IF wa_bsid-shkzg = 'S'.
wa_final-0_30d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-0_30c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 30 AND w_days LT 60 .
IF wa_bsid-shkzg = 'S'.
wa_final-31_60d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-31_60c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 60 AND w_days LT 90 .
IF wa_bsid-shkzg = 'S'.
wa_final-61_90d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-61_90c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 90 AND w_days LT 120.
IF wa_bsid-shkzg = 'S'.
wa_final-91_120d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-91_120c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 120 AND w_days LT 180.
IF wa_bsid-shkzg = 'S'.
wa_final-121_180d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-121_180c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 180 AND w_days LT 365.
IF wa_bsid-shkzg = 'S'.
wa_final-181_365d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-181_365c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 365 AND w_days LT 1080.
IF wa_bsid-shkzg = 'S'.
wa_final-366_1080d = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-366_1080c = wa_bsid-dmbtr .
ENDIF.
ELSEIF w_days GE 1080.
IF wa_bsid-shkzg = 'S'.
wa_final-1080_abvd = wa_bsid-dmbtr .
ELSEIF wa_bsid-shkzg = 'H'.
wa_final-1080_abvc = wa_bsid-dmbtr .
ENDIF.
ENDIF.
wa_final-belnr = wa_bsid-belnr.
wa_final-buzei = wa_bsid-buzei.
wa_final-budat = wa_bsid-budat.
wa_final-shkzg = wa_bsid-shkzg.
wa_final-gjahr = wa_bsid-gjahr.
wa_final-tpend = wa_final-pend_debit - wa_final-pend_credit.
wa_final-t30 = wa_final-0_30d - wa_final-0_30c.
wa_final-t31_60 = wa_final-31_60d - wa_final-31_60c.
wa_final-t61_90 = wa_final-61_90d - wa_final-61_90c.
wa_final-t91_120 = wa_final-91_120d - wa_final-91_120c.
wa_final-t121_180 = wa_final-121_180d - wa_final-121_180c.
wa_final-t181_365 = wa_final-181_365d - wa_final-181_365c.
wa_final-t366_1080 = wa_final-366_1080d - wa_final-366_1080c.
wa_final-t1080_abv = wa_final-1080_abvd - wa_final-1080_abvc.
wa_final-zuonr = wa_bsid-zuonr.
APPEND wa_final TO it_final.
CLEAR : wa_bsid , wa_final,wa_faglflexa .
ENDLOOP.
IF so_prctr IS NOT INITIAL.
DELETE it_final WHERE prctr NOT IN so_prctr.
ENDIF.
IF so_gsber IS NOT INITIAL.
DELETE it_final WHERE gsber NOT IN so_gsber.
ENDIF.
IF it_final[] IS NOT INITIAL.
LOOP AT it_final ASSIGNING <fs> .
READ TABLE it_kna1 INTO wa_kna1 WITH KEY kunnr = <fs>-kunnr.
IF sy-subrc IS INITIAL.
MOVE wa_kna1-name1 TO <fs>-name1 .
ENDIF.
ENDLOOP.
ENDIF.
gtt_final[] = it_final[].
LOOP AT gtt_final INTO gst_final.
CLEAR: gst_final-gjahr,
gst_final-belnr,
gst_final-buzei,
gst_final-budat,
gst_final-blart,
gst_final-shkzg,
gst_final-umskz,
gst_final-prctr,
gst_final-gsber,
gst_final-xblnr,
gst_final-zuonr,
gst_final-invdate.
MOVE-CORRESPONDING gst_final TO gs_final.
COLLECT gs_final INTO gt_final.
ENDLOOP.
DELETE gt_final WHERE total IS INITIAL.
LOOP AT gt_final INTO gs_final.
gs_lifnr-sign = 'I'.
gs_lifnr-option = 'EQ'.
gs_lifnr-low = gs_final-kunnr.
APPEND gs_lifnr TO gv_lifnr.
CLEAR gs_lifnr.
ENDLOOP.
IF cb1 = 'X' OR cb2 = 'X' OR cb3 = 'X'..
it_final[] = gt_final[].
ENDIF.
DELETE it_final WHERE kunnr NOT IN gv_lifnr.
ENDFORM.
No comments:
Post a Comment