14/05/2013

Display the list of cost centers for the given range of controlling areas

*&---------------------------------------------------------------------*
*& Report  Z_ALV_REPORT_COST_CENTER
*&
*&---------------------------------------------------------------------*
*&
*&Author    tech.sap29@gmail.com
*&---------------------------------------------------------------------*

REPORT  Z_ALV_REPORT_COST_CENTER.
TYPE-POOLS SLIS.
TYPES : BEGIN OF TY_CSKS,
        KOKRS TYPE CSKS-KOKRS,
        KOSTL TYPE CSKS-KOSTL,
        DATBI TYPE CSKS-DATBI,
        DATAB TYPE CSKS-DATAB,
        BKZKP TYPE CSKS-BKZKP,
        PKZKP TYPE CSKS-PKZKP,
        BUKRS TYPE CSKS-BUKRS,
        GSBER TYPE CSKS-GSBER,
        KOSAR TYPE CSKS-KOSAR,
        VERAK TYPE CSKS-VERAK,
        VERAK_USER TYPE CSKS-VERAK_USER,
        END OF TY_CSKS.

TYPES : BEGIN OF TY_T001,
        BUKRS TYPE BUKRS ,
        END OF TY_T001.

DATA : IT_T001 TYPE TABLE OF TY_T001.

DATA : IT_CSKS TYPE TABLE OF TY_CSKS ,
       WA_CSKS TYPE          TY_CSKS ,
       IT_EVENT TYPE SLIS_T_EVENT ,
       WA_EVENT LIKE LINE OF IT_EVENT .
*******************************************************

START-OF-SELECTION .

PERFORM GET_DATA .
PERFORM FILL_EVENT .

END-OF-SELECTION.

PERFORM DISPALY_DATA.


*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*

FORM GET_DATA .
SELECT  KOKRS
        KOSTL
        DATBI
        DATAB
        BKZKP
        PKZKP
        BUKRS
        GSBER
        KOSAR
        VERAK
        VERAK_USER FROM CSKS INTO TABLE IT_CSKS UP TO 20 ROWS.
ENDFORM.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  FILL_EVENT
*&---------------------------------------------------------------------*

FORM FILL_EVENT .
CLEAR WA_EVENT .
WA_EVENT-NAME   =   'TOP_OF_PAGE'.
WA_EVENT-FORM   =   'PRINT_HEADING'.
APPEND WA_EVENT TO IT_EVENT.

WA_EVENT-NAME   =   'USER_COMMAND'.
WA_EVENT-FORM   =   'VALIDATE_COMMAND'.
APPEND WA_EVENT TO IT_EVENT.

ENDFORM.                    " FILL_EVENT

*&---------------------------------------------------------------------*
*&      Form  DISPALY_DATA
*&---------------------------------------------------------------------*

FORM DISPALY_DATA .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                 = SY-CPROG
   I_STRUCTURE_NAME                  = 'CSKS'
    IT_EVENTS                         = IT_EVENT
  TABLES
    T_OUTTAB                          = IT_CSKS
* 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.                    " DISPALY_DATA

FORM PRINT_HEADING .
DATA : IT_HEADING TYPE SLIS_T_LISTHEADER,
       WA_HEADING LIKE LINE OF IT_HEADING .
WA_HEADING-TYP  = 'H'.
WA_HEADING-INFO = 'COST CENTER RANGE OF CONTROLLING AREAS'.
APPEND WA_HEADING TO IT_HEADING .

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
    IT_LIST_COMMENTARY       = IT_HEADING
*   I_LOGO                   =
*   I_END_OF_LIST_GRID       =
*   I_ALV_FORM               =
          .

ENDFORM.

FORM VALIDATE_COMMAND USING UCOMM TYPE SY-UCOMM
                            SEL_DET TYPE SLIS_SELFIELD.

CASE UCOMM.
    WHEN  '&IC1' .      "DOUBLE CLICK EVENT
        IF SEL_DET-SEL_TAB_FIELD = '7-BUKRS'.
          SELECT KOKRS FROM CSKS INTO TABLE IT_T001 WHERE BUKRS = SEL_DET-VALUE .

           CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              I_CALLBACK_PROGRAM                 = SY-CPROG
              I_STRUCTURE_NAME                   = 'CSKS'
              IT_EVENTS                         = IT_EVENT
             TABLES
               T_OUTTAB                          = IT_T001
*            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.
ENDIF.
ENDCASE.

ENDFORM  .

No comments:

Post a Comment