User:Upparahally


 * & Report ZFI_COL_TEST7
 * & Report ZFI_COL_TEST7

"Add aditional hidden column for invoice where multiple items have 0 value, then sum it and perform calc with end of recpt and sum of total

REPORT zfi_col_test9.

TABLES: bsad, knb1, T001S, kna1. "Main table for extracting Data


 * For Alv Reasons
 * For Alv Reasons

TYPE-POOLS : slis.

DATA: it_fcat TYPE slis_t_fieldcat_alv, wa_fcat TYPE slis_fieldcat_alv, wa_layout TYPE slis_layout_alv, it_sort TYPE slis_t_sortinfo_alv. DATA : x_sort TYPE slis_sortinfo_alv.

TYPES: BEGIN OF coll, bukrs TYPE bsad-bukrs, "Company Code        kunnr TYPE bsad-kunnr,  "Customer No        belnr TYPE bsad-belnr,  "Accounting Document Number        budat TYPE bsad-budat,  "Posting Date in the Document blart TYPE bsad-blart, "Document Type        dmbtr TYPE bsad-dmbtr,  "Amount in Local Currency
 * Primary structure type
 * Primary structure type

"Provision for Amount in document currency (WRBTR)        REBZG type bsad-rebzg,        waers TYPE bsad-waers,  "Currency Key augbl TYPE bsad-augbl, "Document Number of the Clearing Document        augdt TYPE bsad-augdt,  "Clearing Date zuonr TYPE bsad-zuonr, "Assignment Number        bschl TYPE bsad-bschl,  "Posting Key sgtxt TYPE bsad-sgtxt, "Item Text        ltext(30) TYPE c,       "--Comment this shkzg TYPE bsad-shkzg, "Debit/Credit Indicator       UMSKZ TYPE C,

END OF coll.

DATA: BEGIN OF wa_final, sno TYPE i,       bukrs TYPE bsad-bukrs,  "Company Code        kunnr TYPE bsad-kunnr,  "Customer No        augbl TYPE bsad-augbl,  "Clearance no        augdt TYPE bsad-augdt,  "clearance date belnr TYPE bsad-belnr, "Document No        budat TYPE bsad-budat,  "Doc Date blart TYPE bsad-blart, "Doc Type        dmbtr TYPE bsad-dmbtr,  "Amt in  local Currency "hdmbtr TYPE bsad-dmbtr, "Hidden invoice column waers TYPE bsad-waers, "Currency        zuonr TYPE bsad-zuonr,  "Assignment no        bschl TYPE bsad-bschl, sgtxt TYPE bsad-sgtxt, ltext(30) TYPE c,       rbelnr TYPE bsad-belnr,  "Document No        rbudat TYPE bsad-budat,  "Doc Date rblart TYPE bsad-blart, "Doc Type        rdmbtr TYPE bsad-dmbtr,  "Amt in  local Currency rwaers TYPE bsad-waers, "Currency        rbschl TYPE bsad-bschl,        rltext(30) TYPE c,        rsgtxt TYPE bsad-sgtxt,        rzuonr TYPE bsad-zuonr,  "Assignment no        blank TYPE c LENGTH 3, shkzg TYPE bsad-shkzg, "DEBIT CREDIT INDICATOR "      icon_field LIKE icon-id,  "icon field        balance TYPE bsad-dmbtr,        settled type bsad-dmbtr,        color type c LENGTH 4 VALUE 'C100',        date_diff type i,        sname type SNAME_001S,        busab type knb1-busab,  NAME1 type kna1-NAME1,       END OF wa_final.
 * Final Internal Table structure   --Comment this section properly
 * Final Internal Table structure   --Comment this section properly

DATA : wa_itab TYPE coll,  "primary work area for handling data from BSAD       wa_inv TYPE coll,    "primary work area for handling Invoice Data wa_recpt TYPE coll. "primary work area for handling Receipt Data
 * Primary Data Elements for work area & Internal tables
 * Primary Data Elements for work area & Internal tables

