Welcome To My BLOG

This site is to give a brief idea for the abap learners who are looking for some real time programs .It consists of collection of programs from my side . I hope these programs are very much used for all of the learners. Please check the links for any information in ABAP.
Please vote for my Blog. And please input me on this mail addrssess.Email me

Share this link with your friends

http://www.rebtel.com/u/15163104576

For every friend who signs up using this link and makes a payment, we'll give you 8 €!


Wednesday, September 22, 2010

Coloring a Row and Column in ALV (OOPS)

Coloring a Row
Step 1: Include a field called rowcolor in output internal table.
types : begin of ty.
include structure MARA.
Types : rowcolor(4) TYPE c,
end of ty.
data : itab type standard table of ty,"Output Internal table
wa type ty.
Step 2: Setting the layout accordingly
Data w_layout TYPE lvc_s_layo."Layout structure
* Setting layout
w_layout-info_fname = 'ROWCOLOR'."For row coloring
Step 3: Coloring the specific row * Colouring a row
CLEAR wa.
READ TABLE itab INTO wa INDEX 3.
IF sy-subrc EQ 0.
wa-rowcolor = 'C311'.
MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr.
ENDIF.
Step4: Pass the layout also in the method set_table_for_first_display
* Displaying the output
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
IS_VARIANT = w_variant
I_SAVE = 'A'
is_layout = w_layout
CHANGING
it_outtab = itab
IT_FIELDCATALOG = i_fieldcat
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Complete Code for Coloring a Row
Screen 9000,GUI Status ZSTATUS and GUI Title ZTITLE should be created and in FLow logic of the screen, PBO and PAI should be uncommented.
types : begin of ty. include structure MARA.
types : rowcolor(4) TYPE c,
end of ty.
data : itab type standard table of ty,"Output Internal table
i_fieldcat type standard table of lvc_s_fcat,"Field catalog
wa type ty,
w_variant type disvariant,
w_layout TYPE lvc_s_layo,"Layout structure
o_docking type ref to cl_gui_docking_container,"Docking Container
o_grid type ref to cl_gui_alv_grid."Grid
select * from mara into corresponding fields of table itab up to 10 rows.
call screen 9000.
&---------------------------------------------------------------------
*& Module STATUS_9000 OUTPUT
&---------------------------------------------------------------------
* text
----------------------------------------------------------------------
module STATUS_9000 output. if o_docking is initial.
SET PF-STATUS 'ZSTATUS'. "GUI Status
SET TITLEBAR 'ZTITLE'. "TitleCreating Docking Container
CREATE OBJECT o_docking
EXPORTING
RATIO = '95'.
IF sy-subrc eq 0.Creating Grid
CREATE OBJECT o_grid
EXPORTING
i_parent = o_docking.
ENDIF.Filling the fieldcatalog table
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
w_variant-report = sy-repid.Setting layout
w_layout-info_fname = 'ROWCOLOR'."For row coloringColouring a row
CLEAR wa.
READ TABLE itab INTO wa INDEX 3.
IF sy-subrc EQ 0.
wa-rowcolor = 'C311'.
MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr.
ENDIF.Displaying the output
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
IS_VARIANT = w_variant
I_SAVE = 'A'
is_layout = w_layout
CHANGING
it_outtab = itab
IT_FIELDCATALOG = i_fieldcat
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.endif.endmodule. " STATUS_9000 OUTPUT
&---------------------------------------------------------------------
*& Module USER_COMMAND_9000 INPUT
&---------------------------------------------------------------------
* PAI
----------------------------------------------------------------------
module USER_COMMAND_9000 input.
data lv_ucomm type sy-ucomm.
lv_ucomm = sy-ucomm.
CASE lv_ucomm.
WHEN 'CANCEl' OR 'EXIT'.
perform free_objects.
LEAVE PROGRAM.
when 'BACK'.
perform free_objects.
set screen '0'.
leave screen.
ENDCASE.
endmodule. " USER_COMMAND_9000 INPUT
&---------------------------------------------------------------------
*& Form free_objects
&---------------------------------------------------------------------
* Free Objects
----------------------------------------------------------------------
form free_objects .
CALL METHOD o_grid->free
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD o_docking->free
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform. " free_objects

Output

