Skip to Content
0
Former Member
Jan 15, 2013 at 03:42 AM

ALV trouble when modifying parameters when display it

42 Views

Hi, I have a trouble I generated an ALV list, that function the first time correctly show information and then when the user modify the sort and the subtotals a colum in specific changes the values of the information to different things. The column that changes has the properties as a currency value. is the colum ztotal. How can i correct this I leave the code here. Thank you.

Cheers.


*&---------------------------------------------------------------------*
*& Report ZFI_AGING.
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zfi_aging NO STANDARD PAGE HEADING LINE-SIZE 80 MESSAGE-ID fr.


**************************************************************************
***Data declaration***

INCLUDE zfintop.

****************************************************************************

*************************************************************
****Selections****************************************

SELECTION-SCREEN BEGIN OF BLOCK qsel
WITH FRAME TITLE text-s02.
PARAMETERS p_seld LIKE zseld OBLIGATORY DEFAULT sy-datum.
Parameters p_told LIKE zday1 DEFAULT 5.
PARAMETERS p_zday1 LIKE zday1 OBLIGATORY DEFAULT 30.
PARAMETERS p_zday2 LIKE zday2 OBLIGATORY DEFAULT 60.
PARAMETERS p_zday3 LIKE zday3 OBLIGATORY DEFAULT 90.
PARAMETERS p_zday4 LIKE zday4 OBLIGATORY DEFAULT 120.
SELECTION-SCREEN END OF BLOCK qsel.

SELECTION-SCREEN BEGIN OF BLOCK qsel1
WITH FRAME TITLE text-s04.
SELECT-OPTIONS so_kunnr FOR kna1-kunnr MEMORY ID kun.
SELECT-OPTIONS so_blart FOR bsid-blart MEMORY ID bar.
SELECT-OPTIONS so_bschl FOR bsid-bschl.
SELECT-OPTIONS so_belnr FOR bsid-belnr.
SELECT-OPTIONS so_bukrs FOR bsid-bukrs.
SELECT-OPTIONS so_xzahl FOR bsid-xzahl.
SELECT-OPTIONS so_prctr FOR bsid-prctr.
SELECT-OPTIONS so_hkont FOR bsid-hkont.
SELECT-OPTIONS so_rpmkr For kna1-rpmkr.
SELECT-OPTIONS so_umskz For bsid-umskz.
SELECTION-SCREEN END OF BLOCK qsel1.


SELECTION-SCREEN BEGIN OF BLOCK stdsel WITH FRAME TITLE text-s03.
PARAMETERS %layout TYPE slis_vari MODIF ID lay.
SELECTION-SCREEN END OF BLOCK stdsel.


**************************************************************
START-OF-SELECTION.

**first ball BSID data - up tp date not cleared items

CLEAR xbdoc.
CLEAR hxbdoc.
Clear HWAER.


SELECT * FROM bsid AS B
INNER JOIN KNA1 AS K ON B~kunnr = k~kunnr INTO CORRESPONDING FIELDS OF xbdoc
WHERE B~kunnr IN so_kunnr
AND bukrs IN so_bukrs
AND bschl IN so_bschl
AND blart IN so_blart
AND belnr IN so_belnr
AND hkont IN so_hkont
AND xzahl IN so_xzahl
AND UMSKZ IN so_umskz
AND PRCTR IN so_prctr
AND RPMKR IN so_rpmkr
AND budat <= p_seld.

IF sy-subrc = 0.


Select Single WAERS FROM T001 INTO XBDOC-HWAER
Where bukrs = xbdoc-bukrs.


If ( xbdoc-rebzg <> ' ' And xbdoc-rebzt <> ' ' ) .

Select SINGLE zfbdt zterm zbd1t zbd2t zbd3t From BSEG INTO CORRESPONDING Fields of xbdoc
WHERE belnr = xbdoc-rebzg
AND koart = 'D'.


ENDIF.

xbdoc-zday1 = p_zday1.
xbdoc-zday2 = p_zday2.
xbdoc-zday3 = p_zday3.
xbdoc-zday4 = p_zday4.
xbdoc-zseld = p_seld.

***Calculation net due date