DATA : BEGIN OF wa_recpt_tmp,    "For storing receipt clearing doc number       augbl TYPE bsaD-augbl,       ZUONR  TYPE BSAD-ZUONR,  REBZG TYPE BSAD-REBZG,      END OF wa_recpt_tmp. DATA it_recpt_tmp LIKE STANDARD TABLE OF wa_recpt_tmp.  "For storing receipt clearing doc number

DATA: itab LIKE STANDARD TABLE OF wa_itab, "primary internal table for storing data from BSAD      it_inv LIKE STANDARD TABLE OF wa_inv, "primary internal table for storing invoice data it_recpt LIKE STANDARD TABLE OF wa_recpt. "primary internal table for storing receipt data

DATA it_final LIKE STANDARD TABLE OF wa_final. DATA ln_final like LINE OF it_final.
 * Final Internal Table Declaration
 * Final Internal Table Declaration

DATA inv_sub TYPE bsad-dmbtr. data sett_sub TYPE bsad-dmbtr. data recpt_sub TYPE bsad-dmbtr.
 * Variables for subtotaling
 * Variables for subtotaling

data: begin of wa_recpt_val, rbelnr type bsad-belnr, rdmbtr type bsad-dmbtr, END OF wa_recpt_Val.

data it_recpt_val like STANDARD TABLE OF wa_recpt_val.

selection-screen begin of block main with frame title text-t00. select-options SO_KUNNR for BSAD-KUNNR. " FOR PERSONNEL NUMBER "SELECT-OPTIONS per_nr FOR M_PREMN-pernr. " FOR PERSONNEL NUMBER select-options so_BUSAB for T001S-BUSAB no INTERVALS. " FOR ACCOUNTING CLERK "PARAMETERS p_busab TYPE T001S-BUSAB. select-options s_rbelnr for bsad-belnr . " FOR ACCOUNTING CLERK SELECT-OPTIONS so_budat for bsad-budat. PARAMETERS p_splgl as CHECKBOX. selection-screen end of block main.

"data mark type c LENGTH 5. "data: mark_cl type bsad-augbl, "    mark_inv type bsad-belnr, "      mark_recpt type bsad-belnr.
 * Selecting DATA from BSAD into ITAB.
 * SELECT bukrs kunnr belnr budat  blart  dmbtr waers augbl augdt bschl zuonr sgtxt shkzg UMSKZ
 * INTO CORRESPONDING FIELDS OF TABLE itab
 * FROM bsad WHERE
 * kunnr LIKE '0000020051' AND augbl <> ' ' AND blart = 'DZ'
 * OR kunnr LIKE '0000020051' AND augbl <> ' ' AND blart = 'AB'
 * OR kunnr LIKE '0000020051' AND augbl <> ' ' AND blart = 'DR'
 * OR kunnr LIKE '0000020051' AND augbl <> ' ' AND blart = 'RV'
 * or kunnr like '0000020051' AND augbl <> ' ' AND umskz = 'A' AND blart = 'DZ'.
 * SELECT bukrs kunnr belnr budat  blart  dmbtr waers augbl augdt bschl zuonr sgtxt shkzg UMSKZ
 * APPENDING CORRESPONDING FIELDS OF TABLE itab
 * FROM bsID WHERE
 * kunnr like '0000020051' aND umskz = 'A' AND blart = 'DZ'.
 * SELECT bukrs kunnr belnr budat  blart  dmbtr waers augbl augdt bschl zuonr sgtxt shkzg UMSKZ
 * APPENDING CORRESPONDING FIELDS OF TABLE itab
 * FROM bsID WHERE
 * kunnr like '0000020051' aND umskz = 'A' AND blart = 'DZ'.