Procedure
Coloring a Column
* Declaring field symbols
FIELD-SYMBOLS : TYPE lvc_s_fcat.
* Modifying the fieldcatalog for coloring a column
LOOP AT i_fieldcat ASSIGNING .
CASE -fieldname.
WHEN 'MATNR'.
* Make the field as non-key so that color should take effect
-key = ' '.
* Coloring a column
-emphasize = 'C311'.
ENDCASE.
ENDLOOP.
Complete Code for Coloring a Column
Screen 9000,GUI Status ZSTATUS and GUI Title ZTITLE should be created and in FLow logic of the screen, PBO and PAI should be uncommented.
data : itab type standard table of MARA,"Output Internal table i_fieldcat type standard table of lvc_s_fcat,"Field catalog wa type MARA,
w_variant type disvariant,
w_layout TYPE lvc_s_layo,"Layout structure
o_docking type ref to cl_gui_docking_container,"Docking Container
o_grid type ref to cl_gui_alv_grid."GridDeclaring field symbols
FIELD-SYMBOLS : TYPE lvc_s_fcat.
select * from mara into corresponding fields of table itab up to 10 rows.
call screen 9000.
&---------------------------------------------------------------------
*& Module STATUS_9000 OUTPUT
&---------------------------------------------------------------------
* text
----------------------------------------------------------------------
module STATUS_9000 output.if o_docking is initial.
SET PF-STATUS 'ZSTATUS'. "GUI Status
SET TITLEBAR 'ZTITLE'. "TitleCreating Docking Container
CREATE OBJECT o_docking
EXPORTING
RATIO = '95'.
IF sy-subrc eq 0.Creating Grid
CREATE OBJECT o_grid
EXPORTING
i_parent = o_docking.
ENDIF.Filling the fieldcatalog table
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
w_variant-report = sy-repid.Modifying the fieldcatalog for coloring a column
LOOP AT i_fieldcat ASSIGNING .
CASE -fieldname.
WHEN 'MATNR'.
-key = ' '."Make the field as non-key so that color should take effectColoring a column
-emphasize = 'C311'.
ENDCASE.
ENDLOOP.Displaying the output
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
IS_VARIANT = w_variant
I_SAVE = 'A'
CHANGING
it_outtab = itab
IT_FIELDCATALOG = i_fieldcat
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.endif.endmodule. " STATUS_9000 OUTPUT
&---------------------------------------------------------------------
*& Module USER_COMMAND_9000 INPUT
&---------------------------------------------------------------------
* PAI
----------------------------------------------------------------------
module USER_COMMAND_9000 input.
data lv_ucomm type sy-ucomm.
lv_ucomm = sy-ucomm.
CASE lv_ucomm.
WHEN 'CANCEl' OR 'EXIT'.
perform free_objects.
LEAVE PROGRAM.
when 'BACK'.
perform free_objects.
set screen '0'.
leave screen.
ENDCASE.
endmodule. " USER_COMMAND_9000 INPUT
&---------------------------------------------------------------------
*& Form free_objects
&---------------------------------------------------------------------
* Free Objects
----------------------------------------------------------------------
form free_objects .
CALL METHOD o_grid->free
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD o_docking->free
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Output

Colorconstants
Use this Type-Pool to have "speaking constants" for your colorcodes.
TYPE-POOL ZCOL .

constants:
zcol_greyblue(04) type c value 'C100',
zcol_lightgrey(04) type c value 'C200',
zcol_yellow(04) type c value 'C300',
zcol_bluegreen(04) type c value 'C400',
zcol_green(04) type c value 'C500',
zcol_red(04) type c value 'C600',
zcol_violett(04) type c value 'C700',

zcol_greyblue_int(04) type c value 'C110',
zcol_lightgrey_int(04) type c value 'C210',
zcol_yellow_int(04) type c value 'C310',
zcol_bluegreen_int(04) type c value 'C410',
zcol_green_int(04) type c value 'C510',
zcol_red_int(04) type c value 'C610',
zcol_violett_int(04) type c value 'C710',

zcol_greyblue_inv(04) type c value 'C101',
zcol_lightgrey_inv(04) type c value 'C201',
zcol_yellow_inv(04) type c value 'C301',
zcol_bluegreen_inv(04) type c value 'C401',
zcol_green_inv(04) type c value 'C501',
zcol_red_inv(04) type c value 'C601',
zcol_violett_inv(04) type c value 'C701',

zcol_greyblue_int_inv(04) type c value 'C111',
zcol_lightgrey_int_inv(04) type c value 'C211',
zcol_yellow_int_inv(04) type c value 'C311',
zcol_bluegreen_int_inv(04) type c value 'C411',
zcol_green_int_inv(04) type c value 'C511',
zcol_red_int_inv(04) type c value 'C611',
zcol_violett_int_inv(04) type c value 'C711'.
Create this Type-Pool with transaction SE11.

No comments: