Abap: sy-msgv1, sy-msgv2: Little template to make one or more system-messages out of a string

This little template helps to make a more easy use of the SAP-Logging-Functions – wich are IMHO very OLD-Style:

You may also want to have a look here – ABAP Logger – Java-Style

 


*Copyright (c) 2011, J.Rumpf, www.web-dreamer.de / BSD Licence
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without modification
*are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, th
* is list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the owner nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
*WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
*DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
*OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data: pattern type string,
nmsg type string,
s_msg type bal_s_msg,
s1 type string,
t_msg type table of string.

s_msg-msgty = i_msgty.
s_msg-msgid = i_msgid.
s_msg-msgno = i_msgno.

pattern = ‚([^\n]{0,50}\n?)‘. “ a regex pattern meaning: every symbol until
“ 50 chars that is not the finish/endline symbol
nmsg = i_msg.
“ split messages with the regex
do.
clear s1.
if nmsg is initial.
exit.
endif.
find regex pattern in nmsg submatches s1.
append s1 to t_msg.
if s1 is initial.
exit.
endif.
replace regex pattern in nmsg with “.
enddo.

data: counter type n value 0,
msg_count type i,
field_ type string.
field-symbols: type symsgv.

loop at t_msg into s1.
counter = counter + 1.
concatenate ‚MSGV‘ counter into field_.
assign component field_ of structure s_msg to .
= s1.
if counter = 2. „sometime you got sy-msgv1-4 — if so – put 4 in here
msg = s_msg.
** append your messages here
s_msg-msgv1 = “ . s_msg-msgv2 = “ . „see above if there are 4
counter = 0.
endif.
endloop.

if counter ne 0 .
** append your sy-message a last time
endif .


Beitrag veröffentlicht

in

von

Schlagwörter: