Application Development 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: 

ALV functions

Former Member
0 Kudos

HELLO experts,

i want to display using ALV

can you please tell me how to do to make the two first columns fix , and how to delete a line when i display my alv, of course i've already implment the 'delete' icon on the tool bar but i don't know to connect the event of clicking in this button with the good 'method' .

thank you a lot for help me.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

First tell me how u r creating ALV,using classes or Function Modules.If u r using Function modules then in the Fieldcatalog there is a field called 'Key',make this field as 'X' then the corresponding field will be u r Key field and will not scroll.Like


  LOOP AT T_FLDCAT INTO W_FLDCAT.

    IF W_FLDCAT-FIELDNAME EQ 'ZVER' OR W_FLDCAT-FIELDNAME EQ 'ZSNO'.

      W_FLDCAT-KEY = 'X'.
      W_FLDCAT-FIX_COLUMN = 'X'.
      W_FLDCAT-LZERO = 'X'.

      MODIFY T_FLDCAT FROM W_FLDCAT.

    ENDIF.
ENDLOOP.

As far as deleting of the records after clicking a button from toolbar,then you need o write the following in your usercommand routine :


FORM USERCOMMAND USING R_UCOMM TYPE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.

  DATA: GD_REPID LIKE SY-REPID, "Exists
  REF_GRID TYPE REF TO CL_GUI_ALV_GRID.

  DATA: L_VALID TYPE C.

*Code to reflect the changes done in the internal table

  IF REF_GRID IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        E_GRID = REF_GRID.
  ENDIF.

  IF NOT REF_GRID IS INITIAL.

    CALL METHOD REF_GRID->CHECK_CHANGED_DATA
      IMPORTING
        E_VALID = L_VALID.

  ENDIF.

CASE R_UCOMM.

WHEN 'DEL'.     "When clicked on Delete button

Loop at IT_FINAL WHERE CHK = 'X'. " CHK is the chekcbox checked to delete the record

DELETE IT_FINAL[] FROM IT_FINAL.

ENDLOOP.

ENDCASE.

ENDFORM.

8 REPLIES 8

Former Member
0 Kudos

Handle it using i_callback_user_command in grid display if any issues reply

Former Member
0 Kudos

Hi,

Handle it using user_command in grid display

Former Member
0 Kudos

Hi,

First tell me how u r creating ALV,using classes or Function Modules.If u r using Function modules then in the Fieldcatalog there is a field called 'Key',make this field as 'X' then the corresponding field will be u r Key field and will not scroll.Like


  LOOP AT T_FLDCAT INTO W_FLDCAT.

    IF W_FLDCAT-FIELDNAME EQ 'ZVER' OR W_FLDCAT-FIELDNAME EQ 'ZSNO'.

      W_FLDCAT-KEY = 'X'.
      W_FLDCAT-FIX_COLUMN = 'X'.
      W_FLDCAT-LZERO = 'X'.

      MODIFY T_FLDCAT FROM W_FLDCAT.

    ENDIF.
ENDLOOP.

As far as deleting of the records after clicking a button from toolbar,then you need o write the following in your usercommand routine :


FORM USERCOMMAND USING R_UCOMM TYPE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.

  DATA: GD_REPID LIKE SY-REPID, "Exists
  REF_GRID TYPE REF TO CL_GUI_ALV_GRID.

  DATA: L_VALID TYPE C.

*Code to reflect the changes done in the internal table

  IF REF_GRID IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        E_GRID = REF_GRID.
  ENDIF.

  IF NOT REF_GRID IS INITIAL.

    CALL METHOD REF_GRID->CHECK_CHANGED_DATA
      IMPORTING
        E_VALID = L_VALID.

  ENDIF.

CASE R_UCOMM.

WHEN 'DEL'.     "When clicked on Delete button

Loop at IT_FINAL WHERE CHK = 'X'. " CHK is the chekcbox checked to delete the record

DELETE IT_FINAL[] FROM IT_FINAL.

ENDLOOP.

ENDCASE.

ENDFORM.

I355602
Advisor
Advisor
0 Kudos

Hi,

Take a field in the internal table as chk(1) type c with all the other fields. And while defining the field catalogs declare chk as checkbox.


  wa_field-fieldname = 'CHK'.
  wa_field-tabname = 'IT_FINAL'.
  wa_field-outputlen = 1.
  wa_field-seltext_l = ' '.
  wa_field-checkbox = 'X'.  "to display as checkbox
  wa_field-input = 'X'.
  wa_field-edit = 'X'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

Use code:-


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = sy-repid
      IT_FIELDCAT              = it_field
      i_callback_user_command  = 'COMMAND'
      IS_LAYOUT                = wa_layout
      i_callback_pf_status_set = 'PF'
    TABLES
      T_OUTTAB                 = it_final
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  command
*&---------------------------------------------------------------------*
*       TO HANDLE USER ACTIONS AGAINST PF-STATUS
*----------------------------------------------------------------------*
*      -->UCOMM      text
*      -->SELFIELD   text
*----------------------------------------------------------------------*
FORM command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
  DATA : ok_code TYPE sy-ucomm.
  ok_code = ucomm.
  CASE ok_code.
    when 'DELETE'.
      " to reflect the data changed into internal table
      DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new

      IF ref_grid IS INITIAL.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            e_grid = ref_grid.
      ENDIF.

      IF NOT ref_grid IS INITIAL.
        CALL METHOD ref_grid->check_changed_data.
      ENDIF.
      
      " at this moment you have internal table modified

      sort it_final by chk descending.
      "delete selected records
      delete it_final where chk = 'X'.

      "refresh data back from internal table to alv grid
      selfield-refresh = 'X'.

  ENDCASE.
ENDFORM.                    "command

Hope this helps you.

Regards,

Tarun

sarbajitm
Contributor
0 Kudos

Just right click on the column you want to fix then click on Freeze to column option.

0 Kudos

1)First keep a checkbox in your ALV display so that you can mark the row that you wan to delete.

to do so what you have to do is keep a field like below in your final ITAB that you want to ALVdisplay.

BEGIN OF T_final ,

chk(1) TYPE c, for making checkbox..

............

..............

END OF T_final.

2) Then when you create the field catalog for the checkbox(chk field of your ITAB)

write down the following code

WA_fieldcat-fieldname = 'CHK'.

WA_fieldcat-seltext_m = 'CheckBox'.

WA_fieldcat-checkbox = 'X'.

WA_fieldcat-edit = 'X' .

WA_fieldcat-input = 'X'.

WA_fieldcat-tabname = 'IT_FINAL'.

WA_fieldcat-col_pos = 1.

APPEND WA_fieldcat TO IT_fieldcat.

CLEAR WA_fieldcat.

3) Declare a data at your data section of the report

DATA : lc_s_glay TYPE lvc_s_glay.

then before calling REUSE_ALV_GRID_DISPLAY

just write down the following piece of code

lc_s_glay-edt_cll_cb = 'X'.

In the REUSE_ALV_GRID_DISPLAY FM

you must set the follwing 2 Exporting Parameter

i) i_callback_user_command = 'USER_COMMAND'

ii) i_grid_settings = lc_s_glay

for i) write down the following subroutine........

FORM user_command USING I_r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

DATA: l_out_string TYPE string,

l_out_final TYPE ekpo-menge,

l_cntr TYPE i.

CASE I_r_ucomm.

WHEN 'DEL1'. assuming your Fcode

delete from itab where chk = 'X'.

ENDCASE.

ENDFORM.

hope it solve your problem.

Edited by: Sarbajit Majumdar on Mar 10, 2009 4:50 PM

Edited by: Sarbajit Majumdar on Mar 10, 2009 4:50 PM

Edited by: Sarbajit Majumdar on Mar 10, 2009 4:51 PM

Edited by: Sarbajit Majumdar on Mar 10, 2009 4:51 PM

Edited by: Sarbajit Majumdar on Mar 10, 2009 4:52 PM

Edited by: Sarbajit Majumdar on Mar 10, 2009 4:53 PM

sarbajitm
Contributor
0 Kudos

Hi Assistance MAP,

are you still watching this thread? Are not you get the answer ? Please mark the thread as ANSWERED if you get your desired answer. Otherwise keep posting the difficulties you are still facing. Can try to give the solution.

Thanks and Regards.

Sarbajit

sarbajitm
Contributor
0 Kudos

Hi Assistance MAP,

are you still watching this thread? Are not you get the answer ? Please mark the thread as ANSWERED if you get your desired answer. Otherwise keep posting the difficulties you are still facing. Can try to give the solution.

Thanks and Regards.

Sarbajit