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
462

Hi all,

Can anyone pls tell me WHY we use custom container in ALV using OOPS...

also Some information about the methods of class cl_gui_alv_grid & of cl_gui_docking_container.

Thanks,

Gaurav J.

4 REPLIES 4
Read only

Former Member
Read only

Former Member
0 Likes
433

Hi,

This section describes the easiest way to display a list with selected data in the ALV Grid Control. To do this, you must:

1. Create an instance of the ALV Grid Control and integrate it into a screen.

2. Select the data to be displayed and pass it together with a description of the fields to the instance.

See also sample report BCALV_GRID_DEMO in development class SLIS .

Creating an ALV Grid Control

You instantiate an ALV Grid Control in the same way as other controls:

1. Declare reference variables for the ALV Grid Control and the container. In addition, declare an internal table that you fill with selected data later on:

DATA: grid TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container

gt_sflight TYPE TABLE OF sflight.

In order to integrate a control into a screen, you can use four different container controls (in this example, we use the custom container control).

2. Create a standard screen and mark an area for the custom container control in the graphical Screen Painter (icon identified by letter 'C'). Assign name CCCONTAINER to this area.

Exercise 1: Reserving an Area for a Control of the Controls Tutorial explains how to mark an area in the alphanumerical Screen Painter version.

3. In the PBO module of the screen, you must now instantiate the container control and the ALV Grid Control. By doing this, you create a link between the container control and the screen, using the container created in the Screen Painter. Using parameter parent , you define the container control as the parent of the ALV Grid Control:

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING

CONTAINER_NAME = 'CCCONTAINER'.

CREATE OBJECT GRID1

EXPORTING

I_PARENT = g_custom_container.

ENDIF.

The IF query of reference variable g_custom_container ensures that the instances are only generated when the PBO is processed for the first time.

Normally, you must use method cl_gui_cfw=>flush to pass the methods called to the frontend. However, since the Control Framework performs an automatic flush at the end of the PBO module, this step is not required here.

When you start the program, although the two instances (the container control and the ALV Grid Control) are generated, they are not visible.

Displaying a List in the ALV Grid Control

Once you have created the ALV Grid Control and integrated it into a screen using a container control, you must pass the data and its structure to the ALV Grid Control:

1. Fill the internal table with data:

SELECT * FROM sflight INTO TABLE gt_sflight.

2. Pass the output table and the structure data to the ALV Grid Control. Again, ensure to call this method only once after the ALV Grid Control is created:

CALL METHOD grid->set_table_for_first_display

EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'

CHANGING IT_OUTTAB = gt_sflight.

In this case, the structure data is provided through the Data Dictionary. The ALV Grid Control gets the field information from table SFLIGHT and displays all fiel

DATA : g_dock TYPE REF TO cl_gui_docking_container,

g_split TYPE REF TO cl_gui_easy_splitter_container,

g_cont1 TYPE REF TO cl_gui_container,

g_cont2 TYPE REF TO cl_gui_container,

g_grid1 TYPE REF TO cl_gui_alv_grid,

g_grid2 TYPE REF TO cl_gui_alv_grid.

  • i_mara is an internal table of structure MARA

SELECT * FROM mara INTO TABLE i_mara.

  • i_kna1 is an internal table of structure KNA1

SELECT * FROM kna1 INTO TABLE i_kna1.

  • To create an Object of type Docking Container

CREATE OBJECT g_dock

EXPORTING

side = cl_gui_docking_container=>dock_at_top

extension = 200 .

  • To Create an Object of Type Split Container. Here we can see that the Docking *Container Created above has been used as a parent .

CREATE OBJECT g_split

EXPORTING

parent = g_dock

orientation = 1 .

  • Easy Split container splits one Control into 2 manageable controls, each of them is used * to handle one GUI Container each

g_cont1 = g_split->top_left_container.

g_cont2 = g_split->bottom_right_container.

  • To Create an Object of type Grid . Here we can see that the Left Split Container * Created above has been used as a parent .

