You are on page 1of 10

*&---------------------------------------------------------------------* *& Report ZFI_LATE_PAYMENT_REPORT *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zfi_late_payment_report NO.

TABLES: bkpf,bsad. *----------------------------------------------------------------------* * CLASS lcl_report DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_report DEFINITION. PUBLIC SECTION. TYPES :BEGIN OF gty_bkpf, belnr TYPE bsad-belnr, "Accounting Document Number bldat TYPE bkpf-bldat, "Document Date in Document END OF gty_bkpf, gty_t_bkpf TYPE TABLE OF gty_bkpf, BEGIN OF gty_bseg, belnr TYPE bseg-belnr, augbl TYPE bseg-augbl, Document zfbdt TYPE bseg-zfbdt, Calculation zbd1t TYPE bseg-zbd1t, "Cash Discount Days 1 END OF gty_bseg, gty_t_bseg TYPE TABLE OF gty_bseg, BEGIN OF gty_bsad, kunnr TYPE bsad-kunnr, bukrs TYPE bsad-bukrs, augbl TYPE bsad-augbl, Document belnr TYPE bsad-belnr, "Accounting Document Number budat TYPE bsad-budat, "Posting Date in the Document dmbtr TYPE bsad-dmbtr, "Amount in Local Currency END OF gty_bsad, gty_t_bsad TYPE TABLE OF gty_bsad, BEGIN OF kunnr belnr dmbtr budat gty_final, TYPE bsad-kunnr, TYPE bsad-belnr, TYPE bsad-dmbtr, TYPE bsad-budat, "Customer Number "Company Code "Document Number of the Clearing "Baseline Date for Due Date "Accounting Document Number "Document Number of the Clearing

due_date TYPE bseg-zfbdt, "Invoice Due Date bldat TYPE bkpf-bldat, "Date Paid late_paid TYPE i, "Number of Days Late/ Invoice Paid After Due Date col8 TYPE i, "Invoice paid late ( 1- 10 days) col9 TYPE i, "Amount paid Late ( 1- 10 days) col10 TYPE i, "Invoice paid late ( 11- 20 days) col11 TYPE i, "Amount paid Late ( 11- 20 days) col12 TYPE i, "Invoice paid late ( 21- 30 days) col13 TYPE i, "Amount paid Late ( 21- 30 days) col14 TYPE i, "Invoice paid late ( 31+ days) col15 TYPE i, "Amount paid Late ( 31+ days) col16 TYPE i, "Total Invoice paid late col17 TYPE i, "Total Amount paid Late t_color TYPE lvc_t_scol, "ALV control: Table for cell col END OF gty_final, gty_t_final TYPE TABLE OF gty_final. * Internal Table & Work area DATA : gt_bkpf TYPE gty_t_bkpf, gw_bkpf TYPE gty_bkpf, gt_bsad TYPE gty_t_bsad, gw_bsad TYPE gty_bsad, gt_bseg TYPE gty_t_bseg, gw_bseg TYPE gty_bseg, gt_final TYPE gty_t_final, gw_final TYPE gty_final. *Declaration of variables DATA: gv_col8 TYPE i, gv_col9 TYPE i. DATA: gr_layout TYPE REF TO cl_salv_layout. DATA: key TYPE salv_s_layout_key. DATA: gt_table TYPE REF TO cl_salv_table. **Declaration for coloring the row DATA: lt_s_color TYPE lvc_t_scol, ls_s_color TYPE lvc_s_scol. METHODS: data selection get_data, data filling fill_data, Generating output generate_output.

* * *

METHODS: set_colors CHANGING cgt_table TYPE REF TO cl_salv_table gt_output TYPE gty_t_final. * ENDCLASS. "lcl_report DEFINITION

