Insert a row in ALV

Hi ,
I need to insert a row in ALV output. On click of a Inser Row button a pop up should show with a parameter.Once the value in entered in the parameter enter is hit , the first column of the new row should have value put in that parameter as non editable field.
The Insert row of standard toolbar inserts a blank row . Is there any way to incorporate the above logic in the standard toolbar?
I'm using CL_GUI_ALV_GRID to display the ALV.
It would be helpful if you provide sample coding.
Thanks.
Ajith
Edited by: Ajith  Krishna on Oct 28, 2008 8:01 PM

Hello Ajith
The enhanced version of sample report ZUS_SDN_ALVGRID_EDITABLE_8A demonstrates how to implement your requirement.
*& ZUS_SDN_ALVGRID_EDITABLE_8A
*& Thread: Insert a row in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1105097"></a>
*& Thread: Blanking values on ALV Grid Row Duplicate
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1057161"></a>
*& Thread: Delete line event in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="945471"></a>
REPORT  zus_sdn_alvgrid_editable_8a.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                      WITH DEFAULT KEY.
DATA:
  gd_okcode        TYPE ui_func,
  gd_repid         TYPE syst-repid,
  gt_fcat          TYPE lvc_t_fcat,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_grid          TYPE REF TO cl_gui_alv_grid.
DATA:
  gt_outtab        TYPE ty_t_outtab.
*       CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA:
      mt_sel_rows     TYPE lvc_t_row.
    CLASS-METHODS:
      handle_toolbar
        FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING
          e_object
          sender,
      handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING
          e_ucomm
          sender.
ENDCLASS.                    "lcl_eventhandler DEFINITION
*       CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
  METHOD handle_toolbar.
* define local data
    DATA: ls_button     TYPE stb_button.
    LOOP AT e_object->mt_toolbar INTO ls_button.
      CASE ls_button-function.
        when cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW.
          ls_button-function = 'INSERT_ROW'.
          MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
        WHEN cl_gui_alv_grid=>mc_fc_loc_delete_row.
          ls_button-function = 'DELETE_ROW'.
          MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
        WHEN cl_gui_alv_grid=>mc_fc_loc_copy_row OR
             cl_gui_alv_grid=>mc_fc_loc_copy.
          ls_button-function = 'COPY_ROW'.
          MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
        WHEN OTHERS.
          CONTINUE.
      ENDCASE.
    ENDLOOP.
  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
* define local data
    DATA: lt_rows       TYPE lvc_t_row,
          ls_row        TYPE lvc_s_row.
    REFRESH: mt_sel_rows.
    CASE e_ucomm.
      when 'INSERT_ROW'.
      WHEN 'DELETE_ROW'.
      WHEN 'COPY_ROW'.
      WHEN OTHERS.
        RETURN.
    ENDCASE.
    "   User wants to delete or copy rows => store them in class attribute
    "   and trigger PAI afterwards where we actually delete /copy the rows
    "   and do the recalculations (in case of deletion)
    CALL METHOD sender->get_selected_rows
      IMPORTING
        et_index_rows = mt_sel_rows
*        et_row_no     =
*   Trigger PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = e_ucomm
*      IMPORTING
*        rc       =
  ENDMETHOD.                    "user_command
ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
  p_bukrs      TYPE bukrs  DEFAULT '2000'  OBLIGATORY.
START-OF-SELECTION.
  SELECT  * FROM  knb1 INTO CORRESPONDING FIELDS OF TABLE gt_outtab
         UP TO 15 ROWS
         WHERE  bukrs  = p_bukrs.
  PERFORM init_controls.
  SET HANDLER:
    lcl_eventhandler=>handle_toolbar      FOR go_grid,
    lcl_eventhandler=>handle_user_command FOR go_grid.
  " Used to replace standard toolbar function code with custom FC
  go_grid->set_toolbar_interactive( ).
* Link the docking container to the target dynpro
  gd_repid = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.
END-OF-SELECTION.
*&      Module  STATUS_0100  OUTPUT
*       text
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.
**      CALL METHOD go_grid1->refresh_table_display
***        EXPORTING
***          IS_STABLE      =
***          I_SOFT_REFRESH =
**        EXCEPTIONS
**          FINISHED       = 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.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&      Module  USER_COMMAND_0100  INPUT
*       text
MODULE user_command_0100 INPUT.
  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.
    WHEN 'INSERT_ROW'.
      perform INSERT_ROW.
    WHEN 'DELETE_ROW'.
      PERFORM delete_rows.
    WHEN 'COPY_ROW'.
      PERFORM copy_rows.
    WHEN OTHERS.
  ENDCASE.
  CLEAR: gd_okcode.
  CALL METHOD go_grid->refresh_table_display
