forked from brandoncaulfield/youtube-abap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z_sflight_alv.abap
105 lines (71 loc) · 2.52 KB
/
z_sflight_alv.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
*&---------------------------------------------------------------------*
*& Report z_sflight_alv
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_sflight_alv.
* Local class to
** Get all data from SFLIGHT
** Display in an ALV
CLASS lcl_sflight_alv DEFINITION.
PUBLIC SECTION.
METHODS:
get_all_sflight_data,
set_alv_functions,
set_alv_columns,
display_sflight_alv.
PROTECTED SECTION.
PRIVATE SECTION.
DATA: lo_alv TYPE REF TO cl_salv_table,
lt_sflight TYPE TABLE OF sflight.
ENDCLASS.
CLASS lcl_sflight_alv IMPLEMENTATION.
METHOD display_sflight_alv.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv " Basis Class Simple ALV Tables
CHANGING
t_table = lt_sflight
).
CATCH cx_salv_msg INTO DATA(lx_msg). " ALV: General Error Class with Message
cl_demo_output=>display( lx_msg ).
ENDTRY.
set_alv_functions( ).
set_alv_columns( ).
* Display ALV
lo_alv->display( ).
ENDMETHOD.
METHOD get_all_sflight_data.
SELECT *
FROM sflight
INTO TABLE lt_sflight.
ENDMETHOD.
METHOD set_alv_functions.
DATA(lo_alv_functions_list) = lo_alv->get_functions( ).
lo_alv_functions_list->set_all( if_salv_c_bool_sap=>true ).
* lo_alv_functions_list->set_sort_asc( if_salv_c_bool_sap=>false ).
* lo_alv_functions_list->set_sort_desc( if_salv_c_bool_sap=>false ).
ENDMETHOD.
METHOD set_alv_columns.
TRY.
DATA(lo_columns) = lo_alv->get_columns( ).
* Hide the client (MANDT) column
DATA(lo_column_mandt) = lo_columns->get_column( 'MANDT' ).
lo_column_mandt->set_visible( if_salv_c_bool_sap=>false ).
* Rename Occupied Column to 'Seats Occupied'
DATA(lo_column_seatsocc) = lo_columns->get_column( 'SEATSOCC' ).
lo_column_seatsocc->set_short_text( 'Seats Occ.' ).
lo_column_seatsocc->set_medium_text( 'Seats Occupied' ).
lo_column_seatsocc->set_long_text( 'Seats Occupied' ).
CATCH cx_salv_not_found INTO DATA(lx_msg). " ALV: General Error Class (Checked During Syntax Check)
cl_demo_output=>display( lx_msg ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(lo_sflight_alv) = NEW lcl_sflight_alv( ).
* Get all data from SFLIGHT
lo_sflight_alv->get_all_sflight_data( ).
* Display the sflight data above in an alv
lo_sflight_alv->display_sflight_alv( ).