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 using object oriented concept.

former_member530652
Participant
0 Kudos

Plz send me simple code that will display ALV grid list as an output using object oriented concept.

6 REPLIES 6

former_member386202
Active Contributor
0 Kudos

Hi,

Goto SE38 give BCALV* n press F4 it will display the list of all standard ALV OOps programs Refer that.

Regards,

Prashant

Lakshmant1
Active Contributor
0 Kudos

Hi sandeep,

Have a look at std program BCALV_TEST_GRID. Also look at programs under package SLIS.

Hope this helps.

Thanks

Lakshman

0 Kudos

Hi friends;

I tried one ALV Report Program.,Based on the input ,various storage location value will be dispalyed...

example : i will(statically) generate 30 output fields using filed catalog .

based on input, in 30 fields

some of the fields the value will be dispalyed..

remains the fields the value will be un filled.

i want to generate the fields dynamically, only the fields having values....

i searching the document in net ,using field symbol it may possible... but i not having idea in field symbol....

PLZ help me....

my mail id

k.s.kannan@numericups.com

Best regards

K.S.Kannan.

Former Member
0 Kudos

Hi Sandeep,

http://help.sap.com/saphelp_nw04/helpdata/en/5e/88d440e14f8431e10000000a1550b0/frameset.htm

Check this Shortest Program to display the ALV GRID using class

BCALV_GRID_DEMO

******************************

Check these links.

Check this for basic concepts of OOPS

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b6cae890-0201-0010-ef8b-f970a9c4...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1591ec90-0201-0010-3ba8-cdcd500b...

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Tabstrip

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/022ba607-0301-0010-e382-fdedca55...

Editable ALV

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ec31e990-0201-0010-f4b6-c02d876c...

Tree

http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_usrint.htm

General Tutorial for OOPS

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a41...

standard pgms

ABAP_OBJECTS_ENJOY_0 Template for Solutions of ABAP Object Enjoy Course

ABAP_OBJECTS_ENJOY_1 Model Solution 1: ABAP Objects Enjoy Course

ABAP_OBJECTS_ENJOY_2 Model Solution 2: ABAP Objects Enjoy Course

ABAP_OBJECTS_ENJOY_3 Model Solution 3: ABAP Objects Enjoy Course

ABAP_OBJECTS_ENJOY_4 Model Solution 4: ABAP Objects Enjoy Course

ABAP_OBJECTS_ENJOY_5 Model Solution 5: ABAP Objects Enjoy Course

DEMO_ABAP_OBJECTS Complete Demonstration for ABAP Objects

DEMO_ABAP_OBJECTS_CONTROLS GUI Controls on Screen

DEMO_ABAP_OBJECTS_EVENTS Demonstration of Events in ABAP Objects

DEMO_ABAP_OBJECTS_GENERAL ABAP Objects Demonstration

DEMO_ABAP_OBJECTS_INTERFACES Demonstration of Interfaces in ABAP Objects

DEMO_ABAP_OBJECTS_METHODS Demonstration of Methods in ABAP Objects

DEMO_ABAP_OBJECTS_SPLIT_SCREEN Splitter Control on Screen

some helful links.

Go through the below links,

For Materials:

1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291

2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf

4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf

5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt

6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf

7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt

😎 http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8

1) http://www.erpgenie.com/sap/abap/OO/index.htm

2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

Kindly Reward Points If You Find The Reply Helpful.

Cheers,

Chaitanya.

Former Member
0 Kudos

hi

good

go to se38

put BCALV* and press F4,

You ll get lots of reports related to OO ALV, Pls go through them , it ll help y ou a lot .

check this link for a sample program

http://abapprogramming.blogspot.com/2007/11/alv-list-using-oo-style-sample-code.html

thanks

mrutyun^

Edited by: Mrutyunjaya Tripathy on Dec 20, 2007 3:42 PM

former_member402443
Contributor
0 Kudos

Hi Sandeep,

Check these code.here i am sending two programs.

If you are using the class cl_gui_alv_grid then you have to create a screen that containing the custom container.

If you are using the class cl_salv_table then don't need to define any custom container for getting the ALV grid.

Here I am copying the Example of both the classes .

Now its all depends upon you which class you prefer to use.

Example 1 : cl_gui_alv_grid

*

o

+ Global data definitions for ALV

  1. ALV Grid instance reference

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .

*

o

+

  1. Name of the custom control added on the screen

DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' .

*

o

+

  1. Custom container instance reference

DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .

*

o

+

  1. Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*

o

+

  1. Layout structure

DATA gs_layout TYPE lvc_s_layo .

*

o

+

  1. Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

*--In further sections, some additional fields will added here

*--for some functionality

DATA END OF gt_list .

DATA :gt_sflight like standard TABLE OF gt_list.

START-OF-SELECTION.

CALL SCREEN '0400'.

&----


*& Module STATUS_0400 OUTPUT

&----


  • text

-


MODULE STATUS_0400 OUTPUT.

SET PF-STATUS 'ZMNU'.

perform display_alv.

ENDMODULE. " STATUS_0400 OUTPUT

&----


*& Module USER_COMMAND_0400 INPUT

&----


  • text

-


MODULE USER_COMMAND_0400 INPUT.

CASE SY-UCOMM.

WHEN 'BACK' OR 'EXIT' OR 'RW'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0400 INPUT

&----


*& Form display_alv

&----


  • text

-


form display_alv.

SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT UP TO 30 ROWS.

IF gr_alvgrid IS INITIAL .

*----Creating custom container instance

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = gc_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6 .

IF sy-subrc 0.

  • --Exception handling

ENDIF.

*----Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

others = 5 .

IF sy-subrc 0.

  • *--Exception handling

ENDIF.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

*----Here will be additional preparations

*--e.g. initial sorting criteria, initial filtering criteria, excluding

*--functions

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_STRUCTURE_NAME = 'SFLIGHT'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

is_layout = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

CHANGING

it_outtab = gt_sflight[]

it_fieldcatalog = gt_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4 .

IF sy-subrc 0.

  • --Exception handling

ENDIF.

ELSE .

CALL METHOD gr_alvgrid->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

finished = 1

OTHERS = 2 .

IF sy-subrc 0.

*--Exception handling

ENDIF.

ENDIF .

endform. "display_alv

&----


*& Form prepare_field_catalog

&----


  • text

-


  • -->PT_FIELDCATtext

-


FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .

*---Preparing field catalog manually

*DATA ls_fcat type lvc_s_fcat .

*ls_fcat-fieldname = 'CARRID' .

*ls_fcat-inttype = 'C' .

*ls_fcat-outputlen = '3' .

*ls_fcat-coltext = 'Carrier ID' .

*ls_fcat-seltext = 'Carrier ID' .

*ls_fcat-drdn_hndl = '1' .

*APPEND ls_fcat to pt_fieldcat .

*CLEAR ls_fcat .

*ls_fcat-fieldname = 'CONNID' .

*ls_fcat-ref_table = 'SFLIGHT' .

*ls_fcat-ref_table = 'CONNID' .

*ls_fcat-outputlen = '3' .

*ls_fcat-coltext = 'Connection ID' .

*ls_fcat-seltext = 'Connection ID' .

*APPEND ls_fcat to pt_fieldcat .

*---Preparing field catalog semi-automatically

DATA ls_fcat type lvc_s_fcat .

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

ct_fieldcat = pt_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc 0.

*--Exception handling

ENDIF.

LOOP AT pt_fieldcat INTO ls_fcat .

CASE ls_fcat-fieldname .

WHEN 'CARRID' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'Airline Carrier ID' .

ls_fcat-drdn_hndl = '1' .

MODIFY pt_fieldcat FROM ls_fcat .

WHEN 'PAYMENTSUM' .

ls_fcat-no_out = 'X' .

MODIFY pt_fieldcat FROM ls_fcat .

ENDCASE .

ENDLOOP .

ENDFORM . "prepare_field_catalog

&----


*& Form prepare_layout

&----


  • text

-


  • -->PS_LAYOUT text

-


FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

ps_layout-zebra = 'X' .

ps_layout-grid_title = 'Flights' .

ps_layout-smalltitle = 'X' .

ENDFORM. " prepare_layout

Example 2: cl_salv_table

data: gt_outtab type table of sflight.

data: toolbar type ref to cl_salv_functions_list .

data: gr_table type ref to cl_salv_table.

data: lr_aggregations type ref to cl_salv_aggregations.

data: lr_groups type ref to cl_salv_sorts .

select * from sflight into corresponding fields of table gt_outtab.

call method cl_salv_table=>factory

importing

r_salv_table = gr_table

changing

t_table = gt_outtab.

lr_aggregations = gr_table->get_aggregations( ).

toolbar = gr_table->get_functions( ) .

toolbar->set_all(

value = if_salv_c_bool_sap=>true

).

lr_aggregations->clear( ).

lr_groups = gr_table->get_sorts( ) .

lr_groups->clear( ).

try.

lr_groups->add_sort(

columnname = 'CARRID'

position = 8

subtotal = abap_true

sequence = if_salv_c_sort=>sort_up ).

catch cx_salv_not_found cx_salv_data_error cx_salv_existing.

endtry.

try.

lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ).

catch cx_salv_not_found cx_salv_data_error cx_salv_existing.

endtry.

gr_table->display( ).

Reward points, if useful.

Regards,

Manoj Kumar