SELECT bukrs kunnr belnr budat  blart  dmbtr waers augbl augdt bschl zuonr sgtxt shkzg UMSKZ REBZG INTO CORRESPONDING FIELDS OF TABLE itab FROM bsad WHERE kunnr IN SO_KUNNR AND augbl <> ' ' AND blart = 'DZ' OR kunnr IN SO_KUNNR AND augbl <> ' ' AND blart = 'AB' OR kunnr IN SO_KUNNR AND augbl <> ' ' AND blart = 'DR' OR kunnr IN SO_KUNNR AND augbl <> ' ' AND blart = 'RV' or kunnr IN SO_KUNNR AND augbl <> ' ' AND umskz = 'A' AND blart = 'DZ'.


 * SELECT bukrs kunnr belnr budat  blart  dmbtr waers augbl augdt bschl zuonr sgtxt shkzg UMSKZ REBZG
 * APPENDING CORRESPONDING FIELDS OF TABLE itab
 * FROM bsID WHERE
 * kunnr IN SO_KUNNR aND umskz = 'A' AND blart = 'DZ'.

LOOP AT itab INTO wa_itab. SELECT ltext FROM tbslt INTO wa_itab-ltext WHERE bschl LIKE wa_itab-bschl. ENDSELECT. MODIFY itab FROM wa_itab. CLEAR wa_itab-ltext. ENDLOOP.

it_inv = itab. DELETE it_inv WHERE blart = 'AB'. DELETE it_inv WHERE blart = 'DZ'. SORT it_inv BY augbl. it_recpt = itab. DELETE it_recpt WHERE blart = 'DR'. DELETE it_recpt WHERE blart = 'RV'.
 * Create internal tables for invoice & receipts (Note :Invoice Types are DR/RV & Receipt Types are AB/DZ)
 * Create internal tables for invoice & receipts (Note :Invoice Types are DR/RV & Receipt Types are AB/DZ)

CLEAR itab. SORT it_recpt BY augbl blart DESCENDING. SORT it_inv BY augbl blart DESCENDING.

LOOP AT IT_RECPT INTO WA_RECPT. MOVE-CORRESPONDING WA_RECPT TO WA_RECPT_TMP. APPEND WA_RECPT_TMP TO IT_RECPT_TMP. ENDLOOP.


 * LOOPS
 * LOOPS

LOOP AT it_inv INTO wa_inv. "Looping at Invoice internal table wa_final-bukrs = wa_inv-bukrs.  wa_final-kunnr = wa_inv-kunnr.  wa_final-augbl = wa_inv-augbl.  wa_final-augdt = wa_inv-augdt.  wa_final-belnr = wa_inv-belnr.  wa_final-bschl = wa_inv-bschl.  wa_final-ltext = wa_inv-ltext.  wa_final-budat = wa_inv-budat.  wa_final-blart = wa_inv-blart.  wa_final-dmbtr = wa_inv-dmbtr.  "wa_final-hdmbtr = wa_inv-dmbtr. wa_final-waers = wa_inv-waers. wa_final-sgtxt = wa_inv-sgtxt. wa_final-zuonr = wa_inv-zuonr. wa_final-blank = ' ↔ '. READ TABLE it_recpt INTO wa_recpt WITH KEY augbl = wa_inv-augbl. "Search Receipt Internal table for same Clearing Doc Number IF sy-subrc = 0.    LOOP AT it_recpt INTO wa_recpt WHERE augbl = wa_inv-augbl AND blart ='DZ'.      wa_final-rbelnr = wa_recpt-belnr.      wa_final-rbudat = wa_recpt-budat.      wa_final-rblart = wa_recpt-blart.      wa_final-rdmbtr = wa_recpt-dmbtr.      wa_final-rwaers = wa_recpt-waers.      wa_final-rbschl = wa_recpt-bschl.      wa_final-rltext = wa_recpt-ltext.      wa_final-rsgtxt = wa_recpt-sgtxt.      wa_final-rzuonr = wa_recpt-zuonr.
 * -one invoice one receipt

