Autor Tema: ALV - Ejemplo de Balance  (Leído 9487 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado Enrique.Borroni

  • Moderador_
  • Usuario Completo
  • *****
  • Mensajes: 89
    • Ver Perfil
ALV - Ejemplo de Balance
« en: 03 de Noviembre de 2007, 10:18:06 am »
REPORT Y_BALANCE_ALV  NO STANDARD PAGE  HEADING
                                         LINE-SIZE 132
                                         LINE-COUNT 65.
*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*
TABLES: BSID,          "open items (Accounting: Secondary Index for Customers)
        KNA1,          "customer master
        RF140,         "temp stru (Work Fields for Correspondence (SAPF140*))
        BSAD,          "cleared items (Accounting: Secondary Index for Customers (Cleared Items))
        KNVV,          "sales data (Customer Master Sales Data)
        KNKK.          "credit mgt (

*----------------------------------------------------------------------*
* constants and variables
*----------------------------------------------------------------------*
TYPE-POOLS: SLIS.

DATA: FIELDCAT             TYPE SLIS_T_FIELDCAT_ALV,
      FIELDCAT1             TYPE SLIS_T_FIELDCAT_ALV,
      FIELDCAT_LN          LIKE LINE OF FIELDCAT,
      LAYOUT_IN            TYPE SLIS_LAYOUT_ALV,
      LAYOUT_IN1           TYPE SLIS_LAYOUT_ALV,
      SORTCAT              TYPE SLIS_T_SORTINFO_ALV,
      SORTCAT1              TYPE SLIS_T_SORTINFO_ALV,
      SORTCAT_LN           LIKE LINE OF SORTCAT,
      EVENTCAT1             TYPE SLIS_T_EVENT,
      EVENTCAT             TYPE SLIS_T_EVENT,
      EVENTCAT_LN          LIKE LINE OF EVENTCAT,
      COL_POS              TYPE I.

DATA:  TARG_MONTH(2)         TYPE N,                        "0001
       TARG_YEAR(4)          TYPE N,                        "0001
       TARG_MTH_ABS          TYPE P,                        "0001
       DOC_MONTH(2)          TYPE N,                        "0001
       DOC_YEAR(4)           TYPE N,                        "0001
       DOC_MTH_ABS           TYPE P,                        "0001
       MTH_RESULT            TYPE P,                        "0001
       EXT_DAYS              TYPE P,
       V_DAYS(3)             TYPE C,
       v_kkber               like knkk-kkber.

DATA:
      BEGIN OF INREC OCCURS 1000,                           "0001
        KUNNR    LIKE BSID-KUNNR,
        BELNR    LIKE BSID-BELNR,
        GJAHR    LIKE BSID-GJAHR,
        BLDAT    LIKE BSID-BLDAT,
        XBLNR    LIKE BSID-XBLNR,
        BLART    LIKE BSID-BLART,
        SGTXT    LIKE BSID-SGTXT,
        SHKZG    LIKE BSID-SHKZG,
        DMBTR    LIKE BSID-DMBTR,
        ZFBDT    LIKE BSID-ZFBDT,
        ZBD1T    LIKE BSID-ZBD1T,
        ZBD2T    LIKE BSID-ZBD2T,
        ZBD3T    LIKE BSID-ZBD3T,
        VBELN    LIKE BSID-VBELN,                           " 0001
        ZUONR    LIKE BSID-ZUONR,
      END OF INREC,
      BEGIN OF T_ITEM OCCURS 1000,                          " 0001
        KUNNR LIKE BSID-KUNNR,
        BELNR LIKE BSID-BELNR,
        GJAHR LIKE BSID-GJAHR,
        BLDAT LIKE BSID-BLDAT,
        XBLNR LIKE BSID-XBLNR,
        BLART LIKE BSID-BLART,
        SGTXT LIKE BSID-SGTXT,
        VBELN LIKE BSID-VBELN,
        ZFBDT LIKE BSID-ZFBDT,
        DMBTR LIKE BSID-DMBTR,
        DAYS(3)  TYPE C,
        ZUONR    LIKE BSID-ZUONR,
      END OF T_ITEM,
      T_LINE LIKE T_ITEM OCCURS 1000 WITH HEADER LINE,      " 0001
      BEGIN OF ITAB OCCURS 1000,
        KUNNR    LIKE KNA1-KUNNR,
        TOTAL    TYPE P DECIMALS 2,
        ZFUTURE  TYPE P DECIMALS 2,
        ZCURRENT TYPE P DECIMALS 2,
        30DAYS   TYPE P DECIMALS 2,
        60DAYS   TYPE P DECIMALS 2,
        90DAYS   TYPE P DECIMALS 2,
        99DAYS   TYPE P DECIMALS 2,
        VKBUR    LIKE KNVV-VKBUR,
        VWERK    LIKE KNVV-VWERK,
        VKGRP    LIKE KNVV-VKGRP,
        KLIMK    LIKE KNKK-KLIMK,
        CASHD    LIKE KNKK-CASHD,
        GRUPP    LIKE KNKK-GRUPP,
        ERDAT    LIKE KNA1-ERDAT,
        NAME1    LIKE KNA1-NAME1,
        NAME2    LIKE KNA1-NAME2,
        STRAS    like kna1-STRAS,
        ORT01    like kna1-ORT01,
        TELF1    LIKE KNA1-TELF1,
        PSORT(10),
      END OF ITAB.
DATA: SEL_TAB     TYPE TABLE OF RSPARAMS with header line..
data: t_variant like DISVARIANT occurs 0 with header line.
*----------------------------------------------------------------------*
* parameters and select-options
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLCK0 WITH FRAME TITLE TEXT-001.

PARAMETERS: STIDA LIKE SY-DATUM DEFAULT SY-DATUM OBLIGATORY,
            P_BUKRS LIKE T001-BUKRS MEMORY ID BUK OBLIGATORY.
*           P_BUKRS LIKE T001-BUKRS DEFAULT 'CC01' OBLIGATORY.  "0003
SELECT-OPTIONS: S_VKBUR FOR KNVV-VKBUR,
                S_KUNNR   FOR BSID-KUNNR MATCHCODE OBJECT DEBI,
                S_VKGRP FOR KNVV-VKGRP,
                s_bzirk for knvv-bzirk,
                S_KONDA FOR KNVV-KONDA,
                S_KDGRP FOR KNVV-KVGR2,
                s_kvgr2 for knvv-kvgr2,
                S_KKBER FOR KNKK-KKBER,
                S_GRUPP FOR KNKK-GRUPP,
                S_CTLPC FOR KNKK-CTLPC,
                S_KTOKD FOR KNA1-KTOKD,
                s_blart for bsid-blart.
PARAMETERS: P_FUTURE AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK BLCK0.
*----------------------------------------------------------------------*
* start-of-selection.
*----------------------------------------------------------------------*
START-OF-SELECTION.
*  PERFORM BUILD_EVENTCAT.
*-----------------
  PERFORM GET_CUSTOMER_INVOICES.
* filter records based on selection criteria
  PERFORM FILTER_RECORDS.

END-OF-SELECTION.
*---------------
  PERFORM ADD_SORT_FIELD.
  PERFORM WRITE_REPORT.
*&---------------------------------------------------------------------*
*&      Form  FILTER_RECORDS
*&---------------------------------------------------------------------*
*       To collect all the required data from DB and store them in
*       internal table.
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILTER_RECORDS.
*
* delete records based on selection criteria
  LOOP AT ITAB.
    SELECT VKBUR VKGRP VWERK ERDAT KONDA KDGRP bzirk kvgr2
      INTO (ITAB-VKBUR, ITAB-VKGRP, ITAB-VWERK, KNVV-ERDAT,
            KNVV-KONDA, KNVV-KDGRP,knvv-bzirk,knvv-kvgr2)
      FROM KNVV WHERE KUNNR =  ITAB-KUNNR
                ORDER BY ERDAT DESCENDING.
      CASE ITAB-VKBUR.
        WHEN 'SA1'.
          ITAB-VKBUR = 'SF25'.
        WHEN 'QLD1'.
          ITAB-VKBUR = 'SF23'.
        WHEN 'WA1'.
          ITAB-VKBUR = 'SF26'.
      ENDCASE.
      EXIT.
    ENDSELECT.
    IF ITAB-VKBUR IN S_VKBUR AND
       ITAB-VKGRP IN S_VKGRP AND
       KNVV-KONDA IN S_KONDA AND
       KNVV-KDGRP IN S_KDGRP and
       knvv-bzirk in s_bzirk and
       knvv-kvgr2 in s_kvgr2.
    ELSE.
      DELETE ITAB.
      CONTINUE.
    ENDIF.
    SELECT SINGLE KLIMK GRUPP CASHD
      INTO (ITAB-KLIMK, ITAB-GRUPP, ITAB-CASHD)
      FROM KNKK WHERE KUNNR =  ITAB-KUNNR
                AND   KKBER IN S_KKBER
                AND   CTLPC IN S_CTLPC
                AND   GRUPP IN S_GRUPP.
    IF SY-SUBRC NE 0.
      DELETE ITAB.
      CONTINUE.
    ENDIF.
    SELECT SINGLE NAME1 NAME2 TELF1 ERDAT stras ORT01
         INTO (ITAB-NAME1, ITAB-NAME2, ITAB-TELF1,
                 ITAB-ERDAT, itab-stras, itab-ORT01)
           FROM KNA1
           WHERE KUNNR =  ITAB-KUNNR
           AND   KTOKD IN S_KTOKD.
    IF SY-SUBRC NE 0.
      DELETE ITAB.
      CONTINUE.
    ENDIF.
    MODIFY ITAB.
  ENDLOOP.
ENDFORM.                               " FILTER_RECORDS

*&---------------------------------------------------------------------*
*&      Form  GET_CUSTOMER_INVOICES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_CUSTOMER_INVOICES.

  MOVE STIDA             TO RF140-STIDA.
  MOVE RF140-STIDA+4(2)  TO TARG_MONTH.
  MOVE RF140-STIDA+0(4)  TO TARG_YEAR.
  TARG_MTH_ABS           =  ( TARG_YEAR * 12 ) + TARG_MONTH.

* select open items.
  SELECT KUNNR BELNR GJAHR BLDAT XBLNR BLART SGTXT          " 0001
         SHKZG DMBTR ZFBDT ZBD1T ZBD2T ZBD3T VBELN
         zuonr
    FROM BSID INTO TABLE INREC
    WHERE BUKRS =  P_BUKRS
    AND   BUDAT LE STIDA
    AND   KUNNR IN S_KUNNR
    and   blart in s_blart.

  LOOP AT INREC.
    IF INREC-SHKZG = 'H'.
      INREC-DMBTR  = INREC-DMBTR * -1.
    ENDIF.
    MOVE-CORRESPONDING INREC TO T_ITEM.                     " 0001
    PERFORM COLLECT_INVOICE USING   INREC-KUNNR    INREC-DMBTR
                                    INREC-ZFBDT    INREC-ZBD1T
                                    INREC-ZBD2T    INREC-ZBD3T.
    APPEND T_ITEM.
    CLEAR T_ITEM.
  ENDLOOP.

* select cleared items
  REFRESH INREC.  CLEAR INREC.
  SELECT KUNNR BELNR GJAHR BLDAT XBLNR BLART SGTXT
         SHKZG DMBTR ZFBDT ZBD1T ZBD2T ZBD3T VBELN
         zuonr
    FROM BSAD INTO TABLE INREC
    WHERE BUKRS =  P_BUKRS
    AND   BUDAT LE STIDA
    AND   AUGDT >  STIDA
    AND   KUNNR IN S_KUNNR
    and   blart in s_blart.
  LOOP AT INREC.
    IF INREC-SHKZG = 'H'.
      INREC-DMBTR  = INREC-DMBTR * -1.
    ENDIF.
    MOVE-CORRESPONDING INREC TO T_ITEM.                     " 0001
    PERFORM COLLECT_INVOICE USING   INREC-KUNNR    INREC-DMBTR
                                    INREC-ZFBDT    INREC-ZBD1T
                                    INREC-ZBD2T    INREC-ZBD3T.
    APPEND T_ITEM.
    CLEAR T_ITEM.                                           " 0001
  ENDLOOP.

ENDFORM.                    " GET_CUSTOMER_INVOICES

*&---------------------------------------------------------------------*
*&      Form  COLLECT_INVOICE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_BSID_KUNNR  text
*      -->P_BSID_DMBTR  text
*      -->P_BSID_ZFBDT  text
*      -->P_BSID_ZFBDT1  text
*      -->P_BSID_ZFBDT2  text
*      -->P_BSID_ZFBDT3  text
*----------------------------------------------------------------------*
FORM COLLECT_INVOICE USING    PP_KUNNR
                              PP_DMBTR
                              PP_ZFBDT
                              PP_ZBD1T
                              PP_ZBD2T
                              PP_ZBD3T.

  DOC_MONTH            =  PP_ZFBDT+4(2).
  DOC_YEAR             =  PP_ZFBDT+0(4).
  DOC_MTH_ABS          =  ( DOC_YEAR * 12 ) + DOC_MONTH.
  MTH_RESULT           =  ( TARG_MTH_ABS    - DOC_MTH_ABS ).

  IF NOT PP_ZBD3T IS INITIAL.
    MOVE PP_ZBD3T TO EXT_DAYS.
  ELSEIF NOT PP_ZBD2T IS INITIAL.
    MOVE PP_ZBD2T TO EXT_DAYS.
  ELSEIF NOT PP_ZBD1T IS INITIAL.
    MOVE PP_ZBD1T TO EXT_DAYS.
  ELSE.
    CLEAR EXT_DAYS.
  ENDIF.
* CHECK with Andrew whether this is working or not
* if extended payment terms exist, subtract no of mths from mth_result
*  IF NOT EXT_DAYS IS INITIAL.
*    CASE EXT_DAYS.
*      WHEN 30.
*        SUBTRACT 1 FROM MTH_RESULT.
*      WHEN 60.
*        SUBTRACT 2 FROM MTH_RESULT.
*      WHEN 90.
*        SUBTRACT 3 FROM MTH_RESULT.
*      WHEN 120.
*        SUBTRACT 4 FROM MTH_RESULT.
*    ENDCASE.
*  ENDIF.
* change to key date
  IF P_FUTURE = 'X'.                                        " 0001
    IF MTH_RESULT      <= 0.
      ITAB-ZCURRENT    =  PP_DMBTR.
      T_ITEM-DAYS       = 'CUR'.
    ELSEIF MTH_RESULT  =  1.
      ITAB-30DAYS      =  PP_DMBTR.
      T_ITEM-DAYS       = '30D'.
    ELSEIF MTH_RESULT  =  2.
      ITAB-60DAYS      =  PP_DMBTR.
      T_ITEM-DAYS        = '60D'.
    ELSEIF MTH_RESULT  =  3.
      ITAB-90DAYS      =  PP_DMBTR.
      T_ITEM-DAYS        = '90D'.
    ELSEIF MTH_RESULT  >  3.
      ITAB-99DAYS      =  PP_DMBTR.
      T_ITEM-DAYS        = '99D'.
    ENDIF.
  ELSE.
    IF MTH_RESULT      < 0.
      ITAB-ZFUTURE     =  PP_DMBTR.
      T_ITEM-DAYS       = 'FUT'.
    ELSEIF MTH_RESULT  = 0.
      ITAB-ZCURRENT = PP_DMBTR.
      T_ITEM-DAYS       = 'CUR'.
    ELSEIF MTH_RESULT  =  1.
      ITAB-30DAYS      =  PP_DMBTR.
      T_ITEM-DAYS       = '30D'.
    ELSEIF MTH_RESULT  =  2.
      ITAB-60DAYS      =  PP_DMBTR.
      T_ITEM-DAYS       = '60D'.
    ELSEIF MTH_RESULT  =  3.
      ITAB-90DAYS      =  PP_DMBTR.
      T_ITEM-DAYS       = '90D'.
    ELSEIF MTH_RESULT  >  3.
      ITAB-99DAYS      =  PP_DMBTR.
      T_ITEM-DAYS       = '99D'.
    ENDIF.
  ENDIF.                                                    " 0001
  ITAB-KUNNR         = PP_KUNNR.
  ITAB-TOTAL         = PP_DMBTR.
  COLLECT ITAB.
  CLEAR ITAB.
ENDFORM.                    " COLLECT_INVOICE
*&---------------------------------------------------------------------*
*&      Form  ADD_SORT_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ADD_SORT_FIELD.
  DATA: L_AMOUNT(9)  TYPE N.
  IF P_FUTURE = 'X'.
    LOOP AT ITAB.
      L_AMOUNT = 999999999.
      IF     ITAB-99DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-99DAYS.
        CONCATENATE 'A' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-90DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-90DAYS.
        CONCATENATE 'B' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-60DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-60DAYS.
        CONCATENATE 'C' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-30DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-30DAYS.
        CONCATENATE 'D' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-ZCURRENT > 0.
        L_AMOUNT = L_AMOUNT - ITAB-ZCURRENT.
        CONCATENATE 'E' L_AMOUNT INTO ITAB-PSORT.
*     ELSEif itab-zfuture > 0.
*       L_AMOUNT = L_AMOUNT - ITAB-zfuture.
*       CONCATENATE 'F' L_AMOUNT INTO ITAB-PSORT.
      ELSE.
        L_AMOUNT = ABS( ITAB-TOTAL ).
        CONCATENATE 'G' L_AMOUNT INTO ITAB-PSORT.
      ENDIF.
      MODIFY ITAB.
    ENDLOOP.
  ELSE.
    LOOP AT ITAB.
      L_AMOUNT = 999999999.
      IF     ITAB-99DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-99DAYS.
        CONCATENATE 'A' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-90DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-90DAYS.
        CONCATENATE 'B' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-60DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-60DAYS.
        CONCATENATE 'C' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-30DAYS > 0.
        L_AMOUNT = L_AMOUNT - ITAB-30DAYS.
        CONCATENATE 'D' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-ZCURRENT > 0.
        L_AMOUNT = L_AMOUNT - ITAB-ZCURRENT.
        CONCATENATE 'E' L_AMOUNT INTO ITAB-PSORT.
      ELSEIF ITAB-ZFUTURE > 0.
        L_AMOUNT = L_AMOUNT - ITAB-ZFUTURE.
        CONCATENATE 'F' L_AMOUNT INTO ITAB-PSORT.
      ELSE.
        L_AMOUNT = ABS( ITAB-TOTAL ).
        CONCATENATE 'G' L_AMOUNT INTO ITAB-PSORT.
      ENDIF.
      MODIFY ITAB.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " ADD_SORT_FIELD
*&---------------------------------------------------------------------*
*&      Form  WRITE_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM WRITE_REPORT.
  PERFORM BUILD_FIELDCAT.
  PERFORM BUILD_SORTCAT.
  PERFORM BUILD_EVENTCAT.
  PERFORM BUILD_LAYOUT.
  PERFORM START_LIST_VIEWER.
ENDFORM.                    " WRITE_REPORT

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT.
* KUNNR
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNA1'.
  FIELDCAT_LN-FIELDNAME          = 'KUNNR'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  fieldcat_ln-emphasize = 'C41'.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Name1
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNA1'.
  FIELDCAT_LN-FIELDNAME          = 'NAME1'.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Credit Limit
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNKK'.
  FIELDCAT_LN-FIELDNAME          = 'KLIMK'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  fieldcat_ln-emphasize = 'C41'.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Total Amount
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = 'TOTAL'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  FIELDCAT_LN-SELTEXT_L          = 'Out.St.Amount'.
  FIELDCAT_LN-SELTEXT_M          = 'Out.St.Amount'.
  FIELDCAT_LN-SELTEXT_S          = 'Out.St.Amount'.
  APPEND FIELDCAT_LN TO FIELDCAT.
  IF P_FUTURE NE 'X'.
* Future
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME        = 'BSID'.
    FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
    FIELDCAT_LN-FIELDNAME          = 'ZFUTURE'.
    FIELDCAT_LN-COL_POS            = COL_POS.
    FIELDCAT_LN-DO_SUM             = 'X'.
    FIELDCAT_LN-HOTSPOT            = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    FIELDCAT_LN-SELTEXT_L          = 'Future'.
    FIELDCAT_LN-SELTEXT_M          = 'Future'.
    FIELDCAT_LN-SELTEXT_S          = 'Future'.
    APPEND FIELDCAT_LN TO FIELDCAT.
  ENDIF.
* Current
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = 'ZCURRENT'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-SELTEXT_L          = 'Current'.
  FIELDCAT_LN-SELTEXT_M          = 'Current'.
  FIELDCAT_LN-SELTEXT_S          = 'Current'.
  APPEND FIELDCAT_LN TO FIELDCAT.
* 30 Days
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = '30DAYS'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-SELTEXT_L          = '30 Days'.
  FIELDCAT_LN-SELTEXT_M          = '30 Days'.
  FIELDCAT_LN-SELTEXT_S          = '30 Days'.
  APPEND FIELDCAT_LN TO FIELDCAT.
* 60 Days
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = '60DAYS'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-SELTEXT_L          = '60 Days'.
  FIELDCAT_LN-SELTEXT_M          = '60 Days'.
  FIELDCAT_LN-SELTEXT_S          = '60 Days'.
  APPEND FIELDCAT_LN TO FIELDCAT.
* 90 Days
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = '90DAYS'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-SELTEXT_L          = '90 Days'.
  FIELDCAT_LN-SELTEXT_M          = '90 Days'.
  FIELDCAT_LN-SELTEXT_S          = '90 Days'.
  APPEND FIELDCAT_LN TO FIELDCAT.
* 99 Days
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = '99DAYS'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  fieldcat_ln-emphasize = 'C41'.
  FIELDCAT_LN-SELTEXT_L          = '120 Days'.
  FIELDCAT_LN-SELTEXT_M          = '120 Days'.
  FIELDCAT_LN-SELTEXT_S          = '120 Days'.
  APPEND FIELDCAT_LN TO FIELDCAT.

* Last Payment Date
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNKK'.
  FIELDCAT_LN-FIELDNAME          = 'CASHD'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.

* Street Name
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNA1'.
  FIELDCAT_LN-FIELDNAME          = 'STRAS'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.

* City Details
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNA1'.
  FIELDCAT_LN-FIELDNAME          = 'ORT01'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.


* Telephone
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNA1'.
  FIELDCAT_LN-FIELDNAME          = 'TELF1'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Credit Group
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNKK'.
  FIELDCAT_LN-FIELDNAME          = 'GRUPP'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Sales Office
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNVV'.
  FIELDCAT_LN-FIELDNAME          = 'VKBUR'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Cust Creat Date
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNA1'.
  FIELDCAT_LN-FIELDNAME          = 'ERDAT'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Del Plant
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNVV'.
  FIELDCAT_LN-FIELDNAME          = 'VWERK'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Sales Group
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'KNVV'.
  FIELDCAT_LN-FIELDNAME          = 'VKGRP'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT.
* Sort Criteria
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'KUNNR'.
  FIELDCAT_LN-FIELDNAME          = 'PSORT'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-SELTEXT_L          = 'Sort Field'.
  FIELDCAT_LN-SELTEXT_M          = 'Sort Field'.
  FIELDCAT_LN-SELTEXT_S          = 'Sort Field'.
  APPEND FIELDCAT_LN TO FIELDCAT.

ENDFORM.                    " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  BUILD_SORTCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_SORTCAT.
*  SORTCAT_LN-SPOS          = '1'.
  SORTCAT_LN-SPOS          = '2'.                           " 0001
  SORTCAT_LN-FIELDNAME     = 'PSORT'.
  SORTCAT_LN-UP            = 'X'.                           " 0001
*  sortcat_ln-subtot        = 'X'.
  APPEND SORTCAT_LN TO SORTCAT.

  CLEAR SORTCAT_LN.
*  SORTCAT_LN-SPOS          = '2'.
*  SORTCAT_LN-FIELDNAME     = 'KUNNR'.
  SORTCAT_LN-SPOS          = '1'.                           " 0001
  SORTCAT_LN-FIELDNAME     = 'NAME1'.                       " 0001
  SORTCAT_LN-UP            = 'X'.
  APPEND SORTCAT_LN TO SORTCAT.

ENDFORM.                    " BUILD_SORTCAT

*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_EVENTCAT.
  EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.
  EVENTCAT_LN-FORM = 'PAGE_HEADER'.
  APPEND EVENTCAT_LN TO EVENTCAT.
ENDFORM.                    " BUILD_EVENTCAT

*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT.
   LAYOUT_IN-COLWIDTH_OPTIMIZE = 'X'.
*  layout_in-no_hotspot        = 'X'.
  LAYOUT_IN-ZEBRA             = 'X'.
  LAYOUT_IN-GET_SELINFOS      = 'X'.
ENDFORM.                    " BUILD_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  START_LIST_VIEWER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM START_LIST_VIEWER.
  DATA: PGM LIKE SY-REPID.
  PGM = SY-REPID.
*  if t_variant[] is initial.
*    t_variant-report = pgm.
*    t_variant-variant = '/ATB'.
*    t_variant-TEXT = '/ATB'.
*    t_variant-DEPENDVARS = 'S'.
*    append t_variant.
*    clear t_variant.
*  endif.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM      = PGM
            I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
            IT_FIELDCAT             = FIELDCAT
            IT_SORT                 = SORTCAT
            IS_LAYOUT               = LAYOUT_IN
            I_SAVE                  = 'A'
*            IS_VARIANT              = t_variant
            IT_EVENTS               = EVENTCAT
       TABLES
            T_OUTTAB                = ITAB
       EXCEPTIONS
            OTHERS                  = 2.

ENDFORM.                    " START_LIST_VIEWER
*-----------------------------------------------------------------------
FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM
                        SELFIELD TYPE SLIS_SELFIELD.
  data l_kunnr(10) type n.
  READ TABLE ITAB INDEX SELFIELD-TABINDEX.
  CHECK SY-SUBRC = 0.
  CASE UCOMM.
    WHEN '&IC1'.
      CASE SELFIELD-SEL_TAB_FIELD.
        WHEN 'ITAB-KUNNR'.
*          SET PARAMETER ID 'KUN' FIELD ITAB-KUNNR.
*          SET PARAMETER ID 'BUK' FIELD P_BUKRS.
          if itab-kunnr co '0123456789 '.
            l_kunnr = itab-kunnr.
            itab-kunnr = l_kunnr.
          endif.
          select single kkber into knkk-kkber
                              from knkk where kunnr = itab-kunnr.
          if sy-subrc eq 0.
            v_kkber = knkk-kkber.
          else.
            clear v_kkber.
          endif.
          refresh sel_tab[].
          MOVE: 'KUNNR' TO SEL_TAB-SELNAME,
                'P'     TO SEL_TAB-KIND,      " PARAMETER
                itab-kunnr   TO SEL_TAB-LOW.
          APPEND SEL_TAB.
          clear sel_tab.
          MOVE: 'KKBER' TO SEL_TAB-SELNAME,
                'P'     TO SEL_TAB-KIND,      " PARAMETER
                v_kkber  TO SEL_TAB-LOW.
          APPEND SEL_TAB.
          clear sel_tab.

          SUBMIT RFDKLI41
                 USING SELECTION-SET 'VAR1'
                 WITH SELECTION-TABLE SEL_TAB
                 AND  RETURN.
*          CALL TRANSACTION 'XD03'.
        WHEN 'ITAB-ZCURRENT'.                               " 0001
          V_DAYS = 'CUR'.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.
        WHEN 'ITAB-ZFUTURE'.
          V_DAYS = 'FUT'.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.
        WHEN 'ITAB-30DAYS'.
          V_DAYS = '30D'.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.
        WHEN 'ITAB-60DAYS'.
          V_DAYS = '60D'.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.
        WHEN 'ITAB-90DAYS'.
          V_DAYS = '90D'.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.
        WHEN 'ITAB-99DAYS'.
          V_DAYS = '99D'.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.
        WHEN 'ITAB-TOTAL'.
          V_DAYS = ' '.
          PERFORM DISPLAY_LINE_ITEM_LEVEL.                  " 0001
      ENDCASE.
  ENDCASE.
ENDFORM.
*----------------------------------------------------------------------*
* PAGE_HEADER
*----------------------------------------------------------------------*
FORM PAGE_HEADER.

  WRITE:/02 'Report:',SY-REPID,
        115 'Time:', SY-TIMLO.

  WRITE: /02 'User:', (10) SY-UNAME,
         115 'Date:', SY-DATUM.


  WRITE: /52 'Customer Aged Trial Balance List',            "0002
         115 'Page:', SY-PAGNO.
  SKIP.
  ULINE /(132).

***
  WRITE: /02 'Open Items as of:', STIDA.

  IF NOT S_VKGRP[] IS INITIAL.
    IF S_VKGRP-HIGH IS INITIAL.
      WRITE: 52 'Sales Group        :',S_VKGRP-LOW.
    ELSE.
      WRITE: 52 'Sales Group        :',S_VKGRP-LOW,'to',S_VKGRP-HIGH.
    ENDIF.
  ELSE.
    WRITE: 52 'Sales Group        : All'.
  ENDIF.

  IF NOT S_GRUPP[] IS INITIAL.
    IF S_GRUPP-HIGH IS INITIAL.
      WRITE: 107 'Credit group :',S_GRUPP-LOW.
    ELSE.
      WRITE: 107 'Credit group :',S_GRUPP-LOW,' to',S_GRUPP-HIGH.
    ENDIF.
  ELSE.
    WRITE: 107 'Credit Group : All'.
  ENDIF.
***
  WRITE: /02 'Comapany Code   :', P_BUKRS.
  IF NOT S_KONDA[] IS INITIAL.
    IF S_KONDA-HIGH IS INITIAL.
      WRITE: 52 'Price group        :',S_KONDA-LOW.
    ELSE.
      WRITE: 52 'Price group        :',S_KONDA-LOW,' to',S_KONDA-HIGH.
    ENDIF.
  ELSE.
    WRITE: 52 'Price Group        : All'.
  ENDIF.

  IF NOT S_CTLPC[] IS INITIAL.
    IF S_CTLPC-HIGH IS INITIAL.
      WRITE: 107 'Risk category:',S_CTLPC-LOW.
    ELSE.
      WRITE: 107 'Risk category:',S_CTLPC-LOW,' to',S_CTLPC-HIGH.
    ENDIF.
  ELSE.
    WRITE: 107 'Risk category: All'.
  ENDIF.
***
  IF NOT S_VKBUR[] IS INITIAL.
    IF S_VKBUR-HIGH IS INITIAL.
      WRITE:/02 'Sales Office    :',S_VKBUR-LOW.
    ELSE.
      WRITE:/02 'Sales Office    :',S_VKBUR-LOW,' to',S_VKBUR-HIGH.
    ENDIF.
  ELSE.
    WRITE:/02 'Sales Office    : All'.
  ENDIF.

  IF NOT S_KDGRP[] IS INITIAL.
    IF S_KDGRP-HIGH IS INITIAL.
      WRITE: 52 'Customer group     :',S_KDGRP-LOW.
    ELSE.
      WRITE: 52 'Customer group     :',S_KDGRP-LOW,' to',S_KDGRP-HIGH.
    ENDIF.
  ELSE.
    WRITE: 52 'Customer group     : All'.
  ENDIF.

  IF NOT S_KTOKD[] IS INITIAL.
    IF S_KTOKD-HIGH IS INITIAL.
      WRITE: 107 'Account Group:',S_KTOKD-LOW.
    ELSE.
      WRITE: 107 'Account Group:',S_KTOKD-LOW,' to',S_KTOKD-HIGH.
    ENDIF.
  ELSE.
    WRITE: 107 'Account Group: All'.
  ENDIF.
***
  IF NOT S_KUNNR[] IS INITIAL.
    IF S_KUNNR-HIGH IS INITIAL.
      WRITE: /02 'Customer No     :',S_KUNNR-LOW.
    ELSE.
      WRITE: /02 'Customer No     :',S_KUNNR-LOW,' to',S_KUNNR-HIGH.
    ENDIF.
  ELSE.
    WRITE: /02 'Customer No     : All'.
  ENDIF.

  IF NOT S_KKBER[] IS INITIAL.
    IF S_KKBER-HIGH IS INITIAL.
      WRITE: 52 'Credit Control Area:',S_KKBER-LOW.
    ELSE.
      WRITE: 52 'Credit Control Area:',S_KKBER-LOW,' to',S_KKBER-HIGH.
    ENDIF.
  ELSE.
    WRITE: 52 'Credit Control Area: All'.
  ENDIF.
  SKIP.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  display_line_item_level
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM DISPLAY_LINE_ITEM_LEVEL.
  REFRESH T_LINE[].
  IF V_DAYS EQ SPACE.
    LOOP AT T_ITEM WHERE KUNNR = ITAB-KUNNR.
      MOVE-CORRESPONDING T_ITEM TO T_LINE.
      APPEND T_LINE.
      CLEAR T_LINE.
    ENDLOOP.
  ELSE.
    LOOP AT T_ITEM WHERE KUNNR = ITAB-KUNNR
                   AND   DAYS = V_DAYS.
      MOVE-CORRESPONDING T_ITEM TO T_LINE.
      APPEND T_LINE.
      CLEAR T_LINE.
    ENDLOOP.
  ENDIF.
  PERFORM BUILD_FIELDCAT_ITEM.
  PERFORM BUILD_SORTCAT_ITEM.
  PERFORM BUILD_EVENTCAT_ITEM.
  PERFORM BUILD_LAYOUT_ITEM.
  PERFORM START_LIST_VIEWER_ITEM.

ENDFORM.                    " display_line_item_level

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT_item
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT_ITEM.
  REFRESH FIELDCAT1.
* DOCU TYPE
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME          = 'BLART'.
  FIELDCAT_LN-FIELDNAME          = 'BLART'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT1.
* REF dOCU
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME          = 'XBLNR'.
  FIELDCAT_LN-FIELDNAME          = 'XBLNR'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT1.

* BILLING dOCU
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME          = 'VBELN'.
  FIELDCAT_LN-FIELDNAME          = 'VBELN'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  APPEND FIELDCAT_LN TO FIELDCAT1.
* Belnr
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-FIELDNAME          = 'BELNR'.
  FIELDCAT_LN-FIELDNAME          = 'BELNR'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-HOTSPOT            = 'X'.
  APPEND FIELDCAT_LN TO FIELDCAT1.
* Budat
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-FIELDNAME          = 'BLDAT'.
  FIELDCAT_LN-FIELDNAME          = 'BLDAT'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT1.

* Total Amount
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'DMBTR'.
  FIELDCAT_LN-FIELDNAME          = 'DMBTR'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  FIELDCAT_LN-DO_SUM             = 'X'.
  FIELDCAT_LN-SELTEXT_L          = 'Amount'.
  FIELDCAT_LN-SELTEXT_M          = 'Amount'.
  FIELDCAT_LN-SELTEXT_S          = 'Amount'.
  APPEND FIELDCAT_LN TO FIELDCAT1.

* zfbdt
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-FIELDNAME          = 'ZFBDT'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT1.
* Total Amount
  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-REF_FIELDNAME      = 'SGTXT'.
  FIELDCAT_LN-FIELDNAME          = 'SGTXT'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT1.

  ADD 1 TO COL_POS.
  CLEAR FIELDCAT_LN.
  FIELDCAT_LN-REF_TABNAME        = 'BSID'.
  FIELDCAT_LN-FIELDNAME          = 'ZUONR'.
  FIELDCAT_LN-COL_POS            = COL_POS.
  APPEND FIELDCAT_LN TO FIELDCAT1.



ENDFORM.                    " BUILD_FIELDCAT_item
*&---------------------------------------------------------------------*
*&      Form  BUILD_SORTCAT_item
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_SORTCAT_ITEM.
  REFRESH SORTCAT1.
  SORTCAT_LN-SPOS          = '1'.
  SORTCAT_LN-FIELDNAME     = 'BLDAT'.
  SORTCAT_LN-UP            = 'X'.
*  sortcat_ln-subtot        = 'X'.
  APPEND SORTCAT_LN TO SORTCAT1.

  CLEAR SORTCAT_LN.
  SORTCAT_LN-SPOS          = '2'.
  SORTCAT_LN-FIELDNAME     = 'BELNR'.
  SORTCAT_LN-UP            = 'X'.
  APPEND SORTCAT_LN TO SORTCAT1.

ENDFORM.                    " BUILD_SORTCAT_item

*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTCAT_item
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_EVENTCAT_ITEM.
  REFRESH EVENTCAT1.
*  EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.
*  EVENTCAT_LN-FORM = 'PAGE_HEADER'.
*  APPEND EVENTCAT_LN TO EVENTCAT1.
ENDFORM.            &n
Saludos.

Atte.,
Enrique Borroni

maito : enrique.borroni@abap.es