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-oops

Former Member
0 Likes
1,215

hai friends .....

iam new to alv with opps concepts ..

where can i declare selection screen and how can we retrive the data and print the data on screen.

inclass its not allowing selection screen. .

can u give me detailed view. on alv with container and selection screen.

tanx in advance..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
903

Hi,

ABAP Example Program ALV Grid Control

You need to create a screen 100 for calling it, and in the Element list of the sceen supply OK_CODE of type OK & in the layout, place a Custom - control with name DILEEP_TEST1.

Then activate modules STATUS_0100 and USER_COMMAND_0100 in the flow logic .

REPORT ZTEST_DIL4 .

TABLES ZMSTKSUM.

DATA : OK_CODE LIKE SY-UCOMM,

TAB_DISPLAY TYPE TABLE OF ZMSTKSUM,

C_CONTAINER TYPE SCRFNAME VALUE 'DILEEP_TEST1',

ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,

C_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_WERKS FOR ZMSTKSUM-WERKS.

SELECTION-SCREEN END OF BLOCK B1.

SELECT * FROM ZMSTKSUM INTO TABLE TAB_DISPLAY WHERE WERKS IN S_WERKS.

CALL SCREEN 100.

*&----


*& Module STATUS_0100 OUTPUT

*&----


  • text

*----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN'.

  • SET TITLEBAR 'xxx'.

IF C_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT C_CUSTOM_CONTAINER EXPORTING CONTAINER_NAME = C_CONTAINER

.

CREATE OBJECT ALV_GRID EXPORTING I_PARENT = C_CUSTOM_CONTAINER.

CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

I_STRUCTURE_NAME = 'ZMSTKSUM'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

CHANGING

IT_OUTTAB = TAB_DISPLAY

  • IT_FIELDCATALOG =

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • others = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

*&----


*& Module USER_COMMAND_0100 INPUT

*&----


  • text

*----


MODULE USER_COMMAND_0100 INPUT.

CASE OK_CODE.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

Regards,

Jagadish

6 REPLIES 6
Read only

Former Member
0 Likes
904

Hi,

ABAP Example Program ALV Grid Control

You need to create a screen 100 for calling it, and in the Element list of the sceen supply OK_CODE of type OK & in the layout, place a Custom - control with name DILEEP_TEST1.

Then activate modules STATUS_0100 and USER_COMMAND_0100 in the flow logic .

REPORT ZTEST_DIL4 .

TABLES ZMSTKSUM.

DATA : OK_CODE LIKE SY-UCOMM,

TAB_DISPLAY TYPE TABLE OF ZMSTKSUM,

C_CONTAINER TYPE SCRFNAME VALUE 'DILEEP_TEST1',

ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,

C_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_WERKS FOR ZMSTKSUM-WERKS.

SELECTION-SCREEN END OF BLOCK B1.

SELECT * FROM ZMSTKSUM INTO TABLE TAB_DISPLAY WHERE WERKS IN S_WERKS.

CALL SCREEN 100.

*&----


*& Module STATUS_0100 OUTPUT

*&----


  • text

*----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN'.

  • SET TITLEBAR 'xxx'.

IF C_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT C_CUSTOM_CONTAINER EXPORTING CONTAINER_NAME = C_CONTAINER

.

CREATE OBJECT ALV_GRID EXPORTING I_PARENT = C_CUSTOM_CONTAINER.

CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

I_STRUCTURE_NAME = 'ZMSTKSUM'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

CHANGING

IT_OUTTAB = TAB_DISPLAY

  • IT_FIELDCATALOG =

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • others = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

*&----


*& Module USER_COMMAND_0100 INPUT

*&----


  • text

*----


MODULE USER_COMMAND_0100 INPUT.

CASE OK_CODE.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

Regards,

Jagadish

Read only

Former Member
0 Likes
903

You can create selection screen and also display data retrieved in alv grid using oops methodology.

1. Create a report program.

2. Write code for selection screen.

3. Define classes for alv grid.

4. Use statement CALL SCREEN <screen no>.

5. In the screen create a custom control.

6. In the PBO retrieve data and populate the alv.

Go through the demo program bcalvc_grid_screen0.

Regards

Sourabh

Read only

Former Member
0 Likes
903

Hi vani,

Refer to this program...

TABLES: qmel,qmih,iflot,z94392_notif.

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .

DATA gc_custom_control_name TYPE scrfname VALUE 'CUST_C' .

DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .

DATA gt_fieldcat TYPE lvc_t_fcat .

DATA gs_layout TYPE lvc_s_layo.

DATA: e_row_id TYPE lvc_s_row,

e_column_id TYPE lvc_s_col,