IF ( ( xbdoc-rebzg = ' ' AND xbdoc-shkzg = 'H' ) OR ( xbdoc-xzahl = 'X' AND xbdoc-shkzg = 'S' ) ) .
zzfbdt = xbdoc-zfbdt + p_told.
ELSEIF xbdoc-zbd3t <> ' ' .
zzfbdt = xbdoc-zfbdt + xbdoc-zbd3t + p_told.
ELSEIF xbdoc-zbd2t <> ' ' .
zzfbdt = xbdoc-zfbdt + xbdoc-zbd2t + p_told.
ELSEIF xbdoc-zbd1t >= '0' .
zzfbdt = xbdoc-zfbdt + xbdoc-zbd1t + p_told.
ENDIF.

xbdoc-zzfbdt = zzfbdt.

** Calculation days in arrear

zverz = xbdoc-zseld - xbdoc-zzfbdt.
xbdoc-zverz = zverz.

**********************************************
***negative and postive values

xbdoc-bdifft = xbdoc-dmbtr + xbdoc-bdiff.


IF xbdoc-shkzg = 'H' .
xbdoc-dmbtr = xbdoc-dmbtr * ( -1 ) .
xbdoc-wrbtr = xbdoc-wrbtr * ( -1 ) .
xbdoc-bdifft = xbdoc-bdifft * ( -1 ).
ELSEIF xbdoc-shkzg = 'S' .
xbdoc-dmbtr = xbdoc-dmbtr .
xbdoc-wrbtr = xbdoc-wrbtr.
xbdoc-bdifft = xbdoc-bdifft.
ENDIF.

*********************************
***Adding the days in arrear in the right column

IF zverz <= '0'.
xbdoc-dmbtr0 = xbdoc-dmbtr.
xbdoc-wrbtr0 = xbdoc-wrbtr.
xbdoc-bdiff0 = xbdoc-bdiffT.
ELSEIF ( zverz > '0' ) AND ( zverz <= xbdoc-zday1 ).
xbdoc-dmbtr1 = xbdoc-dmbtr.
xbdoc-wrbtr1 = xbdoc-wrbtr.
xbdoc-bdiff1 = xbdoc-bdiffT.

ELSEIF ( zverz > xbdoc-zday1 ) AND ( zverz <= xbdoc-zday2 ).
xbdoc-dmbtr2 = xbdoc-dmbtr.
xbdoc-wrbtr2 = xbdoc-wrbtr.
xbdoc-bdiff2 = xbdoc-bdiffT.

ELSEIF ( zverz > xbdoc-zday2 ) AND ( zverz <= xbdoc-zday3 ).
xbdoc-dmbtr3 = xbdoc-dmbtr.
xbdoc-wrbtr3 = xbdoc-wrbtr.
xbdoc-bdiff3 = xbdoc-bdiffT.

ELSEIF ( zverz > xbdoc-zday3 ) AND ( zverz <= xbdoc-zday4 ).
xbdoc-dmbtr4 = xbdoc-dmbtr.
xbdoc-wrbtr4 = xbdoc-wrbtr.
xbdoc-bdiff4 = xbdoc-bdiffT.

ELSEIF ( zverz > xbdoc-zday4 ).
xbdoc-dmbtr5 = xbdoc-dmbtr.
xbdoc-wrbtr5 = xbdoc-wrbtr.
xbdoc-bdiff5 = xbdoc-bdiffT.


ENDIF.


APPEND xbdoc TO i_xbdoc.
CLEAR zverz.
CLEAR zzfbdt.
CLEAR xbdoc.

ENDIF.
ENDSELECT.

LOOP AT i_xbdoc INTO wa_xbdoc.


IF sy-subrc = 0.

PERFORM append_data.

ENDIF.
ENDLOOP.

*****historical data BSAD

SELECT * FROM bsad AS B
INNER JOIN KNA1 AS K ON B~kunnr = k~kunnr INTO CORRESPONDING FIELDS OF hxbdoc
WHERE B~kunnr IN so_kunnr
AND bukrs IN so_bukrs
AND bschl IN so_bschl
AND blart IN so_blart
AND belnr IN so_belnr
AND hkont IN so_hkont
AND xzahl IN so_xzahl
AND UMSKZ IN so_umskz
AND PRCTR IN so_prctr
AND RPMKR IN so_rpmkr
AND budat <= p_seld
AND augdt > p_seld.


