ALV COLOR PROGRAM

Hi,
Please send me a sample prgm for colouring a single cell in an alv report.

REPORT  zsd_sales_prodgroup
        LINE-SIZE 351
        NO STANDARD PAGE HEADING
        LINE-COUNT 65
        MESSAGE-ID 00.
INCLUDE zcommon_part.
       TABLES                                                        *
TABLES: vbrk, "Billing Document: Header Data
        vbrp, "Billing Document: Item Data
        zsd_national, "Table for National level reports
        mara, "General Material Data
        t179t. "P
       INTERNAL TABLES AND STRUCTURES                                *
DATA: BEGIN OF it_data OCCURS 0.
        INCLUDE STRUCTURE zsd_national.
       vkbur    like zsd_national-vkbur,
       SUMMERY  like zsd_national-SUMMERY,
       sum_text like zsd_national-sum_text,
       sqno     like zsd_national-sqno,
DATA:   vbeln    LIKE vbrk-vbeln,
        matnr    LIKE vbrp-matnr,
        q1(20),"       like vbrp-fkimg,
        q2(20),"      like vbrp-fkimg,
        q3(20),"       like vbrp-fkimg,
        q4(20),"       like vbrp-fkimg,
        wk1(20),"     like vbrp-fkimg,
        wk2(20),"     like vbrp-fkimg,
        wk3(20),"      like vbrp-fkimg,
        wk4(20),"      like vbrp-fkimg,
        wk5(20),"      like vbrp-fkimg,
        wk6(20),"      like vbrp-fkimg,
        wk7(20),"      like vbrp-fkimg,
        wk8(20),"      like vbrp-fkimg,
        wk9(20),"      like vbrp-fkimg,
        wk10(20),"     like vbrp-fkimg,
        wk11(20),"     like vbrp-fkimg,
        wk12(20),"     like vbrp-fkimg,
        wk13(20),"     like vbrp-fkimg,
        wk_tot(20),"   like vbrp-fkimg,
        fkimg(20),"    like vbrp-fkimg,
        tot_week(20)," like vbrp-fkimg,
        ason_total(20)," like vbrp-fkimg,
        ly_total(20)," like vbrp-fkimg,
        allindia(20)," like vbrp-fklmg,
        goly TYPE i,
        tons LIKE vbrp-fkimg,
       allindia like vbrp-fkimg,
         color          TYPE lvc_t_scol,
      END OF it_data.
DATA: BEGIN OF it_vbrp OCCURS 0,
        fkdat LIKE vbrk-fkdat,
        vkorg LIKE vbrk-vkorg,
        vtweg LIKE vbrk-vtweg,
        fkart LIKE vbrk-fkart,
        fkimg LIKE vbrp-fkimg,
        umvkz LIKE vbrp-umvkz,
        umvkn LIKE vbrp-umvkn,
        fklmg LIKE vbrp-fklmg,
        vkbur LIKE vbrp-vkbur,
        vbeln LIKE vbrp-vbeln,
        matnr LIKE vbrp-matnr,
        prodh LIKE vbrp-prodh,
        matkl LIKE vbrp-matkl,
      END OF it_vbrp.
DATA: BEGIN OF it_vbeln OCCURS 0,
        vbeln LIKE vbrk-vbeln,
        fkart LIKE vbrk-fkart,
        fkdat LIKE vbrk-fkdat,
        vkorg LIKE vbrk-vkorg,
        vtweg LIKE vbrk-vtweg,
      END OF it_vbeln.
DATA: BEGIN OF it_prmatnr OCCURS 0,
        ntgew LIKE mara-ntgew, "netweight
        matnr LIKE mvke-matnr,
        prodh LIKE mvke-prodh,
        vkorg LIKE mvke-vkorg,
        vtweg LIKE mvke-vtweg,
      END OF it_prmatnr.
DATA: it_data_temp LIKE it_data OCCURS 0 WITH HEADER LINE.
DATA: color    TYPE TABLE          OF lvc_s_scol WITH HEADER LINE.
*ALV VARIABLES AND INTERNAL TABLES                                     *
TYPE-POOLS: slis.
DATA: v_repid LIKE sy-repid,
      st_layout TYPE slis_layout_alv,
      it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      it_listheader TYPE slis_t_listheader,
      it_event TYPE slis_t_event.
*VARIABLES                                                            *
DATA: v_pc           LIKE t009b-periv VALUE 'PC',
      v_wc           LIKE t009b-periv VALUE 'WC',
      v_date         LIKE sy-datum,
      v_ly_date      LIKE sy-datum,
      v_qtr_fir_date LIKE sy-datum,
      v_yr_fir_date  LIKE sy-datum,
      v_yr_last_date LIKE sy-datum,
      v_month        LIKE t009b-poper,
      v_lastmonth    LIKE t009b-poper,
      v_back_months  LIKE t009b-poper,
      v_curweek      LIKE t009b-poper,
      v_fdate        LIKE sy-datum,
      v_cyfd         LIKE sy-datum,
      v_lyfd         LIKE sy-datum,
      v_ldate        LIKE sy-datum,
      v_year         LIKE t009b-bdatj,
      v_last_year    LIKE t009b-bdatj,
      v_fkimg(20), "  like vbrp-fkimg ,
      v_fkimg1(20) ,
      v_goly_lyfkimg LIKE vbrp-fkimg ,
      v_goly_cyfkimg LIKE vbrp-fkimg ,
      vtext LIKE t179t-vtext,
      v_cnt(2)       TYPE  c,          "For Counter
      v_fld(6)       TYPE  c,          " For Field name
      v_qtr          LIKE t009b-poper,
      l_pos          TYPE i VALUE 1,  "Position indicator for
      v_wk(4),
      v_fldtxt(15)   TYPE  c,          "fieldcatalog
      v_last_qtr     LIKE t009b-poper,
      v_curpc        TYPE n,
      v_colposi(2)   TYPE n,
      v_currqtr      LIKE t009b-poper,
      v_next_qtr     LIKE t009b-poper,
      v_fpc          LIKE t009b-poper,
      v_lpc          LIKE t009b-poper,
      v_unit         LIKE mara-meins.
INITIALIZATION.
  v_repid = sy-repid.
*SELECTION SCREEN DEFINITIONS                                         *
  SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-000.
  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  PARAMETERS: p_date  TYPE sy-datum OBLIGATORY.
  SELECT-OPTIONS: s_prodh FOR mara-prdha OBLIGATORY.
  SELECTION-SCREEN END OF BLOCK b1.
        selection-screen skip.
  SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
  SELECT-OPTIONS: s_vkorg FOR vbrk-vkorg,
                  s_vtweg FOR vbrk-vtweg.
  PARAMETERS :  p_spart TYPE vbrk-spart.
  SELECTION-SCREEN END OF BLOCK b2.
  SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
  SELECT-OPTIONS : so_rev   FOR vbrk-fkart NO INTERVALS.
  SELECTION-SCREEN END OF BLOCK b3.
  SELECTION-SCREEN END OF BLOCK b.
*START-OF-SELECTION
START-OF-SELECTION.
  perform check_background using sy-batch sy-uname.
  PERFORM find_qtr.
  PERFORM get_vbrk-vbrp.
  PERFORM get_data.
  PERFORM get_ly_data.
  PERFORM add_data.
*TO add the Speciality details in the speciality sales total column.
  perform add_data_speciality.
PERFORM delete_data.
  PERFORM color_data.
  IF it_data[] IS NOT INITIAL.
    PERFORM output_data.
  ELSE.
    MESSAGE i012(zmsg).
  ENDIF.
END-OF-SELECTION.
TOP-OF-PAGE.
  PERFORM alv_events USING it_event.
*END-OF-SELECTION
*&      Form  find_qtr
FORM find_qtr .
  CLEAR v_date.
  CLEAR v_month.
  CLEAR v_date.
  v_date = p_date.
*Finding the period from selected date.
  PERFORM get_period USING v_date v_pc CHANGING v_month v_year .
  IF v_month >= '001' AND v_month     <= '003'.
    v_qtr = 1.
    v_month = '001'.
    PERFORM get_first_day
                       USING v_date v_pc v_month
                       CHANGING v_qtr_fir_date.
  ELSEIF v_month >= '004' AND v_month <= '006'.
    v_qtr = 2.
    v_month = '004'.
    PERFORM get_first_day
                       USING v_date v_pc v_month
                       CHANGING v_qtr_fir_date.
  ELSEIF v_month >= '007' AND v_month <= '009'.
    v_qtr = 3.
    v_month = '007'.
    PERFORM get_first_day
                       USING v_date v_pc v_month
                       CHANGING v_qtr_fir_date.
  ELSEIF v_month >= '010' AND v_month <= '012'.
    v_qtr = 4.
    v_month = '010'.
    PERFORM get_first_day
                       USING v_date v_pc v_month
                       CHANGING v_qtr_fir_date.
  ENDIF.
*Getting data for  2 years(present and previous).
  v_ly_date = v_date.
  v_back_months = 12.
  PERFORM go_months_back USING v_date v_back_months CHANGING v_ly_date.
  v_month = '001'.
  PERFORM get_first_day
                     USING v_ly_date v_pc v_month
                     CHANGING v_yr_fir_date.
  v_month = '012'.
  PERFORM get_last_day
                       USING v_date v_pc v_month
                       CHANGING v_yr_last_date.
ENDFORM.                    " find_qtr
*&      Form  get_vbrk-vbrp
FORM get_vbrk-vbrp .
  SELECT * FROM zsd_national
           INTO CORRESPONDING FIELDS OF TABLE it_data .
  SORT it_data BY sqno.
SELECT *  INTO CORRESPONDING FIELDS OF TABLE it_vbeln
                          FROM vbrk
                          WHERE fkdat >= v_yr_fir_date AND
                                fkdat <= v_yr_last_date AND
                                vkorg IN s_vkorg  AND
                                vtweg IN s_vtweg  AND
                                spart = p_spart   AND
                             fkart NOT IN ('G2','ZG2','F8','ZF8').
IF it_vbeln[] IS NOT INITIAL.
   SELECT * INTO CORRESPONDING FIELDS OF TABLE it_vbrp FROM vbrp
                           FOR ALL ENTRIES IN it_vbeln  WHERE
                           vbeln = it_vbeln-vbeln
                           AND vkbur <> '    '
                           AND prodh IN s_prodh
                     AND pstyv NOT IN  ('TANN','RENN','ZENN', 'ZRNN' ) .
                         and matnr = p_matnr.
ENDIF.
SORT it_vbeln BY vbeln.
SORT it_vbrp BY vbeln.
LOOP AT it_vbeln.
   LOOP AT it_vbrp WHERE vbeln = it_vbeln-vbeln.
     MOVE-CORRESPONDING  it_vbeln TO it_vbrp.
     MODIFY it_vbrp.
     CLEAR it_vbrp.
   ENDLOOP.
ENDLOOP.
*Selecting Product Heirarchy Materials.
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_prmatnr FROM mvke AS a
                       INNER JOIN mara AS b ON amatnr = bmatnr WHERE
                                  a~prodh IN s_prodh AND
                                  a~vkorg IN s_vkorg AND
                                  a~vtweg IN s_vtweg.
*Get billing doc's for last year first day to current year last day
  SELECT Avbeln Afkdat Avkorg Avtweg A~fkart
         Bfkimg Bumvkz Bumvkn Bfklmg Bvkbur Bmatnr Bprodh Bmatkl
                           INTO CORRESPONDING FIELDS OF TABLE it_VBRP
                           FROM vbrk AS A
                           INNER JOIN VBRP AS B ON Avbeln = Bvbeln
                           WHERE A~fkdat >= v_yr_fir_date AND
                                 A~fkdat <= v_yr_last_date AND
                                 A~vkorg IN s_vkorg  AND
                                 A~vtweg IN s_vtweg  AND
                                 A~spart = p_spart   AND
                                 A~fkart NOT IN ('G2','ZG2','F8','ZF8') AND
                                 B~vkbur <> '    ' AND
                                 B~prodh IN s_prodh AND
                                 B~pstyv NOT IN  ('TANN','RENN','ZENN', 'ZRNN' ) .
*Get materials for sales area and product hier
  SELECT matnr prodh vkorg vtweg
                            INTO CORRESPONDING FIELDS OF TABLE it_prmatnr
                            FROM mvke
                            WHERE prodh IN s_prodh AND
                                   vkorg IN s_vkorg AND
                                   vtweg IN s_vtweg.
  LOOP AT it_prmatnr.
