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

REGARDING INTERACTIVE ALV

Former Member
0 Likes
426

Hi..

Can anyone please send me the sample code for

Interactive ALV.

Regards

Sandeep

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
405

I've posted an easy sample program in this Forum.

Particularly if you are NEW to ALV DO NOT USE THE OLD SLIS MODULES as shown in this thread.

IT IS MUCH EASIER to use the new CL_GUI_ALV_GRID class and OO -- this is how it will be done in future anyway as the older Function modules will be deprecated (rendered obsolete) in the not too distant future.

just in case you can't find the original thread here's the code again.

Create a standard screen (SE51) with just one element on it a custom control called CCONTAINER1.

Create also a standard status (SE41) with standard BACK EXIT and CANCEL buttons on it.

Now code something like this -- this program reads some entries from VAPMA and displays as a simple editable grid.

You can insert and delete lines via the standard GRID functionality on the toolbar.

For more complex handling you can add events etc etc.



Program ZZZ_SIMPLE_EDITABLE_GRID.

* Define any structure
types:  begin of s_elements,
  vbeln   type vapma-vbeln,
  posnr   type vapma-posnr,
  matnr   type vapma-matnr,
  kunnr   type vapma-kunnr,
  werks   type vapma-werks,
  vkorg   type vapma-vkorg,
  vkbur   type vapma-vkbur,
  status  type c,

end of  s_elements.

* end of your structure

data lr_rtti_struc type ref to cl_abap_structdescr .
data:
    zog                     like line of lr_rtti_struc->components .
  data:
    zogt                    like table of zog,
  wa_it_fldcat type lvc_s_fcat,
  it_fldcat type lvc_t_fcat ,
  dy_line            type ref to data,
  dy_table           type ref to data.


 data:  dref               type ref to data.
 field-symbols: <fs> type any,
    <dyn_table>    type  standard table,
    <dyn_wa>.

data grid_container1 type ref to cl_gui_custom_container .
  data grid1 type ref to cl_gui_alv_grid .
data: ok_code type sy-ucomm.
data: STRUCT_GRID_LSET type lvc_s_layo.
*now I want to build a field catalog
* First get your data structure into a field symbol
create data dref type s_elements.
  assign dref->* to <fs>.

  lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).

    zogt[]  = lr_rtti_struc->components.
 loop at zogt into zog.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype = zog-type_kind.
      wa_it_fldcat-inttype = zog-type_kind.
      wa_it_fldcat-intlen = zog-length.
      wa_it_fldcat-decimals = zog-decimals.
      wa_it_fldcat-coltext = zog-name.
      wa_it_fldcat-lowercase = 'X'.
      append wa_it_fldcat to it_fldcat .
    endloop.
* Let's create a dynamic table and populate it

call method cl_alv_table_create=>create_dynamic_table
       exporting
            it_fieldcatalog = it_fldcat
       importing
            ep_table = dy_table.


assign dy_table->* to <dyn_table>.
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

  select vbeln posnr matnr kunnr werks vkorg vkbur
         up to 200 rows
         from vapma
         into  corresponding fields of table <dyn_table>.
call screen 100.

module status_0100 output.

if grid_container1 is initial.
create object grid_container1
        exporting
           container_name = 'CCONTAINER1'.
    create object  grid1
       exporting
          i_parent = grid_container1.
  struct_grid_lset-edit = 'X'.    "To enable editing in ALV

call method grid1->set_table_for_first_display
  exporting is_layout =  struct_grid_lset
  changing
             it_outtab       = <dyn_table>
             it_fieldcatalog = it_fldcat.


endif.
set pf-status '001'.
     set titlebar '000'.

endmodule.

  MODULE user_command_0100 INPUT.
      case sy-ucomm.
    when 'BACK'.
      leave program.
    when 'EXIT'.
      leave program.
    when 'RETURN'.
      leave program.
    when others.
  endcase.
endmodule.

Cheers

jimbo

2 REPLIES 2
Read only

Former Member
0 Likes
405

hi,

try like this

&----


*& Report ZINT_ALV

*&

&----


*&

*&

&----