IF sy-subrc = 0.


Select Single WAERS FROM T001 INTO HXBDOC-HWAER
Where bukrs = hxbdoc-bukrs.


If ( hxbdoc-rebzg <> ' ' And hxbdoc-rebzt <> ' ' ).

Select SINGLE zfbdt zterm zbd1t zbd2t zbd3t From BSEG INTO CORRESPONDING Fields of hxbdoc
WHERE belnr = hxbdoc-rebzg
AND koart = 'D'.


ENDIF.


hxbdoc-zday1 = p_zday1.
hxbdoc-zday2 = p_zday2.
hxbdoc-zday3 = p_zday3.
hxbdoc-zday4 = p_zday4.
hxbdoc-zseld = p_seld.


* SELECT SINGLE name1 ort01 pstlz regio sortl stras telf1 telfx Land1 RPMKR FROM kna1 INTO CORRESPONDING FIELDS OF hxbdoc
* WHERE kunnr = hxbdoc-kunnr.

***Calculation net due date

IF ( ( hxbdoc-rebzg = ' ' AND hxbdoc-shkzg = 'H' ) OR ( hxbdoc-xzahl = 'X' AND hxbdoc-shkzg = 'S' ) ).
zzfbdt = hxbdoc-zfbdt + p_told.
ELSEIF hxbdoc-zbd3t <> ' ' .
zzfbdt = hxbdoc-zfbdt + hxbdoc-zbd3t + p_told.
ELSEIF hxbdoc-zbd2t <> ' ' .
zzfbdt = hxbdoc-zfbdt + hxbdoc-zbd2t + p_told.
ELSEIF xbdoc-zbd1t >= '0' .
zzfbdt = hxbdoc-zfbdt + hxbdoc-zbd1t + p_told.
ENDIF.

hxbdoc-zzfbdt = zzfbdt.

** Calculation days in arrear

zverz = hxbdoc-zseld - hxbdoc-zzfbdt.
hxbdoc-zverz = zverz.

**********************************************
***negative and postive values

hxbdoc-bdifft = hxbdoc-dmbtr + hxbdoc-bdiff.


IF hxbdoc-shkzg = 'H' .
hxbdoc-dmbtr = hxbdoc-dmbtr * ( -1 ) .
hxbdoc-wrbtr = hxbdoc-wrbtr * ( -1 ) .
hxbdoc-bdifft = hxbdoc-bdifft * ( -1 ).

ELSEIF xbdoc-shkzg = 'S' .
hxbdoc-dmbtr = hxbdoc-dmbtr .
hxbdoc-wrbtr = hxbdoc-wrbtr.
hxbdoc-bdifft = hxbdoc-bdifft.
ENDIF.

*********************************
***Adding the days in arrear in the right column

IF zverz <= '0'.
hxbdoc-dmbtr0 = hxbdoc-dmbtr.
hxbdoc-wrbtr0 = hxbdoc-wrbtr.
hxbdoc-bdiff0 = hxbdoc-bdifft.

ELSEIF ( zverz > '0' ) AND ( zverz <= hxbdoc-zday1 ).
hxbdoc-dmbtr1 = hxbdoc-dmbtr.
hxbdoc-wrbtr1 = hxbdoc-wrbtr.
hxbdoc-bdiff1 = hxbdoc-bdifft.
ELSEIF ( zverz > hxbdoc-zday1 ) AND ( zverz <= hxbdoc-zday2 ).
hxbdoc-dmbtr2 = hxbdoc-dmbtr.
hxbdoc-wrbtr2 = hxbdoc-wrbtr.
hxbdoc-bdiff2 = hxbdoc-bdifft.
ELSEIF ( zverz > hxbdoc-zday2 ) AND ( zverz <= hxbdoc-zday3 ).
hxbdoc-dmbtr3 = hxbdoc-dmbtr.
hxbdoc-wrbtr3 = hxbdoc-wrbtr.
hxbdoc-bdiff3 = hxbdoc-bdifft.
ELSEIF ( zverz > hxbdoc-zday3 ) AND ( zverz <= hxbdoc-zday4 ).
hxbdoc-dmbtr4 = hxbdoc-dmbtr.
hxbdoc-wrbtr4 = hxbdoc-wrbtr.
hxbdoc-bdiff4 = hxbdoc-bdifft.

ELSEIF ( zverz > hxbdoc-zday4 ).
hxbdoc-dmbtr5 = hxbdoc-dmbtr.
hxbdoc-wrbtr5 = hxbdoc-wrbtr.
hxbdoc-bdiff5 = hxbdoc-bdifft.

ENDIF.


APPEND hxbdoc TO ih_xbdoc.
CLEAR zverz.
CLEAR zzfbdt.
clear hxbdoc.

ENDIF.
ENDSELECT.


LOOP AT ih_xbdoc INTO wa_xbdoc.

IF sy-subrc = 0.
PERFORM append_data.

ENDIF.


ENDLOOP.

*&---------------------------------------------------------------------*
*& Form append_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM append_data.
CLEAR gwa_alv_item.

MOVE-CORRESPONDING wa_xbdoc TO gwa_alv_item.


APPEND gwa_alv_item TO git_alv.

ENDFORM. "append_data

END-OF-SELECTION.

Perform add_division.

PERFORM l01_display.


*&---------------------------------------------------------------------*
*& Form L01_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM l01_display .

DATA : it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA : l_variant TYPE disvariant,
l_layout TYPE slis_layout_alv.

FIELD-SYMBOLS : <field> TYPE slis_fieldcat_alv.

* PREPARE DISPLAY VARIANT
l_variant-report = sy-repid.
* l_variant-variant = p_l01var.

*** Create Table lt_alv_event
PERFORM append_event USING slis_ev_top_of_page
'TOP_OF_PAGE'
CHANGING lt_alv_event.


* PREPARE FIELD CATALOG
**************************************************************
*****REUSE_ALV_FIELDCATALOG_MERGE
**************************************************************

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = ' '
i_structure_name = 'ZFI_AGING'
i_internal_tabname = ''
i_inclname = ' '
i_bypassing_buffer = ' '
CHANGING
ct_fieldcat = it_fieldcat[].

* PREPARE FIELDS LAYOUT
* ==> No keys
* it_fieldcat-key = space.
* MODIFY it_fieldcat TRANSPORTING key WHERE key NE space.

PERFORM create_layout CHANGING l_layout.

*****************************************************************
**********Modify field catalog

DATA l_fieldcat TYPE slis_fieldcat_alv.


*********************************************************************
*************************************************************
*****Variables for Text Arrear

DATA: ll_arrear1t TYPE c LENGTH 20,
ll_arrearot TYPE c LENGTH 20,
ld_arrear1t TYPE c LENGTH 20,
ld_arrearot TYPE c LENGTH 20,
lb_arrear1t TYPE c LENGTH 20,
lb_arrearot TYPE c LENGTH 20,
ll_arrear1 TYPE c LENGTH 20,
ll_arrear2 TYPE c LENGTH 20,
ll_arrear3 TYPE c LENGTH 20,
ll_arrear4 TYPE c LENGTH 20,
ll_arrearo TYPE c LENGTH 20,
ld_arrear1 TYPE c LENGTH 20,
ld_arrear2 TYPE c LENGTH 20,
ld_arrear3 TYPE c LENGTH 20,
ld_arrear4 TYPE c LENGTH 20,
ld_arrearo TYPE c LENGTH 20,
lb_arrear1 TYPE c LENGTH 20,
lb_arrear2 TYPE c LENGTH 20,
lb_arrear3 TYPE c LENGTH 20,
lb_arrearo TYPE c LENGTH 20,
lb_arrear4 TYPE c LENGTH 20,
l_days TYPE c LENGTH 10.


CLEAR: ll_arrear1t,
ll_arrearot,
lb_arrear1t,
lb_arrearot,
ld_arrear1t,
ld_arrearot,
ll_arrear1,
ll_arrear2,
ll_arrear3,
ll_arrear4,
ll_arrearo,
ld_arrear1,
ld_arrear2,
ld_arrear3,
ld_arrear4,
ld_arrearo,
lb_arrear1,
lb_arrear2,
lb_arrear3,
lb_arrear4,
lb_arrearo.


