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

Help req : alv grid with multiple row selection

Former Member
0 Likes
1,580

Hi all sap gurus,

i have a alv list display program , in which i can select the o/p rows(multiple rows)

and perform some actiom based on some icons .

now i have to convert this in to grid display

this is initial code i.e for list

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE ztest.

DATA : checkbox type c.

DATA : END OF itab.

s_layout-box_fieldname = 'CHECKBOX'.

ty_events-name = slis_ev_top_of_page.

ty_events-form = 'TOP_OF_PAGE'.

APPEND ty_events TO it_events.

ALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = v_repid

i_internal_tabname = 'ITAB'

i_inclname = v_repid

CHANGING

ct_fieldcat = build_fieldcatalog.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = v_repid

i_callback_pf_status_set = 'SET_PF_STATUS'

i_callback_user_command = 'USER_COMMAND'

i_structure_name = 'ITAB'

is_layout = s_layout

it_fieldcat = build_fieldcatalog[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

it_events = it_events

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = 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 user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

IF ucomm = 'DELE'.

LOOP AT iTAB WHERE CHECKbox = 'X' .

--

ENDLOOP.

MODIFY ztEST FROM TABLE itAB.

ENDIF.

selfield-refresh = 'X'.

ENDFORM.

NOW I HAVE A LIST O/P WHERE I CAN SELECT THE BOX AND CLICK DELETE ICON.

NOW I WANT TO CHANGE TO GRID, SO I KEPT EVERYTHING SAMRE AND I CHANGED " LIST" TO "GRID"

NOW TWO THINGS HAPPEND

1) I SEE A EMPTY COLUMN IN THE O/P , I GUESS THATS BECAUSE CHECKBOSX IN INTERNAL TABLE , SO I REMOVED IT

SO THIS MADE ME TO REMOVE

IF ucomm = 'DELE'.

LOOP AT iTAB." WHERE CHECKbox = 'X' .------PROBLEM

--

ENDLOOP.

MODIFY ztEST FROM TABLE itAB.

ENDIF.

selfield-refresh = 'X'.

NOW I DON'T SEE THE EMPTY COLUMN , BUT NOW PROBLEM IS I CANNNOT DISTINGUISH AS TO WHICH IS SELECTED AND AT ANY POINT OF TIME I CANSELECT ONLY ROW.

ALL I WANT IS

1) I WANT TO SELECT MULTIPLE ROWS AND SHOULD BE ABLE TO KNOW WHICH ROWS WERE SELECTED IN THE O/P SCREEN.

IN THE LIST DISPLAY I HAD CHECKBOX = 'X' FOR ALL THE ROWS THAT WERE SELECTED , I WANT THE SIMILAR THING in grid display

LET ME KNOW whether this can be done without USING 00 LANG.

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
927

Hi,

You can replace the FM name with GRID FM.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

In the output instead of check box you will be seeing the selectable button..

Press CTRL + Select button..Then you can select multiple rows..

THanks

Naren

7 REPLIES 7
Read only

Former Member
0 Likes
928

Hi,

You can replace the FM name with GRID FM.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

In the output instead of check box you will be seeing the selectable button..

Press CTRL + Select button..Then you can select multiple rows..

THanks

Naren

Read only

0 Likes
927

Hi NARENDRAN,

I did the exactly same what you told me to do and i removed the checkbox from my internal table.

now my question is , i am deleteing the selected rows , how would i know which rows where selected

let me know

thanks

Read only

Former Member
0 Likes
927

Hi,

You still require the check box field in your internal table...

So that if the rows are selected..Then those records will have CHECKBOX = 'X'

Thanks,

Naren

Read only

0 Likes
927

Hi narendran,

if i include checkbox in the intenal table,

iam seing an empty column at the last.

let me know thanks

Read only

0 Likes
927

Hi Narendran,

Thanks for the reply

if i include the box in my internal table then i see a empty column at the end but i hide that column when i select any row then checkbox is returned a value of 'X'.

LET ME KNOW IF IAM WRONG

I AWARDED FULL POINTS TO YOU

THANKS

Read only

Former Member
0 Likes
927

Hi,

Yes..If you don't display the checkbox column in the output..But if you give CHECKBOX in the layout-box_fieldname and have the CHECKBOX in the internal table ..Then you will see CHECKBOX = 'X' if the row is selected..

If you still are not able see the selected rows..Check the following code..

FORM user_command USING p_ucomm TYPE sy-ucomm

p_selfld TYPE slis_selfield.

CASE p_ucomm.

WHEN '&DATA_SAVE'.

