Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding ALV Grid Control using OOPs concepts

Former Member
0 Kudos

Hi ABAP Gurus,

Acutally i dnt have any knowledge on OOPs concepts, i have an object i.e. ALV Grid Control using OOPs concepts..

hope tht sumone will help to get through

here is the requirement, if at all anyone had already done the related , pls send the stuff needed or else any suggestions

OBJECT:

Technical specification deals with the Table Maintenance handled for the Z tables through ALV GRID control in a Module Pool Program.

Screen processing logic

Based on the selection criteria filled in the first screen of the transactions, rows are selected from the corresponding Z tables and displayed via an ALV grid control in Screen 1002.

Validations

Screen 1000:

Check the database entries for the Selection criteria. If the database entries do not match then display error message in the Status Bar for the respective entry.

Screen 1001:

Check the database entries for the Selection criteria. If the database entries do not match then display error message in the Status Bar for the respective entry.

Screen 1002:

When the Save button is pressed and an empty row(s) is/are saved, then delete the empty rows that have been inserted.

When the Save button is clicked, the field entries are checked with the Database entries and if any discrepancy is met, an Error message is displayed in the Status bar stating, “Check the Field Entries”.

After the entries are saved successfully to the database table a Success message is displayed in the Status bar, “Changes were saved”.

When the Change/Delete button is pressed without selecting any row then display the error message stating, “Select a row to perform the operation”.

When the delete button is clicked, a pop up is shown to confirm delete and pressing the delete button again deletes the row/rows which has the lock icon.

When the user clicks the Display button, a pop is shown to confirm for save.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI

check the below links lot of info and examples r there for <b><u>OOPS</u></b>

http://www.sapgenie.com/abap/OO/index.htm

http://www.geocities.com/victorav15/sapr3/abap_ood.html

http://www.brabandt.de/html/abap_oo.html

<b>Check this cool weblog:</b>

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm

http://www.sapgenie.com/abap/OO/

http://www.sapgenie.com/abap/OO/index.htm

http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm

http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt

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

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

http://www.allsaplinks.com/

http://www.sap-img.com/

http://www.sapgenie.com/

http://help.sap.com

http://www.sapgenie.com/abap/OO/

http://www.sapgenie.com/abap/OO/index.htm

http://www.sapgenie.com/abap/controls/index.htm

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

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

http://www.sapgenie.com/abap/OO/index.htm

http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

http://www.sapgenie.com/abap/OO/

<b>these links</b>

http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm

<b>For funtion module to class</b>

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm

<b>

for classes</b>

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm

<b>for methods</b>

http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm

<b>for inheritance</b>

http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm

<b>for interfaces</b>

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm

<u><b>For Materials:</b></u>

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

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

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

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

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

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

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

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

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

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

<b><u>Check these sample code</u></b>

data : begin of it_mara occurs 0,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara.
 
data : begin of it_mara1 occurs 0,
* mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara1.
 
data : begin of it_mara2 occurs 0,
* mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara2.
 
data : t_fieldcat type lvc_t_fcat,
t_fieldcat1 type lvc_t_fcat,
 
s_fieldcat like line of t_fieldcat.
 
data : s_layout type lvc_s_layo.
 
data : control type ref to cl_gui_custom_container,
grid type ref to cl_gui_alv_grid.
 
 
data: begin of wa ,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of wa.
 
class lcl_events_box definition.
 
public section.
 
methods :
 
*Handler_Data_Changed for event Data_Changed of cl_gui_alv_grid
*imporTing er_data_changed,
*
Handler_User_Command for event User_Command of cl_gui_alv_grid
imporTing e_ucomm,
 
Handler_ToolBar for event ToolBar of cl_gui_alv_grid
importing E_object E_interactive.
 
endclass.
 
class lcl_events_box implementation.
 
method Handler_user_command.
 
PERFORM FORM_USERCOMMAND CHANGING E_UCOMM.
endmethod.
 
method Handler_ToolBar.
PERFORM FORM_TOOLBAR CHANGING E_OBJECT E_INTERACTIVE
E_OBJECT->MT_TOOLBAR.
endmethod.
 
ENDCLASS.
 
start-of-selection.
data : w_events type ref to lcl_events_box.
 
select matnr mtart meins from mara into corresponding fields of table
it_mara.
 
call screen 100.
*&---------------------------------------------------------------------*
*& Module pbo_module OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo_module OUTPUT.
if GRID is initial.
 
CREATE OBJECT CONTROL
EXPORTING
CONTAINER_NAME = 'CUST_CTRL'.
 
 
CREATE OBJECT GRID
EXPORTING
I_PARENT = CONTROL.
 
PERFORM BUILD_CATALOG.
 
PERFORM BUILD_CATALOG1.
 
PERFORM BUILD_LAYOUT.
 
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = s_layout
CHANGING
IT_OUTTAB = it_mara[]
IT_FIELDCATALOG = t_fieldcat.
 
 
 
CREATE OBJECT W_EVENTS.
SET HANDLER : W_EVENTS->HANDLER_TOOLBAR FOR GRID,
W_EVENTS->HANDLER_USER_COMMAND FOR GRID.
 
CALL METHOD GRID->SET_TOOLBAR_INTERACTIVE.
 
ELSE.
call method grid->refresh_table_display.
 
 
ENDIF.
ENDMODULE. " pbo_module OUTPUT
*&---------------------------------------------------------------------*
*& Form BUILD_CATALOG
 
FORM BUILD_CATALOG .
 
S_FIELDCAT-COL_POS = '1'.
S_FIELDCAT-FIELDNAME = 'MARK'.
S_FIELDCAT-CHECKBOX = 'X'.
S_FIELDCAT-eDIT = 'X'.
APPEND S_FIELDCAT TO T_FIELDCAT.
CLEAR S_FIELDCAT.
 
S_FIELDCAT-COL_POS = '2'.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-SCRTEXT_M = 'MATERIAL'.
APPEND S_FIELDCAT TO T_FIELDCAT.
 
S_FIELDCAT-COL_POS = '3'.
S_FIELDCAT-FIELDNAME = 'MTART'.
S_FIELDCAT-SCRTEXT_M = 'MATERL TYPE'.
APPEND S_FIELDCAT TO T_FIELDCAT.
 
S_FIELDCAT-COL_POS = '4'.
S_FIELDCAT-FIELDNAME = 'MEINS'.
S_FIELDCAT-SCRTEXT_M = 'UOM'.
APPEND S_FIELDCAT TO T_FIELDCAT.
 
ENDFORM. " BUILD_CATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT .
S_LAYOUT-ZEBRA = 'X'.
* S_LAYOUT-CWIDTH_OPT = 'X'.
S_LAYOUT-GRID_TITLE = 'Material Details'.
ENDFORM.
" BUILD_LAYOUT////////////////////////////////////
" USER_COMMAND_0100 INPUT
 
*&---------------------------------------------------------------------*
*& Form FORM_USERCOMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_E_UCOMM text
*----------------------------------------------------------------------*
form FORM_USERCOMMAND changing p_e_ucomm.
 
CASE P_E_UCOMM.
 
WHEN 'INT1'.
 
DO.
 
READ TABLE IT_MARA INDEX SY-INDEX TRANSPORTING MARK MATNR.
 
 
IF SY-SUBRC <> 0.
 
EXIT.
 
ENDIF.
 
IF IT_MARA-MARK = 'X'.
 
read table it_mara into wa TRANSPORTING MATNR MTART MEINS .
MOVE-CORRESPONDING WA TO IT_MARA1.
READ TABLE IT_MARA1 TRANSPORTING MATNR MTART MEINS .
MOVE-CORRESPONDING IT_MARA1 TO IT_MARA2.
APPEND IT_MARA2.
 
 
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = s_layout
CHANGING
IT_OUTTAB = it_mara2[]
IT_FIELDCATALOG = t_fieldcat1.
*
* SET PARAMETER ID 'MAT' FIELD IT_MARA-MATNR.
* CALL TRANSACTION 'MM02'.
. ENDIF.
* ENDIF.
ENDDO.
ENDCASE.
endform. " FORM_USERCOMMAND
*&---------------------------------------------------------------------*
*& Form FORM_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_E_OBJECT text
* <--P_E_INTERACTIVE text
* <--P_E_OBJECT_>MT_TOOLBAR text
*----------------------------------------------------------------------*
FORM FORM_TOOLBAR CHANGING P_E_OBJECT TYPE REF TO
CL_ALV_EVENT_TOOLBAR_SET
P_E_INTERACTIVE
MT_TOOLBAR TYPE TTB_BUTTON.
 
 
DATA WAL_BUTTON TYPE STB_BUTTON.
 
*WAL_BUTTON-ICON = ICON_status_reverse.
WAL_BUTTON-TEXT = 'GO'.
WAL_BUTTON-QUICKINFO = 'PROCEED'.
waL_button-FUNCTION = 'INT1'.
WAL_BUTTON-BUTN_TYPE = 0.
WAL_BUTTON-DISABLED = SPACE.
insert WAL_BUTTON INTO P_E_OBJECT->MT_TOOLBAR index 1.
 
endform. " FORM_TOOLBAR
*&---------------------------------------------------------------------*
*& Module PF-STATUS OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module PF-STATUS output.
 
set pf-status 'Z7PSTAT'.
 
endmodule. " PF-STATUS OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module USER_COMMAND_0100 input.
 
CASE SY-UCOMM.
 
 
WHEN 'BACK'.
LEAVE PROGRAM.
 
WHEN 'CANCEL'.
LEAVE PROGRAM.
 
 
ENDCASE.
 
 
endmodule. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_CATALOG1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BUILD_CATALOG1 .
 
S_FIELDCAT-COL_POS = '1'.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-SCRTEXT_M = 'MATERIAL'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
 
S_FIELDCAT-COL_POS = '2'.
S_FIELDCAT-FIELDNAME = 'MTART'.
S_FIELDCAT-SCRTEXT_M = 'MATERL TYPE'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
 
S_FIELDCAT-COL_POS = '3'.
S_FIELDCAT-FIELDNAME = 'MEINS'.
S_FIELDCAT-SCRTEXT_M = 'UOM'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
 
 
endform. " BUILD_CATALOG1 


check the below link may be useful for you

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf

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

Go thru these programs they may help u to try on some hands on

ALV Demo program

BCALV_DEMO_HTML

BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode

BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode

BCALV_GRID_DEMO Simple ALV Control Call Demo Program

BCALV_TREE_DEMO Demo for ALV tree control

BCALV_TREE_SIMPLE_DEMO

BC_ALV_DEMO_HTML_D0100

Reward all helpfull answers

Regards

Pavan

Message was edited by:

Pavan praveen

3 REPLIES 3

Former Member
0 Kudos

HI

check the below links lot of info and examples r there for <b><u>OOPS</u></b>

http://www.sapgenie.com/abap/OO/index.htm

http://www.geocities.com/victorav15/sapr3/abap_ood.html

http://www.brabandt.de/html/abap_oo.html

<b>Check this cool weblog:</b>

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm

http://www.sapgenie.com/abap/OO/

http://www.sapgenie.com/abap/OO/index.htm

http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm

http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt

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

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

http://www.allsaplinks.com/

http://www.sap-img.com/

http://www.sapgenie.com/

http://help.sap.com

http://www.sapgenie.com/abap/OO/

http://www.sapgenie.com/abap/OO/index.htm

http://www.sapgenie.com/abap/controls/index.htm

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

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

http://www.sapgenie.com/abap/OO/index.htm

http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

http://www.sapgenie.com/abap/OO/

<b>these links</b>

http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm

<b>For funtion module to class</b>

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm

<b>

for classes</b>

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm

<b>for methods</b>

http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm

<b>for inheritance</b>

http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm

<b>for interfaces</b>

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm

<u><b>For Materials:</b></u>

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

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

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

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

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

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

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

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

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

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

<b><u>Check these sample code</u></b>

data : begin of it_mara occurs 0,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara.
 
data : begin of it_mara1 occurs 0,
* mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara1.
 
data : begin of it_mara2 occurs 0,
* mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara2.
 
data : t_fieldcat type lvc_t_fcat,
t_fieldcat1 type lvc_t_fcat,
 
s_fieldcat like line of t_fieldcat.
 
data : s_layout type lvc_s_layo.
 
data : control type ref to cl_gui_custom_container,
grid type ref to cl_gui_alv_grid.
 
 
data: begin of wa ,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of wa.
 
class lcl_events_box definition.
 
public section.
 
methods :
 
*Handler_Data_Changed for event Data_Changed of cl_gui_alv_grid
*imporTing er_data_changed,
*
Handler_User_Command for event User_Command of cl_gui_alv_grid
imporTing e_ucomm,
 
Handler_ToolBar for event ToolBar of cl_gui_alv_grid
importing E_object E_interactive.
 
endclass.
 
class lcl_events_box implementation.
 
method Handler_user_command.
 
PERFORM FORM_USERCOMMAND CHANGING E_UCOMM.
endmethod.
 
method Handler_ToolBar.
PERFORM FORM_TOOLBAR CHANGING E_OBJECT E_INTERACTIVE
E_OBJECT->MT_TOOLBAR.
endmethod.
 
ENDCLASS.
 
start-of-selection.
data : w_events type ref to lcl_events_box.
 
select matnr mtart meins from mara into corresponding fields of table
it_mara.
 
call screen 100.
*&---------------------------------------------------------------------*
*& Module pbo_module OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo_module OUTPUT.
if GRID is initial.
 
CREATE OBJECT CONTROL
EXPORTING
CONTAINER_NAME = 'CUST_CTRL'.
 
 
CREATE OBJECT GRID
EXPORTING
I_PARENT = CONTROL.
 
PERFORM BUILD_CATALOG.
 
PERFORM BUILD_CATALOG1.
 
PERFORM BUILD_LAYOUT.
 
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = s_layout
CHANGING
IT_OUTTAB = it_mara[]
IT_FIELDCATALOG = t_fieldcat.
 
 
 
CREATE OBJECT W_EVENTS.
SET HANDLER : W_EVENTS->HANDLER_TOOLBAR FOR GRID,
W_EVENTS->HANDLER_USER_COMMAND FOR GRID.
 
CALL METHOD GRID->SET_TOOLBAR_INTERACTIVE.
 
ELSE.
call method grid->refresh_table_display.
 
 
ENDIF.
ENDMODULE. " pbo_module OUTPUT
*&---------------------------------------------------------------------*
*& Form BUILD_CATALOG
 
FORM BUILD_CATALOG .
 
S_FIELDCAT-COL_POS = '1'.
S_FIELDCAT-FIELDNAME = 'MARK'.
S_FIELDCAT-CHECKBOX = 'X'.
S_FIELDCAT-eDIT = 'X'.
APPEND S_FIELDCAT TO T_FIELDCAT.
CLEAR S_FIELDCAT.
 
S_FIELDCAT-COL_POS = '2'.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-SCRTEXT_M = 'MATERIAL'.
APPEND S_FIELDCAT TO T_FIELDCAT.
 
S_FIELDCAT-COL_POS = '3'.
S_FIELDCAT-FIELDNAME = 'MTART'.
S_FIELDCAT-SCRTEXT_M = 'MATERL TYPE'.
APPEND S_FIELDCAT TO T_FIELDCAT.
 
S_FIELDCAT-COL_POS = '4'.
S_FIELDCAT-FIELDNAME = 'MEINS'.
S_FIELDCAT-SCRTEXT_M = 'UOM'.
APPEND S_FIELDCAT TO T_FIELDCAT.
 
ENDFORM. " BUILD_CATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT .
S_LAYOUT-ZEBRA = 'X'.
* S_LAYOUT-CWIDTH_OPT = 'X'.
S_LAYOUT-GRID_TITLE = 'Material Details'.
ENDFORM.
" BUILD_LAYOUT////////////////////////////////////
" USER_COMMAND_0100 INPUT
 
*&---------------------------------------------------------------------*
*& Form FORM_USERCOMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_E_UCOMM text
*----------------------------------------------------------------------*
form FORM_USERCOMMAND changing p_e_ucomm.
 
CASE P_E_UCOMM.
 
WHEN 'INT1'.
 
DO.
 
READ TABLE IT_MARA INDEX SY-INDEX TRANSPORTING MARK MATNR.
 
 
IF SY-SUBRC <> 0.
 
EXIT.
 
ENDIF.
 
IF IT_MARA-MARK = 'X'.
 
read table it_mara into wa TRANSPORTING MATNR MTART MEINS .
MOVE-CORRESPONDING WA TO IT_MARA1.
READ TABLE IT_MARA1 TRANSPORTING MATNR MTART MEINS .
MOVE-CORRESPONDING IT_MARA1 TO IT_MARA2.
APPEND IT_MARA2.
 
 
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = s_layout
CHANGING
IT_OUTTAB = it_mara2[]
IT_FIELDCATALOG = t_fieldcat1.
*
* SET PARAMETER ID 'MAT' FIELD IT_MARA-MATNR.
* CALL TRANSACTION 'MM02'.
. ENDIF.
* ENDIF.
ENDDO.
ENDCASE.
endform. " FORM_USERCOMMAND
*&---------------------------------------------------------------------*
*& Form FORM_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_E_OBJECT text
* <--P_E_INTERACTIVE text
* <--P_E_OBJECT_>MT_TOOLBAR text
*----------------------------------------------------------------------*
FORM FORM_TOOLBAR CHANGING P_E_OBJECT TYPE REF TO
CL_ALV_EVENT_TOOLBAR_SET
P_E_INTERACTIVE
MT_TOOLBAR TYPE TTB_BUTTON.
 
 
DATA WAL_BUTTON TYPE STB_BUTTON.
 
*WAL_BUTTON-ICON = ICON_status_reverse.
WAL_BUTTON-TEXT = 'GO'.
WAL_BUTTON-QUICKINFO = 'PROCEED'.
waL_button-FUNCTION = 'INT1'.
WAL_BUTTON-BUTN_TYPE = 0.
WAL_BUTTON-DISABLED = SPACE.
insert WAL_BUTTON INTO P_E_OBJECT->MT_TOOLBAR index 1.
 
endform. " FORM_TOOLBAR
*&---------------------------------------------------------------------*
*& Module PF-STATUS OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module PF-STATUS output.
 
set pf-status 'Z7PSTAT'.
 
endmodule. " PF-STATUS OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module USER_COMMAND_0100 input.
 
CASE SY-UCOMM.
 
 
WHEN 'BACK'.
LEAVE PROGRAM.
 