if wa_recpt-dmbtr > wa_inv-dmbtr. wa_final-settled = wa_inv-dmbtr. else. wa_final-settled = wa_recpt-dmbtr. endif. wa_final-date_diff = wa_recpt-budat - wa_inv-budat + 1. APPEND wa_final TO it_final. ENDLOOP. ENDIF.
 * If receipt amt is greater than invoice amt then receipt must be equal to invoice
 * If receipt amt is greater than invoice amt then receipt must be equal to invoice
 * wa_final-bukrs = ' '.
 * wa_final-kunnr = ' '.
 * wa_final-bschl = ' '.
 * wa_final-ltext = ' '.
 * wa_final-blart = ' '.
 * wa_final-dmbtr = ' '.
 * wa_final-waers = ' '.
 * wa_final-sgtxt = ' '.
 * wa_final-zuonr = ' '.
 * -one invoice one receipt over


 * -one invoice multiple receipts

"rEAD TABLE it_recpt INTO wa_recpt WITH KEY zuonr = wa_inv-belnr.   READ TABLE it_recpt INTO wa_recpt WITH KEY rebzg = wa_inv-belnr.  IF sy-subrc = 0.    LOOP AT it_recpt_tmp INTO  wa_recpt_tmp WHERE rebzg = wa_inv-belnr.    "Get all receipts where assignment numkber is of the current invoice number. " loop at it_recpt into wa_recpt where blart = 'DZ' and augbl = wa_recpt_tmp-augbl.      loop at it_recpt into wa_recpt where  blart = 'AB' and augbl = wa_recpt_tmp-augbl.          wa_final-rbelnr = wa_recpt-belnr.          wa_final-rbudat = wa_recpt-budat.          wa_final-rblart = wa_recpt-blart.          wa_final-rdmbtr = wa_recpt-dmbtr.          wa_final-rwaers = wa_recpt-waers.          wa_final-rbschl = wa_recpt-bschl.          wa_final-rltext = wa_recpt-ltext.          wa_final-rsgtxt = wa_recpt-sgtxt.          wa_final-rzuonr = wa_recpt-zuonr.      if wa_recpt-dmbtr > wa_inv-dmbtr.        wa_final-settled = wa_inv-dmbtr.        else.         wa_final-settled = wa_recpt-dmbtr.      endif. wa_final-date_diff =  wa_recpt-budat - wa_inv-budat + 1.          append wa_final to it_final.
 * If receipt amt is greater than invoice amt then receipt must be equal to invoice
 * If receipt amt is greater than invoice amt then receipt must be equal to invoice

endloop. endloop. endif. endloop.
 * -one invoice multiple receipts OVER

"BREAK-POINT.

sort it_final by  augdt descending  augbl ASCENDING rbelnr ASCENDING rbudat descending.
 * sort it_final by rbelnr augdt descending augbl ltext descending.

"clear: it_inv, it_recpt, wa_inv, wa_recpt, recpt_sub, sett_sub.
 * _____________________________________________________________________________________________

loop at it_final into wa_final. wa_inv-belnr = wa_final-belnr. wa_inv-dmbtr = wa_final-dmbtr. wa_recpt-belnr = wa_final-rbelnr. wa_recpt-dmbtr = wa_final-rdmbtr. append wa_inv to it_inv. append wa_recpt to it_recpt. endloop.

delete ADJACENT DUPLICATES FROM it_inv. delete ADJACENT DUPLICATES FROM it_recpt.

sort it_final by rbelnr DESCENDING rbudat descending ." augdt descending  augbl ASCENDING . "BREAK-POINT. loop at it_final into wa_final. wa_recpt_val-rbelnr = wa_final-rbelnr. wa_recpt_val-rdmbtr = wa_final-settled. COLLECT wa_recpt_val into it_recpt_val. clear wa_recpt_val. endloop.

loop at it_final into wa_final. on CHANGE OF wa_final-rbelnr. ln_final-rbelnr = wa_final-rbelnr. ln_final-rbudat = wa_final-rbudat. ln_final-rdmbtr = wa_final-rdmbtr. loop at it_recpt_val into wa_recpt_val WHERE rbelnr = wa_final-rbelnr. ln_final-settled = wa_recpt_val-rdmbtr. ln_final-settled = ln_final-rdmbtr - ln_final-settled. endloop.
 * READ TABLE it_recpt_val into wa_recpt_val WITH TABLE KEY rbelnr = wa_final-rbelnr.
 * if sy-subrc = 0.
 * if sy-subrc = 0.

