Register Login

Customer and Vendor Ageing Report

Updated Jun 28, 2019

How to enquire customer and vendor ageing report?

Ans: You may use ME2L and select PLANT and in selection parameters select WE101 for open orders by leaving vendor account blank.

What are the tables to be used to create a Vendor Ageing report?

Ans: Tables: lfa1.

Conditions to be checked for Vendor Ageing Report (Sample Code)

*&---------------------------------------------------------------------*
*& Report ZVEN_OUTS_AGE
*&
*&---------------------------------------------------------------------*
REPORT ZVEN_OUTS_AGE.

TABLES: BSEG, FAGLFLEXA, LFA1, BKPF.
TYPE-POOLS: SLIS.

DATA: V_SYTABIX TYPE SY-TABIX VALUE 0.

DATA: BEGIN OF it_bsik OCCURS 0,
bukrs TYPE bukrs, " COMPANY CODE 
lifnr TYPE lifnr, " vendor
gjahr TYPE gjahr, " Fiscal Year
belnr TYPE belnr_d, " DOCUMENT NO.
buzei TYPE buzei, " LINE ITEM NO.
END OF it_bsik.

DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV
WITH HEADER LINE,
GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID LIKE SY-REPID,
LC_GLAY TYPE LVC_S_GLAY.

CONSTANTS:
C_GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
C_H TYPE SLIS_LISTHEADER VALUE 'H',
C_S TYPE SLIS_LISTHEADER VALUE 'S',
C_GC_FORMNAME_UCOMM TYPE SLIS_FORMNAME VALUE 'USER_COMMAND',
C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'USER_COMMAND'.

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT,

IT_TCAT TYPE SLIS_T_FIELDCAT_ALV,

IT_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_SORT LIKE LINE OF IT_SORT,

WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

IT_GROUP TYPE SLIS_T_SP_GROUP_ALV,
WA_GROUP LIKE LINE OF IT_GROUP,

T_EVENT TYPE SLIS_T_EVENT,

IT_EXCLUDE TYPE SLIS_T_EXTAB, 
WA_EXCLUDE LIKE LINE OF IT_EXCLUDE,

WA_TITLE TYPE LVC_TITLE,

WA_VARIANT TYPE DISVARIANT,
WS_LS_EVENT TYPE SLIS_ALV_EVENT,

WS_LS_LINE TYPE SLIS_LISTHEADER,

W_GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
W_GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA : L_GJAHR LIKE BSEG-GJAHR.
DATA : L_BUKRS LIKE BSEG-BUKRS.
DATA : L_BELNR LIKE BSEG-BELNR.
DATA : L_REBZG LIKE BSEG-REBZG.
DATA : L_WAERS LIKE BKPF-WAERS.
DATA : L_LOW_BUDAT(4) TYPE N. "LIKE BKPF-BUDAT.
DATA : L_LOW_BUDAT1 LIKE BKPF-BUDAT.
DATA : L_LOW_BUDAT2 LIKE BKPF-BUDAT.
DATA : L_LOW_BUDAT3(4) TYPE N."LIKE BKPF-BUDAT.
DATA : L_CREDIT LIKE BSEG-WRBTR.
DATA : L_TDS LIKE BSEG-WRBTR.
DATA : L_BILL LIKE BSEG-WRBTR.
DATA : L_PAID LIKE BSEG-WRBTR.
DATA : L_DOWN LIKE BSEG-WRBTR.
DATA : L_TPAID LIKE BSEG-WRBTR.
DATA : L_NETDUE LIKE BSEG-WRBTR.
DATA : L_DD(2) TYPE C VALUE '01'.
DATA : L_MM(2) TYPE C VALUE '04',
NO_OF_DAYS2 TYPE I.
TYPES : BEGIN OF IT_BSEG,
BUKRS LIKE BSEG-BUKRS,
BELNR LIKE BSEG-BELNR,
BUZEI LIKE BSEG-BUZEI,
GJAHR LIKE BSEG-GJAHR,
LIFNR LIKE BSEG-LIFNR,
KTOSL LIKE BSEG-KTOSL,
ZBD1T LIKE BSEG-ZBD1T, " Cash discount days first
ZBD2T LIKE BSEG-ZBD2T, " Cash discount days second
* XAUTO LIKE BSEG-XAUTO, 
REBZG LIKE BSEG-REBZG,
UMSKS LIKE BSEG-UMSKS,
KOART LIKE BSEG-KOART,
AUGBL LIKE BSEG-AUGBL,
BSCHL LIKE BSEG-BSCHL,
UMSKZ LIKE BSEG-UMSKZ,
SHKZG LIKE BSEG-SHKZG,
WRBTR LIKE BSEG-WRBTR,
ZFBDT LIKE BSEG-ZFBDT,
DMBTR LIKE BSEG-DMBTR,
BLDAT LIKE BKPF-BLDAT,
BUDAT LIKE BKPF-BUDAT,
XBLNR LIKE BKPF-XBLNR,
WAERS LIKE BKPF-WAERS,
PRCTR LIKE FAGLFLEXA-PRCTR,
END OF IT_BSEG.

TYPES : BEGIN OF IT_LFA1,
LIFNR LIKE LFA1-LIFNR, 
NAME1 LIKE LFA1-NAME1,
END OF IT_LFA1.

TYPES : BEGIN OF IT_LFB1,
LIFNR LIKE LFB1-LIFNR,
BUKRS LIKE LFB1-BUKRS,
AKONT LIKE LFB1-AKONT,
END OF IT_LFB1.

TYPES : BEGIN OF IT_BKPF,
BUKRS LIKE BKPF-BUKRS, 
BELNR LIKE BKPF-BELNR,
GJAHR LIKE BKPF-GJAHR,
BLDAT LIKE BKPF-BLDAT,
BUDAT LIKE BKPF-BUDAT,
XBLNR LIKE BKPF-XBLNR,
WAERS LIKE BKPF-WAERS,
HWAER LIKE BKPF-HWAER,
END OF IT_BKPF.

TYPES : BEGIN OF IT_FAGLFLEXA,
RBUKRS LIKE FAGLFLEXA-RBUKRS, 
DOCNR LIKE FAGLFLEXA-DOCNR,
BUZEI LIKE FAGLFLEXA-BUZEI,
RYEAR LIKE FAGLFLEXA-RYEAR,
PRCTR LIKE FAGLFLEXA-PRCTR,
END OF IT_FAGLFLEXA.

TYPES : BEGIN OF IT_FINAL, 
BUKRS LIKE BSEG-BUKRS,
BELNR LIKE BSEG-BELNR,
BUZEI LIKE BSEG-BUZEI,
GJAHR LIKE BSEG-GJAHR,
LIFNR LIKE BSEG-LIFNR,
REBZG LIKE BSEG-REBZG,
KOART LIKE BSEG-KOART,
PRCTR LIKE FAGLFLEXA-PRCTR,
ZBD1T LIKE BSEG-ZBD1T, " Cash discount days first
ZBD2T LIKE BSEG-ZBD2T, " Cash discount days second
ZFBDT LIKE BSEG-ZFBDT,
CREDIT LIKE BSEG-WRBTR,
TDS LIKE BSEG-WRBTR,
PAID LIKE BSEG-WRBTR,
DOWNP LIKE BSEG-WRBTR,
BILL LIKE BSEG-WRBTR,
TPAID LIKE BSEG-WRBTR,
CR10 LIKE BSEG-WRBTR,
CR11 LIKE BSEG-WRBTR,
CR12 LIKE BSEG-WRBTR,
CR13 LIKE BSEG-WRBTR,
CR14 LIKE BSEG-WRBTR,
CR15 LIKE BSEG-WRBTR,
CR16 LIKE BSEG-WRBTR,
CR17 LIKE BSEG-WRBTR,
NETDUE LIKE BSEG-WRBTR,
BLDAT LIKE BKPF-BLDAT,
BUDAT LIKE BKPF-BUDAT,
XBLNR LIKE BKPF-XBLNR,
WAERS LIKE BKPF-WAERS,
NAME1 LIKE LFA1-NAME1,
HWAER LIKE BKPF-HWAER, 
UMSKZ LIKE BSEG-UMSKZ,
END OF IT_FINAL.

DATA : WA_C_T_DATA LIKE DTFIGL_4.
DATA : WA_BSEG TYPE IT_BSEG,
WA_BSEG1 TYPE IT_BSEG,
WA_BSEG2 TYPE IT_BSEG,
WA_BSEG3 TYPE IT_BSEG,
WA_BSEG4 TYPE IT_BSEG,
WA_FAGLFLEXA TYPE IT_FAGLFLEXA,
WA_FAGLFLEXA1 TYPE IT_FAGLFLEXA,
WA_FAGLFLEXA2 TYPE IT_FAGLFLEXA,
WA_FINAL TYPE IT_FINAL,
WA_FINAL1 TYPE IT_FINAL,
WA_I_FINAL1 TYPE IT_FINAL,
WA_FINAL2 TYPE IT_FINAL,
WA_BKPF TYPE IT_BKPF,
WA_LFA1 TYPE IT_LFA1, 
WA_LFB1 TYPE IT_LFB1,
D7(8) TYPE C .

DATA: I_BSEG TYPE STANDARD TABLE OF IT_BSEG INITIAL SIZE 0,
I_BSEG1 TYPE STANDARD TABLE OF IT_BSEG INITIAL SIZE 0,
I_BSEG2 TYPE STANDARD TABLE OF IT_BSEG INITIAL SIZE 0,
I_BSEG3 TYPE STANDARD TABLE OF IT_BSEG INITIAL SIZE 0,
I_BSEG4 TYPE STANDARD TABLE OF IT_BSEG INITIAL SIZE 0,
I_FAGLFLEXA TYPE STANDARD TABLE OF IT_FAGLFLEXA INITIAL SIZE 0,
I_FAGLFLEXA1 TYPE STANDARD TABLE OF IT_FAGLFLEXA INITIAL SIZE 0,
I_FAGLFLEXA2 TYPE STANDARD TABLE OF IT_FAGLFLEXA INITIAL SIZE 0, 
I_FINAL TYPE STANDARD TABLE OF IT_FINAL INITIAL SIZE 0,
I_FINAL1 TYPE STANDARD TABLE OF IT_FINAL INITIAL SIZE 0,
I_FINAL2 TYPE STANDARD TABLE OF IT_FINAL INITIAL SIZE 0,
I_BKPF TYPE STANDARD TABLE OF IT_BKPF INITIAL SIZE 0,
I_LFA1 TYPE STANDARD TABLE OF IT_LFA1 INITIAL SIZE 0,
I_LFB1 TYPE STANDARD TABLE OF IT_LFB1 INITIAL SIZE 0.

*******************DECLARATION *************************** 
DATA: DT1(5) TYPE N,
DT2(5) TYPE N,
DT3( 5) TYPE N,
DT4(5) TYPE N,
DT5(5) TYPE N,
DT6( 5) TYPE N,
DT7(8) TYPE C.
CONSTANTS GTN TYPE C VALUE '>'.
****************************************************************************************** 
*** INPUT PARAMETERS
******************************************************************************************

SELECTION- SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS:P_BUKRS LIKE BSEG-BUKRS OBLIGATORY. " Company Code
PARAMETERS:P_BUDAT LIKE BKPF-BUDAT OBLIGATORY. " Posting date
PARAMETERS:P_AKONT LIKE LFB1-AKONT . " Reconciliation Account in General Ledger

SELECT-OPTIONS:S_LIFNR FOR BSEG-LIFNR. " Vendor 
SELECT-OPTIONS:S_PRCTR FOR FAGLFLEXA-PRCTR OBLIGATORY. " Profit Center
SELECTION-SCREEN END OF BLOCK BLK1.

SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-002.
PARAMETERS:R_ZFBDT RADIOBUTTON GROUP GP1 DEFAULT 'X'. " Bill Date (Base line date)
PARAMETERS :R_BLDAT RADIOBUTTON GROUP GP1 . " Due Date
SELECTION-SCREEN END OF BLOCK BLK2.

SELECTION-SCREEN BEGIN OF BLOCK BLK4 WITH FRAME TITLE TEXT-005.
PARAMETERS:R_WRBTR RADIOBUTTON GROUP GP2 DEFAULT 'X'. " Doc. Curr. Amount
PARAMETERS :R_DMBTR RADIOBUTTON GROUP GP2 . " Local Curr. Amount
SELECTION-SCREEN END OF BLOCK BLK4.

SELECTION-SCREEN BEGIN OF BLOCK BLK3 WITH FRAME TITLE TEXT-003.
PARAMETERS: D1( 5) TYPE N OBLIGATORY,
D2(5) TYPE N ,
D3(5) TYPE N , 
D4(5) TYPE N ,
D5(5) TYPE N ,
D6(5) TYPE N ." D7(3) TYPE N .
SELECTION-SCREEN END OF BLOCK BLK3. 

*INITIALIZATION.
* d7 = d6.
* CONCATENATE
* INTO result SEPARATED BY space.
*START-OF-SELECTION.
* L_LOW_BUDAT2 = SY-DATUM+4(2).
* IF ( L_LOW_BUDAT2 = '01' OR L_LOW_BUDAT2 = '02' OR L_LOW_BUDAT2 = '03' ). 
* L_LOW_BUDAT3 = SY-DATUM+0(4).
* COMPUTE L_LOW_BUDAT = L_LOW_BUDAT3 - 1.
* ELSE.
* L_LOW_BUDAT = SY-DATUM+0(4). 
* ENDIF.
* CONCATENATE L_LOW_BUDAT L_MM L_DD INTO L_LOW_BUDAT1.
* I_BUDAT-SIGN = 'I'.
* I_BUDAT-OPTION = 'EQ'. 
* I_BUDAT-LOW = L_LOW_BUDAT1.
** I_BUDAT-HIGH = 'LH'.
* APPEND I_BUDAT TO I_BUDAT.
*AT SELECTION-SCREEN. 
SHIFT D1 LEFT DELETING LEADING '0'.
SHIFT D2 LEFT DELETING LEADING '0'.
SHIFT D3 LEFT DELETING LEADING '0'.
SHIFT D4 LEFT DELETING LEADING '0'.
SHIFT D5 LEFT DELETING LEADING '0'.
SHIFT D6 LEFT DELETING LEADING '0'.
SHIFT DT1 LEFT DELETING LEADING '0'.
SHIFT DT2 LEFT DELETING LEADING '0'.
SHIFT DT3 LEFT DELETING LEADING '0'.
SHIFT DT4 LEFT DELETING LEADING '0'.
SHIFT DT5 LEFT DELETING LEADING '0'.
SHIFT DT6 LEFT DELETING LEADING '0'.

AT SELECTION-SCREEN.

IF D6 NE SPACE.
IF D1 > D6 OR D2 > D6 OR D3 > D6 OR D4 > D6 OR D5 > D6.
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ENDIF.
IF D5 NE SPACE.
IF D1 > D5 OR D2 > D5 OR D3 > D5 OR D4 > D5. 
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ELSEIF D5 EQ SPACE.
IF D5 < D6.
MESSAGE TEXT- 004 TYPE 'E'.
ENDIF.
ENDIF.
IF D4 NE SPACE.
IF D1 > D4 OR D2 > D4 OR D3 > D4.
MESSAGE TEXT -004 TYPE 'E'.
ENDIF.
ELSEIF D4 EQ SPACE. 
IF D4 < D6 OR D4 < D5.
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ENDIF.
IF D3 NE SPACE.
IF D1 > D3 OR D2 > D3.
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ELSEIF D3 EQ SPACE.
IF D3 < D6 OR D3 < D5 OR D3 < D4.
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ENDIF.
IF D2 NE SPACE.
IF D1 > D2 .
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ELSEIF D2 EQ SPACE.
IF D2 < D6 OR D2 < D5 OR D2 < D4 OR D2 < D3.
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.
ENDIF.
* ELSEIF D6 EQ SPACE.
* CHECK D7 = SPACE .
* MESSAGE TEXT-004 TYPE 'E'.
* ENDIF.
* IF D5 NE SPACE.
* CHECK D1 > D5 OR D2 > D5 OR D3 > D5 OR D4 > D5.
* MESSAGE TEXT-004 TYPE 'E'. 
* ELSEIF D5 EQ SPACE.
* CHECK D6 = SPACE .
* MESSAGE TEXT-004 TYPE 'E'.
* ENDIF. 
* IF D4 NE SPACE.
* CHECK D1 > D4 OR D2 > D4 OR D3 > D4.
* MESSAGE TEXT-004 TYPE 'E'.
* ELSEIF D4 EQ SPACE.
* CHECK D5 = SPACE AND D6 = SPACE.
* MESSAGE TEXT-004 TYPE 'E'.
* ENDIF.
*
* IF D3 NE SPACE.
* CHECK D1 > D3 OR D2 > D3.
* MESSAGE TEXT-004 TYPE 'E'.
* ELSEIF D3 EQ SPACE. 
* CHECK D4 = SPACE AND D5 = SPACE AND D6 = SPACE.
* MESSAGE TEXT-004 TYPE 'E'.
* ENDIF.
*
* IF D2 NE SPACE.
* CHECK D1 > D2 .
* MESSAGE TEXT-004 TYPE 'E'.
* ELSEIF D2 EQ SPACE. 
* CHECK D3 = SPACE AND D4 = SPACE AND D5 = SPACE AND D6 = SPACE .
* MESSAGE TEXT-004 TYPE 'E'.
* ENDIF.

START-OF-SELECTION.

DT1 = D1 + 1.
IF D2 NE SPACE. DT2 = D2 + 1. ENDIF.
IF D3 NE SPACE. DT3 = D3 + 1. ENDIF.
IF D4 NE SPACE. DT4 = D4 + 1. ENDIF.
IF D5 NE SPACE. DT5 = D5 + 1. ENDIF.
IF D6 NE SPACE. DT6 = D6 + 1. ENDIF.
SELECT BUKRS LIFNR AKONT FROM LFB1 INTO TABLE I_LFB1 WHERE AKONT = P_AKONT AND BUKRS = P_BUKRS AND LIFNR IN S_LIFNR.
IF NOT I_LFB1 IS INITIAL.

SELECT BUKRS BELNR BUZEI GJAHR LIFNR KTOSL XAUTO REBZG UMSKS KOART AUGBL BSCHL UMSKZ SHKZG WRBTR ZFBDT DMBTR ZBD1T ZBD2T
FROM BSEG INTO CORRESPONDING FIELDS OF TABLE I_BSEG FOR ALL ENTRIES IN I_LFB1 WHERE BUKRS EQ P_BUKRS AND
LIFNR = I_LFB1-LIFNR AND
( AUGDT GE P_BUDAT OR AUGBL = SPACE ) AND KOART = 'K'
AND ( BSCHL = '21' OR BSCHL = '22' OR BSCHL = '23' OR BSCHL = '24' OR BSCHL = '25' OR BSCHL = '26' OR BSCHL = '27' OR
BSCHL = '28' OR BSCHL = '29' OR BSCHL = '30' OR BSCHL = '31' OR BSCHL = '32' OR BSCHL = '33' OR BSCHL = '34' OR
BSCHL = '35' OR BSCHL = '36' OR BSCHL = '37' OR BSCHL = '38' OR BSCHL = '39' OR BSCHL = '50' ).
IF SY-SUBRC NE 0.
MESSAGE 'There is no data available for the given selection criteria, Please check it' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
IF I_LFB1 IS INITIAL.
SELECT BUKRS BELNR BUZEI GJAHR LIFNR KTOSL XAUTO REBZG UMSKS KOART AUGBL BSCHL UMSKZ SHKZG WRBTR ZFBDT DMBTR ZBD1T ZBD2T 
FROM BSEG INTO CORRESPONDING FIELDS OF TABLE I_BSEG WHERE BUKRS EQ P_BUKRS AND
LIFNR IN S_LIFNR AND
( AUGDT GE P_BUDAT OR AUGBL = SPACE ) AND KOART = 'K'
AND ( BSCHL = '21' OR BSCHL = '22' OR BSCHL = '23' OR BSCHL = '24' OR BSCHL = '25' OR BSCHL = '26' OR BSCHL = '27' OR
BSCHL = '28' OR BSCHL = '29' OR BSCHL = '30' OR BSCHL = '31' OR BSCHL = '32' OR BSCHL = '33' OR BSCHL = '34' OR
BSCHL = '35' OR BSCHL = '36' OR BSCHL = '37' OR BSCHL = '38' OR BSCHL = '39' OR BSCHL = '50' ).
IF SY-SUBRC NE 0.
MESSAGE 'There is no data available for the given selection criteria, Please check it' 
TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.

SORT I_BSEG BY BELNR BUKRS GJAHR ASCENDING .
IF NOT I_BSEG IS INITIAL.
SELECT BUKRS BELNR GJAHR BLDAT BUDAT XBLNR WAERS HWAER FROM BKPF INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG WHERE BUKRS = I_BSEG-BUKRS AND
BELNR = I_BSEG-BELNR AND
GJAHR = I_BSEG-GJAHR AND
BUDAT LE P_BUDAT.
IF SY-SUBRC NE 0.
MESSAGE 'There is no data available for the given selection criteria, Please check it' 
TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT I_BKPF BY BUKRS GJAHR BELNR ASCENDING .

SELECT LIFNR NAME1 FROM LFA1 INTO TABLE I_LFA1
FOR ALL ENTRIES IN I_BSEG WHERE LIFNR = I_BSEG-LIFNR. 

SELECT BUKRS BELNR BUZEI GJAHR LIFNR KTOSL XAUTO REBZG UMSKS KOART AUGBL BSCHL UMSKZ SHKZG WRBTR DMBTR ZFBDT ZBD1T ZBD2T
FROM BSEG INTO CORRESPONDING FIELDS OF TABLE I_BSEG1
FOR ALL ENTRIES IN I_BSEG WHERE BUKRS = I_BSEG-BUKRS AND
GJAHR = I_BSEG-GJAHR AND
BELNR = I_BSEG-BELNR AND
KOART = 'S' AND ( AUGDT GE P_BUDAT OR AUGBL = SPACE ) AND
( BSCHL = '21' OR BSCHL = '22' OR BSCHL = '23' OR BSCHL = '24' OR BSCHL = '25' OR BSCHL = '26' OR BSCHL = '27' OR
BSCHL = '28' OR BSCHL = '29' OR BSCHL = '30' OR BSCHL = '31' OR BSCHL = '32' OR BSCHL = '33' OR BSCHL = '34' OR
BSCHL = '35' OR BSCHL = '36' OR BSCHL = '37' OR BSCHL = '38' OR BSCHL = '39' OR BSCHL = '50' ).
SORT I_BSEG1 BY BELNR BUKRS GJAHR ASCENDING .

SELECT RBUKRS DOCNR BUZEI RYEAR PRCTR FROM FAGLFLEXA INTO CORRESPONDING FIELDS OF TABLE I_FAGLFLEXA1
FOR ALL ENTRIES IN I_BSEG WHERE RBUKRS = I_BSEG-BUKRS AND 
RYEAR = I_BSEG-GJAHR AND
DOCNR = I_BSEG-BELNR AND
BUZEI = I_BSEG-BUZEI AND
PRCTR IN S_PRCTR.
IF SY-SUBRC NE 0.
MESSAGE 'There is no data available for the given selection criteria, Please check it'
TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
SORT I_FAGLFLEXA1 BY DOCNR RBUKRS RYEAR ASCENDING .
IF NOT I_BSEG1 IS INITIAL.
SELECT RBUKRS DOCNR BUZEI RYEAR PRCTR FROM FAGLFLEXA INTO CORRESPONDING FIELDS OF TABLE I_FAGLFLEXA2
FOR ALL ENTRIES IN I_BSEG1 WHERE RBUKRS = I_BSEG1-BUKRS AND
RYEAR = I_BSEG1-GJAHR AND
DOCNR = I_BSEG1-BELNR AND
BUZEI = I_BSEG1-BUZEI AND
PRCTR IN S_PRCTR.
SORT I_FAGLFLEXA2 BY DOCNR RBUKRS RYEAR ASCENDING .
ENDIF.

END-OF-SELECTION.
I_FAGLFLEXA[] = I_FAGLFLEXA1[].
LOOP AT I_FAGLFLEXA2 INTO WA_FAGLFLEXA2.
WA_FAGLFLEXA-RBUKRS = WA_FAGLFLEXA2-RBUKRS.
WA_FAGLFLEXA-RYEAR = WA_FAGLFLEXA2-RYEAR.
WA_FAGLFLEXA-DOCNR = WA_FAGLFLEXA2-DOCNR. 
WA_FAGLFLEXA-BUZEI = WA_FAGLFLEXA2-BUZEI.
WA_FAGLFLEXA-PRCTR = WA_FAGLFLEXA2-PRCTR.
APPEND WA_FAGLFLEXA TO I_FAGLFLEXA.
ENDLOOP.
CLEAR: WA_FAGLFLEXA, WA_FAGLFLEXA1.

I_BSEG4[] = I_BSEG[].
CLEAR: WA_BSEG, WA_BSEG1.
LOOP AT I_BSEG INTO WA_BSEG .
L_BELNR = WA_BSEG-BELNR.
L_BUKRS = WA_BSEG-BUKRS.
L_GJAHR = WA_BSEG-GJAHR.
LOOP AT I_BSEG1 INTO WA_BSEG1 WHERE BELNR = L_BELNR AND
BUKRS = L_BUKRS AND
GJAHR = L_GJAHR. .
WA_BSEG4-BUKRS = WA_BSEG1-BUKRS.
WA_BSEG4-BELNR = WA_BSEG1-BELNR.
WA_BSEG4-BUZEI = WA_BSEG1-BUZEI. 
WA_BSEG4-GJAHR = WA_BSEG1-GJAHR.
WA_BSEG4-LIFNR = WA_BSEG-LIFNR.
WA_BSEG4-KTOSL = WA_BSEG1-KTOSL.
WA_BSEG4-REBZG = WA_BSEG1-REBZG.
WA_BSEG4-UMSKS = WA_BSEG1-UMSKS.
WA_BSEG4-KOART = WA_BSEG1-KOART. 
WA_BSEG4-AUGBL = WA_BSEG1-AUGBL.
WA_BSEG4-BSCHL = WA_BSEG1-BSCHL.
WA_BSEG4-UMSKZ = WA_BSEG1-UMSKZ.
WA_BSEG4-SHKZG = WA_BSEG1-SHKZG.
WA_BSEG4-WRBTR = WA_BSEG1-WRBTR.
WA_BSEG4-ZFBDT = WA_BSEG1-ZFBDT. 
WA_BSEG4-DMBTR = WA_BSEG1-DMBTR.
APPEND WA_BSEG4 TO I_BSEG4.
ENDLOOP.
CLEAR: L_BELNR, L_BUKRS, L_GJAHR. 
CLEAR: WA_BSEG, WA_BSEG1, WA_BSEG4.
ENDLOOP.
SORT I_BSEG4 BY BUKRS GJAHR BELNR.

LOOP AT I_FAGLFLEXA INTO WA_FAGLFLEXA.
READ TABLE I_BSEG4 INTO WA_BSEG4 WITH KEY BUKRS = WA_FAGLFLEXA-RBUKRS
GJAHR = WA_FAGLFLEXA-RYEAR
BELNR = WA_FAGLFLEXA-DOCNR 
BUZEI = WA_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
WA_BSEG3-BUKRS = WA_BSEG4-BUKRS.
WA_BSEG3-BELNR = WA_BSEG4-BELNR. 
WA_BSEG3-BUZEI = WA_BSEG4-BUZEI.
WA_BSEG3-GJAHR = WA_BSEG4-GJAHR.
WA_BSEG3-LIFNR = WA_BSEG4-LIFNR.
WA_BSEG3-KTOSL = WA_BSEG4-KTOSL.
WA_BSEG3-REBZG = WA_BSEG4-REBZG.
WA_BSEG3-UMSKS = WA_BSEG4-UMSKS. 
WA_BSEG3-KOART = WA_BSEG4-KOART.
WA_BSEG3-AUGBL = WA_BSEG4-AUGBL.
WA_BSEG3-BSCHL = WA_BSEG4-BSCHL.
WA_BSEG3-ZBD1T = WA_BSEG4-ZBD1T.
WA_BSEG3-ZBD2T = WA_BSEG4-ZBD2T.
WA_BSEG3-UMSKZ = WA_BSEG4-UMSKZ. 
WA_BSEG3-SHKZG = WA_BSEG4-SHKZG.
WA_BSEG3-WRBTR = WA_BSEG4-WRBTR.
WA_BSEG3-ZFBDT = WA_BSEG4-ZFBDT.
WA_BSEG3-DMBTR = WA_BSEG4-DMBTR.
ELSE.
CONTINUE.
ENDIF.
WA_BSEG3-PRCTR = WA_FAGLFLEXA-PRCTR.
APPEND WA_BSEG3 TO I_BSEG3.
ENDLOOP .
CLEAR: WA_BSEG3, WA_BSEG2.