WHEN 'CANCEL'.
LEAVE PROGRAM.
 
 
ENDCASE.
 
 
endmodule. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_CATALOG1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BUILD_CATALOG1 .
 
S_FIELDCAT-COL_POS = '1'.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-SCRTEXT_M = 'MATERIAL'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
 
S_FIELDCAT-COL_POS = '2'.
S_FIELDCAT-FIELDNAME = 'MTART'.
S_FIELDCAT-SCRTEXT_M = 'MATERL TYPE'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
 
S_FIELDCAT-COL_POS = '3'.
S_FIELDCAT-FIELDNAME = 'MEINS'.
S_FIELDCAT-SCRTEXT_M = 'UOM'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
 
 
endform. " BUILD_CATALOG1 


check the below link may be useful for you

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf

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

Go thru these programs they may help u to try on some hands on

ALV Demo program

BCALV_DEMO_HTML

BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode

BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode

BCALV_GRID_DEMO Simple ALV Control Call Demo Program

BCALV_TREE_DEMO Demo for ALV tree control

BCALV_TREE_SIMPLE_DEMO

BC_ALV_DEMO_HTML_D0100

Reward all helpfull answers

Regards

Pavan

Message was edited by:

Pavan praveen

0 Kudos

i wld like to thank you first for sharing.

but in my alv grid , i need these functionalities, let me knw how can i do get them...., pls can u provide the code if at all u can...

<u>If Insert Row button of Screen 1000/1001 was clicked:</u>

If the Insert Row button was clicked the ALV grid is displayed to the user but with no content. But the ALV grid is constructed to have the same structure of the corresponding Z table following the respective transaction as mentioned above.

<u>If Maintain Entries button of Screen 1000/1001 was clicked:</u>

If the Maintain Entries Button was clicked, then the ALV grid is displayed with the database entries based on the Selection Criteria for the Z tables. These are also loaded into the internal table IT_TAB_ROWS.

There are various options provided in the Screen 1002 to facilitate the user to maintain the Z tables.

They are:

&#61656;<u>Insert row:</u>

Inserts a row in the ALV grid. The row index of the row that has been inserted is loaded into the internal table IT_TAB_ROW_INDEX. When a row is inserted, all the entries are blank except the Costing Version. This entry is internally filled by the program using the value Z_GL_ALLOC_PLAN_VERSN from the TVARVC table and this field is set as disabled in the ALV grid.

&#61656;<u>Select All</u>:

Select All button when clicked selects all the rows that have been displayed in the ALV grid.

&#61656;<u>Deselect All:</u>

Deselect All button when clicked deselects all the rows that have been selected previously.

&#61656;<u>Save:</u>

1) When the save button is clicked the user is prompted with the confirmation to save the data.

2) If the user agrees to save the data then the rows then the changes are updated to the database. This can be identified by the rows that have been selected for change mode (on which the lock icon is present). The lock icons will be removed, the changes will be reflected in the database and the rows are displayed in the display mode. The internal table IT_TAB_ROW_INDEX is looped to fetch the row index and then the row details are fetched from the ALV grid. These row details are loaded into the internal table IT_TAB_ROWS. If the row already exists in the internal table then the row is modified, and the field CHANGED is marked as ‘X’. If the entry does not exist, then a new row is inserted into the internal table IT_TAB_ROWS and the INSERTED field is marked as ‘X’. Now the internal table IT_TAB_ROWS is looped to select the rows with CHANGED field as marked. These rows are inserted into the Z table, and the rows with INSERTED ‘X’ is selected and they are inserted into the Z table.

3) If the user rejects the save option then, discard the changes made, remove the lock icons and display the rows in display mode.

4) The rows which are newly inserted are also saved to the database after validating them with the database entries.

&#61656;<u>Change/Display:</u>

<u>Change:</u>

1)When row/rows are selected and Change option is clicked then, locking is applied for the particular row/rows in the Z table.

2)If the locking succeeds, a lock icon appears near the row/rows and the Savings% fields of the row/rows are activated in change mode. The row indexes of the rows are stored in the internal table IT_TAB_ROW_INDEX.

3)If the locking fails for the row then, a message is displayed in the Status bar stating “Locking failed for the row(s) selected” and the row/ rows selected are in display mode only.

<u>Display:</u>

1)When row/rows are selected and the Display option is clicked then, the user is prompted for a Save of the data.

2)If the user, confirms the Save, then the changes are accepted, the lock icons are removed from the row/rows and the row/rows are activated in display mode with the updated data. Follow the same logic used in the Save button.

3)If the user rejects the Save, then the changes are discarded, the lock icons are removed and the row/rows are activated in display mode.

&#61656;<u>Delete:</u>

When the row/rows selected needs to be deleted, then the Delete button is clicked.

When the delete button is clicked, user is given a pop up which says that locking has been applied to the row/rows and he/she needs to click the delete button again to delete the records. A lock icon appears near the row/rows for which locking was successful. These row/rows will be selected. The indexes of the row/rows are loaded into the internal table IT_TAB_ROW_INDEX. When the user clicks the delete button again, the rows for which the lock icon appeared will be deleted. This is done by loading the indexes of the row/rows into the internal table IT_TAB_ROW_INDEX. The internal table is looped and the row details are fetched from the ALV grid. For this row in the internal table IT_TAB_ROWS the DELETED field is marked as ‘X’. The records which has ‘X’ marked in DELETED field are selected and they are deleted from the Z table.

&#61656;<u>Sort:</u>

Selecting the column and clicking the sort button will enable the data to be sorted based on the column.

Former Member
0 Kudos

Have a look at below link. Its a PDF document Which will give you information abt OO ALV.

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf

Also have a look at below link.

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

Check the following standard programs also.

BCALV_GRID_01 to BCALV_GRID_11,BCALV_GRID_DEMO.

sample

*&----


*

*& Include Z_TABLE_DISPLAY

*&----


*

  • VERSION 2

*

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

  • HOW TO

*

  • Display an ALV grid :

  • CALL METHOD lcl_table_display=>display_grid( 'tabname' ).

*

  • Display a hierarchical list with header and detail :

  • CALL METHOD lcl_table_display=>display_hier( in_header = 'table1'

  • in_detail = 'table2' ).

*

  • Display a block list with two tables :

  • CALL METHOD lcl_table_display=>set_block_mode( 'X' ).

  • CALL METHOD lcl_table_display=>display_grid( 'table1' ).

  • CALL METHOD lcl_table_display=>display_grid( 'table2' ).

  • CALL METHOD lcl_table_display=>end_block_list( ).

*

  • You never have to deal with field catalog of tables !!

*

  • What if field catalog has to be changed anyway ?

*

  • ob_table = lcl_table_display=>create_table( 'tabname' ).

  • CALL METHOD ob_table->set_alv_fieldtext( in_field = field

  • in_ftext = 'text' ).

  • CALL METHOD lcl_table_display=>display_grid( 'tabname' ).

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

type-pools: abap, slis.

*----


*

  • LCL_TABLE_DISPLAY DEFINITION

*----


*

class lcl_table_display definition.

public section.

class-methods: display_list importing in_tabname type any,

display_grid importing in_tabname type any,

display_hier importing in_header type any

in_detail type any

in_level type i optional,

set_block_mode importing in_mode type c,

set_block_text importing in_text type any,

end_block_list importing in_print

type slis_print_alv optional

exceptions display_error,

create_table

importing

in_tabname type tabname

returning

value(out_table) type ref to lcl_table_display

exceptions

create_error,

get_existing_table

importing

in_tabname type any optional

in_repid type any optional

in_struc type any optional

returning

value(out_table) type ref to lcl_table_display

exceptions

no_parameter

not_found,

refresh_objects.

methods: constructor importing in_data type standard table

exceptions casting_error

empty_fieldcat.

methods: get_alv_fieldcat returning value(out_fieldcat)

type slis_t_fieldcat_alv.

methods: set_table_name importing in_tabname type any,

set_alv_title importing in_title type any,

set_alv_fieldcat importing in_fieldcat

type slis_t_fieldcat_alv,

set_alv_fieldnoout importing in_field type any

in_noout type c optional

in_tech type c optional,

set_alv_fieldedit importing in_field type any

in_edit type c optional,

set_alv_fieldtext importing in_field type any

in_ftext type any,

set_alv_fieldsum importing in_field type any

in_dosum type c optional,

set_alv_linebreak importing in_field type any,

set_alv_settings importing in_settings type any,

set_alv_layout importing in_layout type any,

set_alv_print importing in_print type any,

set_alv_sorting importing in_field type any

in_desc type c optional

in_group type any optional

in_subtot type c optional,

set_alv_keys importing in_level type i

in_key type c optional,

set_alv_event importing in_name type any

in_form type any,

set_all_events.

protected section.

data: g_table_type type slis_list_type.

data: g_title type lvc_title,

gt_fcat type slis_t_fieldcat_alv,

gs_sett type lvc_s_glay,

gs_layo type slis_layout_alv,

gt_sort type slis_t_sortinfo_alv,

gt_evnt type slis_t_event,

gs_prin type slis_print_alv.

class-methods: output_hierarchy exceptions display_error.

methods: output_table importing mode type c

exceptions display_error,

output_list,

output_grid.

private section.

class-data: gt_table_obj type table of ref to lcl_table_display,

