ALV with Class
Hello Guys.
I am new to Class programming in SAP -ABAP. I have knowledge of Classes in C++. Can some one send me following Material to improve my knowledge.
1. Study Material on Classs and development.
2. Sample program for creating ALV with Class.
3. Any other Sample program for Class
Thanks in Advance.
Regards
Atul Joshi
Here`s a good document on ALV Tutorial which would serve all ur needs.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/an%20easy%20reference%20for%20alv%20grid%20control.pdf
Refer these links :
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
8) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
http://www.erpgenie.com/sap/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/controls/index.htm
check these links also :
http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
For funtion module to class
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm
for classes
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm
for methods
http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
for inheritance
http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm
for interfaces
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
Similar Messages
-
How to trigger New page while using ALV with classes/oops?
Hi All
I am trying to print a report which has to show the data in two pages.
I am using ALV with classes/oops.
Though I am able to print the report but a new page is not coming. Whole of the data is coming in one single page.
Please tell me as to how to trigger a NEW PAGE while using ALV with classes/oops.
Please send some code samples also if available.
Thanks in advance.
Jerryusing sort option you can do it. in case of grid/oo alv class ALV you can view that only in print mode/preview mode.
in case of list you can view that directly.
sort-fieldname = 'FIELDNAME'.
sort-group = '*' "triggers new page
sort-up = 'X'.
append sort to it_sort. -
ALV with classes for selected fields
Hi ALL,
Please can anybody will give the example code for
<b>ALV with classes for selected fields</b> from database table .Hi,
*& Report YR_TANS_ALVTEST *
REPORT yr_tans_alvtest .
INCLUDE ya_yr_tans_alvtest_top.
TABLES yttans_test.
DATA itab LIKE yttans_test OCCURS 0.
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .
DATA gc_custom_control_name TYPE scrfname.
gc_custom_control_name = 'CC_ALV'.
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 wa_itab like line of itab.
TYPES : BEGIN OF ty_help,
roll_no LIKE yttans_test-roll_no,
name LIKE yttans_test-name,
END OF ty_help.
DATA: git_returntab TYPE TABLE OF ddshretval INITIAL SIZE 0.
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING
e_row e_column es_row_no.
PRIVATE SECTION.
ENDCLASS. "lcl_event_handler DEFINITION
DATA gr_event_handler TYPE REF TO lcl_event_handler .
*& Form handle_double_click
text
-->I_ROW text
-->I_COLUMN text
-->IS_ROW_NO text
FORM handle_double_click USING i_row TYPE lvc_s_row i_column TYPE
lvc_s_col is_row_no TYPE lvc_s_roid.
leave to list-processing.
read table itab index is_row_no-row_id into wa_itab.
write:/ 'Roll no: ', wa_itab-roll_no, /'Name: ', wa_itab-name,
/'Marks: ', wa_itab-marks.
LEAVE SCREEN.
ENDFORM . "handle_double_click
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION .
*--Handle Double Click
METHOD handle_double_click .
PERFORM handle_double_click USING e_row e_column es_row_no .
ENDMETHOD . "lcl_event_handler
ENDCLASS . "lcl_event_handler IMPLEMENTATION
SELECT-OPTIONS roll FOR yttans_test-roll_no .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR roll-low.
DATA: lit_help TYPE TABLE OF ty_help.
DATA: wa_returntab LIKE LINE OF git_returntab.
SELECT roll_no name INTO TABLE lit_help FROM yttans_test.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ROLL_NO'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'roll-low'
value_org = 'S'
TABLES
value_tab = lit_help
return_tab = git_returntab
EXCEPTIONS
parameter_error = 1
no_values_found = 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.
READ TABLE git_returntab INTO wa_returntab INDEX 1.
roll-low = wa_returntab-fieldval.
AT SELECTION-SCREEN.
SELECT * FROM yttans_test INTO TABLE itab WHERE roll_no IN roll.
START-OF-SELECTION.
CREATE OBJECT gr_event_handler .
CALL SCREEN '9000'.
*& Module STATUS_9000 OUTPUT
text
MODULE status_9000 OUTPUT.
SET PF-STATUS 'STATUS_9000'.
SET TITLEBAR 'TITLE_9000'.
ENDMODULE. " STATUS_9000 OUTPUT
*& Module USER_COMMAND_9000 INPUT
text
MODULE user_command_9000 INPUT.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'BACK' OR '%EX' OR 'RW'.
CALL METHOD gr_ccontainer->free.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
*& Module alv_display_9000 OUTPUT
text
MODULE alv_display_9000 OUTPUT.
PERFORM display_alv .
ENDMODULE. " alv_display_9000 OUTPUT
*& Form display_alv
text
FORM display_alv .
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.
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .
PERFORM prepare_field_catalog CHANGING gt_fieldcat .
PERFORM prepare_layout CHANGING gs_layout .
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
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 =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
it_outtab = itab[]
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.
LEAVE TO LIST-PROCESSING.
WRITE 'error'.
ENDIF.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2
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.
ENDFORM. "display_alv
*& Form prepare_field_catalog
text
<--P_GT_FIELDCAT text
FORM prepare_field_catalog CHANGING p_gt_fieldcat TYPE lvc_t_fcat .
DATA ls_fcat TYPE lvc_s_fcat .
ls_fcat-fieldname = 'ROLL_NO'.
ls_fcat-coltext = 'ROLL No.'.
APPEND ls_fcat TO p_gt_fieldcat.
ls_fcat-fieldname = 'NAME'.
ls_fcat-coltext = 'NAME'.
APPEND ls_fcat TO p_gt_fieldcat.
ls_fcat-fieldname = 'MARKS'.
ls_fcat-coltext = 'MARKS'.
APPEND ls_fcat TO p_gt_fieldcat.
ENDFORM. " prepare_field_catalog
*& Form prepare_layout
text
<--P_GS_LAYOUT text
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X' .
ps_layout-grid_title = 'Students Details'.
ps_layout-smalltitle = 'X' .
ENDFORM. " prepare_layout
Regards,
Tanveer.
Mark helpful answers
Message was edited by: Tanveer Shaikh -
Field catalog in alv with classes(OOPS)
please refer the code below of field catalog prepared.
this code is for preparing field catalog using ALV and OOPS.In the below field catalog, do_sum is not working.it is going to dump.
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'VBELN1'.
ls_fcat-ref_field = 'VBELN'.
ls_fcat-ref_table = 'VBRK'.
ls_fcat-coltext = 'Invoice No'.
ls_fcat-seltext = 'Invoice No'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'DMBTR'.
ls_fcat-ref_field = 'DMBTR'.
ls_fcat-ref_table = 'BSAD'.
ls_fcat-coltext = 'Value of Invoice'.
ls_fcat-seltext = 'Value of Invoice'.
ls_fcat-do_sum = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ENDFORM. "PREPARE_FIELD_CATALOG
I would apreciate u response.
regards,
veera.Hello Veeranjaneyulu
I prefer to use function module <b>LVC_FIELDCATALOG_MERGE</b> to build my fieldcatalogs.
If you need fields from different structure that is no problem. Simply call the function module for each structure and collect the result in the same itab (e.g. lt_fcat).
Finally, you delete all fields that you do not need.
If the order is important to you then re-order the fields:
LOOP AT lt_fcat INTO ls_fcat.
ls_fcat-col_pos = syst-tabix.
MODIFY lt_fcat from ls_fcat.
ENDLOOP.
Regards
Uwe -
when i am going from 1st detail list to basic list and choosing another sales order number i am geting the previous data instead of data according to new sales order number.
i have tried in ECC5.0 and also in 4.7EE.Plz Help me.
The code is as follows
*& Report ZAP_OOPS_ALV_2
*& Interactive alv with oops.
REPORT zap_oops_alv_2 MESSAGE-ID zapmsg.
*& Structure Declaration
Structure Declaration for sales order header data
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbeln_va, "Sales Ord Num
vkorg TYPE vkorg, "Sales Org
vkgrp TYPE vkgrp, "Sales Grp
kunnr TYPE kunnr, "Customer
END OF ty_vbak,
Structure Declaration for sales order item data
BEGIN OF ty_vbap,
vbeln TYPE vbeln_va, "Sales Ord Num
posnr TYPE posnr, "Sales item
matnr TYPE matnr, "Material Num
matkl TYPE matkl, "Material Grp
netwr TYPE netwr, "Net values
END OF ty_vbap,
Structure Declaration for customer data
BEGIN OF ty_kna1,
kunnr TYPE kunnr, "Customer
name1 TYPE name1, "Name
ort01 TYPE ort01, "City
pstlz TYPE pstlz, "Postal code
regio TYPE regio, "State
END OF ty_kna1,
Structure declaration for final output
BEGIN OF ty_output,
vbeln TYPE vbeln_va, "Sales Ord Num
vkorg TYPE vkorg, "Sales Org
vkgrp TYPE vkgrp, "Sales Grp
kunnr TYPE kunnr, "Customer
name1 TYPE name1, "Name
ort01 TYPE ort01, "City
pstlz TYPE pstlz, "Postal code
regio TYPE regio, "State
posnr TYPE posnr, "Sales item
matnr TYPE matnr, "Material Num
matkl TYPE matkl, "Material Grp
netwr TYPE netwr, "Net values
END OF ty_output.
*& Internal table Declaration
DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak INITIAL SIZE 0,
t_vbap TYPE STANDARD TABLE OF ty_vbap INITIAL SIZE 0,
t_kna1 TYPE STANDARD TABLE OF ty_kna1 INITIAL SIZE 0,
t_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
t_vbep TYPE STANDARD TABLE OF vbep INITIAL SIZE 0,
*& Work Area Declaration
w_vbak TYPE ty_vbak,
w_vbap TYPE ty_vbap,
w_kna1 TYPE ty_kna1,
w_output TYPE ty_output,
w_vbep TYPE vbep,
g_flag TYPE char1,
g_vbeln TYPE vbak-vbeln.
Alv Declarations
DATA:g_custom_container1 TYPE REF TO cl_gui_custom_container,
g_custom_container2 TYPE REF TO cl_gui_custom_container,
g_grid1 TYPE REF TO cl_gui_alv_grid,
g_grid2 TYPE REF TO cl_gui_alv_grid,
w_fieldcat TYPE lvc_s_fcat,
t_fieldcat TYPE lvc_t_fcat.
*& Selection Screen Declaration
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS:s_vbeln FOR g_vbeln.
SELECTION-SCREEN END OF BLOCK b1.
CLASS handle DEFINITION
CLASS handle DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row.
ENDCLASS. "handle DEFINITION
CLASS handle IMPLEMENTATION
CLASS handle IMPLEMENTATION.
METHOD click.
CLEAR w_output.
READ TABLE t_output INTO w_output INDEX e_row.
CLEAR e_row.
REFRESH t_vbep.
SELECT *
FROM vbep
INTO TABLE t_vbep
WHERE vbeln = w_output-vbeln.
CREATE OBJECT g_custom_container2
EXPORTING
container_name = 'GRID2'.
CREATE OBJECT g_grid2
EXPORTING
i_parent = g_custom_container2.
CALL SCREEN 200.
ENDMETHOD. "click
ENDCLASS. "handle IMPLEMENTATION
DATA: g_handle TYPE REF TO handle.
CLASS main DEFINITION
CLASS main DEFINITION.
PUBLIC SECTION.
METHODS:get_vbak,
get_vbap,
get_kna1,
disp_output,
validate_vbeln,
display_alv.
ENDCLASS. "main DEFINITION
CLASS main IMPLEMENTATION
CLASS main IMPLEMENTATION.
Method declaration for getting vbak data
METHOD get_vbak.
SELECT vbeln
vkorg
vkgrp
kunnr
FROM vbak
INTO TABLE t_vbak
WHERE vbeln IN s_vbeln.
ENDMETHOD. "get_vbak
Method Declaration for getting VBAP data
METHOD get_vbap.
SELECT vbeln
posnr
matnr
matkl
netwr
FROM vbap
INTO TABLE t_vbap
FOR ALL ENTRIES IN t_vbak
WHERE vbeln = t_vbak-vbeln.
ENDMETHOD. "get_vbap
Method Declaration for getting KNA1 data
METHOD get_kna1.
SELECT kunnr
name1
ort01
pstlz
regio
FROM kna1
INTO TABLE t_kna1
FOR ALL ENTRIES IN t_vbak
WHERE kunnr = t_vbak-kunnr.
ENDMETHOD. "get_kna1
Method Declaration for displaying the output
METHOD disp_output.
LOOP AT t_vbap INTO w_vbap.
w_output-vbeln = w_vbap-vbeln.
w_output-posnr = w_vbap-posnr.
w_output-matnr = w_vbap-matnr.
w_output-matkl = w_vbap-matkl.
w_output-netwr = w_vbap-netwr.
CLEAR w_vbak.
READ TABLE t_vbak INTO w_vbak WITH KEY vbeln = w_vbap-vbeln.
IF sy-subrc = 0.
w_output-vkorg = w_vbak-vkorg.
w_output-vkgrp = w_vbak-vkgrp.
w_output-kunnr = w_vbak-kunnr.
ENDIF.
CLEAR w_kna1.
READ TABLE t_kna1 INTO w_kna1 WITH KEY kunnr = w_vbak-kunnr.
IF sy-subrc = 0.
w_output-name1 = w_kna1-name1.
w_output-ort01 = w_kna1-ort01.
w_output-pstlz = w_kna1-pstlz.
w_output-regio = w_kna1-regio.
ENDIF.
APPEND w_output TO t_output.
CLEAR w_output.
ENDLOOP.
ENDMETHOD. "disp_output
METHOD validate_vbeln.
DATA:l_vbeln TYPE vbeln_va.
SELECT SINGLE vbeln
FROM vbak
INTO l_vbeln
WHERE vbeln IN s_vbeln.
IF sy-subrc <> 0.
MESSAGE e001.
ENDIF.
ENDMETHOD. "validate_vbeln
METHOD display_alv.
CREATE OBJECT g_custom_container1
EXPORTING
container_name = 'GRID1'.
CREATE OBJECT g_grid1
EXPORTING
i_parent = g_custom_container1.
SET HANDLER g_handle->click FOR g_grid1.
w_fieldcat-col_pos = 1.
w_fieldcat-fieldname = 'VBELN'.
w_fieldcat-scrtext_m = 'Sales Ord'.
APPEND w_fieldcat TO t_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-col_pos = 2.
w_fieldcat-fieldname = 'POSNR'.
w_fieldcat-scrtext_m = 'Sales Item'.
APPEND w_fieldcat TO t_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-col_pos = 3.
w_fieldcat-fieldname = 'MATNR'.
w_fieldcat-scrtext_m = 'Material'.
APPEND w_fieldcat TO t_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-col_pos = 4.
w_fieldcat-fieldname = 'VKORG'.
w_fieldcat-scrtext_m = 'Sale Org'.
APPEND w_fieldcat TO t_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-col_pos = 5.
w_fieldcat-fieldname = 'KUNNR'.
w_fieldcat-scrtext_m = 'Customer'.
APPEND w_fieldcat TO t_fieldcat.
CLEAR w_fieldcat.
CALL SCREEN 100.
ENDMETHOD. "display_alv
ENDCLASS. "main IMPLEMENTATION
DATA:g_main TYPE REF TO main.
Selection SELECTION EVENT
AT SELECTION-SCREEN.
*Create the object
CREATE OBJECT g_main.
CALL METHOD g_main->validate_vbeln.
Start of selection EVENT
START-OF-SELECTION.
CALL METHOD g_main->get_vbak .
CALL METHOD g_main->get_vbap.
CALL METHOD g_main->get_kna1.
CALL METHOD g_main->disp_output.
CALL METHOD g_main->display_alv.
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MENU'.
SET TITLEBAR 'xxx'.
CALL METHOD g_grid1->set_table_for_first_display
CHANGING
it_outtab = t_output
it_fieldcatalog = t_fieldcat.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module STATUS_0200 OUTPUT
text
MODULE status_0200 OUTPUT.
SET PF-STATUS 'MENU1'.
SET TITLEBAR 'xxx'.
CALL METHOD g_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBEP'
CHANGING
it_outtab = t_vbep.
ENDMODULE. " STATUS_0200 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module USER_COMMAND_0200 INPUT
text
MODULE user_command_0200 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
g_flag = 'X'.
REFRESH t_vbep.
SET HANDLER g_handle->click FOR g_grid1.
CALL METHOD g_main->display_alv.
CALL SCREEN 100.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 100.
LEAVE TO SCREEN 0 .
SET SCREEN 100. LEAVE SCREEN.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUTHi Srikar,
In OOPS ALV, we first define screen then we define container on screen. Container means area on screen where you'll be placing your ALV.
CREATE OBJECT r_cont
EXPORTING
container_name = 'CONTAINER_1' " Container name
EXCEPTIONS
OTHERS = 6
Now you assign reference of container to your grid. grid defines structure of your ALV.
CREATE OBJECT r_grid
EXPORTING
i_parent = r_cont
EXCEPTIONS
OTHERS = 5
Now you call the method set_table_for_first_display of class cl_gui_alv_grid to define fieldcatalog, internal table etc. to display ALV. The reason behind using MODULE is that screen logic is always defined in MODULES. If the user is interacting with screen then screen logic will be defined in PAI of screen.
One more thing is that in normal ALV you don't define screen and container. That means ALV will always be displayed at system defined place, but in OOP ALV, you define container(area) to define the place for your ALV.
The advantage which I found in OOP ALV is that it is more flexible to use.
Regards
Abhijeet -
Can anyone help me with the code of Heirarchical ALV with OOPS in module pool programming.
hi,
<i>link</i>
http://www.sap-img.com/abap/how-to-use-alv-for-hierarchical-lists.htm
<i>Check this example report :</i> BALVHD01
<i>chk a sample code.</i>
REPORT ZTEST_HIER LINE-COUNT 65
LINE-SIZE 200
NO STANDARD PAGE HEADING
MESSAGE-ID ZZ.
TYPE-POOLS: SLIS.
TYPES: BEGIN OF TY_HEAD,
VBELN LIKE VBAK-VBELN,
KUNNR LIKE VBAK-KUNNR,
NAME LIKE KNA1-NAME1,
END OF TY_HEAD.
TYPES: BEGIN OF TY_ITEM,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
MAKTX LIKE MAKT-MAKTX,
CHECK(1),
END OF TY_ITEM.
DATA: IT_ITEM TYPE TABLE OF TY_ITEM.
DATA: IT_HEADER TYPE TABLE OF TY_HEAD,
IT_EVENTS TYPE SLIS_T_EVENT, "Events.
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: X_LAYOUT TYPE SLIS_LAYOUT_ALV,
X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
X_KEY TYPE SLIS_KEYINFO_ALV,
X_EVENTS TYPE SLIS_ALV_EVENT, "Event
X_VBELN LIKE VBAK-VBELN,
X_ITEM TYPE TY_ITEM.
CONSTANTS: C_S(1) VALUE '/'.
DATA: V_FLAG.
* SELECTION-SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR X_VBELN. "Sales order Number
SELECTION-SCREEN END OF BLOCK BLK.
AT SELECTION-SCREEN.
IF NOT S_VBELN[] IS INITIAL.
SELECT SINGLE VBELN
INTO X_VBELN
FROM VBAK
WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE E002 WITH 'Please enter valid Sales Order'(020).
ENDIF.
ENDIF.
* CLASS lcl_bill_complete DEFINITION
CLASS LCL_BILL_COMPLETE DEFINITION.
PUBLIC SECTION.
METHODS:GET_HEADER_DATA,
GET_ITEM_DATA,
SHOW_DATA,
FILL_FIELDCAT,
FILL_EVENTS,
TOP_OF_PAGE.
ENDCLASS. "lcl_bill_complete DEFINITION
* CLASS lcl_bill_complete IMPLEMENTATION
CLASS LCL_BILL_COMPLETE IMPLEMENTATION.
METHOD GET_HEADER_DATA.
DATA:X_HEADER LIKE LINE OF IT_HEADER.
X_HEADER-VBELN = '12345'.
X_HEADER-KUNNR = '1234'.
X_HEADER-NAME = 'Test'.
APPEND X_HEADER TO IT_HEADER.
X_HEADER-VBELN = '12346'.
X_HEADER-KUNNR = '1236'.
X_HEADER-NAME = 'Test'.
APPEND X_HEADER TO IT_HEADER.
X_HEADER-VBELN = '12347'.
X_HEADER-KUNNR = '1235'.
X_HEADER-NAME = 'Test'.
APPEND X_HEADER TO IT_HEADER.
ENDMETHOD. "get_header_data
METHOD GET_ITEM_DATA.
DATA:X_ITEM LIKE LINE OF IT_ITEM.
X_ITEM-VBELN = '12345'.
X_ITEM-POSNR = '0010'.
X_ITEM-MATNR = 'TESTMATNR'.
X_ITEM-MAKTX = 'TESTMAT'.
APPEND X_ITEM TO IT_ITEM.
X_ITEM-VBELN = '12345'.
X_ITEM-POSNR = '0020'.
X_ITEM-MATNR = 'TESTMATNR'.
X_ITEM-MAKTX = 'TESTMAT'.
APPEND X_ITEM TO IT_ITEM.
X_ITEM-VBELN = '12346'.
X_ITEM-POSNR = '0010'.
X_ITEM-MATNR = 'TESTMATNR'.
X_ITEM-MAKTX = 'TESTMAT'.
APPEND X_ITEM TO IT_ITEM.
X_ITEM-VBELN = '12346'.
X_ITEM-POSNR = '0020'.
X_ITEM-MATNR = 'TESTMATNR'.
X_ITEM-MAKTX = 'TESTMAT'.
APPEND X_ITEM TO IT_ITEM.
X_ITEM-VBELN = '12347'.
X_ITEM-POSNR = '0010'.
X_ITEM-MATNR = 'TESTMATNR'.
X_ITEM-MAKTX = 'TESTMAT'.
APPEND X_ITEM TO IT_ITEM.
X_ITEM-VBELN = '12347'.
X_ITEM-POSNR = '0020'.
X_ITEM-MATNR = 'TESTMATNR'.
X_ITEM-MAKTX = 'TESTMAT'.
APPEND X_ITEM TO IT_ITEM.
ENDMETHOD. "get_item_data
METHOD SHOW_DATA.
X_KEY-HEADER01 = 'VBELN'.
X_KEY-ITEM01 = 'VBELN'.
X_KEY-ITEM02 = 'POSNR'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = X_LAYOUT
IT_FIELDCAT = IT_FIELDCAT[]
I_TABNAME_HEADER = 'IT_HEADER'
I_TABNAME_ITEM = 'IT_ITEM'
IS_KEYINFO = X_KEY
IT_EVENTS = IT_EVENTS
TABLES
T_OUTTAB_HEADER = IT_HEADER
T_OUTTAB_ITEM = IT_ITEM
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDMETHOD. "show_data
METHOD FILL_FIELDCAT.
DATA: L_POS TYPE I.
X_LAYOUT-HEADER_TEXT = 'HEADER'.
X_LAYOUT-ITEM_TEXT = 'ITEM'.
X_LAYOUT-DEFAULT_ITEM = ' '.
X_LAYOUT-NO_KEYFIX = 'X'.
X_LAYOUT-BOX_TABNAME = 'IT_ITEM'.
L_POS = L_POS + 1.
*- Sales Order Number
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_HEADER'.
X_FIELDCAT-SELTEXT_M = 'Sales Order'(017).
X_FIELDCAT-OUTPUTLEN = 11.
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'KUNNR'.
X_FIELDCAT-TABNAME = 'IT_HEADER'.
X_FIELDCAT-SELTEXT_M = 'Sold-to Party'(010).
X_FIELDCAT-OUTPUTLEN = 13.
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'NAME'.
X_FIELDCAT-TABNAME = 'IT_HEADER'.
X_FIELDCAT-OUTPUTLEN = 15.
X_FIELDCAT-SELTEXT_M = 'Sold-to name'(011).
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'CHECK'.
X_FIELDCAT-TABNAME = 'IT_ITEM'.
X_FIELDCAT-CHECKBOX = 'X'.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-SELTEXT_M = ' '.
X_FIELDCAT-OUTPUTLEN = 2.
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_ITEM'.
X_FIELDCAT-SELTEXT_M = 'Sales Order'(017).
X_FIELDCAT-OUTPUTLEN = 11.
X_FIELDCAT-TECH = 'X'.
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
*- Sales Order Item
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'IT_ITEM'.
X_FIELDCAT-SELTEXT_M = 'SO Item'(018).
X_FIELDCAT-OUTPUTLEN = 7.
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'MATNR'.
X_FIELDCAT-TABNAME = 'IT_ITEM'.
X_FIELDCAT-OUTPUTLEN = 18.
X_FIELDCAT-SELTEXT_M = 'Material number'(012).
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'MAKTX'.
X_FIELDCAT-TABNAME = 'IT_ITEM'.
X_FIELDCAT-OUTPUTLEN = 40.
X_FIELDCAT-SELTEXT_M = 'Material Description'(013).
X_FIELDCAT-COL_POS = L_POS.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
ENDMETHOD. "fill_fieldcat
*--Fill the events table
METHOD FILL_EVENTS.
*- Top of page
X_EVENTS-NAME = 'TOP_OF_PAGE'.
X_EVENTS-FORM = 'TOP_OF_PAGE'.
APPEND X_EVENTS TO IT_EVENTS.
ENDMETHOD. "fill_events
"fill_events
METHOD TOP_OF_PAGE.
*- Call Steelcase Standard Header
WRITE 'top_of_page here'.
ENDMETHOD. "top_of_page
ENDCLASS. "lcl_bill_complete IMPLEMENTATION
START-OF-SELECTION.
DATA: OBJ TYPE REF TO LCL_BILL_COMPLETE.
CREATE OBJECT OBJ.
CALL METHOD OBJ->GET_HEADER_DATA.
CALL METHOD OBJ->GET_ITEM_DATA.
CALL METHOD OBJ->FILL_FIELDCAT.
CALL METHOD OBJ->FILL_EVENTS.
CALL METHOD OBJ->SHOW_DATA.
*& Form top_of_page
* TOP_OF_PAGE
FORM TOP_OF_PAGE.
*-To show the top of page
CALL METHOD OBJ->TOP_OF_PAGE.
ENDFORM. "top_of_page
if hlped plsmark points.
rgds
Anver -
Can I get a sample program of ALV (oops) with check boxes in it. thank you.
Types: begin of lt_io.
include structure mara. " Your Structure
Types: style_table type lvc_t_style.
Types: end of lt_io.
data: lt_io type table of lt_io,
ls_layout type lvc_s_layo,
lt_fcat type lvc_t_fcat,
lo_grid type ref to cl_gui_alv_grid.
field-symbols: <io> type lt_io,
<fcat> type lvc_s_fcat.
... fill your output table ....
ls_layout-stylefname = 'STYLE_TABLE'.
loop at lt_io assigning <io>.
PERFORM set_style USING 'CHECKBOX' "Your Filename
CHANGING <io>.
endloop.
... Fill Your Field Catalog lt_fcat
read table lt_fcat assigning <fcat>
where fieldname = 'CHECKBOX'.
<fcat>-checkbox = 'X'.
create grid control lo_grid.
CALL METHOD lo_grid->set_table_for_first_display
EXPORTING
is_layout = ls_layout
CHANGING
it_fieldcatalog = lt_fcat
it_outtab = lt_io[].
FORM set_button_to_line
USING iv_fieldname TYPE lvc_fname
CHANGING cs_io TYPE io.
DATA: ls_style TYPE lvc_s_styl,
lt_style TYPE lvc_t_styl.
ls_style-fieldname = iv_fieldname.
if cs_io-checkbox = ' '.
ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
else.
ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
endif.
ls_style-maxlen = 2.
INSERT ls_style INTO TABLE io-style_table.
ENDFORM. "set_icon_to_status_line
[/code].
A classical report is a program that generates a single list, which must contain all of the required detail information.
1) This procedure may result in extensive lists from which the user has to pick the relevant data.
2) For background processing, this is the only possible method. After starting a background job, there is no way of influencing the program.
3) The desired selections must be made beforehand and the list must provide detailed information.
4) For dialog sessions, there are no such restrictions.
5) The user is present during the execution of the program and can control and manipulate the program flow directly.
6) To be able to use all advantages of the online environment, classical reporting was developed into interactive reporting.
ALV is Application List viewer. Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length. In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output. The report output can contain up to 90 columns in the display with the wide array of display options.
Advantages.
Collapse multiple reports into one, drastically cutting down your report development time
Save many hours using built-in ALV sorting, subtotaling and filtering capabilities
Add conditional structures into your ALV report: No programming required!
Combine ALV with display variants to meet a wide range of reporting requirements more easily
Dynamically reorder column layouts and add/subtract fields
Enable users and analysts to save their own personalized variants
All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.
1. SIMPLE REPORT.
The important function modules are
a. Reuse_alv_list_display
b. Reuse_alv_fieldcatalog_merge
c. Reuse_alv_events_get
d. Reuse_alv_commentary_write
e. Reuse_alv_grid_display
A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.
The important parameters are :
I. Export :
i. I_callback_program : report id
ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status
iii. I_callback_user_command : routine where the function codes are handled
iv. I_structure name : name of the dictionary table
v. Is_layout : structure to set the layout of the report
vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE
vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.
II. Tables :
i. t_outtab : internal table with the data to be output
B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.
The Important Parameters are :
I. Export :
i. I_program_name : report id
ii. I_internal_tabname : the internal output table
iii. I_inclname : include or the report name where all the dynamic forms are handled.
II Changing
ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is
declared in the type pool SLIS.
C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type
Parameters :
I. Import :
Et_Events : The event table is returned with all possible CALLBACK events
for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.
II. Export :
I_List_type :
0 = simple list REUSE_ALV_LIST_DISPLAY
1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY
2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND
3 = hierarchical-sequential block list
REUSE_ALV_BLOCK_LIST_HS_APPEND
D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.
Parameters :
I. it_list_commentary : internal table with the headings of the type slis_t_listheader.
This internal table has three fields :
Typ : H header, S selection , A - action
Key : only when typ is S.
Info : the text to be printed
E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.
Parameters : same as reuse_alv_list_display
This is an example for simple list.
2. BLOCK REPORT
This is used to have multiple lists continuously.
The important functions used in this report are:
A. REUSE_ALV_BLOCK_LIST_INIT
B. REUSE_ALV_BLOCK_LIST_APPEND
C. REUSE_ALV_BLOCK_LIST_HS_APPEND
D. REUSE_ALV_BLOCK_LIST_DISPLAY
A. REUSE_ALV_BLOCK_LIST_INIT
Parameters:
I. I_CALLBACK_PROGRAM
II. I_CALLBACK_PF_STATUS_SET
III. I_CALLBACK_USER_COMMAND
This function module is used to set the default gui status etc.
B. REUSE_ALV_BLOCK_LIST_APPEND
Parameters :
Export :
I. is_layout : layout settings for block
II. it_fieldcat : field catalog
III. i_tabname : internal table name with output data
IV. it_events : internal table with all possible events
Tables :
i. t_outtab : internal table with output data.
This function module adds the data to the block.
Repeat this function for all the different blocks to be displayed one after the other.
C. REUSE_ALV_BLOCK_LIST_HS_APPEND
This function module is used for hierarchical sequential blocks.
D. REUSE_ALV_BLOCK_LIST_DISPLAY
Parameters : All the parameters are optional.
This function module display the list with data appended by the above function.
Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.
3. Hierarchical reports :
Hierarchical sequential list output.
The function module is
A. REUSE_ALV_HIERSEQ_LIST_DISPLAY
Parameters:
I. Export:
i. I_CALLBACK_PROGRAM
ii. I_CALLBACK_PF_STATUS_SET
iii. I_CALLBACK_USER_COMMAND
iv. IS_LAYOUT
v. IT_FIELDCAT
vi. IT_EVENTS
vii. i_tabname_header : Name of the internal table in the program containing the
output data of the highest hierarchy level.
viii. i_tabname_item : Name of the internal table in the program containing the
output data of the lowest hierarchy level.
ix. is_keyinfo : This structure contains the header and item table field
names which link the two tables (shared key).
II. Tables
i. t_outtab_header : Header table with data to be output
ii. t_outtab_item : Name of the internal table in the program containing the
output data of the lowest hierarchy level.
slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using REUSE_ALV_FIELDCATALOG_MERGE.
Important Attributes :
A. col_pos : position of the column
B. fieldname : internal fieldname
C. tabname : internal table name
D. ref_fieldname : fieldname (dictionary)
E. ref_tabname : table (dictionary)
F. key(1) : column with key-color
G. icon(1) : icon
H. symbol(1) : symbol
I. checkbox(1) : checkbox
J. just(1) : (R)ight (L)eft (C)ent.
K. do_sum(1) : sum up
L. no_out(1) : (O)blig.(X)no out
M. outputlen : output length
N. seltext_l : long key word
O. seltext_m : middle key word
P. seltext_s : short key word
Q. reptext_ddic : heading (ddic)
R. ddictxt(1) : (S)hort (M)iddle (L)ong
S. datatype : datatype
T. hotspot(1) : hotspot
declarations for spl.group.
GT_SP_GROUP TYPE SLIS_T_SP_GROUP_ALV
GT_SORT TYPE SLIS_T_SORTINFO_ALV, "for sort
DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.
CLEAR LS_SORT.
LS_SORT-FIELDNAME = 'FIELD1'.
LS_SORT-SPOS = 1.
LS_SORT-UP = 'X'.
ls_sort-subtot = 'X'. "subtotal
APPEND LS_SORT TO E06_LT_SORT.
APPEND LS_SORT TO E06_LT_SORT.
LS_SORT-FIELDNAME = 'FIELD2'.
LS_SORT-SPOS = 2.
LS_SORT-UP = 'X'.
ls_sort-subtot = 'X'. "subtotal
APPEND LS_SORT TO E06_LT_SORT.
for creating the group..
DATA: LS_SP_GROUP TYPE SLIS_SP_GROUP_ALV.
CLEAR LS_SP_GROUP.
LS_SP_GROUP-SP_GROUP = 'A'.
LS_SP_GROUP-TEXT = TEXT-005.
APPEND LS_SP_GROUP TO E07_LT_SP_GROUP.
and pass this info to FM...
layout-sUBTOTALS_TEXT = 'SUbt...'
and pass spl group info to fieldcatalog also...
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT[]
IT_SPECIAL_GROUPS = GT_SP_GROUP[]
IT_SORT = GT_SORT[]
TYPES :
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
waerk TYPE vbak-waerk, " Document currency
END OF ty_vbak.
DATA:
vbak TYPE vbak,
gt_vbak TYPE TABLE OF ty_vbak.
SELECT-OPTIONS :
s_vkorg FOR vbak-vkorg, " Sales organization
s_kunnr FOR vbak-kunnr, " Sold-to party
s_vbeln FOR vbak-vbeln. " Sales document
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
v_1 = 'Maximum of records to read'.
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
Form f_read_data
FORM f_read_data.
SELECT vkorg kunnr vbeln netwr waerk
UP TO p_max ROWS
INTO TABLE gt_vbak
FROM vbak
WHERE kunnr IN s_kunnr
AND vbeln IN s_vbeln
AND vkorg IN s_vkorg.
ENDFORM. " F_READ_DATA
Form f_display_data
FORM f_display_data.
TYPE-POOLS: slis. " ALV Global types
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = 'VBAK'.
ls_fieldcat-do_sum = &2.
ls_fieldcat-cfieldname = &3.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
ls_sort-subtot = &2.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_layout TYPE slis_layout_alv.
m_fieldcat 'VKORG' '' ''.
m_fieldcat 'KUNNR' '' ''.
m_fieldcat 'VBELN' '' ''.
m_fieldcat 'NETWR' 'X' 'WAERK'.
m_fieldcat 'WAERK' '' ''.
m_sort 'VKORG' 'X'. " Sort by vkorg and subtotal
m_sort 'KUNNR' 'X'. " Sort by kunnr and subtotal
m_sort 'VBELN' ''. " Sort by vbeln
ls_layout-cell_merge = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
TABLES
t_outtab = gt_vbak.
ENDFORM.
Check out these sample programs
BCALV_GRID_01
This program illustrates how the events for print processing PRINT_TOP_OF_PAGE,
PRINT_END_OF_PAGE, PRINT_TOP_OF_LIST,PRINT_END_OF_LIST are handled. The
corresponding handler methods control the appearance of the list printed.
BCALV_GRID_02
Show a detail list in an amodal window. There is no second dynro needed in contrast to
BCALV_GRID_03.
BCALV_GRID_03
This program implements a function on event DOUBLE_CLICK. According to the selected line data
from table SBOOK is selected and displayed by a second ALV Control in a dialog dynpro.
BCALV_GRID_04
Illustrates the use of exceptions (lights or leds). According to the values of SFLIGHT-SEATSOCC, the
lights are set to 1 (red), 2 (yellow) or 3 (green).
BCALV_GRID_05
Demonstrate the creation of an own toolbar button.
BCALV_GRID_06
Demonstrate the creation of an own context menu.
BCALV_GRID_07
Append a menu button to the standard toolbar.
BCALV_GRID_08
Append a menu with default button to the standard toolbar. It is exactly the same as
BCALVC_TB_WITH_MENU except for methods HANDLE_MENU_BUTTON and HANDLE_TOOLBAR.
Editable ALV grids
BCALV_EDIT_01
This report illustrates the simplest case of using an editable/noneditable ALV Grid Control.
BCALV_EDIT_02
This report illustrates how to set chosen cells of an ALV Grid Control editable.
BCALV_EDIT_03
In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.
The report checks the input value(s) semantically and provides protocol messages in case of error
BCALV_EDIT_04
This report illustrates how to add and remove lines to a table using the ALV Grid Control and how to
implement the saving of the new data.
BCALV_EDIT_05
This example shows how to use checkboxes within an ALV Grid Control. You learn:
(1) how to define a column for editable checkboxes for an attribute of your list
(2) how to evaluate the checked checkboxes
(3) how to switch between editable and non-editable checkboxes
BCALV_EDIT_06
This example shows how to define a dropdown listbox for all cells of one column in an editable ALV
Grid Control.
BCALV_EDIT_07
This example shows how to define dropdown listboxes for particular cells of your output table.
BCALV_EDIT_08
This report implements an ALV Grid Control with an application specific F4 help. The following aspects
are dealt with:
(1) how to replace the standard f4 help
(2) how to pass the selected value to the ALV Grid Control
(3) how to build an f4 help, whose value range depend on a value of another cell.
Check this link tooo
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/07/23/oopsALVin+ABAP&showComments=true
The ALV Grid Control is a tool with which you can output non-hierarchical lists in a
standardized format. The list data is displayed as a table on the screen.
The ALV Grid Control offers a range of interactive standard list functions that users need
frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list,
export list (in different formats), and so on. These functions are implemented in the
proxy object class. You as the programmer have the possibility to turn off functions not
needed. In most cases the implementations of the standard functions provided by the
control are sufficient. However, if required, you can adjust these implementations to
meet application-specific needs.
You can add self-defined functions to the toolbar, if necessary.
The ALV Grid Control allows users to adjust the layout of lists to meet their individual
requirements (for example, they can swap columns, hide columns, set filters for the
data to be displayed, calculate totals, and so on). The settings (list customizing) made
by a specific user are called a display variant. Display variants can be saved on a userspecific
or on a global basis. If such display variants exist for a list, they can be offered
to the user for selection. If a display variant is set as the default variant, the associated
list is always displayed based on the settings of this variant.
2. REUSE_ALV_LIST_DISPLAY
REUSE_ALV_GRID_DISPLAY
REUSE_ALV_FIELDCATALOG_MERGE
REUSE_ALV_COMMENTARY_WRITE
3. Use of Field Catalog is to determines the technical properties & add formating information of the column.
6. all the definition of internal table, structure, constants are declared in a type-pool called SLIS.
7.fieldcat-fieldname
fieldcat-ref_fieldname
fieldcat-tabname
fieldcat-seltext_m
5. Form user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield.
Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length.
In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output.
The report output can contain up to 90 columns in the display with the wide array of display options.
The commonly used ALV functions used for this purpose are;
1. REUSE_ALV_VARIANT_DEFAULT_GET
2. REUSE_ALV_VARIANT_F4
3. REUSE_ALV_VARIANT_EXISTENCE
4. REUSE_ALV_EVENTS_GET
5. REUSE_ALV_COMMENTARY_WRITE
6. REUSE_ALV_FIELDCATALOG_MERGE
7. REUSE_ALV_LIST_DISPLAY
8. REUSE_ALV_GRID_DISPLAY
9. REUSE_ALV_POPUP_TO_SELECT
Purpose of the above Functions are differ not all the functions are required in all the ALV Report.
But either no.7 or No.8 is there in the Program.
How you call this function in your report?
After completion of all the data fetching from the database and append this data into an Internal Table. say I_ITAB.
Then use follwing function module.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Prog.name'
I_STRUCTURE_NAME = 'I_ITAB'
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = I_ITAB.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.
ENDFORM. " GET_FINAL_DATA
The object F_IT_ALV has a field, the activity ACTVT, which can
contain four permitted values: 01, 02, 03 and 70. Each of the
activities 01, 02 and 70 controls the availability of particular
functions (in the menu and the toolbar) of the ALV line item list:
a) 01: "Settings -> Display variant -> Save..."
b) 02: "Settings -> Display variant -> Current..." and
"Settings -> Display variant -> Current header rows "
c) 70: "Settings -> Display variant -> Administration..."
Activity 03 corresponds to the minimum authorization, which is the
most restricted one: The user can only select layouts which have
been configured already. In particular, all of the other functions
named above are inactive with activity 03.
Now if you want to permit a user to change the column selection and
the headers as well as to save the layout thus created, for example,
but if you do not want to permit the user to administrate the
layouts, you grant him or her the authorization for activities 01
and 02.
Check this link it will be mosty usefull for u
http://www.sap-img.com/fu017.htm
check this link
http://abapprogramming.blogspot.com/
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5dc3e690-0201-0010-1ebf-b85b3bed962d
Changing width of a custom container dynamically
Display Page numbers in ALV
Insert picture in selection screen.
Logo in OO ALV Grid
check these links
http://www.sapfans.com/forums/viewtopic.php?t=20386
http://www.sapfans.com/forums/viewtopic.php?t=85191
http://www.sapfans.com/forums/viewtopic.php?t=88401
http://www.sapfans.com/forums/viewtopic.php?t=17335
Try these links
Simple ALV report
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
ALV
1. Please give me general info on ALV.
http://www.sapfans.com/forums/viewtopic.php?t=58286
http://www.sapfans.com/forums/viewtopic.php?t=76490
http://www.sapfans.com/forums/viewtopic.php?t=20591
http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
2. How do I program double click in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=11601
http://www.sapfans.com/forums/viewtopic.php?t=23010
3. How do I add subtotals (I have problem to add them)...
http://www.sapfans.com/forums/viewtopic.php?t=20386
http://www.sapfans.com/forums/viewtopic.php?t=85191
http://www.sapfans.com/forums/viewtopic.php?t=88401
http://www.sapfans.com/forums/viewtopic.php?t=17335
4. How to add list heading like top-of-page in ABAP lists?
http://www.sapfans.com/forums/viewtopic.php?t=58775
http://www.sapfans.com/forums/viewtopic.php?t=60550
http://www.sapfans.com/forums/viewtopic.php?t=16629
5. How to print page number / total number of pages X/XX in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
http://www.sapfans.com/forums/viewtopic.php?t=64320
http://www.sapfans.com/forums/viewtopic.php?t=44477
7. How can I set the cell color in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=52107
8. How do I print a logo/graphics in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=81149
http://www.sapfans.com/forums/viewtopic.php?t=35498
http://www.sapfans.com/forums/viewtopic.php?t=5013
9. How do I create and use input-enabled fields in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=84933
http://www.sapfans.com/forums/viewtopic.php?t=69878
10. How can I use ALV for reports that are going to be run in background?
http://www.sapfans.com/forums/viewtopic.php?t=83243
http://www.sapfans.com/forums/viewtopic.php?t=19224
11. How can I display an icon in ALV? (Common requirement is traffic light icon).
http://www.sapfans.com/forums/viewtopic.php?t=79424
http://www.sapfans.com/forums/viewtopic.php?t=24512
12. How can I display a checkbox in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=88376
http://www.sapfans.com/forums/viewtopic.php?t=40968
http://www.sapfans.com/forums/viewtopic.php?t=6919
For More alv report examples check these Tcodes LIBS, BIBS Here u can find more number of examples on alv reports of different kinds
check this sample code for intercative alv report
TYPE-POOLS: SLIS.
*type declaration for values from ekko
TYPES: BEGIN OF I_EKKO,
EBELN LIKE EKKO-EBELN,
AEDAT LIKE EKKO-AEDAT,
BUKRS LIKE EKKO-BUKRS,
BSART LIKE EKKO-BSART,
LIFNR LIKE EKKO-LIFNR,
END OF I_EKKO.
DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0,
WA_EKKO TYPE I_EKKO.
*type declaration for values from ekpo
TYPES: BEGIN OF I_EKPO,
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MATNR LIKE EKPO-MATNR,
MENGE LIKE EKPO-MENGE,
MEINS LIKE EKPO-MEINS,
NETPR LIKE EKPO-NETPR,
END OF I_EKPO.
DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0,
WA_EKPO TYPE I_EKPO .
*variable for Report ID
DATA: V_REPID LIKE SY-REPID .
*declaration for fieldcatalog
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.
declaration for events table where user comand or set PF status will
be defined
DATA: V_EVENTS TYPE SLIS_T_EVENT,
WA_EVENT TYPE SLIS_ALV_EVENT.
declartion for layout
DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
declaration for variant(type of display we want)
DATA: I_VARIANT TYPE DISVARIANT,
I_VARIANT1 TYPE DISVARIANT,
I_SAVE(1) TYPE C.
*PARAMETERS : p_var TYPE disvariant-variant.
*Title displayed when the alv list is displayed
DATA: I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.
DATA: I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.
INITIALIZATION.
V_REPID = SY-REPID.
PERFORM BUILD_FIELDCATLOG.
PERFORM EVENT_CALL.
PERFORM POPULATE_EVENT.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_REPORT.
*& Form BUILD_FIELDCATLOG
Fieldcatalog has all the field details from ekko
FORM BUILD_FIELDCATLOG.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'EBELN'.
WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'AEDAT'.
WA_FIELDCAT-SELTEXT_M = 'DATE.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'LIFNR'.
WA_FIELDCAT-NO_OUT = 'X'.
WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "BUILD_FIELDCATLOG
*& Form EVENT_CALL
we get all events - TOP OF PAGE or USER COMMAND in table v_events
FORM EVENT_CALL.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "EVENT_CALL
*& Form POPULATE_EVENT
Events populated for TOP OF PAGE & USER COMAND
FORM POPULATE_EVENT.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'USER_COMMAND'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-NAME.
ENDIF.
ENDFORM. "POPULATE_EVENT
*& Form data_retrieval
retreiving values from the database table ekko
FORM DATA_RETRIEVAL.
SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE IT_EKKO.
ENDFORM. "data_retrieval
*& Form bUild_listheader
text
-->I_LISTHEADEtext
FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA HLINE TYPE SLIS_LISTHEADER.
HLINE-INFO = 'this is my first alv pgm'.
HLINE-TYP = 'H'.
ENDFORM. "build_listheader
*& Form display_alv_report
text
FORM DISPLAY_ALV_REPORT.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = I_TITLE_EKKO
I_GRID_SETTINGS =
IS_LAYOUT = ALV_LAYOUT
IT_FIELDCAT = I_FIELDCAT[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
i_default = 'ZLAY1'
I_SAVE = 'A'
is_variant = i_variant
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = IT_EKKO
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "display_alv_report
*& Form TOP_OF_PAGE
text
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
i_logo =
I_END_OF_LIST_GRID =
ENDFORM. "TOP_OF_PAGE
*& Form USER_COMMAND
text
-->R_UCOMM text
-->, text
-->RS_SLEFIELDtext
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.
PERFORM BUILD_FIELDCATLOG_EKPO.
PERFORM EVENT_CALL_EKPO.
PERFORM POPULATE_EVENT_EKPO.
PERFORM DATA_RETRIEVAL_EKPO.
PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_EKPO.
ENDCASE.
ENDFORM. "user_command
*& Form BUILD_FIELDCATLOG_EKPO
text
FORM BUILD_FIELDCATLOG_EKPO.
WA_FIELDCAT-TABNAME = 'IT_EKPO'.
WA_FIELDCAT-FIELDNAME = 'EBELN'.
WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKPO'.
WA_FIELDCAT-FIELDNAME = 'EBELP'.
WA_FIELDCAT-SELTEXT_M = 'LINE NO'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MENGE'.
WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-SELTEXT_M = 'UOM'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'NETPR'.
WA_FIELDCAT-SELTEXT_M = 'PRICE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "BUILD_FIELDCATLOG_EKPO
*& Form event_call_ekpo
we get all events - TOP OF PAGE or USER COMMAND in table v_events
FORM EVENT_CALL_EKPO.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH -
Alv using class In list format
Hi,
I am using a method set_table_for_first_display in class cl_gui_alv_grid to display ALV. but by default the output appears in grid format, I want to change the output in LIST format.
What can I do to change the output in list format.
Kind Regards,
Abhishek.try this.... this is an example code.... don't use set_table_for_first_display rather use CL_SALV_TABLE and execute the below code
*& Report ZAMIT_TEST
REPORT zamit_test MESSAGE-ID z_zzz_ca_messages.
* constants for icons
TYPE-POOLS: icon, col.
* type for internal table
TYPES: BEGIN OF x_sflight.
* selfld TYPE char1.
INCLUDE STRUCTURE sflight.
TYPES: seatsfree TYPE sflight-seatsocc,
usage TYPE n, " exception
icon_future TYPE icon-id, " icon for future / past
line_counter TYPE i, " line counter
it_colors TYPE lvc_t_scol, " internal tab for cell color info
END OF x_sflight.
* Internal table
DATA: i_sflight TYPE STANDARD TABLE OF x_sflight,
wa_sflight TYPE x_sflight,
wa_colors TYPE lvc_s_scol,
list_display TYPE sap_bool,
vref_cont TYPE REF TO cl_gui_custom_container,
vref_alv TYPE REF TO cl_salv_table, " ALV instance
oref_error TYPE REF TO cx_salv_error, " Error instance
l_text_alv_e TYPE string,
ok_code TYPE syucomm.
SELECT-OPTIONS: so_car FOR wa_sflight-carrid MEMORY ID car,
so_con FOR wa_sflight-connid.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK alv WITH FRAME TITLE text-alv.
PARAMETERS: pa_full RADIOBUTTON GROUP alvd DEFAULT 'X',
pa_cont RADIOBUTTON GROUP alvd,
pa_list RADIOBUTTON GROUP alvd.
SELECTION-SCREEN END OF BLOCK alv.
PARAMETERS: p_layout TYPE slis_vari.
* CLASS lcl_handler DEFINITION
CLASS lcl_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
on_added_function FOR EVENT added_function OF cl_salv_events_table
IMPORTING e_salv_function, " type salv_de_function
on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row, " type salv_de_row = int4
on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row " type salv_de_row = int4
column." type salv_de_column = char(30)
ENDCLASS. "lcl_handler definition
* CLASS lcl_handler IMPLEMENTATION
CLASS lcl_handler IMPLEMENTATION.
METHOD on_added_function.
DATA: l_oref_columns TYPE REF TO cl_salv_columns_table,
l_oref_column TYPE REF TO cl_salv_column_table,
l_oref_column1 TYPE REF TO cl_salv_column,
l_except1 TYPE REF TO cx_salv_not_found, "Exception
l_text1 TYPE string, "Exception msg
l_lvc_s_colo TYPE lvc_s_colo.
CASE e_salv_function.
WHEN 'REORDER'.
* get the COLUMNS object
l_oref_columns = vref_alv->get_columns( ).
* positions: (MANDT column + 3 key colums)
l_oref_columns->set_column_position( columnname = 'SEATSOCC'
position = 5 ).
l_oref_columns->set_column_position( columnname = 'SEATSOCC_B'
position = 6 ).
l_oref_columns->set_column_position( columnname = 'SEATSOCC_F'
position = 7 ).
* prepare color info
* column SEATSOCC
TRY.
CALL METHOD l_oref_columns->get_column
EXPORTING
columnname = 'SEATSOCC'
RECEIVING
value = l_oref_column1.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
l_oref_column ?= l_oref_column1.
l_oref_column->set_color( value = l_lvc_s_colo ).
* column SEATSOCC_B
TRY.
CALL METHOD l_oref_columns->get_column
EXPORTING
columnname = 'SEATSOCC_B'
RECEIVING
value = l_oref_column1.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
l_oref_column ?= l_oref_column1.
l_oref_column->set_color( value = l_lvc_s_colo ).
* column SEATSOCC_F
TRY.
CALL METHOD l_oref_columns->get_column
EXPORTING
columnname = 'SEATSOCC_F'
RECEIVING
value = l_oref_column1.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
l_oref_column ?= l_oref_column1.
l_oref_column->set_color( value = l_lvc_s_colo ).
ENDCASE.
ENDMETHOD. "on_added_function
METHOD on_double_click.
DATA: message_text(70),
lc_seatsfree_e(10),
lc_seatsfree_b(10),
lc_seatsfree_f(10).
READ TABLE i_sflight INTO wa_sflight INDEX row.
CHECK sy-subrc EQ 0.
lc_seatsfree_e = wa_sflight-seatsmax - wa_sflight-seatsocc.
lc_seatsfree_b = wa_sflight-seatsmax_b - wa_sflight-seatsocc_b.
lc_seatsfree_f = wa_sflight-seatsmax_f - wa_sflight-seatsocc_f.
CONCATENATE 'FREE SEATS:'(frs) 'ECONOMY:'(eco) lc_seatsfree_e
'BUSINESS'(bus) lc_seatsfree_b 'FIRST'(fst) lc_seatsfree_f
INTO message_text SEPARATED BY space.
MESSAGE message_text TYPE 'I'.
ENDMETHOD. "on_double_click
METHOD on_link_click.
DATA: lc_carrname TYPE scarr-carrname,
lc_currcode TYPE scarr-currcode,
message_text(70).
READ TABLE i_sflight INTO wa_sflight INDEX row.
CHECK sy-subrc EQ 0.
CASE column.
WHEN 'CARRID'.
SELECT SINGLE carrname currcode
INTO (lc_carrname, lc_currcode)
FROM scarr
WHERE carrid = wa_sflight-carrid.
IF sy-subrc EQ 0.
CONCATENATE 'AIRLINE:'(air) wa_sflight-carrid
'NAME:'(nme) lc_carrname
'CURRENCY:' lc_currcode
INTO message_text
SEPARATED BY space.
MESSAGE message_text TYPE 'I'.
ENDIF.
WHEN 'SELFLD'.
MESSAGE i000 with 'Checkbox Clicked'.
ENDCASE.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_handler IMPLEMENTATION
START-OF-SELECTION.
* retrieve data into internal table
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE i_sflight
WHERE carrid IN so_car
AND connid IN so_con.
END-OF-SELECTION.
* fill additional data fields
LOOP AT i_sflight INTO wa_sflight.
* seats free
wa_sflight-seatsfree =
wa_sflight-seatsmax + wa_sflight-seatsmax_b
+ wa_sflight-seatsmax_f
- wa_sflight-seatsocc - wa_sflight-seatsocc_b
- wa_sflight-seatsocc_f.
* usage (exception light)
IF wa_sflight-seatsfree = 0.
wa_sflight-usage = '1'.
ELSEIF wa_sflight-seatsfree <= 20.
wa_sflight-usage = '2'.
ELSE.
wa_sflight-usage = '3'.
ENDIF.
* icon "in the future/not in the future"
IF wa_sflight-fldate > sy-datum.
wa_sflight-icon_future = icon_positive.
ELSE.
wa_sflight-icon_future = icon_negative.
ENDIF.
* cell colors
* single cell if planetype is 747-400
IF wa_sflight-planetype = '747-400'.
CLEAR wa_colors.
wa_colors-fname = 'PLANETYPE'.
wa_colors-color-col = col_positive.
wa_colors-color-int = 1.
APPEND wa_colors TO wa_sflight-it_colors.
ENDIF.
* whole line if seatsfree gt 200
IF wa_sflight-seatsfree >= 200.
CLEAR wa_colors.
wa_colors-color-col = col_heading.
wa_colors-color-int = 1.
APPEND wa_colors TO wa_sflight-it_colors.
ENDIF.
MODIFY i_sflight
FROM wa_sflight
TRANSPORTING
seatsfree
usage
icon_future
it_colors.
ENDLOOP.
CASE 'X'.
WHEN pa_full OR pa_list.
IF pa_list IS NOT INITIAL.
list_display = if_salv_c_bool_sap=>true.
ELSE.
list_display = if_salv_c_bool_sap=>false.
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = list_display
IMPORTING
r_salv_table = vref_alv
CHANGING
t_table = i_sflight.
CATCH cx_salv_msg INTO oref_error.
l_text_alv_e = oref_error->get_text( ).
MESSAGE i000 WITH l_text_alv_e.
LEAVE LIST-PROCESSING.
ENDTRY.
* define settings
PERFORM define_settings USING vref_alv.
* display ALV
vref_alv->display( ).
WHEN pa_cont.
CALL SCREEN 100.
ENDCASE.
*& Form define_settings
* text
* -->P_ALV ALV object
FORM define_settings USING p_alv TYPE REF TO cl_salv_table.
PERFORM: sub_set_display USING p_alv,
sub_set_columns USING p_alv,
sub_set_sorts USING p_alv,
sub_set_aggregs USING p_alv,
sub_set_selections USING p_alv,
sub_set_layout USING p_alv,
sub_set_functions USING p_alv,
sub_set_events USING p_alv,
sub_set_header USING p_alv.
ENDFORM. " define_settings
*& Form sub_set_display
* set general display attributs
* -->P_ALV ALV object
FORM sub_set_display USING p_alv TYPE REF TO cl_salv_table.
DATA: lr_display TYPE REF TO cl_salv_display_settings,
l_title TYPE lvc_title.
* get display settings object
lr_display = p_alv->get_display_settings( ).
* set header
l_title = text-ttl.
lr_display->set_list_header( value = text-ttl ).
* set horizontal lines off
lr_display->set_horizontal_lines( value = ' ' ).
* set striped pattern
lr_display->set_striped_pattern( value = 'X' ).
ENDFORM. " sub_set_display
*& Form sub_set_columns
* text
* -->P_ALV text
FORM sub_set_columns USING p_alv TYPE REF TO cl_salv_table.
DATA: l_oref_columns TYPE REF TO cl_salv_columns_table,
l_oref_column TYPE REF TO cl_salv_column_table,
l_oref_column1 TYPE REF TO cl_salv_column,
l_except1 TYPE REF TO cx_salv_not_found, "Exception
l_except2 TYPE REF TO cx_salv_data_error, "Exception
l_text1 TYPE string, "Exception msg
l_scrtext_s TYPE scrtext_s,
l_scrtext_m TYPE scrtext_m,
l_scrtext_l TYPE scrtext_l,
l_lvc_tip TYPE lvc_tip, " for tooltip
l_pos TYPE i, " column position
l_lvc_s_colo TYPE lvc_s_colo. " column color
l_oref_columns = p_alv->get_columns( ). " get columns object
* set exception column
TRY.
CALL METHOD l_oref_columns->set_exception_column
EXPORTING
value = 'USAGE'.
CATCH cx_salv_data_error INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
* set count column
TRY.
CALL METHOD l_oref_columns->set_count_column
EXPORTING
value = 'LINE_COUNTER'.
CATCH cx_salv_data_error INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
* set cell colors / line colors column
TRY.
CALL METHOD l_oref_columns->set_color_column
EXPORTING
value = 'IT_COLORS'.
CATCH cx_salv_data_error INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
* column ICON_FUTURE
TRY.
CALL METHOD l_oref_columns->get_column
EXPORTING
columnname = 'ICON_FUTURE'
RECEIVING
value = l_oref_column1.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
l_oref_column ?= l_oref_column1.
l_oref_column->set_icon( ).
l_scrtext_s = text-fut.
l_oref_column->set_short_text( value = l_scrtext_s ).
l_oref_column->set_row( value = 2 ).
* Column SEATSFREE
TRY.
CALL METHOD l_oref_columns->get_column
EXPORTING
columnname = 'SEATSFREE'
RECEIVING
value = l_oref_column1.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
l_oref_column ?= l_oref_column1.
* set color to COL_GROUP
l_lvc_s_colo-col = col_group.
l_lvc_s_colo-int = 1.
l_oref_column->set_color( value = l_lvc_s_colo ).
** Column SELFLD
* TRY.
* CALL METHOD l_oref_columns->get_column
* EXPORTING
* columnname = 'SELFLD'
* RECEIVING
* value = l_oref_column1.
* CATCH cx_salv_not_found INTO l_except1.
* l_text1 = l_except1->get_text( ).
* MESSAGE i000 WITH l_text1.
* LEAVE LIST-PROCESSING.
* ENDTRY.
* l_oref_column ?= l_oref_column1.
** set color to COL_GROUP
* if pa_list = 'X'.
* l_oref_column->set_cell_type( value =
* if_salv_c_cell_type=>CHECKBOX ).
* ELSEIF pa_full = 'X'.
* l_oref_column->set_cell_type( value =
* if_salv_c_cell_type=>CHECKBOX_HOTSPOT ).
* endif.
ENDFORM. "sub_set_columns
*& Form sub_set_sorts
* -->P_ALV text
FORM sub_set_sorts USING p_alv TYPE REF TO cl_salv_table.
DATA: l_oref_sorts TYPE REF TO cl_salv_sorts,
l_except1 TYPE REF TO cx_salv_not_found, "Exception
l_except2 TYPE REF TO cx_salv_existing, "Exception
l_except3 TYPE REF TO cx_salv_data_error, "Exception
l_text1 TYPE string. "Exception msg
* get the SORTS object
l_oref_sorts = p_alv->get_sorts( ).
* add sorts
TRY.
CALL METHOD l_oref_sorts->add_sort
EXPORTING
columnname = 'CARRID'
position = 1.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_existing INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_data_error INTO l_except3.
l_text1 = l_except3->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
TRY.
CALL METHOD l_oref_sorts->add_sort
EXPORTING
columnname = 'CONNID'
position = 2
subtotal = if_salv_c_bool_sap=>true.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_existing INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_data_error INTO l_except3.
l_text1 = l_except3->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
TRY.
CALL METHOD l_oref_sorts->add_sort
EXPORTING
columnname = 'FLDATE'
position = 3.
CATCH cx_salv_not_found INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_existing INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_data_error INTO l_except3.
l_text1 = l_except3->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
ENDFORM. " sub_set_sorts
*& Form sub_set_aggregs
* -->P_ALV text
FORM sub_set_aggregs USING p_alv TYPE REF TO cl_salv_table.
DATA: l_oref_aggregs TYPE REF TO cl_salv_aggregations,
l_except1 TYPE REF TO cx_salv_data_error, "Exception
l_except2 TYPE REF TO cx_salv_not_found, "Exception
l_except3 TYPE REF TO cx_salv_existing, "Exception
l_text1 TYPE string. "Exception msg
l_oref_aggregs = p_alv->get_aggregations( ).
TRY.
CALL METHOD l_oref_aggregs->add_aggregation
EXPORTING
columnname = 'SEATSFREE'
aggregation = if_salv_c_aggregation=>total.
CATCH cx_salv_data_error INTO l_except1.
l_text1 = l_except1->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_not_found INTO l_except2.
l_text1 = l_except2->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
CATCH cx_salv_existing INTO l_except3.
l_text1 = l_except3->get_text( ).
MESSAGE i000 WITH l_text1.
LEAVE LIST-PROCESSING.
ENDTRY.
ENDFORM. " sub_set_aggregs
*& Form sub_set_selections
* -->P_ALV text
FORM sub_set_selections USING p_alv TYPE REF TO cl_salv_table.
DATA: lr_selections TYPE REF TO cl_salv_selections.
* get the SELECTIONS object
lr_selections = p_alv->get_selections( ).
* set the selection mode
lr_selections->set_selection_mode(
value = if_salv_c_selection_mode=>cell ).
ENDFORM. " sub_set_selections
*& Form sub_set_layout
* -->P_ALV text
FORM sub_set_layout USING p_alv TYPE REF TO cl_salv_table.
DATA: lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key.
* get the LAYOUT object
lr_layout = p_alv->get_layout( ).
* set the layout key
ls_key-report = sy-cprog.
lr_layout->set_key( value = ls_key ).
* set save restriction
* (restriction "none" is intended,
* so we may use the default)
lr_layout->set_save_restriction(
* VALUE = IF_SALV_C_LAYOUT=>RESTRICT_NONE
* allow setting a default layout
lr_layout->set_default( value = 'X' ).
* set initial layout
lr_layout->set_initial_layout( value = p_layout ).
ENDFORM. " sub_set_layout
*& Form sub_set_functions
* -->P_ALV text
FORM sub_set_functions USING p_alv TYPE REF TO cl_salv_table.
DATA: lr_functions TYPE REF TO cl_salv_functions_list,
l_except1 TYPE REF TO cx_salv_existing,
l_except2 TYPE REF TO cx_salv_wrong_call,
l_text1 TYPE string,
* help variables for method call ADD_FUNCTION
l_icon TYPE string,
l_text TYPE string,
l_tooltip TYPE string.
IF pa_full = 'X' or pa_list = 'X'.
p_alv->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD'
report = sy-repid
set_functions = p_alv->c_functions_all ).
ENDIF.
* get the FUNCTIONS object
lr_functions = p_alv->get_functions( ).
* offer all generic functions
lr_functions->set_all( value = if_salv_c_bool_sap=>true ).
* subtract average
lr_functions->set_aggregation_average(
value = if_salv_c_bool_sap=>false ).
* subtract all export functions
lr_functions->set_group_export(
value = if_salv_c_bool_sap=>false ).
* enable exort to local file
lr_functions->set_export_localfile(
value = if_salv_c_bool_sap=>true ).
* subtract transfer to lotus
lr_functions->set_view_lotus(
value = if_salv_c_bool_sap=>false ).
* customer defined function:
* display occupied seats columns most left
* and highlight them
* IF pa_cont = 'X'.
* l_icon = icon_insert_row.
* l_text = text-tot.
* l_tooltip = text-ttt.
* TRY.
* CALL METHOD lr_functions->add_function
* EXPORTING
* name = 'REORDER'
* icon = l_icon
* text = l_text
* tooltip = l_tooltip
* position = if_salv_c_function_position=>right_of_salv_functions.
* CATCH cx_salv_existing INTO l_except1.
* l_text1 = l_except1->get_text( ).
* MESSAGE i000 WITH l_text1.
* LEAVE LIST-PROCESSING.
* CATCH cx_salv_wrong_call INTO l_except2.
* l_text1 = l_except2->get_text( ).
* MESSAGE i000 WITH l_text1.
* LEAVE LIST-PROCESSING.
* ENDTRY.
* ENDIF.
ENDFORM. " sub_set_functions
*& Form sub_set_events
* text
* -->P_ALV text
FORM sub_set_events USING p_alv TYPE REF TO cl_salv_table.
DATA: lr_event TYPE REF TO cl_salv_events_table.
* get the EVENT object
lr_event = p_alv->get_event( ).
SET HANDLER :
lcl_handler=>on_added_function FOR lr_event,
lcl_handler=>on_double_click FOR lr_event,
lcl_handler=>on_link_click FOR lr_event.
ENDFORM. " sub_set_events
*& Form sub_set_header
* -->P_ALV text
FORM sub_set_header
USING p_alv TYPE REF TO cl_salv_table.
DATA: lr_grid TYPE REF TO cl_salv_form_layout_grid.
* 1st step: create the grid object
CREATE OBJECT lr_grid.
* 2nd step: add some text items
lr_grid->create_header_information( row = 1 column = 1
text = 'Flight List Grp ##'(fll) ).
lr_grid->create_text( row = 2 column = 1
text = 'Please check utilization'(uti) ).
* 3rd step: declare grid as header of list
p_alv->set_top_of_list( value = lr_grid ).
ENDFORM. " sub_set_header
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SALV_TABLE_STANDARD'.
SET TITLEBAR 'T100'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module create_control OUTPUT
* text
MODULE create_control OUTPUT.
IF vref_cont IS NOT BOUND.
* create container control
* and link it to the dynpro
CREATE OBJECT vref_cont
EXPORTING
container_name = 'MY_CONTAINER'
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Error when creating the container object'.
ENDIF.
* create ALV and
* link it to the container control
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = vref_cont
IMPORTING
r_salv_table = vref_alv
CHANGING
t_table = i_sflight ).
CATCH cx_salv_msg INTO oref_error.
l_text_alv_e = oref_error->get_text( ).
MESSAGE i000 WITH l_text_alv_e.
LEAVE LIST-PROCESSING.
ENDTRY.
* display ALV
vref_alv->display( ).
ENDIF.
ENDMODULE. " create_control OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
SET SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module exit INPUT
* text
MODULE exit INPUT.
SET SCREEN 0.
ENDMODULE. " exit INPUT -
Reg..ALV using classes
i have displayed a ALV report with a push button 'HST'.
When i select a particular line(vbeln) and click on pushbutton 'HST' it has to display me a interactive report based on the condition vbeln and posnr.
can anyone help me with the detail code using classes..
answers will be rewarded....
regards,
kumarHi,
Class ALV Specification
Classes used:
CL_GUI_ALV_GRID
Example of ALV using Classes
DATA: lcl_alv TYPE REF TO cl_gui_alv_grid,
t_flights TYPE STANDARD TABLE OF FLIGHTS.
SELECT * FROM flights INTO TABLE t_flights.
CREATE OBJECT lcl_alv
EXPORTING I_PARENT = cl_gui_container=>screen0.
CALL METHOD lcl_alv->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME = 'FLIGHTS'
CHANGING
IT_OUTTAB = t_flights.
CALL SCREEN 100.
Example Details
This is a simple example of the class ALV, we do not need to create, in this case, a field catalog because we are using the whole table of FLIGHTS and we will show all the fields that this table contains, we do this at the I_STRUCTURE_NAME = 'FLIGHTS' statement.
The CL_GUI_ALV_GRID constructor needs the I_PARENT parameter to define where it will be show, in the example we set the entire screen to place the ALV.
reward if helpful -
List display for ALV using class and methods
Hi friends
I want the list display for the ALV using Class and methods
which class and methods i can use.
Here we can't use the REUSE_ALV_LIST_DISPLAY and also GRID
I was done GRID display using class and methods but i want only list display for using class.
plz Give me sample code of list display not for grid.
Thanks
Nani.hi
please check with this code...
declare grid and container.
DATA : o_alvgrid TYPE REF TO cl_gui_alv_grid,
o_dockingcontainer TYPE REF TO cl_gui_docking_container,
i_fieldcat TYPE lvc_t_fcat,"fieldcatalogue
w_layout TYPE lvc_s_layo."layout
If any events like double click,etc., are needed we have to add additional functionality.
call the screen in program.
Then , create the container as follows
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CREATE OBJECT o_dockingcontainer
EXPORTING
ratio = '95'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
ENDIF.
CREATE OBJECT o_alvgrid
EXPORTING
i_parent = o_dockingcontainer.
Build the fieldcatalog
create a output structure in SEll for the ALV output
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = <alv output>
CHANGING
ct_fieldcat = i_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE i030."Error in building the field catalogue
LEAVE LIST-PROCESSING.
ENDIF.
*If you need to modify the field catalog,modify it using field sysmbols
*setting the layout
w_layout-grid_title = title.
w_layout-zebra = 'X'.
then displaying the output
CALL METHOD o_alvgrid->set_table_for_first_display
EXPORTING
i_save = 'A'
is_layout = w_layout
CHANGING
it_outtab = i_output[]
it_fieldcatalog = i_fieldcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE i032 ."Error in Displaying
LEAVE LIST-PROCESSING.
ENDIF.
*After that in PAI of the screen, you need to free the *object while going back from the screen(according to *your requirement)
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
PERFORM f9600_free_objects:
USING o_alvgrid 'ALV' text-e02,
USING o_dockingcontainer 'DOCKING'
text-e01.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
*in the program, write the follwoing code
FORM f9600_free_objects USING pobject
value(ptype)
value(ptext).
DATA: l_objectalv TYPE REF TO cl_gui_alv_grid.
CASE ptype.
WHEN 'ALV'.
l_objectalv = pobject.
IF NOT ( l_objectalv IS INITIAL ).
CALL METHOD l_objectalv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, l_objectalv.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'DOCKING'.
DATA: lobjectdock TYPE REF TO cl_gui_docking_container.
lobjectdock = pobject.
IF NOT ( lobjectdock IS INITIAL ).
CALL METHOD lobjectdock->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectdock.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'CONTAINER'.
DATA: lobjectcontainer TYPE REF TO cl_gui_container.
lobjectcontainer = pobject.
IF NOT ( lobjectcontainer IS INITIAL ).
CALL METHOD lobjectcontainer->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectcontainer.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN OTHERS.
sy-subrc = 1.
PERFORM f9700_error_handle USING
text-e04.
ENDCASE.
ENDFORM. " f9600_free_objects
FORM f9700_error_handle USING value(ptext).
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-e03
txt2 = sy-subrc
txt1 = ptext.
ENDIF.
endform.
also check with this
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
Hope this helps
if it helped, you can acknowledge the same by rewarding
regards
dinesh -
Hi,
Does any one have code or pointers for creating a ALV with top of page using OOPS.
I need to create a top of page with variables like :
Report Name : ZABC
User Name : Z234ASD
Date : System Date
Time : System Time
Transaction : ZXYZ
Thanks
Khan.The code i used to implement top of page for OO ALV is as below but when you proceed to print out the report, it doesn't print out the header as the list output doesn't show the header.
codeREPORT ZTEST1234_ALV_TOP MESSAGE-ID ZZ .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: L_VALID TYPE C,
V_FLAG,
V_DATA_CHANGE,
V_ROW TYPE LVC_S_ROW,
V_COLUMN TYPE LVC_S_COL,
V_ROW_NUM TYPE LVC_S_ROID.
"The Below Definitions Must.....
DATA:
Reference to document
DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,
Reference to split container
DG_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
Reference to grid container
DG_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,
Reference to html container
DG_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER,
Reference to html container
DG_PARENT_HTML TYPE REF TO CL_GUI_CONTAINER.
"up to here
CLASS lcl_event_handler DEFINITION
CLASS LCL_EVENT_HANDLER DEFINITION .
PUBLIC SECTION .
METHODS:
**Hot spot Handler
HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Double Click Handler
HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN ES_ROW_NO,
TOP_OF_PAGE FOR EVENT TOP_OF_PAGE "event handler
OF CL_GUI_ALV_GRID
IMPORTING E_DYNDOC_ID.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*Handle Hotspot Click
METHOD HANDLE_HOTSPOT_CLICK .
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW_ID.
V_COLUMN = E_COLUMN_ID.
V_ROW_NUM = ES_ROW_NO.
MESSAGE I000 WITH V_ROW 'clicked'.
ENDMETHOD. "lcl_event_handler
*Handle Double Click
METHOD HANDLE_DOUBLE_CLICK.
ENDMETHOD. "handle_double_click
METHOD TOP_OF_PAGE. "implementation
Top-of-page event
PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
ENDMETHOD. "top_of_page
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION
*& Global Definitions
DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1
G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler
DATA: OK_CODE LIKE SY-UCOMM,
SAVE_OK LIKE SY-UCOMM,
G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
GS_LAYOUT TYPE LVC_S_LAYO.
Fieldcatalog for First and second Report
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
X_FIELDCAT TYPE LVC_S_FCAT,
LS_VARI TYPE DISVARIANT.
START-OF_SELECTION
START-OF-SELECTION.
DATA:BEGIN OF ITAB OCCURS 0,
VBELN LIKE LIKP-VBELN,
POSNR LIKE LIPS-POSNR,
CELLCOLOR TYPE LVC_T_SCOL, "required for color
DROP(10),
END OF ITAB.
SELECT VBELN
POSNR
FROM LIPS
UP TO 20 ROWS
INTO CORRESPONDING FIELDS OF TABLE ITAB.
END-OF-SELECTION.
IF NOT ITAB[] IS INITIAL.
CALL SCREEN 100.
ELSE.
MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
ENDIF.
*& Form CREATE_AND_INIT_ALV
text
FORM CREATE_AND_INIT_ALV .
DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
"attention.....from here
"split your container here...into two parts
"create the container
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = G_CONTAINER1.
"this is for top of page
Create TOP-Document
CREATE OBJECT DG_DYNDOC_ID
EXPORTING STYLE = 'ALV_GRID'.
Create Splitter for custom_container
CREATE OBJECT DG_SPLITTER
EXPORTING PARENT = G_CUSTOM_CONTAINER
ROWS = 2
COLUMNS = 1.
Split the custom_container to two containers and move the reference
to receiving containers g_parent_html and g_parent_grid
"i am allocating the space for grid and top of page
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_HTML.
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_GRID.
"you can set the height of it
Set height for g_parent_html
CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
EXPORTING
ID = 1
HEIGHT = 5.
"from here as usual..you need to specify parent as splitter part
"which we alloted for grid
CREATE OBJECT G_GRID
EXPORTING I_PARENT = DG_PARENT_GRID.
Set a titlebar for the grid control
CLEAR GS_LAYOUT.
GS_LAYOUT-GRID_TITLE = TEXT-003.
GS_LAYOUT-ZEBRA = SPACE.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-NO_ROWMARK = 'X'.
GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
CREATE OBJECT G_HANDLER.
SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.
DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color
DATA: L_INDEX TYPE SY-TABIX.
"Here i am changing the color of line 1,5,10...
"so you can change the color of font conditionally
LOOP AT ITAB.
L_INDEX = SY-TABIX.
IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.
LS_CELLCOLOR-FNAME = 'VBELN'.
LS_CELLCOLOR-COLOR-COL = '6'.
LS_CELLCOLOR-COLOR-INT = '0'.
LS_CELLCOLOR-COLOR-INV = '1'.
APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
LS_CELLCOLOR-FNAME = 'POSNR'.
LS_CELLCOLOR-COLOR-COL = '6'.
LS_CELLCOLOR-COLOR-INT = '0'.
LS_CELLCOLOR-COLOR-INV = '1'.
APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
ENDIF.
ENDLOOP.
setting focus for created grid control
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = G_GRID.
Build fieldcat and set editable for date and reason code
edit enabled. Assign a handle for the dropdown listbox.
PERFORM BUILD_FIELDCAT.
PERFORM SET_DRDN_TABLE.
Optionally restrict generic functions to 'change only'.
(The user shall not be able to add new lines).
PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
**Vaiant to save the layout
LS_VARI-REPORT = SY-REPID.
LS_VARI-HANDLE = SPACE.
LS_VARI-LOG_GROUP = SPACE.
LS_VARI-USERNAME = SPACE.
LS_VARI-VARIANT = SPACE.
LS_VARI-TEXT = SPACE.
LS_VARI-DEPENDVARS = SPACE.
**Calling the Method for ALV output
CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
IS_VARIANT = LS_VARI
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB[].
"do these..{
Initializing document
CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.
Processing events
CALL METHOD G_GRID->LIST_PROCESSING_EVENTS
EXPORTING
I_EVENT_NAME = 'TOP_OF_PAGE'
I_DYNDOC_ID = DG_DYNDOC_ID.
"end }
Set editable cells to ready for input initially
CALL METHOD G_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.
ENDFORM. "CREATE_AND_INIT_ALV
*& Form EXCLUDE_TB_FUNCTIONS
text
-->PT_EXCLUDE text
FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
Only allow to change data not to create new entries (exclude
generic functions).
DATA LS_EXCLUDE TYPE UI_FUNC.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*& Form build_fieldcat
Fieldcatalog
FORM BUILD_FIELDCAT .
DATA: L_POS TYPE I.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_FINAL'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-NO_ZERO = 'X'.
X_FIELDCAT-OUTPUTLEN = '10'.
X_FIELDCAT-HOTSPOT = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Item'(025).
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'IT_FINAL'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Drop'(025).
X_FIELDCAT-FIELDNAME = 'DROP'.
X_FIELDCAT-TABNAME = 'IT_FINAL'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-DRDN_HNDL = '1'.
X_FIELDCAT-DRDN_ALIAS = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
ENDFORM. " build_fieldcat
*& Module STATUS_0100 OUTPUT
text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF G_CUSTOM_CONTAINER IS INITIAL.
**Initializing the grid and calling the fm to Display the O/P
PERFORM CREATE_AND_INIT_ALV.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form SET_DRDN_TABLE
text
FORM SET_DRDN_TABLE.
DATA:LT_DRAL TYPE LVC_T_DRAL,
LS_DRAL TYPE LVC_S_DRAL.
LOOP AT ITAB .
First listbox (handle '1').
IF SY-INDEX = 1.
LS_DRAL-HANDLE = '1'.
LS_DRAL-VALUE = ' '.
LS_DRAL-INT_VALUE = ' '.
ELSE.
LS_DRAL-HANDLE = '1'.
LS_DRAL-VALUE = ITAB-POSNR.
LS_DRAL-INT_VALUE = ITAB-POSNR.
ENDIF.
APPEND LS_DRAL TO LT_DRAL.
ENDLOOP.
**Setting the Drop down table for Reason Code
CALL METHOD G_GRID->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN_ALIAS = LT_DRAL.
ENDFORM. " set_drdn_table
*& Form EVENT_TOP_OF_PAGE
text
-->DG_DYNDOC_ID text
FORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.
"this is more clear.....check it
"first add text, then pass it to comentry write fm
DATA : DL_TEXT(255) TYPE C. "Text
Populating header to top-of-page
CALL METHOD DG_DYNDOC_ID->ADD_TEXT
EXPORTING
TEXT = 'Test Report'
SAP_STYLE = CL_DD_AREA=>HEADING.
Add new-line
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
CLEAR : DL_TEXT.
Move program ID
CONCATENATE 'Program Name :' SY-REPID
INTO DL_TEXT SEPARATED BY SPACE.
Add Program Name to Document
PERFORM ADD_TEXT USING DL_TEXT.
Add new-line
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
CLEAR : DL_TEXT.
Move User ID
CONCATENATE 'User ID :' SY-UNAME INTO DL_TEXT SEPARATED BY SPACE
Add User ID to Document
PERFORM ADD_TEXT USING DL_TEXT.
Add new-line
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
CLEAR : DL_TEXT.
Move Client
CONCATENATE 'Client :' SY-MANDT INTO DL_TEXT SEPARATED BY SPACE.
Add Client to Document
PERFORM ADD_TEXT USING DL_TEXT.
Add new-line
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
CLEAR : DL_TEXT.
Move date
WRITE SY-DATUM TO DL_TEXT.
CONCATENATE 'Date :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.
Add Date to Document
PERFORM ADD_TEXT USING DL_TEXT.
Add new-line
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
CLEAR : DL_TEXT.
Move time
WRITE SY-UZEIT TO DL_TEXT.
CONCATENATE 'Time :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.
Add Time to Document
PERFORM ADD_TEXT USING DL_TEXT.
Add new-line
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
Populating data to html control
PERFORM HTML.
ENDFORM. " EVENT_TOP_OF_PAGE
*& Form ADD_TEXT
To add Text
FORM ADD_TEXT USING P_TEXT TYPE SDYDO_TEXT_ELEMENT.
Adding text
CALL METHOD DG_DYNDOC_ID->ADD_TEXT
EXPORTING
TEXT = P_TEXT
SAP_EMPHASIS = CL_DD_AREA=>HEADING.
ENDFORM. " ADD_TEXT
*& Form HTML
text
FORM HTML.
DATA : DL_LENGTH TYPE I, " Length
DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " Background_id
Creating html control
IF DG_HTML_CNTRL IS INITIAL.
CREATE OBJECT DG_HTML_CNTRL
EXPORTING
PARENT = DG_PARENT_HTML.
ENDIF.
Reuse_alv_grid_commentary_set
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
DOCUMENT = DG_DYNDOC_ID
BOTTOM = SPACE
IMPORTING
LENGTH = DL_LENGTH.
Get TOP->HTML_TABLE ready
CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.
Set wallpaper
CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND
EXPORTING
PICTURE_ID = DL_BACKGROUND_ID.
Connect TOP document to HTML-Control
DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.
Display TOP document
CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT
EXPORTING
REUSE_CONTROL = 'X'
PARENT = DG_PARENT_HTML
EXCEPTIONS
HTML_DISPLAY_ERROR = 1.
IF SY-SUBRC NE 0.
MESSAGE I999 WITH 'Error in displaying top-of-page'(036).
ENDIF.
ENDFORM. " HTML
[/code] -
Download Option Not Working in ALV Using Classes
Hi,
Can anyone let me know what im missing since i get only my header downloaded when i download my output to EXCEL.
Im using ALV using CLASSES.
Thanks,
AnitaREPORT ZTMM_STOCK MESSAGE-ID zmsg
LINE-SIZE 270
LINE-COUNT 58
NO STANDARD PAGE HEADING.
tables: YGFMLINV, "Material Ledger - Inventory Data Extract
lfa1, "Vendor Master (General Section)
setheader, "Set Header and Directory(checking profit center grp)
mseg,
t001w,
mslbh,
mslb,
t001.
Internal Tables Declaration
data: begin of i_ygfmlinv occurs 0,
BDATJ like ygfmlinv-bdatj, "Posting date YYYY
POPER like ygfmlinv-poper, "Posting period
BUKRS like ygfmlinv-bukrs, "Company Code
PRCTR like ygfmlinv-prctr, "Profit center
WERKS like ygfmlinv-werks, "Plant
BKLAS like ygfmlinv-bklas, "Valuation class
MATNR like ygfmlinv-matnr, "Material number
BWTAR like ygfmlinv-bwtar, "Valuation type
STOCK_IND like ygfmlinv-stock_ind, "Stock indicators
MEINS like ygfmlinv-meins, "Base unit of measure
MLAST like ygfmlinv-mlast, "Material Price Dtermination: Control
LBKUM like ygfmlinv-lbkum, "Total valuated stock
vprsv like ygfmlinv-vprsv, "Price control indicator
lc_mvp_prc like ygfmlinv-lc_mvp_prc, "LC:Moving Avg/Periodic Prc
LC_CURTP like ygfmlinv-LC_CURTP, "Currency Type
LC_CURRENCY like ygfmlinv-lc_currency, "Currency Key
gc_curtp like ygfmlinv-gc_curtp, "Grp.Curr Type
gc_currency like ygfmlinv-gc_currency, " Grp.Curr
LC_TOT_AMT like ygfmlinv-lc_tot_amt, "LC: Total Amount
KONTS LIKE T030-KONTS, "G/L Account No
XBILK LIKE SKA1-XBILK,
lc_cogs like ygfmlinv-lc_var_amt,
lifnr like mslbh-lifnr,
lc_trfix_amt like ygfmlinv-lc_trfix_amt,
lc_lofix_amt like ygfmlinv-lc_lofix_amt,
lc_var_amt like ygfmlinv-lc_var_amt,
lc_utp_amt like ygfmlinv-lc_utp_amt,
end of i_ygfmlinv.
data: begin of i_mslbh occurs 0,
MATNR like mslbh-matnr, "Material number
SOBKZ like mslbh-sobkz, "Special stock indicator
LIFNR like mslbh-lifnr, "Account number of vendor or creditor
WERKS like mslbh-werks, "Plant
CHARG like mslbh-charg, "Batch number
LFGJA like mslbh-lfgja, "Fiscal year of current period
LFMON like mslbh-lfmon, "Current period (posting period)
LBLAB like mslbh-lblab, "Current period (posting period)
LBINS like mslbh-lbins, "Stock in quality inspection
end of i_mslbh.
data: begin of i_MSLB occurs 0,
MATNR like mslb-matnr,
WERKS like mslb-werks,
SOBKZ like mslb-sobkz,
LIFNR like mslb-lifnr,
LFGJA like mslb-lfgja,
LFMON like mslb-lfmon,
LBLAB like mslb-lblab,
LBINS like mslb-lbins,
LBEIN like mslb-lbein,
end of i_mslb.
*data: begin of i_t030 occurs 0,
KTOPL like t030-ktopl,
BKLAS like t030-bklas,
KONTS like t030-konts,
end of i_t030.
*data: begin of i_ska1 occurs 0,
SAKNR like ska1-saknr,
XBILK like ska1-xbilk,
end of i_ska1.
DATA : BEGIN OF i_non_subc OCCURS 0,
MATNR LIKE YGFMLINV-MATNR, "Material
WERKS LIKE YGFMLINV-WERKS, "Plant,
bukrs like ygfmlinv-bukrs, "Company Code
BKLAS LIKE YGFMLINV-BKLAS, "Val Class
PRCTR LIKE YGFMLINV-PRCTR, "Profit Center
BWTAR LIKE YGFMLINV-BWTAR, "Val Type
LBKUM LIKE YGFMLINV-LBKUM, "QTY
PEINH LIKE YGFMLINV-PEINH, "Price Unit
MEINS LIKE YGFMLINV-MEINS, "Unit of Measure
lc_currency like ygfmlinv-lc_currency,
lc_curtp like ygfmlinv-lc_curtp,
gc_currency like ygfmlinv-gc_currency,
gc_curtp like ygfmlinv-gc_currency,
LC_VAR_AMT LIKE YGFMLINV-LC_VAR_AMT, "LC :Variable Amt
LC_TRFIX_AMT LIKE YGFMLINV-LC_TRFIX_AMT, "LC :Trnsfer Fixed Amt
LC_LOFIX_AMT LIKE YGFMLINV-LC_LOFIX_AMT, "LC:Local Fixed Amt.
LC_COGS LIKE YGFMLINV-LC_VAR_AMT, "Total LC fixed COGS
"added as per CC01507
LC_UTP_AMT LIKE YGFMLINV-LC_UTP_AMT, "LC:UTP Amount.
LC_TR_VAL LIKE YGFMLINV-LC_LOFIX_AMT,"TotalLC Transfer value
XBILK LIKE SKA1-XBILK, "Balance Indicator
gc_var_amt like ygfmlinv-gc_var_amt,
gc_trfix_amt like ygfmlinv-gc_trfix_amt,
gc_lofix_amt like ygfmlinv-gc_lofix_amt,
gc_cogs like ygfmlinv-gc_var_amt,
gc_utp_amt like ygfmlinv-gc_utp_amt,
gc_tr_val like ygfmlinv-gc_lofix_amt,
END OF i_non_subc.
Final Output Table
types: begin of t_output,
matnr like ygfmlinv-matnr,
lifnr like mslbh-lifnr,
werks like ygfmlinv-werks,
spstk like mslbh-lblab,
totstk like ygfmlinv-lbkum,
lc_currency like ygfmlinv-LC_CURRENCY,
lc_curtp like ygfmlinv-lc_curtp,
gc_curtp like ygfmlinv-gc_curtp,
gc_currency like ygfmlinv-gc_currency,
name1 like lfa1-name1,
vprsv like ygfmlinv-vprsv,
bukrs like ygfmlinv-bukrs,
mlast like ygfmlinv-mlast,
meins like ygfmlinv-meins,
bklas like ygfmlinv-bklas,
maktx like makt-maktx,
stdprice(18),
totval like ygfmlinv-lc_tot_amt,
sobkz like mslbh-sobkz,
end of t_output.
Work Area for Final Output Table
data: wa_output type t_output.
ALV Display
Name of Custom Container added on the screen
data: G_CONTAINER TYPE SCRFNAME VALUE 'ZGRID_CTRL',
ALV GRID Instance Reference
G_GRID1 TYPE REF TO CL_GUI_ALV_GRID, "Grid
Instance Reference to Custom Container
G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
PBO Status
data: ok_code like sy-ucomm,
Field Catalog Table
gT_FIELDCAT TYPE LVC_T_FCAT,
Layout Structure
gs_layout type lvc_s_layo,
Sorting anf Subtotal
gt_sort TYPE lvc_s_sort occurs 0,
gt_output type standard table of t_output.
data: g_curr(2).
CLASS lcl_event_receiver DEFINITION
class lcl_event_receiver definition.
public section.
Add SUB TOTAL TEXT to the ALV DISPLAY
methods handle_subtotal_text
for event subtotal_text of cl_gui_alv_grid
importing es_subtottxt_info ep_subtot_line e_event_data.
endclass.
Declaration for EVENT Receiver
data: event_receiver type ref to lcl_event_receiver,
l_subtxt(60) value 'Subtotal Text'.
field-symbols: <fs> type t_output,
<fs1>.
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_SUBTOTAL_TEXT.
FIELD for which the SUBTOTAL is Calculated
if es_subtottxt_info-criteria = 'MATNR'.
ASSIGN EP_SUBTOT_LINE->* TO <FS1>.
ASSIGN E_EVENT_DATA->M_DATA->* TO <FS>.
CONCATENATE es_subtottxt_info-keyword ':MATERIAL'
<fs>-matnr INTO <fs1>.
ENDIF.
ENDMETHOD. "HANDLE_SUBTOTAL_TEXT
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
Constants
constants: c_eb(2) value 'EB',
c_m value 'M',
C_KTOPL(4) VALUE 'TCOA',
C_KTOSL(3) VALUE 'BSX',
C_KONTS(4) VALUE '002%'.
Selection Screen
selection-screen:begin of block b1 with frame title text-001.
select-options: s_lifnr for lfa1-lifnr , "Vendor
s_werks for YGFMLINV-werks obligatory, "Plant
s_prctr for YGFMLINV-prctr, "Pr.Ctr
s_matnr for ygfmlinv-matnr, "Mat.No
s_bwtar for mseg-bwtar no-display.
parameters: p_bukrs like YGFMLINV-bukrs obligatory, "C.Code
p_pctrgp like SETHEADER-SETNAME, "Pf.ct.Grp
p_poper like YGFMLINV-poper obligatory, " Period
p_bdatj like YGFMLINV-bdatj obligatory, " Year
r_ccode radiobutton group rad1 default 'X',
r_grpcur radiobutton group rad1.
selection-screen: end of block b1.
Ranges Declaration
RANGES : R_PROFIT_CTR FOR CEPC-PRCTR.
INITIALIZATON
*initialization.
Validations for Selection Screen
Validation for Vendor
at selection-screen on s_lifnr.
select single lifnr
from lfa1
into lfa1-lifnr
where lifnr in s_lifnr.
if sy-subrc ne 0.
message e039.
endif.
Validation for Plant
at selection-screen on s_werks.
select single werks
from t001w
into t001w-werks
where werks in s_werks.
if sy-subrc ne 0.
message e040.
endif.
Validation for Profit Center
at selection-screen on s_prctr.
select single prctr
from ygfmlinv
into ygfmlinv-prctr
where prctr in s_prctr.
if sy-subrc ne 0.
message e041.
endif.
Validation for Company Code
at selection-screen on p_bukrs.
select single bukrs
from t001
into t001-bukrs
where bukrs eq p_bukrs.
if sy-subrc ne 0.
message e042.
endif.
Validation for Profit Center Group
at selection-screen on p_pctrgp.
if not p_pctrgp is initial.
select single setname
from setheader
into setheader-setname
where setname eq p_pctrgp.
if sy-subrc ne 0.
message e043.
endif.
endif.
Validation for Fiscal Period
*at selection-screen on p_poper.
select single poper
from YGFMLINV
into YGFMLINV-poper
where poper eq p_poper.
if sy-subrc ne 0.
message e045.
endif.
Validation for Fiscal Year
*at selection-screen on p_bdatj.
select single bdatj
from YGFMLINV
into YGFMLINV-bdatj
where bdatj eq p_bdatj.
if sy-subrc ne 0.
message e046.
endif.
start-of-selection.
if p_pctrgp ne ' '.
perform f_profit_center_select.
endif.
perform f_data_selection. "using p_profit_center..
end-of-selection.
call screen 100.
*& Form f_data_selection
text
--> p1 text
<-- p2 text
FORM f_data_selection.
data: l_flg,
l_lblab like mslbh-lblab,
l_name1 like lfa1-name1,
l_rate like mslbh-lblab,
l_maktx like makt-maktx,
l_diff_stk like mslbh-lblab,
l_totval like ygfmlinv-lc_tot_amt.
From profit center group get Profit Center
LOOP AT R_PROFIT_CTR.
IF R_PROFIT_CTR-LOW EQ R_PROFIT_CTR-HIGH.
R_PROFIT_CTR-OPTION = 'EQ'.
R_PROFIT_CTR-HIGH = SPACE.
MODIFY R_PROFIT_CTR.
ENDIF.
ENDLOOP.
if r_ccode eq 'X'.
g_curr = '10'.
else.
g_curr = '30'.
endif.
if g_curr eq '10'.
Fetch TOTAL STOCK ,VALUE from ML - Inv. Data Extract Table
select BDATJ POPER BUKRS PRCTR WERKS BKLAS MATNR
BWTAR STOCK_IND MEINS MLAST LBKUM
vprsv lc_mvp_prc LC_CURTP
LC_CURRENCY LC_TOT_AMT
lc_var_amt LC_UTP_AMT
lc_trfix_amt lc_lofix_amt
gc_curtp gc_currency
from YGFMLINV
into corresponding fields of table i_YGFMLINV
where bdatj eq p_bdatj and
poper eq p_poper and
bukrs eq p_bukrs and
werks in s_werks and
matnr in s_matnr and
STOCK_IND eq c_m and
trans_type eq c_eb and
lc_curtp eq g_curr.
else.
Fetch TOTAL STOCK ,VALUE from ML - Inv. Data Extract Table
select BDATJ POPER BUKRS PRCTR WERKS BKLAS MATNR
BWTAR STOCK_IND MEINS MLAST LBKUM
vprsv lc_mvp_prc LC_CURTP
LC_CURRENCY LC_TOT_AMT
lc_var_amt LC_UTP_AMT
lc_trfix_amt lc_lofix_amt
gc_curtp gc_currency
from YGFMLINV
into corresponding fields of table i_YGFMLINV
where bdatj eq p_bdatj and
poper eq p_poper and
bukrs eq p_bukrs and
werks in s_werks and
matnr in s_matnr and
STOCK_IND eq c_m and
trans_type eq c_eb and
gc_curtp eq g_curr.
endif.
Delete Entries not in Profit Center range
LOOP AT I_YGFMLINV.
IF NOT I_YGFMLINV-PRCTR IN R_PROFIT_CTR.
DELETE I_YGFMLINV.
ENDIF.
ENDLOOP.
if not i_ygfmlinv[] is initial.
data l_date like mkpf-budat.
move : p_bdatj to l_date(4),
p_poper to l_date+4(2),
'31' to l_date+6(2).
Get the TOTAL STOCK for Vendor and Material
SELECT MATNR
WERKS
CHARG
SOBKZ
LIFNR
LFGJA
LFMON
LBLAB
LBINS
FROM MSLBH INTO corresponding fields of TABLE I_MSLBH
for all entries in i_ygfmlinv
WHERE MATNR eq i_ygfmlinv-matnr and
WERKS EQ i_ygfmlinv-WERKS AND
SOBKZ in p_stkind AND
LIFNR in s_LIFNR AND
LFGJA GE P_BDATJ and
lfmon eq p_poper.
if sy-subrc eq 0.
DELETE I_MSLBH WHERE LFGJA EQ P_BDATJ AND
LFMON LT P_POPER.
endif.
endif.
sort i_mslbh by matnr lifnr werks lfgja lfmon.
sort i_ygfmlinv by matnr werks bdatj poper.
loop at i_mslbh.
l_lblab = l_lblab + i_mslbh-lblab.
at end of lifnr.
l_flg = 'X'.
endat.
read table i_ygfmlinv with key matnr = i_mslbh-matnr
werks = i_mslbh-werks
bdatj = i_mslbh-lfgja
poper = i_mslbh-lfmon
binary search.
if sy-subrc eq 0.
select single name1 from lfa1 into l_name1
where lifnr eq i_mslbh-lifnr.
if sy-subrc eq 0.
select single maktx
from makt
into l_maktx
where matnr eq i_mslbh-matnr and
spras eq sy-langu.
if l_flg eq 'X'.
Subtract Total stk from Special Stock Vendor to get the difference
l_diff_stk = i_ygfmlinv-lbkum - l_lblab.
move : i_mslbh-matnr to wa_output-matnr,
i_mslbh-lifnr to wa_output-lifnr,
i_mslbh-werks to wa_output-werks,
l_lblab to wa_output-totstk,
l_name1 to wa_output-name1,
i_ygfmlinv-vprsv to wa_output-vprsv,
i_ygfmlinv-meins to wa_output-meins,
i_ygfmlinv-lc_mvp_prc to wa_output-stdprice,
i_ygfmlinv-mlast to wa_output-mlast,
i_ygfmlinv-bukrs to wa_output-bukrs,
i_ygfmlinv-bklas to wa_output-bklas,
i_mslbh-sobkz to wa_output-sobkz.
if g_curr eq '10'.
move: i_ygfmlinv-lc_curtp to wa_output-lc_curtp,
i_ygfmlinv-lc_currency to wa_output-lc_currency.
else.
move: i_ygfmlinv-gc_curtp to wa_output-gc_curtp,
i_ygfmlinv-gc_currency to wa_output-gc_currency.
endif.
if wa_output-totstk ne 0.
l_rate = i_ygfmlinv-LC_TOT_AMT / i_ygfmlinv-lbkum.
wa_output-totval = l_rate * l_lblab.
endif.
append wa_output to gt_output.
move wa_output-totval to l_totval.
clear: l_rate,wa_output.
if l_diff_stk ne 0.
wa_output-totval = i_ygfmlinv-LC_TOT_AMT - l_totval.
move: i_mslbh-matnr to wa_output-matnr,
*Included - Remove
i_mslbh-matnr to wa_output-matnr,
i_mslbh-werks to wa_output-werks,
l_diff_stk to wa_output-totstk,
i_ygfmlinv-vprsv to wa_output-vprsv,
i_ygfmlinv-meins to wa_output-meins,
i_ygfmlinv-lc_mvp_prc to wa_output-stdprice,
i_ygfmlinv-mlast to wa_output-mlast,
i_ygfmlinv-bukrs to wa_output-bukrs,
i_ygfmlinv-bklas to wa_output-bklas.
if g_curr eq '10'.
move: i_ygfmlinv-lc_curtp to wa_output-lc_curtp,
i_ygfmlinv-lc_currency to wa_output-lc_currency.
else.
move: i_ygfmlinv-gc_curtp to wa_output-gc_curtp,
i_ygfmlinv-gc_currency to wa_output-gc_currency.
endif.
append wa_output to gt_output.
clear: i_ygfmlinv,l_flg,l_lblab,l_name1,wa_output,
i_mslbh.
endif.
endif.
endif.
endif.
endloop.
sort: i_ygfmlinv by matnr werks,
i_mslbh by matnr werks.
LOOP AT I_YGFMLINV.
read table i_mslbh with key matnr = i_ygfmlinv-matnr
binary search.
if sy-subrc eq 0.
delete i_ygfmlinv.
clear i_ygfmlinv.
else.
MOVE-CORRESPONDING I_YGFMLINV TO i_non_subc.
APPEND i_non_subc.
CLEAR I_YGFMLINV.
endif.
ENDLOOP.
sort i_non_subc by matnr werks.
data: l_lc_cogs(16) type p decimals 2,
l_lc_tr_val(16) type p decimals 2,
l_gc_cogs(16) type p decimals 2,
l_gc_tr_val(16) type p decimals 2.
LOOP AT i_non_subc.
if g_curr eq '10'.
l_LC_COGS = i_non_subc-LC_TRFIX_AMT +
i_non_subc-LC_LOFIX_AMT.
l_LC_TR_VAL = i_non_subc-LC_VAR_AMT + l_LC_COGS +
i_non_subc-LC_UTP_AMT.
else.
l_gc_cogs = i_non_subc-gc_trfix_amt + i_non_subc-gc_lofix_amt.
l_gc_tr_val = i_non_subc-gc_var_amt + i_non_subc-gc_cogs +
i_non_subc-gc_utp_amt.
endif.
at end of matnr.
l_flg = 'X'.
endat.
if l_flg eq 'X'.
move: i_non_subc-matnr to wa_output-matnr,
i_non_subc-werks to wa_output-werks,
i_non_subc-lbkum to wa_output-totstk,
i_non_subc-meins to wa_output-meins,
i_non_subc-bukrs to wa_output-bukrs,
i_non_subc-bklas to wa_output-bklas,
i_non_subc-lc_curtp to wa_output-lc_curtp,
i_non_subc-lc_currency to wa_output-lc_currency,
i_non_subc-gc_curtp to wa_output-gc_curtp,
i_non_subc-gc_currency to wa_output-gc_currency.
if g_curr eq '10'.
move l_lc_tr_val to wa_output-totval.
else.
move l_gc_tr_val to wa_output-totval.
endif.
i_non_subc-mlast to wa_output-mlast.
select single maktx
from makt
into l_maktx
where matnr eq i_non_subc-matnr and
spras eq sy-langu.
if sy-subrc eq 0.
move l_maktx to wa_output-maktx.
append wa_output to gt_output .
clear: wa_output,l_flg,l_lc_tr_val,l_lc_cogs,
l_gc_cogs,l_gc_tr_val.
endif.
endif.
ENDLOOP.
ENDFORM. " f_data_selection
*& Module STATUS_0100 OUTPUT
text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ZPF_STATUS'.
SET TITLEBAR 'ZTITLE'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module alv_display OUTPUT
text
MODULE alv_display OUTPUT.
data: total type ref to data,
subtotal1 type ref to data.
field-symbols <total> like gt_output .
field-symbols <subtotal1> like gt_output.
if g_grid1 is initial.
perform f_create_objects.
perform f_build_field_catalog changing gt_fieldcat.
perform f_prepare_layout changing gs_layout.
perform f_sort_sub_total changing gt_sort.
CALL METHOD G_GRID1->GET_SORT_CRITERIA
IMPORTING
ET_SORT = gt_sort[] .
CALL METHOD g_grid1->GET_SUBTOTALS
IMPORTING
EP_COLLECT00 = total
EP_COLLECT01 = subtotal1 .
EP_COLLECT02 =
EP_COLLECT03 =
EP_COLLECT04 =
EP_COLLECT05 =
EP_COLLECT06 =
EP_COLLECT07 =
EP_COLLECT08 =
EP_COLLECT09 =
ET_GROUPLEVELS = .
assign total->* to <total>.
assign subtotal1->* to <subtotal1>.
*ALV Display - Specify Sorting,Filtering Criteria
if gt_output[] is initial.
message i015.
endif.
CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BYPASSING_BUFFER =
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 =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
IT_OUTTAB = gt_output[]
IT_FIELDCATALOG = gt_fieldcat
IT_SORT = gt_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.
else.
CALL METHOD G_GRID1->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
FINISHED = 1
others = 2 .
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. " alv_display OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE USER_COMMAND_0100 INPUT.
case ok_code.
when 'BACK'.
set screen '0'.
leave screen.
when 'EXIT' or 'CANCEL'.
PERFORM EXIT_PROGRAM.
endcase.
clear ok_code.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form f_create_objects
text
--> p1 text
<-- p2 text
FORM f_create_objects.
Creating Custom Container Objects and GRID
IF G_grid1 IS INITIAL.
*Creating Custom Container Instance
Pass the name of the control that you have created on the screen
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = 'ZGRID_CTRL'.
*Creating ALV Grid Instance
CREATE OBJECT G_GRID1 EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
endif.
ENDFORM. " f_create_objects
*& Form f_build_field_catalog
text
--> p1 text
<-- p2 text
FORM f_build_field_catalog changing pt_fieldcat type lvc_t_fcat.
data ls_fcat type lvc_s_fcat.
Val Type
ls_fcat-fieldname = 'BUKRS'.
ls_fcat-inttype = 'C'.
ls_fcat-outputlen = '4'.
ls_fcat-coltext = 'Val.Type'.
ls_fcat-seltext = 'Val.Type'.
ls_fcat-col_pos = '1'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
Val.Class
ls_fcat-fieldname = 'BKLAS'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-outputlen = '4'.
ls_fcat-coltext = 'Val.Class'.
ls_fcat-seltext = 'Val.Class'.
ls_fcat-col_pos = '2'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Plant
ls_fcat-fieldname = 'WERKS'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-outputlen = '4'.
ls_fcat-coltext = 'Plant'.
ls_fcat-seltext = 'Plant'.
ls_fcat-col_pos = '3'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Material
ls_fcat-fieldname = 'MATNR'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-outputlen = '18'.
ls_fcat-coltext = 'Material'.
ls_fcat-seltext = 'Material'.
ls_fcat-col_pos = '4'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Description
ls_fcat-fieldname = 'MAKTX'.
ls_fcat-TABNAME = 'MAKT'.
ls_fcat-outputlen = '40'.
ls_fcat-coltext = 'Description'.
ls_fcat-seltext = 'Description'.
ls_fcat-col_pos = '5'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Price Control
ls_fcat-fieldname = 'VPRSV'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-outputlen = '1'.
ls_fcat-coltext = 'Price Control'.
ls_fcat-seltext = 'Price Control'.
ls_fcat-col_pos = '6'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Price Determination
ls_fcat-fieldname = 'MLAST'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-outputlen = '1'.
ls_fcat-coltext = 'Price Determination'.
ls_fcat-seltext = 'Price Determination'.
ls_fcat-col_pos = '7'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
Total Stock
ls_fcat-fieldname = 'TOTSTK'.
ls_fcat-REF_TABLE = 'YGFMLINV'.
ls_fcat-REF_FIELD = 'LBKUM'.
ls_fcat-QFIELDNAME = 'MEINS'.
ls_fcat-IFIELDNAME = 'YGFMLINV'.
ls_fcat-coltext = 'Total Stock'.
ls_fcat-seltext = 'Total Stock'.
ls_fcat-col_pos = '8'.
ls_fcat-do_sum = 'X'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
Std. Price
ls_fcat-fieldname = 'STDPRICE'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-REF_TABLE = 'YGFMLINV'.
ls_fcat-ref_field = 'LC_MVP_PRC'.
ls_fcat-coltext = 'Std.Price'.
ls_fcat-col_pos = '9'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
if g_curr eq '10'.
Currency Type
ls_fcat-fieldname = 'LC_CURTP'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-coltext = 'Currency Type'.
ls_fcat-seltext = 'Currency Type'.
ls_fcat-col_pos = '10'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
else.
Currency Type
ls_fcat-fieldname = 'GC_CURTP'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-coltext = 'Currency Type'.
ls_fcat-seltext = 'Currency Type'.
ls_fcat-col_pos = '10'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
endif.
*Per Unit Price
ls_fcat-fieldname = 'STDPRICE'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-ref_table = 'YGFMLINV'.
ls_fcat-ref_field = 'LC_MVP_PRC'.
ls_fcat-currency = 'LC_CURRENCY'.
ls_fcat-coltext = 'Per.Unit.Price'.
ls_fcat-seltext = 'Per.Unit.Price'.
ls_fcat-col_pos = '11'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
Quantity Measurement
ls_fcat-fieldname = 'MEINS'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-coltext = 'Base Unit'.
ls_fcat-seltext = 'Base Unit'.
ls_fcat-col_pos = '12'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Total Value
ls_fcat-fieldname = 'TOTVAL'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-currency = 'GC_CURRENCY'.
ls_fcat-coltext = 'Total Value'.
ls_fcat-seltext = 'Total Value'.
ls_fcat-col_pos = '13'.
ls_fcat-do_sum = 'X'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Value/period
ls_fcat-fieldname = 'TOTVAL'.
ls_fcat-TABNAME = 'YGFMLINV'.
ls_fcat-currency = 'GC_CURRENCY'.
ls_fcat-coltext = 'Value/Period'.
ls_fcat-seltext = 'Value/Period'.
ls_fcat-col_pos = '14'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Vendor
ls_fcat-fieldname = 'LIFNR'.
ls_fcat-TABNAME = 'LFA1'.
ls_fcat-coltext = 'Vendor'.
ls_fcat-seltext = 'Vendor'.
ls_fcat-col_pos = '15'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Vendor Description
ls_fcat-fieldname = 'NAME1'.
ls_fcat-TABNAME = 'LFA1'.
ls_fcat-coltext = 'Vend.Desc'.
ls_fcat-seltext = 'Vend.Desc'.
ls_fcat-col_pos = '16'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
*Special Stock Indicator
ls_fcat-fieldname = 'SOBKZ'.
ls_fcat-TABNAME = 'MSLBH'.
ls_fcat-coltext = 'Spl.Stock Ind'.
ls_fcat-seltext = 'Spl.Stock Ind'.
ls_fcat-col_pos = '17'.
append ls_fcat to pt_fieldcat.
clear ls_fcat.
ENDFORM. " f_build_field_catalog
*& Form f_prepare_layout
text
<--P_GS_LAYOUT text
FORM f_prepare_layout CHANGING P_GS_LAYOUT type lvc_s_layo.
p_gs_layout-zebra = 'X'.
p_gs_layout-grid_title = 'Material List: Prices and Inventory Values'.
p_gs_layout-smalltitle ='X'.
p_gs_layout-no_totline = 'X'.
p_gs_layout-no_totarr = 'X'.
p_gs_layout-no_totexp = 'X'.
p_gs_layout-totals_bef = 'X'.
ENDFORM. " f_prepare_layout
*& Form f_profit_center_select
Validate the Profit Center Groups with Profit Center
--> p1 text
<-- p2 text
FORM f_profit_center_select.
DATA:V_RETCODE LIKE BAPIRET2,
V_GROUPNAME LIKE BAPICO_GROUP-GROUPNAME ,
p_kokrs like CEPC-KOKRS value 'DU01',
I_HIERARCHYNODES LIKE BAPISET_HIER OCCURS 0 WITH HEADER LINE,
I_PRCTR LIKE BAPI1116_VALUES OCCURS 0 WITH HEADER LINE.
V_GROUPNAME = P_PCTRGP.
CALL FUNCTION 'BAPI_PROFITCENTERGRP_GETDETAIL'
EXPORTING
CONTROLLINGAREA = P_KOKRS
GROUPNAME = V_GROUPNAME
IMPORTING
RETURN = V_RETCODE
TABLES
HIERARCHYNODES = I_HIERARCHYNODES
HIERARCHYVALUES = I_PRCTR.
LOOP AT I_PRCTR.
R_PROFIT_CTR-LOW = I_PRCTR-VALFROM.
R_PROFIT_CTR-HIGH = I_PRCTR-VALTO.
R_PROFIT_CTR-SIGN = 'I'.
R_PROFIT_CTR-OPTION = 'BT'.
APPEND R_PROFIT_CTR.
ENDLOOP.
ENDFORM. " f_profit_center_select
*& Form f_sort_sub_total
text
<--P_GT_SORT text
FORM f_sort_sub_total CHANGING P_GT_SORT.
DATA: ls_sort TYPE lvc_s_sort occurs 0 with header line.
ls_sort-spos = '1' .
ls_sort-fieldname = 'MATNR'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
ls_sort-expa ='X'.
ls_sort-group = 'UL'.
append ls_sort TO gt_sort.
ENDFORM. " f_sort_sub_total
*& Form EXIT_PROGRAM
text
--> p1 text
<-- p2 text
FORM EXIT_PROGRAM.
data: g_repid like sy-repid.
g_repid = sy-repid.
CALL METHOD G_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. " EXIT_PROGRAM -
Hi Experts,
When clicking the button 'append row', I want to add a line filled with some values in selection screen.
I work with OO.
need help please.
MohamedHello Mohamed
The logic is the same as before. Search for $MODFIED to detect the changes in the sample report.
However, I do not think that these requirements make any sense because if you re-implement the Copy function you obviously have to re-implement the Paste function (and perhaps Undo function as well), too.
So basically you reinvent the wheel again.
*& Report ZUS_SDN_ALV_GRID_EDITABLE
*& Thread: ADD A line in alv with values
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="974654"></a>
REPORT zus_sdn_alv_grid_editable_1x.
TYPE-POOLS: abap.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
gif_adapter TYPE REF TO if_salv_adapter,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo.
DATA:
gt_outtab TYPE STANDARD TABLE OF knb1.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
md_function TYPE ui_func READ-ONLY,
ms_row TYPE lvc_s_row READ-ONLY,
ms_outtab LIKE LINE OF gt_outtab. "$MODIFIED
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender,
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
sender,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender,
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed
e_onf4
e_onf4_before
e_onf4_after
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
ENDMETHOD. "handle_double_click
METHOD handle_toolbar.
" define local data
DATA: ls_button TYPE stb_button.
" Redefine toolbar button functions in order to be able to
" handle them in event USER_COMMAND (standard toolbar functions
" do NOT raise event USER_COMMAND !!!)
LOOP AT e_object->mt_toolbar INTO ls_button.
CASE ls_button-function.
WHEN cl_gui_alv_grid=>mc_fc_loc_append_row.
ls_button-function = 'APPEND_ROW'.
WHEN cl_gui_alv_grid=>mc_fc_loc_insert_row.
ls_button-function = 'INSERT_ROW'.
WHEN cl_gui_alv_grid=>mc_fc_loc_copy. "$MODIFIED
ls_button-function = 'COPY'.
WHEN OTHERS.
CONTINUE.
ENDCASE.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
ENDLOOP.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
" Get current row for function 'Insert Row'
CALL METHOD sender->get_current_cell
IMPORTING
* e_row =
* e_value =
* e_col =
es_row_id = ms_row
* es_col_id =
* es_row_no =
" Store redefined function code
md_function = e_ucomm.
CASE e_ucomm.
WHEN 'APPEND_ROW' OR
'INSERT_ROW'.
" Just trigger PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'NEW_ROW'
* IMPORTING
* rc =
WHEN 'COPY'. "$MODIFIED
READ TABLE gt_outtab INTO ms_outtab INDEX ms_row-index.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_user_command
METHOD handle_data_changed.
* define local data
DATA: ls_outtab LIKE LINE OF gt_outtab,
ls_good TYPE lvc_s_modi.
BREAK-POINT.
LOOP AT er_data_changed->mt_good_cells INTO ls_good
WHERE ( fieldname = 'ERDAT' ).
** CALL METHOD er_data_changed->get_cell_value
** EXPORTING
** i_row_id = ls_good-row_id
** i_fieldname = ls_good-fieldname
** IMPORTING
** e_value = ls_outtab-erdat.
ls_outtab-erdat = ls_good-value.
IF ( ls_outtab-erdat < '20070101' ).
CALL METHOD er_data_changed->add_protocol_entry
EXPORTING
i_msgid = '00'
i_msgty = 'E'
i_msgno = '398'
i_msgv1 = 'Date must be >= 01.01.2007'
* i_msgv2 =
* i_msgv3 =
* i_msgv4 =
i_fieldname = ls_good-fieldname
i_row_id = ls_good-row_id
i_tabix = ls_good-tabix.
ENDIF.
ENDLOOP.
er_data_changed->display_protocol( ).
" Not really required (only for validations)
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_outtab UP TO 10 ROWS.
PERFORM init_controls.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'NEW_ROW'.
PERFORM add_new_row.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form ADD_NEW_ROW
* text
* --> p1 text
* <-- p2 text
FORM add_new_row .
* define local data
DATA: ls_outtab LIKE LINE OF gt_outtab,
ls_stable TYPE lvc_s_stbl,
ld_idx TYPE i.
ls_outtab-bukrs = '1000'.
ls_outtab-ernam = syst-uname.
CASE lcl_eventhandler=>md_function.
WHEN 'APPEND_ROW'.
APPEND ls_outtab TO gt_outtab.
WHEN 'INSERT_ROW'.
ld_idx = lcl_eventhandler=>ms_row-index + 1.
INSERT ls_outtab INTO gt_outtab INDEX ld_idx.
WHEN OTHERS.
ENDCASE.
" Refresh ALV list display
ls_stable-row = abap_true.
ls_stable-col = abap_true.
CALL METHOD go_grid1->refresh_table_display
EXPORTING
is_stable = ls_stable
* i_soft_refresh =
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " ADD_NEW_ROW
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking " go_cell_top
EXCEPTIONS
OTHERS = 5.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" ENTER trigger event DATA_CHANGED
CALL METHOD go_grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
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 event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid1,
lcl_eventhandler=>handle_toolbar FOR go_grid1,
lcl_eventhandler=>handle_user_command FOR go_grid1,
lcl_eventhandler=>handle_data_changed FOR go_grid1.
PERFORM build_fieldcatalog.
* Display data
gs_layout-grid_title = 'Customers'.
gs_layout-smalltitle = abap_true.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
** i_structure_name = 'KNB1'
is_layout = gs_layout
ir_salv_adapter = gif_adapter
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " INIT_CONTROLS
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA: ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'KNB1'
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
ls_fcat-edit = abap_true.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE abap_true ).
ENDFORM. " BUILD_FIELDCATALOG
Regards
Uwe -
Provide me Helpful Links/Documents on ALV using Classes
Dear all,
Could you guys provide me with some Helpful Links/Documents on ALV using Classes.
Thanks in Advance,
Joseph ReddyHi,
Check these out:
Check this for basic concepts of OOPS
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/abap objects/abap code sample to learn basic concept of object-oriented programming.doc
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/alv grid/abap code sample to display data in alv grid using object oriented programming.doc
Tabstrip
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/alv grid/abap code sample for tab strip in alv.pdf
Editable ALV
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/alv grid/abap code sample to edit alv grid.doc
Tree
http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_usrint.htm
General Tutorial for OOPS
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/an easy reference for alv grid control.pdf
http://www.geocities.com/mpioud/Abap_programs.html
Best Regards,
Anjali -
ALV with dropdown in column and other questions
hi,
I created an editable alv with configuration model via external context mapping.
now I have a column which contains strings and my aim is to show this whole column as a dropdownlist. the possible values of this dropdown are fetched in a database table at runtime and each cell in this column got its own selected value in this dropdownlist.
changes of the selected values should be written in the database table in a later step.
1. what changes do I have to do?
should I remove my external mapping concerning the alv and use the setData method? or what is the easiest way to get my dropdownlist in this column instead of normal text (string) ?
2. should I choose dropdownbykey or by index?
I suppose I have to change the context when changing the selected value in the dropdownlist and the read out the changed context element and update my database table?
3. how could I access rows (= tuples) in an alv?
4. how can I avoid that a row could be deleted, inserted or added with the normal functions of the alv?Hi Thorsten,
If the possible list of values in the dropdown is different for each row, you need a drop down by index. Else this can be done using a dropdown by key itself.
The only change that you need to do is create a cell editor of type dropdown for that particular column and configure your ALV model.
The sample code for changing the cell editor would be:
l_alv_model = l_ref_interfacecontroller->get_model( ).
DATA:
lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_column type ref to CL_SALV_WD_COLUMN.
lr_dropdown TYPE REF TO CL_SALV_WD_UIE_DROPDOWN_BY_KEY.
lr_column_settings ?= l_alv_model.
lr_column = lr_column_settings->get_column( <column name> ).
CREATE OBJECT lr_dropdown EXPORTING
SELECTED_KEY_FIELDNAME= '<fieldname>'
lr_column->set_cell_editor( lr_dropdown ).
Here, you can substitute the field name with your field name that has to be displayed as a dropdown.
The dropdown list can be populated in the wddoinit method by attaching a value set to the attribute in the context node info. Everything else will be like you do in a normal table. You can so a get_static_attributes of your elements and persist in tables. Whenever you change the selected value, the context will be updated immediately. You can have a user defined function like 'Save' or something where you can just read the context and process the data.
If you do not want to display any of the normal functions, you can do the following:
data: lt_functions type SALV_WD_T_FUNCTION_STD_REF,
ls_function type SALV_WD_s_FUNCTION_STD_REF.
lt_functions = l_alv_model->if_salv_wd_function_settings~get_functions_std( ).
loop at lt_functions into ls_function.
ls_function-r_function->set_visible( CL_WD_UIELEMENT=>E_VISIBLE-NONE ).
endloop.
The above code will hide all the standard functions. If you want to hide specific ones, do a get_function(id) and set_visible.
Hope this helps.
Regards
Nithya
Maybe you are looking for
-
Unable to hide feilds for a limit item at PO level in SRM 7.0
Hi, Currently we are working in SRM 7.0. extended classic scenario. While creating a limit item at PO level we are unable to control the custom feilds in general data tab. We have created some custom fields. And we are trying to control (Visible,Enab
-
Just updated to Mavericks (10.9.4) on my MacBook Pro, and among many other annoying issues, when I type out an email I cannot easily edit the text once typed. For instance if I misspell a word, I cannot click on it with my cursor to edit; I have to c
-
Ical not sending email notifications
iCal no longer sends email reminders. I have come to rely on this feature and it no longer works. I am running OS 10.6.
-
I have created asset Lines for Capital Projects .Asset Lines status is Pending. After that I have run Interface assets to Oracle Assets . But asset lines are not yet interfaced . Please suggest what to do ??
-
Jsp/custom tag compiler error (HttpServletResponse)
I originally posted with on Oracle's site but I am not getting any help. Our server is running Oracle 9ias with JServ and Apache. I have created a simple jsp that calls a custom tag but I am getting the following error: Method addHeader(java.lang.Str