LOOP AT I_BKPF INTO WA_BKPF.
LOOP AT I_BSEG3 INTO WA_BSEG3 WHERE BUKRS = WA_BKPF-BUKRS AND
GJAHR = WA_BKPF-GJAHR AND
BELNR = WA_BKPF-BELNR.
* READ TABLE I_BSEG3 INTO WA_BSEG3 WITH KEY BUKRS = WA_BKPF-BUKRS
* GJAHR = WA_BKPF-GJAHR 
* BELNR = WA_BKPF-BELNR.
* IF SY-SUBRC = 0.
WA_BSEG2-BUKRS = WA_BSEG3-BUKRS.
WA_BSEG2-BELNR = WA_BSEG3-BELNR. 
WA_BSEG2-BUZEI = WA_BSEG3-BUZEI.
WA_BSEG2-GJAHR = WA_BSEG3-GJAHR.
WA_BSEG2-LIFNR = WA_BSEG3-LIFNR.
WA_BSEG2-KTOSL = WA_BSEG3-KTOSL.
WA_BSEG2-ZBD1T = WA_BSEG3-ZBD1T.
WA_BSEG2-ZBD2T = WA_BSEG3-ZBD2T. 
WA_BSEG2-UMSKZ = WA_BSEG3-UMSKZ.
WA_BSEG2-REBZG = WA_BSEG3-REBZG.
WA_BSEG2-UMSKS = WA_BSEG3-UMSKS.
WA_BSEG2-KOART = WA_BSEG3-KOART.
WA_BSEG2-AUGBL = WA_BSEG3-AUGBL.
WA_BSEG2-BSCHL = WA_BSEG3-BSCHL. 
WA_BSEG2-SHKZG = WA_BSEG3-SHKZG.
IF R_WRBTR = 'X'.
WA_BSEG2-WRBTR = WA_BSEG3-WRBTR.
WA_BSEG2-WAERS = WA_BKPF-WAERS.
ELSEIF R_DMBTR = 'X'.
WA_BSEG2-WRBTR = WA_BSEG3-DMBTR.
WA_BSEG2-WAERS = WA_BKPF-HWAER.
ENDIF.
WA_BSEG2-PRCTR = WA_BSEG3-PRCTR.
SHIFT WA_BSEG3-ZFBDT LEFT DELETING LEADING '0'.
IF WA_BSEG3-ZFBDT = SPACE.
WA_BSEG2-ZFBDT = WA_BKPF-BLDAT.
ELSE.
WA_BSEG2-ZFBDT = WA_BSEG3-ZFBDT.
ENDIF .
WA_BSEG2-BUDAT = WA_BKPF-BUDAT.
WA_BSEG2-XBLNR = WA_BKPF-XBLNR.
APPEND WA_BSEG2 TO I_BSEG2.
ENDLOOP.
CLEAR: WA_BSEG3, WA_BSEG2, WA_BKPF.
ENDLOOP.
* LOOP AT I_BSEG2 INTO WA_BSEG2.
* READ TABLE I_FAGLFLEXA INTO WA_FAGLFLEXA WITH KEY RBUKRS = WA_BSEG2-BUKRS 
* RYEAR = WA_BSEG2-GJAHR
* DOCNR = WA_BSEG2-BELNR 
* BUZEI = WA_BSEG2-BUZEI.
* IF SY-SUBRC = 0.
* WA_BSEG2-PRCTR = WA_FAGLFLEXA-PRCTR. 
* ELSE.
* DELETE WA_BSEG2 FROM I_BSEG2 INDEX SY-TABIX.
* ENDIF.
* READ TABLE I_BKPF INTO WA_BKPF WITH KEY BELNR = WA_BSEG2-BELNR 
* BUKRS = WA_BSEG2-BUKRS
* GJAHR = WA_BSEG2-GJAHR.
* IF SY-SUBRC = 0.
* WA_BSEG2-BLDAT = WA_BKPF-BLDAT.
* WA_BSEG2-BUDAT = WA_BKPF-BUDAT.
* WA_BSEG2-XBLNR = WA_BKPF-XBLNR. 
* WA_BSEG2-WAERS = WA_BKPF-WAERS.
* ELSE.
* DELETE I_BSEG2 INDEX SY-TABIX.
* ENDIF. 
* APPEND WA_BSEG2 TO I_BSEG2.
* ENDLOOP.
* CLEAR: WA_BSEG, WA_BSEG1, WA_BSEG2.


***** NO_OF_DAYS2 = 0. 
***** NO_OF_DAYS2 = P_BUDAT - WA_BSEG2-BLDAT.
*****
***** IF WA_BSEG2-SHKZG = 'H' AND WA_BSEG2-BSCHL NE '50' AND WA_BSEG2-UMSKS NE 'A'. 
*****
***** IF NO_OF_DAYS2 < DT1.
***** WA_FINAL-CR11 = WA_BSEG2-WRBTR.
***** ENDIF. 
*****
***** IF DT2 NE SPACE AND NO_OF_DAYS2 < DT2 AND NO_OF_DAYS2 ge DT1.
***** WA_FINAL-CR12 = WA_BSEG2-WRBTR. 
***** ELSEIF DT2 EQ SPACE AND DT3 EQ SPACE AND DT1 NE SPACE AND NO_OF_DAYS2 GE DT1.
***** WA_FINAL-CR12 = WA_BSEG2-WRBTR.
***** ENDIF. 
*****
***** IF DT3 NE SPACE AND NO_OF_DAYS2 < DT3 AND NO_OF_DAYS2 ge DT2.
***** WA_FINAL-CR13 = WA_BSEG2-WRBTR. 
***** ELSEIF DT3 EQ SPACE AND DT4 EQ SPACE AND DT2 NE SPACE AND NO_OF_DAYS2 GE DT2.
***** WA_FINAL-CR13 = WA_BSEG2-WRBTR.
***** ENDIF. 
*****
***** IF DT4 NE SPACE AND NO_OF_DAYS2 < DT4 AND NO_OF_DAYS2 ge DT3.
***** WA_FINAL-CR14 = WA_BSEG2-WRBTR. 
***** ELSEIF DT4 EQ SPACE AND DT5 EQ SPACE AND DT3 NE SPACE AND NO_OF_DAYS2 GE DT3.
***** WA_FINAL-CR14 = WA_BSEG2-WRBTR.
***** ENDIF. 
*****
***** IF DT5 NE SPACE AND NO_OF_DAYS2 < DT5 AND NO_OF_DAYS2 ge DT4.
***** WA_FINAL-CR15 = WA_BSEG2-WRBTR. 
***** ELSEIF DT5 EQ SPACE AND DT6 EQ SPACE AND DT4 NE SPACE AND NO_OF_DAYS2 GE DT4.
***** WA_FINAL-CR15 = WA_BSEG2-WRBTR.
***** ENDIF. 
*****
***** IF DT6 NE SPACE AND NO_OF_DAYS2 < DT6 AND NO_OF_DAYS2 ge DT5.
***** WA_FINAL-CR16 = WA_BSEG2-WRBTR. 
***** ELSEIF DT6 EQ SPACE AND DT7 EQ SPACE AND DT5 NE SPACE AND NO_OF_DAYS2 GE DT5.
***** WA_FINAL-CR16 = WA_BSEG2-WRBTR.
***** ENDIF. 
*****
***** IF DT6 NE SPACE AND NO_OF_DAYS2 GE DT6.
***** WA_FINAL-CR17 = WA_BSEG2-WRBTR.
***** ENDIF.

*IF DT2 NE SPACE AND no_of_days2 > dt2 AND DT3 EQ SPACE.
* WA_FINAL-cr13 = wa_bseg2-wrbtr. ENDIF.
** IF DT3 NE SPACE AND no_of_days2 < dt3 AND no_of_days2 > DT2. 
** WA_FINAL-cr13 = wa_bseg2-wrbtr.
**ELSEIF DT3 NE SPACE AND no_of_days2 > dt3 AND DT4 EQ SPACE.
** WA_FINAL-cr14 = wa_bseg2-wrbtr. ENDIF. 
**
** IF DT4 NE SPACE AND no_of_days2 < dt4 AND no_of_days2 > DT3.
** WA_FINAL-cr14 = wa_bseg2-wrbtr.
**ELSEIF DT4 NE SPACE AND no_of_days2 > dt4 AND DT5 EQ SPACE.
** WA_FINAL-cr15 = wa_bseg2-wrbtr. ENDIF.
**
** IF DT5 NE SPACE AND no_of_days2 < dt5 AND no_of_days2 > DT4. 
** WA_FINAL-cr15 = wa_bseg2-wrbtr.
**ELSEIF DT5 NE SPACE AND no_of_days2 > dt5 AND DT6 EQ SPACE.
** WA_FINAL-cr16 = wa_bseg2-wrbtr. ENDIF. 
** IF DT6 NE SPACE AND no_of_days2 < dt6 AND no_of_days2 > DT5.
** WA_FINAL-cr16 = wa_bseg2-wrbtr.
** ELSEIF DT6 NE SPACE AND no_of_days2 > dt6. 
** WA_FINAL-cr17 = wa_bseg2-wrbtr. ENDIF.
* ELSE.
* WA_FINAL-cr16 = wa_bseg2-wrbtr.ENDIF.
* ELSE.
* WA_FINAL-cr15 = wa_bseg2-wrbtr.ENDIF.
* ELSE.
* WA_FINAL-cr14 = wa_bseg2-wrbtr.ENDIF.
*ELSE.
* WA_FINAL-cr13 = wa_bseg2-wrbtr. ENDIF.
*ELSE.
* WA_FINAL-cr12 = wa_bseg2-wrbtr. ENDIF.
* ELSE.
* WA_FINAL-cr12 = wa_bseg2-wrbtr. ENDIF.

* IF no_of_days2 < dt1.
* WA_FINAL-cr11 = wa_bseg2-wrbtr. 
* ELSEIF no_of_days2 < dt2 AND no_of_days2 > DT1.
* WA_FINAL-cr12 = wa_bseg2-wrbtr.
* ELSEIF no_of_days2 < dt3 AND no_of_days2 > DT2. 
* WA_FINAL-cr13 = wa_bseg2-wrbtr.
* ELSEIF no_of_days2 < dt4 AND no_of_days2 > DT3.
* WA_FINAL-cr14 = wa_bseg2-wrbtr. 
* ELSEIF no_of_days2 < dt5 AND no_of_days2 > DT4.
* WA_FINAL-cr15 = wa_bseg2-wrbtr.
* ELSEIF no_of_days2 < dt6 AND no_of_days2 > DT5. 
* WA_FINAL-cr16 = wa_bseg2-wrbtr.
* ELSEIF no_of_days2 ge dt6 .
* WA_FINAL-cr17 = wa_bseg2-wrbtr.
* ENDIF.
** ELSEIF WA_BSEG2-UMSKS = 'A' AND ( WA_BSEG2-SHKZG = 'S' OR WA_BSEG2-SHKZG = 'H' ).
** IF WA_BSEG2-SHKZG = 'H'. 
** WA_FINAL-DOWNP = WA_BSEG2-WRBTR * -1. " DOWN PAYMENT
** ELSE.
** WA_FINAL-DOWNP = WA_BSEG2-WRBTR. " DOWN PAYMENT 
** ENDIF.
** ELSEIF WA_BSEG2-UMSKS NE 'A' AND WA_BSEG2-SHKZG = 'S'.
** WA_FINAL-PAID = WA_BSEG2-WRBTR. " PAID AMOUNT 
** ELSE.
** CONTINUE.
** ENDIF.
LOOP AT I_BSEG2 INTO WA_BSEG2.
IF WA_BSEG2-SHKZG = 'H' AND WA_BSEG2-BSCHL NE '50' AND WA_BSEG2-UMSKS NE 'A'.
WA_FINAL-CREDIT = WA_BSEG2-WRBTR. "CREDIT BILL
* WA_FINAL-ZFBDT = WA_BSEG2-ZFBDT.
ELSEIF WA_BSEG2-UMSKS NE 'A' AND WA_BSEG2-SHKZG = 'H' AND WA_BSEG2-BSCHL EQ '50' AND WA_BSEG2-KTOSL = 'WIT' .
WA_FINAL-TDS = WA_BSEG2-WRBTR. " TDS AMOUNT
ELSEIF WA_BSEG2-UMSKS NE 'A' AND WA_BSEG2-SHKZG = 'S'.
WA_FINAL-PAID = WA_BSEG2-WRBTR. " PAID AMOUNT
ELSEIF WA_BSEG2-UMSKS = 'A' AND ( WA_BSEG2-SHKZG = 'S' OR WA_BSEG2-SHKZG = 'H' ).
IF WA_BSEG2-SHKZG = 'H'.
WA_FINAL-DOWNP = WA_BSEG2-WRBTR * -1. " DOWN PAYMENT
ELSE .
WA_FINAL-DOWNP = WA_BSEG2-WRBTR. " DOWN PAYMENT
ENDIF.
ELSE.
CONTINUE .
ENDIF.

WA_FINAL-ZFBDT = WA_BSEG2-ZFBDT.
WA_FINAL-UMSKZ = WA_BSEG2-UMSKZ.

WA_FINAL-BUKRS = WA_BSEG2-BUKRS.
WA_FINAL-GJAHR = WA_BSEG2-GJAHR.
WA_FINAL-LIFNR = WA_BSEG2-LIFNR.
WA_FINAL-BELNR = WA_BSEG2-BELNR.
WA_FINAL-BUZEI = WA_BSEG2-BUZEI.
WA_FINAL-BLDAT = WA_BSEG2-BLDAT.
WA_FINAL-BUDAT = WA_BSEG2-BUDAT.
WA_FINAL-ZBD1T = WA_BSEG2-ZBD1T. 
WA_FINAL-ZBD2T = WA_BSEG2-ZBD2T.
WA_FINAL-XBLNR = WA_BSEG2-XBLNR.
WA_FINAL-WAERS = WA_BSEG2-WAERS.
WA_FINAL-KOART = WA_BSEG2-KOART.
WA_FINAL-PRCTR = WA_BSEG2-PRCTR.
IF WA_BSEG2-REBZG = SPACE.
WA_FINAL-REBZG = WA_BSEG2-BELNR.
ELSE.
WA_FINAL-REBZG = WA_BSEG2-REBZG.
ENDIF.

* IF WA_BSEG2-REBZG = SPACE.
* WA_FINAL-REBZG = WA_BSEG2-BELNR.
* ELSE.
* WA_FINAL-REBZG = WA_BSEG2-REBZG.
* ENDIF.
* IF WA_BSEG2-SHKZG = 'H' AND WA_BSEG2-BSCHL NE '50' AND WA_BSEG2-UMSKs NE 'A'.
* WA_FINAL-CREDIT = WA_BSEG2-WRBTR. "CREDIT BILL 
*
* ELSEIF WA_BSEG2-UMSKs NE 'A' AND WA_BSEG2-SHKZG = 'H' AND WA_BSEG2-BSCHL EQ '50' AND WA_BSEG2-KTOSL = 'WIT'.
* WA_FINAL-TDS = WA_BSEG2-WRBTR. " TDS AMOUNT
*
* ELSEIF WA_BSEG2-UMSKs NE 'A' AND WA_BSEG2-SHKZG = 'S'.
* WA_FINAL-PAID = WA_BSEG2-WRBTR. " PAID AMOUNT

