Skip to Content
0
Former Member
Mar 29, 2013 at 06:32 AM

Color a particular cell in alv grid when there are more than one table

16 Views

Hi Experts,

I want to color a particular cell in ALV report based a condition. The answers are given on many sites but they have only one internal table which they have passed in reuse_alv_grid_display.

In my report, there are 3 structures which have corresponding internal tables. Bsid, bsad and final table. I have passed it_Final in the reuse FM.

Whenever I add CELLCOLOR TYPE LVC_T_SCOL, to my final structure, it gives an error of incompatible structure on the following line:

it_final[] = it_bsad[].

How should I do it? Following is the code. Please guide.

*&---------------------------------------------------------------------*

*& Report Zcustout

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT Zrough.

tables: bsad, bsid, kna1.

TYPE-POOLS: slis.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid,

bal type p decimals 2.

DATA:

T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FS_FIELDCAT LIKE LINE OF T_FIELDCAT,

FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,

W_COLOR(3) ,

W_ROW TYPE I,

W_FIELDNAME(20),

W_PROG TYPE SY-REPID.

data: begin of ty_bsad,

bukrs type bukrs,

kunnr type kunnr,

budat type budat,

wrbtr type wrbtr,

belnr type belnr_d,

shkzg type SHKZG,

end of ty_bsad.

*data dr1 type i.

types: begin of ty_bsid,

bukrs type bukrs,

kunnr type kunnr,

budat type budat,

wrbtr type wrbtr,

belnr type belnr_d,

shkzg type SHKZG,

end of ty_bsid.

types: begin of ty_kna1,

kunnr type kna1-kunnr,

name1 type kna1-name1,

name2 type kna1-name2,

name3 type kna1-name3,

end of ty_kna1.

*data: op_bal type p DECIMALS 2,

* bsad_wrbtr TYPE p DECIMALS 2,

* bsid_wrbtr type p DECIMALS 2.

data: begin of ty_final,

bukrs type bukrs,

kunnr type kunnr,

budat type budat,

wrbtr type wrbtr,

belnr type belnr_d,

shkzg type SHKZG,

budat1 type budat,

wrbtr1 type wrbtr,

dr type p decimals 2,

cr type p decimals 2,

sno type sy-tabix,

name1 type kna1-name1,

name2 type kna1-name2,

name3 type kna1-name3,

balance type p decimals 2,

op_bal type p decimals 2,

* COLOR(3),

*CHECKBOX ,

*CELL TYPE SLIS_T_SPECIALCOL_ALV,

end of ty_final.

*data: begin of ty_colour,

* CELLCOLOR TYPE LVC_T_SCOL,

* END OF ty_colour.

* data: it_colour type STANDARD TABLE OF ty_colour,

* wa_colour type ty_colour.

DATA: it_final1 TYPE STANDARD TABLE OF bapi3007_2,

wa_final1 TYPE bapi3007_2.

data: dr type bapi3007_2-lc_amount,

cr type bapi3007_2-lc_amount,

dr1 type bapi3007_2-lc_amount,

cr1 type bapi3007_2-lc_amount.

* op_bal type bapi3007_2-lc_amount.

*types: beg

data: it_bsad like standard table of ty_bsad,

it_bsid type standard table of ty_bsid,

it_kna1 type standard table of ty_kna1,

it_final like standard table of ty_final.

* * it_final1 type standard table of ty_final1.

data: wa_bsad like ty_bsad,

wa_bsid type ty_bsid,

wa_kna1 type ty_kna1,

wa_Final like ty_final.

* wa_final1 type ty_final1.

DATA: w_fcat TYPE slis_fieldcat_alv.

DATA: t_fcat TYPE slis_t_fieldcat_alv.

data: wa_layout type slis_layout_alv.

* data: op_bal_v type i.

CONSTANTS: c_bsad TYPE slis_tabname VALUE 'WA_BSAD'.

CONSTANTS: c_bsid TYPE slis_tabname VALUE 'WA_BSID'.

DATA: w_keyinfo TYPE slis_keyinfo_alv.

select-options: s_bukrs for bsad-bukrs no INTERVALS no-EXTENSION,

s_kunnr for bsad-kunnr no INTERVALS no-EXTENSION.

select-options: s_date for bsad-budat no-EXTENSION.

"top_of_page