*Selection Screen SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001. PARAMETERS : s_bukrs TYPE bsad-bukrs OBLIGATORY. "Company Code SELECT-OPTIONS : s_budat FOR bsad-budat, "Posting date s_kunnr FOR bsad-kunnr. "Customer No. SELECTION-SCREEN END OF BLOCK blk. *START-OF-SELECTION. DATA: lo_report TYPE REF TO lcl_report. CREATE OBJECT lo_report. lo_report->get_data( ). lo_report->fill_data( ). lo_report->generate_output( ). * *----------------------------------------------------------------------* * CLASS lcl_report IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_report IMPLEMENTATION. * METHOD get_data. *Fetching Accounting: Secondary Index for Customers SELECT kunnr bukrs augbl belnr budat dmbtr INTO TABLE gt_bsad FROM bsad WHERE bukrs = s_bukrs AND kunnr IN s_kunnr AND budat IN s_budat. IF gt_bsad[] IS NOT INITIAL. *Fetching Accounting Document Header SELECT belnr bldat INTO TABLE gt_bkpf FROM bkpf

FOR ALL ENTRIES IN gt_bsad WHERE belnr = gt_bsad-augbl. *Fetching Accounting Document Segment SELECT belnr augbl zfbdt zbd1t INTO TABLE gt_bseg FROM bseg FOR ALL ENTRIES IN gt_bsad WHERE belnr = gt_bsad-belnr. ENDIF. ENDMETHOD. " FETCH_DATA *&---------------------------------------------------------------------* *& Form FILL_FINAL *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* METHOD fill_data . LOOP AT gt_bsad INTO gw_bsad. MOVE: gw_bsad-kunnr gw_bsad-belnr gw_bsad-dmbtr gw_bsad-budat TO TO TO TO gw_final-kunnr, gw_final-belnr, gw_final-dmbtr, gw_final-budat.

READ TABLE gt_bseg INTO gw_bseg WITH KEY belnr = gw_bsad-belnr augbl = gw_bsad-augbl. IF sy-subrc = 0. *Invoice due date = baseline payment date + cash discount days gw_final-due_date = gw_bseg-zfbdt + gw_bseg-zbd1t. ENDIF. READ TABLE gt_bkpf INTO gw_bkpf WITH KEY belnr = gw_bsad-augbl. IF sy-subrc = 0. MOVE: gw_bkpf-bldat TO gw_final-bldat. ENDIF. *Number of Days Late = paid date - due date. gw_final-late_paid = gw_final-bldat - gw_final-due_date. *Display only if Number of Days Late value is positive IF gw_final-late_paid <= 0 . CLEAR gw_final. ENDIF. *Check Number of Days Late value is in between 1 & 10 IF gw_final-late_paid BETWEEN 1 AND 10. gw_final-col8 = 1. gw_final-col9 = gw_final-dmbtr + gw_final-col9 .

gv_col8 = gv_col8 + gw_final-col8. gv_col9 = gv_col9 + gw_final-col9. gw_final-col16 = gw_final-col8. gw_final-col17 = gw_final-col9. *Check Number of Days Late value is in between 11 & 20 ELSEIF gw_final-late_paid BETWEEN 11 AND 20. gw_final-col10 = 1. gw_final-col11 = gw_final-dmbtr + gw_final-col11 . gv_col8 = gv_col8 + gw_final-col10. gv_col9 = gv_col9 + gw_final-col11. gw_final-col16 = gw_final-col10. gw_final-col17 = gw_final-col11. *Check Number of Days Late value is in between 21 & 30 ELSEIF gw_final-late_paid BETWEEN 21 AND 30. gw_final-col12 = 1. gw_final-col13 = gw_final-dmbtr + gw_final-col13 . gv_col8 = gv_col8 + gw_final-col12. gv_col9 = gv_col9 + gw_final-col13. gw_final-col16 = gw_final-col12. gw_final-col17 = gw_final-col13. *Check Number of Days Late value is above 30 ELSEIF gw_final-late_paid >= 31. gw_final-col14 = 1. gw_final-col15 = gw_final-dmbtr + gw_final-col15 . gv_col8 = gv_col8 + gw_final-col14. gv_col9 = gv_col9 + gw_final-col15. gw_final-col16 = gw_final-col14. gw_final-col17 = gw_final-col15. ENDIF. IF gw_final IS NOT INITIAL. APPEND gw_final TO gt_final. CLEAR: gw_final. ENDIF. *Displaying Total invoice and Amount based on Customer AT END OF kunnr. READ TABLE gt_final INTO gw_final WITH KEY kunnr = kunnr. IF sy-subrc = 0. CLEAR gw_final. gw_final-kunnr = gw_bsad-kunnr. gw_final-col16 = gv_col8. gw_final-col17 = gv_col9. gw_bsad-

