Thursday, September 25, 2014

How to change sm21 syslog from an ABAP program in SAP

Hi Folks,
once the log is read, like i did in my previous post, then it is easy to write it back to where it belongs.

Here is some really trivial coding, that runs on ECC 6 EHP6.

Again the syslog record size must be 320 and not 180.
The date time is a string in the format "AAAAMMDDHHMMSS00" ( ends with zero zero )
So 2014091523593000 means 2014/09/15 23:59:30


You trust me that it works just fine don't you?
Cheers!

REPORT  zzsyslog2.

  DATA l_line TYPE rslgentr_new.

PARAMETERS     pfilein  TYPE rlgrap-filename DEFAULT '/usr/sap/SID/DVEBMGS00/log/SLOG00'.
PARAMETERS     pfileout TYPE rlgrap-filename DEFAULT '/tmp/SLOG00OUT'.
PARAMETERS     pUNAME   TYPE SY-UNAME        DEFAULT SY-UNAME.
select-options PDATTIM  FOR  L_LINE-SLGDATTIM.


START-OF-SELECTION.

  DATA l_str(512) TYPE c.
  DATA lt_log TYPE STANDARD TABLE OF rslgentr_new.
  DATA len TYPE i VALUE 320.
  DATA l_log TYPE string.


  OPEN DATASET pfilein FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  DO.
    READ DATASET pfilein INTO l_str ACTUAL LENGTH len MAXIMUM LENGTH len.
    IF sy-subrc = 0.
      l_line = l_str.
      APPEND l_line TO lt_log.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

  CLOSE DATASET pfilein.

  DELETE lt_log WHERE slguser = puname
                and   SLGDATTIM IN PDATTIM.


  len = 320.

  OPEN DATASET pfileout FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

  LOOP AT lt_log INTO l_line.

    TRANSFER l_line TO pfileout LENGTH len NO END OF LINE .
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
  ENDLOOP.

  CLOSE DATASET pfileout.

How to read syslog SM21 from a program. SAP ABAP

Hi folks,
i know there is a standard function to read the syslog, but i was messing around to read it the quick and dirty way.

So i made a little report who reads it.

Assumptions:
1) you know the file where it resides.
2) the structure is the "new" syslog structure of 320 bytes. The old one was 180. It obviously makes a difference.

Here the little hack for you:

REPORT  zlogsm21.

PARAMETERS pfile TYPE rlgrap-filename DEFAULT '/usr/sap/SID/DVEBMGS00/log/SLOG00'.


START-OF-SELECTION.

  DATA l_str(250) TYPE c.
  DATA l_line TYPE rslgentr_new.
  DATA lt_log TYPE STANDARD TABLE OF RSLGENTR_NEW.
  DATA len TYPE i VALUE 320.

  OPEN DATASET pfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  DO.
    READ DATASET pfile INTO l_str ACTUAL LENGTH len MAXIMUM LENGTH len.
    IF sy-subrc = 0.
      l_line = l_str.
      APPEND l_line TO lt_log.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

  CLOSE DATASET pfile.


CALL FUNCTION 'HR_IT_SHOW_ANY_TABLE_ON_ALV'
  TABLES
    table          = lt_log
 EXCEPTIONS
   FB_ERROR       = 1
   OTHERS         = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.





Hope you enjoyed it.

How to delete a DUMP ST22

Hi Folks,
i am back, somehow.  I have been working on stuff that is absolutely uninteresting for anybody. So i stopped blogging.
today i triggered a dump and i don't want it to show up.

So i looked up in the coding.
The table is "snap".

It is sufficient to do a simple

report zsnap.
start-of-selection.
delete from snap where DATUM= sy-datum AND uname = 'MYUSER'.
 
and voilĂ  you have it.

Check also tables snap_beg it might contin a line you also need to delete.

Have fun withi this little hack!