g_header_table type ref to lcl_table_display,

g_detail_table type ref to lcl_table_display.

class-data: g_variant_level type i.

class-data: g_block_mode type c,

g_block_text type slis_text40.

types: begin of ty_defin,

fieldname type fieldname,

ref_tabname type tabname,

ref_fieldname type fieldname,

end of ty_defin.

data: g_repid type repid,

g_struc type tabname,

g_table type tabname.

data: gt_data type ref to data.

data: gt_defin type table of ty_defin,

g_level type tabname.

methods: init_block_list,

fill_fieldcat importing repid type repid

struc type tabname

changing fcat type slis_t_fieldcat_alv

exceptions no_definition,

get_definition importing repid type repid

struc type tabname

changing abap type rsfb_source,

recursive_definition importing repid type repid

changing abap type rsfb_source,

map_structure importing source type any

changing destin type any,

get_default_variant changing out_variant type disvariant.

endclass. "lcl_table_display DEFINITION

*----


*

  • LCL_TABLE_DISPLAY IMPLEMENTATION

*----


*

class lcl_table_display implementation.

***

  • Display table in ALV list

***

method display_list.

data: l_object type ref to lcl_table_display,

l_tabname type tabname,

l_found type c.

l_tabname = in_tabname.

loop at gt_table_obj into l_object.

if l_object->g_table = l_tabname.

l_found = 'X'.

exit.

endif.

endloop.

if l_found is initial.

l_object = lcl_table_display=>create_table( l_tabname ).

if g_block_mode is initial.

l_object->g_table_type = 4.

else.

l_object->g_table_type = 2.

endif.

call method l_object->set_all_events.

endif.

call method l_object->output_list.

endmethod. "display_list

***

  • Display table in ALV grid

***

method display_grid.

data: l_object type ref to lcl_table_display,

l_tabname type tabname,

l_found type c.

l_tabname = in_tabname.

loop at gt_table_obj into l_object.

if l_object->g_table = l_tabname.

l_found = 'X'.

exit.

endif.

endloop.

if l_found is initial.

l_object = lcl_table_display=>create_table( l_tabname ).

if g_block_mode is initial.

l_object->g_table_type = 4.

else.

l_object->g_table_type = 2.

endif.

call method l_object->set_all_events.

endif.

if g_block_mode is initial.

call method l_object->output_grid.

else.

call method l_object->output_list.

endif.

endmethod. "display_grid

***

  • Display tables in ALV hierarchy

***

method display_hier.

data: l_tabnam1 type tabname,

l_tabnam2 type tabname,

lt_fcat1 type slis_t_fieldcat_alv,

lt_fcat2 type slis_t_fieldcat_alv,

ls_fcat1 type slis_fieldcat_alv,

ls_fcat2 type slis_fieldcat_alv.

l_tabnam1 = in_header.

l_tabnam2 = in_detail.

call method lcl_table_display=>get_existing_table

exporting

in_tabname = l_tabnam1

receiving

out_table = g_header_table

exceptions

not_found = 1.

if sy-subrc ne 0.

g_header_table = lcl_table_display=>create_table( l_tabnam1 ).

if g_block_mode is initial.

g_header_table->g_table_type = 1.

else.

g_header_table->g_table_type = 3.

endif.

call method g_header_table->set_all_events.

endif.

call method lcl_table_display=>get_existing_table

exporting

in_tabname = l_tabnam2

receiving

out_table = g_detail_table

exceptions

not_found = 1.

if sy-subrc ne 0.

g_detail_table = lcl_table_display=>create_table( l_tabnam2 ).

endif.

  • Set key fields

if in_level is initial.

lt_fcat1 = g_header_table->get_alv_fieldcat( ).

lt_fcat2 = g_detail_table->get_alv_fieldcat( ).

loop at lt_fcat1 into ls_fcat1.

ls_fcat1-key = space.

loop at lt_fcat2 into ls_fcat2

where fieldname = ls_fcat1-fieldname.

ls_fcat2-key = space.

ls_fcat2-key_sel = 'X'.

ls_fcat2-tech = 'X'.

modify lt_fcat2 from ls_fcat2 transporting key.

endloop.

if sy-subrc = 0.

ls_fcat1-key = 'X'.

endif.

modify lt_fcat1 from ls_fcat1 transporting key.

endloop.

call method g_header_table->set_alv_fieldcat

exporting

in_fieldcat = lt_fcat1.

call method g_detail_table->set_alv_fieldcat

exporting

in_fieldcat = lt_fcat2.

else.

call method g_header_table->set_alv_keys

exporting

in_level = in_level.

call method g_detail_table->set_alv_keys

exporting

in_level = in_level

in_key = space.

endif.

call method output_hierarchy.

endmethod. "display_hier

***

  • Set block mode

***

method set_block_mode.

g_block_mode = in_mode.

endmethod. "set_block_mode

***

  • Set block text

***

method set_block_text.

g_block_text = in_text.

endmethod. "set_block_text

***

  • Create new table

***

method create_table.

data: l_object type ref to lcl_table_display.

field-symbols: set_table_name

exporting

in_tabname = in_tabname.

  • Default print options

l_object->gs_prin-no_print_selinfos = 'X'.

l_object->gs_prin-no_coverpage = 'X'.

l_object->gs_prin-no_print_listinfos = 'X'.

out_table = l_object.

endmethod. "create_table

***

  • Get existing table

***

method get_existing_table.

data: l_object type ref to lcl_table_display,

l_tabname type tabname,

l_repid type repid,

l_struc type tabname,

l_found type c.

l_tabname = in_tabname.

l_repid = in_repid.

l_struc = in_struc.

if l_tabname is initial.

if l_repid is initial and

l_struc is initial.

raise no_parameter.

else.

  • Get last existing table with same definition

loop at gt_table_obj into l_object.

if l_object->g_repid = l_repid and

l_object->g_struc = l_struc.

l_found = 'X'.

exit.

endif.

endloop.

endif.

else.

  • Get last existing table with same name

loop at gt_table_obj into l_object.

if l_object->g_table = l_tabname.

l_found = 'X'.

exit.

endif.

endloop.

endif.

if l_found is initial.

raise not_found.

else.

out_table = l_object.

endif.

endmethod. "get_existing_table

***

  • Create table display

***

method constructor.

data: l_object type ref to lcl_table_display.

data: ls_data type ref to data.

data: ob_desc type ref to cl_abap_structdescr.

data: l_found type c,

l_absol type char200,

l_repid type repid,

l_struc type tabname.

field-symbols: type any.

  • Get data and store it into attribute

create data me->gt_data like in_data.

assign me->gt_data->* to .

= in_data.

  • Get global data definition

create data ls_data like line of ).

endcatch.

if sy-subrc = 1.

raise casting_error.

endif.

  • Get program name and main type used to define table

l_absol = ob_desc->absolute_name.

split l_absol at 'TYPE=' into l_repid l_struc.

shift l_repid up to '='.

shift l_repid.

check l_struc np '%_*'.

  • Set attributes

me->g_repid = l_repid.

me->g_struc = l_struc.

me->g_table = l_struc.

replace 'TY' with 'WT' into me->g_table.

  • Field catalog

call method lcl_table_display=>get_existing_table

exporting

in_repid = l_repid

in_struc = l_struc

receiving

out_table = l_object

exceptions

not_found = 1.

if sy-subrc = 0.

me->gt_fcat = l_object->get_alv_fieldcat( ).

call method set_table_name

exporting

in_tabname = me->g_table.

else.

call method fill_fieldcat

exporting

repid = l_repid

struc = l_struc

changing

fcat = me->gt_fcat.

if me->gt_fcat is initial.

raise empty_fieldcat.

endif.

endif.

  • Keep list of tables

append me to gt_table_obj.

endmethod. "constructor

***

  • Output list

***

method output_list.

call method output_table

exporting

mode = 'L'.

endmethod. "output_list

***

  • Output grid

***

method output_grid.

call method output_table

exporting

mode = 'G'.

endmethod. "output_grid

***

  • Output table

***

method output_table.

data: l_object type ref to lcl_table_display.

data: ls_vari type disvariant.

field-symbols: type standard table.

assign me->gt_data->* to .

if not g_block_mode is initial.
read table gt_table_obj into l_object index 1.
if sy-subrc = 0.
if l_object->g_table = me->

g_table.

call method init_block_list.

endif.

endif.

endif.

  • Get default user variant

call method get_default_variant

changing

out_variant = ls_vari.

  • Display table contents

if mode = 'G'.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = me->g_repid

i_grid_title = me->g_title

i_grid_settings = me->gs_sett

is_layout = me->gs_layo

it_fieldcat = me->gt_fcat

it_sort = me->gt_sort

i_save = 'U'

is_variant = ls_vari

it_events = me->gt_evnt

is_print = me->gs_prin

tables

t_outtab =
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
raise display_error.
endif.
call method refresh_objects.
else.
if g_block_mode is initial.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = me->g_repid
is_layout = me->gs_layo
it_fieldcat = me->gt_fcat
it_sort = me->gt_sort
i_save = 'U'
is_variant = ls_vari
it_events = me->gt_evnt
is_print = me->gs_prin
tables
t_outtab =
exceptions
others = 0.
if sy-subrc <> 0.
raise display_error.
endif.
call method refresh_objects.
else.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = me->gs_layo
it_fieldcat = me->gt_fcat
i_tabname = me->g_table
it_events = me->gt_evnt
it_sort = me->gt_sort
i_text = g_block_text
tables
t_outtab =
exceptions
program_error = 1
maximum_of_appends_reached = 2
others = 3.
if sy-subrc <>

0.

raise display_error.

endif.

endif.

endif.

endmethod. "output_table

***

  • Output hierarchy

***

method output_hierarchy.

data: l_object type ref to lcl_table_display.

data: lt_fcat type slis_t_fieldcat_alv,

lt_sort type slis_t_sortinfo_alv,

ls_fcat type slis_fieldcat_alv,

ls_vari type disvariant,

ls_keyi type slis_keyinfo_alv.

data: l_index type numc2,

l_field type fieldname.

field-symbols: .

  • Set key fields as common fields between header and detail

loop at g_header_table->gt_fcat into ls_fcat

where key = 'X'.

l_index = l_index + 1.

  • Create link

concatenate 'HEADER' l_index into l_field.

assign component l_field of structure ls_keyi to init_block_list.

endif.

endif.

endif.

  • Get default user variant

call method g_header_table->get_default_variant

changing

out_variant = ls_vari.

if g_block_mode is initial.

call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

exporting

i_callback_program = g_header_table->g_repid

is_layout = g_header_table->gs_layo

it_fieldcat = lt_fcat

it_sort = lt_sort

i_save = 'U'

is_variant = ls_vari

it_events = g_header_table->gt_evnt

i_tabname_header = g_header_table->g_table

i_tabname_item = g_detail_table->g_table

is_keyinfo = ls_keyi

is_print = g_header_table->gs_prin

tables

t_outtab_header = 0.

raise display_error.

endif.

endif.

endmethod. "output_hierarchy

***

  • Init block list

***

method init_block_list.

data: ls_evnt1 type slis_alv_event,

ls_evnt2 type slis_alv_event.

  • Events for whole list display

concatenate 'F_' slis_ev_pf_status_set '_BLOCK'

into ls_evnt1-form.

concatenate 'F_' slis_ev_user_command '_BLOCK'

into ls_evnt2-form.

  • Initialization of block list

call function 'REUSE_ALV_BLOCK_LIST_INIT'

exporting

i_callback_program = me->g_repid

i_callback_pf_status_set = ls_evnt1-form

i_callback_user_command = ls_evnt2-form.

endmethod. "init_block_list

***

  • End of block list

***

method end_block_list.

data: l_object type ref to lcl_table_display,

ls_print type slis_print_alv.

check not g_block_mode is initial.

if in_print is supplied.

ls_print = in_print.

else.

read table gt_table_obj into l_object index 1.

ls_print = l_object->gs_prin.

endif.

call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'

exporting

is_print = ls_print

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

raise display_error.

endif.

call method refresh_objects.

endmethod. "end_block_list

***

  • Refresh table of objects

***

method refresh_objects.

free: gt_table_obj.

endmethod.

***

  • Fill field catalog

***

method fill_fieldcat.

data: lt_abap type rsfb_source.

data: ls_defin type ty_defin.

data: lt_dfies type table of dfies,

ls_dfies type dfies,

ls_dd04v type dd04v,

ls_dd01v type dd01v,

l_flong type dfies-lfieldname,

l_dname type dfies-domname.

data: ls_fcat type slis_fieldcat_alv,

ls_fcat2 type slis_fieldcat_alv.

data: l_index type i,

l_nbfld type i.

free: me->gt_defin.

  • Process data definition

call method get_definition

exporting

repid = repid

struc = struc

changing

abap = lt_abap.

  • Process sub levels if required

call method recursive_definition

exporting

repid = repid

changing

abap = lt_abap.

if me->gt_defin is initial.

raise no_definition.

endif.

loop at me->gt_defin into ls_defin.

clear: ls_fcat.

move-corresponding ls_defin to ls_fcat.

  • Retrieve info about this field

free: ls_dfies, ls_dd04v, ls_dd01v, l_dname.

l_flong = ls_fcat-ref_fieldname.

set locale language 'E'.

translate: ls_fcat-ref_tabname to upper case,

ls_fcat-ref_fieldname to upper case,

l_flong to upper case.

if not ls_fcat-ref_tabname is initial.

  • Try to get info about field in table

call function 'DDIF_FIELDINFO_GET'

exporting

tabname = ls_fcat-ref_tabname

fieldname = ls_fcat-ref_fieldname

lfieldname = l_flong

importing

dfies_wa = ls_dfies

exceptions

not_found = 1

internal_error = 2

others = 3.

if sy-subrc = 0.

move-corresponding ls_dfies to ls_fcat.

ls_fcat-fieldname = ls_defin-fieldname.

move: ls_dfies-keyflag to ls_fcat-key,

ls_dfies-scrtext_m to ls_fcat-seltext_l,

ls_dfies-domname to l_dname.

endif.

else.

  • Try to get info about structure

ls_defin-ref_tabname = ls_defin-ref_fieldname.

call function 'DDIF_FIELDINFO_GET'

exporting

tabname = ls_defin-ref_tabname

tables

dfies_tab = lt_dfies

exceptions

others = 0.

if not lt_dfies is initial.

  • Process fields of this structure

loop at lt_dfies into ls_dfies.

clear: ls_fcat.

move-corresponding ls_dfies to ls_fcat.

if ls_defin-fieldname ne 'INCLUDE'.

concatenate ls_defin-fieldname ls_fcat-fieldname

into ls_fcat-fieldname

separated by '-'.

endif.

move ls_dfies-keyflag to ls_fcat-key.

move ls_dfies-scrtext_m to ls_fcat-seltext_l.

ls_fcat-tabname = me->g_table.

clear: ls_fcat-col_pos,

ls_fcat-offset.

if ls_fcat-ref_tabname is initial.

ls_fcat-ddictxt = 'L'.

endif.

  • Display Yes/No fields as checkboxes

if ls_dfies-domname = 'XFELD'.

ls_fcat-checkbox = 'X'.

endif.

  • Add field to field catalog

append ls_fcat to fcat.

endloop.

continue.

else.

  • Try to get info about data element

call function 'DDIF_DTEL_GET'

exporting

name = ls_fcat-ref_fieldname

langu = sy-langu

importing

dd04v_wa = ls_dd04v

exceptions

illegal_input = 1

others = 2.

if sy-subrc = 0.

move-corresponding ls_dd04v to ls_fcat.

move: ls_dd04v-scrtext_m to ls_fcat-seltext_l,

ls_dd04v-domname to l_dname.

else.

  • Finally try to get info about domain

call function 'DDIF_DOMA_GET'

exporting

name = ls_fcat-ref_fieldname

langu = sy-langu

importing

dd01v_wa = ls_dd01v

exceptions

illegal_input = 1

others = 2.

if sy-subrc = 0.

move-corresponding ls_dd01v to ls_fcat.

move: ls_dd01v-ddtext to ls_fcat-seltext_l,

ls_dd01v-domname to l_dname.

endif.

endif.

endif.

endif.

  • Table name must be internal table containing data

ls_fcat-tabname = g_table.

  • No offset

clear: ls_fcat-offset.

  • Default text is stored in long text

if ls_fcat-ref_tabname is initial.

ls_fcat-ddictxt = 'L'.

endif.

  • Display Yes/No fields as checkboxes

if l_dname = 'XFELD'.

ls_fcat-checkbox = 'X'.

endif.

  • Add field to field catalog

append ls_fcat to fcat.

endloop.

  • Positions

loop at fcat into ls_fcat.

ls_fcat-row_pos = 1.

ls_fcat-col_pos = sy-tabix.

modify fcat from ls_fcat transporting row_pos col_pos.

endloop.

  • Link between fields

describe table fcat lines l_nbfld.

loop at fcat into ls_fcat.

if sy-tabix ne l_nbfld.

l_index = sy-tabix + 1.

read table fcat into ls_fcat2 index l_index.

if sy-subrc = 0.

if ls_fcat-datatype = 'CURR'.

  • Currency unit

if ls_fcat2-datatype = 'CUKY'.

ls_fcat-cfieldname = ls_fcat2-fieldname.

ls_fcat-ctabname = ls_fcat2-tabname.

modify fcat from ls_fcat.

else.

loop at fcat into ls_fcat2

from l_index

where datatype = 'CUKY'.

  • First currency unit after field

ls_fcat-cfieldname = ls_fcat2-fieldname.

ls_fcat-ctabname = ls_fcat2-tabname.

modify fcat from ls_fcat.

exit.

endloop.

if sy-subrc ne 0.

  • No currency unit after field, try before

read table fcat into ls_fcat2

with key datatype = 'CUKY'.

if sy-subrc = 0.

ls_fcat-cfieldname = ls_fcat2-fieldname.

ls_fcat-ctabname = ls_fcat2-tabname.

modify fcat from ls_fcat.

else.

  • Default is EURO

ls_fcat-currency = 'EUR'.

endif.

endif.

endif.

endif.

if ls_fcat-datatype = 'QUAN'.

  • Quantity unit

if ls_fcat2-datatype = 'UNIT'.

ls_fcat-cfieldname = ls_fcat2-fieldname.

ls_fcat-ctabname = ls_fcat2-tabname.

modify fcat from ls_fcat.

endif.

endif.

endif.

endif.

endloop.

