Friday, September 7, 2018

HIDING/UNHIDE PARTICLUAR FIELD IN ALV USING OOABAP.

HIDING/UNHIDE PARTICLUAR FIELD IN ALV USING OOABAP.

In  this tutorial , we are simply hiding the particular field , for this there we have used to two classes ,look carefully at there names , there's a very small difference , one is used to get all the columns while the other is used to get the particular column.
when we have got the column name
**accessing the super class data so we are using ?= it's an example of widing casting 
LO_COLUMN ?= LO_COLUMNS->GET_COLUMN(
                                    COLUMNNAME 'MATNR'
                                    ).
we now need to hide or unhide the field , if you set it true , it will show up.
                      LO_COLUMN->SET_VISIBLE(
                       VALUE IF_SALV_c_BOOL_SAP=>FALSE ).
*&---------------------------------------------------------------------*
*& Report  ZALVWITHTTOOLBAR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZALVWITHTTOOLBAR.
TYPES:BEGIN OF  TY_MARA,
      MATNR TYPE MARA-MATNR,
      ERNAM TYPE MARA-ERNAM,
      END OF TY_MARA.

DATAIT_MARA TYPE TABLE OF TY_MARA.
SELECT MATNR
       ERNAM
       FROM MARA INTO TABLE IT_MARA UP TO 20 ROWS.

DATAOO_ALV TYPE REF TO CL_SALV_TABLE.

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

DATALO_FUNCTION TYPE REF TO CL_SALV_FUNCTIONS_LIST.
LO_FUNCTION  OO_ALV->GET_FUNCTIONS).
LO_FUNCTION->SET_ALLABAP_TRUE ).
DATA:LO_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS.
LO_DISPLAY OO_ALV->GET_DISPLAY_SETTINGS).
LO_DISPLAY->SET_LIST_HEADERVALUE ' MATERIAL DETAILS').
LO_DISPLAY->SET_STRIPED_PATTERNVALUE 'X').


********for optimizing the column width , we are going to use set_optimize method
data:LO_COLUMNS TYPE REF TO  CL_SALV_COLUMNS_TABLE.
LO_COLUMNS OO_ALV->GET_COLUMNS).  "GETTING THE COLUMNS "
LO_COLUMNS->SET_OPTIMIZE).         " OPTIMISING THE COLUMNS

*************now hiding the particular field , in our case we are  hiding  matnr
DATALO_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.
**accessing the super class data so we are using ?= it's an example of widing casting
LO_COLUMN ?= LO_COLUMNS->GET_COLUMN(
                                    COLUMNNAME 'MATNR'
                                    ).
LO_COLUMN->SET_VISIBLE(
                       VALUE IF_SALV_c_BOOL_SAP=>FALSE ).

OO_ALV->DISPLAY).