DATA ref1 TYPE REF TO cl_gui_alv_grid.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

e_grid = ref1.

CALL METHOD ref1->check_changed_data.

LOOP AT itab WHERE checkbox = 'X'.

DELETE itab INDEX sy-tabix.

ENDLOOP.

p_selfld-refresh = 'X'.

ENDCASE.

ENDFORM. "user_command

Thanks,

Naren

Read only

Former Member
0 Likes
927

Hi Swati,

Below code might help full for you. Description: is It selects multiple rows from ALV and display it on the next ALV.

*************************Reward Point If help full********************************************


*&---------------------------------------------------------------------*
*& Report   z7cc_alv_oops_show_next_alv                                *
*&                                                                     *
*&---------------------------------------------------------------------*
*&          DEVELOPERS NAME : CHIDANAND CHAUHAN
*&          DATE: SATURDAY 08-07-2006

*&          DESCRIPTION: TO CREATE AN OBJECT ORIENTED ALV
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT      z7cc_alv_oops_show_next_alv MESSAGE-ID  z5hs .





DATA : BEGIN OF it_mara OCCURS 0,
  mark  TYPE flag,
  matnr TYPE matnr,
  mtart TYPE mtart,
  meins TYPE meins,
END OF it_mara.

DATA : BEGIN OF it_mara1 OCCURS 0,
*  mark  type flag,
  matnr TYPE matnr,
  mtart TYPE mtart,
  meins TYPE meins,
END OF it_mara1.

DATA : BEGIN OF it_mara2 OCCURS 0,
*  mark  type flag,
  matnr TYPE matnr,
  mtart TYPE mtart,
  meins TYPE meins,
END OF it_mara2.

DATA : t_fieldcat TYPE lvc_t_fcat,
         t_fieldcat1 TYPE lvc_t_fcat,

      s_fieldcat LIKE LINE OF t_fieldcat.

DATA : s_layout TYPE lvc_s_layo.

DATA : control TYPE REF TO cl_gui_custom_container,
       grid  TYPE REF TO cl_gui_alv_grid.


DATA: BEGIN OF wa ,
  mark  TYPE flag,
  matnr TYPE matnr,
  mtart TYPE mtart,
  meins TYPE meins,
END OF wa.

*---------------------------------------------------------------------*
*       CLASS lcl_events_box DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_events_box DEFINITION.

  PUBLIC SECTION.

    METHODS :

*Handler_Data_Changed for event Data_Changed of cl_gui_alv_grid
*imporTing er_data_changed,
*
    handler_user_command FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm,

    handler_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING e_object e_interactive.

ENDCLASS.                    "lcl_events_box DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_events_box IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_events_box IMPLEMENTATION.
* method to handle the user command.
  METHOD handler_user_command.
    PERFORM form_usercommand CHANGING e_ucomm.
  ENDMETHOD.                    "Handler_user_command
*& Mehod to handle the toolbar.
  METHOD handler_toolbar.
    PERFORM form_toolbar CHANGING e_object e_interactive
    e_object->mt_toolbar.
  ENDMETHOD.                    "Handler_ToolBar

ENDCLASS.                    "lcl_events_box IMPLEMENTATION

START-OF-SELECTION.
  DATA : w_events TYPE REF TO lcl_events_box.

  SELECT matnr mtart meins FROM mara INTO CORRESPONDING FIELDS OF TABLE
  it_mara.

  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  pbo_module  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE pbo_module OUTPUT.
  IF grid IS INITIAL.

    CREATE OBJECT control
      EXPORTING
        container_name     = 'CUST_CTRL'.


    CREATE OBJECT grid
      EXPORTING
        i_parent          = control.

    PERFORM build_catalog.

    PERFORM build_catalog1.

    PERFORM build_layout.

    CALL METHOD grid->set_table_for_first_display
      EXPORTING
        is_layout       = s_layout
      CHANGING
        it_outtab       = it_mara[]
        it_fieldcatalog = t_fieldcat.



    CREATE OBJECT w_events.
    SET HANDLER : w_events->handler_toolbar FOR grid,
                  w_events->handler_user_command FOR grid.

    CALL METHOD grid->set_toolbar_interactive.

  ELSE.
    CALL METHOD grid->refresh_table_display.


  ENDIF.
ENDMODULE.                 " pbo_module  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  BUILD_CATALOG

