Search on this Website

Tuesday, September 30, 2008

Example ABAP Code to colour individual box in ALV

REPORT ZSACHIN_ALV_DEEP33.


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 CELL of type SLIS_T_SPECIALCOL_ALV
CELL TYPE SLIS_T_SPECIALCOL_ALV,
END OF ITAB.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
* Create a work area of type SLIS_T_SPECIALCOL_ALV
DATA: FS_CELL LIKE LINE OF ITAB-CELL.

* Create a layout
DATA: gd_layout type slis_layout_alv.

*-----------------------------------------------------------------*
* START OF SELECTION *
*-----------------------------------------------------------------*

START-OF-SELECTION.

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

*-----------------------------------------------------------------*
* Creating field catalog *
*-----------------------------------------------------------------*

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 = 'C611'.

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.


* Fill the workarea with the field to be colored,
* the color to be appeared
* and give NOKEYCOL = 'X'.

FS_CELL-FIELDNAME = 'ERSDA'.
FS_CELL-COLOR-COL = 3.
FS_CELL-NOKEYCOL = 'X'.
APPEND FS_CELL TO ITAB-CELL.

* To the specific row modify the contents of the CELL
MODIFY ITAB INDEX 8 TRANSPORTING CELL.


*PERFORM GET_EVENTS.


gd_layout-info_fieldname = 'WA_COLOR'.
gd_layout-zebra = 'X'.

* Give the name field in which we have filled the color code
gd_LAYOUT-COLTAB_FIELDNAME = 'CELL'.

*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: