Alv field heading in two rows

hi all
In alv report out put  the field heading  is too long.
So I want to disply the heading in two rows.
Like ‘ April 2006 prior month personal’,
Is to be disply like in one row ‘April 2006’.
And in next row ‘prior month personal’.
Please send the reply as early as possible to [email protected]

i think it is not possible like that , u can increase the length of that field in fieldcatalog
wa_fieldname-outputlen = '100'.
and in layout u can use
wa_layout-colwidth_optimize = 'X'.

Similar Messages

  • How to display the column header in two rows?

    Hi Experts,
    I am using ALV_LIST_DISPLAY i neeed to display the column header in two rows.. How can i do that?
    Ex: purchase order i  need to display "purchase" in one row and "order" in second row.
    Thanks in advance,
    Sarath.j

    REPORT zpwtest .
    TYPE-POOLS slis .
    DATA : layout TYPE slis_layout_alv .
    CONSTANTS : c_len TYPE i VALUE 20 .
    TYPES : BEGIN OF ty_t100          ,
              sprsl TYPE t100-sprsl   ,
              arbgb TYPE t100-arbgb   ,
              msgnr TYPE t100-msgnr   ,
              text  TYPE t100-text    ,
              fline TYPE t100-text    ,
            END OF ty_t100            .
    TYPES : BEGIN OF ty_wrd   ,
             text TYPE char20 ,
            END OF ty_wrd     .
    DATA : it_t100     TYPE TABLE OF ty_t100 ,
           it_sentence TYPE TABLE OF ty_wrd  ,
           wa_t100     TYPE ty_t100          ,
           wa_word     TYPE ty_wrd           ,
           v_repid     TYPE syst-repid       ,
           v_tabix     TYPE syst-tabix       .
    DATA : it_fld TYPE slis_t_fieldcat_alv ,
           it_evt TYPE slis_t_event        ,
           wa_fld TYPE slis_fieldcat_alv   ,
           wa_evt TYPE slis_alv_event      .
    INITIALIZATION .
      v_repid = sy-repid .
    START-OF-SELECTION .
    * Get data
      SELECT *
        INTO TABLE it_t100
        FROM t100
       WHERE sprsl = 'EN'
         AND arbgb = '00' .
      LOOP AT it_t100 INTO wa_t100 .
        v_tabix = sy-tabix .
        CLEAR : it_sentence .
        CALL FUNCTION 'RKD_WORD_WRAP'
             EXPORTING
                  textline  = wa_t100-text
                  outputlen = c_len
             TABLES
                  out_lines = it_sentence.
        IF NOT it_sentence IS INITIAL .
          READ TABLE it_sentence INTO wa_word INDEX 1 .
          wa_t100-fline = wa_word-text .
          MODIFY it_t100 FROM wa_t100 INDEX v_tabix .
        ENDIF.
      ENDLOOP.
    * Prepare fieldcatelog
      CLEAR wa_fld .
      wa_fld-fieldname = 'SPRSL' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'SPRSL' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'ARBGB' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'ARBGB' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'MSGNR' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'MSGNR' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'FLINE' .
      wa_fld-inttype      = 'CHAR' .
      wa_fld-outputlen = 20 .
      wa_fld-intlen    = 20.
      wa_fld-seltext_l = 'Text' .
      wa_fld-ddictxt = 'L' .
      APPEND wa_fld TO it_fld .
    * Get event.. we will handle BOFORE and AFTER line output
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           IMPORTING
                et_events = it_evt.
      READ TABLE it_evt INTO wa_evt
      WITH KEY name = slis_ev_after_line_output .
      wa_evt-form = slis_ev_after_line_output .
      MODIFY it_evt FROM wa_evt INDEX sy-tabix .
      READ TABLE it_evt INTO wa_evt
      WITH KEY name = slis_ev_top_of_page .
      wa_evt-form = slis_ev_top_of_page .
      MODIFY it_evt FROM wa_evt INDEX sy-tabix .
      layout-no_colhead = 'X' .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                i_callback_program = v_repid
                it_fieldcat        = it_fld
                is_layout          = layout
                it_events          = it_evt
           TABLES
                t_outtab           = it_t100.
    *       FORM top_of_page                                              *
    FORM top_of_page .
        uline .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line1'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line2'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line3'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
    ENDFORM.
    *       FORM AFTER_LINE_OUTPUT                                        *
    FORM after_line_output   USING rs_lineinfo TYPE slis_lineinfo .
      CLEAR : it_sentence ,
              wa_t100     .
      READ TABLE it_t100 INTO wa_t100 INDEX rs_lineinfo-tabindex .
      CHECK sy-subrc = 0 .
      CALL FUNCTION 'RKD_WORD_WRAP'
           EXPORTING
                textline  = wa_t100-text
                outputlen = c_len
           TABLES
                out_lines = it_sentence.
      DESCRIBE TABLE it_sentence LINES v_tabix .
      CHECK v_tabix > 1 .
      LOOP AT it_sentence INTO wa_word FROM 2 .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               31 sy-vline    ,
               37 sy-vline    ,
               38 wa_word-text ,
               58 sy-vline .
      ENDLOOP.
    ENDFORM .

  • Alv output splitting into two rows when converting into excel sheet.

    Hi frends,
    I have alv report with 60 fields . The report output is coming currently .  But when i am exporting into excel sheet from the option local file--> speadsheet  each row is splitting into two rows including header in excel sheet.
    Please provide your valuable suggestions to avoid this.
    Regards,
    Ramu .
    Edited by: Ramu.K on Sep 8, 2009 5:59 PM

    Hi,
    Please use the grid option and with the Spreadsheet button (CntrShiftF7). Do  "Save as" and save it as excel. It should work.
    Regards,
    Pradyumna

  • To display variable date in the ALV field header

    HI all,
    I have an ALV list and one of the field headers is "Total received till 14.03.2008".
    Now the date field here is variable. it is being fetched from an internal table and displayed in thee field header of an ALV list.
    cud y'all pls tell me how to display this variable date.
    thanx,
    pk

    Hi,
    Just have a look on the following code,i hope this is enough to
    meet your requirement.
    type-pools: slis.
    data: x_fieldcat type slis_fieldcat_alv,
          it_fieldcat type slis_t_fieldcat_alv,
          l_layout type slis_layout_alv,
          x_events type slis_alv_event,
          it_events type slis_t_event.
    data: begin of itab occurs 0,
          vbeln like vbak-vbeln,
          posnr like vbap-posnr,
          male type i,
          female type i,
         end of itab.
    select vbeln
           posnr
           from vbap
           up to 20 rows
           into table itab.
    x_fieldcat-fieldname = 'VBELN'.
    x_fieldcat-seltext_l = 'VBELN'.
    x_fieldcat-tabname = 'ITAB'.
    x_fieldcat-col_pos = 1.
    append x_fieldcat to it_fieldcat.
    clear x_fieldcat.
    x_fieldcat-fieldname = 'POSNR'.
    x_fieldcat-seltext_l = 'POSNR'.
    x_fieldcat-tabname = 'ITAB'.
    x_fieldcat-col_pos = 2.
    append x_fieldcat to it_fieldcat.
    clear x_fieldcat.
    x_fieldcat-fieldname = 'MALE'.
    x_fieldcat-seltext_l = 'MALE'.
    x_fieldcat-tabname = 'ITAB'.
    x_fieldcat-col_pos = 3.
    append x_fieldcat to it_fieldcat.
    clear x_fieldcat.
    x_fieldcat-fieldname = 'FEMALE'.
    x_fieldcat-seltext_l = 'FEMALE'.
    x_fieldcat-tabname = 'ITAB'.
    x_fieldcat-col_pos = 3.
    append x_fieldcat to it_fieldcat.
    clear x_fieldcat.
      x_events-name = slis_ev_top_of_page.
      x_events-form = 'TOP_OF_PAGE'.
      append x_events  to it_events.
      clear x_events .
      l_layout-no_colhead = 'X'.
    call function 'REUSE_ALV_LIST_DISPLAY'
      exporting
        i_callback_program       = sy-repid
        is_layout                = l_layout
        it_fieldcat              = it_fieldcat
        it_events                = it_events
      tables
        t_outtab                 = 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.
    form top_of_page.
    *-To display the headers for main list
        format color col_heading.
            write: / sy-uline(103).
        write: /   sy-vline,
              (8) ' ' ,
                   sy-vline,
              (8)  ' ' ,
                   sy-vline,
              (27) '***'(015) centered,
                   sy-vline.
        write: /   sy-vline,
              (8) 'VBELN'(013) ,
                   sy-vline,
              (8) 'POSNR'(014) ,
                   sy-vline,
              (8) 'MALE'(016) ,
                   sy-vline,
               (5)  'FMALE'(017) ,
               (10) sy-datum,
                   sy-vline.
        format color off.
    endform.
    Reward points,if it is useful.
    Thanks,
    Chandu.

  • JTable header : text = two-rows, onClick action = sorting

    Hi guys.
    I want to create a JTable where the user can have the data sorted by clicking upon a column's header. The code below shows the table I describe (you can click upon a column and sorting is performed).
    import javax.swing.JFrame;
    import java.awt.HeadlessException;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.util.Vector;
    import javax.swing.table.DefaultTableModel;
    //--------- TableSorter ----------
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    //---------- Table Height - Column Width
    import javax.swing.table.TableColumn;
    import java.awt.FontMetrics;
    import javax.swing.JTable;
    import java.awt.Dimension;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2006</p>
    * <p>Company: </p>
    * @author not attributable
    * @version 1.0
    public class Test extends JFrame {
      JPanel jPanel1 = new JPanel();
      JPanel jPanel2 = new JPanel();
      JButton jButton1 = new JButton();
      FlowLayout flowLayout1 = new FlowLayout();
      BorderLayout borderLayout1 = new BorderLayout();
      BorderLayout borderLayout2 = new BorderLayout();
      //------------- MY VARIABLES -------------
      String[] columnNames_objectArr = new String[] {
          "Col1",
          "Column 2",
          "Column 3",
          "C4",
          "Col5",
          "Col 6",
      Vector columnNames_vector = new Vector();
      private Vector data_vector = new Vector();
      private Object[][] data_objectArr;
      public TableHeight_ColumnWidth tcw;
      private int totalTableWidth = 0, totalTableHeight = 0;
      private JComboBox jcmbxData = new JComboBox(
          new String[] {"Not Configured", "Switch", "Modem"});
      private int maxVisibleRows = 51;
      TableSorter model;
      private JTable table;
      JScrollPane jScrollPane1;
      public Test(String[] args) throws HeadlessException {
        try {
          jbInit();
          setupGUI();
          launchGUI();
        catch(Exception e) {
          e.printStackTrace();
      private void jbtnClose_actionPerformed(ActionEvent e) {
        dispose();
      private void launchGUI() {
        pack();
        setVisible(true);
        setResizable(false);
      private void setupGUI() {
        columnNames_vector.addElement("Col1");
        columnNames_vector.addElement("Column 2");
        columnNames_vector.addElement("Column 3");
        columnNames_vector.addElement("C4");
        columnNames_vector.addElement("Col5");
        columnNames_vector.addElement("Col 6");
        Vector row_data1 = new Vector();
        Vector row_data2 = new Vector();
        Vector row_data3 = new Vector();
        Vector row_data4 = new Vector();
        Vector row_data5 = new Vector();
        Vector row_data6 = new Vector();
        row_data1.add("Mary");
        row_data1.add("Campioneato");
        row_data1.add("Snowboarding");
        row_data1.add(new Integer(578987899));
        row_data1.add(new Boolean(false));
        row_data1.add("Not Configured");
        row_data2.add("Alison");
        row_data2.add("Huml");
        row_data2.add("Rowing");
        row_data2.add(new Integer(3));
        row_data2.add(new Boolean(true));
        row_data2.add("Switch");
        row_data3.add("Ka");
        row_data3.add("Walrath");
        row_data3.add("Knitting");
        row_data3.add(new Integer(2));
        row_data3.add(new Boolean(false));
        row_data3.add("Modem");
        row_data4.add("Sharon");
        row_data4.add("Zakhouras");
        row_data4.add("Speed reading");
        row_data4.add(new Integer(20));
        row_data4.add(new Boolean(true));
        row_data4.add("Switch");
        row_data5.add("Philip");
        row_data5.add("Milner");
        row_data5.add("Pool");
        row_data5.add(new Integer(10));
        row_data5.add(new Boolean(false));
        row_data5.add("Not Configured");
        data_vector.add(row_data1);
        data_vector.add(row_data2);
        data_vector.add(row_data3);
        data_vector.add(row_data4);
        data_vector.add(row_data5);
        model = new TableSorter(new SortTableModel(data_vector, columnNames_vector));
        table = new JTable(model);
        tcw = new TableHeight_ColumnWidth(model, table);
        jScrollPane1 = new JScrollPane(table);
        model.setTableHeader(table.getTableHeader());
        jPanel1.add(jScrollPane1, BorderLayout.CENTER);
        //Add a JComboBox as a cellEditor...
        DefaultCellEditor dce = new DefaultCellEditor(jcmbxData);
        table.getColumnModel().getColumn(5).setCellEditor(dce);
        //..... add the IPJPanel as cellEditor.....
        tcw.fixTableLook(maxVisibleRows);
      private void jbInit() throws Exception {
        this.getContentPane().setLayout(borderLayout2);
        jPanel1.setLayout(borderLayout1);
        jPanel2.setLayout(flowLayout1);
        jButton1.setText("Close");
        jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
        jPanel2.add(jButton1, null);
        jButton1.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jbtnClose_actionPerformed(e);
      public static void main( String[] args ) {
        new Test(args);
      public boolean getScrollableTracksViewportHeight() {
        Component parent = getParent();
        if (parent instanceof JViewport) {
          return parent.getHeight() > getPreferredSize().height;
        return false;
      //------------------ MY TABLE MODEL ------------------
      public class SortTableModel extends DefaultTableModel {
        private boolean DEBUG = false;
        public SortTableModel(Object[][] data, String[] columnNames) {
          super(data, columnNames);
        public SortTableModel(Vector data, Vector columnNames) {
          super(data, columnNames);
      //------------------ TABLE SORTER -----------------------
      public class TableSorter extends AbstractTableModel {
          protected TableModel tableModel;
          public static final int DESCENDING = -1;
          public static final int NOT_SORTED = 0;
          public static final int ASCENDING = 1;
          private Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
          public final Comparator COMPARABLE_COMAPRATOR = new Comparator() {
              public int compare(Object o1, Object o2) {
                  return ((Comparable) o1).compareTo(o2);
          public final Comparator LEXICAL_COMPARATOR = new Comparator() {
              public int compare(Object o1, Object o2) {
                  return o1.toString().compareTo(o2.toString());
          private Row[] viewToModel;
          private int[] modelToView;
          private JTableHeader tableHeader;
          private MouseListener mouseListener;
          private TableModelListener tableModelListener;
          private Map columnComparators = new HashMap();
          private List sortingColumns = new ArrayList();
          public TableSorter() {
              this.mouseListener = new MouseHandler();
              this.tableModelListener = new TableModelHandler();
          public TableSorter(TableModel tableModel) {
              this();
              setTableModel(tableModel);
          public TableSorter(TableModel tableModel, JTableHeader tableHeader) {
              this();
              setTableHeader(tableHeader);
              setTableModel(tableModel);
          private void clearSortingState() {
              viewToModel = null;
              modelToView = null;
          public TableModel getTableModel() {
              return tableModel;
          public void setTableModel(TableModel tableModel) {
              if (this.tableModel != null) {
                  this.tableModel.removeTableModelListener(tableModelListener);
              this.tableModel = tableModel;
              if (this.tableModel != null) {
                  this.tableModel.addTableModelListener(tableModelListener);
              clearSortingState();
              fireTableStructureChanged();
          public JTableHeader getTableHeader() {
              return tableHeader;
          public void setTableHeader(JTableHeader tableHeader) {
              if (this.tableHeader != null) {
                  this.tableHeader.removeMouseListener(mouseListener);
                  TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
                  if (defaultRenderer instanceof SortableHeaderRenderer) {
                      this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
              this.tableHeader = tableHeader;
              if (this.tableHeader != null) {
                  this.tableHeader.addMouseListener(mouseListener);
                  this.tableHeader.setDefaultRenderer(
                          new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
          public boolean isSorting() {
              return sortingColumns.size() != 0;
          private Directive getDirective(int column) {
              for (int i = 0; i < sortingColumns.size(); i++) {
                  Directive directive = (Directive)sortingColumns.get(i);
                  if (directive.column == column) {
                      return directive;
              return EMPTY_DIRECTIVE;
          public int getSortingStatus(int column) {
              return getDirective(column).direction;
          private void sortingStatusChanged() {
              clearSortingState();
              fireTableDataChanged();
              if (tableHeader != null) {
                  tableHeader.repaint();
          public void setSortingStatus(int column, int status) {
              Directive directive = getDirective(column);
              if (directive != EMPTY_DIRECTIVE) {
                  sortingColumns.remove(directive);
              if (status != NOT_SORTED) {
                  sortingColumns.add(new Directive(column, status));
              sortingStatusChanged();
          protected Icon getHeaderRendererIcon(int column, int size) {
              Directive directive = getDirective(column);
              if (directive == EMPTY_DIRECTIVE) {
                  return null;
              return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
          private void cancelSorting() {
              sortingColumns.clear();
              sortingStatusChanged();
          public void setColumnComparator(Class type, Comparator comparator) {
              if (comparator == null) {
                  columnComparators.remove(type);
              } else {
                  columnComparators.put(type, comparator);
          protected Comparator getComparator(int column) {
              Class columnType = tableModel.getColumnClass(column);
              Comparator comparator = (Comparator) columnComparators.get(columnType);
              if (comparator != null) {
                  return comparator;
              if (Comparable.class.isAssignableFrom(columnType)) {
                  return COMPARABLE_COMAPRATOR;
              return LEXICAL_COMPARATOR;
          private Row[] getViewToModel() {
              if (viewToModel == null) {
                  int tableModelRowCount = tableModel.getRowCount();
                  viewToModel = new Row[tableModelRowCount];
                  for (int row = 0; row < tableModelRowCount; row++) {
                      viewToModel[row] = new Row(row);
                  if (isSorting()) {
                      Arrays.sort(viewToModel);
              return viewToModel;
          public int modelIndex(int viewIndex) {
              return getViewToModel()[viewIndex].modelIndex;
          private int[] getModelToView() {
              if (modelToView == null) {
                  int n = getViewToModel().length;
                  modelToView = new int[n];
                  for (int i = 0; i < n; i++) {
                      modelToView[modelIndex(i)] = i;
              return modelToView;
          // TableModel interface methods
          public int getRowCount() {
              return (tableModel == null) ? 0 : tableModel.getRowCount();
          public int getColumnCount() {
              return (tableModel == null) ? 0 : tableModel.getColumnCount();
          public String getColumnName(int column) {
              return tableModel.getColumnName(column);
          public Class getColumnClass(int column) {
              return tableModel.getColumnClass(column);
          public boolean isCellEditable(int row, int column) {
              return tableModel.isCellEditable(modelIndex(row), column);
          public Object getValueAt(int row, int column) {
              return tableModel.getValueAt(modelIndex(row), column);
          public void setValueAt(Object aValue, int row, int column) {
              tableModel.setValueAt(aValue, modelIndex(row), column);
          // Helper classes
          private class Row implements Comparable {
              private int modelIndex;
              public Row(int index) {
                  this.modelIndex = index;
              public int compareTo(Object o) {
                  int row1 = modelIndex;
                  int row2 = ((Row) o).modelIndex;
                  for (Iterator it = sortingColumns.iterator(); it.hasNext();) {
                      Directive directive = (Directive) it.next();
                      int column = directive.column;
                      Object o1 = tableModel.getValueAt(row1, column);
                      Object o2 = tableModel.getValueAt(row2, column);
                      int comparison = 0;
                      // Define null less than everything, except null.
                      if (o1 == null && o2 == null) {
                          comparison = 0;
                      } else if (o1 == null) {
                          comparison = -1;
                      } else if (o2 == null) {
                          comparison = 1;
                      } else {
                          comparison = getComparator(column).compare(o1, o2);
                      if (comparison != 0) {
                          return directive.direction == DESCENDING ? -comparison : comparison;
                  return 0;
          private class TableModelHandler implements TableModelListener {
              public void tableChanged(TableModelEvent e) {
                  // If we're not sorting by anything, just pass the event along.
                  if (!isSorting()) {
                      clearSortingState();
                      fireTableChanged(e);
                      return;
                  // If the table structure has changed, cancel the sorting; the
                  // sorting columns may have been either moved or deleted from
                  // the model.
                  if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                      cancelSorting();
                      fireTableChanged(e);
                      return;
                  // We can map a cell event through to the view without widening
                  // when the following conditions apply:
                  // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
                  // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
                  // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
                  // d) a reverse lookup will not trigger a sort (modelToView != null)
                  // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
                  // The last check, for (modelToView != null) is to see if modelToView
                  // is already allocated. If we don't do this check; sorting can become
                  // a performance bottleneck for applications where cells
                  // change rapidly in different parts of the table. If cells
                  // change alternately in the sorting column and then outside of
                  // it this class can end up re-sorting on alternate cell updates -
                  // which can be a performance problem for large tables. The last
                  // clause avoids this problem.
                  int column = e.getColumn();
                  if (e.getFirstRow() == e.getLastRow()
                          && column != TableModelEvent.ALL_COLUMNS
                          && getSortingStatus(column) == NOT_SORTED
                          && modelToView != null) {
                      int viewIndex = getModelToView()[e.getFirstRow()];
                      fireTableChanged(new TableModelEvent(TableSorter.this,
                                                           viewIndex, viewIndex,
                                                           column, e.getType()));
                      return;
                  // Something has happened to the data that may have invalidated the row order.
                  clearSortingState();
                  fireTableDataChanged();
                  return;
          private class MouseHandler extends MouseAdapter {
              public void mouseClicked(MouseEvent e) {
                  JTableHeader h = (JTableHeader) e.getSource();
                  TableColumnModel columnModel = h.getColumnModel();
                  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                  int column = columnModel.getColumn(viewColumn).getModelIndex();
                  if (column != -1) {
                      int status = getSortingStatus(column);
                      if (!e.isControlDown()) {
                          cancelSorting();
                      // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                      // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                      status = status + (e.isShiftDown() ? -1 : 1);
                      status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                      setSortingStatus(column, status);
          private class Arrow implements Icon {
              private boolean descending;
              private int size;
              private int priority;
              public Arrow(boolean descending, int size, int priority) {
                  this.descending = descending;
                  this.size = size;
                  this.priority = priority;
              public void paintIcon(Component c, Graphics g, int x, int y) {
                  Color color = c == null ? Color.GRAY : c.getBackground();
                  // In a compound sort, make each succesive triangle 20%
                  // smaller than the previous one.
                  int dx = (int)(size/2*Math.pow(0.8, priority));
                  int dy = descending ? dx : -dx;
                  // Align icon (roughly) with font baseline.
                  y = y + 5*size/6 + (descending ? -dy : 0);
                  int shift = descending ? 1 : -1;
                  g.translate(x, y);
                  // Right diagonal.
                  g.setColor(color.darker());
                  g.drawLine(dx / 2, dy, 0, 0);
                  g.drawLine(dx / 2, dy + shift, 0, shift);
                  // Left diagonal.
                  g.setColor(color.brighter());
                  g.drawLine(dx / 2, dy, dx, 0);
                  g.drawLine(dx / 2, dy + shift, dx, shift);
                  // Horizontal line.
                  if (descending) {
                      g.setColor(color.darker().darker());
                  } else {
                      g.setColor(color.brighter().brighter());
                  g.drawLine(dx, 0, 0, 0);
                  g.setColor(color);
                  g.translate(-x, -y);
              public int getIconWidth() {
                  return size;
              public int getIconHeight() {
                  return size;
          private class SortableHeaderRenderer implements TableCellRenderer {
              private TableCellRenderer tableCellRenderer;
              public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {
                  this.tableCellRenderer = tableCellRenderer;
              public Component getTableCellRendererComponent(JTable table,
                                                             Object value,
                                                             boolean isSelected,
                                                             boolean hasFocus,
                                                             int row,
                                                             int column) {
                  Component c = tableCellRenderer.getTableCellRendererComponent(table,
                          value, isSelected, hasFocus, row, column);
                  if (c instanceof JLabel) {
                      JLabel l = (JLabel) c;
                      l.setHorizontalTextPosition(JLabel.LEFT);
                      int modelColumn = table.convertColumnIndexToModel(column);
                      l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
                  return c;
          private class Directive {
              private int column;
              private int direction;
              public Directive(int column, int direction) {
                  this.column = column;
                  this.direction = direction;
      //-------------- FIX TABLE'S HEIGHT & COLUMN WIDTH ---------
      public class TableHeight_ColumnWidth {
        private TableSorter sorter;
        private FontMetrics fm;
        private JTable table;
        private int numOfRows = 0, totalTableHeight = 0, totalTableWidth = 0;
         * Constructor --- it needs the model as well the JTable as parameters
         * @param sorter - the model
         * @param table - the JTable created based on the model
        public TableHeight_ColumnWidth(TableSorter sorter, JTable table) {
          this.sorter = sorter;
          this.table = table;
          this.fm = table.getFontMetrics(table.getFont());
          this.numOfRows = table.getRowCount();
         * Calculates the width of each column according to the String it contains
         * @param col = the desired column
         * @param fm = the FontMetrics of this column
         * @return - the width of the single column
        public int determineColumnWidth(TableColumn col, FontMetrics fm) {
          int headerWidth = fm.stringWidth((String)col.getHeaderValue());
          int columnNumber = col.getModelIndex();
          int max = headerWidth;
          int columnWidth = 0;
          String cell = "";
          Integer cell_int = new Integer(0);
          Short cell_short = new Short((short)0);
          for (int i = 0; i != sorter.getRowCount(); i++) {
            Object obj = (Object) sorter.getValueAt(i, columnNumber);
            if (obj instanceof String) {
              cell = (String)sorter.getValueAt(i, columnNumber);
            else if (obj instanceof Integer) {
              cell_int = (Integer)sorter.getValueAt(i, columnNumber);
              cell = String.valueOf(cell_int.intValue());
            else if (obj instanceof Short) {
              cell_short = (Short) sorter.getValueAt(i, columnNumber);
              cell = String.valueOf(cell_short.shortValue());
            columnWidth = fm.stringWidth(cell) + 5;
            if (columnWidth > max) {
              max = columnWidth;
          return max + 5;
         * Calculates the total width of the table according to the width of each
         * column.
         * @return - totalTableWidth
        private int fixColumnWidth () {
          int totalTableWidth = 0;
          TableColumn c = null;
          int cw = 0;
          for (int i = 0; i < table.getColumnCount(); i++) {
            c = table.getColumn(table.getColumnName(i));
            cw = this.determineColumnWidth(c, fm);
            c.setPreferredWidth(cw);
            totalTableWidth = totalTableWidth + cw;
            c.setMinWidth(cw);
          return totalTableWidth;
         * Calculates the height of the table according to the height of each row
         * multiplied by 51 (by default) or by the totalRowsCount.
         * @return - totalTableHeight
        private int fixTableHeight(int maxVisibleRows) {
          int rowHeight = table.getRowHeight();
          //Show maxVisibleRows rows maximum
          if (numOfRows > maxVisibleRows) {
            totalTableHeight = rowHeight * maxVisibleRows;
          else {
            totalTableHeight = rowHeight * numOfRows;
          return totalTableHeight;
         * Sets up the table according to the totalTableWidth and totalTableHeight
        public void fixTableLook(int maxVisibleRows) {
          table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          totalTableWidth = this.fixColumnWidth();
          totalTableHeight = this.fixTableHeight(maxVisibleRows);
          table.setPreferredScrollableViewportSize(new Dimension(totalTableWidth, totalTableHeight));
    }Also, I want some column headers to display their text in two-rows. But by using the HTML technique look at the result in comparison with the previous table I had!
    import javax.swing.JFrame;
    import java.awt.HeadlessException;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.util.Vector;
    import javax.swing.table.DefaultTableModel;
    //--------- TableSorter ----------
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    //---------- Table Height - Column Width
    import javax.swing.table.TableColumn;
    import java.awt.FontMetrics;
    import javax.swing.JTable;
    import java.awt.Dimension;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2006</p>
    * <p>Company: </p>
    * @author not attributable
    * @version 1.0
    public class Test extends JFrame {
      JPanel jPanel1 = new JPanel();
      JPanel jPanel2 = new JPanel();
      JButton jButton1 = new JButton();
      FlowLayout flowLayout1 = new FlowLayout();
      BorderLayout borderLayout1 = new BorderLayout();
      BorderLayout borderLayout2 = new BorderLayout();
      //------------- MY VARIABLES -------------
      String[] columnNames_objectArr = new String[] {
          "Col1",
          "Column 2",
          "Column 3",
          "C4",
          "Col5",
          "Col 6",
      Vector columnNames_vector = new Vector();
      private Vector data_vector = new Vector();
      private Object[][] data_objectArr;
      public TableHeight_ColumnWidth tcw;
      private int totalTableWidth = 0, totalTableHeight = 0;
      private JComboBox jcmbxData = new JComboBox(
          new String[] {"Not Configured", "Switch", "Modem"});
      private int maxVisibleRows = 51;
      TableSorter model;
      private JTable table;
      JScrollPane jScrollPane1;
      public Test(String[] args) throws HeadlessException {
        try {
          jbInit();
          setupGUI();
          launchGUI();
        catch(Exception e) {
          e.printStackTrace();
      private void jbtnClose_actionPerformed(ActionEvent e) {
        dispose();
      private void launchGUI() {
        pack();
        setVisible(true);
        setResizable(false);
      private void setupGUI() {
        columnNames_vector.addElement("<html>Col1</html>");
        columnNames_vector.addElement("<html>Column 2</html>");
        columnNames_vector.addElement("<html>Column 3<br>Second Row</html>");
        columnNames_vector.addElement("<html>C4</html>");
        columnNames_vector.addElement("<html>Col5</html>");
        columnNames_vector.addElement("<html>Col 6</html>");
        Vector row_data1 = new Vector();
        Vector row_data2 = new Vector();
        Vector row_data3 = new Vector();
        Vector row_data4 = new Vector();
        Vector row_data5 = new Vector();
        Vector row_data6 = new Vector();
        row_data1.add("Mary");
        row_data1.add("Campioneato");
        row_data1.add("Snowboarding");
        row_data1.add(new Integer(578987899));
        row_data1.add(new Boolean(false));
        row_data1.add("Not Configured");
        row_data2.add("Alison");
        row_data2.add("Huml");
        row_data2.add("Rowing");
        row_data2.add(new Integer(3));
        row_data2.add(new Boolean(true));
        row_data2.add("Switch");
        row_data3.add("Ka");
        row_data3.add("Walrath");
        row_data3.add("Knitting");
        row_data3.add(new Integer(2));
        row_data3.add(new Boolean(false));
        row_data3.add("Modem");
        row_data4.add("Sharon");
        row_data4.add("Zakhouras");
        row_data4.add("Speed reading");
        row_data4.add(new Integer(20));
        row_data4.add(new Boolean(true));
        row_data4.add("Switch");
        row_data5.add("Philip");
        row_data5.add("Milner");
        row_data5.add("Pool");
        row_data5.add(new Integer(10));
        row_data5.add(new Boolean(false));
        row_data5.add("Not Configured");
        data_vector.add(row_data1);
        data_vector.add(row_data2);
        data_vector.add(row_data3);
        data_vector.add(row_data4);
        data_vector.add(row_data5);
        model = new TableSorter(new SortTableModel(data_vector, columnNames_vector));
        table = new JTable(model);
        tcw = new TableHeight_ColumnWidth(model, table);
        jScrollPane1 = new JScrollPane(table);
        model.setTableHeader(table.getTableHeader());
        jPanel1.add(jScrollPane1, BorderLayout.CENTER);
        //Add a JComboBox as a cellEditor...
        DefaultCellEditor dce = new DefaultCellEditor(jcmbxData);
        table.getColumnModel().getColumn(5).setCellEditor(dce);
        //..... add the IPJPanel as cellEditor.....
        tcw.fixTableLook(maxVisibleRows);
      private void jbInit() throws Exception {
        this.getContentPane().setLayout(borderLayout2);
        jPanel1.setLayout(borderLayout1);
        jPanel2.setLayout(flowLayout1);
        jButton1.setText("Close");
        jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
        jPanel2.add(jButton1, null);
        jButton1.addActionListener(new ActionListener() {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

    First of all I found out that when I set the column's header like this:
    columnNames_vector.addElement("<html>Column 3<br>Second Row</html>"); //In the setupGUI() methodthe TableHeight_ColumnWidth.determineColumnWidth(TableColumn col, FontMetrics fm) method calculates the column's width by counting <html>, </html>, <br> characters as well. So I added a check to reject these characters and not count them for the column's width.
    As for the header's height:
    I found that when the first column's header is set to display two-lines, then the height of the rest columns headers is set to display two-lines as well. In other words, the height of the first column's header affects the height of the whole JTableHeader.
    I found that the BasicTableHeaderUI.getHeaderHeight() method is called, within which there are these comments:
              // If the header value is empty (== "") in the
              // first column (and this column is set up
              // to use the default renderer) we will
              // return zero from this routine and the header
              // will disappear altogether. Avoiding the calculation
              // of the preferred size is such a performance win for
              // most applications that we will continue to
              // use this cheaper calculation, handling these
              // issues as `edge cases'. Should I override a class and if so which one? I am so confused! If anyone has any idea about how to set the header's height according to the cell's height that is the maximum among all, please let me know.

  • How to make a table control header become two rows?

    Hi, all.
    May I know how to make the static header/label rown in table control on screen become two rows?
    As we know, normally a table control's first row is header, and starting from the second row onwards are it's content or data. So, now I would like to make the hedear/label become first two rows.
    Anyone know about it?
    Thanks in advance.

    Hai Lim,
    Kindly search in SDN.
    "You can't actually have two lines but you can create a title which you may be able to align with the headings to achieve what you want. On the table control tick the 'w/title' box. It then forces you to put an element into a line at the top of the table control."
    Regards,
    Harish

  • Split ALV Column heading into two

    Hello All,
    I have a ALV Column Header - ALV LIST - SAP 46C.
    Material   |  Info Type |  Quantity |  Price etc..
    Due to space contraints and other reason client needs to split the Info type column into two.
    Material   |  Info  |  Quantity |  Price etc..
               | Type   |
    The data records should not have any additional blank lines.
    How to achieve this?
    Thanks,

    You have to assign X to layout property no_colhead.
    Then write your heading using write statements.
    Here is the exact example you are looking for [Create Multiple Lines Header In ALV List Report|http://www.freesaptutorial.com/create-multiple-lines-header-in-alv-list-report/]

  • ALV column header with multiple rows and ALV column header span

    How could I have in an ALV a column header on several lines and/or a column header that spans on multiple columns?
    i.e. I would like to have in an ALV two columns, each with it's own distinct header and additionally another column header for both of the columns, that spans across both columns. How could I program this?

    Hi,
    follow below mentioned code
    SET THE LABEL OF THE COLUMN
    DATA: hr_weeknum TYPE REF TO cl_salv_wd_column_header.
    CALL METHOD lr_weeknum->get_header
    RECEIVING
    value = hr_weeknum.
    CALL METHOD lr_weeknum->set_resizable
    EXPORTING
    value = abap_false.
    hr_weeknum->set_prop_ddic_binding_field(
    property = if_salv_wd_c_ddic_binding=>bind_prop_text
    value = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
    set the text of the column
    CALL METHOD hr_weeknum->set_text
    EXPORTING
    value = 'C Form'.
    Regards,
    Srini.

  • Alv column heading in two lines

    Hi,
    In ALV grid column headings is possible in two lines.
    ex.
    material            old material
    Number            Number
    Regards,
    Suresh

    Hi Suresh,
              It is possible in ALV Grid. Please try using the code below:
    Data : it_fieldcat type slis_t_fieldcat_alv,
              wa_fieldcat like line of it_fieldcat,
              IT_LISTHEADER  TYPE SLIS_T_LISTHEADER,
              WA_LISTHEADER  LIKE LINE OF IT_LISTHEADER,
              W_PSTRING1(65) TYPE C,
              W_PSTRING2(60) TYPE C.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = SY-REPID
       I_CALLBACK_TOP_OF_PAGE         = 'TOP'
       IT_FIELDCAT                                  = it_fieldcat
      TABLES
        t_outtab                                         = it_final
    *&      Form  TOP
        TOP OF PAGE FOR ALV REPORT
    FORM TOP.
    *APPENDING HEADER DETAILS
      W_PSTRING1 = text-001.
      WA_LISTHEADER-TYP = 'H'.
      WA_LISTHEADER-INFO = W_PSTRING1.
      APPEND WA_LISTHEADER TO IT_LISTHEADER.
      clear wa_listheader.
      W_PSTRING2 = text-002.
      WA_LISTHEADER-TYP = 'H'.
      WA_LISTHEADER-INFO = W_PSTRING2.
      APPEND WA_LISTHEADER TO IT_LISTHEADER.
       clear wa_listheader.
    FM FOR DISPLAYING THE HEADER
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY = IT_LISTHEADER.
      CLEAR IT_LISTHEADER.
    ENDFORM.
    text-001 = ALV Demo
    text-002 = Sample Program
    Output : ALV Demo
                Sample Program
           I hope it will solve your problem.

  • I want to create an ALV  with two row fields name

    Hi
    I want to create an ALV  with two row fields name. please suggest how to do it or send some sample code
    thanks

    Hi,
    see this link
    http://****************/Tutorials/ALV/ALVMainPage.htm
    http://www.alvrobot.com.ar/tutorial.php
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b09ac4d5-e3ad-2910-6a81-96d1b861928c
    http://abapprogramming.blogspot.com/2007/11/alv-check-boxes-sample-code.html
    REPORT zalv5 NO STANDARD PAGE HEADING.
    Description----
    TOPICS INTRODUCED:
    1. Learn about the u2018Standardu2019 PF-Status that comes as default.
    2. Exclude function codes from u2018Standardu2019 PF-Status and customize it.
    TYPE-POOLS: slis.
    DATA: BEGIN OF i_data OCCURS 0,
    qmnum LIKE qmel-qmnum,
    qmart LIKE qmel-qmart,
    qmtxt LIKE qmel-qmtxt,
    ws_row TYPE i,
    ws_char(5) TYPE c,
    chk,
    END OF i_data.
    DATA: report_id LIKE sy-repid.
    DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.
    DATA: i_layout TYPE slis_layout_alv.
    DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
    DATA: i_events TYPE slis_t_event.
    DATA: i_header TYPE slis_t_listheader.
    DATA: i_extab TYPE slis_t_extab.
    SELECT qmnum
    qmart
    qmtxt
    INTO TABLE i_data
    FROM qmel
    WHERE qmnum <= '00030000010'. LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. PERFORM f3000_build_header CHANGING i_header. PERFORM f4000_events_init CHANGING i_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_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 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data 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.
    *& Form F1000_Layout_Init
    FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
    CLEAR i_layout.
    i_layout-colwidth_optimize = 'X'.
    i_layout-edit = 'X'.
    ENDFORM. " F1000_Layout_Init
    *& Form f2000_fieldcat_init
    FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
    DATA: line_fieldcat TYPE slis_fieldcat_alv.
    CLEAR line_fieldcat.
    line_fieldcat-fieldname = 'QMNUM'. " The field name and the table
    line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req.
    line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)
    line_fieldcat-seltext_m = 'Notification No.'. " Column Header
    APPEND line_fieldcat TO i_fieldcat.
    CLEAR line_fieldcat.
    line_fieldcat-fieldname = 'QMART'.
    line_fieldcat-ref_tabname = 'I_DATA'.
    line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot.
    line_fieldcat-seltext_m = 'Notif Type'.
    APPEND line_fieldcat TO i_fieldcat.
    CLEAR line_fieldcat.
    line_fieldcat-fieldname = 'QMTXT'.
    line_fieldcat-tabname = 'I_DATA'.
    line_fieldcat-seltext_m = 'Description'.
    APPEND line_fieldcat TO i_fieldcat.
    CLEAR line_fieldcat.
    line_fieldcat-fieldname = 'WS_ROW'.
    line_fieldcat-tabname = 'I_DATA'.
    line_fieldcat-seltext_m = 'Row Number'.
    APPEND line_fieldcat TO i_fieldcat.
    CLEAR line_fieldcat.
    line_fieldcat-fieldname = 'WS_CHAR'.
    line_fieldcat-tabname = 'I_DATA'.
    line_fieldcat-seltext_l = 'Test Character Field'.
    line_fieldcat-datatype = 'CHAR'.
    line_fieldcat-outputlen = '15'. " You can specify the width of a
    APPEND line_fieldcat TO i_fieldcat. " column.
    CLEAR line_fieldcat.
    line_fieldcat-fieldname = 'CHK'.
    line_fieldcat-tabname = 'I_DATA'.
    line_fieldcat-seltext_l = 'Checkbox'.
    line_fieldcat-checkbox = 'X'. " Display this field as a checkbox
    line_fieldcat-edit = 'X'. " This option ensures that you can
    " edit the checkbox. Else it will
    " be protected.
    APPEND line_fieldcat TO i_fieldcat.
    ENDFORM. " f2000_fieldcat_init
    *& Form f3000_build_header
    FORM f3000_build_header USING i_header TYPE slis_t_listheader.
    DATA: gs_line TYPE slis_listheader.
    CLEAR gs_line.
    gs_line-typ = 'H'.
    gs_line-info = 'This is line of type HEADER'.
    APPEND gs_line TO i_header.
    CLEAR gs_line.
    gs_line-typ = 'S'.
    gs_line-key = 'STATUS 1'.
    gs_line-info = 'This is line of type STATUS'.
    APPEND gs_line TO i_header.
    gs_line-key = 'STATUS 2'.
    gs_line-info = 'This is also line of type STATUS'.
    APPEND gs_line TO i_header.
    CLEAR gs_line.
    gs_line-typ = 'A'.
    gs_line-info = 'This is line of type ACTION'.
    APPEND gs_line TO i_header.
    ENDFORM. " f3000_build_header
    *& Form f4000_events_init
    FORM f4000_events_init CHANGING i_events TYPE slis_t_event.
    DATA: line_event TYPE slis_alv_event.
    CLEAR line_event.
    line_event-name = 'TOP_OF_PAGE'.
    line_event-form = 'F4100_TOP_OF_PAGE'.
    APPEND line_event TO i_events.
    CLEAR line_event.
    line_event-name = 'PF_STATUS_SET'.
    line_event-form = 'F4200_PF_STATUS_SET'.
    APPEND line_event TO i_events.
    ENDFORM. " f3000_events_init
    FORM F4100_TOP_OF_PAGE *
    FORM f4100_top_of_page.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    it_list_commentary = i_header.
    ENDFORM.
    FORM F4200_PF_STATUS_SET *
    FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab.
    REFRESH i_extab.
    PERFORM f4210_exclude_fcodes CHANGING i_extab.
    SET PF-STATUS 'STANDARD' OF PROGRAM 'SAPLSALV' EXCLUDING i_extab.
    ENDFORM.
    *& Form f4210_exclude_fcodes
    FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab.
    DATA: ws_fcode TYPE slis_extab.
    CLEAR ws_fcode.
    ws_fcode = '&EB9'. " Call up Report.
    APPEND ws_fcode TO i_extab.
    ws_fcode = '&ABC'. " ABC Analysis.
    APPEND ws_fcode TO i_extab.
    ws_fcode = '&NFO'. " Info Select.
    APPEND ws_fcode TO i_extab.
    ws_fcode = '&LFO'. " Information.
    APPEND ws_fcode TO i_extab.
    ENDFORM. " f4210_exclude_fcodes
    thanks
    karthik
    reward me if usefull

  • How to hide the grid lines between two rows in a ALv? Please help!

    Hi Experts,
             I have a ABAP ALV(reuse alv grid FM) report.
    The last field in the ALV is "Description" which can contain data of size more than 130 chars.
    Since the max field length in ALV grid is 130 chars hence I am splitting this field value whenever the field length is more than 130 chars.
    After splitting I am generating duplicate rows but with different "Description" field values ( each contains the splitted values".
    For example:
    Name| City | Description                             |
    Hari|HK    |Employee responsible for time management |
    Hari|HK    |and issue resolution                     |
    Now I want to hide the grid line between these two rows
    and just for Description field.
    In other words I want ALV to display like this:
    Name| City | Description                             |
    Hari|HK    |Employee responsible for time management |
    Hari|HK    |and issue resolution                     |
    How can I acheive this?
    Please provide some sample code.
    Please help. I will be really greatfull to your help.
    Thanks
    Gopal

    Hi Rich,
          If that is the case then atleast how can I hide the complete row grid line?
    Please give some sample code.
    Thanks
    Gopal

  • Header in two lines in ALV

    Hello experts,
    How to get the header in two lines with the use of ALV...like
    PO LINE  #          ORD QTY         UNIT     MATERIAL          DESCRIPTION               QTY TO RECV     QTY  RECV
                   VEND MAT          ST LOCSHELF BIN     ST LOCBULK BIN          
    I am not getting the correct format here but the scenario is like in the first line at the first second and forth columns i have 3 fields n in the second line at the third postion i have one more field...
    Can any one guide me in this plz its bit urgent....
    SRI

    hi,
    Finally one more question....
    I need some outlined logic for the below requirement... can u guide me plz
    functional specs like goes here
    SAP Assumes that all stock receipts will occur online using the MIGO_GR transaction.  However most dealers receive from a paper receiver report.  Some dealers use a blind receipt in which the goods receiver writes down the quantities counted.  Others use an 'open' receivers report where the receiver can see the open quantities to be received.  The report should have a run flag which supports both options.  The receiver report should capture the basic information from the purchase order to include:
    Vendor
    Purchase Order Number
    Line Item Details      
    Material ( Vendor Material Number )      
    Dealer Material Number      
    Quantity Ordered/To-be-received      
    Unit of Measure * Receiver Name  ( Write In Blank )
    Buyer
    Plz gimme some guidance...
    SRI

  • In ALV to make coloum heading in two lines

    I have requrement that my alv report should display the output in two lines.
    ie the first one should be in English and the second line should be in fresh for the same field description .
    Is this posible? can one help me in doing this.

    Hi,
      I guess this is not possible to display the report header in two lines.
    If you find any solution then please post it in SDN, so that i can use the functionality in my future.
    Rgds,
    Bujji

  • Query : In rows, can we split heading in two lines?

    Hi Friends !
    I know, in columns, we can split the heading in two lines.
    In Rows, characteristics " Nomination Header " is there. The output should come like:
    Nomination
    Header
    Awaiting your inputs.
    Thanks
    Rekha

    Hi,
    After entering the text <i>Nomination</i> click on enter button and type <i>Header</i> , in the query designer.
    With rgds,
    Anil Kumar Sharma .P

  • How to get difference between two rows for a column field?

    hi, all,
    Could anyone show me what query statement is to get the difference betweem two rows for two column fields?
    The tables and its records are like this:
    id,      begin,      end
    p1         21          30
    p2          45          60
    p3          120          150
    I would like to have the query result like this
    id,    diff
    p1     15    --- which is 45 minus 30
    p2     60    --- which is 120 minus 60
    and so on...
    thank you in advance.
    Raffy

    You can use the LAG function to access values from previous rows:
    with q as (select 'p1' id, 21 v_start, 30 v_end from dual
    union all
    select 'p2', 45, 60 from dual
    union all
    select 'p3', 120, 150 from dual)
    select id, v_start, v_end, v_start - lag (v_end, 1, 0)
      over (order by id) v_diff from q
    ID,V_START,V_END,V_DIFF
    p1,21,30,21
    p2,45,60,15
    p3,120,150,60
    See the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions075.htm

Maybe you are looking for