*Get material net weight
    SELECT SINGLE ntgew INTO it_prmatnr-ntgew
                        FROM mara
                        WHERE matnr = it_prmatnr-matnr.
    MODIFY it_prmatnr.
    CLEAR it_prmatnr.
  ENDLOOP.
  SORT it_vbrp BY matnr.
  SORT it_prmatnr BY matnr.
  LOOP AT it_vbrp.
    clear it_prmatnr.
    READ TABLE it_prmatnr WITH KEY matnr = it_vbrp-matnr
                                   vkorg = it_vbrp-vkorg
                                   vtweg = it_vbrp-vtweg.
    IF sy-subrc <> 0.
      DELETE it_vbrp.
      CONTINUE.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " get_vbrk-vbrp
*&      Form  get_data
FORM get_data .
  LOOP AT it_data WHERE vkbur <> '    '.
    DO 4 TIMES.
      CLEAR it_data-fkimg.
*Finding current quarter to get first and last day of this quarter
      CLEAR v_fkimg.
      IF sy-index = 1 AND v_qtr <> sy-index.
        v_fpc = 001.
        v_lpc = 003.
        CLEAR v_fkimg.
        CLEAR v_fdate.
        CLEAR v_ldate.
        PERFORM get_first_last_date.
        PERFORM get_fkimg.
        PERFORM fill_week USING 'QTR'.
      ELSEIF sy-index = 2 AND v_qtr <> sy-index.
        v_fpc = 004.
        v_lpc = 006.
        CLEAR v_fkimg.
        CLEAR v_ldate.
        CLEAR v_fdate.
        PERFORM get_first_last_date.
        PERFORM get_fkimg.
        PERFORM fill_week USING 'QTR'.
      ELSEIF sy-index = 3 AND v_qtr <> sy-index.
        v_fpc = 007.
        v_lpc = 009.
        CLEAR v_ldate.
        CLEAR v_fdate.
        CLEAR v_fkimg.
        PERFORM get_first_last_date.
        PERFORM get_fkimg.
        PERFORM fill_week USING 'QTR'.
      ELSEIF sy-index = 4 AND v_qtr <> sy-index.
        v_fpc = 010.
        v_lpc = 012.
        CLEAR v_ldate.
        CLEAR v_fdate.
        CLEAR v_fkimg.
        PERFORM get_first_last_date.
        PERFORM get_fkimg.
        PERFORM fill_week USING 'QTR'.
      ENDIF.
Get the value for fkimg (Invoiced Quantity).
     perform get_fkimg.
     perform fill_week using 'WK'.
Moving value for fkimg
    ENDDO.
    PERFORM get_period
                      USING v_qtr_fir_date v_wc
                      CHANGING v_curweek v_year.
*Calling subroutines to create fieldcatalog,fill fieldcatalog and
*intenal table dynamicaly based on user selected date(Quarter).
    DO 13 TIMES.
Calling subroutine to get first date of current week
      CLEAR v_fkimg.
      PERFORM get_first_day
                  USING v_date v_wc v_curweek
                  CHANGING v_fdate.
Calling subroutine to get last date of current week
      PERFORM get_last_day
                  USING v_date v_wc v_curweek
                  CHANGING v_ldate.
      PERFORM get_fkimg.
      PERFORM fill_week USING 'WK'.
      v_curweek = v_curweek + 1.
      CLEAR v_fkimg.
    ENDDO.
CALCULATE TOTAL FOR AS ON DATE YEAR
    v_fdate = v_cyfd.
    v_ldate = sy-datum.
    PERFORM get_fkimg.
    it_data-ason_total = v_fkimg.
CALCULATE TOTAL FOR PREVIOUS YEAR
    PERFORM get_first_day
                     USING v_date v_pc '001'
                     CHANGING v_fdate.
    v_cyfd = v_fdate. "current year first day
    "(will be used in as on date)
    v_back_months = 12.
    PERFORM go_months_back USING v_fdate v_back_months CHANGING v_fdate.
    v_lyfd = v_fdate. "last year first day(will be used in goly).
    PERFORM get_last_day
                     USING  v_lyfd v_pc '012'
                     CHANGING v_ldate.
To be checked
   v_yr_fir_date     = v_lyfd.
   v_yr_last_date    = v_ldate.
   perform get_vbrk-vbrp.
    CLEAR v_fkimg.
    PERFORM get_fkimg.
    it_data-ly_total = v_fkimg.
CALCULATION FOR GOLY
*Calculating fkimg for last year.
*Dates passed are last year first date and 12 months back from present
*date.
    v_fdate = v_lyfd.
    v_ldate = sy-datum.
    v_back_months = 12.
    PERFORM go_months_back USING v_ldate v_back_months CHANGING v_ldate.
    PERFORM get_fkimg.
    v_goly_lyfkimg = v_fkimg.
    IF v_goly_lyfkimg <> 0 .
