Zfi - Cust - Ageing Report

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 21

ZFI_CUST_AGEING REPORT

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

*&---------------------------------------------------------------------*
*& Report ZFI_CUST_AGEING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zfi_cust_ageing.

TYPE-POOLS: slis.

TABLES: bsid, bsad, adrc, t005u, j_1iexcdtl.

************************************************************************
*Types
************************************************************************

*Types
TYPES: BEGIN OF ty_adrc,
adrnr LIKE kna1-adrnr,
street LIKE adrc-street,
city1 LIKE adrc-city1,
region LIKE adrc-region,
END OF ty_adrc,

BEGIN OF ty_t005u,
spras LIKE t005u-spras,
land1 LIKE t005u-land1,
bland LIKE t005u-bland,
bezei LIKE t005u-bezei,
END OF ty_t005u,

BEGIN OF ty_j1iexcdtl,
exnum TYPE j_1iexcnum,
rdoc2 TYPE j_1irdoc2,
END OF ty_j1iexcdtl,

BEGIN OF ty_knav,
kunnr TYPE kunnr,
name1 TYPE name1_gp,
ort01 TYPE ort01_gp,
adrnr TYPE adrnr,
* bzirk TYPE bzirk,
END OF ty_knav,

BEGIN OF ty_bsidad,
bukrs TYPE bukrs,
kunnr TYPE kunnr,
augdt TYPE augdt,
augbl TYPE augbl,
gjahr TYPE gjahr,
belnr TYPE belnr_d,
budat TYPE budat,
bldat TYPE bldat,
blart TYPE blart,
shkzg TYPE shkzg,
dmbtr TYPE dmbtr,
zfbdt TYPE dzfbdt,
zterm TYPE dzterm,
zbd1t TYPE dzbd1t,
vbeln TYPE vbeln_vf,
END OF ty_bsidad,

BEGIN OF ty_vbrk,
vbeln TYPE vbeln,
fkdat TYPE fkdat,
END OF ty_vbrk,

BEGIN OF ty_output,
bukrs TYPE bukrs,
kunnr TYPE kunnr,
name1 TYPE name1,
gjahr TYPE gjahr,
zterm TYPE dzterm,
city TYPE ad_city1,
state TYPE bezei20,
budat TYPE budat,
vbeln TYPE vbeln,
bldat TYPE bldat,
duedate TYPE dzfbdt,
belnr TYPE belnr_d,
bzirk TYPE bzirk,
exnum TYPE j_1iexcnum,
day1 TYPE tfmatage,
dd TYPE i,
nd TYPE dmbtr, "Not Due
a_4 TYPE dmbtr,
a_7 TYPE dmbtr,
a_10 TYPE dmbtr,
a_15 TYPE dmbtr,
a_20 TYPE dmbtr,
a_30 TYPE dmbtr,
a_60 TYPE dmbtr,
a_90 TYPE dmbtr,
a_120 TYPE dmbtr,
a_150 TYPE dmbtr,
a_180 TYPE dmbtr,
a_210 TYPE dmbtr,
a_240 TYPE dmbtr,
a_275 TYPE dmbtr,
a_300 TYPE dmbtr,
a_330 TYPE dmbtr,
a_365 TYPE dmbtr,
a_366 TYPE dmbtr,
total TYPE dmbtr,
END OF ty_output.

*Workareas
DATA: gs_adrc TYPE ty_adrc,
gs_t005u TYPE ty_t005u,
gs_knav TYPE ty_knav,
gs_vbrk TYPE ty_vbrk,
gs_bskna1 TYPE ty_bsidad,
gs_bsexinv TYPE ty_bsidad,
gs_bsidad TYPE ty_bsidad,
gs_bsidtmp TYPE ty_bsidad,
gs_output TYPE ty_output,
gs_j1iexcdtl TYPE ty_j1iexcdtl.

*Internal tables
DATA: gt_adrc TYPE STANDARD TABLE OF ty_adrc,
gt_t005u TYPE STANDARD TABLE OF ty_t005u,
gt_knav TYPE STANDARD TABLE OF ty_knav,
gt_vbrk TYPE STANDARD TABLE OF ty_vbrk,
gt_bskna1 TYPE STANDARD TABLE OF ty_bsidad,
gt_bsexinv TYPE STANDARD TABLE OF ty_bsidad,
gt_bsidad TYPE STANDARD TABLE OF ty_bsidad,
gt_bsidtmp TYPE STANDARD TABLE OF ty_bsidad,
gt_output TYPE STANDARD TABLE OF ty_output,
gt_j1iexcdtl TYPE STANDARD TABLE OF ty_j1iexcdtl.

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.

*Variables
DATA: gv_days TYPE tfmatage,
gv_1st_age(17) TYPE c,
gv_2nd_age(17) TYPE c,
gv_3rd_age(17) TYPE c,
gv_4th_age(17) TYPE c,
gv_5th_age(17) TYPE c,
gv_6th_age(18) TYPE c,
gv_7th_age(18) TYPE c,
gv_8th_age(18) TYPE c,
gv_9th_age(18) TYPE c,
gv_10th_age(18) TYPE c,
gv_11th_age(18) TYPE c,
gv_12th_age(18) TYPE c,
gv_13th_age(18) TYPE c,
gv_14th_age(18) TYPE c,
gv_15th_age(18) TYPE c,
gv_16th_age(18) TYPE c,
gv_17th_age(18) TYPE c,
gv_18th_age(18) TYPE c.

SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-001.


PARAMETER : p_duedat RADIOBUTTON GROUP gr1 DEFAULT 'X' USER-COMMAND check,
p_docdat RADIOBUTTON GROUP gr1.
SELECTION-SCREEN END OF BLOCK blk2.

SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-000.


SELECT-OPTIONS : s_kunnr FOR bsid-kunnr.

SELECTION-SCREEN : BEGIN OF LINE.


SELECTION-SCREEN : COMMENT (31) text-003.
PARAMETERS: p_aged01(3) TYPE n OBLIGATORY DEFAULT '4'.
PARAMETERS: p_aged02(3) TYPE n OBLIGATORY DEFAULT '7'.
PARAMETERS: p_aged03(3) TYPE n OBLIGATORY DEFAULT '10'.
PARAMETERS: p_aged04(3) TYPE n OBLIGATORY DEFAULT '15'.
PARAMETERS: p_aged05(3) TYPE n OBLIGATORY DEFAULT '20'.
PARAMETERS: p_aged06(3) TYPE n OBLIGATORY DEFAULT '30'.
PARAMETERS: p_aged07(3) TYPE n OBLIGATORY DEFAULT '60'.
PARAMETERS: p_aged08(3) TYPE n OBLIGATORY DEFAULT '90'.
PARAMETERS: p_aged09(3) TYPE n OBLIGATORY DEFAULT '120'.
PARAMETERS: p_aged10(3) TYPE n OBLIGATORY DEFAULT '150'.
PARAMETERS: p_aged11(3) TYPE n OBLIGATORY DEFAULT '180'.
PARAMETERS: p_aged12(3) TYPE n OBLIGATORY DEFAULT '210'.
PARAMETERS: p_aged13(3) TYPE n OBLIGATORY DEFAULT '240'.
PARAMETERS: p_aged14(3) TYPE n OBLIGATORY DEFAULT '275'.
PARAMETERS: p_aged15(3) TYPE n OBLIGATORY DEFAULT '300'.
PARAMETERS: p_aged16(3) TYPE n OBLIGATORY DEFAULT '330'.
PARAMETERS: p_aged17(3) TYPE n OBLIGATORY DEFAULT '365'.
PARAMETERS: p_aged18(4) TYPE c OBLIGATORY DEFAULT '>365'.
*End of changes
SELECTION-SCREEN : END OF LINE.

SELECT-OPTIONS: s_bldat FOR bsid-bldat NO INTERVALS NO-EXTENSION OBLIGATORY.


SELECTION-SCREEN : END OF BLOCK blk1.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF ( ( p_docdat = 'X' OR p_duedat = 'X' ) AND


( screen-name = 'P_AGED01' OR screen-name = 'P_AGED02' OR
screen-name = 'P_AGED03' OR screen-name = 'P_AGED04' OR
screen-name = 'P_AGED05' OR screen-name = 'P_AGED06' OR
screen-name = 'P_AGED07' OR screen-name = 'P_AGED08' OR
screen-name = 'P_AGED09' OR screen-name = 'P_AGED10' OR
screen-name = 'P_AGED11' OR screen-name = 'P_AGED12' OR
screen-name = 'P_AGED13' OR screen-name = 'P_AGED14' OR
screen-name = 'P_AGED15' OR screen-name = 'P_AGED16' OR
screen-name = 'P_AGED17' OR screen-name = 'P_AGED18' ) ).

