Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

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

$
0
0

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 withheaderline,

       gd_tab_group type slis_t_sp_group_alv,

       gd_layout    type slis_layout_alv,

       gd_repid     like sy-repid,

       bal type   p decimals2.

 

DATA:

 

T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

 

FS_FIELDCAT LIKELINEOF T_FIELDCAT,

 

FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,

 

W_COLOR(3) ,

 

W_ROW TYPEI,

 

W_FIELDNAME(20),

 

W_PROG TYPE SY-REPID.

 

data: beginof ty_bsad,

        bukrs type bukrs,

        kunnr type kunnr,

        budat type budat,

        wrbtr type wrbtr,

        belnr type belnr_d,

        shkzg type SHKZG,

   endof ty_bsad.

*data dr1 type i.

 

   types: beginof ty_bsid,

          bukrs type bukrs,

          kunnr type kunnr,

        budat type budat,

        wrbtr type wrbtr,

        belnr type belnr_d,

        shkzg type SHKZG,

   endof ty_bsid.

 

   types: beginof ty_kna1,

         kunnr type kna1-kunnr,

         name1 type kna1-name1,

         name2 type kna1-name2,

         name3 type kna1-name3,

     endof ty_kna1.

 

*data: op_bal type p DECIMALS 2,

*      bsad_wrbtr TYPE p DECIMALS 2,

*      bsid_wrbtr type p DECIMALS 2.

 

data: beginof 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 decimals2,

        cr type p decimals2,

        sno type sy-tabix,

        name1 type kna1-name1,

        name2 type kna1-name2,

        name3 type kna1-name3,

        balance type p decimals2,

        op_bal type p decimals2,

*       COLOR(3),

 

*CHECKBOX ,

 

*CELL TYPE SLIS_T_SPECIALCOL_ALV,

      endof 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 TYPESTANDARDTABLEOF 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 likestandardtableof ty_bsad,

         it_bsid typestandardtableof ty_bsid,

         it_kna1 typestandardtableof ty_kna1,

         it_final likestandardtableof 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 TYPEI,

         LD_LINESC(10) TYPEC.

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

 

 

describetable it_final lines ld_lines.

ld_linesc = ld_lines.

concatenate'Total No. of Records Selected: ' ld_linesc

into t_line separatedby 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.

   CALLFUNCTION'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

     intotable it_bsad

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

 

   select bukrs

        kunnr

        budat

        wrbtr

        belnr

        shkzg

     intotable 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.

appendlinesof it_bsid to it_final.

*sort it_final by budat.

 

sort it_final by budat.

if it_final isnotinitial.

  select kunnr name1 from kna1 intotable it_kna1 for  all entries in

    it_final where kunnr = it_final-kunnr.

    endif.

 

 

 

data: firsttype budat.

first = s_date-low.

 

IF IT_BSAD ISNOTINITIAL.

loopat it_bsad into wa_bsad.

 

CALLFUNCTION'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 ISNOTINITIAL.

LOOPAT IT_BSID INTO WA_BSID.

     CALLFUNCTION'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.

loopat 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 DECIMALS2,

       v_op1 type p DECIMALS2.

 

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.

loopat 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.

 

 

   readtable it_kna1 into wa_kna1 withkey 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.

   callfunction'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


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>