abap tutorials » blog archive abap program for alv grid, the oops way - abap tutorials

6

Upload: shikhar-agarwal

Post on 22-Dec-2015

82 views

Category:

Documents


4 download

DESCRIPTION

ABAP

TRANSCRIPT

Page 1: ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, The OOPS Way - ABAP Tutorials

10/27/2014 ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials

http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45 1/6

ABAP Tutorials

ABAP Tutorials, Guides, Training, Manuals

Welcome

Blog

Archives

Subscribe

Downloads

Interview Q&A

Code Contribution

ABAP Books

Disclaimer

About

Subscribe To Entries

Subscribe To Comments

Subscribe Via Email

Want to find something?

09 Jul

ABAP Program for ALV Grid, the OOPS way

Posted by Admin, under ABAP, Abap Objects, ALV, Sample Code

The program below shows OOPS concept implementation in ALV. ALV is created inside the Custom Container, which acts as

wrapper for ALV. For both ALV and Custom Container, Objects has been created from the respective classes.

► ALV ► The Grid ► ABAP in Sap ► ABAP

Page 2: ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, The OOPS Way - ABAP Tutorials

10/27/2014 ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials

http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45 2/6

REPORT zalv_using_objects.

********Data declarations with respect to classes

DATA :

t_cust TYPE REF TO cl_gui_custom_container,

t_grid TYPE REF TO cl_gui_alv_grid .

*******Declaration of Structure with respect to SPFLI

TYPES:

BEGIN OF type_s_flight,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

END OF type_s_flight.

*******Fieldstring Declaration

DATA:

fs_flight TYPE type_s_flight.

******Table Declaration

DATA:

t_flight LIKE STANDARD TABLE OF fs_flight.

*******Declarations with respect to ALV

DATA:

t_fcat TYPE lvc_t_fcat, ” Field Catalog for List Viewer Control

w_fcat TYPE lvc_s_fcat, ” ALV control: Field catalog

w_lay TYPE lvc_s_layo . ” ALV control: Layout structure

********Select Query to retrive values from table SPFLI

SELECT *

FROM spfli

INTO CORRESPONDING FIELDS OF TABLE t_flight.

*******Calling the screen that has been designed in SE51 in the following manner

******* Goto SE51,design a layout and give the name of the container (ZALV01)

CALL SCREEN 100.

*&———————————————————————*

*& Module STATUS_0100 OUTPUT

*&———————————————————————*

* Module that has been called from SE51

*———————————————————————-*

MODULE status_0100 OUTPUT.

SET PF-STATUS ‘BACK’.

SET TITLEBAR ‘FLIGHT’.

ENDMODULE. ” STATUS_0100 OUTPUT

*&———————————————————————*

*& Module ALV_OUTPUT OUTPUT

*&———————————————————————*

* Module that has been created in SE51 and called

*———————————————————————-*

MODULE alv_output OUTPUT.

*****Appending data to t_fcat

w_fcat-fieldname = ‘CARRID’.

w_fcat-coltext = ‘Carrid’.

APPEND w_fcat TO t_fcat.

w_fcat-fieldname = ‘CONNID’.

w_fcat-coltext = ‘Connid’.

APPEND w_fcat TO t_fcat.

*******Create a object of class ‘CL_GUI_CUSTOM_CONTAINER’

CREATE OBJECT t_cust

EXPORTING

Page 3: ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, The OOPS Way - ABAP Tutorials

10/27/2014 ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials

http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45 3/6

* parent =

container_name = ‘ZALV01′

* style =

* lifetime = lifetime_default

* repid =

* dynnr =

* no_autodef_progid_dynnr =

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.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*******Create a object of class ‘CL_GUI_ALV_GRID’

CREATE OBJECT t_grid

EXPORTING

* i_shellstyle = 0

* i_lifetime =

i_parent = t_cust

* i_appl_events = space

* i_parentdbg =

* i_applogparent =

* i_graphicsparent =

* i_name =

* i_fcat_complete = space

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5

.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*********Call a method of instance t_grid , class cl_gui_grid_alv and method set_table_for_first_display

CALL METHOD t_grid->set_table_for_first_display

EXPORTING

* i_buffer_active =

* i_bypassing_buffer =

* i_consistency_check =

i_structure_name = ‘T_SPFLI’

* is_variant =

* i_save =

* i_default = ‘X’

is_layout = w_lay

* is_print =

Page 4: ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, The OOPS Way - ABAP Tutorials

10/27/2014 ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials

http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45 4/6

* it_special_groups =

* it_toolbar_excluding =

* it_hyperlink =

* it_alv_graphics =

* it_except_qinfo =

* ir_salv_adapter =

CHANGING

it_outtab = t_flight

it_fieldcatalog = t_fcat

* it_sort =

* it_filter =

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4

.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMODULE. ” ALV_OUTPUT OUTPUT

*&———————————————————————*

*& Module USER_COMMAND_0100 INPUT

*&———————————————————————*

* Module that has been called from SE51

*———————————————————————-*

MODULE user_command_0100 INPUT.

CASE sy-ucomm.

WHEN ‘BACK’.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. ” USER_COMMAND_0100 INPUT

*Source = Amuktha Naraparaju

You might also be interested in these posts:

1. ABAP Program for Creating an ALV Grid in 3 lines

2. ABAP Program with Editable ALV Grid Contents

3. ABAP Program to add Colors in ALV Grid

4. Displaying Icons in ALV Grid using ABAP

5. Demystifying Field Groups in ABAP

Tags: ABAP, ALV, ALV grid, OOP, OOPS, SAP

One Response to “ABAP Program for ALV Grid, the OOPS way”

Renjini Posted on January 18, 2013 at 12:39 PM

Page 5: ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, The OOPS Way - ABAP Tutorials

10/27/2014 ABAP Tutorials » Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials

http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45 5/6

Thanks for the explanation and sample code. It was very much useful.

Post a Comment

Name (Required)

E-Mail (Required) (Will not be published)

Website

Submit

BLOG CATEGORIES

Select Category

NEWS FROM THE BLOG

Mass Change SAP FI Documents

Generate Data Declarations Automatically for FM and Method Call

SAP PS Module Tables

Create FI Substitutions using GGB1 (Substitution Maintenance) SAP

Dynamic Columns in ABAP ALV

POPULAR POSTS

About ABAPUnicode in SAP

Tcodes in SAP – Part 1

Add Search Help to Screen Field in SAP