Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

10 REPLIES 10

Former Member
0 Kudos

Hi,

Please check the following screenshot. I have to color that particular column. I have the logic of condition in my mind but how to add it in it_final.

Regards

Purnand

Abhijit74
Active Contributor
0 Kudos

Hello,

Check the area for cellcolor highlighted in bold.

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,

       cellcolors TYPE lvc_t_scol,

      end of ty_final.

DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.

DATA: ld_index TYPE SY-TABIX,

            lv_line     TYPE SY-TABIX.

Describe table  it_final lines lv_line.

LOOP AT IT_FINAL INTO WA_FINAL.

   LD_INDEX = SY-TABIX.

IF LD_INDEX = lv_line.

    WA_CELLCOLOR-FNAME = 'BALANCE'.

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

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

    APPEND WA_CELLCOLOR TO wa_final-CELLCOLORS.

    MODIFY it_final from wa_final INDEX ld_index .

ENDIF.

ENDLOOP.

Thanks,

Abhijit

Former Member
0 Kudos

Hi Abhijit,

I appreciate your reply but the same error is coming. Please check the following screenshot:

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

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

   cellcolors TYPE lvc_t_scol,

      end of ty_final.

DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.

DATA: ld_index TYPE SY-TABIX,

       lv_line     TYPE i."SY-TABIX.

 

*Describe table it_final lines lv_line.

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.

*wa_header-typ = 'S'.

*wa_header-key = 'Opening Balance: '.

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

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.

*BREAK-POINT.

*select wrbtr from bsad

* into op_bal

*  where bukrs = s_bukrs and budat = s_date and kunnr = s_kunnr.

*  ENDSELECT.

*break-point.

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.

*BREAK-POINT.

*loop at it_final into wa_final.

*op_bal = wrbtr

*loop at it_bsad into wa_

*BREAK-POINT.

*loop at it_bsad into wa_bsad.

*  if sy-tabix = '1'.

*    bsad_wrbtr = wa_bsad-wrbtr.

*    ENDIF.

*  endloop.

*  loop at it_bsid into wa_bsid.

*    if sy-tabix = '1'.

*      bsid_wrbtr = wa_bsid-wrbtr.

*      ENDIF.

*    ENDLOOP.

*BREAK-POINT.

*BREAK-POINT.

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.

Describe table  it_final lines lv_line.

 

loop at it_final into wa_final.

  LD_INDEX = SY-TABIX.

IF LD_INDEX = lv_line.

     WA_CELLCOLOR-FNAME = 'BALANCE'.

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

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

     APPEND WA_CELLCOLOR TO wa_final-CELLCOLORS.

     MODIFY it_final from wa_final INDEX ld_index .

ENDIF.

   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.

*BREAK-POINT.

*          .

   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-balance = wa_final-op_bal + wa_final-dr - wa_final-cr.

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

*op_bal = bsad_wrbtr - bsid_wrbtr.

*wa_final-op_bal = op_bal.

*wa_final-op_bal = v_op.

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

   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

Abhijit74
Active Contributor
0 Kudos

Hello Purnand,

How can you convert it_final = it_bsad. ?

Is it_bsad and it_final is same structure? These are very basic things.

You can loop at it_bsad and then append the required data into It_final. Then there will be no error.

LOOP AT IT_BSAD INTO WA_BSAD.

CLEAR WA_FINAL.

WA_FINAL-bukrs = WA_BSAD-bukrs

WA_FINAL-kunnr = WA_BSAD-kunnr

WA_FINAL-budat = WA_BSAD-buDAT

AND SO ON.

APPEND OR MODIFY THE IT_FINAL TABLE.

ENDLOOP.

Thanks,

Abhijit

former_member288351
Participant
0 Kudos

Dear Purnanad,

Have you got your fault, I have checked it, only one line code is left before display of alv

  gd_layout-coltab_fieldname = 'CELLCOLORS'.

and also find below whole program which is ok.

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

   cellcolors TYPE lvc_t_scol,

      end of ty_final.


DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.

DATA: ld_index TYPE SY-TABIX,

       lv_line     TYPE i."SY-TABIX.



*Describe table it_final lines lv_line.



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 WITH HEADER LINE,

         it_bsid type standard table of ty_bsid,

         it_kna1 type standard table of ty_kna1,

         it_final like standard table of ty_final WITH HEADER LINE.

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


*wa_header-typ = 'S'.

*wa_header-key = 'Opening Balance: '.

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




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.





*BREAK-POINT.

*select wrbtr from bsad

* into op_bal

*  where bukrs = s_bukrs and budat = s_date and kunnr = s_kunnr.

*  ENDSELECT.


*break-point.

*it_final = it_bsad.
*
*append lines of it_bsid to it_final.
LOOP AT IT_BSAD.
MOVE-CORRESPONDING IT_BSAD TO IT_FINAL.
APPEND IT_FINAL.
ENDLOOP.



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

*BREAK-POINT.


*loop at it_final into wa_final.

*op_bal = wrbtr


*loop at it_bsad into wa_

*BREAK-POINT.

*loop at it_bsad into wa_bsad.