CREATE OBJECT g_grid1

EXPORTING

i_parent = g_cont1 .

  • To Create an Object of type Grid . Here we can see that the Right Split Container * Created above has been used as a parent .

CREATE OBJECT g_grid2

EXPORTING

i_parent = g_cont2 .

  • The method of Grid Control Object is used to display the Data.

CALL METHOD g_grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'MARA'

CHANGING

it_outtab = i_mara[] .

  • The method of Grid Control Object is used to display the Data.

CALL METHOD g_grid2->set_table_for_first_display

EXPORTING

i_structure_name = 'KNA1'

CHANGING

it_outtab = i_kna1[] .

Hope this helps u..

Regards,

Arunsri

Read only

Former Member
0 Likes
433

Hai Gaurav

&----


*& Include ZALVS3

&----


tables : zsflight.

data : container type ref to cl_gui_custom_container, " controls

grid type ref to cl_gui_alv_grid.

types : begin of ty_itab,

carrid type sflight-carrid,

connid type sflight-connid,

fldate type sflight-fldate,

price type zsflight-price,

seatsocc type sflight-seatsocc,

seatsmax type sflight-seatsmax,

end of ty_itab.

data : itab type table of zsflight,

wa type zsflight.

"{internal table for transfering the data in control

data : fieldcatlog type lvc_t_fcat, " field catalog

wa_fieldcatlog like line of fieldcatlog.

data : ok_code type sy-ucomm. "okcode handling

data gs_layout type lvc_s_layo.

data :input1 type c, " INPUT FIELDS IN SCREEN 1001 '

input2 type n,

input9 type d,

input3 type c,

input4 type c,

input5 type c,

input6 type c,

input7 type c,

input8 type n.

data: fname type rs38l_fnam. "FUNCTION FOR zALVS2

data : itab2 type table of zsflight.

data : container2 type ref to cl_gui_custom_container,

grid2 type ref to cl_gui_alv_grid.

data : fieldcatlog2 type lvc_t_fcat,

wa_fieldcatlog2 like line of fieldcatlog2,

gs_layout2 type lvc_s_layo.

&----


& Report ZALVS----


&----


&----


&----


&----


&----


report zalvs.

include zalvs3.

start-of-selection.

select *

from zsflight

into corresponding fields of table itab.

if sy-subrc eq 0.

call screen 1000.

endif.

-


MODULE status_1000 OUTPUT

-


-


-


module status_1000 output.

set pf-status 'SAP'.

endmodule. " STATUS_1000 OUTPUT

&----


*& Module USER_COMMAND_1000 INPUT

&----


text

-


module user_command_1000 input.

ok_code = sy-ucomm.

case ok_code.

when 'BACK'.

leave to screen 0.

when 'Exit'.

leave program.

when 'CANCEL'.

leave program.

when 'PUSH1'.

perform call_form1.

when 'PUSH2'.

call screen 1001.

when 'PUSH3'.

perform call_form3 tables itab.

endcase.

endmodule. " USER_COMMAND_1000 INPUT

&----


*& Module Create_Object OUTPUT

&----


text

-


module create_object output.

perform prepare_layout changing gs_layout.

if container is initial.

create object container

exporting

parent = parent

container_name = 'CONT'

style = style

lifetime = lifetime_default

repid = repid

dynnr = dynnr

no_autodef_progid_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 grid

exporting

i_shellstyle = 0

i_lifetime = i_lifetime

i_parent = container

i_appl_events = space

i_parentdbg = i_parentdbg

i_applogparent = i_applogparent

i_graphicsparent = i_graphicsparent

i_name = 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.

endif.

endmodule. " Create_Object OUTPUT

&----


*& Module Transfer_data OUTPUT

&----


-


text----


*

-


module transfer_data output.

call method grid->set_table_for_first_display

exporting

i_buffer_active = i_buffer_active

i_bypassing_buffer = i_bypassing_buffer

i_consistency_check = i_consistency_check

i_structure_name = 'SFLIGHT'

is_variant = is_variant