ll_arrear1t = 'LAmt<='.
ll_arrearot = 'LAmt>'.

ld_arrear1t = 'DAmt<='.
ld_arrearot = 'DAmt>'.

lb_arrear1t = 'VAmt<='.
lb_arrearot = 'VAmt>'.

l_days = 'Days'.

CONCATENATE ll_arrear1t wa_xbdoc-zday1 l_days INTO ll_arrear1 SEPARATED BY space.
CONCATENATE ll_arrear1t wa_xbdoc-zday2 l_days INTO ll_arrear2 SEPARATED BY space.
CONCATENATE ll_arrear1t wa_xbdoc-zday3 l_days INTO ll_arrear3 SEPARATED BY space.
CONCATENATE ll_arrear1t wa_xbdoc-zday4 l_days INTO ll_arrearo SEPARATED BY space.
CONCATENATE ll_arrearot wa_xbdoc-zday4 l_days INTO ll_arrear4 SEPARATED BY space.

CONCATENATE ld_arrear1t wa_xbdoc-zday1 l_days INTO ld_arrear1 SEPARATED BY space.
CONCATENATE ld_arrear1t wa_xbdoc-zday2 l_days INTO ld_arrear2 SEPARATED BY space.
CONCATENATE ld_arrear1t wa_xbdoc-zday3 l_days INTO ld_arrear3 SEPARATED BY space.
CONCATENATE ld_arrear1t wa_xbdoc-zday4 l_days INTO ld_arrearo SEPARATED BY space.
CONCATENATE ld_arrearot wa_xbdoc-zday4 l_days INTO ld_arrear4 SEPARATED BY space.

CONCATENATE lb_arrear1t wa_xbdoc-zday1 l_days INTO lb_arrear1 SEPARATED BY space.
CONCATENATE lb_arrear1t wa_xbdoc-zday2 l_days INTO lb_arrear2 SEPARATED BY space.
CONCATENATE lb_arrear1t wa_xbdoc-zday3 l_days INTO lb_arrear3 SEPARATED BY space.
CONCATENATE lb_arrear1t wa_xbdoc-zday4 l_days INTO lb_arrearo SEPARATED BY space.
CONCATENATE lb_arrearot wa_xbdoc-zday4 l_days INTO lb_arrear4 SEPARATED BY space.

LOOP AT it_fieldcat INTO l_fieldcat.

CASE l_fieldcat-fieldname. "Define Currencies
WHEN 'DMBTR'.
l_fieldcat-seltext_s = 'LAmount'.
l_fieldcat-seltext_m = 'LAmount'.
l_fieldcat-seltext_l = 'LAmount'.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'WRBTR'.
l_fieldcat-seltext_s = 'DAmount'.
l_fieldcat-seltext_m = 'DAmount'.
l_fieldcat-seltext_l = 'DAmount'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.
WHEN 'BDIFF'.
l_fieldcat-seltext_s = 'ValDiff'.
l_fieldcat-seltext_m = 'ValDiff'.
l_fieldcat-seltext_l = 'ValDiff'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.
WHEN 'BDIFFT'.
l_fieldcat-seltext_s = 'VAmount'.
l_fieldcat-seltext_m = 'VAmount'.
l_fieldcat-seltext_l = 'VAmount'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'DMBTR0'.
l_fieldcat-seltext_s = 'LAmt not due'.
l_fieldcat-seltext_m = 'LAmt not due'.
l_fieldcat-seltext_l = 'LAmt not due'.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'BDIFF0'.
l_fieldcat-seltext_s = 'VAmt not due'.
l_fieldcat-seltext_m = 'VAmt not due'.
l_fieldcat-seltext_l = 'VAmt not due'.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.


WHEN 'DMBTR1'.
l_fieldcat-seltext_s = ll_arrear1.
l_fieldcat-seltext_m = ll_arrear1.
l_fieldcat-seltext_l = ll_arrear1.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'BDIFF1'.
l_fieldcat-seltext_s = lb_arrear1.
l_fieldcat-seltext_m = lb_arrear1.
l_fieldcat-seltext_l = lb_arrear1.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.


WHEN 'DMBTR2'.
l_fieldcat-seltext_s = ll_arrear2.
l_fieldcat-seltext_m = ll_arrear2.
l_fieldcat-seltext_l = ll_arrear2.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'BDIFF2'.
l_fieldcat-seltext_s = lb_arrear2.
l_fieldcat-seltext_m = lb_arrear2.
l_fieldcat-seltext_l = lb_arrear2.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'DMBTR3'.
l_fieldcat-seltext_s = ll_arrear3.
l_fieldcat-seltext_m = ll_arrear3.
l_fieldcat-seltext_l = ll_arrear3.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'BDIFF3'.
l_fieldcat-seltext_s = lb_arrear3.
l_fieldcat-seltext_m = lb_arrear3.
l_fieldcat-seltext_l = lb_arrear3.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'DMBTR4'.
l_fieldcat-seltext_s = ll_arrearo.
l_fieldcat-seltext_m = ll_arrearo.
l_fieldcat-seltext_l = ll_arrearo.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.


WHEN 'BDIFF4'.
l_fieldcat-seltext_s = lb_arrearo.
l_fieldcat-seltext_m = lb_arrearo.
l_fieldcat-seltext_l = lb_arrearo.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.


WHEN 'DMBTR5'.
l_fieldcat-seltext_s = ll_arrear4.
l_fieldcat-seltext_m = ll_arrear4.
l_fieldcat-seltext_l = ll_arrear4.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.


WHEN 'BDIFF5'.
l_fieldcat-seltext_s = lb_arrear4.
l_fieldcat-seltext_m = lb_arrear4.
l_fieldcat-seltext_l = lb_arrear4.
l_fieldcat-no_out = 'X'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'WRBTR0'.
l_fieldcat-seltext_s = 'DAmt not due'.
l_fieldcat-seltext_m = 'DAmt not due'.
l_fieldcat-seltext_l = 'DAmt not due'.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.
WHEN 'WRBTR1'.
l_fieldcat-seltext_s = ld_arrear1.
l_fieldcat-seltext_m = ld_arrear1.
l_fieldcat-seltext_l = ld_arrear1.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.
WHEN 'WRBTR2'.
l_fieldcat-seltext_s = ld_arrear2.
l_fieldcat-seltext_m = ld_arrear2.
l_fieldcat-seltext_l = ld_arrear2.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.
WHEN 'WRBTR3'.
l_fieldcat-seltext_s = ld_arrear3.
l_fieldcat-seltext_m = ld_arrear3.
l_fieldcat-seltext_l = ld_arrear3.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.
WHEN 'WRBTR4'.
l_fieldcat-seltext_s = ld_arrearo.
l_fieldcat-seltext_m = ld_arrearo.
l_fieldcat-seltext_l = ld_arrearo.
l_fieldcat-reptext_ddic = ld_arrearo.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.

WHEN 'WRBTR5'.
l_fieldcat-seltext_s = ld_arrear4.
l_fieldcat-seltext_m = ld_arrear4.
l_fieldcat-seltext_l = ld_arrear4.
l_fieldcat-reptext_ddic = ld_arrear4.
l_fieldcat-do_sum = 'X'.
l_fieldcat-NO_ZERO = 'X'.


WHEN 'ZDAY1'.
l_fieldcat-seltext_s = 'Arrear 1'.
l_fieldcat-seltext_m = 'Arrear 1'.
l_fieldcat-seltext_l = 'Arrear 1'.
l_fieldcat-reptext_ddic = 'Arrear 1'.
l_fieldcat-no_out = 'X'.

WHEN 'ZDAY2'.
l_fieldcat-seltext_s = 'Arrear 2'.
l_fieldcat-seltext_m = 'Arrear 2'.
l_fieldcat-seltext_l = 'Arrear 2'.
l_fieldcat-reptext_ddic = 'Arrear 2'.
l_fieldcat-no_out = 'X'.
WHEN 'ZDAY3'.
l_fieldcat-seltext_s = 'Arrear 3'.
l_fieldcat-seltext_m = 'Arrear 3'.
l_fieldcat-seltext_l = 'Arrear 3'.
l_fieldcat-reptext_ddic = 'Arrear 3'.
l_fieldcat-no_out = 'X'.

WHEN 'ZDAY4'.
l_fieldcat-seltext_s = 'Arrear 4'.
l_fieldcat-seltext_m = 'Arrear 4'.
l_fieldcat-seltext_l = 'Arrear 4'.
l_fieldcat-reptext_ddic = 'Arrear 4'.
l_fieldcat-no_out = 'X'.


WHEN 'ZVERZ'.
l_fieldcat-seltext_s = 'Days Overdue'.
l_fieldcat-seltext_m = 'Days Overdue'.
l_fieldcat-seltext_l = 'Days Overdue'.
l_fieldcat-reptext_ddic = 'Days Overdue'.


WHEN 'ZSELD'.
l_fieldcat-seltext_s = 'Sel Date'.
l_fieldcat-seltext_m = 'Sel Date'.
l_fieldcat-seltext_l = 'Selection Date'.
l_fieldcat-rollname = 'SelDate'.
l_fieldcat-reptext_ddic = 'Sel Date'.

WHEN 'ZZFBDT'.
l_fieldcat-seltext_s = 'Net Due Date'.
l_fieldcat-seltext_m = 'Net Due Date'.
l_fieldcat-seltext_l = 'Net Due Date'.
l_fieldcat-reptext_ddic = 'Net Due Date'.


WHEN 'SGTXT'.
l_fieldcat-seltext_s = 'Line Item Text'.
l_fieldcat-seltext_m = 'Line Item Text'.
l_fieldcat-seltext_l = 'Line Item Text'.
l_fieldcat-reptext_ddic = 'Line Item Text'.

WHEN 'ZBD1T'.
l_fieldcat-no_out = 'X'.
WHEN 'ZBD2T'.
l_fieldcat-no_out = 'X'.
WHEN 'ZBD3T'.
l_fieldcat-no_out = 'X'.
WHEN 'ZFBDT'.
l_fieldcat-no_out = 'X'.
WHEN 'DZTERM'.
l_fieldcat-no_out = 'X'.
WHEN 'AUGDT'.
l_fieldcat-no_out = 'X'.
WHEN 'AUGDT'.
l_fieldcat-no_out = 'X'.
WHEN 'AUGCP'.
l_fieldcat-no_out = 'X'.
WHEN 'AUGBL'.
l_fieldcat-no_out = 'X'.
WHEN 'BSCHL'.
l_fieldcat-no_out = 'X'.
WHEN 'KOART'.
l_fieldcat-no_out = 'X'.

WHEN 'KOART'.
l_fieldcat-no_out = 'X'.
WHEN 'SHKZG'.
l_fieldcat-no_out = 'X'.

ENDCASE.
MODIFY it_fieldcat FROM l_fieldcat.

ENDLOOP.

* DISPLAY DATA WITHIN AN ALV REPORT
*************************************************
*****REUSE_ALV_GRID_DISPLAY
*************************************************

* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
*
* EXPORTING
* i_grid_title = 'Trench Aging Report'
* it_fieldcat = it_fieldcat[]
* i_default = 'X'
* i_save = 'A' " A = All Users
* is_variant = l_variant
* is_layout = l_layout
* i_callback_program = l_variant-report
* it_events = lt_alv_event
* TABLES
* t_outtab = git_alv
* EXCEPTIONS
* program_error = 1
* OTHERS = 2.


**Print tables git_alv.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = l_variant-report
is_layout = l_layout
it_fieldcat = it_fieldcat[]
i_default = 'X'
is_variant = l_variant
i_save = 'A'
it_events = lt_alv_event
TABLES
t_outtab = git_alv.


**************************************************************

ENDFORM. " L01_DISPLAY

*&---------------------------------------------------------------------*
*& Form L01_PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM l01_pf_status USING i_extab TYPE slis_t_extab.
SET TITLEBAR 'L01'.
SET PF-STATUS 'STATUS1'.

ENDFORM. "l01_pf_status

*&---------------------------------------------------------------------*
*& Form L01_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM l01_user_command USING i_ucomm LIKE sy-ucomm
io_selfield TYPE slis_selfield.

*Refresh Abap list viewer screen
IF i_ucomm = 'EXEC' OR
i_ucomm = '&IC1'.
io_selfield-refresh = c_x.
ENDIF.
io_selfield-col_stable = 'x'.
ENDFORM. "l01_user_command

*---------------------------------------------------------------------*
* FORM top_of_page *
*---------------------------------------------------------------------*
* Information output at the top of a page *
*---------------------------------------------------------------------*
FORM top_of_page.

"Print special header
bhdgd-line2 = 'Trench Aging report'.
bhdgd-line2 = p_seld.
bhdgd-line1 = sy-title.
bhdgd-inifl = P_seld.
bhdgd-lines = sy-linsz.
IF bhdgd-lines > 250.
bhdgd-lines = 250.
ENDIF.
MOVE git_alv-bukrs TO bhdgd-bukrs.
MOVE git_alv-bukrs TO bhdgd-werte.

PERFORM new-section(rsbtchh0).
PERFORM batch-heading(rsbtchh0).
PERFORM print_heading.

ENDFORM. "top_of_page


*---------------------------------------------------------------------*
* FORM create_layout *
*---------------------------------------------------------------------*
* --> c_layout *
*---------------------------------------------------------------------*
FORM create_layout CHANGING c_layout TYPE slis_layout_alv.
c_layout-group_change_edit = 'X'. "Aufbereitungsoptionen änderbar
ENDFORM. "create_layout


*---------------------------------------------------------------------*
* FORM append_event *
*---------------------------------------------------------------------*
* --> u_name Event-name *
* --> u_form Form-name *
*---------------------------------------------------------------------*
* <-- ct_event Table of events to perform *
*---------------------------------------------------------------------*
FORM append_event USING u_name TYPE slis_alv_event-name
u_form TYPE slis_alv_event-form
CHANGING ct_event TYPE slis_t_event.

DATA: l_alv_event TYPE slis_alv_event.

l_alv_event-name = u_name.
l_alv_event-form = u_form.
APPEND l_alv_event TO ct_event.
ENDFORM. "append_event


*---------------------------------------------------------------------*
* FORM print_heading *
*---------------------------------------------------------------------*
* Print a header *
*---------------------------------------------------------------------*
FORM print_heading.
WRITE: /.
ULINE AT /1(sy-linsz).
WRITE: sy-vline,
'Aging Report Trench'.
WRITE AT sy-linsz(1) sy-vline.
WRITE: / sy-vline,
'Selection Date:',
p_seld.
WRITE AT sy-linsz(1) sy-vline.

ENDFORM. "print_heading
*/MAPC January 10 2013. Form to add division.*/


*---------------------------------------------------------------------*
* FORM Add Division *
*---------------------------------------------------------------------*
* The program reads the profit center to add a description *
*---------------------------------------------------------------------*
form add_division.
data: vzdivdesc type zdivdesc, "Variable to save description from the description table
vzidiv type zidiv, "Variable to save the id that we are looking for.
vsum type WRBTR. "Variable to add the values of request values.(Tolerance days, Arrear 1, Arrear 2 , Arrear 3, Arrear 4)

clear: vzdivdesc, vzidiv, vsum.
*Loop at the final table to add the description reading zdivdesc with id from table.
loop at git_alv.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = git_alv-PRCTR
importing
output = git_alv-PRCTR.

move git_alv-PRCTR(1) to vzidiv.

select single zdivdesc
from zttr_div into vzdivdesc
where zidiv = vzidiv.
if sy-subrc = 0.
move vzdivdesc to git_alv-zdivision. "We add the division value to the end of the alv table.
else.
clear git_alv-zdivision.
endif.
clear: vzdivdesc, vzidiv.
*Perform addition of the fields.
vsum = git_alv-WRBTR0 + git_alv-WRBTR1 + git_alv-WRBTR2 + git_alv-WRBTR3 + git_alv-WRBTR4.
move vsum to git_alv-ztotal.
modify git_alv index sy-tabix.
clear: vsum, vzdivdesc.
endloop.
endform. "add_division