if ln_final-settled > 0.

ln_final-rltext = 'UNALLOCATED'. ln_final-color = 'C300'. insert ln_final INTO it_final.

endif. clear ln_final. endon. endloop.

"

CLEAR: WA_INV, WA_RECPT,WA_FINAL. LOOP AT IT_RECPT INTO WA_RECPT WHERE umskz = 'A' AND BLART = 'DZ'. wa_final-rbelnr = wa_recpt-belnr. wa_final-rbudat = wa_recpt-budat. wa_final-rblart = wa_recpt-blart. wa_final-rdmbtr = wa_recpt-dmbtr. wa_final-rwaers = wa_recpt-waers. wa_final-rbschl = wa_recpt-bschl. wa_final-rltext = wa_recpt-ltext. wa_final-rsgtxt = wa_recpt-sgtxt. wa_final-rzuonr = wa_recpt-zuonr. WA_FINAL-rltext = 'ADVANCE PAYMENT'. APPEND WA_FINAL TO IT_FINAL. ENDLOOP.


 * loop at it_final into wa_final.
 * on CHANGE OF wa_final-rbelnr.
 * ln_final-rbelnr = wa_final-rbelnr.
 * ln_final-rbudat = wa_final-rbudat.
 * ln_final-rdmbtr = wa_final-rdmbtr.
 * READ TABLE it_recpt_val into wa_recpt_val WITH TABLE KEY rbelnr = wa_final-rbelnr.
 * if sy-subrc = 0.
 * loop at it_recpt_val into wa_recpt_val WHERE rbelnr = wa_final-rbelnr.
 * ln_final-settled = wa_recpt_val-rdmbtr.
 * ln_final-settled = ln_final-rdmbtr - ln_final-settled.
 * if ln_final-settled > 0.
 * ln_final-rltext = 'UNALLOCATED'.
 * endif.
 * endloop.
 * insert ln_final INTO it_final.
 * clear ln_final.
 * endon.
 * endloop.
 * endloop.

clear ln_final. clear sett_sub.

"loop at it_final.

loop at it_final into wa_final. select busab from knb1 into wa_final-busab where kunnr = wa_final-kunnr. ENDSELECT. modify it_final from wa_final. select sname from t001s INTO wa_final-sname where busab = wa_final-busab.endselect. modify it_final from wa_final. select name1 from kna1 INTO wa_final-name1 where kunnr = wa_final-kunnr. ENDSELECT. modify it_final from wa_final. endloop.

"BREAK-POINT.

delete it_final where busab not in so_busab[]. delete it_final where kunnr not in so_kunnr[]. delete it_final where rbelnr not in s_rbelnr[]. delete it_final where rbudat not in so_budat[]. if p_splgl ne 'X'. delete  it_final where  rltext = 'ADVANCE PAYMENT'. ENDIF.

wa_fcat-col_pos = '-3'. wa_fcat-fieldname = 'BUKRS'. wa_fcat-seltext_l = 'Company Code'. wa_fcat-outputlen = '10'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '-2'. wa_fcat-fieldname = 'KUNNR'. wa_fcat-seltext_l = 'Customer No.'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '-1'. wa_fcat-fieldname = 'NAME1'. wa_fcat-seltext_l = 'Customer Name.'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '0'. wa_fcat-fieldname = 'SNAME'. wa_fcat-seltext_l = 'Acc Clerk'.

wa_fcat-outputlen = '10'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '1'. wa_fcat-fieldname = 'AUGDT'. wa_fcat-seltext_l = 'Clearing Date'. wa_fcat-outputlen = '10'. "wa_fcat-emphasize = 'C010'. append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '2'. wa_fcat-fieldname = 'AUGBL'. wa_fcat-seltext_l = 'Clearing Doc'. "wa_fcat-emphasize = 'C410'. "wa_fcat-emphasize = 'C010'. wa_fcat-outputlen = '12'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '3'. wa_fcat-fieldname = 'BSCHL'. wa_fcat-seltext_l = 'PK'. "wa_fcat-emphasize = 'C410'. wa_fcat-no_out = 'X'.  wa_fcat-outputlen = '20'.  append wa_fcat to it_fcat.  clear wa_fcat.
 * 88

wa_fcat-col_pos = '4'. wa_fcat-fieldname = 'LTEXT'. wa_fcat-seltext_l = 'Posting Key'. wa_fcat-outputlen = '20'. "wa_fcat-emphasize = 'C410'. append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '5'. wa_fcat-fieldname = 'BLART'. wa_fcat-seltext_l = 'Doc.Type'. "wa_fcat-emphasize = 'C410'.. wa_fcat-outputlen = '3'.  append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '6'. wa_fcat-fieldname = 'BELNR'. wa_fcat-seltext_l = 'Invoice. No'. "wa_fcat-emphasize = 'C410'. wa_fcat-outputlen = '12'.  append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '7'. wa_fcat-fieldname = 'BUDAT'. wa_fcat-seltext_l = 'Posting Dt.'. wa_fcat-outputlen = '10'. "wa_fcat-emphasize = 'C410'. append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '8'. wa_fcat-fieldname = 'DMBTR'. wa_fcat-seltext_l = 'Invoice Amt.(KWD)'. wa_fcat-outputlen = '12'. "wa_fcat-emphasize = 'C410'. wa_fcat-currency = 'KWD'.  "wa_fcat-do_sum = 'X'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '9'. wa_fcat-fieldname = 'ZUONR'. wa_fcat-seltext_l = 'Inv Assign. No'. "wa_fcat-outputlen = '12'. wa_fcat-no_out = 'X'.