screen-input = '0'.
MODIFY SCREEN.

ENDIF.

ENDLOOP.

CONCATENATE '0 -' p_aged01 'days' INTO gv_1st_age SEPARATED BY


space.
CONCATENATE p_aged01 '-' p_aged02 'days' INTO gv_2nd_age SEPARATED BY
space.
CONCATENATE p_aged02 '-' p_aged03 'days' INTO gv_3rd_age SEPARATED BY
space.
CONCATENATE p_aged03 '-' p_aged04 'days' INTO gv_4th_age SEPARATED BY
space.
CONCATENATE p_aged04 '-' p_aged05 'days' INTO gv_5th_age SEPARATED BY
space.
CONCATENATE p_aged05 '-' p_aged06 'days' INTO gv_6th_age SEPARATED BY
space.
CONCATENATE p_aged06 '-' p_aged07 'days' INTO gv_7th_age SEPARATED BY
space.
CONCATENATE p_aged07 '-' p_aged08 'days' INTO gv_8th_age SEPARATED BY
space.
CONCATENATE p_aged08 '-' p_aged09 'days' INTO gv_9th_age SEPARATED BY
space.
CONCATENATE p_aged09 '-' p_aged10 'days' INTO gv_10th_age SEPARATED BY
space.
CONCATENATE p_aged10 '-' p_aged11 'days' INTO gv_11th_age SEPARATED BY
space.
CONCATENATE p_aged11 '-' p_aged12 'days' INTO gv_12th_age SEPARATED BY
space.
CONCATENATE p_aged12 '-' p_aged13 'days' INTO gv_13th_age SEPARATED BY
space.
CONCATENATE p_aged13 '-' p_aged14 'days' INTO gv_14th_age SEPARATED BY
space.
CONCATENATE p_aged14 '-' p_aged15 'days' INTO gv_15th_age SEPARATED BY
space.
CONCATENATE p_aged15 '-' p_aged16 'days' INTO gv_16th_age SEPARATED BY
space.
CONCATENATE p_aged16 '-' p_aged17 'days' INTO gv_17th_age SEPARATED BY
space.
CONCATENATE 'Above' p_aged17 'days' INTO gv_18th_age SEPARATED BY
space.

*Start Of Selection
START-OF-SELECTION.

*Retrieve the Customer Accouting details from BSID table


SELECT bukrs kunnr augdt augbl gjahr belnr budat bldat blart shkzg dmbtr
zfbdt zterm zbd1t vbeln
FROM bsid
INTO TABLE gt_bsidad
WHERE kunnr IN s_kunnr AND
budat LE s_bldat-low AND
bldat LE s_bldat-low.

SELECT bukrs kunnr augdt augbl gjahr belnr budat bldat blart shkzg dmbtr
zfbdt zterm zbd1t vbeln
FROM bsad
APPENDING TABLE gt_bsidad
WHERE kunnr IN s_kunnr AND
augdt GT s_bldat-low AND
budat LE s_bldat-low AND
bldat LE s_bldat-low.

*Retrive the Customer address number


gt_bskna1[] = gt_bsidad[].

SORT gt_bskna1 BY kunnr.


DELETE ADJACENT DUPLICATES FROM gt_bskna1 COMPARING kunnr.

*Retrieve the Customer City


IF gt_bskna1[] IS NOT INITIAL.

SELECT kunnr name1 ort01 adrnr


FROM kna1
* INNER JOIN knvv ON kna1~kunnr = knvv~kunnr
INTO TABLE gt_knav
FOR ALL ENTRIES IN gt_bskna1
WHERE kunnr = gt_bskna1-kunnr AND
spras = 'EN'.

IF gt_knav[] IS NOT INITIAL.

SELECT addrnumber AS adrnr street city1 region


FROM adrc
INTO TABLE gt_adrc
FOR ALL ENTRIES IN gt_knav
WHERE addrnumber = gt_knav-adrnr.

IF gt_adrc[] IS NOT INITIAL.