i_save = i_save

i_default = 'x'

is_layout = gs_layout

is_print = is_print

it_special_groups = it_special_groups

it_toolbar_excluding = it_toolbar_excluding

it_hyperlink = it_hyperlink

it_alv_graphics = it_alv_graphics

it_except_qinfo = it_except_qinfo

ir_salv_adapter = ir_salv_adapter

changing

it_outtab = itab[]

it_fieldcatalog = fieldcatlog[]

it_sort = it_sort

it_filter = it_filter

exceptions

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 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.

endmodule. " Transfer_data OUTPUT

&----


*& Module Fill_fieldcatlog OUTPUT

&----


text

-


module fill_fieldcatlog output.

clear wa_fieldcatlog.

data i type i value 0.

i = i + 1.

wa_fieldcatlog-fieldname = 'FLDATE'.

wa_fieldcatlog-ref_table = 'ZSFLIGHT'.

wa_fieldcatlog-coltext = text(001).

wa_fieldcatlog-col_pos = i .

append wa_fieldcatlog to fieldcatlog.

clear wa_fieldcatlog.

i = i + 1.

wa_fieldcatlog-fieldname = 'CARRID'.

wa_fieldcatlog-coltext = 'CARRID' .

wa_fieldcatlog-col_pos = i.

append wa_fieldcatlog to fieldcatlog.

clear wa_fieldcatlog.

i = i + 1.

wa_fieldcatlog-fieldname = 'CONNID'.

wa_fieldcatlog-coltext = 'CONNID' .

wa_fieldcatlog-col_pos = i.

append wa_fieldcatlog to fieldcatlog.

i = i + 1.

clear wa_fieldcatlog.

wa_fieldcatlog-fieldname = 'PRICE'.

wa_fieldcatlog-ref_table = 'ZSFLIGHT'.

"wa_fieldcatlog-coltext = text(001).

wa_fieldcatlog-col_pos = i.

append wa_fieldcatlog to fieldcatlog.

i = i + 1.

clear wa_fieldcatlog.

wa_fieldcatlog-fieldname = 'SEATSMAX'.

wa_fieldcatlog-coltext = 'TOTAL CAPACITY' .

wa_fieldcatlog-col_pos = i.

append wa_fieldcatlog to fieldcatlog.

clear wa_fieldcatlog.

i = i + 1.

wa_fieldcatlog-fieldname = 'SEATSOCC'.

wa_fieldcatlog-coltext = 'SEATS OCCUPIED' .

wa_fieldcatlog-col_pos = i.

append wa_fieldcatlog to fieldcatlog.

endmodule. " Fill_fieldcatlog OUTPUT

&----


*& Form prepare_layout

&----


text

-


-->GS_LAYOUT text

-


form prepare_layout changing gs_layout type lvc_s_layo.

gs_layout-stylefname = 'FIELD_STYLE'.

gs_layout-zebra = 'X'.

gs_layout-grid_title = 'FLIGHT'.

gs_layout-sel_mode = 'A'.

gs_layout-ctab_fname = 'COLORS'.

endform. "prepare_layout

&----


*& Form call_form1

&----


text

-


form call_form1.

call function '/1BCDWB/SF00000173'

EXPORTING

ARCHIVE_INDEX = ARCHIVE_INDEX

ARCHIVE_INDEX_TAB = ARCHIVE_INDEX_TAB

ARCHIVE_PARAMETERS = ARCHIVE_PARAMETERS

CONTROL_PARAMETERS = CONTROL_PARAMETERS

MAIL_APPL_OBJ = MAIL_APPL_OBJ

MAIL_RECIPIENT = MAIL_RECIPIENT

MAIL_SENDER = MAIL_SENDER

OUTPUT_OPTIONS = OUTPUT_OPTIONS

USER_SETTINGS = 'X'

IMPORTING

DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO

JOB_OUTPUT_INFO = JOB_OUTPUT_INFO

JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS

tables

itab = itab

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

.

endform. "call_form1

&----


