Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Example ABAP Code to colour Selected row in ALV

*&---------------------------------------------------------------------*
*& Report ZSACHIN_ALV_DEEP32

REPORT ZSACHIN_ALV_DEEP32.

TABLES: MARA.

TYPE-POOLS: SLIS.

DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,

* create a field of 4 char to fill the color
WA_COLOR(4) TYPE C,

END OF ITAB.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

* create a field symbol to add color for the selected row
FIELD-SYMBOLS: LIKE ITAB.

DATA: gd_layout type slis_layout_alv.

START-OF-SELECTION.


SELECT MATNR ERSDA ERNAM FROM MARA INTO TABLE ITAB UP TO 100 ROWS.



WA_FIELDCAT-SELTEXT_L = 'MATERIAL NUMBER'.
WA_FIELDCAT-COL_POS = '1'.
WA_FIELDCAT-TABNAME = 'MARA'.
WA_FIELDCAT-hotspot = 'X'.
WA_FIELDCAT-no_zero = 'X'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.

APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-SELTEXT_L = 'Created On'.
WA_FIELDCAT-COL_POS = '2'.
WA_FIELDCAT-TABNAME = 'MARA'.
WA_FIELDCAT-FIELDNAME = 'ERSDA'.
WA_FIELDCAT-emphasize = 'C110'.

APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-SELTEXT_L = 'Name of Person'.
WA_FIELDCAT-COL_POS = '3'.
WA_FIELDCAT-TABNAME = 'MARA'.
WA_FIELDCAT-FIELDNAME = 'ERNAM'.
WA_FIELDCAT-just = 'R'.
*WA_FIELDCAT-emphasize = 'C600'.

APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.


* loop through thetable to update the color forthe selected row
LOOP AT ITAB ASSIGNING .

IF SY-TABIX = '5'.
-WA_COLOR = 'C311'.
ENDIF.

ENDLOOP.




*PERFORM GET_EVENTS.

* Give the name field in which we have filled the color code
gd_layout-info_fieldname = 'WA_COLOR'.
gd_layout-zebra = 'X'.

*GD_LAYOUT-edit = 'X'. " this will make the alv editable
" and for each record make a box on left side
GD_LAYOUT-no_vline = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = 'X'
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = 'ZSACHIN1111'
I_CALLBACK_USER_COMMAND = 'FRM_USR_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME = MARA etc
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'TITLE OF THE GRID'
* I_GRID_SETTINGS =
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'A'
* IS_VARIANT = i_varient1
* 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 = ITAB
EXCEPTIONS

PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


*FORM SAC_LAYOUT.


*ENDFORM.


FORM FRM_USR_COMMAND USING OK_CODE TYPE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD .

CASE OK_CODE.

WHEN 'PICK'.

READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.


PERFORM CALL_TRANS USING ITAB-MATNR.

ENDCASE.

ENDFORM.


FORM CALL_TRANS USING MATNR.

SET PARAMETER ID 'MAT' FIELD MATNR. "Global memory sap memory.

CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

ENDFORM.


form PFSTATUS.

*SET PF-STATUS 'ZSACHIN1111'.

ENDFORM.

FORM TOP_OF_PAGE.

WRITE: 'SACHIN THE BOND'.

ENDFORM.

No comments:

Post a Comment

Google
 

Subscribe Here

AddThis Feed Button