append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '10'. wa_fcat-fieldname = 'SGTXT'. wa_fcat-seltext_l = 'Inv Text'. wa_fcat-no_out = 'X'. "wa_fcat-outputlen = '12'. append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '10'. wa_fcat-fieldname = 'BLANK'. wa_fcat-seltext_l = ''. "wa_fcat-NO_out = 'X'. "wa_fcat-outputlen = '12'. wa_fcat-emphasize = 'C501'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '11'. wa_fcat-fieldname = 'RBLART'. wa_fcat-seltext_l = 'Doc.Type'. "wa_fcat-emphasize = 'C510'. wa_fcat-outputlen = '3'.  append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '12'. wa_fcat-fieldname = 'RBELNR'. wa_fcat-seltext_l = 'Receipt No'. "wa_fcat-emphasize = 'C510'. wa_fcat-outputlen = '12'.  append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '13'. wa_fcat-fieldname = 'RBUDAT'. wa_fcat-seltext_l = 'Posting Dt.'. wa_fcat-outputlen = '10'. "wa_fcat-emphasize = 'C510'. append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '14'. wa_fcat-fieldname = 'RDMBTR'. wa_fcat-seltext_l = 'Receipt Amt.(KWD)'. wa_fcat-outputlen = '12'. "wa_fcat-emphasize = 'C510'. "wa_fcat-DO_SUM = 'X'. wa_fcat-currency = 'KWD'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '15'. wa_fcat-fieldname = 'SETTLED'. wa_fcat-seltext_l = 'Settled Amt.(KWD)'. wa_fcat-outputlen = '12'. "wa_fcat-emphasize = 'C510'. "wa_fcat-DO_SUM = 'X'. wa_fcat-currency = 'KWD'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '16'. wa_fcat-fieldname = 'RBSCHL'. wa_fcat-seltext_l = 'PK'. "wa_fcat-emphasize = 'C410'. wa_fcat-outputlen = '20'.  "wa_fcat-emphasize = 'C510'. """"""""""""""""""""""""""""" wa_fcat-no_out = 'X'.  append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '17'. wa_fcat-fieldname = 'RLTEXT'. wa_fcat-seltext_l = 'Posting Key'. wa_fcat-outputlen = '20'. "wa_fcat-emphasize = 'C510'. append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '18'. wa_fcat-fieldname = 'RZUONR'. wa_fcat-seltext_l = 'Recpt Assign. No'. wa_fcat-outputlen = '12'. wa_fcat-no_out = 'X'. append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '19'. wa_fcat-fieldname = 'RSGTXT'. wa_fcat-seltext_l = 'Recpt Text'. "wa_fcat-outputlen = '12'. wa_fcat-no_out = 'X'.  append wa_fcat to it_fcat.  clear wa_fcat.

wa_fcat-col_pos = '20'. wa_fcat-fieldname = 'BALANCE'. wa_fcat-seltext_l = 'Outstanding'. wa_fcat-currency = 'KWD'. "wa_fcat-do_sum = 'X'. "wa_fcat-outputlen = '12'. "wa_fcat-NO_out = 'X'. " append wa_fcat to it_fcat. clear wa_fcat.

wa_fcat-col_pos = '21'. wa_fcat-fieldname = 'DATE_DIFF'. wa_fcat-seltext_l = 'Days'. "wa_fcat-outputlen = '12'. "wa_fcat-no_out = 'X'. append wa_fcat to it_fcat. clear wa_fcat.

wa_layout-colwidth_optimize = 'X'. wa_layout-info_fieldname = 'COLOR'.
 * x_sort-spos = 1.                          " Sort order
 * x_sort-fieldname = 'AUGDT'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-down = 'X'.
 * append x_sort to it_sort.
 * clear x_sort.
 * x_sort-spos = 2.                          " Sort order
 * x_sort-fieldname = 'AUGBL'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-up = 'X'.
 * x_sort-group = 'UL'.
 * append x_sort to it_sort.
 * clear x_sort.
 * x_sort-spos = 3.                          " Sort order
 * x_sort-fieldname = 'RBELNR'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-up = 'X'.
 * append x_sort to it_sort.
 * clear x_sort.
 * x_sort-spos = 4.                          " Sort order
 * x_sort-fieldname = 'RBUDAT'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-down = 'X'.
 * append x_sort to it_sort.
 * clear x_sort.
 * x_sort-fieldname = 'RBUDAT'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-down = 'X'.
 * append x_sort to it_sort.
 * clear x_sort.


 * x_sort-spos = 1.                          " Sort order
 * x_sort-fieldname = 'AUGDT'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-down = 'X'.
 * append x_sort to it_sort.
 * clear x_sort.
 * x_sort-spos = 2.                          " Sort order
 * x_sort-fieldname = 'AUGBL'.
 * x_sort-tabname = 'IT_final'.
 * x_sort-up = 'X'.
 * x_sort-group = 'UL'.
 * append x_sort to it_sort.
 * clear x_sort.
 * append x_sort to it_sort.
 * clear x_sort.

x_sort-spos = 1. " Sort order x_sort-fieldname = 'RBELNR'. x_sort-tabname = 'IT_final'. x_sort-down = 'X'. "x_sort-group = 'UL'. append x_sort to it_sort. clear x_sort.

x_sort-spos = 2. " Sort order x_sort-fieldname = 'RBUDAT'. x_sort-tabname = 'IT_final'. x_sort-down = 'X'. append x_sort to it_sort. clear x_sort.

x_sort-spos = 2. " Sort order x_sort-fieldname = 'RBLART'. x_sort-tabname = 'IT_final'. x_sort-down = 'X'. append x_sort to it_sort. clear x_sort.

call function 'REUSE_ALV_LIST_DISPLAY' exporting is_layout                     = wa_layout it_fieldcat                   = it_fcat it_sort                       = it_sort tables t_outtab                      = it_final. if sy-subrc <> 0. endif.
 * IT_EXCLUDING                  =
 * IT_SPECIAL_GROUPS             =
 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.