REPORT zint_alv.

TYPE-POOLS:slis.

TABLES:mara,

makt,

mseg.

DATA:BEGIN OF itab OCCURS 0,

matnr LIKE mara-matnr,

maktx LIKE makt-maktx,

END OF itab.

DATA:BEGIN OF itab1 OCCURS 0,

mblnr LIKE mseg-mblnr,

menge LIKE mseg-menge,

meins LIKE mseg-meins,

werks LIKE mseg-werks,

END OF itab1.

DATA:BEGIN OF itab2 OCCURS 0,

mblnr LIKE mseg-mblnr,

budat LIKE mkpf-budat,

END OF itab2.

DATA:fcat TYPE slis_t_fieldcat_alv,

fcat1 TYPE slis_t_fieldcat_alv,

fcat2 TYPE slis_t_fieldcat_alv,

eve TYPE slis_t_event,

eve1 TYPE slis_t_event.

DATA:t_mat LIKE mara-matnr,

t_doc LIKE mseg-mblnr,

s_mat LIKE mara-matnr,

g_repid LIKE sy-repid,

subtot TYPE slis_t_sortinfo_alv,

g_subtot LIKE LINE OF subtot.

SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS:mat FOR mara-matnr OBLIGATORY.

SELECTION-SCREEN:END OF BLOCK blk1.

INITIALIZATION.

PERFORM build_fcat USING fcat.

PERFORM build_eve.

START-OF-SELECTION.

PERFORM get_data.

PERFORM dis_data.

&----


*& Form build_fcat

&----


  • text

----


  • -->T_FCAT text

----


FORM build_fcat USING t_fcat TYPE slis_t_fieldcat_alv.

DATA:wa_fcat TYPE slis_fieldcat_alv.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-ref_fieldname = 'MATNR'.

wa_fcat-ref_tabname = 'MARA'.

wa_fcat-seltext_m = 'Material'.

  • wa_fcat-input = ' '.

  • wa_fcat-edit = 'X'.

wa_fcat-input = 'X'.

  • wa_fcat-key = 'X'.

APPEND wa_fcat TO t_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MAKTX'.

wa_fcat-seltext_m = 'Description'.

APPEND wa_fcat TO t_fcat.

CLEAR wa_fcat.

ENDFORM. "build_fcat

&----


*& Form build_eve

&----


  • text

----


FORM build_eve.

DATA:t_eve TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = eve

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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. "build_eve

&----


*& Form get_data

&----


  • text

----


FORM get_data.

SELECT maramatnr maktmaktx INTO CORRESPONDING FIELDS OF TABLE itab

FROM mara INNER JOIN makt

ON maramatnr = maktmatnr

WHERE mara~matnr IN mat.

ENDFORM. "get_data

&----


*& Form dis_data

&----


  • text

----


FORM dis_data.

g_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid "'ZINT_ALV'

i_callback_user_command = 'USER_COMMAND'

i_grid_title = 'Interactive ALV'

it_fieldcat = fcat

it_events = eve

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.

ENDFORM. "dis_data

&----


*& Form user_command

&----


  • text

----


  • -->U_COM text

----


FORM user_command USING u_com LIKE sy-ucomm sel_field TYPE slis_selfield.

CLEAR fcat1.

CASE u_com.

WHEN '&IC1'.

READ TABLE itab INDEX sel_field-tabindex.

IF sel_field-fieldname = 'MATNR'.

IF sy-subrc = 0.

t_mat = itab-matnr.

PERFORM build_cat1 USING fcat1.

PERFORM build_eve1.

PERFORM get_data1.

PERFORM dis_data1.

ENDIF.

ENDIF.

  • SET PARAMETER ID 'MAT' FIELD t_mat.

  • CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

ENDCASE.

ENDFORM. "user_command

&----


*& Form build_fcat1

&----


  • text

----


  • -->T_FCAT1 text

----


FORM build_cat1 USING t_fcat1 TYPE slis_t_fieldcat_alv.

DATA:wa_fcat1 TYPE slis_fieldcat_alv.

wa_fcat1-tabname = 'ITAB1'.

wa_fcat1-fieldname = 'MBLNR'.

wa_fcat1-seltext_m = 'Material Doc.'.

APPEND wa_fcat1 TO t_fcat1.

CLEAR wa_fcat1.

wa_fcat1-tabname = 'ITAB1'.

wa_fcat1-fieldname = 'MENGE'.

wa_fcat1-seltext_m = 'Quantity'.

wa_fcat1-do_sum = 'X'.

APPEND wa_fcat1 TO t_fcat1.

CLEAR wa_fcat1.

wa_fcat1-tabname = 'ITAB1'.

wa_fcat1-fieldname = 'MEINS'.

wa_fcat1-seltext_m = 'UOM'.

APPEND wa_fcat1 TO t_fcat1.

CLEAR wa_fcat1.

wa_fcat1-tabname = 'ITAB1'.

wa_fcat1-fieldname = 'WERKS'.

wa_fcat1-seltext_m = 'Plant'.

APPEND wa_fcat1 TO t_fcat1.

CLEAR wa_fcat1.

  • g_subtot-spos = 1.

  • g_subtot-fieldname = 'MBLNR'.

  • g_subtot-tabname = 'ITAB1'.

  • g_subtot-up = 'X'.

  • g_subtot-group = 'X'.

  • g_subtot-subtot = 'X'.

  • g_subtot-expa = 'X'.

  • APPEND g_subtot TO subtot.

*

*

  • g_subtot-spos = 2.

  • g_subtot-fieldname = 'MENGE'.

  • g_subtot-tabname = 'ITAB1'.

  • g_subtot-up = 'X'.

  • g_subtot-group = 'X'.

  • g_subtot-subtot = 'X'.

  • g_subtot-expa = 'X'.

  • APPEND g_subtot TO subtot.

ENDFORM. "build_fcat1

&----


*& Form build_eve1

&----


  • text

----


FORM build_eve1.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = eve1

EXCEPTIONS

list_type_wrong = 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. "build_eve1

&----


*& Form get_data1

&----


  • text

----


FORM get_data1.

SELECT mblnr menge meins werks FROM mseg

INTO CORRESPONDING FIELDS OF TABLE itab1

WHERE matnr = t_mat.

ENDFORM. "get_data1

&----


*& Form dis_data1

&----


  • text

----


FORM dis_data1.

g_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid "'ZINT_ALV'

i_callback_user_command = 'USER_COMMAND1'

it_fieldcat = fcat1

it_events = eve1

i_save = 'A'

it_sort = subtot

TABLES

t_outtab = itab1

  • 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. "dis_data1

&----


*& Form user_command1

&----


  • text

----


  • -->U_COM1 text

  • -->SEL_FIELD text

----


FORM user_command1 USING u_com1 LIKE sy-ucomm sel_field TYPE slis_selfield.

CASE u_com1.

WHEN '&IC1'.

READ TABLE itab1 INDEX sel_field-tabindex.

IF sy-subrc = 0.

t_doc = itab1-mblnr.

PERFORM build_cat2 USING fcat2.

PERFORM get_data2.

PERFORM dis_data2.

ENDIF.

ENDCASE.

ENDFORM. "user_command

&----


*& Form build_cat2

&----


  • text

----


  • -->P_FCAT1 text

----


FORM build_cat2 USING t_fcat2 TYPE slis_t_fieldcat_alv.

DATA:wa_fcat2 TYPE slis_fieldcat_alv.

wa_fcat2-tabname = 'ITAB2'.

wa_fcat2-fieldname = 'MBLNR'.

wa_fcat2-seltext_m = 'Material Doc.'.

APPEND wa_fcat2 TO t_fcat2.

CLEAR wa_fcat2.

wa_fcat2-tabname = 'ITAB2'.

wa_fcat2-fieldname = 'BUDAT'.

wa_fcat2-seltext_m = 'Material Date'.

APPEND wa_fcat2 TO t_fcat2.

CLEAR wa_fcat2.

ENDFORM. " build_cat2

&----


*& Form get_data2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data2 .

SELECT mblnr budat FROM mkpf

INTO CORRESPONDING FIELDS OF TABLE itab2