SELECT spras land1 bland bezei


FROM t005u
INTO TABLE gt_t005u
FOR ALL ENTRIES IN gt_adrc
WHERE spras = 'EN' AND
land1 = 'IN' AND
bland = gt_adrc-region.

IF sy-subrc EQ 0.

SORT gt_knav BY kunnr.


SORT gt_adrc BY adrnr.
SORT gt_t005u BY bland.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

*For retrieve the Billing document numbers of DZ Payments


gt_bsidtmp[] = gt_bsidad[].
* DELETE gt_bsidtmp WHERE blart NE 'DZ'.
DELETE gt_bsidtmp WHERE vbeln IS INITIAL.

SORT gt_bsidtmp BY vbeln.


DELETE ADJACENT DUPLICATES FROM gt_bsidtmp COMPARING vbeln.

IF gt_bsidtmp[] IS NOT INITIAL.

SELECT vbeln fkdat


FROM vbrk
INTO TABLE gt_vbrk
FOR ALL ENTRIES IN gt_bsidtmp
WHERE vbeln = gt_bsidtmp-vbeln.

IF sy-subrc = 0.

SORT gt_vbrk BY vbeln.

ENDIF.

ENDIF.

**Retrieve the Excise Invoice Number


* gt_bsexinv[] = gt_bsidad[].
*
* SORT gt_bsexinv BY vbeln.
* DELETE ADJACENT DUPLICATES FROM gt_bsexinv COMPARING vbeln.
*
* IF gt_bsexinv[] IS NOT INITIAL.
*
* SELECT exnum rdoc2
* FROM j_1iexcdtl
* INTO TABLE gt_j1iexcdtl
* FOR ALL ENTRIES IN gt_bsexinv
* WHERE rdoc2 = gt_bsexinv-vbeln.
*
* IF sy-subrc EQ 0.
*
* SORT gt_j1iexcdtl BY rdoc2.
*
* ENDIF.
*
* ENDIF.

*Prepare the final output


LOOP AT gt_bsidad INTO gs_bsidad.
gs_output-bukrs = gs_bsidad-bukrs.
gs_output-kunnr = gs_bsidad-kunnr.
gs_output-gjahr = gs_bsidad-gjahr.
gs_output-bukrs = gs_bsidad-bukrs.
gs_output-zterm = gs_bsidad-zterm.
gs_output-bldat = gs_bsidad-bldat.
* gs_output-budat = gs_bsidad-budat.
gs_output-vbeln = gs_bsidad-vbeln.
gs_output-belnr = gs_bsidad-belnr.

IF gs_output-vbeln IS NOT INITIAL.

READ TABLE gt_vbrk INTO gs_vbrk WITH KEY vbeln = gs_output-vbeln


BINARY SEARCH.
IF sy-subrc = 0.

gs_output-budat = gs_vbrk-fkdat.

ENDIF.

ENDIF.

*Retrieve the Customer name and Zone/Sales District


READ TABLE gt_knav INTO gs_knav WITH KEY kunnr = gs_output-kunnr
BINARY SEARCH.
IF sy-subrc EQ 0.

gs_output-name1 = gs_knav-name1.
* gs_output-bzirk = gs_knav-bzirk.

READ TABLE gt_adrc INTO gs_adrc WITH KEY adrnr = gs_knav-adrnr


BINARY SEARCH.
IF sy-subrc = 0.

*Retrieve City
gs_output-city = gs_adrc-city1.

READ TABLE gt_t005u INTO gs_t005u WITH KEY bland = gs_adrc-region


BINARY SEARCH.
IF sy-subrc EQ 0.

*Retrieve State
gs_output-state = gs_t005u-bezei.

ENDIF.

ENDIF.

ENDIF.
* READ TABLE gt_j1iexcdtl INTO gs_j1iexcdtl WITH KEY rdoc2 = gs_output-
vbeln.
* IF sy-subrc EQ 0.
*
**Retrieve Excise Number
* gs_output-exnum = gs_j1iexcdtl-exnum.
*
* ENDIF.

*Retrieve the logic for due date