**Filling color to the specified row in the final internal table ls_s_color-color-col = '03'. ls_s_color-color-int = 0. ls_s_color-color-inv = 0. APPEND ls_s_color TO lt_s_color. CLEAR ls_s_color. gw_final-t_color = lt_s_color. APPEND gw_final TO gt_final. CLEAR: gw_final,gv_col8,gv_col9. ENDIF. ENDAT. ENDLOOP. ENDMETHOD. " FILL_FINAL *&---------------------------------------------------------------------* *& Form ALV_DISPLAY *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* METHOD generate_output. DATA: lv_functions TYPE REF TO cl_salv_functions_list. DATA: lx_msg TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = gt_table CHANGING t_table = gt_final ). CATCH cx_salv_msg INTO lx_msg. ENDTRY. * Set the colors to ALV display CALL METHOD set_colors CHANGING cgt_table = gt_table gt_output = gt_final.

** activate ALV generic Functions lv_functions = gt_table->get_functions( ). lv_functions->set_all( abap_true ). * **Allow the user to manage layouts of the ALV grid gr_layout = gt_table->get_layout( ). key-report = sy-repid. gr_layout->set_key( key ). gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ). *Display Output Report Column labels

* *... set the columns technical> DATA:lv_columns TYPE REF TO cl_salv_columns_table, lv_column TYPE REF TO cl_salv_column_table. lv_columns = gt_table->get_columns( ). lv_columns->set_optimize( abap_true ). *display the table gt_table->display( ). ENDMETHOD.

"ALV_DISPLAY

METHOD set_colors. * *.....Color for COLUMN..... DATA: lv_columns TYPE REF TO cl_salv_columns_table, lv_column TYPE REF TO cl_salv_column_table. DATA: ls_color TYPE lvc_s_colo. " Colors strucutre * * get Columns object lv_columns = cgt_table->get_columns( ). * INCLUDE <color>. TRY. lv_column ?= lv_columns->get_column( 'KUNNR' ). lv_column->set_long_text( 'Customer No.' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'BELNR' ). lv_column->set_long_text( 'Invoice Number' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'DMBTR' ). lv_column->set_long_text( 'Invoice Amount' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'BUDAT' ). lv_column->set_long_text( 'Invoice Date' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER

ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'DUE_DATE' ). lv_column->set_long_text( 'Invoice Due Date' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'BLDAT' ). lv_column->set_long_text( 'Date Paid' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'LATE_PAID' ). lv_column->set_long_text( 'Invoice Paid Late (In Days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. ***** TRY. lv_column ?= lv_columns->get_column( 'COL8' ). lv_column->set_long_text( 'Late Paid(1-10 days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL9' ). lv_column->set_long_text( 'Amount( 1-10 Days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL10' ). lv_column->set_long_text( 'Late Paid(11-20 days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL11' ). lv_column->set_long_text( 'Amount( 11-20 Days)' ). lv_column->set_medium_text( ' ' ).

lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. ENDTRY. TRY.

"#EC NO_HANDLER

lv_column ?= lv_columns->get_column( 'COL12' ). lv_column->set_long_text( 'Late Paid(21-30 days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL13' ). lv_column->set_long_text( 'Amount( 21-30 Days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL14' ). lv_column->set_long_text( 'Late Paid(31+ days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL15' ). lv_column->set_long_text( 'Amount(31+ Days)' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL16' ). lv_column->set_long_text( 'Total Invoice Paid Late' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY. TRY. lv_column ?= lv_columns->get_column( 'COL17' ). lv_column->set_long_text( 'Total Amount' ). lv_column->set_medium_text( ' ' ). lv_column->set_short_text( ' ' ). lv_column->set_color( ls_color ). CATCH cx_salv_not_found. "#EC NO_HANDLER ENDTRY.

TRY. lv_columns->set_color_column( 'T_COLOR' ). CATCH cx_salv_data_error. ENDTRY. * ENDMETHOD. ENDCLASS. "set_colors "lcl_report IMPLEMENTATION "#EC NO_HANDLER