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

ALV

Former Member
0 Likes
703

hi,

can any one help me to understand with a sample code of ALV grid in ABAP OBJECTS.

i would appreciate all ur answers.

thanks,

ganesh

hi,

can any one help me to understand with a sample code of ALV grid in ABAP OBJECTS.

i would appreciate all ur answers.

thanks,

ganesh

6 REPLIES 6
Read only

LucianoBentiveg
Active Contributor
0 Likes
670

Go to transacion ABAPDOCU.

Regards,

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
670

CHeck any program that starts with BCALV*

Regards,

Rich Heilman

Read only

0 Likes
670

See transaction DWDM too, there is several examples.

Regards.

Read only

Former Member
0 Likes
670

Hi,

Check the program BCALV_GRID_EDIT

Thanks,

Naren

Read only

Former Member
0 Likes
670

Hi,

The general procedure is as explained below...

SAP has provided different controls catering needs of various applications. One such control is ALV Grid Control.

A control as such cannot be called directly for output display. A control should be attached to a Container. SAP provided different types of containers namely CUstom Container, Split Container, Dialog COntainer etc....

The attributes of the container can be accessed by instantiating the Container class. For our purpose consider the CUSTOM CONTAINER. The custom container class is CL_GUI_CUSTOM_CONTAINER

The attributes and methods of ALV Grid can be accessed by instantiating the Grid Class CL_GUI_ALV_GRID.

After assigning the grid to the container, Field catalog for the output is prepared. Display method of Gird Control is called to display the output.

Check the below code... This is SAP standard program

<b>start-of-selection.</b>

select * from sflight into table gt_sflight up to g_max rows.

*

<b>end-of-selection.</b>

g_repid = sy-repid.

call screen 100.

----


  • MODULE PBO OUTPUT *

----


module pbo output.

<b>* Set the PF Status</b>

set pf-status 'MAIN100'.

set titlebar 'MAIN100'.

<b>* Create a Custom Area in SAP Screen. If the Custom container is initial then instantiate the Container class</b>

if custom_container is initial.

<b>* create a custom container control for our ALV Control</b>

create object custom_container

exporting

container_name = mycontainer

exceptions

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

if sy-subrc ne 0.

<b>* add your handling, for example</b>

call function 'POPUP_TO_INFORM'

exporting

titel = g_repid

txt2 = sy-subrc

txt1 = 'The control could not be created'(010).

endif.

<b>* Instantiate the GRid Class. create an instance of alv control</b>

create object grid1

exporting i_parent = custom_container.

*

  • Set a titlebar for the grid control

*

gs_layout-grid_title = 'Flights'(100).

<b>* Build the field catalog for output display</b>

call method grid1->set_table_for_first_display

exporting i_structure_name = 'SFLIGHT'

changing IT_FIELDCATALOG = gt_fldcat

it_outtab = gt_sflight.

endif.

<b>* Controls are not integrated into the TAB-Order

  • Call "set_focus" if you want to make sure that 'the cursor'

  • is active in your control.</b>

call method cl_gui_control=>set_focus exporting control = grid1.

  • Control Framework flushes at the end of PBO automatically!

endmodule.

----


  • MODULE PAI INPUT *

----


module pai input.

case ok_code.

when 'EXIT'.

perform exit_program.

endcase.

clear ok_code.

endmodule.

----


  • FORM EXIT_PROGRAM *

----


form exit_program.

call method custom_container->free.

call method cl_gui_cfw=>flush.

if sy-subrc ne 0.

  • add your handling, for example

call function 'POPUP_TO_INFORM'

exporting

titel = g_repid

txt2 = sy-subrc

txt1 = 'Error in Flush'(009).

endif.

leave program.

endform.

For other examples,

check these programs

BCALV_GRID_01

BCALV_GRID_02

BCALV_GRID_03

BCALV_GRID_04

BCALV_GRID_05

BCALV_GRID_06

BCALV_GRID_07

BCALV_GRID_08

BCALV_GRID_09

BCALV_GRID_10

BCALV_GRID_11

Regards,

Vara

Read only

former_member199581
Active Participant
0 Likes
670

If you are on at least WAS 640 you can use class CL_SALV_TABLE.

It is very very simple.

For example, this few lines creates an ALV output:

data: gt_outtab type table of SFLIGHT.

data: gr_table type ref to cl_salv_table.

*... Select data

select * from SFLIGHT into corresponding fields of table gt_outtab.

*... Create Instance

call method cl_salv_table=>factory

IMPORTING

R_SALV_TABLE = gr_table

changing

t_table = gt_outtab.

*... Display table

gr_table->display( ).

However, check programs that starts with SALV_*

Hope this helps,

Roby.