*  if sy-tabix = '1'.

*    bsad_wrbtr = wa_bsad-wrbtr.

*    ENDIF.

*  endloop.

*  loop at it_bsid into wa_bsid.

*    if sy-tabix = '1'.

*      bsid_wrbtr = wa_bsid-wrbtr.

*      ENDIF.

*    ENDLOOP.



*BREAK-POINT.



*BREAK-POINT.

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.



Describe table  it_final lines lv_line.




loop at it_final into wa_final.

  LD_INDEX = SY-TABIX.

IF LD_INDEX = lv_line.

     WA_CELLCOLOR-FNAME = 'BALANCE'.

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

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

     APPEND WA_CELLCOLOR TO wa_final-CELLCOLORS.

     MODIFY it_final from wa_final INDEX LD_INDEX. "ld_index .

ENDIF.


   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.


*BREAK-POINT.


*          .





   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-balance = wa_final-op_bal + wa_final-dr - wa_final-cr.

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

*op_bal = bsad_wrbtr - bsid_wrbtr.

*wa_final-op_bal = op_bal.

*wa_final-op_bal = v_op.

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

   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.

gd_layout-coltab_fieldname = 'CELLCOLORS'.

   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

with regards

vikas pandey

0 Kudos

Hi,

I appreciate your reply. I am afraid I could not understand well. Where should I put that bold line?

Regards

Purnand

Former Member
0 Kudos

Hi,

Thank you abhijit, that was a very helpful answer. I am very close. I just want the last cell in the balance to get colored. Following is my code

   *&---------------------------------------------------------------------*
*& 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: 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,
  cellcolors TYPE lvc_t_scol,
     end of ty_final.

DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.
DATA: ld_index TYPE SY-TABIX,
      lv_line     TYPE i."SY-TABIX.

*Describe table it_final lines lv_line.


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.

*wa_header-typ = 'S'.
*wa_header-key = 'Opening Balance: '.
*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.



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.




*BREAK-POINT.
*select wrbtr from bsad
* into op_bal
*  where bukrs = s_bukrs and budat = s_date and kunnr = s_kunnr.
*  ENDSELECT.

*break-point.
loop at it_bsad into wa_bsad.
wa_final-bukrs = wa_bsad-bukrs.
wa_final-kunnr = wa_bsad-kunnr.
wa_final-budat = wa_bsad-budat.
wa_final-wrbtr = wa_bsad-wrbtr.
wa_final-belnr = wa_bsad-belnr.
wa_final-shkzg = wa_bsad-shkzg.
append wa_final to it_final.
       endloop.
*it_final = it_bsad.
*append lines of it_bsid to it_final.
*sort it_final by budat.
loop at it_bsid into wa_bsid.
  wa_final-bukrs = wa_bsid-bukrs.
wa_final-kunnr = wa_bsid-kunnr.
wa_final-budat = wa_bsid-budat.
wa_final-wrbtr = wa_bsid-wrbtr.
wa_final-belnr = wa_bsid-belnr.
wa_final-shkzg = wa_bsid-shkzg.
APPEND wa_final to it_final.
  ENDLOOP.

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

*loop at it_final into wa_final.
*op_bal = wrbtr

*loop at it_bsad into wa_
*BREAK-POINT.
*loop at it_bsad into wa_bsad.
*  if sy-tabix = '1'.
*    bsad_wrbtr = wa_bsad-wrbtr.
*    ENDIF.
*  endloop.
*  loop at it_bsid into wa_bsid.
*    if sy-tabix = '1'.
*      bsid_wrbtr = wa_bsid-wrbtr.
*      ENDIF.
*    ENDLOOP.


*BREAK-POINT.


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


Describe table  it_final lines lv_line.


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.

*BREAK-POINT.

*          .




  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-balance = wa_final-op_bal + wa_final-dr - wa_final-cr.
*op_bal = wa_final-dr + wa_final-cr - wa_final-balance.
*op_bal = bsad_wrbtr - bsid_wrbtr.
*wa_final-op_bal = op_bal.
*wa_final-op_bal = v_op.
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.
BREAK-POINT.
IF LD_INDEX = lv_line.
      WA_CELLCOLOR-FNAME = 'BALANCE'.
     WA_CELLCOLOR-COLOR-COL = 8"color code 1-7, if outside
    WA_CELLCOLOR-COLOR-INT = '1'"1 = Intensified on, 0 =
    APPEND WA_CELLCOLOR TO wa_final-CELLCOLORS.
    MODIFY it_final from wa_final INDEX ld_index .
ENDIF.


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

0 Kudos

Hello,

Why you are appending two times? As many times you will append it will create that many rows. Modify it after getting all the data into it_final structure. Do not loop again and again. Used read table.

Thanks,

Abhijit

0 Kudos

Hi Abhijit,

You are right, I will do that but where I am lacking in the coloring the particular cell?

Regards

Purnand

0 Kudos

Hello,

I think you first generate your it_final table correctly. For cell color the code is already there but you have put your code outside of the loop of IT_FINAL. Put inside the loop then only it will satisfy

ld_index = lv_ine.

Thanks,

Abhijit