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

Former Member
0 Kudos

Can anyone help me in creating an Object Oriented ALV?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Create a prog called ZR_COLORS and add this code.

Then create a screen 100 for prog ZR_COLORS and add a custom control called 'CUSTOM_GRID_CONTAINER'.

Run it.

REPORT ZR_Colors.

data: begin of i_vbak2 occurs 0.

include structure vbak.

data: end of i_vbak2.

data: begin of i_vbak occurs 0.

include structure vbak.

data: cellcolors type lvc_t_scol. " note that is an int table within

data: end of i_vbak. " an int table !!!

types: begin of r_vbak.

include structure vbak.

types: cellcolors type lvc_t_scol.

types: end of r_vbak.

data: i_vbak_out type table of r_vbak.

data: cellcolor type lvc_s_scol.

data: layout type LVC_S_LAYO.

data: grid1 type ref to cl_gui_alv_grid,

field_catalog type lvc_t_fcat,

grid1_container type ref to cl_gui_custom_container.

data: lt_fieldcat type LVC_T_FCAT.

data: wa_fieldcat type LVC_s_FCAT.

start-of-selection.

select * from vbak into table i_vbak2

where erdat > '20041201'

and erdat < '20041216'.

loop at i_vbak2.

move-corresponding i_vbak2 to i_vbak.

append i_vbak.

endloop.

layout-edit = 'X'.

layout-zebra = 'X'.

layout-cwidth_opt = 'X'.

  • Set first cell in Net value column.

read table i_vbak index 2.

cellcolor-fname = 'NETWR'.

cellcolor-color-col = '3'.

cellcolor-color-int = '1'.

cellcolor-NOKEYCOL = 'X'.

append cellcolor to i_vbak-cellcolors.

modify i_vbak index 2.

  • Set 2nd cell in Net value column.

read table i_vbak index 4.

cellcolor-fname = 'NETWR'.

cellcolor-color-col = '6'.

cellcolor-color-int = '1'.

cellcolor-NOKEYCOL = 'X'.

append cellcolor to i_vbak-cellcolors.

modify i_vbak index 4.

  • Identify the internal table name with the colors reference.

layout-CTAB_FNAME = 'CELLCOLORS'.

  • Instantiate the grid container.

create object grid1_container

exporting

container_name = 'CUSTOM_GRID_CONTAINER'.

  • Instantiate the grid itself within the container.

create object grid1

exporting

i_parent = grid1_container

i_appl_events = 'X'.

i_vbak_out[] = i_vbak[].

layout-frontend = 'E'.

data: lt_exclude type ui_functions.

data: r_exclude type ui_func.

r_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.

append r_exclude to lt_exclude.

  • Call method of grid1 class object to build/display the grid.

call method grid1->set_table_for_first_display

EXPORTING i_structure_name = 'VBAK'

  • IT_TOOLBAR_EXCLUDING = lt_exclude

is_layout = layout

changing

it_outtab = i_vbak_out.

  • it_fieldcatalog = lt_fieldcat.

call screen '0100'.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'E100'.

SET TITLEBAR '100'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

case sy-ucomm.

when 'EXIT' or 'BACK' or 'CANCEL'.

leave program.

endcase.

ENDMODULE. " USER_COMMAND_0100 INPUT

6 REPLIES 6

Former Member
0 Kudos

Create a prog called ZR_COLORS and add this code.

Then create a screen 100 for prog ZR_COLORS and add a custom control called 'CUSTOM_GRID_CONTAINER'.

Run it.

REPORT ZR_Colors.

data: begin of i_vbak2 occurs 0.

include structure vbak.

data: end of i_vbak2.

data: begin of i_vbak occurs 0.

include structure vbak.

data: cellcolors type lvc_t_scol. " note that is an int table within

data: end of i_vbak. " an int table !!!

types: begin of r_vbak.

include structure vbak.

types: cellcolors type lvc_t_scol.

types: end of r_vbak.

data: i_vbak_out type table of r_vbak.

data: cellcolor type lvc_s_scol.

data: layout type LVC_S_LAYO.

data: grid1 type ref to cl_gui_alv_grid,

field_catalog type lvc_t_fcat,

grid1_container type ref to cl_gui_custom_container.

data: lt_fieldcat type LVC_T_FCAT.

data: wa_fieldcat type LVC_s_FCAT.

start-of-selection.

select * from vbak into table i_vbak2

where erdat > '20041201'

and erdat < '20041216'.

loop at i_vbak2.

move-corresponding i_vbak2 to i_vbak.

append i_vbak.

endloop.

layout-edit = 'X'.

layout-zebra = 'X'.

layout-cwidth_opt = 'X'.

  • Set first cell in Net value column.

read table i_vbak index 2.

cellcolor-fname = 'NETWR'.

cellcolor-color-col = '3'.

cellcolor-color-int = '1'.

cellcolor-NOKEYCOL = 'X'.

append cellcolor to i_vbak-cellcolors.

modify i_vbak index 2.

  • Set 2nd cell in Net value column.

read table i_vbak index 4.

cellcolor-fname = 'NETWR'.

cellcolor-color-col = '6'.

cellcolor-color-int = '1'.

cellcolor-NOKEYCOL = 'X'.

append cellcolor to i_vbak-cellcolors.

modify i_vbak index 4.

  • Identify the internal table name with the colors reference.

layout-CTAB_FNAME = 'CELLCOLORS'.

  • Instantiate the grid container.

create object grid1_container

exporting

container_name = 'CUSTOM_GRID_CONTAINER'.

  • Instantiate the grid itself within the container.

create object grid1

exporting

i_parent = grid1_container

i_appl_events = 'X'.

i_vbak_out[] = i_vbak[].

layout-frontend = 'E'.

data: lt_exclude type ui_functions.

data: r_exclude type ui_func.

r_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.

append r_exclude to lt_exclude.

  • Call method of grid1 class object to build/display the grid.

call method grid1->set_table_for_first_display

EXPORTING i_structure_name = 'VBAK'

  • IT_TOOLBAR_EXCLUDING = lt_exclude

is_layout = layout

changing

it_outtab = i_vbak_out.

  • it_fieldcatalog = lt_fieldcat.

call screen '0100'.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'E100'.

SET TITLEBAR '100'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

case sy-ucomm.

when 'EXIT' or 'BACK' or 'CANCEL'.

leave program.

endcase.

ENDMODULE. " USER_COMMAND_0100 INPUT

Former Member
0 Kudos

Hi,

Go to Transaction DWDM. Here you will find demo programs for ALV Grid, Tree, Drag n Drop, HTML Containers, Splitter Containers using ABAP Object etc.

Also check out the package SLIS. It contains demo programs using ABAP Objects.

Reward points if the answer is helpful.

Regards,

Mukul

Former Member

Former Member

uwe_schieferstein
Active Contributor
0 Kudos

Hello Boddhu

Have a look at the following sample reports:

Sample report

You will find lots of sample reports dealing with ALV interaction (events) in the <u>ABAP Objects</u> forum (search for <b>ZUS_SDN)</b>.

Regards

Uwe

GrahamRobbo
Active Contributor
0 Kudos

Hi Bod,

load data into a suitable itab, then...

DATA: i_alv type ref to cl_salv_table.

cl_salv_table=>factory(
  IMPORTING
    r_salv_table = i_alv
  CHANGING
    t_table = wa_itab
  ).

i_alv->display( ).

Cheers

G