Monday, December 20, 2010
Define COLOR field(type c length) in ITAB to be displayed using REUSE_LIST_DISPLAY. Pass COLOR field name through w_layout-info_fieldname. Use USER_COMMAND to display color for the selected row on ALV output.
 
REPORT  zvenkat_alv_list.
*&---------------------------------------------------------------------*
*&  Declarations
*&---------------------------------------------------------------------*
DATA: 
  BEGIN OF i_mard OCCURS 0,
    color(3) TYPE c,  "color
    werks TYPE mard-werks,
    lgort TYPE mard-lgort,
    matnr TYPE mard-matnr,
    insme TYPE mard-insme,
    einme TYPE mard-einme,
    speme TYPE mard-speme,
  END OF i_mard.
* Types Pools
TYPE-POOLS:
  slis.
* Types
TYPES:
  t_fieldcat         TYPE slis_fieldcat_alv,
  t_events           TYPE slis_alv_event,
  t_layout           TYPE slis_layout_alv.
* Workareas
DATA:
  w_fieldcat         TYPE t_fieldcat,
  w_events           TYPE t_events,
  w_layout           TYPE t_layout.
* Internal Tables
DATA:
  i_fieldcat         TYPE STANDARD TABLE OF t_fieldcat,
  i_events           TYPE STANDARD TABLE OF t_events.

*&---------------------------------------------------------------------*
*& Start-of-selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM get_data_from_database .
  PERFORM build_fieldcatalog.
  w_layout-info_fieldname = 'COLOR'. "color
  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  get_data_from_database
*&---------------------------------------------------------------------*
FORM get_data_from_database .
  CLEAR :i_mard,i_mard[].
  SELECT werks lgort matnr insme einme speme
  FROM mard
  INTO CORRESPONDING FIELDS OF TABLE i_mard
  UP TO 100 ROWS.
ENDFORM.                    " get_data_from_database
*&---------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&---------------------------------------------------------------------*
FORM build_fieldcatalog .
  CLEAR :w_fieldcat,i_fieldcat[].
  PERFORM build_fcat USING:
  "Field   Int Tab  Text
  'WERKS' 'I_MARD' 'WERKS',
  'LGORT' 'I_MARD' 'LGORT',
  'MATNR' 'I_MARD' 'MATNR',
  'INSME' 'I_MARD' 'INSME',
  'EINME' 'I_MARD' 'EINME',
  'SPEME' 'I_MARD' 'SPEME'.
ENDFORM.                    " build_fieldcatalog
*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data .
  DATA :program LIKE sy-repid VALUE sy-repid.
  SORT i_mard BY werks.
  DELETE ADJACENT DUPLICATES FROM i_mard COMPARING werks.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program      = program
      i_callback_user_command = 'USER_COMMAND'
      is_layout               = w_layout
      it_fieldcat             = i_fieldcat
      it_events               = i_events
    TABLES
      t_outtab                = i_mard.
ENDFORM.                    " display_data
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT
*&---------------------------------------------------------------------*
FORM build_fcat  USING  l_field l_tab l_text.
  w_fieldcat-fieldname = l_field.
  w_fieldcat-tabname   = l_tab.
  w_fieldcat-seltext_m = l_text.
  IF l_field = 'WERKS'.
    w_fieldcat-hotspot = 'X'.
  ENDIF.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.
ENDFORM.                    " BUILD_FCAT
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
  IF r_ucomm = '&IC1'.
    READ TABLE i_mard WITH KEY werks = rs_selfield-value.
    IF sy-subrc = 0.
      i_mard-color = 'C31'.
      MODIFY i_mard INDEX sy-tabix.
    ENDIF.
    rs_selfield-refresh = 'X'.
  ENDIF.
ENDFORM.                    "USER_COMMAND


0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.