*Calculating fkimg for present year (this will be same as 'As On
*Total')
      v_goly_cyfkimg = it_data-ason_total.
      it_data-goly   =
    (  (  v_goly_cyfkimg  - v_goly_lyfkimg ) / v_goly_lyfkimg ) * 100.
    ELSEIF v_goly_lyfkimg = 0 .
      it_data-goly = 100.
    ENDIF.
    MODIFY it_data.
    CLEAR it_data.
  ENDLOOP.
ENDFORM.                    " get_data
*&      Form  get_first_last_date
      text
FORM get_first_last_date .
*Calling inlude prog subroutine to get first date of Quarter
  PERFORM get_first_day
                    USING v_date v_pc v_fpc
                    CHANGING v_fdate.
   Calling inlude prog subroutine to get last date of month
  PERFORM get_last_day
                    USING v_date v_pc v_lpc
                    CHANGING v_ldate.
ENDFORM.                    " get_first_last_date
*&      Form  get_fkimg
FORM get_fkimg  .
  SORT it_vbrp BY vkbur.
  CLEAR v_fkimg.
  LOOP AT it_vbrp WHERE fkdat >= v_fdate  AND fkdat  <= v_ldate
                        AND vkbur = it_data-vkbur.
    PERFORM get_unit USING it_vbrp-matkl CHANGING v_unit.
    READ TABLE it_prmatnr WITH KEY matnr = it_vbrp-matnr.
    if sy-subrc <> 0.
     it_vbrp-fkimg =  it_vbrp-fkimg * ( it_vbrp-umvkz   /
                                it_vbrp-umvkn ).
    IF v_unit = 'CV'.
      PERFORM convert_to_cv USING it_vbrp-matnr
                                  it_vbrp-fklmg
                                  'CS'
                         CHANGING it_vbrp-fklmg.
    ELSEIF v_unit = 'PAC'.
      PERFORM convert_to_cv USING it_vbrp-matnr
                                  it_vbrp-fklmg
                                  'PAK'
                         CHANGING it_vbrp-fklmg.
added on 12.03.2007 as per the requirement.
    ELSEIF v_unit = 'TAB'.
      PERFORM convert_to_cv USING it_vbrp-matnr
                                   it_vbrp-fklmg
                                   'TAB'
                          CHANGING it_vbrp-fklmg.
*AS PER THE REQUIREMENT THE QTY IS DIVIDED BY 1000
      it_vbrp-fklmg = it_vbrp-fklmg / 1000.
    ELSEIF v_unit = 'TON'.
      it_vbrp-fklmg = ( it_vbrp-fklmg * it_prmatnr-ntgew ) /
                                              1000000.
    ENDIF.
*Deducting sales return invoice quantity
   IF ( it_vbrp-fkart = 'RE'   OR
        it_vbrp-fkart = 'ZRE'  OR
        it_vbrp-fkart = 'ZRE1' OR
        it_vbrp-fkart = 'ZFR'  OR
        it_vbrp-fkart = 'S1' ).
    IF it_vbrp-fkart IN so_rev.
      v_fkimg =  v_fkimg - it_vbrp-fklmg.
    ELSE.
      v_fkimg =  v_fkimg + it_vbrp-fklmg.
    ENDIF.
  ENDLOOP.
  IF v_unit = 'EA'.
    WRITE v_fkimg TO v_fkimg1 DECIMALS 0.
  ELSE.
    v_fkimg1 = v_fkimg.
  ENDIF.
ENDFORM. " get_fkimg
*&      Form  fill_week
FORM fill_week  USING    value(v_wkqc).
  IF v_wkqc = 'WK'.
    CASE sy-index.
      WHEN 1.
        it_data-wk1 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 2.
        it_data-wk2 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 3.
        it_data-wk3 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 4.
        it_data-wk4 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 5.
        it_data-wk5 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 6.
        it_data-wk6 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 7.
        it_data-wk7 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 8.
        it_data-wk8 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 9.
        it_data-wk9 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 10.
        it_data-wk10 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 11.
        it_data-wk11 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 12.
        it_data-wk12 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
      WHEN 13.
        it_data-wk13 = v_fkimg1.
        it_data-tot_week = it_data-tot_week + v_fkimg1.
    ENDCASE.
  ELSEIF v_wkqc = 'QTR'.
    CASE sy-index.
      WHEN 1.
         if sy-index = 1 and v_qtr <> sy-index.
         elseif sy-index = 2 and v_qtr <> sy-index.
         elseif sy-index = 3 and v_qtr <> sy-index.
         elseif sy-index = 4 and v_qtr <> sy-index.
         endif.
        it_data-q1 = v_fkimg1.
      WHEN 2.
        it_data-q2 = v_fkimg1.
      WHEN 3.
        it_data-q3 = v_fkimg1.
      WHEN 4.
        it_data-q4 = v_fkimg1.
    ENDCASE.
  ENDIF.
ENDFORM.                    " fill_week
*&      Form  add_data
FORM add_data .
  MOVE it_data[] TO it_data_temp[].
  SORT it_data BY sqno.
  SORT it_data_temp BY sqno.
  LOOP AT it_data WHERE summery <> ' ' AND summery <> 'N'.
    IF it_data-summery = 'X' .
      LOOP AT it_data_temp
              WHERE sqno >= it_data-fr AND sqno <= it_data-upto.
        PERFORM add_fields.
      ENDLOOP.
    ENDIF.
*if it_data-ason_total = 0 .
delete it_data.
continue.
*endif.
    MODIFY it_data.
    CLEAR  it_data.
  ENDLOOP.
  MOVE it_data[] TO it_data_temp[].
  LOOP AT it_data WHERE summery <> ' ' AND summery <> 'N'.
    IF it_data-summery = 'A'.
      READ TABLE it_data_temp WITH KEY sqno = it_data-fr.
      IF sy-subrc = 0.
        PERFORM add_fields.
      ENDIF.
      READ TABLE it_data_temp WITH KEY sqno = it_data-upto.
      IF sy-subrc = 0.
        PERFORM add_fields.
      ENDIF.
    ENDIF.
    MODIFY it_data.
    CLEAR  it_data.
  ENDLOOP.
ENDFORM.                    " add_data
*&      Form  add_fields
FORM add_fields .
  it_data-q1 = it_data-q1 + it_data_temp-q1.
  it_data-q2 = it_data-q2 + it_data_temp-q2.
  it_data-q3 = it_data-q3 + it_data_temp-q3.
  it_data-q4 = it_data-q4 + it_data_temp-q4.
  it_data-wk1 = it_data-wk1 + it_data_temp-wk1.
  it_data-wk2 = it_data-wk2 + it_data_temp-wk2.
  it_data-wk3 = it_data-wk3 + it_data_temp-wk3.
  it_data-wk4 = it_data-wk4 + it_data_temp-wk4.
  it_data-wk5 = it_data-wk5 + it_data_temp-wk5.
  it_data-wk6 = it_data-wk6 + it_data_temp-wk6.
  it_data-wk7 = it_data-wk7 + it_data_temp-wk7.
  it_data-wk8 = it_data-wk8 + it_data_temp-wk8.
  it_data-wk9 = it_data-wk9 + it_data_temp-wk9.
  it_data-wk10 = it_data-wk10 + it_data_temp-wk10.
  it_data-wk11 = it_data-wk11 + it_data_temp-wk11.
  it_data-wk12 = it_data-wk12 + it_data_temp-wk12.
  it_data-wk13 = it_data-wk13 + it_data_temp-wk13.
  it_data-tot_week = it_data-tot_week + it_data_temp-tot_week.
  it_data-ly_total = it_data-ly_total + it_data_temp-ly_total.
  it_data-ason_total = it_data-ason_total + it_data_temp-ason_total.
  it_data-allindia = it_data-allindia + it_data_temp-allindia.
ENDFORM.                    " add_fields
*&      Form  color_data
      text
FORM color_data.
  LOOP AT it_data.
  Color
    CLEAR   color.
    REFRESH color.
   IF NOT it_data-summery IS INITIAL.
     IF it_data-summery <> ' ' and it_data-summery <> 'N'.
      color-color-col = '5'.
      color-color-int = '1'.
      color-color-inv = '1'.
     color-nokeycol = 'X'.
      color-fname = 'Q1'. APPEND color.
      color-fname = 'Q2'. APPEND color.
      color-fname = 'Q3'. APPEND color.
      color-fname = 'Q4'. APPEND color.
      color-fname = 'TOT_WEEK'. APPEND color.
      color-fname = 'WK1'.  APPEND color.
      color-fname = 'WK2'.  APPEND color.
      color-fname = 'WK3'.   APPEND color.
      color-fname = 'WK4'.  APPEND color.
      color-fname = 'WK5'.  APPEND color.
      color-fname = 'WK6'.  APPEND color.
      color-fname = 'WK7'.  APPEND color.
      color-fname = 'WK8'.  APPEND color.
      color-fname = 'WK9'.  APPEND color.
      color-fname = 'WK10'. APPEND color.
      color-fname = 'WK11'. APPEND color.
      color-fname = 'WK12'. APPEND color.
      color-fname = 'WK13'. APPEND color.
      color-fname = 'SUM_TEXT'. APPEND color.
      color-fname = 'LY_TOTAL'. APPEND color.
      color-fname = 'ASON_TOTAL'. APPEND color.
      color-fname = 'GOLY'. APPEND color.
      it_data-color = color[].
      MODIFY it_data.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "color_data
*&      Form  output_data
FORM output_data .
*To delete the GR Punjab And UP West
  loop at it_data.
    if it_data-SQNO = '3' or it_data-SQNO = '6'.
      delete it_data.
    endif.
  endloop.
  PERFORM fill_layout_structure.
  PERFORM fill_listheader USING it_listheader.
  PERFORM fill_fieldcatalog USING 'SUM_TEXT' 'Sales Office' 10
'IT_DATA' .
  IF v_qtr = 1.
    PERFORM fill_fieldcatalog  USING :
     'WK1'       'WK1'    10  'IT_DATA' ,
     'WK2'       'WK2'    10  'IT_DATA' ,
     'WK3'       'WK3'    10  'IT_DATA' ,
     'WK4'       'WK4'    10  'IT_DATA' ,
     'WK5'       'WK5'    10  'IT_DATA' ,
     'WK6'       'WK6'    10  'IT_DATA' ,
     'WK7'       'WK7'    10  'IT_DATA' ,
     'WK8'       'WK8'    10  'IT_DATA',
     'WK9'       'WK9'    10  'IT_DATA' ,
     'WK10'      'WK10'   10  'IT_DATA' ,
     'WK11'      'WK11'   10  'IT_DATA' ,
     'WK12'      'WK12'   10  'IT_DATA' ,
     'WK13'      'WK13'   10  'IT_DATA' ,
     'TOT_WEEK'  'Weekly Total' 10 'IT_DATA' ,
     'Q2'        'Q2 CY'     10  'IT_DATA' ,
     'Q3'        'Q3 CY'     10  'IT_DATA' ,
     'Q4'        'Q4 CY'     10  'IT_DATA' .
  ELSEIF v_qtr = 2.
    PERFORM fill_fieldcatalog  USING :
      'Q1'     'Q1 CY'    10 'IT_DATA' ,
     'WK1'       'WK1'    10  'IT_DATA' ,
     'WK2'       'WK2'    10  'IT_DATA' ,
     'WK3'       'WK3'    10  'IT_DATA' ,
     'WK4'       'WK4'    10  'IT_DATA' ,
     'WK5'       'WK5'    10  'IT_DATA' ,
     'WK6'       'WK6'    10 'IT_DATA' ,
     'WK7'       'WK7'    10  'IT_DATA' ,
     'WK8'       'WK8'    10  'IT_DATA' ,
     'WK9'       'WK9'    10  'IT_DATA',
     'WK10'      'WK10'   10 'IT_DATA' ,
     'WK11'      'WK11'   10  'IT_DATA' ,
     'WK12'      'WK12'   10 'IT_DATA' ,
     'WK13'      'WK13'   10  'IT_DATA' ,
     'TOT_WEEK'  'Weekly Total' 10 'IT_DATA' ,
     'Q3'        'Q3 CY'     10  'IT_DATA' ,
     'Q4'        'Q4 CY'     10 'IT_DATA' .
  ELSEIF v_qtr = 3.
    PERFORM fill_fieldcatalog USING :
     'Q1'     'Q1 CY'     10  'IT_DATA' ,
     'Q2'     'Q2 CY'     10  'IT_DATA' ,
     'WK1'       'WK1'    10  'IT_DATA' ,
     'WK2'       'WK2'    10  'IT_DATA' ,
     'WK3'       'WK3'    10  'IT_DATA' ,
     'WK4'       'WK4'    10  'IT_DATA' ,
     'WK5'       'WK5'    10  'IT_DATA' ,
     'WK6'       'WK6'    10  'IT_DATA' ,
     'WK7'       'WK7'    10  'IT_DATA' ,
     'WK8'       'WK8'    10  'IT_DATA' ,
     'WK9'       'WK9'    10  'IT_DATA' ,
     'WK10'      'WK10'   10  'IT_DATA' ,
     'WK11'      'WK11'   10  'IT_DATA' ,
     'WK12'      'WK12'   10  'IT_DATA' ,
     'WK13'      'WK13'   10  'IT_DATA' ,
     'TOT_WEEK'  'Weekly Total' 10 'IT_DATA' ,
     'Q4'        'Q4 CY'  10  'IT_DATA' .
  ELSEIF v_qtr = 4.
    PERFORM fill_fieldcatalog USING :
    'Q1'     'Q1 CY'     10 'IT_DATA' ,
    'Q2'     'Q2 CY'     10 'IT_DATA' ,
    'Q3'     'Q3 CY'     10 'IT_DATA' ,
    'WK1'       'WK1'    10 'IT_DATA' ,
    'WK2'       'WK2'    10 'IT_DATA' ,
    'WK3'       'WK3'    10 'IT_DATA' ,
    'WK4'       'WK4'    10 'IT_DATA' ,
    'WK5'       'WK5'    10 'IT_DATA' ,
    'WK6'       'WK6'    10 'IT_DATA' ,
    'WK7'       'WK7'    10 'IT_DATA' ,
    'WK8'       'WK8'    10 'IT_DATA' ,
    'WK9'       'WK9'    10 'IT_DATA' ,
    'WK10'      'WK10'   10 'IT_DATA' ,
    'WK11'      'WK11'   10 'IT_DATA' ,
    'WK12'      'WK12'   10 'IT_DATA' ,
    'WK13'      'WK13'   10  'IT_DATA' ,
    'TOT_WEEK'  'Weekly Total' 10 'IT_DATA' .
  ENDIF.
  PERFORM fill_fieldcatalog USING :
             'LY_TOTAL' 'LY TOTAL' 10 'IT_DATA' ,
             'ASON_TOTAL' 'AS ON TOTAL' 10 'IT_DATA',
             'GOLY'        'GOLY %'  10 'IT_DATA'.
  PERFORM alv_list_display.
ENDFORM.                    "output_data
*FORM TO FILL FIELDCATALOG                                             *
FORM fill_fieldcatalog USING  f d o t .
  DATA wa_fieldcat TYPE slis_fieldcat_alv.
  STATICS pos LIKE sy-index VALUE 1.
  pos = pos + 1.
  CLEAR wa_fieldcat.
  MOVE : 1     TO   wa_fieldcat-row_pos,
         pos   TO   wa_fieldcat-col_pos,
         f     TO   wa_fieldcat-fieldname,
         d     TO   wa_fieldcat-seltext_l,
         o     TO   wa_fieldcat-outputlen,
         t     TO   wa_fieldcat-tabname.
  APPEND wa_fieldcat TO it_fieldcat.
ENDFORM.                    "FILL_FIELDCATALOG
*FORM FOR FILLING LISTHEADER
FORM fill_listheader USING it_listheader TYPE slis_t_listheader.
  SELECT SINGLE vtext INTO vtext FROM t179t WHERE prodh IN s_prodh.
  DATA : wa_listheader TYPE slis_listheader,
         v_variantname LIKE  varit-vtext.
  CLEAR wa_listheader.
  wa_listheader-typ  = 'H'.
  wa_listheader-info ='Quarter Sales Product Group Report'.
  APPEND wa_listheader TO it_listheader.
     CLEAR wa_listheader.
     wa_listheader-typ  = 'S'.
     wa_listheader-key  = 'Date:'.
     write v_date to wa_listheader-info.
     APPEND wa_listheader to it_listheader.
  CLEAR wa_listheader.
  wa_listheader-typ  = 'S'.
  wa_listheader-key  = 'Product Heirarchy'.
  WRITE vtext TO wa_listheader-info.
  APPEND wa_listheader TO it_listheader.
*To print the variantname as the report header
  PERFORM get_variant_name USING sy-repid sy-slset
                          CHANGING v_variantname.
  IF NOT v_variantname IS INITIAL.
    CLEAR wa_listheader.
    wa_listheader-typ  = 'S'.
    wa_listheader-key  = 'Variant '.
    wa_listheader-info = v_variantname.
    APPEND wa_listheader TO it_listheader.
  ENDIF.
**Displaying Sales Organisation
   IF  s_vkorg-low IS NOT INITIAL AND s_vkorg-high IS NOT INITIAL.
     CLEAR wa_listheader.
     wa_listheader-typ = 'S '.
     wa_listheader-key = 'Sales Organisation:'.
     CONCATENATE '' s_vkorg-low 'To'
*s_vkorg-high
     INTO
     wa_listheader-info SEPARATED BY space.
     APPEND wa_listheader TO it_listheader.
  ELSEIF  s_vkorg-low IS NOT INITIAL .
     CLEAR wa_listheader.
     wa_listheader-typ = 'S'.
     wa_listheader-key = 'Sales Organisation:'.
     CONCATENATE '' s_vkorg-low INTO
     wa_listheader-info.
     APPEND wa_listheader TO it_listheader.
ELSEIF  s_vkorg-low IS INITIAL AND s_vkorg-high IS  INITIAL.
     CLEAR wa_listheader.
     wa_listheader-typ = 'S'.
     wa_listheader-info  = 'Sales Organisation: *'.
     APPEND wa_listheader TO it_listheader.
ENDIF.
**Displaying Distribution Channel
   IF  s_vtweg-low IS NOT INITIAL AND s_vtweg-high IS NOT INITIAL.
     CLEAR wa_listheader.
     wa_listheader-typ = 'S '.

Similar Messages

  • Send me notes of ALV, DAILOG PROGRAMMING

    hi friends,
    this is shafeeq plz send me the notes of ALV, DAILOG PROGRAMMING WITH SOME interview quetions also
    MY MAIL ID [email protected]
    accept my thanks in advance
    regards
    shafeeq

    Hi,
    dialog programming.
    Refer to the documentation @
    <u>http://help.sap.com/saphelp_47x200/helpdata/en/c9/5472fc787f11d194c90000e8353423/frameset.htm</u>
    <u>http://www.sapdevelopment.co.uk/dialog/dialoghome.htm
    http://help.sap.com/saphelp_webas630/helpdata/en/9f/db9cdc35c111d1829f0000e829fbfe/content.htm</u>
    <b>ALV</b>
    check these links,
    About ALV:
    http://www.geocities.com/mpioud/Abap_programs.html
    ALV Group Heading
    http://www.sap-img.com/fu037.htm
    and few more,
    ALV
    1. Please give me general info on ALV.
    http://www.sapfans.com/forums/viewtopic.php?t=58286
    http://www.sapfans.com/forums/viewtopic.php?t=76490
    http://www.sapfans.com/forums/viewtopic.php?t=20591
    http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
    2. How do I program double click in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=11601
    http://www.sapfans.com/forums/viewtopic.php?t=23010
    3. How do I add subtotals (I have problem to add them)...
    http://www.sapfans.com/forums/viewtopic.php?t=20386
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.sapfans.com/forums/viewtopic.php?t=88401
    http://www.sapfans.com/forums/viewtopic.php?t=17335
    4. How to add list heading like top-of-page in ABAP lists?
    http://www.sapfans.com/forums/viewtopic.php?t=58775
    http://www.sapfans.com/forums/viewtopic.php?t=60550
    http://www.sapfans.com/forums/viewtopic.php?t=16629
    5. How to print page number / total number of pages X/XX in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
    6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
    http://www.sapfans.com/forums/viewtopic.php?t=64320
    http://www.sapfans.com/forums/viewtopic.php?t=44477
    7. How can I set the cell color in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=52107
    8. How do I print a logo/graphics in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=81149
    http://www.sapfans.com/forums/viewtopic.php?t=35498
    http://www.sapfans.com/forums/viewtopic.php?t=5013
    9. How do I create and use input-enabled fields in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=84933
    http://www.sapfans.com/forums/viewtopic.php?t=69878
    10. How can I use ALV for reports that are going to be run in background?
    http://www.sapfans.com/forums/viewtopic.php?t=83243
    http://www.sapfans.com/forums/viewtopic.php?t=19224
    11. How can I display an icon in ALV? (Common requirement is traffic light icon).
    http://www.sapfans.com/forums/viewtopic.php?t=79424
    http://www.sapfans.com/forums/viewtopic.php?t=24512
    12. How can I display a checkbox in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=88376
    http://www.sapfans.com/forums/viewtopic.php?t=40968
    http://www.sapfans.com/forums/viewtopic.php?t=6919
    <b>Interview questions</b>.
    refer this one...
    /message/2042837#2042837 [original link is broken]
    Please check these links.
    http://www.sap-img.com/abap/abap-interview-question.htm
    http://www.sap-img.com/abap/answers-to-some-abap-interview-questions.htm
    http://sap.ittoolbox.com/documents/document.asp?i=3240
    http://www.techinterviews.com/?p=198
    Regards
    Anver
    if hlped pls mark points

  • Shortdump @ alv grid program

    Hi,
    we have a problem with our alv grid program.
    Here is the coding:
    *Varibalendeklaration
    DATA:   wa_buero TYPE zd06_buero.
    DATA:   it_buero LIKE TABLE OF wa_buero.
    *Selectierung und Sortierung
    SELECT agencynum COUNT( * ) AS zcount
           INTO CORRESPONDING FIELDS OF TABLE it_buero
           FROM sbook
           GROUP BY agencynum
           ORDER BY zcount DESCENDING.
    *Den Dynpro aufrufen
    CALL SCREEN 103.
    *&      Module  STATUS_0103  OUTPUT
    *       text
    MODULE status_0103 OUTPUT.
    *Aufrufen des von Hendrik erstellten Funktionsbaustein zum Aufruf des
    *Alv Grids
      CALL FUNCTION 'ZD06_06_ALV'
        EXPORTING
          container_name_in   = 'CONTAINER_1'
          i_structure_name_in = 'ZD06_BUERO'
        CHANGING
          it_outtab_in        = it_buero.
    ENDMODULE.                 " STATUS_103  OUTPUT
    We have just create an new DDIC Structure with the points we need.
    Our referent can't solve the problem and know I need your help.
    Thanks.
    Best Regards,
    Marcus

    Hi,
    thank you for answering.
    The programm take a travelagencynumber from dbtab sbook. There also is a counter who sort and count the agencynumbers. The programm should tell us, how many books are done with this agency. e.g.: Travelagency 98565    1358 books
    ZD06_06_ALV is a function for alv grid. The code for this function is:
    *"*"Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(CONTAINER_NAME_IN) TYPE  CHAR30
    *"     REFERENCE(I_STRUCTURE_NAME_IN)
    *"  CHANGING
    *"     REFERENCE(IT_OUTTAB_IN)
      DATA: container_r TYPE REF TO cl_gui_custom_container,
            grid_r      TYPE REF TO cl_gui_alv_grid.
      CREATE OBJECT container_r
       EXPORTING container_name = container_name_in.
      CREATE OBJECT grid_r
      EXPORTING i_parent = container_r.
      CALL METHOD grid_r->set_table_for_first_display
        EXPORTING
          i_structure_name = i_structure_name_in
        CHANGING
          it_outtab        = it_outtab_in.
    ENDFUNCTION.
    The dump reason is
    Runtime error: DBIF_RSQL_INVALID_RSQL
    We set a breakpoint at the select statement and there is the problem. exactly there is the dump.
    Best Regards.
    Marcu

  • ALV color

    Hi all,
    Can anyone tell me how to display different colors on different coloumns of an ALV.
    thanks

    hi
    check this code
    An example of using linecolor (ALV).
    Here you have a good example of coloring rows, columns and specific cells in alvs. It comes in an example of how to use hashed tables. 
    For coloured rows and cols check gp_bymat
    for coloured specific rows uncheck gp_bymat.
    HTH.
    Horacio
    ps: code:
    report zuseofhashedtables.
    Program: ZUseOfHashedTables                                        **
    Author: Horacio Zapettini                                          **
    Versions: 4.6b - 4.6c                                              **
    Notes:                                                             **
        this program shows how we can use hashed tables to improve     **
        the responce time.                                             **
        It shows,                                                      **
           1. how to declare hashed tables                             **
           2. a cache-like technique to improve access to master data  **
           3. how to collect data using hashed tables                  **
           4. how to avoid deletions of unwanted data                  **
    Results: the test we run read about 31000 rows from mkpf, 150000   **
             rows from mseg, 500 rows from makt and 400 from lfa1.     **
             it filled ht_lst with 24500 rows and displayed them in    **
             alv grid format.                                          **
             It took about 65 secodns to perform this task (first time **
             we run it when all the db buffers are empty.              **
             The same program with standard tables needed 140 seconds  **
             to run with the same recordset and with buffers filled in **
             A simmilar test over more than a million rows
    Objetive: show a list that consists of  all the material movements **
             '101' - '901' for a certain range of dates in mkpf-budat. **
    the columns to be displayed are:                                   **
             mkpf-budat,                                               **
             mkpf-mblnr,                                               **
             mseg-lifnr,                                               **
             lfa1-name1,                                               **
             mkpf-xblnr,                                               **
             mseg-zeile                                                **
             mseg-charg,                                               **
             mseg-matnr,                                               **
             makt-maktx,                                               **
             mseg-erfmg,                                               **
             mseg-erfme.                                               **
    or show a sumary list by matnr - menge                             **
    You'll have to create a pf-status called vista -                   **
    See form set_pf_status for details                                 **
    tables used -
    tables: mkpf,
            mseg,
            lfa1,
            makt.
    global hashed tables used
    data: begin of wa_mkpf, "header
          mblnr like mkpf-mblnr,
          mjahr like mkpf-mjahr,
          budat like mkpf-budat,
          xblnr like mkpf-xblnr,
          end of wa_mkpf.
    data: ht_mkpf like hashed table of wa_mkpf
          with unique key mblnr mjahr
          with header line.
    data: st_mkpf like standard table of wa_mkpf
          with header line.
    data: begin of wa_mseg, " line items
          mblnr like mseg-mblnr,
          mjahr like mseg-mjahr,
          zeile like mseg-zeile,
          bwart like mseg-bwart,
          charg like mseg-charg,
          matnr like mseg-matnr,
          lifnr like mseg-lifnr,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          end of wa_mseg.
    data ht_mseg like hashed table of wa_mseg
          with unique key mblnr mjahr zeile
          with header line.
    data st_mseg like standard table of wa_mseg
          with header line.
    cache structure for lfa1 records
    data: begin of wa_lfa1,
          lifnr like lfa1-lifnr,
          name1 like lfa1-name1,
          end of wa_lfa1.
    data ht_lfa1 like hashed table of wa_lfa1
          with unique key lifnr
          with header line.
    cache structure for material related data
    data: begin of wa_material,
          matnr like makt-matnr,
          maktx like makt-maktx,
          end of wa_material.
    data: ht_material like hashed table of wa_material
            with unique key matnr
            with header line.
    result table
    data: begin of wa_lst, "
          budat like mkpf-budat,
          mblnr like mseg-mblnr,
          lifnr like mseg-lifnr,
          name1 like lfa1-name1,   
          xblnr like mkpf-xblnr,
          zeile like mseg-zeile,
          charg like mseg-charg,
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          mjahr like mseg-mjahr,
          end of wa_lst.
    data: ht_lst like hashed table of wa_lst
            with unique key mblnr mjahr zeile
            with header line.
    data: begin of wa_lst1, " sumary by material
          matnr like mseg-matnr,
          maktx like makt-maktx,
          erfmg like mseg-erfmg,
          erfme like mseg-erfme,
          color_line(4) TYPE c,           " Line color
          color_cell    TYPE lvc_t_scol,  " Cell color
          celltab type LVC_T_STYL,
          end of wa_lst1.
    data: ht_lst1 like hashed table of wa_lst1
            with unique key matnr
            with header line.
    structures for alv grid display.
    itabs
    type-pools: slis.
    data: it_lst            like standard table of wa_lst with header line,
          it_fieldcat_lst   type slis_t_fieldcat_alv with header line,
          it_sort_lst       type slis_t_sortinfo_alv,
          it_lst1           like standard table of wa_lst1 with header line,
          it_fieldcat_lst1  type slis_t_fieldcat_alv with header line,
          it_sort_lst1      type slis_t_sortinfo_alv.
    structures
    data: wa_sort         type slis_sortinfo_alv,
          ls_layout       type slis_layout_alv.
    color management.
    DATA  : wa_color    TYPE lvc_s_scol.
    Internal table for color management.
    DATA : it_color    TYPE TABLE          OF lvc_s_scol.
    itab for input enabling.
    DATA: lt_celltab TYPE lvc_t_styl. "
    global varialbes
    data: g_lines type i.
    data: g_repid like sy-repid,
          ok_code       like sy-ucomm.
    selection-screen
    "text: Dates:
    select-options: so_budat for mkpf-budat default sy-datum.
    "text: Material numbers.
    select-options: so_matnr for mseg-matnr.
    selection-screen uline.
    selection-screen skip 1.
    "Text: show summary by material.
    parameters: gp_bymat as checkbox default ''.
    parameters: gp_hier  as checkbox default 'X'.
    start-of-selection.
      perform get_data.
      perform show_data.
    end-of-selection.
          FORM get_data                                                 *
    form get_data.
            select mblnr mjahr budat xblnr
                into table ht_mkpf
               from mkpf
              where budat in so_budat. " make use of std index.
    have we retrieved data from mkpf?
      describe table ht_mkpf lines g_lines.
      if g_lines > 0.
    if true then retrieve all related records from mseg.
    Doing this way we make sure that the access is by primary key
    of mseg.
    The reason is that is faster to filter them in memory
    than to allow the db server to do it.
        select mblnr mjahr zeile bwart charg
                 matnr lifnr erfmg erfme
          into table ht_mseg
          from mseg
            for all entries in ht_mkpf
         where mblnr = ht_mkpf-mblnr
           and mjahr = ht_mkpf-mjahr.
      endif.
    fill t_lst or t_lst1 according to user's choice.
      if gp_bymat = ' '.
        perform fill_ht_lst.
      else.
        perform fill_ht_lst1.
      endif.
    endform.
    form fill_ht_lst.
      refresh ht_lst.
    Example: how to discard unwanted data in an efficient way.
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
      read header line.
        read table ht_mkpf with table key mblnr = ht_mseg-mblnr
        mjahr = ht_mseg-mjahr.
        clear ht_lst.
    * note : this may be faster if you specify field by field.
        move-corresponding ht_mkpf to ht_lst.
        move-corresponding ht_mseg to ht_lst.
        perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
        perform read_material using ht_mseg-matnr changing ht_lst-maktx.
        insert table ht_lst.
      endloop.
    endform.
    form fill_ht_lst1.
    data: colorear.
      refresh ht_lst1.
    Example: how to discard unwanted data in an efficient way.
             hot to simulate a collect in a faster way
      loop at ht_mseg.
      filter unwanted data
        check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
        check ht_mseg-matnr in so_matnr.
    * note : this may be faster if you specify field by field.
        read table ht_lst1 with table key matnr = ht_mseg-matnr
        transporting erfmg.
        if sy-subrc <> 0. " if matnr doesn't exist in sumary table
        " insert a new record
          clear ht_lst1.
          ht_lst1-matnr = ht_mseg-matnr.
          perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
          ht_lst1-erfmg = ht_mseg-erfmg.
          ht_lst1-erfme = ht_mseg-erfme.
          if colorear = ''.
            colorear = 'X'.
            refresh it_color.
            ht_lst1-color_cell[] = it_color[].
            MOVE 'C410' TO ht_lst1-color_line.
          else.
            colorear = ' '.
            refresh it_color. clear it_color.
            MOVE 'MATNR' TO wa_color-fname.
            MOVE '6'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'MAKTX' TO wa_color-fname.
            MOVE '3'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            MOVE 'ERFMG' TO wa_color-fname.
            MOVE '5'         TO wa_color-color-col.
            MOVE '1'         TO wa_color-color-int.
            MOVE '1'         TO wa_color-color-inv.
            APPEND wa_color TO it_color.
            ht_lst1-color_cell[] = it_color[].
            clear ht_lst1-color_line.
          endif.
          insert table ht_lst1.
        else." a record was found.
        " collect erfmg.  To do so, fill in the unique key and add
        " the numeric fields.
          ht_lst1-matnr = ht_mseg-matnr.
          add ht_mseg-erfmg to ht_lst1-erfmg.
          modify table ht_lst1 transporting erfmg.
        endif.
      endloop.
    endform.
    implementation of cache for lfa1.
    form read_lfa1 using p_lifnr changing p_name1.
            read table ht_lfa1 with table key lifnr = p_lifnr
            transporting name1.
      if sy-subrc <> 0.
        clear ht_lfa1.
        ht_lfa1-lifnr = p_lifnr.
        select single name1
           into ht_lfa1-name1
          from lfa1
        where lifnr = p_lifnr.
        if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
        insert table ht_lfa1.
      endif.
      p_name1 = ht_lfa1-name1.
    endform.
    implementation of cache for material data
    form read_material using p_matnr changing p_maktx.
      read table ht_material with table key matnr = p_matnr
      transporting maktx.
      if sy-subrc <> 0.
        ht_material-matnr = p_matnr.
        select single maktx into  ht_material-maktx
          from makt
         where spras = sy-langu
           and matnr = p_matnr.
        if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
        insert table ht_material.
      endif.
      p_maktx = ht_material-maktx.
    endform.
    form show_data.
      if gp_hier = 'X'. "no anda.
       perform show_hierarchicalALV.
      else.
        if gp_bymat = ' '.
          perform show_ht_lst.
        else.
          perform show_ht_lst1.
        endif.
      endif.
    endform.
    form show_hierarchicalALV.
    st_mkpf[] = ht_mkpf[].
    st_mseg[] = ht_mseg[].
    call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
      I_INTERFACE_CHECK              = ' '
      I_CALLBACK_PROGRAM             =
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      IS_LAYOUT                      =
      IT_FIELDCAT                    =
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
      IT_EVENTS                      =
      IT_EVENT_EXIT                  =
       i_tabname_header               =
       i_tabname_item                 =
      I_STRUCTURE_NAME_HEADER        =
      I_STRUCTURE_NAME_ITEM          =
       is_keyinfo                     =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_BUFFER_ACTIVE                =
      I_BYPASSING_BUFFER             =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      tables
        t_outtab_header                = st_mkpf
        t_outtab_item                  = st_mseg
    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.
    form show_ht_lst.
      "needed because the FM can't use a hashed table.
      it_lst[] = ht_lst[].
      perform fill_layout using 'full display'
                           changing ls_layout.
      perform fill_columns_lst.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form show_ht_lst1.
      "needed because the FM can't use a hashed table.
      it_lst1[] = ht_lst1[].
      perform fill_layout using 'Sumary by matnr'
                           changing ls_layout.
      perform fill_columns_lst1.
    perform sort_lst.
      g_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program       = g_repid
                i_callback_pf_status_set = 'SET_PF_STATUS'
                is_layout                = ls_layout
                it_fieldcat              = it_fieldcat_lst1[]
               it_sort                  = it_sort_lst
           tables
                t_outtab                 = it_lst1
           exceptions
                program_error            = 1
                others                   = 2.
    endform.
    form fill_layout using p_window_titlebar
                   changing cs_layo type slis_layout_alv.
      clear cs_layo.
      cs_layo-window_titlebar        = p_window_titlebar.
      cs_layo-edit                   = 'X'.
      cs_layo-edit_mode              = space.
      MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.
    Field that identify cell color in inetrnal table
      MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
    move 'CELLTAB' TO cs_layo-stylefname.
    endform.                    " armar_layout_stock
    form set_pf_status using rt_extab type slis_t_extab.
    create a new status
    and then select extras -> adjust template -> listviewer
      set pf-status 'VISTA'.
    endform.        "set_pf_status
    define add_lst.
      clear it_fieldcat_lst.
      it_fieldcat_lst-fieldname     = &1.
      it_fieldcat_lst-outputlen     = &2.
      it_fieldcat_lst-ddictxt       = 'L'.
      it_fieldcat_lst-seltext_l       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      it_fieldcat_lst-seltext_m       = &1.
      if &1 = 'MATNR'.
        it_fieldcat_lst-emphasize = 'C111'.
      endif.
      append it_fieldcat_lst.
    end-of-definition.
    define add_lst1.
      clear it_fieldcat_lst.
      it_fieldcat_lst1-fieldname     = &1.
      it_fieldcat_lst1-outputlen     = &2.
      it_fieldcat_lst1-ddictxt       = 'L'.
      it_fieldcat_lst1-seltext_l       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      it_fieldcat_lst1-seltext_m       = &1.
      append it_fieldcat_lst1.
    end-of-definition.
    form fill_columns_lst.
    set columns for output.
      refresh it_fieldcat_lst.
      add_lst 'BUDAT' 10.
      add_lst   'MBLNR' 10.
      add_lst  'LIFNR' 10.
      add_lst  'NAME1' 35.
      add_lst  'XBLNR' 15.
      add_lst    'ZEILE' 5.
      add_lst    'CHARG' 10.
      add_lst   'MATNR' 18.
      add_lst   'MAKTX' 30.
      add_lst   'ERFMG' 17.
      add_lst   'ERFME' 5.
      add_lst   'MJAHR' 4.
    endform.
    form fill_columns_lst1.
    set columns for output.
      refresh it_fieldcat_lst1.
      add_lst1 'MATNR' 18.
      add_lst1 'MAKTX' 30.
      add_lst1 'ERFMG' 17.
      add_lst1 'ERFME' 5..
    endform.
    Horacio Zapettini
    Program to Calculate FI Opening Balance
    How to find the Opening balance for a given period in FI Module for a Particular GL A/c.
    I was calculated opening balance, code is below maybe it will be helpful.
    *find period.
      CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
        EXPORTING
          i_date         = s_budat-low
          i_periv        = i_tab-periv                          "'K4'
        IMPORTING
          e_buper        = v_donem
          e_gjahr        = v_gjahr
        EXCEPTIONS
          input_false    = 1
          t009_notfound  = 2
          t009b_notfound = 3
          OTHERS         = 4.
    *calc opening balance hesabý
      SELECT * FROM knc1 WHERE kunnr = i_tab-kunnr
                         AND bukrs = i_tab-bukrs " s_bukrs
                         AND gjahr EQ v_gjahr.
        v_dnm = v_donem.
    opening balance first calc > old year ,
        WHILE v_dnm > 1.
          v_dnm = v_dnm - 1.
          CONCATENATE 'knc1-um' v_dnm 's' INTO v_field_name_borc.
          CONCATENATE 'knc1-um' v_dnm 'h' INTO v_field_name_alacak.
          ASSIGN (v_field_name_borc) TO  old
    add days which is from selected date-low month
        IF v_donem > 1.
          v_dnm = v_donem - 1.
        ELSE.
          v_dnm = v_donem.
        ENDIF.
        SELECT SINGLE * FROM t009b WHERE periv = i_tab-periv    "'K4'
                                     AND bdatj = s_budat-low+0(4)
                                     AND poper = v_dnm.
        t009b-butag = t009b-butag + 1.
        IF s_budat-low+6(2) NE t009b-butag.
          v_date_high = s_budat-low - 1.
          IF v_donem = 1.
            v_date_low = s_budat-low.
            v_date_low+4(4)  = '0101'.
          ELSE.
            CONCATENATE t009b-bdatj t009b-bumon t009b-butag INTO
            v_date_low.
          ENDIF.
          SELECT *  FROM bsad WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
                                AND kunnr = i_tab-kunnr
                                AND budat BETWEEN v_date_low AND
                                v_date_high
                                AND umskz = space
                                AND blart IN s_blart.
            IF bsad-shkzg = 'S'.
              i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsad-dmbtr ).
            ELSEIF bsad-shkzg = 'H'.
              i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsad-dmbtr   ).
            ENDIF.
          ENDSELECT.
          SELECT *  FROM bsid WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
                               AND kunnr = i_tab-kunnr
                               AND budat BETWEEN v_date_low AND
                               v_date_high
                               AND umskz = space
                               AND blart IN s_blart.
                                 AND gsber IN gsber.
            IF bsid-shkzg = 'S'.
              i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsid-dmbtr   ).
            ELSEIF bsid-shkzg = 'H'.
              i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsid-dmbtr   ).
            ENDIF.
          ENDSELECT.
        ENDIF.
        "opening balance ( þirket bazlý )z1 degeri
       i_tab-z1 = i_tab-z1 + ( knc1-umsav + i_tab-dmbtr_s - i_tab-dmbtr_h ).
    for israel
        i_tab-dmbtril_s = i_tab-dmbtr_s .
        i_tab-dmbtril_h = i_tab-dmbtr_h .
      ENDSELECT.
    praveen

  • Doubt in ALV coloring

    hai friends,
    i want to give a color for specified line in ALV list or grid.
    How can i give?
    What are the declaration should i do?
    if have, please mail me sample coding .
    thanks,
    Maran

    Here is the sample code.  This program shows how to color a line, column or cell.
    report zrich_0002 .
    * Use of colours in ALV grid (cell, line and column)            *
    * Table
    tables : mara.
    * Type
    types : begin of ty_mara,
              matnr         like mara-matnr,
              matkl         like mara-matkl,
              counter(4)    type n,
              free_text(15) type c,
              color_line(4) type c,           " Line color
              color_cell    type lvc_t_scol,  " Cell color
    end of ty_mara.
    * Structures
    data  : wa_mara     type ty_mara,
            wa_fieldcat type lvc_s_fcat,
            is_layout   type lvc_s_layo,
            wa_color    type lvc_s_scol.
    * Internal table
    data : it_mara     type standard table of ty_mara,
           it_fieldcat type standard table of lvc_s_fcat,
           it_color    type table          of lvc_s_scol.
    * Variables
    data : okcode like sy-ucomm,
           w_alv_grid          type ref to cl_gui_alv_grid,
           w_docking_container type ref to cl_gui_docking_container.
    parameters : p_column as checkbox,
                 p_line   as checkbox,
                 p_cell   as checkbox.
    at selection-screen output.
      perform get_data.
      perform fill_catalog.
      if w_docking_container is initial.
        perform create_objects.
      endif.
    *&      Form  create_objects
    form create_objects.
      create object w_docking_container
        exporting
          ratio                       = 60
        exceptions
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5
          others                      = 6.
      create object w_alv_grid
        exporting
          i_parent          = w_docking_container.
    * Field that identify color line in internal table
      move 'COLOR_LINE' to is_layout-info_fname.
    * Field that identify cell color in inetrnal table
      move 'COLOR_CELL' to is_layout-ctab_fname.
      call method w_alv_grid->set_table_for_first_display
        exporting
          is_layout                     = is_layout
        changing
          it_outtab                     = it_mara
          it_fieldcatalog               = it_fieldcat
        exceptions
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          others                        = 4.
    endform.
    *&      Form  get_data
    form get_data.
      select * from mara up to 5 rows.
        clear : wa_mara-color_line, wa_mara-color_cell.
        move-corresponding mara to wa_mara.
        add 1                   to wa_mara-counter.
        move 'Blabla'           to wa_mara-free_text.
        if wa_mara-counter = '0002'
        and p_line = 'X'.
    * Color line
          move 'C410' to wa_mara-color_line.
        elseif wa_mara-counter = '0004'
        and p_cell = 'X'.
    * Color cell
          move 'FREE_TEXT' to wa_color-fname.
          move '6'         to wa_color-color-col.
          move '1'         to wa_color-color-int.
          move '1'         to wa_color-color-inv.
          append wa_color to it_color.
          wa_mara-color_cell[] = it_color[].
        endif.
        append wa_mara to it_mara.
      endselect.
    endform.
    *&      Form  fill_catalog
    form fill_catalog.
    * Colour code :                                                 *
    * Colour is a 4-char field where :                              *
    *              - 1st char = C (color property)                  *
    *              - 2nd char = color code (from 0 to 7)            *
    *                                  0 = background color         *
    *                                  1 = blue                     *
    *                                  2 = gray                     *
    *                                  3 = yellow                   *
    *                                  4 = blue/gray                *
    *                                  5 = green                    *
    *                                  6 = red                      *
    *                                  7 = orange                   *
    *              - 3rd char = intensified (0=off, 1=on)           *
    *              - 4th char = inverse display (0=off, 1=on)       *
    * Colour overwriting priority :                                 *
    *   1. Line                                                     *
    *   2. Cell                                                     *
    *   3. Column                                                   *
      data : w_position type i value '1'.
      clear wa_fieldcat.
      move w_position to wa_fieldcat-col_pos.
      move 'MATNR'    to wa_fieldcat-fieldname.
      move 'MARA'     to wa_fieldcat-ref_table.
      move 'MATNR'    to wa_fieldcat-ref_field.
      append wa_fieldcat to it_fieldcat.
      add 1 to w_position.
      clear wa_fieldcat.
      move w_position to wa_fieldcat-col_pos.
      move 'MATKL'    to wa_fieldcat-fieldname.
      move 'MARA'     to wa_fieldcat-ref_table.
      move 'MATKL'    to wa_fieldcat-ref_field.
    * Color column
      if p_column = 'X'.
        move 'C610'     to wa_fieldcat-emphasize.
      endif.
      append wa_fieldcat to it_fieldcat.
      add 1 to w_position.
      clear wa_fieldcat.
      move w_position to wa_fieldcat-col_pos.
      move 'COUNTER'  to wa_fieldcat-fieldname.
      move 'N'        to wa_fieldcat-inttype.
      move '4'        to wa_fieldcat-intlen.
      move 'Counter'  to wa_fieldcat-coltext.
      append wa_fieldcat to it_fieldcat.
      add 1 to w_position.
      clear wa_fieldcat.
      move w_position  to wa_fieldcat-col_pos.
      move 'FREE_TEXT' to wa_fieldcat-fieldname.
      move 'C'         to wa_fieldcat-inttype.
      move '20'        to wa_fieldcat-intlen.
      move 'Text'      to wa_fieldcat-coltext.
      append wa_fieldcat to it_fieldcat.
    endform.
    REgards,
    Rich Heilman

  • ALV: Color cells in subtotals. Is it possible?

    Hi,
    I have an ALV-report which initially shows subtotals only. The users want to see specific colors in specific cells of the subtotals if possible.
    Is it?
    Regards
    Thomas

    Hi Thomas,
    Please check the Demo program ERGP2120.
    It has this feature.
    Step1: define you internal table like below
    DATA: BEGIN OF mylist OCCURS 20,       " Internal table for preparing
            zuordnung(8) TYPE c,
            belegnr(10) TYPE c,
            ba(2) TYPE c,
            bldatum TYPE d,
            bs(2) TYPE c,
            s(4) TYPE c VALUE ' ',
            wrg(4) TYPE c,
            betrag TYPE p DECIMALS 2,
            colinfo TYPE slis_t_specialcol_alv,
          END OF mylist.
    Step2:
      LOOP AT lt_mylist.
        REFRESH gt_color.
        CLEAR   gt_color.
        IF lt_mylist-betrag  > 500000.
          CLEAR gt_color.
          gt_color-fieldname = 'BETRAG'.
          gt_color-color-col = cl_gui_resources=>list_col_positive.
          gt_color-color-int = 0.
          APPEND gt_color.
        ELSEIF lt_mylist-betrag < 100000.
          CLEAR gt_color.
          gt_color-fieldname = 'BETRAG'.
          gt_color-color-col =  cl_gui_resources=>list_col_negative.
          gt_color-color-int = 0.
          APPEND gt_color.
        ENDIF.
        lt_mylist-colinfo[] = gt_color[].
        MODIFY lt_mylist.
      ENDLOOP.
    Thanks,
    Ramakrishna
    Message was edited by: Ramakrishna Prasad

  • ALV color a particular cell on meeting certain condition

    hi all
         i am working with ALV , my requirement is to color a particular cell if condition mate.
    like .
       i have two fields in my ITAB  PlanedCost and ActualCost
    If ACTUALCOST is >= 80% of PLANEDCOST then
    ACTUALCOST cell must come in RED COLOR.
    how to do so .
    please guide me.

    Hi Rock,
            I tried a program to color a cell based on its value, but it is not working. Am pasting the code below and please can u exactly tell me what is the problem it.
    *& Report  ZSAPCOLV
    REPORT  zsapcolv.
    TABLES:mara.
    TYPES:BEGIN OF ty_mara,
          matnr TYPE mara-matnr,
          mtart TYPE mara-mtart,
          color1(4),
         END OF ty_mara.
    DATA:it_mara TYPE STANDARD TABLE OF ty_mara,
         it_color  TYPE TABLE  OF lvc_s_scol,
         wa_mara TYPE ty_mara,
         wa_color    TYPE lvc_s_scol,
         is_layout   TYPE lvc_s_layo.
    DATA: t_newtable TYPE REF TO data,
    t_newline  TYPE REF TO data.
    FIELD-SYMBOLS: <dyntab> TYPE STANDARD TABLE,
                   <wa_dyntab> TYPE ANY,
                   <gfs_wa> TYPE ANY.
    TYPES: BEGIN OF ty_cmara,
        matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
       tabcolor TYPE lvc_t_scol,
    END OF ty_cmara.   " Cell color
    DATA:it_cmara TYPE STANDARD TABLE OF ty_cmara.
    DATA:
          gr_table     TYPE REF TO cl_salv_table,
          gr_functions TYPE REF TO cl_salv_functions,
          gr_display   TYPE REF TO cl_salv_display_settings.
    DATA:   it_fcat TYPE lvc_t_fcat,
            wa_fcat TYPE lvc_s_fcat.
    DATA:it_fcat1 TYPE lvc_t_fcat, "with cell color
         it_fcat2 TYPE lvc_t_fcat,
    wa_fieldcat LIKE LINE OF it_fcat1,
    wa_cellcolors TYPE lvc_s_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:<t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    DATA:t_line  TYPE REF TO data .
    *-----design selection screen for plant and material type.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-b01.
    SELECT-OPTIONS:
                     s_matnr     FOR mara-matnr.    "material type
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      PERFORM fetch_data.
      PERFORM display_data.
    *&      Form  fetch_data
    FORM fetch_data .
      DATA:wa_cmara TYPE ty_cmara.
      DATA: ls_tabcolor TYPE lvc_s_scol.
      SELECT
    FROM mara
        INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE matnr IN s_matnr.
      CHECK sy-subrc EQ 0.
      PERFORM build_catalog USING '1' 'MATNR' 'Material number' 'Material Number' ' ' '18'.
      PERFORM build_catalog USING '1' 'MTART' 'Material type' 'Material type' ' ' '10'.
      it_fcat1[] = it_fcat[].
       wa_fieldcat-fieldname = 'T_CELLCOLORS'.
       wa_fieldcat-ref_field = 'COLTAB'.
       wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
      APPEND wa_fieldcat TO it_fcat.
      cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = it_fcat
                                                  IMPORTING ep_table = t_newtable ).
      ASSIGN t_newtable->* TO <dyntab>.
      CREATE DATA t_line LIKE LINE OF <dyntab>.
      ASSIGN t_line->* TO <gfs_wa>.
      PERFORM fill_data.
    ENDFORM.                    " fetch_data
    *&      Form  build_catalog
    FORM build_catalog  USING    p_pos TYPE lvc_colpos
                           p_field TYPE lvc_fname
                           p_reptext TYPE reptext
                           p_coltext TYPE coltext
                           p_check TYPE lvc_checkb
                           p_len TYPE lvc_outlen.
      wa_fcat-col_pos    = p_pos.
      wa_fcat-fieldname  = p_field.
      wa_fcat-reptext    = p_reptext.
      wa_fcat-checkbox   = p_check.
      wa_fcat-outputlen  = p_len.
      wa_fcat-emphasize = '6'.
      IF p_check = 'X'.
        wa_fcat-edit = 'X'.
      ENDIF.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
    ENDFORM.                    " catalog
    *&      Form  fill_data
    FORM fill_data .
      FIELD-SYMBOLS: <wa_tmp> TYPE ANY,
                     <v_fld> TYPE ANY,
                     <color> TYPE ANY,
                     <wa_color> TYPE lvc_s_scol.
      DATA: v_fld(20).
      DATA : lv_cnt TYPE i,
             t_newline1  type ref to data,
             lv_cnt1 TYPE i.
        FIELD-SYMBOLS: <ta_color> TYPE lvc_t_scol.
         DATA : field(15) TYPE c,
             col TYPE lvc_s_scol.
      create data t_newline1 LIKE <wa_color>.
      LOOP AT it_mara INTO wa_mara.
        lv_cnt1 = lv_cnt1 + 1.
        LOOP AT it_fcat INTO wa_fcat.
          UNASSIGN <wa_tmp>.
          ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <wa_tmp>.
          CONCATENATE 'WA_MARA-' wa_fcat-fieldname INTO v_fld.
          ASSIGN (v_fld) TO <v_fld>.
          CHECK sy-subrc EQ 0.
          IF <v_fld> = '000000000000000004'.
             col-fname = wa_fcat-fieldname.
             col-color-col = '5' .
             col-color-int = '0' .
              "ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <ta_color>.
               ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <ta_color> .
               APPEND col TO <ta_color>.
            <wa_tmp> = <v_fld>.
            lv_cnt = lv_cnt + 1.
          ENDIF.
          IF lv_cnt = 1.
            APPEND <gfs_wa> TO <dyntab>.
          ELSE.
            MODIFY <dyntab> INDEX lv_cnt1 FROM <gfs_wa>.
          ENDIF.
        ENDLOOP.
        lv_cnt = 0.
        CLEAR wa_mara.
      ENDLOOP.
    ENDFORM.                    " fill_data
    *&      Form  display_data
    FORM display_data .
    IF <dyntab> IS NOT INITIAL.
       LOOP AT <dyntab> INTO <gfs_wa>.
         ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gfs_wa> TO <w_field>.
         ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <t_cellcolors> .
         CLEAR wa_cellcolors.
        "wa_cellcolors-fname = 'MATNR'.
         "IF <w_field> = '000000000000000004'.
           "FORMAT INTENSIFIED COLOR = 6.
           wa_cellcolors-fname = 'MATNR'.
           wa_cellcolors-color-col = '7'.
           wa_cellcolors-color-int = '1'.
           "wa_cellcolors-color-inv = '1'.
           "wa_cellcolors-NOKEYCOL = ''.
          "ELSE.
          "wa_cellcolors-color-col = '5'.
        "ENDIF.
         APPEND wa_cellcolors TO <t_cellcolors>.
         MODIFY <dyntab> FROM <gfs_wa>.
       ENDLOOP.
      cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyntab> ).
      gr_functions = gr_table->get_functions( ).
      gr_functions->set_all( abap_true ).
      gr_display = gr_table->get_display_settings( ).
      gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
      gr_display->set_list_header( 'MARA DATA' ).
      gr_table->display( ).
      "ENDIF.
    ENDFORM.                    " display_data

  • ALV color priority:  The layout color or the cell color?

    I'm trying to assign an ALV at the cell level but it is not showing up.  I have specificed the column color at the layout level.  Does the layout level have color priority?

    Hi
    see the doc and do accordingly
    1. add one more field to ur final internal table say COLOR(4)
    2. in layout wa_layout-style_fname = 'COLOR'. " if its grid
    wa_layout-style_fieldname = 'COLOR'. "if its list
    3. read table itab index 3.
    itab-color = 'C410'.
    modify itab index 3
    4. see program SHOWCOLO for all color codes
    1. Add a field of data type CHAR(3) to the internal output table.
    2. Enter the color code in the appropriate field of the row to be colored in the internal
    output table:
    Code: 'Cxy'
    C = Color (all codes begin with 'C')
    x = color number ('1' - '9')
    y = highlight ('0' = off, '1' = on)
    3. Assign the internal output table color code field name to the IS_LAYOUT importing
    structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call
    interface.
    To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, let’s modify declaration of our list data table “gt_list”.
    you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field “INFO_FNAME” of the layout structure.
    e.g.
    ps_layout-info_fname = <field_name_containing_color_codes>. “e.g. ‘ROWCOLOR’
    You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.
    You can color an entire row as described in the next section. However, this method is less time consuming.
    Coloring Individual Cells
    This is the last point about coloring procedures for the ALV Grid. The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by “more” is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.
    The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse).
    If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.
    Regards
    Anji

  • ALV coloring help

    Hi all,
    Hi I have 2 requirements in ALV.
    1)  my third field is Sales Organisation.I have to make the column  heading of this column intesified.
    2)In the top of page I have to color a particular line.
    Please suggest some solution as soon as possible as I need it very urgently...
    Thanks
    Nazmul

    you can show the color in the Top of  page .
    Check this..
    TOP_OF_PAGE in ALV  Using CL_GUI_ALV_GRID
    and also check this
    report  ztest_page.
    tables: sflight.
    data : it_flight type table of sflight with header line.
    data begin of it_sel_opt occurs 0.
            include structure rsparams.
    data end   of it_sel_opt.
    select-options: s_carrid for sflight-carrid.
    start-of-selection.
      select * from sflight into table it_flight
       where carrid in s_carrid.
    end-of-selection.
      call function 'RS_REFRESH_FROM_SELECTOPTIONS'
        exporting
          curr_report     = sy-repid
        tables
          selection_table = it_sel_opt
        exceptions
          not_found       = 01
          no_report       = 02.
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program          = sy-repid
          i_callback_html_top_of_page = 'TOP_OF_PAGE'
          i_structure_name            = 'SFLIGHT'
        tables
          t_outtab                    = it_flight
        exceptions
          program_error               = 1
          others                      = 2.
    *&      Form  top_of_page
    *       text
    *      -->DOCUMENT   text
    form top_of_page using document type ref to cl_dd_document.
      data : dl_text(255) type c.  "Text
    * Add new-line
      call method document->new_line.
      call method document->new_line.
      clear : dl_text.
    * program ID
      dl_text = 'Program Name :'.
      call method document->add_gap.
      call method document->add_text
        exporting
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_heading_int.
      clear dl_text.
      dl_text = sy-repid.
      call method document->add_text
        exporting
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      call method document->new_line.
      clear : dl_text.
      dl_text = 'Selection Criteria'.
      call method document->add_gap
        exporting
          width = 34.
      call method document->add_text
        exporting
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      call method document->new_line.
      clear : dl_text.
      concatenate 'SELECT Option' 'SIGN' 'OPTION' 'LOW' 'HIGH'
      into dl_text separated by cl_abap_char_utilities=>horizontal_tab.
      call method document->add_gap
        exporting
          width = 34.
      call method document->add_text
        exporting
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      call method document->new_line.
      loop at it_sel_opt.
        clear : dl_text.
        concatenate it_sel_opt-selname  it_sel_opt-sign
         it_sel_opt-option it_sel_opt-low it_sel_opt-high
        into dl_text separated by cl_abap_char_utilities=>horizontal_tab.
        call method document->add_gap
          exporting
            width = 34.
        call method document->add_text
          exporting
            text         = dl_text
            sap_emphasis = cl_dd_area=>heading
            sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
        call method document->new_line.
      endloop.
    endform.                    "top_of_page

  • Help needed for editable alv grid program

    hi,
    Can you please tell me how to set a ‘update’ button in application toolbar of alv griv without suppressing it and how to write the code for that update button so that if I change my editable column data and press the update button my updated data should be stored in my database table.
    the code what i wrote is:
    TABLES: vbak,vbap.
    TYPE-POOLS: slis. "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_final,
    vbeln LIKE vbak-vbeln,
    erdat LIKE vbak-erdat,
    matnr LIKE vbap-matnr,
    posnr LIKE vbap-posnr,
    END OF t_final.
    DATA: i_final TYPE STANDARD TABLE OF t_final INITIAL SIZE 0,
    wa_final TYPE t_final.
    *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.
    *Start-of-selection.
    START-OF-SELECTION.
    PERFORM data_retrieval.
    PERFORM build_fieldcatalog.
    PERFORM build_layout.
    PERFORM display_alv_report.
    *& Form BUILD_FIELDCATALOG
    •     Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
    fieldcatalog-fieldname = 'VBELN'.
    fieldcatalog-seltext_m = 'sales order'.
    fieldcatalog-col_pos = 0.
    APPEND fieldcatalog TO fieldcatalog.
    CLEAR fieldcatalog.
    fieldcatalog-fieldname = 'ERDAT'.
    fieldcatalog-seltext_m = 'date'.
    fieldcatalog-col_pos = 1.
    APPEND fieldcatalog TO fieldcatalog.
    CLEAR fieldcatalog.
    fieldcatalog-fieldname = 'MATNR'.
    fieldcatalog-seltext_m = 'material no.'.
    fieldcatalog-col_pos = 2.
    fieldcatalog-edit = 'X'.
    APPEND fieldcatalog TO fieldcatalog.
    CLEAR fieldcatalog.
    fieldcatalog-fieldname = 'POSNR'.
    fieldcatalog-seltext_m = 'line item no.'.
    fieldcatalog-col_pos = 3.
    APPEND fieldcatalog TO fieldcatalog.
    CLEAR fieldcatalog.
    ENDFORM. " BUILD_FIELDCATALOG
    *& Form BUILD_LAYOUT
    •     Build layout for ALV grid report
    FORM build_layout.
    gd_layout-no_input = 'X'.
    gd_layout-colwidth_optimize = 'X'.
    gd_layout-totals_text = 'Totals'(201).
    •     gd_layout-totals_only = 'X'.
    •     gd_layout-f2code = 'DISP'. "Sets fcode for when double
    •     "click(press f2)
    •     gd_layout-zebra = 'X'.
    •     gd_layout-group_change_edit = 'X'.
    •     gd_layout-header_text = 'helllllo'.
    ENDFORM. " BUILD_LAYOUT
    *& Form DISPLAY_ALV_REPORT
    •     Display report using ALV grid
    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
    TABLES
    t_outtab = i_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
    *& Form DATA_RETRIEVAL
    •     Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
    SELECT avbeln aerdat bmatnr bposnr FROM vbak AS a
    INNER JOIN vbap AS b ON avbeln = bvbeln
    INTO TABLE i_final WHERE avbeln = bvbeln.
    •     ENDFORM. " DATA_RETRIEVAL
    thanks in advance.

    hi sudhir,
    thanks for ur reply.
    after seeing the code u send to me i made changes to my program.but still when i click on update button,nothing is happening.can u please suggest me an idea.
    TABLES: vbak,vbap.
    TYPE-POOLS: slis.                                 "ALV Declarations
    TYPES: BEGIN OF t_final,
         vbeln LIKE vbak-vbeln,
         erdat LIKE vbak-erdat,
         matnr LIKE vbap-matnr,
         posnr LIKE vbap-posnr,
         END OF t_final.
    DATA: i_final TYPE STANDARD TABLE OF t_final WITH HEADER LINE,
          wa_final TYPE t_final.
    *DATA:i_final LIKE vbap OCCURS 0.
    *DATA:wa_final LIKE vbap.
    *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.
    *Start-of-selection.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      fieldcatalog-fieldname   = 'VBELN'.
      fieldcatalog-seltext_m   = 'sales order'.
      fieldcatalog-col_pos     = 0.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'ERDAT'.
      fieldcatalog-seltext_m   = 'date'.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'material no.'.
      fieldcatalog-col_pos     = 2.
      fieldcatalog-edit        = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'POSNR'.
      fieldcatalog-seltext_m   = 'line item no.'.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    gd_layout-totals_only        = 'X'.
    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                            "click(press f2)
    gd_layout-zebra             = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text       = 'helllllo'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    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_callback_pf_status_set = 'GUI_STAT'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               it_events                = it_events
                i_save                  = 'X'
               is_variant              = z_template
           TABLES
                t_outtab                = i_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
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT avbeln aerdat bmatnr bposnr FROM vbak AS a
      INNER JOIN vbap AS b ON avbeln = bvbeln
      INTO TABLE i_final WHERE avbeln = bvbeln.
    ENDFORM.                    " DATA_RETRIEVAL
          FORM GUI_STAT                                                 *
    -->  RT_EXTAB                                                      *
    FORM gui_stat USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'UPDATE' EXCLUDING rt_extab.
    ENDFORM.
          FORM USER_COMMAND                                             *
    -->  U_COMM                                                        *
    -->  RS_SELFIELD                                                   *
    FORM user_command USING u_comm LIKE sy-ucomm
    rs_selfield TYPE slis_selfield.
      DATA:selfield TYPE slis_selfield.
      CASE u_comm.
        WHEN 'UPDATE'.
          LOOP AT i_final ."into wa_final.
            i_final-matnr = vbap-matnr.
            update (vbap) from table i_final.
            IF sy-subrc = 0.
              MESSAGE s000(0) WITH 'records updated successfully'.
            ENDIF.
          ENDLOOP.
      ENDCASE.
    ENDFORM.

  • Calling a ALV Report program via a Remote Function module.

    H All,
         The thing which I am looking out for is ,to know a technique to acheive this,
      To start with,
    For the transaction MB51-(Material Document List),which is a Report Program "RM07DOCS",I also observed that this uses a ALV to display the output.
    Now what I actually require is another extra field (from MARA table )  along with the standard output that is displayed from this report.
    Also this needs to be passed to a different UI system(build using VC ).
    So I have a RFC eg DisplayList(),where in I need to exeucte this report program ,get the output what it gives ,add my additional information what I want to and pass it as a export parameter,
    So this is the structure which I can visualise,
    FUNCTION ZFUN_MB51TXN.
    I would get all the import parameters here ,from who ever is calling my fun module,
    *Call the report program,pass the input  parameters required
    *get the output from this report program
    *send the output to the caller through export parameters
    ENDFUNCTION.
    So Here I need to know ,Can this be achieved something using Submit report or anything,Any guidelines to move further would be really of great help!

    Hi All,
    It would really be great if you can explain with the reference to the same report program,the same selection screen elemetns or something.
    Thanks,
    Archies!

  • Functionality of queries to be added to custom ALV GRID program

    I have got a requirement in which we have created a custom program. Earlier it used to be a query for that. Now the customer wants the same options such as ABC analysis , Graphics , Import to excel, word processing etc., options to be added to the custom program. What I have observed is that these are present in the  PF status of the ALV grid display which I am using . Is there any way to trigger the functionality of them directly after displaying the ALV. i.e. If the user wants to see the ABC analysis checks the option and we need to get the ABC analysis which is there in the ALV display

    Varun,
    I have never tried this but try callig the function LVC_ABC_ANALYSIS and pass the field catalog and the field on which you want to do the analysis, after the SET_TABLE_FOR_FIRST_DISPLAY method or the REUSE* function.
    Regards,
    Ravi
    Note : Please mark the helpful answers

  • ALV colors in edit mode

    Hello,
    I have an ALV grid with an editable checkbox column.
    Now I have two problems regarding the colors:
    1. as you know, when in edit mode, the colors change. I overrode them with custom colors, but the editable column's cells have still a white margin which I cannot get rid of
    2. Zebra layout does not work anymore. If I color the rows with a zebra pattern manually, I would have to re-do it everytime the table is resorted.
    Can anyone think of a better way to handle coloring in edit mode?
    Thanks a lot.

    hi,
    Chk this link.
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
    Regards
    Reshma

  • ALV colors

    Please let me know how to display alternate colors in ALV?
    how to display end of list and top of list in a seperate colour?
    Thanks

    Hello Ramya,
    there is an option for zebra coloring in  layout... use the following statement.
    data:       g_r_layout    type  slis_layout_alv.
      g_r_layout-zebra = 'X'.
    example code is below...
    report z_alv_ex1 .
    *SET TITLEBAR 'T_MATNR'.
    TYPE-POOLS
    type-pools: slis.    " Type pool for ALV
    TABLE USED
    tables: mara,    " General Material Data
            makt,    " Material Descriptions
            mard,    " Storage Location Data for Material
            marc,    " Plant Data for Material
            t001w.   " Plants/Branches
    INTERNAL TABLES
    data: begin of g_t_itab occurs 0,           " TO HOLD
            sel          type c,
            lgort        like mard-lgort,       " storage location
            werks        like marc-werks,       " plant
            labst        like mard-labst,       " stock
            matnr        like mara-matnr,       " material number
            land1        like t001w-land1,      " country i.e. branches
          end of g_t_itab.
    data: begin of g_t_detail occurs 0,         " TO HOLD
             matnr like mara-matnr,             " material number
          end of g_t_detail.
    data: begin of g_t_makt occurs 0,           " TO HOLD
             matnr like makt-matnr,             " material number
             maktx like makt-maktx,             " material description
             spras like makt-spras,             " language key
          end of g_t_makt.
    data: l_t_makt like makt occurs 0           " internal table with
          with header line.                     " same structure like MAKT
    Data Fields used for ALV call - Simple List
    data: g_f_repid     like  sy-repid,
          g_t_fieldcat  type  slis_t_fieldcat_alv,
          g_r_fieldcat  type  slis_fieldcat_alv,
          g_t_events    type  slis_t_event,
          g_r_events    type  slis_alv_event,
          g_r_layout    type  slis_layout_alv.
    data: g_r_x_variant   like  disvariant,
          g_r_variant     like  disvariant.
    data: g_f_exit(1),
          g_f_save(1).
    SELECTION SCREEN
    selection-screen begin of block b1 with frame title text-001.
    select-options:  s_matnr for mara-matnr,
                     s_werks for marc-werks.
    parameter: p_gerplt as checkbox user-command r1.
    selection-screen end of block b1.
    START OF SELECTION
    start-of-selection.
      perform get_data.
    AT SELECTION SCREEN
    at selection-screen on s_matnr.
      if not ( s_werks is initial ).
        perform validation.
      endif.
    at selection-screen output.
      loop at screen.
        if screen-group1 eq 'G' and p_gerplt = 'X'.
          screen-input = 0.
          refresh s_werks.
        endif.
        modify screen.
      endloop.
    INITIALIZATION
    initialization.
      perform initial_selection_screen.
    AT LINE SELECTION
    *AT LINE-SELECTION.
    PERFORM at_line_selection.
    END OF SELECTION
    end-of-selection.
      perform set_alv_parameters.
      perform display_list.
          FORM get_data                                                 *
    form get_data.
      if p_gerplt = 'X'.
        select blgort cwerks blabst amatnr d~land1
            from mara as a
            inner join mard as b
            on amatnr = bmatnr
            inner join marc as c
            on bmatnr = cmatnr
            inner join t001w as d
            on cwerks = dwerks
            into corresponding fields of table g_t_itab
            where
            a~matnr in s_matnr and
            d~land1 eq 'DE'.
      else.
        select blgort cwerks blabst amatnr
            from mara as a
            inner join mard as b
            on amatnr = bmatnr
            inner join marc as c
            on bmatnr = cmatnr
            into corresponding fields of table g_t_itab
            where
            a~matnr in s_matnr and
            c~werks in s_werks.
      endif.
    endform.
          FORM set_alv_parameters                                       *
    form set_alv_parameters.
      perform set_fieldcatlog.
    Events
      refresh : g_t_events.
      clear   : g_r_events.
    TOP OF PAGE event for standard header
      g_r_events-name = 'TOP_OF_PAGE'.
      g_r_events-form = 'TOP_OF_PAGE'.
      append g_r_events to g_t_events.
    Attributes for layout
    <b>  g_r_layout-zebra = 'X'.</b>
      g_r_layout-min_linesize = 119.
      g_r_layout-colwidth_optimize = 'X'.
    Field having checkbox
      g_r_layout-box_fieldname = 'SEL'.
    Field havind checkbox internal table name
      g_r_layout-box_tabname = 'G_T_ITAB'.
    endform.
          FORM display_list                                             *
    form display_list.
      g_f_repid = sy-repid.
      call function 'REUSE_ALV_LIST_DISPLAY'
          exporting
       I_INTERFACE_CHECK              = ' '
       I_BYPASSING_BUFFER             =
       I_BUFFER_ACTIVE                = ' '
                       i_callback_program             = g_f_repid
                        i_callback_pf_status_set       = 'PF_STATUS_SET'
                        i_callback_user_command        = 'USER_COMMAND'
       I_STRUCTURE_NAME               =
                        is_layout                      = g_r_layout
                        it_fieldcat                    = g_t_fieldcat[]
       IT_EXCLUDING                   =
       IT_SPECIAL_GROUPS              =
       IT_SORT                        =
       IT_FILTER                      =
       IS_SEL_HIDE                    =
       I_DEFAULT                      = 'X'
       I_SAVE                         = ' '
                        is_variant                     = g_r_variant
                        it_events                      = g_t_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
       IMPORTING
         E_EXIT_CAUSED_BY_CALLER        =
         ES_EXIT_CAUSED_BY_USER         =
                       tables
                         t_outtab                       = g_t_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.
    endform.
          FORM set_fieldcatlog                                          *
    form set_fieldcatlog.
      data: l_r_fieldcat type slis_fieldcat_alv.
      clear : g_t_fieldcat,
              g_t_fieldcat[].
    Check - box
      l_r_fieldcat-tabname        = 'G_T_ITAB'.
      l_r_fieldcat-fieldname      = 'SEL'.
      l_r_fieldcat-col_pos        = 1.
      l_r_fieldcat-checkbox       = 'X'.
      l_r_fieldcat-input          = 'X'.
      append l_r_fieldcat to g_t_fieldcat.
      clear l_r_fieldcat.
    Plant
      l_r_fieldcat-tabname        = 'G_T_ITAB'.
      l_r_fieldcat-fieldname      = 'WERKS'.
      l_r_fieldcat-ref_tabname    = 'MARC'.
      l_r_fieldcat-ref_fieldname  = 'WERKS'.
    l_r_fieldcat-no_out         = ' '.
    l_r_fieldcat-input          = ' '.
    l_r_fieldcat-key            = 'X'.
      l_r_fieldcat-col_pos        = 2.
      append l_r_fieldcat to g_t_fieldcat.
      clear l_r_fieldcat.
    Storage Location
      l_r_fieldcat-tabname        = 'G_T_ITAB'.
      l_r_fieldcat-fieldname      = 'LGORT'.
      l_r_fieldcat-ref_tabname    = 'MARD'.
      l_r_fieldcat-ref_fieldname  = 'LGORT'.
      l_r_fieldcat-col_pos        = 3.
      append l_r_fieldcat to g_t_fieldcat.
      clear l_r_fieldcat.
    Material Number
      l_r_fieldcat-tabname        = 'G_T_ITAB'.
      l_r_fieldcat-fieldname      = 'MATNR'.
      l_r_fieldcat-ref_tabname    = 'MARA'.
      l_r_fieldcat-ref_fieldname  = 'MATNR'.
      l_r_fieldcat-col_pos        = 4.
      append l_r_fieldcat to g_t_fieldcat.
      clear l_r_fieldcat.
    Stock (Un Restricted)
      l_r_fieldcat-tabname        = 'G_T_ITAB'.
      l_r_fieldcat-fieldname      = 'LABST'.
      l_r_fieldcat-ref_tabname    = 'MARD'.
      l_r_fieldcat-ref_fieldname  = 'LABST'.
      l_r_fieldcat-col_pos        = 5.
      append l_r_fieldcat to g_t_fieldcat.
      clear l_r_fieldcat.
    endform.
          FORM top_of_page                                              *
    form top_of_page.
      write: 'TOP OF PAGE'.
    endform.
          FORM user_command                                             *
    -->  I_F_UCOMM                                                     *
    -->  I_R_SELFIELD                                                  *
    form user_command using i_f_ucomm     like  sy-ucomm
                            i_r_selfield  type  slis_selfield.
      if i_f_ucomm = 'DESCR'.
        perform display_mat_desc.
      endif.
    endform.
          FORM pf_status_set                                            *
    -->  I_T_EXTAB                                                     *
    form pf_status_set using i_t_extab type slis_t_extab.
      set pf-status 'S_MATNR'.
    endform.
          FORM display_mat_desc                                         *
    form display_mat_desc.
      read table g_t_itab with key sel = 'X'.
      if sy-subrc ne 0.
        message e001(00) with text-002.
      endif.
      clear   : g_t_makt.
      refresh : g_t_makt.
      loop at g_t_itab where sel eq 'X'.
        select matnr maktx spras
        from makt
        appending table g_t_makt
        where
        matnr eq g_t_itab-matnr.
      endloop.
      loop at g_t_makt.
        write: / g_t_makt-matnr, g_t_makt-maktx, g_t_makt-spras.
      endloop.
    endform.
          FORM initial_selection_screen                                 *
    form initial_selection_screen.
      s_matnr-sign = 'I'.
      s_matnr-option = 'EQ'.
      s_matnr-low = '000000000000000012'.
      s_matnr-high = ' '.
      append s_matnr.
      clear s_matnr.
      s_matnr-sign = 'I'.
      s_matnr-option = 'NE'.
      s_matnr-low = '000000000000000002'.
      s_matnr-high = ' '.
      append s_matnr.
      clear s_matnr.
      s_matnr-sign = 'I'.
      s_matnr-option = 'EQ'.
      s_matnr-low = '000000000000000015'.
      s_matnr-high ='000000000010000012'.
      append s_matnr.
      clear s_matnr.
    endform.
          FORM validation                                               *
    form validation.
      select single * from marc
                    where matnr in s_matnr and
                          werks in s_werks.
      if sy-subrc ne 0.
        message e047(m3).
      endif.
    endform.
    Reward If Useful
    Sasi.
    Message was edited by:
            Sasidhar Reddy Matli

  • ALV Report program linking 5 db tables.

    What should be the general approach to generate a simple ALV program that links 5 database tables, where the selection criteria is date field?
    Edited by: Matt on Dec 4, 2008 11:38 AM - Removed all caps

    SAP Query is a bit of an abomination -- complicated to use correctly and definitely difficult to maintain.
    If you need to get stuff from 5 different databases in one report it might be better from a Systems Performance perspective to create a "Z_object" containing the data you want and then simply run your ABAP ALV against your "Z_Object".
    Depending on the frequency / content of your report you could run say a batch job every evening to update your "Z_Object".
    The other possibility would be to run your query on a BW/BI system if the volume of data is quite large -- however if you don't have BW then OK this is not a possible solution.
    My preference would be to go for the "Z-Object".
    I also have to wonder at how the original application was designed if you really do need to collect data from 5 different data bases --perhaps you should re-design the original application.
    Cheers
    jimbo.