**If Document type is DZ and created with reference to Invoice take invoice
date other wise existing
* IF gs_bsidad-blart = 'DZ' AND
* gs_bsidad-vbeln IS NOT INITIAL.
*
* READ TABLE gt_vbrk INTO gs_vbrk WITH KEY vbeln = gs_bsidad-vbeln.
* IF sy-subrc = 0.
*
* gs_output-duedate = gs_vbrk-fkdat + gs_bsidad-zbd1t.
*
* ELSE.
*
* gs_output-duedate = gs_bsidad-zfbdt + gs_bsidad-zbd1t.
*
* ENDIF.
*
* ELSE.

IF p_docdat = 'X'.

gs_output-duedate = gs_bsidad-zfbdt. " + gs_bsidad-zbd1t.

ELSEIF p_duedat = 'X'.

gs_output-duedate = gs_bsidad-zfbdt + gs_bsidad-zbd1t.

ENDIF.

* ENDIF.

*Retrieve the logic for difference of dates based on selection entry


IF p_docdat = 'X'.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'


EXPORTING
i_date_from = gs_output-duedate "bldat
i_date_to = s_bldat-low
IMPORTING
e_days = gv_days.

ELSEIF p_duedat = 'X'.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'


EXPORTING
i_date_from = gs_output-duedate
i_date_to = s_bldat-low
IMPORTING
e_days = gv_days.

ENDIF.

IF gs_bsidad-shkzg = 'H'.

gs_bsidad-dmbtr = gs_bsidad-dmbtr * -1.

ENDIF.

IF gv_days GT p_aged17.

MOVE gs_bsidad-dmbtr TO gs_output-a_366.

ELSEIF gv_days <= p_aged17 AND gv_days > p_aged16.

MOVE gs_bsidad-dmbtr TO gs_output-a_365.

ELSEIF gv_days <= p_aged16 AND gv_days > p_aged15.

MOVE gs_bsidad-dmbtr TO gs_output-a_330.

ELSEIF gv_days <= p_aged15 AND gv_days > p_aged14.

MOVE gs_bsidad-dmbtr TO gs_output-a_300.

ELSEIF gv_days <= p_aged14 AND gv_days > p_aged13.

MOVE gs_bsidad-dmbtr TO gs_output-a_275.

ELSEIF gv_days <= p_aged13 AND gv_days > p_aged12.

MOVE gs_bsidad-dmbtr TO gs_output-a_240.

ELSEIF gv_days <= p_aged12 AND gv_days > p_aged11.

MOVE gs_bsidad-dmbtr TO gs_output-a_210.

ELSEIF gv_days <= p_aged11 AND gv_days > p_aged10.


MOVE gs_bsidad-dmbtr TO gs_output-a_180.

ELSEIF gv_days <= p_aged10 AND gv_days > p_aged09.

MOVE gs_bsidad-dmbtr TO gs_output-a_150.

ELSEIF gv_days <= p_aged09 AND gv_days > p_aged08.

MOVE gs_bsidad-dmbtr TO gs_output-a_120.

ELSEIF gv_days <= p_aged08 AND gv_days > p_aged07.

MOVE gs_bsidad-dmbtr TO gs_output-a_90.

ELSEIF gv_days <= p_aged07 AND gv_days > p_aged06.

MOVE gs_bsidad-dmbtr TO gs_output-a_60.

ELSEIF gv_days <= p_aged06 AND gv_days > p_aged05.

MOVE gs_bsidad-dmbtr TO gs_output-a_30.

ELSEIF gv_days <= p_aged05 AND gv_days > p_aged04.

MOVE gs_bsidad-dmbtr TO gs_output-a_20.

ELSEIF gv_days <= p_aged04 AND gv_days > p_aged03.

MOVE gs_bsidad-dmbtr TO gs_output-a_15.

ELSEIF gv_days <= p_aged03 AND gv_days > p_aged02.

MOVE gs_bsidad-dmbtr TO gs_output-a_10.

ELSEIF gv_days <= p_aged02 AND gv_days > p_aged01.

MOVE gs_bsidad-dmbtr TO gs_output-a_7.

ELSEIF gv_days <= p_aged01 AND gv_days >= 0.

MOVE gs_bsidad-dmbtr TO gs_output-a_4.

*For Not Due datys


ELSEIF p_duedat = 'X' AND
gv_days = 0 AND
gs_output-duedate GT s_bldat-low.

MOVE gs_bsidad-dmbtr TO gs_output-nd.