*& Module STATUS_1001 OUTPUT

&----


text

-


module status_1001 output.

set pf-status 'SAP2'.

SET TITLEBAR 'xxx'.

endmodule. " STATUS_1001 OUTPUT

&----


*& Module USER_COMMAND_1001 INPUT

&----


text

-


module user_command_1001 input.

ok_code = sy-ucomm.

case ok_code.

when 'BACK'.

leave to screen 1000.

when 'EXIT'.

leave program.

when 'CANCEL'.

leave program.

when 'CONTINUE'.

perform call_form2.

endcase.

endmodule. " USER_COMMAND_1001 INPUT

&----


*& Form call_form2

&----


text

-


--> p1 text

<-- p2 text

-


form call_form2 .

call function 'SSF_FUNCTION_MODULE_NAME'

exporting

formname = 'ZALVS2'

VARIANT = ' '

DIRECT_CALL = ' '

importing

fm_name = fname

*EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

.

call function fname

EXPORTING

ARCHIVE_INDEX = ARCHIVE_INDEX

ARCHIVE_INDEX_TAB = ARCHIVE_INDEX_TAB

ARCHIVE_PARAMETERS = ARCHIVE_PARAMETERS

CONTROL_PARAMETERS = CONTROL_PARAMETERS

MAIL_APPL_OBJ = MAIL_APPL_OBJ

MAIL_RECIPIENT = MAIL_RECIPIENT

MAIL_SENDER = MAIL_SENDER

OUTPUT_OPTIONS = OUTPUT_OPTIONS

USER_SETTINGS = 'X'

IMPORTING

DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO

JOB_OUTPUT_INFO = JOB_OUTPUT_INFO

JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

.

endform. " call_form2

&----


*& Module STATUS_1002 OUTPUT

&----


text

-


module status_1002 output.

set pf-status 'SAP3'.

SET TITLEBAR 'xxx'.

endmodule. " STATUS_1002 OUTPUT

&----


*& Module USER_COMMAND_1002 INPUT

&----


text

-


module user_command_1002 input.

ok_code = sy-ucomm.

case ok_code.

when 'BACK'.

leave to screen 1000.

when 'EXIT'.

leave program.

when 'CANCEL'.

leave to screen 1000.

endcase.

endmodule. " USER_COMMAND_1002 INPUT

&----


*& Form call_form3

&----


text

-


--> p1 text

<-- p2 text

-


form call_form3 tables itab.

"APPEND wa TO itab2.

" CALL SCREEN 1002.

perform prepare_layout changing gs_layout.

clear wa_fieldcatlog2.

data j type i value 0.

j = j + 1.

wa_fieldcatlog2-fieldname = 'FLDATE'.

wa_fieldcatlog2-ref_table = 'ZSFLIGHT'.

wa_fieldcatlog-coltext = text(001).

wa_fieldcatlog2-col_pos = j .

append wa_fieldcatlog2 to fieldcatlog2.

clear wa_fieldcatlog2.

j = j + 1.

wa_fieldcatlog2-fieldname = 'CARRID'.

wa_fieldcatlog2-coltext = 'CARRID' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

clear wa_fieldcatlog2.

j = j + 1.

wa_fieldcatlog2-fieldname = 'CONNID'.

wa_fieldcatlog2-coltext = 'CONNID' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

j = j + 1.

clear wa_fieldcatlog2.

wa_fieldcatlog2-fieldname = 'PRICE'.

wa_fieldcatlog2-ref_table = 'ZSFLIGHT'.

"wa_fieldcatlog-coltext = text(001).

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

j = j + 1.

clear wa_fieldcatlog2.

wa_fieldcatlog2-fieldname = 'SEATSMAX'.

wa_fieldcatlog2-coltext = 'TOTAL CAPACITY' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

clear wa_fieldcatlog2.

j = j + 1.

wa_fieldcatlog2-fieldname = 'SEATSOCC'.

wa_fieldcatlog2-coltext = 'SEATS OCCUPIED' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

I_INTERFACE_CHECK = ' '