es_row_no TYPE lvc_s_roid.

DATA: BEGIN OF itab1 OCCURS 0,

qmnum LIKE qmel-qmnum,

qmtxt LIKE qmel-qmtxt,

indtx LIKE qmel-indtx,

qmdat LIKE qmel-qmdat,

ltrmn LIKE qmel-ltrmn,

priok LIKE qmel-priok,

aufnr LIKE qmel-aufnr,

bezdt LIKE qmel-bezdt,

qmnam LIKE qmel-qmnam,

qmart LIKE qmel-qmart,

END OF itab1.

DATA: BEGIN OF itab2 OCCURS 0,

qmnum LIKE qmih-qmnum,

btpln LIKE qmih-btpln,

ingrp LIKE qmih-ingrp,

END OF itab2.

DATA : itab3 TYPE TABLE OF z94392_notif WITH HEADER LINE.

CLASS notification DEFINITION.

PUBLIC SECTION.

CLASS-METHODS : handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column.

ENDCLASS. "NOTIFICATION DEFINITION

CLASS notification IMPLEMENTATION.

METHOD handle_double_click.

PERFORM handle_double_click USING e_row e_column es_row_no.

ENDMETHOD. "handle_double_click

ENDCLASS. "NOTIFICATION IMPLEMENTATION

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.

SELECT-OPTIONS : notnum FOR qmel-qmnum OBLIGATORY,

notype FOR qmel-qmart,

floc FOR qmih-btpln,

name FOR qmel-qmnam.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

SELECT qmnum qmtxt indtx qmdat ltrmn priok aufnr bezdt qmnam qmart INTO

TABLE itab1 FROM qmel WHERE qmnum IN notnum

AND qmart IN notype AND qmnam IN name.

SELECT qmnum btpln ingrp INTO TABLE itab2 FROM qmih FOR ALL ENTRIES IN

itab1 WHERE qmnum = itab1-qmnum AND btpln IN floc.

LOOP AT itab1.

itab3-qmnum = itab1-qmnum.

itab3-qmtxt = itab1-qmtxt.

itab3-indtx = itab1-indtx.

itab3-qmdat = itab1-qmdat.

itab3-ltrmn = itab1-ltrmn.

itab3-priok = itab1-priok.

itab3-aufnr = itab1-aufnr.

itab3-bezdt = itab1-bezdt.

itab3-qmnam = itab1-qmnam.

itab3-qmart = itab1-qmart.

READ TABLE itab2 WITH KEY qmnum = itab1-qmnum.

itab3-btpln = itab2-btpln.

itab3-ingrp = itab2-ingrp.

APPEND itab3.

ENDLOOP.

END-OF-SELECTION.

IF itab3 IS INITIAL.

MESSAGE 'ENTER A VALID ENTRY' TYPE 'I'.

else.

CALL SCREEN '100'.

ENDIF.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS '100'.

  • SET TITLEBAR 'xxx'.

IF gr_alvgrid IS INITIAL .

CREATE OBJECT gr_ccontainer

EXPORTING

  • PARENT =

container_name = gc_custom_control_name

  • 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 OBJECT gr_alvgrid

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

i_parent = gr_ccontainer

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

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 METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

i_structure_name = 'Z94392_NOTIF'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

it_outtab = itab3[]

  • IT_FIELDCATALOG =

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

SET HANDLER notification=>handle_double_click FOR gr_alvgrid.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Form handle_double_click

&----


  • text

----


  • -->P_E_ROW text

  • -->P_E_COLUMN text

  • -->P_ES_ROW_NO text

----


FORM handle_double_click USING e_row TYPE lvc_s_row

e_column TYPE lvc_s_col

es_row_no TYPE lvc_s_roid.

DATA: t_output TYPE z94392_notif.

READ TABLE itab3 INTO t_output INDEX e_row-index .

IF sy-subrc = 0 AND e_column-fieldname EQ 'QMNUM'.

CALL TRANSACTION 'Z94406_SAPSCR' AND SKIP FIRST SCREEN.

ENDIF.

ENDFORM. "

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

If helpful then reward points.

Regards,

Syed

Read only

Former Member
0 Likes
903

container class link screen name with Oo ALV grid..

with help of u can use event like double click passing row and collumn and move to next screen

Read only

Former Member
0 Likes
903

Hi,

u201CThe ALV Grid control is a flexible tool for displaying lists. The tool provides common list operations as generic functions and can be enhanced by self-defined options.u201D

The ALV Grid control is used to build non-hierarchical, interactive, and modern-design lists. As a control, it is a component that is installed on the local PC.

The ALV Grid control provides typical list functions as sorting, filtering, summing, etc.,while also gives the opportunity to develop user functions where needed. It presents numerous interfaces like Excel Inplace and Crystal Reports.

The wrapper class implemented to encapsulate ALV Grid functionality is u201CCL_GUI_ALV_GRIDu201D. There is another way to display lists with ALV utilizing u201CREUSE_ALV...u201D functions. However, that way is not comprised in this tutorial.

While preparing a list to be displayed via an ALV grid control, we have some basic components to prepare. These are;

i. List data: Obviously, this is the data in an internal table to be listed. Standard ALV functions except sorting makes just read access to the list data. However, sorting changes state of the internal table. The internal table holding list data may be of any flat type. Deep types are only allowed when set for some functionalities of ALV Grid.

ii. Field Catalog: We use another internal table to define specifications on how the fields of our list will be displayed. This internal table is called the

u201Cfield catalogu201D. The field catalog must comprise some technical and additional information about display options for each column to be displayed. There are three procedures to generate the field catalog as u201CAutomatic generationu201D, u201CSemi-automatic generationu201D, and u201CManualgenerationu201D. The internal table for the field catalog must be referenced to the dictionary type u201CLVC_T_FCATu201D.

iii. Layout Structure: We fill a structure to specify general layout options for the grid. With this structure we can set general display options, grid customizing, totals options, color adjustments etc... The layout structure must be of type u201CLVC_S_LAYOu201D.

iv. Event Handler: We should define and implement an event handler class if we want to handle events triggered by the ALV Grid instance. After creating ALV Grid instance, we must register an instance of this event handler class to handle ALV Grid events.

v. Additional Data: To trigger some additional features of ALV Grid we can have some additional data to pass as parameters. For example, initial sorting criteria, buttons to be deactivated, etc...

Now, we can figure out a primitive scheme to prepare our ALV Grid. As a control object, ALV Grid instance requires a container to be linked to the screen. Generally, an instance of the class u201Ccl_gui_custom_containeru201D is used for this purpose. Instances of some other container classes such as u201Ccl_gui_docking_containeru201D, u201Ccl_gui_dialogbox_containeru201D may also be used. In our example we take a custom container. To create a custom container instance, we need a custom control area on the screen.

Step 1􀃆 Add a custom control on the screen which will be related to the custom container. Letu2019s give it the name u2018CC_ALVu2019.

Step 2 􀃆 Declare global variables to be used for ALV Grid.

Code Part 1 u2013 Global data definitions for ALV

*-- Global data definitions for ALV

*--- ALV Grid instance reference

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .

*--- Name of the custom control added on the screen

DATA gc_custom_control_name TYPE scrfname VALUE u2018CC_ALVu2019 .

*--- Custom container instance reference

DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .

*--- Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*--- Layout structure

DATA gs_layout TYPE lvc_s_layo .

Step 3 􀃆 Declare your internal table which is supposed to hold the list data. Letu2019s name it u201Cgt_listu201D. Here is an example declaration.

*--- 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 .

Code Part 2 u2013 Declaration of the internal table that will hold the list data

Step 4 􀃆 Somewhere in your program before calling list display, fill your list data as you want. Here, it is not our concern what the data are. We assume the internal table is filled reasonably. We will use the data of table SFLIGHT as our list data.

Step 5 􀃆 Call the screen which comprises the ALV Grid control. At PBO of this screen we will deal with creating the ALV Grid instance.

*--PBO

PROCESS BEFORE OUTPUT .

...

MODULE display_alv .

Code Part 3 u2013 PBO of the flow logic for the screen containing ALV Grid control

...

MODULE display_alv OUTPUT .

PERFORM display_alv .

ENDMODULE .

Step 6 􀃆 Now, it is high time we wrote something to play. So, this piece will be the one we will deal mainly. What we do is, checking whether an instance of the container (or ALV Grid) exists. If it exists, refreshing it, and if not, creating and setting ALV for the first display.

FORM display_alv .

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_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • 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_list[]

it_fieldcatalog = gt_fieldcat

  • IT_SORT =

  • IT_FILTER =

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 .

From ABAP objects, we are familiar with u201CCREATE OBJECTu201D statement which instantiate classes. In this snippet of code, we used two instance methods of u201Ccl_gui_alv_gridu201D. First is u201Cset_table_for_first_displayu201D whose name implies for what it is used. After creating the ALV Grid instance we call this method to make our list displayed. We pass list data table, field catalog table, layout structure and additional information. Here are parameter definitions taken from SAP Library.

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

Read it , it will give you a good idea about alv oops.

With regards,

Syed

Read only

Former Member
0 Likes
903

This message was moderated.