endmethod. "fill_fieldcat

***

  • Get definition of type from code source

***

method get_definition.

data: l_strng type rssource,

ls_abap type rssource,

l_fdpos type i,

l_first type i,

l_lastr type i.

data: lt_incl type table of repid,

ls_incl type repid.

  • Get program code

read report repid into abap.

check sy-subrc eq 0.

  • Get first line of definition

concatenate 'BEGIN OF' struc into l_strng

separated by space.

loop at abap into ls_abap.

if ls_abap cs l_strng.

l_fdpos = strlen( l_strng ) + sy-fdpos.

if ls_abap(1) = '*' or ls_abap(sy-fdpos) cs '"'.

continue.

endif.

if ls_abap+l_fdpos(1) ca ',. "'.

l_first = sy-tabix.

exit.

endif.

endif.

endloop.

if l_first is initial.

  • Table is defined in an include

call function 'RS_GET_ALL_INCLUDES'

exporting

program = repid

tables

includetab = lt_incl

exceptions

others = 1.

if sy-subrc = 0.

loop at lt_incl into ls_incl.

  • Try to find definition in this include

read report ls_incl into abap.

loop at abap into ls_abap.

if ls_abap cs l_strng.

l_fdpos = strlen( l_strng ) + sy-fdpos.

if ls_abap(1) = '*' or ls_abap(sy-fdpos) cs '"'.

continue.

endif.

if ls_abap+l_fdpos(1) ca ',. "'.

l_first = sy-tabix.

exit.

endif.

endif.

endloop.

if not l_first is initial.

exit.

endif.

endloop.

endif.

endif.

  • Get last line of definition

concatenate 'END OF' struc into l_strng

separated by space.

loop at abap into ls_abap.

if ls_abap cs l_strng.

l_fdpos = strlen( l_strng ) + sy-fdpos.

if ls_abap(1) = '*' or ls_abap(sy-fdpos) cs '"'.

continue.

endif.

if ls_abap+l_fdpos(1) ca ',. "'.

l_lastr = sy-tabix - l_first.

exit.

endif.

endif.

endloop.

  • Keep only relevant code lines

if l_first le 0

or l_lastr le 0.

refresh abap.

else.

delete abap to l_first.

delete abap from l_lastr.

endif.

endmethod. "get_definition

***

  • Get definition of type recursively

***

method recursive_definition.

data: lt_token type table of stokex,

ls_token type stokex,

lt_state type table of sstmnt,

ls_state type sstmnt.

data: ls_defin type ty_defin,

l_reffld type fieldname.

data: lt_recu type rsfb_source.

  • Retrieve tokens

scan abap-source abap

tokens into lt_token

statements into lt_state.

loop at lt_state into ls_state.

clear: ls_defin.

  • Field name

read table lt_token into ls_token

index ls_state-from.

ls_defin-fieldname = ls_token-str.

  • Reference type

read table lt_token into ls_token

index ls_state-to.

l_reffld = ls_token-str.

  • Check if this type is defined in program

free: lt_recu.

call method get_definition

exporting

repid = repid

struc = l_reffld

changing

abap = lt_recu.

if lt_recu is initial.

if not g_level is initial.

concatenate g_level ls_defin-fieldname

into ls_defin-fieldname separated by '-'.

condense ls_defin-fieldname.

endif.

if l_reffld cs '-'.

split l_reffld at '-'

into ls_defin-ref_tabname

ls_defin-ref_fieldname.

if ls_defin-ref_tabname = 'SY'.

ls_defin-ref_tabname = 'SYST'.

endif.

else.

ls_defin-ref_fieldname = ls_token-str.

endif.

append ls_defin to me->gt_defin.

else.

  • Process sub levels

if me->g_level is initial.

me->g_level = ls_defin-fieldname.

else.

concatenate me->g_level ls_defin-fieldname into me->g_level

separated by '-'.

endif.

call method recursive_definition

exporting

repid = repid

changing

abap = lt_recu.

if me->g_level cs '-'.

shift me->g_level right up to '-'.

shift me->g_level right.

shift me->g_level left deleting leading space.

else.

clear: me->g_level.

endif.

endif.

endloop.

endmethod. "recursive_definition

***

  • Get fieldcat

***

method get_alv_fieldcat.

out_fieldcat = me->gt_fcat.

endmethod. "get_alv_fieldcat

***

  • Set table name

***

method set_table_name.

data: l_fcat type slis_fieldcat_alv.

loop at me->gt_fcat into l_fcat.

l_fcat-tabname = in_tabname.

modify me->gt_fcat from l_fcat.

endloop.

me->g_table = in_tabname.

endmethod. "set_table_name

***

  • Set title

***

method set_alv_title.

me->g_title = in_title.

endmethod. "set_alv_title

***

  • Set fieldcat

***

method set_alv_fieldcat.

me->gt_fcat = in_fieldcat.

endmethod. "set_alv_fieldcat

***

  • Set field invisible

***

method set_alv_fieldnoout.

data: l_field type fieldname,

l_noout type c,

l_tech type c,

ls_fcat type slis_fieldcat_alv.

l_field = in_field.

if in_noout is supplied.

l_noout = in_noout.

else.

l_noout = 'X'.

endif.

if in_tech is supplied.

l_tech = in_tech.

endif.

loop at me->gt_fcat into ls_fcat

where fieldname = l_field.

ls_fcat-no_out = l_noout.

ls_fcat-tech = l_tech.

modify gt_fcat from ls_fcat transporting no_out tech.

endloop.

endmethod. "set_alv_fieldnoout

***

  • Set field editable

***

method set_alv_fieldedit.

data: l_field type fieldname,

l_edit type c,

ls_fcat type slis_fieldcat_alv.

l_field = in_field.

if in_edit is supplied.

l_edit = in_edit.

else.

l_edit = 'X'.

endif.

loop at me->gt_fcat into ls_fcat

where fieldname = l_field.

ls_fcat-edit = l_edit.

modify gt_fcat from ls_fcat transporting edit.

endloop.

endmethod. "set_alv_fieldedit

***

  • Set field text

***

method set_alv_fieldtext.

data: l_field type fieldname,

ls_fcat type slis_fieldcat_alv.

l_field = in_field.

loop at me->gt_fcat into ls_fcat

where fieldname = l_field.

ls_fcat-seltext_m = in_ftext.

ls_fcat-ddictxt = 'M'.

modify gt_fcat from ls_fcat transporting seltext_m ddictxt.

endloop.

endmethod. "set_alv_fieldtext

***

  • Set field sum

***

method set_alv_fieldsum.

data: l_field type fieldname,

l_dosum type c,

ls_fcat type slis_fieldcat_alv.

l_field = in_field.

if in_dosum is supplied.

l_dosum = in_dosum.

else.

l_dosum = 'X'.

endif.

loop at me->gt_fcat into ls_fcat

where fieldname = l_field.

ls_fcat-do_sum = l_dosum.

modify gt_fcat from ls_fcat transporting do_sum.

endloop.

endmethod. "set_alv_fieldsum

***

  • Set line break in field catalog

***

method set_alv_linebreak.

data: l_field type fieldname,

ls_fcat type slis_fieldcat_alv,

l_tabix type i.

l_field = in_field.

read table me->gt_fcat into ls_fcat

with key fieldname = l_field.

if sy-subrc = 0.

l_tabix = sy-tabix.

else.

exit.

endif.

loop at me->gt_fcat into ls_fcat

from l_tabix.

ls_fcat-row_pos = ls_fcat-row_pos + 1.

modify gt_fcat from ls_fcat transporting row_pos.

endloop.

endmethod. "set_alv_linebreak

***

  • Set settings

***

method set_alv_settings.

call method map_structure

exporting

source = in_settings

changing

destin = me->gs_sett.

endmethod. "set_alv_settings

***

  • Set layout

***

method set_alv_layout.

call method map_structure

exporting

source = in_layout

changing

destin = me->gs_layo.

endmethod. "set_alv_layout

***

  • Set printing options

***

method set_alv_print.

call method map_structure

exporting

source = in_print

changing

destin = me->gs_prin.

endmethod. "set_alv_print

***

  • Set sortings

***

method set_alv_sorting.

data: l_desc type alvdynp-sortdown,

l_group type alvdynp-grouplevel,

l_subtot type alvdynp-subtotals.

data: ls_sort type slis_sortinfo_alv,

l_index type i.

if in_desc is supplied.

l_desc = in_desc.

endif.

if in_group is supplied.

l_group = in_group.

else.

l_group = '*'.

endif.

if in_subtot is supplied.

l_subtot = in_subtot.

else.

l_subtot = 'X'.

endif.

describe table me->gt_sort lines l_index.

l_index = l_index + 1.

ls_sort-spos = l_index.

ls_sort-fieldname = in_field.

ls_sort-tabname = me->g_table.

if l_desc is initial.

ls_sort-up = 'X'.

else.

ls_sort-down = 'X'.

endif.

ls_sort-group = l_group.

ls_sort-subtot = l_subtot.

append ls_sort to me->gt_sort.

endmethod. "set_alv_sorting

***

  • Set key fields

***

method set_alv_keys.

data: l_key type c,

ls_fcat type slis_fieldcat_alv.

if in_key is supplied.

l_key = in_key.

else.

l_key = 'X'.

endif.

loop at me->gt_fcat into ls_fcat from 1 to in_level.