*      EXPORTING
*        IS_STABLE      =
*        I_SOFT_REFRESH =
    EXCEPTIONS
      finished       = 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.
ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&      Form  BUILD_FIELDCATALOG_KNB1
*       text
*  -->  p1        text
*  <--  p2        text
FORM build_fieldcatalog_knb1 .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'KNB1'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* Only non-key fields are editable
  ls_fcat-edit = 'X'.
  MODIFY gt_fcat FROM ls_fcat
    TRANSPORTING edit
    WHERE ( key NE 'X' ).
ENDFORM.                    " BUILD_FIELDCATALOG_KNB1
*&      Form  INIT_CONTROLS
*       text
*  -->  p1        text
*  <--  p2        text
FORM init_controls .
* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent = cl_gui_container=>screen0
      ratio  = 90
    EXCEPTIONS
      OTHERS = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* Create ALV grid
  CREATE OBJECT go_grid
    EXPORTING
      i_parent = go_docking
    EXCEPTIONS
      OTHERS   = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog_knb1.
* Display data
  CALL METHOD go_grid->set_table_for_first_display
    CHANGING
      it_outtab       = gt_outtab
      it_fieldcatalog = gt_fcat
    EXCEPTIONS
      OTHERS          = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " INIT_CONTROLS
*&      Form  delete_rows
*       text
*  -->  p1        text
*  <--  p2        text
FORM delete_rows .
* define local data
  DATA: ls_row    TYPE lvc_s_row.
  SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
  LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
    DELETE gt_outtab INDEX ls_row-index.
  ENDLOOP.
  " After deleting rows do RE-CALCULATION
*  perform RECALCULATION.
ENDFORM.                    " delete_rows
*&      Form  COPY_ROWS
*       text
*  -->  p1        text
*  <--  p2        text
FORM copy_rows .
* define local data
  DATA: ld_next   TYPE i,
        ls_row    TYPE lvc_s_row,
        ls_outtab TYPE ty_s_outtab.
  SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
  LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
    READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.
    CLEAR: ls_outtab-akont. " In your case: clear GUID
    ld_next = ls_row-index + 1.
    INSERT ls_outtab INTO gt_outtab INDEX ld_next.
  ENDLOOP.
ENDFORM.                    " COPY_ROWS
*&      Form  INSERT_ROW
*       text
*  -->  p1        text
*  <--  p2        text
form INSERT_ROW .
* define local data
  DATA: ld_value1  type SPOP-VARVALUE1,
        ls_outtab  TYPE ty_s_outtab.
  CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
    EXPORTING
      textline1            = 'Enter Value (4 Chars):'
*     TEXTLINE2            = ' '
*     TEXTLINE3            = ' '
      titel                = 'Enter Value'
      valuelength          = 4
    IMPORTING
*     ANSWER               =
      VALUE1               = ld_value1
    EXCEPTIONS
      TITEL_TOO_LONG       = 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.
  ls_outtab-kunnr = ld_value1.
  ls_outtab-bukrs = ld_value1.
  append ls_outtab to gt_outtab.
endform.                    " INSERT_ROW
Regards
  Uwe

