Monday, October 8, 2018

ALV FIELD COLORING ON CONDITION

 
 BUSINESS REQ:- ALV FIELD COLORING WHERE NETWEIGHT IS LOWER THAN 2400
*&---------------------------------------------------------------------*
*& Report  ZALVWITHCOLOR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZALVWITHCOLOR.
tablesEKKOEKPO.
TYPE-POOLS:SLIS.
TYPES BEGIN OF ty_ekpo ,
        ebeln  TYPE ebeln ,
        ebelp  TYPE ebelp ,
        matnr  TYPE matnr ,
        werks  TYPE ewerks,
        ntgew type entge ,
        GEWEI   type EGEWE,
        CELLCOLOR TYPE LVC_T_SCOL,
        end of ty_ekpo.

DATA it_ekpo TYPE TABLE OF ty_ekpo,
       wa_ekpo type          ty_ekpo.

**SLIS STRUCTURE*****************
DATAIT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT TYPE SLIS_FIELDCAT_ALV.
**************************************

**FOR LAYOUT AND CELL COLOR AND INDEX
DATAWA_LAYOUT TYPE SLIS_LAYOUT_ALV,
      WA_CELLCOLOR TYPE LVC_S_SCOL,
      LV_INDEX TYPE SY-TABIX.
**************************************
************************************************************
*********SELECT OPTION *************************************
************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:S_EBELN FOR  EKKO-EBELN.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************
START-OF-SELECTION.
IF S_EBELN IS NOT INITIAL.
SELECT EBELN
       EBELP
       MATNR
       WERKS
       NTGEW
       GEWEI
       FROM  EKPO INTO CORRESPONDING FIELDS OF TABLE IT_EKPO WHERE
        EBELN IN S_EBELN .

SORT IT_EKPO BY EBELN .
ENDIF.
 IF IT_EKPO IS NOT INITIAL.
LOOP AT IT_EKPO INTO WA_EKPO .
**TO STORE THE CURRENT ITERATION ****************
 LV_INDEX SY-TABIX.
IF WA_EKPO-NTGEW < 2500.
WA_CELLCOLOR-FNAME 'NTGEW'.
WA_CELLCOLOR-COLOR-COL 6.
WA_CELLCOLOR-COLOR-INT '1'.
WA_CELLCOLOR-COLOR-INV '0'.
APPEND WA_CELLCOLOR TO WA_EKPO-CELLCOLOR.
CLEAR wa_cellcolor.

MODIFY IT_EKPO FROM WA_EKPO INDEX LV_INDEX TRANSPORTING CELLCOLOR.
ENDIF.

ENDLOOP.
ENDIF.

PERFORM FIELDCATLOG.
IF IT_FCAT IS NOT INITIAL.
PERFORM F_BUILD_LAYOUT.
ENDIF .
PERFORM f_Alv_display.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  FIELDCATLOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FIELDCATLOG .

WA_fcat-col_pos        =  1.           "Column
  WA_fcat-fieldname      =  'EBELN'.     "Field Name
  WA_fcat-tabname        =  'IT_EKPO'.   "Internal Table Name
  WA_fcat-seltext_l      =  'Doc. No'.    "Field Text
  APPEND WA_fcat TO IT_FCAT.

  WA_fcat-col_pos        =  2.           "Column
  WA_fcat-fieldname      =  'EBELP'.     "Field Name
  WA_fcat-tabname        =  'IT_EKPO'.   "Internal Table Name
  WA_fcat-seltext_l      =  'Item No'.   "Field Text
  APPEND WA_fcat TO IT_FCAT.
  CLEAR:WA_fcat.


  WA_fcat-col_pos        =  3.           "Column
  WA_fcat-fieldname      =  'WERKS'.     "Field Name
  WA_fcat-tabname        =  'IT_EKPO'.   "Internal Table Name
  WA_fcat-seltext_l      =  'Plant'.     "Field Text
  APPEND WA_fcat TO IT_FCAT.
  CLEAR:WA_fcat.

  WA_fcat-col_pos        =  4.           "Column
  WA_fcat-fieldname      =  'MATNR'.     "Field Name
  WA_fcat-tabname        =  'IT_EKPO'.   "Internal Table Name
  WA_fcat-seltext_l      =  'Material'.  "Field Text
  APPEND WA_fcat TO IT_FCAT.
  CLEAR:WA_fcat.


WA_FCAT-COL_POS '5'.
WA_FCAT-FIELDNAME 'NTGEW'.
WA_FCAT-TABNAME 'IT_EKPO'.
WA_FCAT-SELTEXT_S 'QUANTITY'.
WA_FCAT-DO_SUM 'X'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

 WA_FCAT-COL_POS '6'.
WA_FCAT-FIELDNAME 'GEWEI'.
WA_FCAT-TABNAME 'IT_EKPO'.
WA_FCAT-SELTEXT_M 'UNIT OF MESURE'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
ENDFORM.                    " FIELDCATLOG
*&---------------------------------------------------------------------*
*&      Form  F_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_BUILD_LAYOUT .
WA_LAYOUT-COLWIDTH_OPTIMIZE 'X'.
WA_LAYOUT-COLTAB_FIELDNAME 'CELLCOLOR'.

ENDFORM.                    " F_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  F_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_ALV_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                'sy-repid'
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
   IS_LAYOUT                         =  WA_LAYOUT
    IT_FIELDCAT                       IT_FCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
   I_SAVE                            'A'
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          IT_EKPO
 EXCEPTIONS
   PROGRAM_ERROR                     1
   OTHERS                            2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.                    " F_ALV_DISPLAY