ls_fcat-key = l_key.

modify gt_fcat from ls_fcat transporting key.

endloop.

endmethod. "set_alv_keys

***

  • Add event

***

method set_alv_event.

data: ls_evnt type slis_alv_event.

loop at gt_evnt into ls_evnt

where name = in_name.

ls_evnt-form = in_form.

modify gt_evnt from ls_evnt transporting form.

endloop.

if sy-subrc ne 0.

ls_evnt-name = in_name.

ls_evnt-form = in_form.

append ls_evnt to gt_evnt.

endif.

endmethod. "set_alv_event

***

  • Add event

***

method set_all_events.

data: lt_trig type table of rtrig,

ls_evnt type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = g_table_type

importing

et_events = gt_evnt

exceptions

list_type_wrong = 1

others = 2.

if sy-subrc = 0.

  • Get program form routines

load report g_repid part 'TRIG' into lt_trig.

  • List of valid form routines

loop at gt_evnt into ls_evnt.

concatenate 'F_' ls_evnt-name into ls_evnt-form.

if not g_block_mode is initial.

concatenate ls_evnt-form me->g_table into ls_evnt-form

separated by '_'.

endif.

read table lt_trig with key exto = ls_evnt-form

fform = 'X'

transporting no fields.

if sy-subrc = 0.

modify gt_evnt from ls_evnt transporting form.

else.

delete gt_evnt.

endif.

endloop.

endif.

endmethod. "set_all_events

***

  • Map fields from incoming structure into attribute

***

method map_structure.

data: ob_desc type ref to cl_abap_structdescr,

ls_compo type abap_compdescr.

field-symbols: .

endif.

endloop.

endmethod. "map_structure

***

  • Get default variant

***

method get_default_variant.

g_variant_level = g_variant_level + 1.

out_variant-report = me->g_repid.

out_variant-handle = me->g_variant_level.

out_variant-username = sy-uname.

call function 'REUSE_ALV_VARIANT_DEFAULT_GET'

exporting

i_save = 'U'

changing

cs_variant = out_variant

exceptions

others = 0.

endmethod. "get_default_variant

endclass. "lcl_table_display IMPLEMENTATION

-

-


REPORT BALVHT01 NO STANDARD PAGE HEADING.

  • ALV

TYPE-POOLS: SLIS.

  • DB-Table

TABLES: SCARR, SPFLI.

  • Includes

INCLUDE .

*

CONSTANTS:

GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

GS_LAYOUT TYPE SLIS_LAYOUT_ALV,

GS_KEYINFO TYPE SLIS_KEYINFO_ALV,

GT_SORT TYPE SLIS_T_SORTINFO_ALV,

GT_SP_GROUP TYPE SLIS_T_SP_GROUP_ALV,

GT_EVENTS TYPE SLIS_T_EVENT.

  • Data to be displayed

DATA: BEGIN OF GT_SPFLI OCCURS 0.

INCLUDE STRUCTURE SPFLI.

DATA: ADD1,

BOX,

WERT TYPE P,

LIGHTS.

DATA: END OF GT_SPFLI.

DATA: BEGIN OF GT_SCARR OCCURS 0.

INCLUDE STRUCTURE SCARR.

DATA: BOX,

LIGHTS,

EXPAND.

DATA: END OF GT_SCARR.

*

DATA: G_REPID LIKE SY-REPID.

DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

  • Report Selections

SELECT-OPTIONS CARRID FOR SCARR-CARRID.

SELECTION-SCREEN SKIP 1.

  • Parameters

PARAMETERS: P_MAXROW TYPE I DEFAULT 50.

SELECTION-SCREEN SKIP 1.

  • Variante

SELECTION-SCREEN BEGIN OF BLOCK 0 WITH FRAME TITLE TEXT-064.

PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT.

SELECTION-SCREEN END OF BLOCK 0.

  • Layout

SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-060.

PARAMETERS:

P_ZEBRA AS CHECKBOX DEFAULT ' ',

P_NOCOLH AS CHECKBOX DEFAULT ' ',

P_COLOPT AS CHECKBOX DEFAULT ' ',

P_KEYHOT AS CHECKBOX DEFAULT ' ',

P_NOINPT AS CHECKBOX DEFAULT ' '.

SELECTION-SCREEN END OF BLOCK A.

SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME TITLE TEXT-061.

PARAMETERS:

P_LIGHTS AS CHECKBOX DEFAULT ' ',

P_LIGHTC AS CHECKBOX DEFAULT ' '.

SELECTION-SCREEN END OF BLOCK B.

SELECTION-SCREEN BEGIN OF BLOCK C WITH FRAME TITLE TEXT-062.

PARAMETERS:

P_TOTONL AS CHECKBOX DEFAULT ' ',

P_TOTEXT(60),

P_STTEXT(60).

SELECTION-SCREEN END OF BLOCK C.

SELECTION-SCREEN BEGIN OF BLOCK D WITH FRAME TITLE TEXT-063.

PARAMETERS:

P_GPCE AS CHECKBOX DEFAULT ' ',

P_CHKBOX AS CHECKBOX DEFAULT ' ',

P_EXPAND AS CHECKBOX DEFAULT ' ',

P_DETPOP AS CHECKBOX DEFAULT ' '.

SELECTION-SCREEN END OF BLOCK D.

DATA: G_BOXNAM TYPE SLIS_FIELDNAME VALUE 'BOX',

G_EXPANDNAME TYPE SLIS_FIELDNAME VALUE 'EXPAND',

P_F2CODE LIKE SY-UCOMM VALUE '&ETA',

P_LIGNAM TYPE SLIS_FIELDNAME VALUE 'LIGHTS',

G_SAVE(1) TYPE C,

G_TABNAME_HEADER TYPE SLIS_TABNAME,

G_TABNAME_ITEM TYPE SLIS_TABNAME,

  • g_default(1) type c,

G_EXIT(1) TYPE C,

GX_VARIANT LIKE DISVARIANT,

G_VARIANT LIKE DISVARIANT.

*----


*

INITIALIZATION.

G_REPID = SY-REPID.

G_TABNAME_HEADER = 'GT_SCARR'.

G_TABNAME_ITEM = 'GT_SPFLI'.

  • define keyinfo

CLEAR GS_KEYINFO.

GS_KEYINFO-HEADER01 = 'CARRID'.

GS_KEYINFO-ITEM01 = 'CARRID'.

*

PERFORM E01_FIELDCAT_INIT USING GT_FIELDCAT[].

PERFORM E03_EVENTTAB_BUILD USING GT_EVENTS[].

PERFORM E04_COMMENT_BUILD USING GT_LIST_TOP_OF_PAGE[].

PERFORM E06_T_SORT_BUILD USING GT_SORT[].

PERFORM E07_SP_GROUP_BUILD USING GT_SP_GROUP[].

  • Schalter Varianten benutzerspezifisch/allgemein speicherbar setzen

  • Set Options: save variants userspecific or general

G_SAVE = 'A'.

PERFORM VARIANT_INIT.

  • Get default variant

GX_VARIANT = G_VARIANT.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

I_SAVE = G_SAVE

CHANGING

CS_VARIANT = GX_VARIANT

EXCEPTIONS

NOT_FOUND = 2.

IF SY-SUBRC = 0.

P_VARI = GX_VARIANT-VARIANT.

ENDIF.

  • Process on value request

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.

PERFORM F4_FOR_VARIANT.

  • PAI

AT SELECTION-SCREEN.

PERFORM PAI_OF_SELECTION_SCREEN.

START-OF-SELECTION.

PERFORM SELECTION.

END-OF-SELECTION.

PERFORM E05_LAYOUT_BUILD USING GS_LAYOUT. "wg. Parameters

  • Call ABAP/4 List Viewer

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = G_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

IS_LAYOUT = GS_LAYOUT

IT_FIELDCAT = GT_FIELDCAT[]

  • IT_EXCLUDING =

IT_SPECIAL_GROUPS = GT_SP_GROUP[]

