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!

Tuesday, June 24, 2014

How to change syslog (SM21) SAP R/3

Hi Folks,
i'm fiddling around these day with the SAP R/3 system. I had to change some table data with se16 ( se my previous post for that ).

Doing so i realized that this changes in debugging leave ugly traces in the syslog ( SM21 )
They look like this
And inside ( clicking on the lines shown ) you find the name of the table changed.

Once upon a time there were sys-ops who had put up scripts under cron that searched debugging changes in the syslog, and locked the authors of the debugging change. 

So, just for fun i tried to figure out how to remove these traces of debugging changes.

The log at least in my system ( one application server ) is stored in a file called
SLOG* ( you can check rz11 parameter rslg/local/file )
I ran a quick find /usr/sap -name SLOG*
and i got this answer
/usr/sap/xxx/DVEBMGSnn/log/SLOGnn
/usr/sap/xxx/DVEBMGSnn/log/SLOGnn.SAV
/usr/sap/xjx/SCSnn/log/SLOGmm

where xxx is my sysid. xjx i a java sysid. nn is my sap system number. mm is the java system number ( i suppose)
So i decided that
/usr/sap/xxx/DVEBMGSnn/log/SLOGnn was my file.
I made a quick cg3y and downloaded it.
It is a binary ( ? looks more like a text file with some hex info...) file with plenty of text in it.
Ultraedit shows it like this

 

The user is cleartext: USERXXU.
I do a find and replace with another user.

Then, in the hope that the file is not locked by the application server processes ( shouldn'd be as it is shared and a quick lsof confirms it).  i do cg3z and overwrite the log with the changed log file.

It works. After that, running again sm21 shows that for user USERXXU there is no syslog entry anymore.


But now, at last, i have a question: anybody knows further places where changes done in debug are logged ( apart from the DB change logs )? Pls comment!

Enjoy and have fun!






Thursday, March 20, 2014

SAP ABAP Shared memory objects tutorial

Hi Folks,
this is an advanced topic.
I was looking for a way to share data across application servers for parallel jobs (so many concurrent  read and write accesses)

At first it seemed that shared memory objects could do the trick: but then i read that they "live" only on an application server.
You can set them to get invalidated and synchronized from the database when data changes cross application server, so they basically act as a memory cache for DB data.

Not really what i need.

Anyway you find here a nice tutorial that explains the main concepts of abap shared objects.

ABAP Shared memory programming made easy

HTH
cheers

Tuesday, March 11, 2014

ABAP change PNP LDB select options behaviour SELECT_OPTIONS_RESTRICT



Hi Folks,
this time i needed to change a select option from the PNP logical data base.
Normally you can change things from the HR report class. But some things you cannot.
For example i want to select only one person in an Hr report with the PNP logical database.
I could have used no-interval if it were a select option defined by me in my program.
But it is defined in the PNP LDB so i cannot access its coding.

Luckily enough there is a function module called SELECT_OPTIONS_RESTRICT
that allow to change parameters and select options from both the LDB and the current program.
Here a coding example and below the result.

INITIALIZATION.

* Include des Typepools SSCR
  TYPE-POOLS sscr.
* define objects for restriction
  DATA restrict TYPE sscr_restrict.
* helpobject to fill restriction
  DATA opt_list TYPE sscr_opt_list.
  DATA ass TYPE sscr_ass.

* EQ: only EQ allowed
  CLEAR opt_list.
  MOVE 'ONLY_EQ' TO opt_list-name.
  MOVE 'X' TO: opt_list-options-eq.
  APPEND opt_list TO restrict-opt_list_tab.

* options you want to allow
  CLEAR ass.
  MOVE: 'S' TO ass-kind,
  'PNPPERNR' TO ass-name,
  'I'  TO ass-sg_main,
  'N'  TO ass-sg_addy, "removes the interval selections
  'ONLY_EQ' TO ass-op_main.
  APPEND ass TO restrict-ass_tab.

* Eingrenzung der möglichen Selektionsoptionen
  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
*     PROGRAM                =
      restriction            = restrict
*     DB                     = ' '
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 3
      selopt_without_signs   = 4
      invalid_sign           = 5
      empty_option_list      = 6
      invalid_kind           = 7
      repeated_kind_a        = 8
      OTHERS                 = 9
    . " Punkt
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF. " sy-subrc <> 0 - CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'


And here the result.
 
 
Enjoy!

Tuesday, December 17, 2013

How to force sm30 to edit mode to change data in a production system

Hi folks,
from time to time it happens that you need to change data from sm30 on a closed systems.
A Transport is not an option and change the table to editable in se16 o to "application data" in se11 neither.

You need to be able to edit data in debug mode.
here the procedure:

1) Determine the name of the module pool that contains your view. (Se56 function group field


2) Put a break point into
- View module pool  ( for example SAPL0PX0 ) Include  LSVIMF21 line 297
the context is:
* CHECK X_HEADER-FLAG NE VIM_TRANSPORT_DENIED.          "240997
  IF x_header-flag NE vim_transport_denied AND
     vim_actopts-transp_off NE bc_transport_denied AND
     vim_client_state EQ vim_locked AND

- Program SAPLSTRD inclue LSTRDU50 line 816
the context is:
*** client_edit = 2 (closed-client): (DDIC-EXIT) =================> ****
    IF   system_client_edit  =    2
    AND ( ls_s-category        =    cat_cust
    OR   ls_s-category         =    cat_sys_cust )
    AND  ls_s-cli_dep          <>   space
    AND  ls_s-check_result          <>   'S'
    AND  ls_s-no_wbo_control             =    space.
      IF   ls_g-masterflag  <>   space.

3) Goto sm30 put in your view and press edit. When the debugger pops up in the first point set vim_client_state to '1' and in the second point set ls_g-masterflag to X
4) after each variable change press F8 to continue
5) sm30 shows the view as editable you can do changes
6) Press save and change the variables in the debugger again to the values i've told.

Caveat: doing so you disalign your production systems with development and quality. So if you do it at the same time you set up a transport to align the data. 

I imagine you will use this if transports are down or charm is down or it's late at night and you have no one to authorize the transport but the change is vital for your operations.

That's it.
Hope it help.
And Happy Holidays!


ps. this works an R/3 systems with this patch level.
SAP_BASIS    731    0007    SAPKB73107    
SAP_ABA    731    0007    SAPKA73107    
PI_BASIS    731    0007    SAPK-73107INPIBASIS    
ST-PI    2008_1_700    0008    SAPKITLRD8  
SAP_BW    731    0007    SAPKW73107   
MDG_FND    731    0007    SAPK-73107INMDGFND 
SAP_AP    700    0029    SAPKNA7029    
SAP_BS_FND    731    0007    SAPK-73107INSAPBSFND  
WEBCUIF    731    0007    SAPK-73107INWEBCUIF  
MDG_APPL    606    0007    SAPK-60607INMDGAPPL  
SAP_APPL    606    0007    SAPKH60607  
SAP_HR    604    0063    SAPKE60463    
no guarantee that it works on newer or older systems.