Skip to content

Commit 5fb9596

Browse files
authored
Add files via upload
1 parent 948e837 commit 5fb9596

File tree

6 files changed

+87
-65
lines changed

6 files changed

+87
-65
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ Create messages easily from
66
- text-symbol
77
- message system fields
88
- exception
9+
10+
There are two possible ways of creating messages like those; one is to use the factory class, the other is to use the subclasses. The two are not too coupled (the factory uses only the class ZCL_MESSAGE, while the subclasses don't use the factory at all) and are a sort of convenience, for myself, in the form of code duplication
11+
12+
The interface does not consider types so a message from an object like this can only be sent with "MESSAGE ... TYPE ..."

src/zcl_free_message.clas.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class zcl_free_message definition
77

88
public section.
99

10-
"! <p class="shorttext synchronized" lang="EN">Create a message ID '00' TYPE <em>i_type</em> NUMBER '001'</p>
10+
"! <p class="shorttext synchronized" lang="EN">Creates a message ID '00' TYPE <em>i_type</em> NUMBER '001'</p>
1111
"!
1212
"! @parameter i_text | <p class="shorttext synchronized" lang="EN"></p>
1313
"! @parameter i_type | <p class="shorttext synchronized" lang="EN"></p>

src/zcl_message.clas.abap

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class zcl_message definition
1616
information type sy-msgty value 'I',
1717
warning type sy-msgty value 'W',
1818
exit type sy-msgty value 'X',
19+
success type sy-msgty value 'S',
1920
end of valid_type.
2021

2122
data var1 type sy-msgv1 read-only.
@@ -26,43 +27,58 @@ class zcl_message definition
2627

2728
data var4 type sy-msgv4 read-only.
2829

30+
"! <p class="shorttext synchronized" lang="EN">Used for {@link .METH:send} and {@link .METH:send_like}</p>
2931
data type type sy-msgty read-only.
3032

31-
"! <p class="shorttext synchronized" lang="EN">Create a T100 message</p>
32-
"!
33-
"! @parameter i_id | <p class="shorttext synchronized" lang="EN"></p>
34-
"! @parameter i_number | <p class="shorttext synchronized" lang="EN"></p>
35-
"! @parameter i_type | <p class="shorttext synchronized" lang="EN"></p>
36-
"! @parameter i_var1 | <p class="shorttext synchronized" lang="EN"></p>
37-
"! @parameter i_var2 | <p class="shorttext synchronized" lang="EN"></p>
38-
"! @parameter i_var3 | <p class="shorttext synchronized" lang="EN"></p>
39-
"! @parameter i_var4 | <p class="shorttext synchronized" lang="EN"></p>
40-
methods constructor
41-
importing
42-
i_id like if_t100_message=>t100key-msgid
43-
i_number like if_t100_message=>t100key-msgno
44-
i_type like sy-msgty
45-
i_var1 like sy-msgv1 optional
46-
i_var2 like sy-msgv2 optional
47-
i_var3 like sy-msgv3 optional
48-
i_var4 like sy-msgv4 optional.
49-
50-
"! <p class="shorttext synchronized" lang="EN">Copies message information to sy structure</p>
51-
"!
52-
"! @parameter r_self | <p class="shorttext synchronized" lang="EN"></p>
53-
methods load_into_system_fields
54-
returning
55-
value(r_self) type ref to if_t100_message.
56-
57-
"! <p class="shorttext synchronized" lang="EN">Sends message</p>
58-
"!
59-
"! @parameter i_display_like | <p class="shorttext synchronized" lang="EN"></p>
60-
"! @parameter r_self | <p class="shorttext synchronized" lang="EN"></p>
61-
methods send
62-
importing
63-
i_display_like type sy-msgty optional
64-
returning
65-
value(r_self) type ref to if_t100_message.
33+
"! <p class="shorttext synchronized" lang="EN">Creates a T100 message</p>
34+
"!
35+
"! @parameter i_id | <p class="shorttext synchronized" lang="EN"></p>
36+
"! @parameter i_number | <p class="shorttext synchronized" lang="EN"></p>
37+
"! @parameter i_type | <p class="shorttext synchronized" lang="EN">Used for {@link .METH:send} and {@link .METH:send_like}</p>
38+
"! @parameter i_var1 | <p class="shorttext synchronized" lang="EN"></p>
39+
"! @parameter i_var2 | <p class="shorttext synchronized" lang="EN"></p>
40+
"! @parameter i_var3 | <p class="shorttext synchronized" lang="EN"></p>
41+
"! @parameter i_var4 | <p class="shorttext synchronized" lang="EN"></p>
42+
methods constructor
43+
importing
44+
i_id like if_t100_message=>t100key-msgid
45+
i_number like if_t100_message=>t100key-msgno
46+
i_type like sy-msgty
47+
i_var1 like sy-msgv1 optional
48+
i_var2 like sy-msgv2 optional
49+
i_var3 like sy-msgv3 optional
50+
i_var4 like sy-msgv4 optional.
51+
52+
"! <p class="shorttext synchronized" lang="EN">Sends message</p>
53+
"!
54+
"! @parameter r_self | <p class="shorttext synchronized" lang="EN"></p>
55+
methods send
56+
returning
57+
value(r_self) type ref to if_t100_message.
58+
59+
"! <p class="shorttext synchronized" lang="EN">Sends message and displays it like a specific type</p>
60+
"!
61+
"! @parameter i_display_like | <p class="shorttext synchronized" lang="EN"></p>
62+
"! @parameter r_self | <p class="shorttext synchronized" lang="EN"></p>
63+
methods send_like
64+
importing
65+
i_type type sy-msgty
66+
returning
67+
value(r_self) type ref to if_t100_message.
68+
69+
"! <p class="shorttext synchronized" lang="EN">Sends message that displays at the end of the process</p>
70+
"!
71+
"! @parameter r_self | <p class="shorttext synchronized" lang="EN"></p>
72+
methods display
73+
returning
74+
value(r_self) type ref to if_t100_message.
75+
76+
"! <p class="shorttext synchronized" lang="EN">Sends message that displays before continuing the process</p>
77+
"!
78+
"! @parameter r_self | <p class="shorttext synchronized" lang="EN"></p>
79+
methods display_immediately
80+
returning
81+
value(r_self) type ref to if_t100_message.
6682

6783
endclass.
6884
class zcl_message implementation.
@@ -98,24 +114,24 @@ class zcl_message implementation.
98114
result = cl_message_helper=>get_text_for_message( me ).
99115

100116
endmethod.
101-
method load_into_system_fields.
102-
103-
me->get_text( ).
117+
method send.
104118

105-
r_self = me.
119+
message me type me->type.
106120

107121
endmethod.
108-
method send.
122+
method send_like.
109123

110-
if i_display_like is supplied.
124+
message me type me->type display like i_type.
111125

112-
message me type me->type display like i_display_like.
126+
endmethod.
127+
method display.
113128

114-
else.
129+
message me type 'S' display like me->type.
115130

116-
message me type me->type.
131+
endmethod.
132+
method display_immediately.
117133

118-
endif.
134+
message me type 'I' display like me->type.
119135

120136
endmethod.
121137

src/zcl_message_factory.clas.abap

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"! <p class="shorttext synchronized" lang="EN">Message factory</p>
1+
"! <p class="shorttext synchronized" lang="EN">{@link ZCL_MESSAGE} factory</p>
22
class zcl_message_factory definition
33
public
44
create public.
@@ -47,15 +47,16 @@ class zcl_message_factory definition
4747

4848
"! <p class="shorttext synchronized" lang="EN">Returns a new message from an exception message</p>
4949
"!
50-
"! @parameter i_exception | <p class="shorttext synchronized" lang="EN"></p>
51-
"! @parameter i_type | <p class="shorttext synchronized" lang="EN"></p>
50+
"! @parameter i_exception | <p class="shorttext synchronized" lang="EN">Exception with {@link IF_T100_MESSAGE} message</p>
5251
"! @parameter r_error_message | <p class="shorttext synchronized" lang="EN"></p>
52+
"! @raising cx_sy_message_illegal_text | <p class="shorttext synchronized" lang="EN">Provided exc. does not implement {@link IF_T100_MESSAGE}</p>
5353
methods from_exception
5454
importing
5555
i_exception type ref to cx_root
56-
i_type type sy-msgty default zcl_message=>valid_type-error
5756
returning
58-
value(r_error_message) type ref to if_t100_message.
57+
value(r_error_message) type ref to if_t100_message
58+
raising
59+
cx_sy_message_illegal_text.
5960

6061
"! <p class="shorttext synchronized" lang="EN">Returns a new message from an existing message</p>
6162
"!
@@ -105,29 +106,30 @@ class zcl_message_factory implementation.
105106
endmethod.
106107
method from_text_symbol.
107108

108-
r_text_symbol_message = me->from_string( replace( val = replace( val = replace( val = replace( val = i_text_symbol
109-
sub = '&1'
110-
with = i_placeholder1 )
111-
sub = '&2'
112-
with = i_placeholder2 )
113-
sub = '&3'
114-
with = i_placeholder3 )
115-
sub = '&4'
116-
with = i_placeholder4 ) ).
109+
r_text_symbol_message = me->from_string( i_free_text = replace( val = replace( val = replace( val = replace( val = i_text_symbol
110+
sub = '&1'
111+
with = i_placeholder1 )
112+
sub = '&2'
113+
with = i_placeholder2 )
114+
sub = '&3'
115+
with = i_placeholder3 )
116+
sub = '&4'
117+
with = i_placeholder4 )
118+
i_type = i_type ).
117119

118120
endmethod.
119121
method from_exception.
120122

121-
i_exception->if_message~get_text( ). "copy data into sy structure
123+
cl_message_helper=>set_msg_vars_for_if_t100_msg( cast #( i_exception ) ).
122124

123-
sy-msgty = i_type.
125+
sy-msgty = 'E'.
124126

125127
r_error_message = me->from_system_message( ).
126128

127129
endmethod.
128130
method clone.
129131

130-
i_message->if_message~get_text( ). "copy data into sy structure
132+
cl_message_helper=>set_msg_vars_for_if_t100_msg( i_message ).
131133

132134
sy-msgty = cond #( when i_new_type is supplied
133135
then i_new_type

src/zcl_sy_message.clas.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class zcl_sy_message definition
77

88
public section.
99

10-
"! <p class="shorttext synchronized" lang="EN">Create msg. with SY MSGID, MSGTY, MSGNO, and MSGV1 to MSGV4</p>
10+
"! <p class="shorttext synchronized" lang="EN">Creates msg. with SY MSGID, MSGTY, MSGNO, and MSGV1 to MSGV4</p>
1111
methods constructor.
1212

1313
endclass.

src/zcl_text_symbol_message.clas.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class zcl_text_symbol_message definition
99

1010
types t_value type rs38m-itex132.
1111

12-
"! <p class="shorttext synchronized" lang="EN">Create a message ID '00' TYPE <em>i_type</em> NUMBER '001'</p>
12+
"! <p class="shorttext synchronized" lang="EN">Creates a message ID '00' TYPE <em>i_type</em> NUMBER '001'</p>
1313
"!
1414
"! @parameter i_text_symbol | <p class="shorttext synchronized" lang="EN"></p>
1515
"! @parameter i_type | <p class="shorttext synchronized" lang="EN"></p>

0 commit comments

Comments
 (0)