FORM TOP-OF-PAGE.

*ALV Header declarations

DATA: T_HEADER TYPE SLIS_T_LISTHEADER,

WA_HEADER TYPE SLIS_LISTHEADER,

T_LINE LIKE WA_HEADER-INFO,

LD_LINES TYPE I,

LD_LINESC(10) TYPE C.

* Title

WA_HEADER-TYP = 'H'.

WA_HEADER-INFO = 'Customer Outstanding Report'.

APPEND WA_HEADER TO T_HEADER.

CLEAR WA_HEADER.

wa_header-typ = 'S'.

wa_header-key = 'Opening Balance'.

wa_header-info = wa_final-op_bal.

append wa_header to t_header.

clear wa_header.

describe table it_final lines ld_lines.

ld_linesc = ld_lines.

concatenate 'Total No. of Records Selected: ' ld_linesc

into t_line separated by space.

wa_header-typ = 'A'.

wa_header-info = t_line.

append wa_header to t_header.

clear: wa_header, t_line.

* Date

WA_HEADER-TYP = 'S'.

WA_HEADER-KEY = 'Date: '.

CONCATENATE SY-DATUM+6(2) '.'

SY-DATUM+4(2) '.'

SY-DATUM(4) INTO WA_HEADER-INFO. "todays date

APPEND WA_HEADER TO T_HEADER.

CLEAR: WA_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = T_HEADER

i_logo = 'NATIONAL'.

ENDFORM. "top-of-page

start-of-selection.

*break-point.

select bukrs

kunnr

budat

wrbtr

belnr

shkzg

from bsad

into table it_bsad

where bukrs in s_bukrs and kunnr in s_kunnr and budat in s_date.

select bukrs

kunnr

budat

wrbtr

belnr

shkzg

into table it_bsid

from bsid

* for all entries in it_bsad

where bukrs in s_bukrs and kunnr in s_kunnr and budat in s_date.

it_final = it_bsad.

append lines of it_bsid to it_final.

*sort it_final by budat.

sort it_final by budat.

if it_final is not initial.

select kunnr name1 from kna1 into table it_kna1 for all entries in

it_final where kunnr = it_final-kunnr.

endif.

data: first type budat.

first = s_date-low.

IF IT_BSAD IS NOT INITIAL.

loop at it_bsad into wa_bsad.

CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'

EXPORTING

COMPANYCODE = '100' "wa_bsad-bukrs

CUSTOMER = wa_bsad-kunnr

KEYDATE = first

* NOTEDITEMS = ' '

* SECINDEX = ' '

* IMPORTING

* RETURN =

TABLES

LINEITEMS = it_final1.

ENDLOOP.

ELSEIF IT_BSID IS NOT INITIAL.

LOOP AT IT_BSID INTO WA_BSID.

CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'

EXPORTING

COMPANYCODE = '100' "wa_bsad-bukrs

CUSTOMER = wa_bsId-kunnr

KEYDATE = first

* NOTEDITEMS = ' '

* SECINDEX = ' '

* IMPORTING

* RETURN =

TABLES

LINEITEMS = it_final1.

ENDLOOP.

ENDIF.

*BREAK-POINT.

sort it_final1 by pstng_date.

loop at it_final1 into wa_final1.

if wa_final1-db_cr_ind = 'S' and wa_final1-pstng_date <> s_date-low.

dr = wa_final1-lc_amount.

dr1 = dr1 + dr.

elseif wa_final1-db_cr_ind = 'H' and wa_final1-pstng_date <>

s_date-low.

cr = wa_final1-lc_amount.

cr1 = cr1 + cr.

ENDIF.

ENDLOOP.

*BREAK-POINT.

*loop at it_final into wa_final.

*

* ENDLOOP.

*BREAK-POINT.

wa_final-op_bal = dr1 - cr1.

data: v_op type p DECIMALS 2,

v_op1 type p DECIMALS 2.

v_op = wa_final-op_bal.

v_op1 = wa_final-op_bal.

*BREAK-POINT.

DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.

DATA: ld_index TYPE SY-TABIX.

BREAK-POINT.

loop at it_final into wa_final.

LD_INDEX = SY-TABIX.

if wa_final-shkzg = 'S'.

wa_final-dr = wa_final-wrbtr.

* wa_final-op_bal = wa_final-wrbtr.

