Hotspot in ALV with OOABAP factory methods

Insert hotspot into ALV columns using factory methods, example ALV report with hotspot factory methods

+ -
The below example explains you how to insert hotspot in a column using factory methods.
Step 1: Data deceleration, get alv factory instance.
REPORT ZSAPN_ALV_MARA_FACTORY.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
       WA_MARA TYPE MARA.
DATA : LR_ALV TYPE REF TO CL_SALV_TABLE.
SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.
*  TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY "get SALV factory instance
*    EXPORTING
*      LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
*      R_CONTAINER    =
*      CONTAINER_NAME =
  IMPORTING
    R_SALV_TABLE = LR_ALV
  CHANGING
    T_TABLE      = IT_MARA.
*   CATCH CX_SALV_MSG .
*  ENDTRY.

Step 2: Get ALV Columns using GET_COLUMNS method.

**get ALV columns
DATA : LR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE. "columns instance
CALL METHOD LR_ALV->GET_COLUMNS  "get all columns
  RECEIVING
    VALUE = LR_COLUMNS.

Step 3: Get single column to add hotspot.

DATA : LR_COL TYPE REF TO CL_SALV_COLUMN_TABLE. "column instance
  TRY.
      LR_COL ?= LR_COLUMNS->GET_COLUMN( 'MATNR' ). "get MATNR columns to insert hotspot
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

Step 4:Insert hotspot into column using SET_CELL_TYPE method.

*   Set the Hotspot for MATNR Column
  TRY.
      CALL METHOD LR_COL->SET_CELL_TYPE "set cell type hotspot
        EXPORTING
          VALUE = IF_SALV_C_CELL_TYPE=>HOTSPOT.
      .
    CATCH CX_SALV_DATA_ERROR .
  ENDTRY.

Step5: Display ALV .

LR_ALV->DISPLAY( ). "display grid

Final code will be

REPORT ZSAPN_ALV_MARA_FACTORY.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
       WA_MARA TYPE MARA.
DATA : LR_ALV TYPE REF TO CL_SALV_TABLE.
SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.
*  TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY "get SALV factory instance
*    EXPORTING
*      LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
*      R_CONTAINER    =
*      CONTAINER_NAME =
  IMPORTING
    R_SALV_TABLE = LR_ALV
  CHANGING
    T_TABLE      = IT_MARA.
*   CATCH CX_SALV_MSG .
*  ENDTRY.

**get ALV columns
DATA : LR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE. "columns instance
DATA : LR_COL TYPE REF TO CL_SALV_COLUMN_TABLE. "column instance
CALL METHOD LR_ALV->GET_COLUMNS  "get all columns
  RECEIVING
    VALUE = LR_COLUMNS.
IF LR_COLUMNS IS NOT INITIAL.
*TRY.
*   Get VBELN column
  TRY.
      LR_COL ?= LR_COLUMNS->GET_COLUMN( 'MATNR' ). "get MATNR columns to insert hotspot
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.
*
*   Set the Hotspot for MATNR Column
  TRY.
      CALL METHOD LR_COL->SET_CELL_TYPE "set cell type hotspot
        EXPORTING
          VALUE = IF_SALV_C_CELL_TYPE=>HOTSPOT.
      .
    CATCH CX_SALV_DATA_ERROR .
  ENDTRY.
ENDIF.
LR_ALV->DISPLAY( ). "display grid

Out put of ALV using factory method

Hotspot in ALV using factory methods

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 30 People out of 30 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →