-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzst2framework.abap
182 lines (131 loc) · 4.68 KB
/
zst2framework.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
* SAP ABAP Programming and HANA Database Tutorials
* Report Program Framework in ABAP
*&---------------------------------------------------------------------*
*& Report ZST2FRAMEWORK
*&---------------------------------------------------------------------*
*& Generic report program framework
* This program is a generic framework for creating report programs.
* It is designed to be used as a starting point for creating new report programs.
* The program is divided into three classes:
* 1. Exception class - lcx_error
* 2. Startup class - lcl_start
* 3. Main processing class - lcl_main
* The program is designed to be run as a report program.
* The program uses the TRY-CATCH-ENDTRY statement to handle exceptions.
* The program uses the RAISING clause to raise exceptions.
* The program uses the MESSAGE statement to display messages.
*&---------------------------------------------------------------------*
REPORT zst2framework.
***********************************************************************
* Selection screen definition
***********************************************************************
***********************************************************************
* Exception class definition
***********************************************************************
CLASS lcx_error DEFINITION
INHERITING FROM cx_static_check
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES:
if_t100_message.
CONSTANTS:
exception_lcx_error TYPE string
VALUE 'LCX_ERROR'.
* Add additional exception type texts and objects
CONSTANTS:
BEGIN OF lcx_error,
* --> Default exception type
msgid TYPE symsgid VALUE 'ZST2_GENERAL',
msgno TYPE symsgno VALUE '000',
attr1 TYPE scx_attrname VALUE 'EXCEPTION_LCX_ERROR',
attr2 TYPE scx_attrname VALUE '',
attr3 TYPE scx_attrname VALUE '',
attr4 TYPE scx_attrname VALUE '',
END OF lcx_error.
METHODS:
constructor
IMPORTING
textid LIKE if_t100_message=>t100key OPTIONAL
previous LIKE previous OPTIONAL.
ENDCLASS.
***********************************************************************
* Startup class definition
***********************************************************************
CLASS lcl_start DEFINITION.
PUBLIC SECTION.
CONSTANTS:
mc_error TYPE bapi_mtype VALUE 'E',
mc_status TYPE bapi_mtype VALUE 'S'.
CLASS-DATA:
* Generic error object
mo_error TYPE REF TO cx_root.
CLASS-METHODS:
run
RAISING lcx_error.
ENDCLASS.
***********************************************************************
* Main processing class definition
***********************************************************************
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
* Uncomment for one-time INITIALIZATION routines
* CLASS-METHODS:
* class_constructor.
METHODS:
constructor
RAISING lcx_error.
PRIVATE SECTION.
* Define program data attributes as class members
ENDCLASS.
***********************************************************************
* Program starts here
***********************************************************************
START-OF-SELECTION.
TRY.
lcl_start=>run( ).
CATCH cx_root INTO lcl_start=>mo_error.
MESSAGE lcl_start=>mo_error TYPE lcl_start=>mc_status
DISPLAY LIKE lcl_start=>mc_error.
ENDTRY.
***********************************************************************
* Exception class implementation
***********************************************************************
CLASS lcx_error IMPLEMENTATION.
METHOD constructor.
CALL METHOD super->constructor
EXPORTING
previous = previous.
CLEAR me->textid.
IF textid IS INITIAL.
* Raise default exception type
if_t100_message~t100key = lcx_error.
ELSE.
if_t100_message~t100key = textid.
* Transfer additional exception texts here
ENDIF.
ENDMETHOD.
ENDCLASS.
***********************************************************************
* Startup class implementation
***********************************************************************
CLASS lcl_start IMPLEMENTATION.
METHOD run.
* Extend call to include any selection screen parameters
DATA(lo_main) = NEW lcl_main( ).
ENDMETHOD.
ENDCLASS.
***********************************************************************
* Main processing class implementation
***********************************************************************
CLASS lcl_main IMPLEMENTATION.
* Uncomment for one-time INITIALIZATION routines
* METHOD class_constructor.
*
** Add code for implementation
*
* ENDMETHOD.
METHOD constructor.
* Add code for implementation
ENDMETHOD.
ENDCLASS.