** WA_FINAL-BILL = WA_FINAL-CR11 + WA_FINAL-CR12 + WA_FINAL-CR13 + WA_FINAL-CR14 + WA_FINAL-CR15 + WA_FINAL-CR16 + WA_FINAL-CR17. 
* WA_FINAL-TPAID = WA_FINAL-PAID + WA_FINAL-TDS.
** WA_FINAL-NETDUE = WA_FINAL-BILL - WA_FINAL-DOWNP - WA_FINAL-PAID.
APPEND WA_FINAL TO I_FINAL.
CLEAR: WA_FINAL, WA_BSEG2, WA_BKPF, WA_FAGLFLEXA.
ENDLOOP.
SORT I_FINAL BY BUKRS GJAHR REBZG DESCENDING.
* I_FINAL2[] = I_FINAL[].
* DELETE I_FINAL2 WHERE KOART NE 'K'.
* DELETE ADJACENT DUPLICATES FROM I_FINAL2 COMPARING BUKRS GJAHR BELNR.
*
* LOOP AT I_FINAL2 INTO WA_FINAL2.
* L_BELNR = WA_FINAL2-BELNR.
* L_BUKRS = WA_FINAL2-BUKRS.
* L_GJAHR = WA_FINAL2-GJAHR.
* L_XBLNR = WA_FINAL2-XBLNR. 
* WA_FINAL1-BUKRS = WA_FINAL2-BUKRS.
* WA_FINAL1-GJAHR = WA_FINAL2-GJAHR.
* WA_FINAL1-LIFNR = WA_FINAL2-LIFNR.
* WA_FINAL1-BELNR = WA_FINAL2-BELNR.
* WA_FINAL1-BUZEI = WA_FINAL2-BUZEI.
* WA_FINAL1-REBZG = WA_FINAL2-REBZG.
* WA_FINAL1-BLDAT = WA_FINAL2-BLDAT. 
* WA_FINAL1-BUDAT = WA_FINAL2-BUDAT.
* WA_FINAL1-XBLNR = WA_FINAL2-XBLNR.
* WA_FINAL1-WAERS = WA_FINAL2-WAERS.
* WA_FINAL1-PRCTR = WA_FINAL2-PRCTR.
* LOOP AT I_FINAL INTO WA_FINAL WHERE BELNR = L_BELNR AND BUKRS = L_BUKRS AND GJAHR = L_GJAHR AND XBLNR = L_XBLNR.
* WA_FINAL1-CREDIT = WA_FINAL1-CREDIT + WA_FINAL-CREDIT.
* WA_FINAL1-TDS = WA_FINAL1-TDS + WA_FINAL-TDS.
* WA_FINAL1-PAID = WA_FINAL1-PAID + WA_FINAL-PAID. 
* WA_FINAL1-DOWNP = WA_FINAL1-DOWNP + WA_FINAL-DOWNP.
* WA_FINAL1-BILL = WA_FINAL1-BILL + WA_FINAL-BILL.
* WA_FINAL1-TPAID = WA_FINAL1-TPAID + WA_FINAL-TPAID. 
* WA_FINAL1-NETDUE = WA_FINAL1-NETDUE + WA_FINAL-NETDUE.
* ENDLOOP.
* CLEAR: L_XBLNR, L_BELNR, L_BUKRS, L_GJAHR. 
* READ TABLE I_BKPF INTO WA_BKPF WITH KEY BELNR = WA_FINAL2-BELNR
* BUKRS = WA_FINAL2-BUKRS
* GJAHR = WA_FINAL2-GJAHR. 
* IF SY-SUBRC = 0.
* WA_FINAL1-BLDAT = WA_BKPF-BLDAT.
* WA_FINAL1-BUDAT = WA_BKPF-BUDAT.
* WA_FINAL1-XBLNR = WA_BKPF-XBLNR.
* WA_FINAL1-WAERS = WA_BKPF-WAERS.
* ENDIF.
* READ TABLE I_FAGLFLEXA INTO WA_FAGLFLEXA WITH KEY RBUKRS = WA_FINAL2-BUKRS 
* RYEAR = WA_FINAL2-GJAHR
* DOCNR = WA_FINAL2-BELNR.
** BUZEI = WA_BSEG-BUZEI. 
* IF SY-SUBRC = 0.
* WA_FINAL1-PRCTR = WA_FAGLFLEXA-PRCTR.
* ENDIF.
I_FINAL2[] = I_FINAL[].
DELETE ADJACENT DUPLICATES FROM I_FINAL2 COMPARING BUKRS GJAHR REBZG WAERS.
LOOP AT I_FINAL2 INTO WA_FINAL2.
L_BELNR = WA_FINAL2-BELNR.
L_BUKRS = WA_FINAL2-BUKRS.
L_GJAHR = WA_FINAL2-GJAHR.
L_REBZG = WA_FINAL2-REBZG.
L_WAERS = WA_FINAL2-WAERS.
LOOP AT I_FINAL INTO WA_FINAL WHERE BUKRS = L_BUKRS AND GJAHR = L_GJAHR AND REBZG = L_REBZG AND WAERS = L_WAERS.
* WA_FINAL1-CR11 = WA_FINAL1-CR11 + WA_FINAL-CR11.
* WA_FINAL1-CR12 = WA_FINAL1-CR12 + WA_FINAL-CR12.
* WA_FINAL1-CR13 = WA_FINAL1-CR13 + WA_FINAL-CR13.
* WA_FINAL1-CR14 = WA_FINAL1-CR14 + WA_FINAL-CR14. 
* WA_FINAL1-CR15 = WA_FINAL1-CR15 + WA_FINAL-CR15.
* WA_FINAL1-CR16 = WA_FINAL1-CR16 + WA_FINAL-CR16.
* WA_FINAL1-CR17 = WA_FINAL1-CR17 + WA_FINAL-CR17. 
WA_FINAL1-DOWNP = WA_FINAL1-DOWNP + WA_FINAL-DOWNP.
* WA_FINAL1-BILL = WA_FINAL1-BILL + WA_FINAL-BILL.
* WA_FINAL1-NETDUE = WA_FINAL1-NETDUE + WA_FINAL-NETDUE. 
WA_FINAL1-CREDIT = WA_FINAL1-CREDIT + WA_FINAL-CREDIT.
WA_FINAL1-TDS = WA_FINAL1-TDS + WA_FINAL-TDS.
WA_FINAL1-PAID = WA_FINAL1-PAID + WA_FINAL-PAID.
* WA_FINAL1-TPAID = WA_FINAL1-TPAID + WA_FINAL-TPAID. 
ENDLOOP.
WA_FINAL1-BILL = WA_FINAL1-CREDIT + WA_FINAL1-TDS.
WA_FINAL1-TPAID = WA_FINAL1-BILL - WA_FINAL1-PAID - WA_FINAL1-TDS.
WA_FINAL1-NETDUE = WA_FINAL1-TPAID - WA_FINAL1-DOWNP. 

NO_OF_DAYS2 = 0.
NO_OF_DAYS2 = P_BUDAT - WA_FINAL2-ZFBDT.
IF R_BLDAT = 'X' AND WA_FINAL2-ZBD1T > WA_FINAL2-ZBD2T. 
NO_OF_DAYS2 = NO_OF_DAYS2 - WA_FINAL2-ZBD1T.
ELSEIF R_BLDAT = 'X' AND WA_FINAL2-ZBD1T < WA_FINAL2-ZBD2T.
NO_OF_DAYS2 = NO_OF_DAYS2 - WA_FINAL2-ZBD2T. 
ENDIF.

IF NO_OF_DAYS2 < '0'.
WA_FINAL1-CR10 = WA_FINAL1-TPAID.
ENDIF .

IF NO_OF_DAYS2 < DT1 AND NO_OF_DAYS2 > '0'.
WA_FINAL1-CR11 = WA_FINAL1-TPAID.
ENDIF.

IF DT2 NE SPACE AND NO_OF_DAYS2 < DT2 AND NO_OF_DAYS2 GE DT1. 
WA_FINAL1-CR12 = WA_FINAL1-TPAID.
ELSEIF DT2 EQ SPACE AND DT3 EQ SPACE AND DT1 NE SPACE AND NO_OF_DAYS2 GE DT1.
WA_FINAL1-CR12 = WA_FINAL1-TPAID.
ENDIF.

IF DT3 NE SPACE AND NO_OF_DAYS2 < DT3 AND NO_OF_DAYS2 GE DT2.
WA_FINAL1-CR13 = WA_FINAL1-TPAID. 
ELSEIF DT3 EQ SPACE AND DT4 EQ SPACE AND DT2 NE SPACE AND NO_OF_DAYS2 GE DT2.
WA_FINAL1-CR13 = WA_FINAL1-TPAID.
ENDIF.

IF DT4 NE SPACE AND NO_OF_DAYS2 < DT4 AND NO_OF_DAYS2 GE DT3.
WA_FINAL1-CR14 = WA_FINAL1-TPAID.
ELSEIF DT4 EQ SPACE AND DT5 EQ SPACE AND DT3 NE SPACE AND NO_OF_DAYS2 GE DT3.
WA_FINAL1-CR14 = WA_FINAL1-TPAID.
ENDIF.

IF DT5 NE SPACE AND NO_OF_DAYS2 < DT5 AND NO_OF_DAYS2 GE DT4.
WA_FINAL1-CR15 = WA_FINAL1-TPAID.
ELSEIF DT5 EQ SPACE AND DT6 EQ SPACE AND DT4 NE SPACE AND NO_OF_DAYS2 GE DT4.
WA_FINAL1-CR15 = WA_FINAL1-TPAID.
ENDIF.

IF DT6 NE SPACE AND NO_OF_DAYS2 < DT6 AND NO_OF_DAYS2 GE DT5.
WA_FINAL1-CR16 = WA_FINAL1-TPAID.
ELSEIF DT6 EQ SPACE AND DT7 EQ SPACE AND DT5 NE SPACE AND NO_OF_DAYS2 GE DT5.
WA_FINAL1-CR16 = WA_FINAL1-TPAID. 
ENDIF.

IF DT6 NE SPACE AND NO_OF_DAYS2 GE DT6.
WA_FINAL1-CR17 = WA_FINAL1-TPAID. 
ENDIF.

WA_FINAL1-BUKRS = WA_FINAL2-BUKRS.
WA_FINAL1-GJAHR = WA_FINAL2-GJAHR.
WA_FINAL1-LIFNR = WA_FINAL2-LIFNR.
WA_FINAL1-BELNR = WA_FINAL2-BELNR.
WA_FINAL1-BUZEI = WA_FINAL2-BUZEI. 
WA_FINAL1-REBZG = WA_FINAL2-REBZG.
WA_FINAL1-ZFBDT = WA_FINAL2-ZFBDT.
* WA_FINAL1-BLDAT = WA_FINAL2-BLDAT.

WA_FINAL1-UMSKZ = WA_FINAL2-UMSKZ.

WA_FINAL1-BUDAT = WA_FINAL2-BUDAT. 
WA_FINAL1-XBLNR = WA_FINAL2-XBLNR.
WA_FINAL1-WAERS = WA_FINAL2-WAERS.
WA_FINAL1-PRCTR = WA_FINAL2-PRCTR.
CLEAR: L_REBZG, L_BELNR, L_BUKRS, L_GJAHR.

READ TABLE I_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_FINAL-LIFNR.
IF SY-SUBRC = 0.
WA_FINAL1-NAME1 = WA_LFA1-NAME1.
ENDIF.
APPEND WA_FINAL1 TO I_FINAL1.
CLEAR: WA_FINAL, WA_FINAL1, WA_FINAL2.
ENDLOOP.

select bukrs lifnr gjahr belnr buzei
FROM bsik
INTO CORRESPONDING FIELDS OF TABLE it_bsik.

LOOP AT I_FINAL1 INTO WA_I_FINAL1.

V_SYTABIX = SY-TABIX.

READ TABLE IT_BSIK WITH KEY BUKRS = WA_I_FINAL1-BUKRS
LIFNR = WA_I_FINAL1-LIFNR
GJAHR = WA_I_FINAL1-GJAHR
BELNR = WA_I_FINAL1-BELNR
BUZEI = WA_I_FINAL1-BUZEI.
IF SY-SUBRC NE 0.
DELETE I_FINAL1[] INDEX V_SYTABIX.
ELSE.
READ TABLE I_BSEG4 INTO WA_BSEG4 WITH KEY BUKRS = WA_I_FINAL1-BUKRS
GJAHR = WA_I_FINAL1-GJAHR
BELNR = WA_I_FINAL1-BELNR
BUZEI = WA_I_FINAL1-BUZEI. 
IF SY-SUBRC = 0.
WA_I_FINAL1-UMSKZ = WA_BSEG4-UMSKZ.
MODIFY I_FINAL1 FROM WA_I_FINAL1 INDEX V_SYTABIX TRANSPORTING UMSKZ.
ENDIF.
ENDIF.

ENDLOOP.

SORT I_FINAL1 BY GJAHR LIFNR REBZG ASCENDING.

IF D6 = SPACE AND D5 = SPACE AND D4 = SPACE AND D3 = SPACE AND D2 = SPACE.
CONCATENATE GTN D1 INTO D2 SEPARATED BY SPACE.
ELSEIF D6 = SPACE AND D5 = SPACE AND D4 = SPACE AND D3 = SPACE AND D2 NE SPACE.
CONCATENATE GTN D2 INTO D3 SEPARATED BY SPACE.
* d7 = d7.
ELSEIF D6 = SPACE AND D5 = SPACE AND D4 = SPACE AND D3 NE SPACE AND D2 NE SPACE.
CONCATENATE GTN D3 INTO D4 SEPARATED BY SPACE.
* d7 = d7.
ELSEIF D6 = SPACE AND D5 = SPACE AND D4 NE SPACE AND D3 NE SPACE AND D2 NE SPACE.
CONCATENATE GTN D4 INTO D5 SEPARATED BY SPACE.
* d7 = d7.
ELSEIF D6 = SPACE AND D5 NE SPACE AND D4 NE SPACE AND D3 NE SPACE AND D2 NE SPACE. 
CONCATENATE GTN D5 INTO D6 SEPARATED BY SPACE.
* d7 = d7.
ELSEIF D6 NE SPACE AND D5 NE SPACE AND D4 NE SPACE AND D3 NE SPACE AND D2 NE SPACE.
CONCATENATE GTN D6 INTO D7 SEPARATED BY SPACE.
ENDIF.


PERFORM F_FIELDCAT_INIT USING 'I_FINAL1' W_GT_FIELDCAT[].
PERFORM SUM_NETAMT.
PERFORM SORT_FIELDS.
PERFORM SET_VARIANT.
PERFORM POPULATE_EVENT. 
PERFORM COMMENT_BUILD USING W_GT_LIST_TOP_OF_PAGE[].
PERFORM ALV_REPORT.
PERFORM LAYOUT_BUILD.

*&---------------------------------------------------------------------*
*& Form f_fieldcat_init
*&---------------------------------------------------------------------* 

FORM F_FIELDCAT_INIT USING I_FINAL1 LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'GJAHR'.
LS_FIELDCAT-TABNAME = I_FINAL1. 
LS_FIELDCAT-OUTPUTLEN = 5.
* ls_fieldcat-seltext_l = 'M'.
LS_FIELDCAT-SELTEXT_M = 'Year'.
* ls_fieldcat-seltext_s = 'MaterialDesc'.
LS_FIELDCAT-COL_POS = 1.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'LIFNR'.
LS_FIELDCAT-TABNAME = I_FINAL1. 
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-NO_ZERO = 'X'.
LS_FIELDCAT-JUST = 'L'.
LS_FIELDCAT-SELTEXT_L = 'Vendor'.
LS_FIELDCAT-SELTEXT_M = 'Vendor'.
LS_FIELDCAT-SELTEXT_S = 'Vendor'.
LS_FIELDCAT-COL_POS = 2.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT. 
LS_FIELDCAT-FIELDNAME = 'NAME1'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 25.
LS_FIELDCAT-SELTEXT_L = 'Vendor Name'.
LS_FIELDCAT-SELTEXT_M = 'Vendor Name'.
LS_FIELDCAT-SELTEXT_S = 'Vendor Name'.
LS_FIELDCAT-COL_POS = 3.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT. 
LS_FIELDCAT-FIELDNAME = 'REBZG'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = 'Invoice NO.'.
LS_FIELDCAT-SELTEXT_M = 'Invoice NO.'.
LS_FIELDCAT-SELTEXT_S = 'Invoice NO.'.
LS_FIELDCAT-COL_POS = 4.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

* CLEAR LS_FIELDCAT. 
* LS_FIELDCAT-FIELDNAME = 'BELNR'.
* LS_FIELDCAT-TABNAME = I_FINAL1.
* LS_FIELDCAT-OUTPUTLEN = 10.
* LS_FIELDCAT-SELTEXT_L = 'Doc No.'.
* LS_FIELDCAT-SELTEXT_M = 'Doc No.'.
* LS_FIELDCAT-SELTEXT_S = 'Doc No.'. 
* LS_FIELDCAT-COL_POS = 4.
** ls_fieldcat-fix_column = 'X'.
* APPEND LS_FIELDCAT TO LT_FIELDCAT.

* CLEAR LS_FIELDCAT.
* LS_FIELDCAT-FIELDNAME = 'BUDAT'.
* LS_FIELDCAT-TABNAME = I_FINAL1.
* LS_FIELDCAT-OUTPUTLEN = 10. 
* LS_FIELDCAT-SELTEXT_L = 'Post Date'.
* LS_FIELDCAT-SELTEXT_M = 'Post Date'.
* LS_FIELDCAT-SELTEXT_S = 'Post Date'. 
* LS_FIELDCAT-COL_POS = 5.
** ls_fieldcat-fix_column = 'X'.
* APPEND LS_FIELDCAT TO LT_FIELDCAT.

* CLEAR LS_FIELDCAT.
* LS_FIELDCAT-FIELDNAME = 'BUDAT'.
* LS_FIELDCAT-TABNAME = I_FINAL1.
* LS_FIELDCAT-OUTPUTLEN = 10. 
* LS_FIELDCAT-SELTEXT_L = 'Post Date'.
* LS_FIELDCAT-SELTEXT_M = 'Post Date'.
* LS_FIELDCAT-SELTEXT_S = 'Post Date'. 
* LS_FIELDCAT-COL_POS = 5.
** ls_fieldcat-fix_column = 'X'.
* APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'ZFBDT'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = 'Bill Date'.
LS_FIELDCAT-SELTEXT_M = 'Bill Date'.
LS_FIELDCAT-SELTEXT_S = 'Bill Date'.
LS_FIELDCAT-COL_POS = 5.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'XBLNR'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = 'Reference No.'.
LS_FIELDCAT-SELTEXT_M = 'Reference No.'.
LS_FIELDCAT-SELTEXT_S = 'Reference No.'.
LS_FIELDCAT-COL_POS = 6.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'PRCTR'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = 'Profit Center'.
LS_FIELDCAT-SELTEXT_M = 'Profit Center'.
LS_FIELDCAT-SELTEXT_S = 'Profit Center'.
LS_FIELDCAT-COL_POS = 7.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'UMSKZ'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 1.
LS_FIELDCAT-SELTEXT_L = 'Spl.Gl.Ind.'.
LS_FIELDCAT-SELTEXT_M = 'Spl.Gl.Ind.'.
LS_FIELDCAT-SELTEXT_S = 'Spl.Gl.Ind.'.
LS_FIELDCAT-COL_POS = 8.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'BILL'.
LS_FIELDCAT-CFIELDNAME = 'WAERS'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 15.
LS_FIELDCAT-SELTEXT_L = 'Bill Amount' .
LS_FIELDCAT-SELTEXT_M = 'Bill Amount' .
LS_FIELDCAT-SELTEXT_S = 'Bill Amount' .
LS_FIELDCAT-COL_POS = 9.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'PAID'.
LS_FIELDCAT-CFIELDNAME = 'WAERS'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 15.
LS_FIELDCAT-SELTEXT_L = 'Paid Amount' .
LS_FIELDCAT-SELTEXT_M = 'Paid Amount' .
LS_FIELDCAT-SELTEXT_S = 'Paid Amount' .
LS_FIELDCAT-COL_POS = 10.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'TDS'.
LS_FIELDCAT-CFIELDNAME = 'WAERS'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 15.
LS_FIELDCAT-SELTEXT_L = 'TDS Amount'.
LS_FIELDCAT-SELTEXT_M = 'TDS Amount'.
LS_FIELDCAT-SELTEXT_S = 'TDS Amount'.
LS_FIELDCAT-COL_POS = 11.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR10'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = 'Not Due' .
LS_FIELDCAT-SELTEXT_M = 'Not Due' .
LS_FIELDCAT-SELTEXT_S = 'Not Due' .
LS_FIELDCAT-COL_POS = 12.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR11'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D1 .
LS_FIELDCAT-SELTEXT_M = D1 .
LS_FIELDCAT-SELTEXT_S = D1 .
LS_FIELDCAT-COL_POS = 13.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR12' .
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D2 ."'Date'.
LS_FIELDCAT-SELTEXT_M = D2 . "'Date'.
LS_FIELDCAT-SELTEXT_S = D2 ."'Date'.
LS_FIELDCAT-COL_POS = 14.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR13' .
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D3 ."'Date'.
LS_FIELDCAT-SELTEXT_M = D3 . "'Date'.
LS_FIELDCAT-SELTEXT_S = D3 ."'Date'.
LS_FIELDCAT-COL_POS = 15.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR14' .
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D4 ."'DAYS'.
LS_FIELDCAT-SELTEXT_M = D4 . "'DAYS'.
LS_FIELDCAT-SELTEXT_S = D4 ."'DAYS'.
LS_FIELDCAT-COL_POS = 16.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR15' .
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D5 ."'DAYS'.
LS_FIELDCAT-SELTEXT_M = D5 . "'DAYS'.
LS_FIELDCAT-SELTEXT_S = D5 ."'DAYS'.
LS_FIELDCAT-COL_POS = 17.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR16' .
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D6 ."'DAYS'.
LS_FIELDCAT-SELTEXT_M = D6 . "'DAYS'.
LS_FIELDCAT-SELTEXT_S = D6 ."'DAYS'.
LS_FIELDCAT-COL_POS = 18.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'CR17' .
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-SELTEXT_L = D7 ."'DAYS'.
LS_FIELDCAT-SELTEXT_M = D7 . "'DAYS'.
LS_FIELDCAT-SELTEXT_S = D7 ."'DAYS'.
LS_FIELDCAT-COL_POS = 19.
* ls_fieldcat-fix_column = 'X'. 
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'DOWNP' .
LS_FIELDCAT-CFIELDNAME = 'WAERS'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 15.
LS_FIELDCAT-SELTEXT_L = 'Down Payment'.
LS_FIELDCAT-SELTEXT_M = 'Down Payment'.
LS_FIELDCAT-SELTEXT_S = 'Down Payment'.
LS_FIELDCAT-COL_POS = 20.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT. 
LS_FIELDCAT-FIELDNAME = 'NETDUE'.
LS_FIELDCAT-CFIELDNAME = 'WAERS'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 15.
LS_FIELDCAT-SELTEXT_L = 'Net Due Amt'.
LS_FIELDCAT-SELTEXT_M = 'Net Due Amt'.
LS_FIELDCAT-SELTEXT_S = 'Net Due Amt'.
LS_FIELDCAT-COL_POS = 21.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'WAERS'.
LS_FIELDCAT-TABNAME = I_FINAL1.
LS_FIELDCAT-OUTPUTLEN = 16.
LS_FIELDCAT-SELTEXT_L = 'Unit'.
LS_FIELDCAT-SELTEXT_M = 'Unit'.
LS_FIELDCAT-SELTEXT_S = 'Unit'.
LS_FIELDCAT-COL_POS = 22.
* ls_fieldcat-fix_column = 'X'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