IT_SORT = GT_SORT[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • i_default = g_default

I_SAVE = G_SAVE

IS_VARIANT = G_VARIANT

IT_EVENTS = GT_EVENTS[]

  • IT_EVENT_EXIT =

I_TABNAME_HEADER = G_TABNAME_HEADER

I_TABNAME_ITEM = G_TABNAME_ITEM

IS_KEYINFO = GS_KEYINFO

  • IS_PRINT =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

TABLES

T_OUTTAB_HEADER = GT_SCARR

T_OUTTAB_ITEM = GT_SPFLI.

*----


*

  • FORM E01_FIELDCAT_INIT *

*----


*

  • ........ *

*----


*

  • --> E01_LT_FIELDCAT *

*----


*

FORM E01_FIELDCAT_INIT USING E01_LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

*

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'ADD1'.

LS_FIELDCAT-TABNAME = G_TABNAME_ITEM.

LS_FIELDCAT-REPTEXT_DDIC = '?'.

LS_FIELDCAT-OUTPUTLEN = 1.

LS_FIELDCAT-NO_OUT = 'X'.

LS_FIELDCAT-INPUT = 'X'.

LS_FIELDCAT-SP_GROUP = 'A'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

*

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

  • I_PROGRAM_NAME =

I_INTERNAL_TABNAME = G_TABNAME_HEADER

I_STRUCTURE_NAME = 'SCARR'

  • I_CLIENT_NEVER_DISPLAY = 'X'

CHANGING

CT_FIELDCAT = E01_LT_FIELDCAT[].

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

  • I_PROGRAM_NAME =

I_INTERNAL_TABNAME = G_TABNAME_ITEM

I_STRUCTURE_NAME = 'SPFLI'

  • I_CLIENT_NEVER_DISPLAY = 'X'

CHANGING

CT_FIELDCAT = E01_LT_FIELDCAT[].

  • geht am Anfang nicht !!!!

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'WERT'.

LS_FIELDCAT-TABNAME = G_TABNAME_ITEM.

LS_FIELDCAT-REPTEXT_DDIC = 'Wert'(070).

LS_FIELDCAT-OUTPUTLEN = 4.

LS_FIELDCAT-INTTYPE ='P'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

ENDFORM.

*----


*

  • FORM E02_DATA_ADD *

*----


*

  • ........ *

*----


*

  • --> E02_LT_SFLIGHT *

*----


*

FORM E02_DATA_ADD TABLES E02_LT_SPFLI STRUCTURE GT_SPFLI.

LOOP AT E02_LT_SPFLI.

IF SY-TABIX > 10.

E02_LT_SPFLI-ADD1 = 'A'.

E02_LT_SPFLI-BOX = 'X'.

E02_LT_SPFLI-LIGHTS = '3'.

ELSE.

IF SY-TABIX = 1.

E02_LT_SPFLI-LIGHTS = '2'.

ELSE.

E02_LT_SPFLI-LIGHTS = '1'.

ENDIF.

ENDIF.

E02_LT_SPFLI-WERT = SY-TABIX MOD 5.

MODIFY E02_LT_SPFLI.

ENDLOOP.

ENDFORM.

*----


*

  • FORM E03_EVENTTAB_BUILD *

*----


*

  • ........ *

*----


*

  • --> E03_LT_EVENTS *

*----


*

FORM E03_EVENTTAB_BUILD USING E03_LT_EVENTS TYPE SLIS_T_EVENT.

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

*

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 1

IMPORTING

ET_EVENTS = E03_LT_EVENTS.

READ TABLE E03_LT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.

APPEND LS_EVENT TO E03_LT_EVENTS.

ENDIF.

ENDFORM.

*----


*

  • FORM E04_COMMENT_BUILD *

*----


*

  • ........ *

*----


*

  • --> E04_LT_TOP_OF_PAGE *

*----


*

FORM E04_COMMENT_BUILD USING E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: LS_LINE TYPE SLIS_LISTHEADER.

*

  • Listenüberschrift: Typ H

CLEAR LS_LINE.

LS_LINE-TYP = 'H'.

  • LS_LINE-KEY: not used for this type

LS_LINE-INFO = TEXT-001.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

  • Kopfinfo: Typ S

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = TEXT-050.

LS_LINE-INFO = TEXT-010.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

LS_LINE-KEY = TEXT-051.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

  • Aktionsinfo: Typ A

CLEAR LS_LINE.

LS_LINE-TYP = 'A'.

  • LS_LINE-KEY: not used for this type

LS_LINE-INFO = TEXT-002.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDFORM.

*----


*

  • FORM E05_LAYOUT_BUILD *

*----


*

  • ........ *

*----


*

  • <-> E05_LS_LAYOUT *

*----


*

FORM E05_LAYOUT_BUILD USING E05_LS_LAYOUT TYPE SLIS_LAYOUT_ALV.

E05_LS_LAYOUT-F2CODE = P_F2CODE.

E05_LS_LAYOUT-ZEBRA = P_ZEBRA.

E05_LS_LAYOUT-COLWIDTH_OPTIMIZE = P_COLOPT.

IF P_CHKBOX = 'X'.

E05_LS_LAYOUT-BOX_FIELDNAME = G_BOXNAM.

E05_LS_LAYOUT-BOX_TABNAME = G_TABNAME_ITEM.

ELSE.

CLEAR E05_LS_LAYOUT-BOX_FIELDNAME.

CLEAR E05_LS_LAYOUT-BOX_TABNAME.

ENDIF.

IF P_EXPAND = 'X'.

E05_LS_LAYOUT-EXPAND_FIELDNAME = G_EXPANDNAME.

ELSE.

CLEAR E05_LS_LAYOUT-EXPAND_FIELDNAME.

ENDIF.

E05_LS_LAYOUT-NO_INPUT = P_NOINPT.

E05_LS_LAYOUT-NO_COLHEAD = P_NOCOLH.

IF P_LIGHTS = 'X' OR P_LIGHTC = 'X'.

E05_LS_LAYOUT-LIGHTS_FIELDNAME = P_LIGNAM.

E05_LS_LAYOUT-LIGHTS_TABNAME = G_TABNAME_ITEM.

ELSE.

CLEAR E05_LS_LAYOUT-LIGHTS_FIELDNAME.

CLEAR E05_LS_LAYOUT-LIGHTS_TABNAME.

ENDIF.

IF P_GPCE = 'X'.

E05_LS_LAYOUT-GROUP_CHANGE_EDIT = 'X'.

ENDIF.

E05_LS_LAYOUT-LIGHTS_CONDENSE = P_LIGHTC.

E05_LS_LAYOUT-TOTALS_TEXT = P_TOTEXT.

E05_LS_LAYOUT-SUBTOTALS_TEXT = P_STTEXT.

E05_LS_LAYOUT-TOTALS_ONLY = P_TOTONL.

E05_LS_LAYOUT-KEY_HOTSPOT = P_KEYHOT.

E05_LS_LAYOUT-DETAIL_POPUP = P_DETPOP.

ENDFORM.

*----


*

  • FORM E06_T_SORT_BUILD *

*----


*

  • ........ *

*----


*

  • --> E06_LT_SORT *

*----


*

FORM E06_T_SORT_BUILD USING E06_LT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.

*

CLEAR LS_SORT.

LS_SORT-FIELDNAME = 'CARRID'.

LS_SORT-TABNAME = G_TABNAME_HEADER.

LS_SORT-SPOS = 1.

LS_SORT-UP = 'X'.

APPEND LS_SORT TO E06_LT_SORT.

CLEAR LS_SORT.

LS_SORT-FIELDNAME = 'CONNID'.

LS_SORT-TABNAME = G_TABNAME_ITEM.

LS_SORT-SPOS = 2.

LS_SORT-DOWN = 'X'.

APPEND LS_SORT TO E06_LT_SORT.

ENDFORM.

*----


*

  • FORM E07_SP_GROUP_BUILD *

*----


*

  • ........ *

*----


*

  • --> E07_LT_SP_GROUP *

*----


*

FORM E07_SP_GROUP_BUILD USING E07_LT_SP_GROUP TYPE SLIS_T_SP_GROUP_ALV.

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.

ENDFORM.

*----


*

  • FORM SELECTION *

*----


*

  • ........ *

*----


*

FORM SELECTION.

SELECT * FROM SCARR INTO CORRESPONDING FIELDS OF TABLE GT_SCARR

WHERE CARRID IN CARRID.

SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE GT_SPFLI

UP TO P_MAXROW ROWS

WHERE CARRID IN CARRID.

LOOP AT GT_SCARR.

READ TABLE GT_SPFLI WITH KEY CARRID = GT_SCARR-CARRID.

IF SY-SUBRC NE 0.

DELETE GT_SCARR.

ENDIF.

ENDLOOP.

*

PERFORM E02_DATA_ADD TABLES GT_SPFLI.

ENDFORM.

*----


*

  • FORM TOP_OF_PAGE *

*----


*

  • ........ *

*----


*

FORM TOP_OF_PAGE.

*

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.

ENDFORM.

*----


*

  • FORM F4_FOR_VARIANT *

*----


*

  • ........ *

*----


*

FORM F4_FOR_VARIANT.

*

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

IS_VARIANT = G_VARIANT

I_SAVE = G_SAVE

I_TABNAME_HEADER = G_TABNAME_HEADER

I_TABNAME_ITEM = G_TABNAME_ITEM

  • it_default_fieldcat =

IMPORTING

E_EXIT = G_EXIT

ES_VARIANT = GX_VARIANT

EXCEPTIONS

NOT_FOUND = 2.

IF SY-SUBRC = 2.

MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO

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

ELSE.

IF G_EXIT = SPACE.

P_VARI = GX_VARIANT-VARIANT.

ENDIF.

ENDIF.

ENDFORM.

*&----


*

*& Form PAI_OF_SELECTION_SCREEN

*&----


*

  • text

*----


*

FORM PAI_OF_SELECTION_SCREEN.

*

IF NOT P_VARI IS INITIAL.

MOVE G_VARIANT TO GX_VARIANT.

MOVE P_VARI TO GX_VARIANT-VARIANT.

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

EXPORTING

I_SAVE = G_SAVE

CHANGING

CS_VARIANT = GX_VARIANT.

G_VARIANT = GX_VARIANT.

ELSE.

PERFORM VARIANT_INIT.

ENDIF.

ENDFORM. " PAI_OF_SELECTION_SCREEN

*&----


*

*& Form VARIANT_INIT

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM VARIANT_INIT.

*

CLEAR G_VARIANT.

G_VARIANT-REPORT = G_REPID.

ENDFORM. " VARIANT_INIT

regards,

Prabhu

Reward if it is helpful.