Similar Messages

  • How to get Inserted and Deleted Rows in ALV

    I have looked at the BC_EDIT* examples but I still can't figure out how to determine which rows were Inserted and Deleted from the ALV list.  Can someone please provide me the code to do this?
    Thanks.
    Sandy

    Hi sandy,
    i dont think you will have issue in inserting a row in ALV because whenever the user done some actions say for eg clicking the pushbutton at the toolbar you could insert the a new row into the ALV.for creating pushbutton you need to use the events TOOLBAR,USER_COMMAND.
    deleting a row may also follow the above procedure.
    Have a look at the demo program
    BCALV_GRID_05
    Cheers,
    Abdul Hakim

  • Insert  Blank row  After every Row  in alv report

    How to insert blank  row After every row  in Alv report

    what do you mean by a 'blank row'? ALV displays tabular data with 'any' number of columns. Now if you actually want a blank row (no columns at all, just a row), then that is just not possible. If I'm not mistaken, this question was posted before, so try to do a search on SCN. See what is says.

  • About inserting color to rows in alv

    hi ,
        could any one tell me how to insert colors to rows in alv.
    regards,
    pavan.

    hi,
    try like this
    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
      line_color(4) TYPE c,     "Used to store row color attributes
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE slis_layout_alv,
          gd_repid     LIKE sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-info_fieldname =      'LINE_COLOR'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    FORM display_alv_report.
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = gd_repid
          is_layout          = gd_layout
          it_fieldcat        = fieldcatalog[]
          i_save             = 'X'
        TABLES
          t_outtab           = it_ekko
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      DATA: ld_color(1) TYPE c.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekko.
    *Populate field with color attributes
      LOOP AT it_ekko INTO wa_ekko.
    Populate color variable with colour properties
    Char 1 = C (This is a color property)
    Char 2 = 3 (Color codes: 1 - 7)
    Char 3 = Intensified on/off ( 1 or 0 )
    Char 4 = Inverse display on/off ( 1 or 0 )
              i.e. wa_ekko-line_color = 'C410'
        ld_color = ld_color + 1.
    Only 7 colours so need to reset color value
        IF ld_color = 8.
          ld_color = 1.
        ENDIF.
        CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
    wa_ekko-line_color = 'C410'.
        MODIFY it_ekko FROM wa_ekko.
      ENDLOOP.
    ENDFORM.                    " DATA_RETRIEVAL
    reward if usefull....

  • Inserting rows in ALV

    Hi Experts,
           Which part of the program in BCALV_EDIT04 is responsible for inserting a row in the grid? there is code to handle the data in the inserted line, to check the cells modified using the protocol, and event handler too. Can you please explain which fm or subroutine or step adds a new row to the grid when teh insert button in tool bar is pressed.
    I also want some guidance reg the event handler thing. Is mouse click on the cell makes the methods of the protocol to be called? ( I am a java student.. learning SAP slowly.. can you please help me?)

    methods:
          get_inserted_rows
               exporting
                  inserted_rows type sflight_keys.
    This part of the code is responsible for inserting rows in a grid. We call this method to insert records in the Grid.
    There is no such function module implemented here. We implement the above functionality using <b>Classes and Methods</b>.
    Just go to transaction SE24. You'll have a list of Classes in that transaction. Also, we can implement methods using those classes.
    Regards,
    Pavan.

  • How to change the colour of row in ALV depending on condition?

    Hi All,
    I want to change the color(from green to red )of perticular row in ALV depending on certain conditions like if amount in some field in row is more than 5000.
    Can anybody please tell me how to do that?
    expecting early reply.
    Thanks in advance,
    Rohini.

    Hi
    Check this sample report
    *& Report  ZALVCOLOR                                                   *
    REPORT  ZALVCOLOR                               .
    DATA : mara TYPE mara.                 " General Material Data
    TYPE-POOLS: slis.                      " ALV Global types
    FIELD-SYMBOLS :
      <data> TYPE table.                   " Data to display
    SELECT-OPTIONS :
      s_matnr FOR mara-matnr.              " Material number
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
    PARAMETERS p_max(2) TYPE n DEFAULT '50' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    INITIALIZATION.
      v_1 = 'Maximum of lines to display'.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
    *      Form  f_read_data
    FORM f_read_data.
      FIELD-SYMBOLS :
        <field>    TYPE ANY,
        <field2>   TYPE ANY,
        <header>   TYPE ANY,
        <header2>  TYPE ANY,
        <lt_data>  TYPE table.             " Data read from DB
      DATA:
        lp_struct  TYPE REF TO data,
        lp_struct2 TYPE REF TO data,
        lp_table   TYPE REF TO data,       " Pointer to dynamic table
        lp_table2  TYPE REF TO data,       " Pointer to dynamic table
        ls_lvc_cat TYPE lvc_s_fcat,
        lt_lvc_cat TYPE lvc_t_fcat.        " Field catalog
    * First column
      CLEAR ls_lvc_cat.
      ls_lvc_cat-fieldname = 'MATNR'.
      ls_lvc_cat-ref_table = 'MARA'.
      APPEND ls_lvc_cat TO lt_lvc_cat.
    * 2nd column
      CLEAR ls_lvc_cat.
      ls_lvc_cat-fieldname = 'MAKTX'.
      ls_lvc_cat-ref_table = 'MAKT'.
      APPEND ls_lvc_cat TO lt_lvc_cat.
    * 3rd column
      CLEAR ls_lvc_cat.
      ls_lvc_cat-fieldname = 'MATKL'.
      ls_lvc_cat-ref_table = 'MARA'.
      APPEND ls_lvc_cat TO lt_lvc_cat.
    * Create 1st internal table
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING it_fieldcatalog = lt_lvc_cat
        IMPORTING ep_table = lp_table.
      ASSIGN lp_table->* TO <lt_data>.
    * Read data into 1st internal table
      SELECT matnr maktx matkl
        INTO TABLE <lt_data>
        FROM v_matnr
          UP TO p_max ROWS
       WHERE matnr IN s_matnr.
    * Create 2nd internal table
    * Checkbox
      CLEAR ls_lvc_cat.
      ls_lvc_cat-fieldname = 'CHECKBOX'.
      APPEND ls_lvc_cat TO lt_lvc_cat.
    * Table color
      CLEAR ls_lvc_cat.
      ls_lvc_cat-fieldname = 'TABCOLOR'.
      ls_lvc_cat-ref_table = 'CALENDAR_TYPE'.
      ls_lvc_cat-ref_field = 'COLTAB'.
      APPEND ls_lvc_cat TO lt_lvc_cat.
    * Create 2nd internal table
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING it_fieldcatalog = lt_lvc_cat
        IMPORTING ep_table = lp_table2.
      ASSIGN lp_table2->* TO <data>.
    * Create structure = structure of the 1st internal table
      CREATE DATA lp_struct LIKE LINE OF <lt_data>.
      ASSIGN lp_struct->* TO <header>.
    * Create structure = structure of the 2nd internal table
      CREATE DATA lp_struct2 LIKE LINE OF <data>.
      ASSIGN lp_struct2->* TO <header2>.
    * Move data from 1st internal table --> 2nd internal table
      LOOP AT <lt_data> ASSIGNING <header>.
        DESCRIBE TABLE lt_lvc_cat.
        CLEAR <header2>.
    *   Fill the internal to display <data>
        DO sy-tfill TIMES.
          READ TABLE lt_lvc_cat INTO ls_lvc_cat INDEX sy-index.
    *     For each field of lt_lvc_cat.
          ASSIGN COMPONENT ls_lvc_cat-fieldname OF STRUCTURE <header>
                        TO <field>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          ASSIGN COMPONENT ls_lvc_cat-fieldname OF STRUCTURE <header2>
                        TO <field2>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          <field2> = <field>.
        ENDDO.
    *   Modify color
        ASSIGN COMPONENT 'TABCOLOR' OF STRUCTURE <header2>
                      TO <field2>.
        IF sy-subrc EQ 0.
          PERFORM f_modify_color USING 'MAKTX' <field2>.
          PERFORM f_modify_color USING 'MATKL' <field2>.
        ENDIF.
        APPEND <header2> TO <data> .
      ENDLOOP.
    ENDFORM.                    " f_read_data
    *      Form  F_DISPLAY_DATA
    FORM f_display_data.
    * Macro definition
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-down      = 'X'.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA:
        ls_layout   TYPE slis_layout_alv,
        lt_sort     TYPE slis_t_sortinfo_alv,
        ls_sort     TYPE slis_sortinfo_alv,
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.  " Field catalog
    * Build Fieldcatalog - First column
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   = 'MATNR'.
      ls_fieldcat-ref_tabname = 'MARA'.
      ls_fieldcat-key  = 'X'.
      APPEND ls_fieldcat TO lt_fieldcat.
    * Build Fieldcatalog - 2nd column
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   = 'MAKTX'.
      ls_fieldcat-ref_tabname = 'MAKT'.
      APPEND ls_fieldcat TO lt_fieldcat.
    * Build Fieldcatalog - 3rd column
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname   = 'MATKL'.
      ls_fieldcat-ref_tabname = 'MARA'.
      APPEND ls_fieldcat TO lt_fieldcat.
    * Layout
      ls_layout-zebra = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      ls_layout-box_fieldname = 'CHECKBOX'.
      ls_layout-coltab_fieldname = 'TABCOLOR'.
      m_sort 'MATNR'.                      " Sort by creation date
    * Display data
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           TABLES
                t_outtab    = <data>.
    ENDFORM.                               " F_DISPLAY_DATA
    *      Form  F_modify_color
    FORM f_modify_color USING u_fieldname TYPE lvc_fname
                              ut_tabcolor TYPE table.
      DATA:
        l_rnd_value TYPE datatype-integer2,
        ls_tabcolor TYPE lvc_s_scol.
    * Random value
      CALL FUNCTION 'RANDOM_I2'
           EXPORTING
                rnd_min   = 0
                rnd_max   = 3
           IMPORTING
                rnd_value = l_rnd_value.
      CLEAR ls_tabcolor.
      ls_tabcolor-fname = u_fieldname.
      CASE l_rnd_value.
        WHEN 0.
          ls_tabcolor-color-col = 1.       " Blue.
          ls_tabcolor-color-int = 0.
          ls_tabcolor-color-inv = 0.
        WHEN 1.
          ls_tabcolor-color-col = 3.       " Yellow.
          ls_tabcolor-color-int = 0.
          ls_tabcolor-color-inv = 0.
        WHEN 2.
          ls_tabcolor-color-col = 5.       " Green.
          ls_tabcolor-color-int = 0.
          ls_tabcolor-color-inv = 0.
        WHEN 3.
          ls_tabcolor-color-col = 6.       " Red.
          ls_tabcolor-color-int = 0.
          ls_tabcolor-color-inv = 0.
      ENDCASE.
      INSERT ls_tabcolor INTO TABLE ut_tabcolor.
    ENDFORM.                               " F_MODIFY_COLOR
    Reward all helpfull answers
    Regards
    Pavan

  • Blank Row in ALV Grid Display

    In ALV Display I want to have a <u>BLANK row</u> everytime the value of 'Cross Company Code Document Number' (BVORG) changes.
    Is there a way to use the Sort Option of "REUSE_ALV_GRID_DISPLAY" to do this? Or is the only possible way is by modifying the ITAB that is being passed for display?
    If ITAB is the only method to do it then how should I go about making this happen?
    Thanks-
    Rohit.

    if you do again sort then blank rows will come top,so make sure that should not do sort after inserting blank rows.
    please sort it before inserting blank row .
    sort itab by fields..
    loop at itab.
    endloop.
    do not sort here.
    Thanks
    Seshu

  • Grey-out Row in ALV Grid

    Hi,
    Is it possible that when a user higlights a row in ALV, the entire row will be uneditable? Please teach me how.
    Thanks,
    Jim

    This code works for grey cells...But it could be adapted to lines -;) It uses OO ALV...
    *& Report  Z_DUMMY_ATG
    REPORT  Z_DUMMY_ATG NO STANDARD PAGE HEADING.
    TABLES: SPFLI.
    *============================================================
    * Variables
    *============================================================
    DATA: OK_CODE TYPE SY-UCOMM,
          L_MODE TYPE RAW4,
          W_TABIX TYPE SY-TABIX.
    *============================================================
    * Tablas internas
    *============================================================
    DATA: L_S_LAYO TYPE LVC_S_LAYO.
    DATA: WA_EDIT TYPE LVC_T_STYL WITH HEADER LINE.
    DATA: IT_EDIT TYPE LVC_T_STYL WITH HEADER LINE.
    DATA: BEGIN OF G_WA_SFLIGHT.
            INCLUDE STRUCTURE SPFLI.
    DATA: CELL_TAB TYPE LVC_T_STYL.
    DATA: END OF G_WA_SFLIGHT.
    TYPES: BEGIN OF SPFLI_TAB.
            INCLUDE STRUCTURE SPFLI.
    TYPES: CELL_TAB TYPE LVC_T_STYL.
    TYPES: END OF SPFLI_TAB.
    TYPES: SPFLI_TABS TYPE STANDARD TABLE OF SPFLI_TAB.
    DATA: GI_SFLIGHT TYPE SPFLI_TABS.
    DATA: BEGIN OF AUX_TAB OCCURS 0,
          CARRID LIKE SPFLI-CARRID,
          CONNID LIKE SPFLI-CONNID,
          CITYFROM LIKE SPFLI-CITYFROM,
          AIRPFROM LIKE SPFLI-AIRPFROM,
          CITYTO LIKE SPFLI-CITYTO,
          AIRPTO LIKE SPFLI-AIRPTO,
          END OF AUX_TAB.
    DATA: SPFLI_TAB_WA LIKE G_WA_SFLIGHT.
    FIELD-SYMBOLS: <SF> STRUCTURE G_WA_SFLIGHT
                   DEFAULT SPFLI_TAB_WA.
    *============================================================
    * Objetos
    *============================================================
    DATA: CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
          ALV_LIST TYPE REF TO CL_GUI_ALV_GRID.
    *============================================================
    * Selección de Datos
    *============================================================
    SELECT *
    FROM SPFLI
    INTO CORRESPONDING FIELDS OF TABLE AUX_TAB .
    LOOP AT AUX_TAB.
      MOVE-CORRESPONDING AUX_TAB TO <SF>.
      APPEND <SF> TO GI_SFLIGHT.
    ENDLOOP.
    *============================================================
    * Instancimiento de Objetos
    *============================================================
    CREATE OBJECT CONTAINER
           EXPORTING CONTAINER_NAME = 'LIST_AREA'.
    CREATE OBJECT ALV_LIST
           EXPORTING I_PARENT = CONTAINER.
    *============================================================
    * Procesamiento
    *============================================================
    LOOP AT GI_SFLIGHT INTO G_WA_SFLIGHT.
      W_TABIX = SY-TABIX.
      IF G_WA_SFLIGHT-CITYTO EQ 'SAN FRANCISCO'.
        L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
        MOVE 'CITYTO' TO WA_EDIT-FIELDNAME.
        MOVE L_MODE TO WA_EDIT-STYLE.
        INSERT WA_EDIT INTO IT_EDIT INDEX W_TABIX.
        G_WA_SFLIGHT-CELL_TAB[] = IT_EDIT[].
      ENDIF.
      MODIFY GI_SFLIGHT FROM G_WA_SFLIGHT.
    ENDLOOP.
    MOVE 'CELL_TAB' TO L_S_LAYO-STYLEFNAME.
    CALL METHOD ALV_LIST->SET_READY_FOR_INPUT
          EXPORTING I_READY_FOR_INPUT = 1.
    CALL METHOD ALV_LIST->SET_TABLE_FOR_FIRST_DISPLAY(
                          EXPORTING I_STRUCTURE_NAME = 'SPFLI'
                                    IS_LAYOUT = L_S_LAYO
                          CHANGING IT_OUTTAB = GI_SFLIGHT ).
    *============================================================
    * Dynpro
    *============================================================
    CALL SCREEN 100.
    *&      Module  STATUS_0100  OUTPUT
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS '100'.
    ENDMODULE.
    *&      Module  USER_COMMAND_0100  INPUT
    MODULE USER_COMMAND_0100 INPUT.
      OK_CODE = SY-UCOMM.
      IF OK_CODE = 'BACK'.
        SET SCREEN 0.
        LEAVE SCREEN.
        CLEAR OK_CODE.
      ENDIF.
    ENDMODULE.
    Greetings,
    Blag.

  • Set specific rows in ALV grid ready for input

    Hi everyone,
      I have a question about how to set specific rows in ALV grid ready for input.
      I know that I can make some columns ready for input before the ALV displayed,but I have no idea how to make specific rows displayed in the ALV ready for input.

    Hello Aaron
    For editable columns we can use the fieldcatalog (LVC_S_FCAT-EDIT = 'X') but for rows you need to define editability on cell level.
    The required steps are documented in sample report BCALV_EDIT_02. Below I point out a few crucial points:
    *§1.Extend your output table for a field, e.g., CELLTAB, that holds
    *   information about the edit status of each cell for the
    *   corresponding row (the table type is SORTED!).
    DATA: BEGIN OF gt_outtab occurs 0.  "with header line
            include structure sflight.
    DATA: celltab type LVC_T_STYL.
    DATA: END OF gt_outtab.
    *§3.Provide the fieldname of the celltab field by using field
    *   STYLEFNAME of the layout structure.
       gs_layout-stylefname = 'CELLTAB'.
       CALL METHOD grid1->set_table_for_first_display
             EXPORTING i_structure_name = 'SFLIGHT'
                       is_layout        = gs_layout
             CHANGING  it_outtab        = gt_outtab[].
    Note: in the sample report only field SEATSMAX is editable. In your case you need
    to fill CELLTAB for all fields in a row.
    *§2.After selecting data, set edit status for each row in a loop
    *   according to field SEATSMAX.
      LOOP AT gt_outtab.
        l_index = sy-tabix.
        refresh lt_celltab.
        if gt_outtab-seatsmax ge 300.
            perform fill_celltab using 'RW'
                                 changing lt_celltab.
        else.
            perform fill_celltab using 'RO'
                                 changing lt_celltab.
        endif.
    *§2c.Copy your celltab to the celltab of the current row of gt_outtab.
        INSERT LINES OF lt_celltab INTO TABLE gt_outtab-celltab.
        MODIFY gt_outtab INDEX l_index.
      ENDLOOP.
    ENDFORM.                               " SELECT_DATA_AND_INIT_STYLE
    NOTE: LVC_T_STYL is a SORTED table type. Thus, take care that you are using the
    INSERT ... INTO TABLE statement and not APPEND (because then nothing is appended
    to the CELLTAB itab).
      IF p_mode EQ 'RW'.
    *§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell
    *    to status "editable".
        l_mode = cl_gui_alv_grid=>mc_style_enabled.
      ELSE. "p_mode eq 'RO'
    *§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell
    *    to status "non-editable".
        l_mode = cl_gui_alv_grid=>mc_style_disabled.
      ENDIF.
      ls_celltab-fieldname = 'SEATSMAX'.
      ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
      INSERT ls_celltab INTO TABLE pt_celltab.
    Regards
      Uwe

  • Single row in alv report

    Hi experts...
    I want single row in alv report.
    I have use loop for fatch data into internal table using loop when i am passing data in alv report then the data comes according loop. i want onlu one data in alv row.
    how can i do such, plz help me.

    decleare two internal table.
    read table itab into  wa index  1.
    append wa to itab2.
    pass itab2 only one record display.

  • New inserted detail row is not showing through accessor

    I have to insert master and detail row. I insert row in master view  and then I get detail row using getAttribute on master view. Then I insert row into detail row. Result is one inserted master row and no data display in detail view.
    How ever in managed bean when I get master view using finditerator and then get detail row also using finditerator on the specific page then rows inserted on master and detail view appear.
    DCIteratorBinding dcIter =             ADFUtils.findIterator("PlotMst1Iterator");
    ViewObject mvo = dcIter.getViewObject();
    mvo.insertRowAtRangeIndex(0, row);
    mvo.setCurrentRow(row);
    Row row = mvo.createRow();
    // DETAIL ACCESSOR  not working
      //  RowSet Pd = (RowSet) row.getAttribute("PlotDtl");
    DCIteratorBinding dcIter2 =       ADFUtils.findIterator("PlotDtl2Iterator");      
    ViewObject dvo = dcIter2.getViewObject();
    nvp.setAttribute("FabricCode",r.getAttribute("FabricCode"));
    Row drow = dvo.createAndInitRow(nvp);      
    dvo.insertRow(drow);   

    Hi,
    its a classical programming mistake you do. You create a new row on the model layer and not the binding layer. The proper way of doing this would be to
    1) either create a method binding for the "CreateInsert" operation in the PageDef file and call it from there
    or
    2) DCIteratorBinding dcIter = ADFUtils.findIterator("PlotMst1Iterator");
        Row rw = dcIter.getRowSetIterator().createRow();
    Same for your attempt to create the detail row. Again you can expose the createInsert operation in the PageDef file or use the RowSetIterator. As you create a master and detail row at the same time, be aware of a constraint problem that may arise from this as you have no guarantee that the master is inserted first. Read this http://docs.oracle.com/cd/E35521_01/web.111230/e16182/bcentities.htm#CEGJAFCF to learn about the problem.
    Note that use case often matters. While I can see where your coding goes wrong, I can't tell if your approach in general could be chosen better
    Frank

  • Can not insert a row to a table from Oracle DBA Studio

    Hi,
    I try to use the Oracle DBA Studio to create a table and put some test data in it. Here is what I found:
    I start Oracle DBA Studio on the client machine by connecting to an Oracle server 8i (8.1.7). I create a simple table called Test with two columns: one is USER, VARCHAR2, 10; and the other is USER2, CHAR, 2. After that, I right click on the table name and select "Table Data Editor" from the popup menu. The table editor window shows up. I type in the value 'AA' and 'BB' in the grid of two columns. Then I click the Apply button. An error message box popped up:
    ORA-00928 missing SELECT keyword.
    I click Show SQL button. The SQL statement is as following:
    INSERT INTO "TASYS"."TEST" (USER ,USER2 ) VALUES ('AA' ,'BB').
    I copy the statement to SQL Plus and run it. The same error is generated. But if I remove (USER, USER2) from the statement, it inserts a row without complaint. In other word, the database will not allow to insert if individual columns are list. I realize something must wrong with the new server and client installed and could not figure out what happening. Hope someone can help.
    Thanks.
    null

    I am not sure, but could it be that USER is a keyword or predefine word. Check Oracle'slist of predefine/keyword

  • How to insert horizontal lines in alv report?

    hi,
        i have to insert horizontal lines in alv report.( RM07MLBB )
            actually my requirement is:
                               basis list = RM07MLBB.
    first secondary list = another report is called here ( RM07DOCS )
                      i want to insert horizontal lines in the first secondary list, when i execute individually RM07DOCS , i can get horizontal lines, but when i dounle click in the basic list --> in the first secondary list , i am not getting the horizontal lnes.
    functional modules used are REUSE_ALV_HIERSEQ_LIST_DISPLAY & REUSE_ALV_GRID_DISPLAY.
        here in this program,
                        is_layout = alv_layout.
    hence i tried to give     
                  alv_layout-no_hline = ' '. 
    but not effecting.
              can some one please tell me , how to insert lines in the alv report.
    thanks in advance,
    Dastagir.

    hello,
         so i cannot insert horizontal lines in the first secondary list according to my sorting condition, i.e., in a single block there should be :
           if same delivery challan number is repeating they should come in the same block,
    for the corresponding delivery challen number, if have po number, is repeating , they also should come in the same block.
                       in this way i have to seperate the blocks containing EXNUM , EBELN CONDITIONED.

  • Deactivate the double click/ hot spot for a particular row in alv grid.

    Hello,
       As per a certain condition how to deactivate the double click/ hot spot for a particular row in alv grid.
    Regards,
    Saroj

    where u define layout there is a field hotspot.like
    data: var.
    if con is true
    var = 'X'. (show hotspot)
    else.
    var = ' '. (deactive hotspot)
    elseif ws_fieldcat-fieldname = 'DMBTR'
                    AND ws_fieldcat-tabname = 'T_MTAB'.
          ws_fieldcat-do_sum = C_X.
          <b>ws_fieldcat-hotsopts = var.</b>
          MODIFY Wt_fieldcat FROM ws_fieldcat
                  TRANSPORTING   DO_SUM.
    It is helpful for u. if any problen send me ur coding i will change it.
    Regards
    Manish Kumar

  • Deleting rows in alv report.

    Hi Experts,
                I want to delete a row in alv report output, It is duplicating  records in the report  and 'GRAND TOTAL' also be displayed . In under the report . <<removed_by_moderator>>
    Thanks,
    Dinesh.B
    Edited by: Vijay Babu Dudla on May 11, 2009 9:15 AM

    Hi,
    use the following code for deleting duplicate and adjacent records from itab
    delete ADJACENT DUPLICATES FROM itab.
    or
    sort itab by pernr.
    delete ADJACENT DUPLICATE FROM itab COMPARING pernr.
    Also, for grand total you can use fieldcat-do_sum    =  'X'  with the field catalog. It will give you total for the required column.
    Hope this solves your problem.
    Regards,
    Ibrar Munsif.