ENDFORM. " f_fieldcat_init
*&---------------------------------------------------------------------* 
*& Form sum_netamt
*&---------------------------------------------------------------------*
FORM SUM_NETAMT . 
CLEAR WA_FCAT.

READ TABLE W_GT_FIELDCAT INTO WA_FCAT WITH KEY FIELDNAME = 'BILL'.
IF SY-SUBRC = 0.
WA_FCAT-DO_SUM = 'X'.
MODIFY W_GT_FIELDCAT FROM WA_FCAT INDEX SY-TABIX TRANSPORTING DO_SUM.
ENDIF.
CLEAR WA_FCAT.

READ TABLE W_GT_FIELDCAT INTO WA_FCAT WITH KEY FIELDNAME = 'PAID'.
IF SY-SUBRC = 0.
WA_FCAT-DO_SUM = 'X'.
MODIFY W_GT_FIELDCAT FROM WA_FCAT INDEX SY-TABIX TRANSPORTING DO_SUM.
ENDIF.
CLEAR WA_FCAT.
READ TABLE W_GT_FIELDCAT INTO WA_FCAT WITH KEY FIELDNAME = 'TDS'.
IF SY-SUBRC = 0.
WA_FCAT-DO_SUM = 'X'.
MODIFY W_GT_FIELDCAT FROM WA_FCAT INDEX SY-TABIX TRANSPORTING DO_SUM.
ENDIF.
CLEAR WA_FCAT.
READ TABLE W_GT_FIELDCAT INTO WA_FCAT WITH KEY FIELDNAME = 'TPAID'.
IF SY-SUBRC = 0.
WA_FCAT-DO_SUM = 'X'.
MODIFY W_GT_FIELDCAT FROM WA_FCAT INDEX SY-TABIX TRANSPORTING DO_SUM.
ENDIF.
CLEAR WA_FCAT.
READ TABLE W_GT_FIELDCAT INTO WA_FCAT WITH KEY FIELDNAME = 'DOWNP'.
IF SY-SUBRC = 0.
WA_FCAT-DO_SUM = 'X'.
MODIFY W_GT_FIELDCAT FROM WA_FCAT INDEX SY-TABIX TRANSPORTING DO_SUM.
ENDIF.
CLEAR WA_FCAT.
READ TABLE W_GT_FIELDCAT INTO WA_FCAT WITH KEY FIELDNAME = 'NETDUE'.
IF SY-SUBRC = 0.
WA_FCAT-DO_SUM = 'X'.
MODIFY W_GT_FIELDCAT FROM WA_FCAT INDEX SY-TABIX TRANSPORTING DO_SUM.
ENDIF.
CLEAR WA_FCAT.

ENDFORM. " sum_netamt
*&---------------------------------------------------------------------*
*& Form sort_fields
*&---------------------------------------------------------------------* 
FORM SORT_FIELDS .
WA_SORT-FIELDNAME = 'LIFNR' .
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.

ENDFORM. " sort_fields 
*&---------------------------------------------------------------------*
*& Form set_variant
*&---------------------------------------------------------------------* 

FORM SET_VARIANT .

ENDFORM. " set_variant
*&---------------------------------------------------------------------* 
*& Form populate_event
*&---------------------------------------------------------------------*
FORM POPULATE_EVENT . 
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = T_EVENT "event handling
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.
ELSE.
READ TABLE T_EVENT WITH KEY NAME = SLIS_EV_TOP_OF_PAGE INTO WS_LS_EVENT. 
IF SY-SUBRC = 0.
MOVE C_GC_FORMNAME_TOP_OF_PAGE TO WS_LS_EVENT-FORM.
MODIFY T_EVENT FROM WS_LS_EVENT INDEX SY-TABIX TRANSPORTING FORM.
ENDIF.
READ TABLE T_EVENT WITH KEY NAME = SLIS_EV_USER_COMMAND INTO
WS_LS_EVENT. 
IF SY-SUBRC = 0.
MOVE C_GC_FORMNAME_UCOMM TO WS_LS_EVENT-FORM.
MODIFY T_EVENT FROM WS_LS_EVENT INDEX SY-TABIX TRANSPORTING FORM.
ENDIF.
ENDIF.
ENDFORM. " populate_event
*&---------------------------------------------------------------------* 
*& Form comment_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

FORM COMMENT_BUILD USING P_T_GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

CLEAR WS_LS_LINE.
WS_LS_LINE-TYP = C_H.

WS_LS_LINE-INFO = SY-TITLE.

APPEND WS_LS_LINE TO P_T_GT_LIST_TOP_OF_PAGE.

CLEAR WS_LS_LINE.
WS_LS_LINE-TYP = C_S.
WS_LS_LINE-KEY = 'Company Code :' .
WS_LS_LINE-INFO = P_BUKRS.
APPEND WS_LS_LINE TO P_T_GT_LIST_TOP_OF_PAGE.

CLEAR WS_LS_LINE.
WS_LS_LINE-TYP = C_S. 
WS_LS_LINE-KEY = 'As On Date :'.
CONCATENATE P_BUDAT+6(2) P_BUDAT+ 4(2) P_BUDAT+0(4) INTO WS_LS_LINE-INFO SEPARATED BY '.'.
* WS_LS_LINE-INFO = P_budat.
APPEND WS_LS_LINE TO P_T_GT_LIST_TOP_OF_PAGE.
ENDFORM. " comment_build
*&---------------------------------------------------------------------*
*& Form alv_report 
*&---------------------------------------------------------------------*

FORM ALV_REPORT .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' ' 
* I_CALLBACK_USER_COMMAND = C_USER_COMMAND
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' ' 
* I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME = 'I_FINAL1'
* I_BACKGROUND_ID = ' ' 
I_GRID_TITLE = WA_TITLE
I_GRID_SETTINGS = LC_GLAY
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = W_GT_FIELDCAT[] 
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = IT_SORT
* IT_FILTER = 
* IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'U'
IS_VARIANT = WA_VARIANT
IT_EVENTS = T_EVENT[]
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0 
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0 
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING 
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = I_FINAL1 
* EXCEPTIONS
* PROGRAM_ERROR = 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.


ENDFORM. " alv_report
*&---------------------------------------------------------------------* 
*& Form layout_build
*&---------------------------------------------------------------------*

FORM LAYOUT_BUILD . 
* WA_LAYOUT-ZEBRA = 'X'.
* WA_LAYOUT-TOTALS_ONLY = 'X'.
* WA_LAYOUT-TOTALS_BEFORE_ITEMS = 'X'.
* WA_LAYOUT-SUBTOTALS_TEXT = 'Material Wise Total'.
ENDFORM. " layout_build


*&---------------------------------------------------------------------* 
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = W_GT_LIST_TOP_OF_PAGE.
* i_logo = 'TRVPICTURE_REC_WIZ04'."'ENJOYSAP_LOGO'. ". 
* I_END_OF_LIST_GRID =
* I_ALV_FORM = I_ALV_FORM.
ENDFORM. "TOP_OF_PAGE

*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------* 
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
IF RS_SELFIELD-SEL_TAB_FIELD = 'I_FINAL1-BELNR'.
* IF rs_selfield-value IS NOT INITIAL.
* READ TABLE I_FINAL1 INTO WA_final1 INDEX rs_selfield-tabindex.
* SET PARAMETER ID 'BLN' FIELD wa_Final1-belnr ." rs_selfield-value.
* SET PARAMETER ID 'BUK' FIELD wa_Final1-BUKRS.
* SET PARAMETER ID 'GJR' FIELD wa_Final1-GJAHR. 
* CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
* ENDIF.
ENDIF.

ENDFORM . "user_command

 


×