Skip to Content
author's profile photo Former Member
Former Member

column and row heading in alv report

Dear All,

how to display following format in ALV grid display.

-


description collection sales oil sales exide

-


TEXT 1 HEADING 123123234 12341234 12342134234

-


TEXT 2 HEADING 12342134234 2134234234 234234234

-


TEXT 3 HEADING 1234234 21342134234 2342134234

-


PLEASE HELP

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 04:27 PM

    hi check this..

    &----


    *& Report ZPR_02

    *&

    &----


    *&

    *&

    &----


    REPORT ZPR_02.

    TYPE-POOLS: SLIS.

    TABLES: MARA.

    DATA: BEGIN OF IT_MARA OCCURS 0,

    MATNR LIKE MARA-MATNR,

    MTART LIKE MARA-MTART,

    MATKL LIKE MARA-MATKL,

    END OF IT_MARA.

    DATA: IT_FIELD_CAT TYPE SLIS_T_FIELDCAT_ALV,

    WA_FIELD_CAT TYPE SLIS_FIELDCAT_ALV,

    IT_EVENTS TYPE SLIS_T_EVENT,

    WA_EVENTS TYPE SLIS_ALV_EVENT,

    IT_HEADER TYPE SLIS_T_LISTHEADER,

    WA_HEADER TYPE SLIS_LISTHEADER.

    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

    START-OF-SELECTION.

    PERFORM GET_DATA.

    PERFORM BUILD_FIELD_CAT.

    PERFORM GET_EVENTS.

    PERFORM DISPLAY_DATA.

    &----


    *& Form get_data

    &----


    • text

    ----


    FORM GET_DATA .

    SELECT MATNR

    MTART

    MATKL FROM MARA

    INTO TABLE IT_MARA

    WHERE MATNR IN S_MATNR.

    ENDFORM. " get_data

    &----


    *& Form build_field_cat

    &----


    • text

    ----


    FORM BUILD_FIELD_CAT .

    CLEAR WA_FIELD_CAT.

    WA_FIELD_CAT-COL_POS = 1.

    WA_FIELD_CAT-FIELDNAME = 'MATNR'.

    WA_FIELD_CAT-SELTEXT_L = 'Material Number'.

    APPEND WA_FIELD_CAT TO IT_FIELD_CAT.

    WA_FIELD_CAT-COL_POS = 2.

    WA_FIELD_CAT-FIELDNAME = 'MTART'.

    WA_FIELD_CAT-SELTEXT_L = 'Material Type'.

    APPEND WA_FIELD_CAT TO IT_FIELD_CAT.

    WA_FIELD_CAT-COL_POS = 3.

    WA_FIELD_CAT-FIELDNAME = 'MATKL'.

    WA_FIELD_CAT-SELTEXT_L = 'Material Group'.

    APPEND WA_FIELD_CAT TO IT_FIELD_CAT.

    ENDFORM. " build_field_cat

    &----


    *& Form display_data

    &----


    • text

    ----


    FORM DISPLAY_DATA .

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = SY-REPID

    IT_FIELDCAT = IT_FIELD_CAT

    IT_EVENTS = IT_EVENTS

    TABLES

    T_OUTTAB = IT_MARA.

    ENDFORM. " display_data

    &----


    *& Form get_events

    &----


    • text

    ----


    FORM GET_EVENTS .

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    • EXPORTING

    • I_LIST_TYPE = 0

    IMPORTING

    ET_EVENTS = IT_EVENTS .

    READ TABLE IT_EVENTS INTO WA_EVENTS

    WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.

    IF SY-SUBRC = 0.

    WA_EVENTS-FORM = 'TOP_OF_PAGE'.

    MODIFY IT_EVENTS FROM WA_EVENTS INDEX SY-TABIX.

    ENDIF.

    ENDFORM. " get_events

    &----


    *& Form top_of_page

    &----


    • text

    ----


    FORM TOP_OF_PAGE.

    WA_HEADER-TYP = 'H'.

    WA_HEADER-INFO = 'THIS IS TESTING FOR HEADER'.

    APPEND WA_HEADER TO IT_HEADER.

    WA_HEADER-TYP = 'H'.

    WA_HEADER-INFO = 'Material Data'.

    APPEND WA_HEADER TO IT_HEADER.

    WA_HEADER-TYP = 'S'..

    WA_HEADER-INFO = 'IT IS WORKIG FINE'.

    APPEND WA_HEADER TO IT_HEADER.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = IT_HEADER

    • I_LOGO = I_LOGO

    • I_END_OF_LIST_GRID = I_END_OF_LIST_GRID

    • I_ALV_FORM = I_ALV_FORM

    .

    ENDFORM. "top_of_page

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 04:31 PM

    you can use the FM,

    REUSE_ALV_GRID_DISPLAY

    you have to a bit careful when building teh field catlog.

    Shreekant

    look the code below for exampls.

    *&---------------------------------------------------------------------*
    *& Report  zalv                                                      *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    
    REPORT zalv .
    
    TYPE-POOLS: kkblo,
                slis.
    
    TABLES: mara, marc, mard.
    
    DATA:       disvariant   LIKE disvariant,
                eventcat     TYPE slis_t_event,
                eventcat_ln  LIKE LINE OF eventcat,
                fieldcat     TYPE slis_t_fieldcat_alv,
                fieldcat_kkb TYPE kkblo_t_fieldcat,
                fieldcat_ln  LIKE LINE OF fieldcat,
                keyinfo      TYPE slis_keyinfo_alv,
                layout       TYPE slis_layout_alv,
                layout_kkb   TYPE kkblo_layout,
                pgm          LIKE sy-repid,
                printcat     TYPE slis_print_alv,
                sortcat      TYPE slis_t_sortinfo_alv,
                sortcat_ln   LIKE LINE OF sortcat,
    
                BEGIN OF coltab OCCURS 50,
                  fieldname LIKE fieldcat_ln-fieldname,
                END OF coltab.
    
    DATA: print          TYPE slis_print_alv.
    
    DATA : v_repid TYPE sy-repid.
    
    DATA: BEGIN OF wa OCCURS 0,
            matnr TYPE mara-matnr,
            ersda TYPE mara-ersda,
            ernam TYPE mara-ernam,
            aenam TYPE mara-aenam,
            werks TYPE marc-werks,
            pstat TYPE marc-pstat,
            lfmon TYPE mard-lfmon,
          END OF wa.
    
    DATA: itab LIKE TABLE OF wa.
    
    **Selection Screen
    
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001..
    SELECT-OPTIONS: mat_no FOR mara-matnr.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK b1.
    * Parameter for list viewer display variant
    
    PARAMETERS:    variant  LIKE disvariant-variant.
    
    AT SELECTION-SCREEN ON variant.
      CHECK NOT variant IS INITIAL.
      PERFORM check_variant_existence USING variant 'U'.
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR variant.
      PERFORM f4_display_variant USING variant 'U'.
    
    *Initialization
    INITIALIZATION.
      v_repid = sy-repid.
    
    *Start of selection
      PERFORM check_tcode_authority USING 'SA38'.
    
    START-OF-SELECTION.
      SELECT a~matnr a~ersda
             a~ernam a~aenam
             c~werks c~pstat d~lfmon
      INTO TABLE itab
      UP TO 10 ROWS
      FROM mara AS a
      INNER JOIN marc AS c ON a~matnr = c~matnr
      INNER JOIN mard AS d ON c~matnr = d~matnr
      WHERE a~matnr IN mat_no.
    
    *End of Selection
    END-OF-SELECTION.
      PERFORM call_list_viewer.
    
    *&---------------------------------------------------------------------*
    *&      Form  call_list_viewer
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM call_list_viewer .
      PERFORM build_fieldcat USING:
               'MATNR' 'ITAB'
                'Material #' 'CHAR'     18 ' ' ' ' ' ' ' ' ' ',
               'ERSDA' 'ITAB'
                'Date Created' 'CHAR'   10 ' ' ' ' ' ' ' ' ' ',
               'ERNAM' 'ITAB'
                'Created By' 'CHAR'     10 ' ' ' ' ' ' ' ' ' ',
               'AENAM' 'ITAB'
                'Changed By' 'CHAR'     10 ' ' ' ' ' ' ' ' ' ',
               'WERKS' 'ITAB'
                'Plant' 'CHAR'           4 ' ' ' ' ' ' ' ' ' ',
               'PSTAT' 'ITAB'
                'Status' 'CHAR'         10 ' ' ' ' ' ' ' ' ' ',
               'LFMON' 'ITAB'
                'Current Period' 'CHAR'  8 ' ' ' ' ' ' ' ' ' '.
    
      PERFORM build_eventcat USING: 'TOP_OF_LIST',
                                    'TOP_OF_PAGE'.
      PERFORM list_display TABLES itab.
    
    ENDFORM.                    "call_list_viewer
    
    *----------------------------------------------------------------------*
    * build field catalog entry                                            *
    *----------------------------------------------------------------------*
    FORM build_fieldcat USING a_fieldname
                              a_tabname
                              a_heading
                              a_datatype
                              a_outputlen
                              a_key
                              a_no_out
                              a_no_sum
                              a_do_sum
                              a_no_zero.
    
    
      CLEAR fieldcat_ln.
      fieldcat_ln-fieldname = a_fieldname.
      fieldcat_ln-tabname  = a_tabname.
      fieldcat_ln-outputlen = a_outputlen.
      fieldcat_ln-datatype = a_datatype.
      fieldcat_ln-reptext_ddic = a_heading.
      fieldcat_ln-key = a_key.
      fieldcat_ln-no_out = a_no_out.
      fieldcat_ln-no_sum = a_no_sum.
      fieldcat_ln-do_sum = a_do_sum.
      fieldcat_ln-no_zero = a_no_zero.
      APPEND fieldcat_ln TO fieldcat.
    
    ENDFORM.                    "BUILD_FIELDCAT
    *----------------------------------------------------------------------*
    *       FORM BUILD_EVENTCAT
    *----------------------------------------------------------------------*
    FORM build_eventcat USING a_event.
    
      eventcat_ln-name = eventcat_ln-form = a_event.
      APPEND eventcat_ln TO eventcat.
    
    ENDFORM.                    "BUILD_EVENTCAT
    *----------------------------------------------------------------------*
    * call the ABAP list viewer                                            *
    *----------------------------------------------------------------------*
    FORM list_display TABLES a_output.
    
      pgm = disvariant-report = sy-repid.
      disvariant-variant = variant.
    * call list viewer
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = pgm
    *      i_callback_pf_status_set = 'SET_PF_STATUS'
          it_fieldcat              = fieldcat
          is_variant               = disvariant
          is_layout                = layout
          is_print                 = print
          i_save                   = 'A'
          it_events                = eventcat
          it_sort                  = sortcat
    *      i_callback_user_command  = 'USER_COMMAND'
        TABLES
          t_outtab                 = a_output
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
    
    ENDFORM.                    "LIST_DISPLAY
    
    
    *&---------------------------------------------------------------------*
    *&      Form  top_of_page
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM top_of_page.
      PERFORM standard_headings.
    
      PERFORM print_selection_screen TABLES:
                   mat_no USING  'Material No  : ' 18 'N' 1.
    ENDFORM.                    "top_of_page
    
    
    
    
    *----------------------------------------------------------------------*
    *       FORM CHECK_VARIANT_EXISTENCE
    *----------------------------------------------------------------------*
    *       Verify that a variant on the selection screen exists
    *----------------------------------------------------------------------*
    FORM check_variant_existence USING varname LIKE disvariant-variant
                                       save   TYPE c.
    
      DATA: xdisvar LIKE disvariant.
    
      xdisvar-report  = sy-repid.
      xdisvar-variant = varname.
    
      CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
        EXPORTING
          i_save        = save
        CHANGING
          cs_variant    = xdisvar
        EXCEPTIONS
          wrong_input   = 1
          not_found     = 2
          program_error = 3
          OTHERS        = 4.
    
      IF sy-subrc <> 0.
        MESSAGE e256(56) WITH varname.
    *   Anzeigevariante &1 nicht gefunden
      ENDIF.
    
      disvariant-report  = sy-repid.
      disvariant-variant = varname.
    
    ENDFORM.                    "check_variant_existence
    *----------------------------------------------------------------------*
    *       Form  F4_DISPLAY_VARIANT
    *----------------------------------------------------------------------*
    *       F4 help to find a display variant
    *       varname = name of the dynpro field for which f4 is requested
    *       save    = type of list variant saving
    *                 ' ' = no saving allowed
    *                 'A' = standard & user specific variants can be saved
    *                 'U' = only user specific variants can be saved
    *                 'X' = only standard variants can be saved
    *----------------------------------------------------------------------*
    FORM f4_display_variant USING varname LIKE disvariant-variant
                                  save    TYPE c.
    
      disvariant-report = sy-repid.
    
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant    = disvariant
          i_save        = save
        IMPORTING
          es_variant    = disvariant
        EXCEPTIONS
          not_found     = 1
          program_error = 2
          OTHERS        = 3.
    
      IF sy-subrc = 0.
        varname = disvariant-variant.
      ELSE.
        MESSAGE s245(56).
    *   Keine Anzeigevariante(n) vorhanden
      ENDIF.
    ENDFORM.                               " F4_DISPLAY_VARIANT
    
    
    
    *---------------------------------------------------------------------*
    *       FORM STANDARD_HEADINGS                                        *
    *---------------------------------------------------------------------*
    *       Print standard page headings for report                       *
    *---------------------------------------------------------------------*
    FORM standard_headings.
      DATA: start_column TYPE i,
            title_len TYPE i,
            header_for_80_col(45),
            date_time_for_80_col(45),
            text_h0(11) VALUE 'Report No. ',
            text_h1(5) VALUE 'Date ',
            text_h2(6) VALUE 'Page -',
            text_h3(7) VALUE 'System ',
            text_h4(5) VALUE 'Time ',
            text_h5(11) VALUE 'Run By     '.
      FORMAT INTENSIFIED ON.
    
      CONDENSE syst-title.
    
      IF syst-linsz > 80.
        WRITE: /  text_h0,                 "Report No.
               12 syst-repid(8),
               23 text_h1,                 "Date
                  sy-datlo.
        title_len = STRLEN( syst-title ) / 2.
        start_column = ( syst-linsz / 2 ) - title_len.
        IF start_column < 40.
          start_column = 40.
        ENDIF.
        WRITE: AT start_column syst-title.
      ELSE.
        WRITE: /  text_h0,                 "Report No.
               12 syst-repid(8).
        start_column = 22.
        WRITE syst-title TO header_for_80_col CENTERED.
        WRITE: header_for_80_col.
      ENDIF.
    
      start_column = syst-linsz - 12.
      WRITE: AT start_column text_h2, syst-pagno LEFT-JUSTIFIED.
    
      IF syst-linsz > 80.
        WRITE: / text_h3,                  "System
              12 syst-sysid(4),
                 syst-mandt,
              23 text_h4,                  "Time
                 syst-timlo.
        WRITE: / text_h5,                  "Run By
              12 syst-uname.
      ELSE.
        WRITE: / text_h3,                  "System
              12 syst-sysid(4),
                 syst-mandt,
              23 text_h1,                  "Date
                 syst-datlo.
        WRITE: / text_h5,                  "Run By
              12 syst-uname,
              23 text_h4,                  "Time
                 syst-timlo.
    
      ENDIF.
    
      SKIP.
    ENDFORM.                    "STANDARD_HEADINGS
    
    *---------------------------------------------------------------------*
    *       FORM PRINT_SELECTION_SCREEN                                        *
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    *  -->  SIGN                                                          *
    *  -->  OPTION                                                        *
    *  -->  LOW                                                           *
    *  -->  HIGH                                                          *
    *  -->  D_IND                                                         *
    *  -->  S_STRING                                                      *
    *---------------------------------------------------------------------*
    FORM print_selection_screen TABLES r_selection TYPE table
                           USING  p_name
                                  p_length TYPE i
                                  p_ind
                                  p_start_col.
    
      DATA: year(4)       TYPE c,
            month(2)      TYPE c,
            day(2)        TYPE c,
            low_date(10)  TYPE c,
            high_date(10) TYPE c,
            offset(80)    TYPE c.
    
      DATA: BEGIN OF l_selline,
              sign(1) TYPE c,
              option(2) TYPE c,
              data(200) TYPE c,
            END OF l_selline.
    
      DATA: l_string(80) TYPE c,
            l_temp(80) TYPE c,
            len TYPE i,
            len1 TYPE i.
    
      DESCRIBE FIELD p_name LENGTH len IN CHARACTER MODE.
      len = len + p_start_col + 2.
    
      LOOP AT r_selection.
        IF syst-tabix = 1.
          WRITE AT /p_start_col p_name.
        ELSE.
          len1 = ( STRLEN( l_string ) ).
          len = len1 + len + 2.
        ENDIF.
    
        MOVE r_selection TO l_selline.
        SHIFT l_selline-data LEFT DELETING LEADING '0'.
    
        CLEAR l_string.
        CASE l_selline-option.
          WHEN 'EQ'.
            CONCATENATE l_string '=' INTO l_string.
          WHEN 'NE'.
            CONCATENATE l_string 'not =' INTO l_string.
          WHEN 'LT'.
            CONCATENATE l_string '<' INTO l_string.
          WHEN 'GT'.
            CONCATENATE l_string '>' INTO l_string.
          WHEN 'LE'.
            CONCATENATE l_string '<=' INTO l_string.
          WHEN 'GE'.
            CONCATENATE l_string '>=' INTO l_string.
          WHEN 'BT'.
            CONCATENATE l_string 'between' INTO l_string.
          WHEN 'NB'.
            CONCATENATE l_string 'not between' INTO l_string.
          WHEN 'CP'.
            CONCATENATE l_string 'contains pattern' INTO l_string.
          WHEN 'NP'.
            CONCATENATE l_string 'no pattern' INTO l_string.
        ENDCASE.
        IF l_selline-sign EQ 'E'.
          CONCATENATE 'NOT' l_string INTO l_string SEPARATED BY ' '.
        ENDIF.
        IF p_ind EQ 'Y'.
          MOVE l_selline-data(4) TO year.
          MOVE l_selline-data+4(2) TO month.
          MOVE l_selline-data+6(2) TO day.
    
          CONCATENATE month '/' day '/' year INTO low_date.
    
          CONCATENATE l_string low_date INTO l_string SEPARATED BY ' '.
          IF l_selline-option EQ 'BT' OR l_selline-option EQ 'NB'.
            MOVE l_selline-data+p_length(4) TO year.
            offset = p_length + 4.
            MOVE l_selline-data+offset(2) TO month.
            ADD 2 TO offset.
            MOVE l_selline-data+offset(2) TO day.
    
            CONCATENATE month '/' day '/' year INTO high_date.
    
            CONCATENATE l_string 'and' high_date INTO l_string SEPARATED
                                                  BY ' '.
          ENDIF.
        ELSE.
          MOVE l_selline-data(p_length) TO l_temp.
          CONCATENATE l_string l_temp INTO l_string SEPARATED BY ' '.
          IF l_selline-option EQ 'BT' OR l_selline-option EQ 'NB'.
            MOVE l_selline-data+p_length(p_length) TO l_temp.
            CONCATENATE l_string 'and' l_temp INTO l_string SEPARATED
                                                                BY ' '.
          ENDIF.
        ENDIF.
        WRITE AT len l_string.
      ENDLOOP.
      IF syst-subrc <> 0.
        WRITE: AT /p_start_col p_name, ' *** ALL ***'.
      ENDIF.
    ENDFORM.                    "PRINT_SELECTION_SCREEN
    
    *---------------------------------------------------------------------*
    *       FORM CHECK_TCODE_AUTHORITY                                    *
    *---------------------------------------------------------------------*
    *       Check User Security Against A SAP Transaction                 *
    *---------------------------------------------------------------------*
    *  -->  a_tcode  Transaction Code For Security                        *
    *---------------------------------------------------------------------*
    FORM check_tcode_authority USING a_tcode.
    *
    * if tcode is not passed, then return ok.
    *
    
      IF NOT a_tcode IS INITIAL.
        CALL FUNCTION 'AUTHORITY_CHECK_TCODE'"Only People that
             EXPORTING                     " have access to
               tcode  = a_tcode            " Transaction t-tcode
             EXCEPTIONS                    " are ALLOWED to execute
                  ok     = 1               " this Program
                  not_ok = 2.
        IF syst-subrc NE 1.
          MESSAGE a999(zz) WITH 'YOU Do Not Have Authority to Execute'.
        ENDIF.
      ELSE.
        MOVE 1 TO syst-subrc.
      ENDIF.
    ENDFORM.                    "CHECK_TCODE_AUTHORITY
    

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.