I_BYPASSING_BUFFER = ' '

I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = ' '

I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = ' '

I_CALLBACK_TOP_OF_PAGE = ' '

I_CALLBACK_HTML_TOP_OF_PAGE = ' '

I_CALLBACK_HTML_END_OF_LIST = ' '

i_structure_name = 'ZSFLIGHT'

I_BACKGROUND_ID = ' '

i_grid_title = grid2

I_GRID_SETTINGS = I_GRID_SETTINGS

is_layout = gs_layout

it_fieldcat = fieldcatlog2[]

IT_EXCLUDING = IT_EXCLUDING

IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS

IT_SORT = IT_SORT

IT_FILTER = IT_FILTER

IS_SEL_HIDE = IS_SEL_HIDE

I_DEFAULT = 'X'

I_SAVE = ' '

IS_VARIANT = IS_VARIANT

IT_EVENTS = IT_EVENTS

IT_EVENT_EXIT = IT_EVENT_EXIT

IS_PRINT = IS_PRINT

IS_REPREP_ID = IS_REPREP_ID

I_SCREEN_START_COLUMN = 0

I_SCREEN_START_LINE = 0

I_SCREEN_END_COLUMN = 0

I_SCREEN_END_LINE = 0

I_HTML_HEIGHT_TOP = 0

I_HTML_HEIGHT_END = 0

IT_ALV_GRAPHICS = IT_ALV_GRAPHICS

IT_HYPERLINK = IT_HYPERLINK

IT_ADD_FIELDCAT = IT_ADD_FIELDCAT

IT_EXCEPT_QINFO = IT_EXCEPT_QINFO

IR_SALV_FULLSCREEN_ADAPTER = IR_SALV_FULLSCREEN_ADAPTER

IMPORTING

E_EXIT_CAUSED_BY_CALLER = E_EXIT_CAUSED_BY_CALLER

ES_EXIT_CAUSED_BY_USER = ES_EXIT_CAUSED_BY_USER

tables

t_outtab = itab[]

exceptions

program_error = 1

.

refresh itab2[].

endform. " call_form3

&----


*& Module FILLCATLOG OUTPUT

&----


text

-


module fillcatlog output.

clear wa_fieldcatlog2.

data j type i value 0.

j = j + 1.

wa_fieldcatlog2-fieldname = 'FLDATE'.

wa_fieldcatlog2-ref_table = 'ZSFLIGHT'.

wa_fieldcatlog-coltext = text(001).

wa_fieldcatlog2-col_pos = j .

append wa_fieldcatlog2 to fieldcatlog2.

clear wa_fieldcatlog2.

j = j + 1.

wa_fieldcatlog2-fieldname = 'CARRID'.

wa_fieldcatlog2-coltext = 'CARRID' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

clear wa_fieldcatlog2.

j = j + 1.

wa_fieldcatlog2-fieldname = 'CONNID'.

wa_fieldcatlog2-coltext = 'CONNID' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

j = j + 1.

clear wa_fieldcatlog2.

wa_fieldcatlog2-fieldname = 'PRICE'.

wa_fieldcatlog2-ref_table = 'ZSFLIGHT'.

"wa_fieldcatlog-coltext = text(001).

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

j = j + 1.

clear wa_fieldcatlog2.

wa_fieldcatlog2-fieldname = 'SEATSMAX'.

wa_fieldcatlog2-coltext = 'TOTAL CAPACITY' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

clear wa_fieldcatlog2.

j = j + 1.

wa_fieldcatlog2-fieldname = 'SEATSOCC'.

wa_fieldcatlog2-coltext = 'SEATS OCCUPIED' .

wa_fieldcatlog2-col_pos = j.

append wa_fieldcatlog2 to fieldcatlog2.

endmodule. " FILLCATLOG OUTPUT

Read only

Former Member
0 Likes
433

hi

good

check this link, hope this would help you to solve your problem.

http://abapprogramming.blogspot.com/2007/10/alv-1.html

thanks

mruyun^