ENDIF.

gs_output-total = gs_output-a_366 + gs_output-a_365 + gs_output-a_330 +


gs_output-a_300 + gs_output-a_275 + gs_output-a_240 +
gs_output-a_210 + gs_output-a_180 + gs_output-a_150 +
gs_output-a_120 + gs_output-a_90 + gs_output-a_60 +
gs_output-a_30 + gs_output-a_20 + gs_output-a_15 +
gs_output-a_10 + gs_output-a_7 + gs_output-a_4 +
gs_output-nd. "ND means Not Due

APPEND gs_output TO gt_output.


CLEAR gs_output.

ENDLOOP.

*Display Report Output


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 = 'gt_output'.
fieldcat_ln-seltext_l = 'Customer Code'.
fieldcat_ln-hotspot = 'X'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'NAME1'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Customer Name'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'VBELN'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Invoice No'.
fieldcat_ln-hotspot = 'X'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.
CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'BUDAT'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Invoice date'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'BELNR'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Doc No'.
fieldcat_ln-hotspot = 'X'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'BLDAT'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Doc. Date'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

* CLEAR fieldcat_ln.
* fieldcat_ln-fieldname = 'EXNUM'.
* fieldcat_ln-tabname = 'gt_output'.
* fieldcat_ln-seltext_l = 'Ex. Invoice no'.
* fieldcat_ln-no_zero = 'X'.
* APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'DUEDATE'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Due Date'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'ZTERM'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Payment Terms'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'CITY'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'CITY'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'STATE'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'STATE'.
fieldcat_ln-no_zero = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

* CLEAR fieldcat_ln.
* fieldcat_ln-fieldname = 'BZIRK'.
* fieldcat_ln-tabname = 'gt_output'.
* fieldcat_ln-seltext_l = 'ZONE'.
* fieldcat_ln-no_zero = 'X'.
* APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'ND'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = 'Not Due'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_4'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '0 - 4'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_7'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '4 - 7'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_10'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '7 - 10'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_15'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '10 - 15'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_20'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '15 - 20'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_30'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '20 - 30'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_60'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '30 - 60'.
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 = 'gt_output'.
fieldcat_ln-seltext_l = '60 - 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 = 'gt_output'.
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 = 'gt_output'.
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 = 'gt_output'.
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_210'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '180 - 210'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_240'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '210 - 240'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_275'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '240 - 275'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_300'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '275 - 300'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-do_sum = 'X'.
APPEND fieldcat_ln TO gt_fieldcat.

CLEAR fieldcat_ln.
fieldcat_ln-fieldname = 'A_330'.
fieldcat_ln-tabname = 'gt_output'.
fieldcat_ln-seltext_l = '300 - 330'.
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 = 'gt_output'.
fieldcat_ln-seltext_l = '330 - 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 = 'gt_output'.
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 = 'gt_output'.
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[]
i_callback_user_command = 'ALV_USER_COMMAND'
TABLES
t_outtab = gt_output
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 = 'MK Agrotech 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

*&---------------------------------------------------------------------*
*& Form ALV_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_user_command USING in_ucomm LIKE sy-ucomm
in_selfield TYPE slis_selfield.

IF in_ucomm = '&IC1'.
READ TABLE gt_output INTO gs_output INDEX in_selfield-tabindex.

CASE in_selfield-fieldname.

WHEN 'KUNNR'.

IF gs_output-kunnr IS NOT INITIAL.

SET PARAMETER ID 'KUN' FIELD in_selfield-value.


SET PARAMETER ID 'BUK' FIELD gs_output-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

ENDIF.

WHEN 'VBELN'.

IF gs_output-vbeln IS NOT INITIAL.

CALL FUNCTION 'RV_CALL_DISPLAY_TRANSACTION'


EXPORTING
vbeln = gs_output-vbeln.

ENDIF.

WHEN 'BELNR'.

IF gs_output-belnr IS NOT INITIAL.

SET PARAMETER ID 'BLN' FIELD in_selfield-value.


SET PARAMETER ID 'BUK' FIELD gs_output-bukrs.
SET PARAMETER ID 'GJR' FIELD gs_output-gjahr.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.

ENDIF.

WHEN OTHERS.

ENDCASE.

ENDIF.

ENDFORM.

You might also like