WHERE mblnr = t_doc.

ENDFORM. " get_data2

&----


*& Form dis_data2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM dis_data2 .

g_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid "'ZINT_ALV'

it_fieldcat = fcat2

i_save = 'A'

TABLES

t_outtab = itab2

  • 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. " dis_data2

reward if useful...

Read only

Former Member
0 Likes
406

I've posted an easy sample program in this Forum.

Particularly if you are NEW to ALV DO NOT USE THE OLD SLIS MODULES as shown in this thread.

IT IS MUCH EASIER to use the new CL_GUI_ALV_GRID class and OO -- this is how it will be done in future anyway as the older Function modules will be deprecated (rendered obsolete) in the not too distant future.

just in case you can't find the original thread here's the code again.

Create a standard screen (SE51) with just one element on it a custom control called CCONTAINER1.

Create also a standard status (SE41) with standard BACK EXIT and CANCEL buttons on it.

Now code something like this -- this program reads some entries from VAPMA and displays as a simple editable grid.

You can insert and delete lines via the standard GRID functionality on the toolbar.

For more complex handling you can add events etc etc.



Program ZZZ_SIMPLE_EDITABLE_GRID.

* Define any structure
types:  begin of s_elements,
  vbeln   type vapma-vbeln,
  posnr   type vapma-posnr,
  matnr   type vapma-matnr,
  kunnr   type vapma-kunnr,
  werks   type vapma-werks,
  vkorg   type vapma-vkorg,
  vkbur   type vapma-vkbur,
  status  type c,

end of  s_elements.

* end of your structure

data lr_rtti_struc type ref to cl_abap_structdescr .
data:
    zog                     like line of lr_rtti_struc->components .
  data:
    zogt                    like table of zog,
  wa_it_fldcat type lvc_s_fcat,
  it_fldcat type lvc_t_fcat ,
  dy_line            type ref to data,
  dy_table           type ref to data.


 data:  dref               type ref to data.
 field-symbols: <fs> type any,
    <dyn_table>    type  standard table,
    <dyn_wa>.

data grid_container1 type ref to cl_gui_custom_container .
  data grid1 type ref to cl_gui_alv_grid .
data: ok_code type sy-ucomm.
data: STRUCT_GRID_LSET type lvc_s_layo.
*now I want to build a field catalog
* First get your data structure into a field symbol
create data dref type s_elements.
  assign dref->* to <fs>.

  lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).

    zogt[]  = lr_rtti_struc->components.
 loop at zogt into zog.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype = zog-type_kind.
      wa_it_fldcat-inttype = zog-type_kind.
      wa_it_fldcat-intlen = zog-length.
      wa_it_fldcat-decimals = zog-decimals.
      wa_it_fldcat-coltext = zog-name.
      wa_it_fldcat-lowercase = 'X'.
      append wa_it_fldcat to it_fldcat .
    endloop.
* Let's create a dynamic table and populate it

call method cl_alv_table_create=>create_dynamic_table
       exporting
            it_fieldcatalog = it_fldcat
       importing
            ep_table = dy_table.


assign dy_table->* to <dyn_table>.
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

  select vbeln posnr matnr kunnr werks vkorg vkbur
         up to 200 rows
         from vapma
         into  corresponding fields of table <dyn_table>.
call screen 100.

module status_0100 output.

if grid_container1 is initial.
create object grid_container1
        exporting
           container_name = 'CCONTAINER1'.
    create object  grid1
       exporting
          i_parent = grid_container1.
  struct_grid_lset-edit = 'X'.    "To enable editing in ALV

call method grid1->set_table_for_first_display
  exporting is_layout =  struct_grid_lset
  changing
             it_outtab       = <dyn_table>
             it_fieldcatalog = it_fldcat.


endif.
set pf-status '001'.
     set titlebar '000'.

endmodule.

  MODULE user_command_0100 INPUT.
      case sy-ucomm.
    when 'BACK'.
      leave program.
    when 'EXIT'.
      leave program.
    when 'RETURN'.
      leave program.
    when others.
  endcase.
endmodule.

Cheers

jimbo