08-26-2015 11:35 AM
Hi Experts,
I am successful in creating logs for SLG1. When I go to SLG1 I am able to view my logs there but I am facing one issue here. In log message my requirement is to show string but somehow it is not getting displayed completely. Its been long that I am reading blogs on SCN but couldn't find anything useful.
Code I have written for generating logs is below:
DATA: lf_obj TYPE balobj_d VALUE '/HSGRP1/DI',
lf_subobj TYPE balsubobj VALUE 'ZAPPL_LOGS',
ls_header TYPE balhdri,
lf_log_handle TYPE balloghndl,
lf_log_number TYPE balognr,
lt_msg TYPE balmi_tab,
ls_msg TYPE balmi,
lt_lognum TYPE TABLE OF balnri,
ls_lognum TYPE balnri,
lf_ID TYPE symsgid VALUE '/HSGRP1/DI_MESSAGES'.
* Header information for the log
ls_header-object = lf_obj.
ls_header-subobject = lf_subobj.
ls_header-aldate = sy-datum.
ls_header-altime = sy-uzeit.
ls_header-aluser = sy-uname.
ls_header-aldate_del = sy-datum + 1.
* Get the Log handle using the header
CALL FUNCTION 'APPL_LOG_WRITE_HEADER'
EXPORTING
header = ls_header
IMPORTING
e_log_handle = lf_log_handle
EXCEPTIONS
object_not_found = 1
subobject_not_found = 2
error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* * Get the next avaliable Log number
CALL FUNCTION 'BAL_DB_LOGNUMBER_GET'
EXPORTING
i_client = sy-mandt
i_log_handle = lf_log_handle
IMPORTING
e_lognumber = lf_log_number
EXCEPTIONS
log_not_found = 1
lognumber_already_exists = 2
numbering_error = 3
OTHERS = 4.
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '000'.
ls_msg-msgv1 = outdata_itab-line.
APPEND ls_msg TO lt_msg.
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '001'.
ls_msg-msgv1 = fromClauseString.
APPEND ls_msg TO lt_msg.
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '002'.
ls_msg-msgv1 = whereClauseString.
APPEND ls_msg TO lt_msg.
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '003'.
ls_msg-msgv1 = rowcount.
APPEND ls_msg TO lt_msg.
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '004'.
ls_msg-msgv1 = rowskips.
APPEND ls_msg TO lt_msg.
* lt_msg = '1'.
CALL FUNCTION 'APPL_LOG_WRITE_MESSAGES'
EXPORTING
object = lf_obj
subobject = lf_subobj
log_handle = lf_log_handle
TABLES
messages = lt_msg
EXCEPTIONS
object_not_found = 1
subobject_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
MOVE-CORRESPONDING ls_header TO ls_lognum.
ls_lognum-lognumber = lf_log_number.
APPEND ls_lognum TO lt_lognum.
*
CALL FUNCTION 'APPL_LOG_WRITE_DB'
EXPORTING
object = lf_obj
subobject = lf_subobj
log_handle = lf_log_handle
TABLES
object_with_lognumber = lt_lognum
EXCEPTIONS
object_not_found = 1
subobject_not_found = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR lt_msg.
REFRESH lt_msg.
CLEAR gv_msg.
In slg1 when I try to view logs it comes like this:
Here in "fields selected" it should show complete text which is coming dynamically from front end in string format. As of now it is showing limited text.
Also I tried to add long text but that's not useful for our requirement. Please help me in letting me know what else I can try..
Regards
Akanksha Srivastava
08-26-2015 12:11 PM
08-26-2015 12:43 PM
You are passing only one parameter (so max 50) in each message, try to redefine you message with 4 parameters, split your string into 4 character fields of 50 or less character, spit at space, so the result should better fulfill your requirement ?
Usually I use FM BAL_LOG_MSG_ADD :
l_s_msg-msgid = return-id.
l_s_msg-msgno = return-number.
l_s_msg-msgty = return-type.
l_s_msg-msgv1 = return-message_v1.
l_s_msg-msgv2 = return-message_v2.
l_s_msg-msgv3 = return-message_v3.
l_s_msg-msgv4 = return-message_v4.
if l_s_msg-msgty = 'E'.
l_s_msg-probclass = '1'.
elseif l_s_msg-msgty = 'W'.
l_s_msg-probclass = '2'.
else.
l_s_msg-probclass = '3'.
endif.
* Application Log: Log: Message: Add
call function 'BAL_LOG_MSG_ADD'
exporting
i_log_handle = l_log_handle
i_s_msg = l_s_msg
exceptions
others = 1.
Also remeber that you are limited to 256 character per technical design.
Regards,
Raymond
08-26-2015 1:52 PM
Hi,
as Raymond Giuseppi said. the problem is with following statement:
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '002'.
ls_msg-msgv1 = whereClauseString.
APPEND ls_msg TO lt_msg.
as msgv1 can only carry 50 chars
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '002'.
ls_msg-msgv1 = whereClauseString+0(50).
ls_msg-msgv2 = whereClauseString+50(50).
ls_msg-msgv3 = whereClauseString+100(50).
ls_msg-msgv4 = whereClauseString+150(50).
but be carefull, as you cant work with offset regarding to strings, it will give runtime error when string is too short.
so do a move into a char 200 variable
regards
Stefan Seeburger
08-28-2015 8:11 AM
Hi Raymond / Stefan.
I tried changing code and written like:
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '000'.
ls_msg-msgv1 = outdata_itab-line+0(50).
ls_msg-msgv1 = outdata_itab-line+50(50).
ls_msg-msgv1 = outdata_itab-line+100(50).
ls_msg-msgv1 = outdata_itab-line+150(50).
APPEND ls_msg TO lt_msg.
But now when I try to look into the logs I see nothing, not even half string what used to come:
Please help me in this.
Just to let you guys know that I am executing one query with all dynamic parameters in it and my requirement is to log these parameters. that query is:
SELECT (outdata_itab-line) FROM (fromClauseString) INTO @<datarow> BYPASSING BUFFER UP TO @ROWCOUNT ROWS WHERE (whereClauseString).
Please let me know what wrong I am doing here.
Regards
Akanksha Srivastava
08-28-2015 8:35 AM
Could you check (debug) actual values in string whereClauseString, and post how you actually split it in text of 50 characters (without dump, as if the string was shorter than 200 characters, your program should have dumped...)
Regards,
Raymond
08-28-2015 8:50 AM
Hi Raymond,
I did a dumb mistake of not changing message parameter in code. I was using msgv1 for all 4 messages.Changed it to:
ls_msg-msgty = 'I'.
ls_msg-msgid = lf_ID.
ls_msg-msgno = '000'.
ls_msg-msgv1 = outdata_itab-line+0(50).
ls_msg-msgv2 = outdata_itab-line+50(50).
ls_msg-msgv3 = outdata_itab-line+100(50).
ls_msg-msgv4 = outdata_itab-line+150(50).
APPEND ls_msg TO lt_msg.
now I can see values in slg1 but it is again coming only foe MSGV1 in main screen. But when I click on display icon on left top corner it shows complete value in separate popup. Is it standard behavior or we do something to display this on main screen?
Also is there a limitation of 200 characters display? Because in my case these values may extend 200 characters as well.
I did not get dump though value is less than 200 Char
Thanks!
Akanksha
08-28-2015 9:26 AM
Okay, now your code is fine, but there are some limitation due to standard tools.
You won't be allowed to display more than 132/128 characters in a dynpro field/ALV cell whatever you try (SAPGUI limitation, click on length for reference)
Hint: You could also try to add TWO messages when overflow occurs.
Regards,
Raymond
08-28-2015 9:48 AM
Alright. I was thinking so. Thanks a lot for the inputs.
What if I use any other approach to save these logs for customer?
-Akanksha
08-28-2015 9:55 AM
Well if you save those informations in your own log system (e.g. storing in an INDX type table) and building your own report, you are the only master on board. But don't forget the technical limitation, you will have to split information in multiple cells in the "summarized" screen (some ALV I guess) but could create your own "fancy graphics" detail screen (on double-click, generate a display similar to SQL trace explain of statements, in a classic list style)
Regards,
Raymond
08-28-2015 9:33 AM
08-28-2015 9:46 AM
We are a product company and this code is going to be part of that. So Requirement is to provide a facility to customer so that they can go and check dynamic query getting passed to SAP from front end.
Is there any other approach I can follow to show these logs?
-Akanksha
08-28-2015 9:59 AM
Let your creativity explode, but think of those who will maintaining the product