FORM build_catalog .

  s_fieldcat-col_pos = '1'.
  s_fieldcat-fieldname = 'MARK'.
  s_fieldcat-checkbox = 'X'.
  s_fieldcat-edit = 'X'.
  APPEND s_fieldcat TO t_fieldcat.
  CLEAR s_fieldcat.

  s_fieldcat-col_pos = '2'.
  s_fieldcat-fieldname = 'MATNR'.
  s_fieldcat-scrtext_m = 'MATERIAL'.
  APPEND s_fieldcat TO t_fieldcat.

  s_fieldcat-col_pos = '3'.
  s_fieldcat-fieldname = 'MTART'.
  s_fieldcat-scrtext_m = 'MATERL TYPE'.
  APPEND s_fieldcat TO t_fieldcat.

  s_fieldcat-col_pos = '4'.
  s_fieldcat-fieldname = 'MEINS'.
  s_fieldcat-scrtext_m = 'UOM'.
  APPEND s_fieldcat TO t_fieldcat.

ENDFORM.                    " BUILD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_layout .
  s_layout-zebra = 'X'.
* S_LAYOUT-CWIDTH_OPT = 'X'.
  s_layout-grid_title = 'Material Details'.
ENDFORM.                    "BUILD_LAYOUT
" BUILD_LAYOUT////////////////////////////////////
" USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  FORM_USERCOMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_E_UCOMM  text
*----------------------------------------------------------------------*
FORM form_usercommand  CHANGING p_e_ucomm.

  CASE p_e_ucomm.

    WHEN 'INT1'.

      DO.

        READ TABLE it_mara INDEX sy-index TRANSPORTING mark matnr.


        IF sy-subrc <> 0.

          EXIT.

        ENDIF.

        IF it_mara-mark = 'X'.

          READ TABLE it_mara INTO wa TRANSPORTING matnr mtart meins .
          MOVE-CORRESPONDING wa TO it_mara1.
          READ TABLE it_mara1 TRANSPORTING matnr mtart meins .
          MOVE-CORRESPONDING it_mara1  TO it_mara2.
          APPEND it_mara2.


          CALL METHOD grid->set_table_for_first_display
            EXPORTING
              is_layout       = s_layout
            CHANGING
              it_outtab       = it_mara2[]
              it_fieldcatalog = t_fieldcat1.
*
*       SET PARAMETER ID 'MAT' FIELD IT_MARA-MATNR.
*       CALL TRANSACTION 'MM02'.
          .
        ENDIF.
*      ENDIF.
      ENDDO.
  ENDCASE.
ENDFORM.                    " FORM_USERCOMMAND
*&---------------------------------------------------------------------*
*&      Form  FORM_TOOLBAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_E_OBJECT  text
*      <--P_E_INTERACTIVE  text
*      <--P_E_OBJECT_>MT_TOOLBAR  text
*----------------------------------------------------------------------*
FORM form_toolbar  CHANGING p_e_object TYPE REF TO
cl_alv_event_toolbar_set
p_e_interactive
mt_toolbar TYPE ttb_button.


  DATA wal_button TYPE stb_button.

*WAL_BUTTON-ICON = ICON_status_reverse.
  wal_button-text = 'GO'.
  wal_button-quickinfo = 'PROCEED'.
  wal_button-function = 'INT1'.
  wal_button-butn_type = 0.
  wal_button-disabled = space.
  INSERT wal_button  INTO p_e_object->mt_toolbar INDEX 1.

ENDFORM.                    " FORM_TOOLBAR
*&---------------------------------------------------------------------*
*&      Module  PF-STATUS  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE pf-status OUTPUT.

  SET PF-STATUS 'Z7CCSTAT'.

ENDMODULE.                 " PF-STATUS  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE sy-ucomm.


    WHEN 'BACK'.
      LEAVE PROGRAM.

    WHEN 'CANCEL'.
      LEAVE PROGRAM.


  ENDCASE.


ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  BUILD_CATALOG1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_catalog1 .

  s_fieldcat-col_pos = '1'.
  s_fieldcat-fieldname = 'MATNR'.
  s_fieldcat-scrtext_m = 'MATERIAL'.
  APPEND s_fieldcat TO t_fieldcat1.

  s_fieldcat-col_pos = '2'.
  s_fieldcat-fieldname = 'MTART'.
  s_fieldcat-scrtext_m = 'MATERL TYPE'.
  APPEND s_fieldcat TO t_fieldcat1.

  s_fieldcat-col_pos = '3'.
  s_fieldcat-fieldname = 'MEINS'.
  s_fieldcat-scrtext_m = 'UOM'.
  APPEND s_fieldcat TO t_fieldcat1.


ENDFORM.                    " BUILD_CATALOG1