Maybe you are looking for

  • Mophie iPhone 5 Case - iPhone will no longer charge using the apple cable.

    Hi All, In July, I purchased a Mophie Case for my iPhone 5. Everything was going great until I realized a few months later that my iPhone would no longer charge using my apple cable. It would only charge using my mophie. Turns out my husband, who als

  • Issue in ABAP Mapping

    Hi All I am using ABAP mapping. After getting children of the root node, i create an iterator by the following statements: node_collection = root_node->get_children( ). node_iterator = node_collection->create_iterator( ). Now, In a loop, i want to ge

  • IPhoto wont open?

    Here is the error report Process:         iPhoto [427] Path:            /Applications/iPhoto.app/Contents/MacOS/iPhoto Identifier:      com.apple.iPhoto Version:         9.3.2 (9.3.2) Build Info:      iPhotoProject-670063000000000~2 App Item ID:    

  • Can someone please shed some light...

    I downloaded a few different apps onto my computer, i eventually managed to work out how to transfer them to my phone without too much trouble but when i press the icon to enter the app the screen goes blank for around 2 seconds as if its about to st

  • HELP! Need to put iPod touch in Recovery mode...

    My brother has an iPod touch (don't know which version but it's about 1 year old) and has forgotten the passcode for it. Unfortunately, we're now using a new installation of Windows (and hence, iTunes too) so we cannot resore it by plugging into it's