Maybe you are looking for

  • Different channel derived in Accounting document and Copa document.

    Hi, We have a problem. The billing document has Distr. Channel 20 and Division 40, hence channel FM. The sales document has Distr. Channel 20 and Division 40, hence channel FM. The material has Distr. Channel 20 and Division 20, hence channel INDIREC

  • STK: max length for initDisplayText ?

    Hi, where can I find information on the max possible length of a text string in the source buffer, when using sim.toolkit.ProactiveHandler.initDisplayText command ? For example, the following command works well (buffer size is 512): proHdlr.initDispl

  • Re: Warranty Status Complaint

    hai please make correction about my warranty and contact me after success my contactr number is xxxxxxxxxx and my email is [email protected] Moderator Note; picture displaying s/n & private information removed, email & phone number edited to prevent

  • DBUM Trusted Resource reconciliation fails

    I'm trying to set up a trusted resource reconciliation job. I currently have it set up like this : http://i.imgur.com/uUh4X.jpg Also, I set up the configuration lookup definition (using OIM Design Console). In my case its: u01/oracle/product/fmw/1111

  • Error in Target cost version

    Hi Experts, Can any body solve following error. I was creating Target cost version ( T-code OKV6 ) but facing following error. Version 2222 1 not intended to be used as the target cost version Diagnosis The specified target cost version has not been