else.

wa_final-cr = wa_final-wrbtr.

* wa_final-op_bal = wa_final-wrbtr * -1.

endif.

read table it_kna1 into wa_kna1 with key kunnr = wa_final-kunnr.

wa_final-name1 = wa_kna1-name1.

* wa_final-balance = bal + wa_final-dr - wa_final-cr.

*bal = wa_final-balance.

wa_final-balance = v_op + wa_final-dr - wa_final-cr.

v_op = wa_final-balance.

wa_final-op_bal = v_op1.

modify it_final from wa_Final. " TRANSPORTING balance dr cr.

* clear wa_final.

clear wa_kna1.

*WA_CELLCOLOR-FNAME = 'BALANCE'.

* WA_CELLCOLOR-COLOR-COL = 6. "color code 1-7, if outside

*"rage defaults to 7

* WA_CELLCOLOR-COLOR-INT = '1'. "1 = Intensified on, 0 =

*"Intensified off

* WA_CELLCOLOR-COLOR-INV = '0'. "1 = text colour, 0 = background

*"colour

* APPEND WA_CELLCOLOR TO wa_colour-CELLCOLOR.

* MODIFY it_final from wa_colour INDEX ld_index TRANSPORTING

*CELLCOLOR.

endloop.

fieldcatalog-fieldname = 'BUDAT'.

fieldcatalog-seltext_m = 'Posting Date'.

fieldcatalog-col_pos = 1.

fieldcatalog-row_pos = 2.

fieldcatalog-outputlen = 15.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'BUKRS'.

fieldcatalog-seltext_m = 'Comp Code'.

fieldcatalog-col_pos = 2.

fieldcatalog-row_pos = 2.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'KUNNR'.

fieldcatalog-seltext_m = 'Customer no.'.

fieldcatalog-col_pos = 3.

fieldcatalog-row_pos = 2.

fieldcatalog-outputlen = 15.

* fieldcatalog-emphasize = 'X'.

* fieldcatalog-key = 'X'.

* fieldcatalog-do_sum = 'X'.

* fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NAME1'.

fieldcatalog-seltext_m = 'Cusomter Name'.

fieldcatalog-col_pos = 4.

fieldcatalog-row_pos = 2.

fieldcatalog-outputlen = 25.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

*

fieldcatalog-fieldname = 'BELNR'.

fieldcatalog-seltext_m = 'Document Number'.

fieldcatalog-col_pos = 5.

fieldcatalog-row_pos = 2.

fieldcatalog-outputlen = 15.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'BALANCE'.

fieldcatalog-seltext_m = 'BALANCE'.

fieldcatalog-col_pos = 8.

fieldcatalog-row_pos = 2.

fieldcatalog-outputlen = 15.

* fieldcatalog-do_sum = 'X'.

fieldcatalog-EMPHASIZE = 'X'.

FIELDCATalog-HOTSPOT = 'X'.

* FIELDCATalog-coltext = 'hiiii'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

*

*fieldcatalog-fieldname = 'OP_BAL'.

* fieldcatalog-seltext_m = 'BALANCE'.

* fieldcatalog-col_pos = 9.

* fieldcatalog-row_pos = 1.

* fieldcatalog-outputlen = 15.

* append fieldcatalog to fieldcatalog.

* clear fieldcatalog.

fieldcatalog-fieldname = 'DR'.

fieldcatalog-seltext_m = 'DEBIT'.

fieldcatalog-col_pos = 6.

fieldcatalog-row_pos = 2.

* fieldcatalog-do_sum = 'X'.

fieldcatalog-outputlen = 15.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'CR'.

fieldcatalog-seltext_m = 'CREDIT'.

fieldcatalog-col_pos = 7.

fieldcatalog-row_pos = 2.

* fieldcatalog-do_sum = 'X'.

fieldcatalog-outputlen = 15.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

data: i_print TYPE slis_print_alv.

i_print-no_print_listinfos = 'X'.

*form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

* i_callback_user_command = 'USER_COMMAND'

* i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

* it_special_groups = gd_tabgroup

* IT_EVENTS = GT_XEVENTS

i_save = 'X'

* is_variant = z_template

is_print = i_print

tables

t_outtab = it_final

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.

*endform. " DISPLAY_ALV_REPORT


Regards

Purnand