Wednesday, 4 June 2014

Total&Subtotal using oops

*&---------------------------------------------------------------------*
*& Report  ZISU_TEST
*&Developed by : 
*&Date :
*&Request Number 
*&Description : Sample ISU Program To Display billing data Based On BP
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZISU_TEST2.

TABLES ERCH.
CLASS LCL_CLASS DEFINITION DEFERRED.


SELECT-OPTIONS  S_GPAR FOR ERCH-GPARTNER.
INCLUDE ZTOP.





*----------------------------------------------------------------------*
*       CLASS lcl_class DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_CLASS DEFINITION.
  PUBLIC SECTION.
    METHODS : GET_DATA,
              DISPLAY .
ENDCLASS .                    "lcl_class DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_class IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_CLASS IMPLEMENTATION.

  METHOD GET_DATA.
    PERFORM GET_DATA.
  ENDMETHOD.                    "get_data

  METHOD DISPLAY.
    PERFORM DISPLAY.
  ENDMETHOD.                    "display

ENDCLASS.                    "lcl_class IMPLEMENTATION


START-OF-SELECTION.
  DATA : OBJ_DISP TYPE REF TO LCL_CLASS.

  CREATE OBJECT OBJ_DISP.

  CALL METHOD OBJ_DISP->GET_DATA.
  CALL METHOD OBJ_DISP->DISPLAY.









*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .
  SELECT
      GPARTNER
      VKONT
      VERTRAG
      BELNR FROM ERCH INTO TABLE IT_ERCH
    WHERE GPARTNER IN S_GPAR  "P_GPART
    AND SIMULATION = '4'.

  IF  IT_ERCH IS NOT INITIAL .
    SELECT
      BELNR
      NETTOBTR
      PREISBTR FROM DBERCHZ3
      INTO TABLE IT_DBERCHZ3
      FOR ALL ENTRIES IN IT_ERCH
      WHERE BELNR  = IT_ERCH-BELNR.

    SELECT BELNR V_ABRMENGE N_ABRMENGE  FROM DBERCHZ1 INTO TABLE IT_DBERCHZ1 FOR ALL ENTRIES IN IT_ERCH WHERE BELNR = IT_ERCH-BELNR.
  ENDIF.
  LOOP AT IT_ERCH INTO WA_ERCH.
    WA_FINAL-GPARTNER = WA_ERCH-GPARTNER.
    WA_FINAL-VKONT = WA_ERCH-VKONT.
    WA_FINAL-VERTRAG = WA_ERCH-VERTRAG.
    WA_FINAL-BELNR = WA_ERCH-BELNR.

    READ TABLE IT_DBERCHZ1 INTO WA_DBERCHZ1 WITH KEY BELNR = WA_ERCH-BELNR.

    WA_FINAL-QUAN = WA_DBERCHZ1-V_ABRMENGE + WA_DBERCHZ1-N_ABRMENGE.

    READ TABLE IT_DBERCHZ3 INTO WA_DBERCHZ3 WITH KEY BELNR = WA_ERCH-BELNR.
    WA_FINAL-NETTOBTR = WA_DBERCHZ3-NETTOBTR.
    WA_FINAL-PREISBTR = WA_DBERCHZ3-PREISBTR.
    APPEND WA_FINAL TO IT_FINAL.
    CLEAR WA_FINAL.
  ENDLOOP.


ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY .


  DATA : LT_GRID TYPE REF TO CL_SALV_TABLE.

  DATA : LT_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST,
          LT_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS.
  CONSTANTS :GC_TRUE TYPE SAP_BOOL VALUE 'X'.

  DATA : LT_AGGR TYPE REF TO CL_SALV_AGGREGATIONS.
  DATA : LT_SORT TYPE REF TO CL_SALV_SORTS.


  TRY.
      CALL METHOD CL_SALV_TABLE=>FACTORY
*  EXPORTING
*    LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
*    R_CONTAINER    =
*    CONTAINER_NAME =
        IMPORTING
          R_SALV_TABLE   = LT_GRID
        CHANGING
          T_TABLE        = IT_FINAL
          .
    CATCH CX_SALV_MSG .
  ENDTRY.

  LT_FUNCTIONS = LT_GRID->GET_FUNCTIONS( ).
  LT_FUNCTIONS->SET_ALL( GC_TRUE ).

  LT_AGGR = LT_GRID->GET_AGGREGATIONS( ).
  LT_SORT = LT_GRID->GET_SORTS( ).


  TRY.
      CALL METHOD LT_AGGR->ADD_AGGREGATION
        EXPORTING
          COLUMNNAME  =  'NETTOBTR'
          AGGREGATION = IF_SALV_C_AGGREGATION=>TOTAL
**  RECEIVING
**    VALUE       =
          .
    CATCH CX_SALV_DATA_ERROR .
    CATCH CX_SALV_NOT_FOUND .
    CATCH CX_SALV_EXISTING .
  ENDTRY.


*TRY.
DATA : LT_SORT_COLUMN TYPE REF TO CL_SALV_SORT.
CALL METHOD LT_SORT->ADD_SORT
  EXPORTING
    COLUMNNAME = 'GPARTNER'
*    POSITION   =
*    SEQUENCE   = IF_SALV_C_SORT=>SORT_UP
*    SUBTOTAL   = IF_SALV_C_BOOL_SAP=>FALSE
*    GROUP      = IF_SALV_C_SORT=>GROUP_NONE
*    OBLIGATORY = IF_SALV_C_BOOL_SAP=>FALSE
  RECEIVING
    VALUE      = LT_SORT_COLUMN
    .
* CATCH CX_SALV_NOT_FOUND .
* CATCH CX_SALV_EXISTING .
* CATCH CX_SALV_DATA_ERROR .
*ENDTRY.

*TRY.
CALL METHOD LT_SORT_COLUMN->SET_SUBTOTAL
  EXPORTING
    VALUE  = IF_SALV_C_BOOL_SAP=>TRUE
    .
* CATCH CX_SALV_DATA_ERROR .
*ENDTRY.

  LT_DISPLAY = LT_GRID->GET_DISPLAY_SETTINGS( ).
  LT_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ).


  LT_GRID->DISPLAY( ).


**  LT_AGGR->SET_AGGREGATION_BEFORE_ITEMS( ).




ENDFORM.                    " DISPLAY

No comments:

Post a Comment