Showing posts with label ABAP Programming. Show all posts
Showing posts with label ABAP Programming. Show all posts

Friday, October 15, 2010

Macro to validate Date in abap sap

*======================================================================*
* Programme : zdate_validate *
* Title : Macro to validate Date *
* Author : Abhishek Kumar *
* Description : This program has two macros and a sample code which is *
* showing how to use that. *
* Macro 1. > Val_date *
* Macro 2. > Valdate *
* It return SY-Subrc value if it 0 then the entered date *
* is valid else either the date is invalid or the *
* specified format is invalid *
*----------------------------------------------------------------------*
* Created and Designed by Abhishek Kumar in Nov 2001. *
*----------------------------------------------------------------------*
*Abhishek is not responsible for any damages caused by the use or *
*misuse of this program and cannot provide any warranty with this *
*program. Use it entirely at your own risk. *
* *
*You are not authorised to make any changes without prior written *
*permission from the author. *
*======================================================================*

PROGRAM ZDATE_VALIDATE .
* Validation of Date
DEFINE VAL_DATE.
CLEAR: %_DATE1,
%_DATE2.
%_DATE1(4) = &1. "Year
%_DATE1+4(2) = &2. "Month
%_DATE1+6(2) = &3. "Date
%_DATE2 = %_DATE1 - 1.
%_DATE2 = %_DATE2 + 1.
IF %_DATE1 <> %_DATE2.
SY-SUBRC = 1.
ELSE.
SY-SUBRC = 0.
ENDIF.
END-OF-DEFINITION.

DEFINE VALDATE.
***************************************************
* Passing Parameters: &1 - Date
* &2 - Date Format
*
* Date Format:
* DDMMYYYY MMDDYYYY YYYYMMDD YYYYDDMM
*
* SY-SUBRC Return Value:
* 1 invalid date
* 0 Valid Date
* 2 Invalid Format
***************************************************
DATA: %_DATE1 LIKE SY-DATUM ,
%_DATE2 LIKE SY-DATUM ,
%_DATE3(8).
case &2.
when 'DDMMYYYY'.
val_date &1+4(4) &1+2(2) &1+0(2).
when 'MMDDYYYY'.
val_date &1+4(4) &1+0(2) &1+2(2).
when 'YYYYMMDD'.
val_date &1+0(4) &1+4(2) &1+6(2).
when 'MMYYYYDD'.
val_date &1+2(4) &1+0(2) &1+6(2).
when others.
sy-subrc = 2.
endcase.
END-OF-DEFINITION.

***********************************************
* SAMPLE USE of above MACRO *
***********************************************

DATA: V_DATE(8).
V_DATE = '30022002'.
*=>
VALDATE V_DATE 'DDMMYYYY'.
*=>
IF SY-SUBRC = 0.
WRITE:/ 'Valid Date'.
ELSEIF SY-SUBRC = 1.
WRITE:/ 'Invalid Date'.
ELSEIF SY-SUBRC = 2.
WRITE:/ 'Invalid Format'.
ENDIF.
*********************************************************************

Dynamically increase/decrease the number of batch/dialog workprocesses from ABAP

REPORT ZURLS.
************************************************************************
* This program dynamically increases/decreases the number of
* dialog/batch workpocesses by 1,2,3 or 4. Before running the program
* two working test (non-productive) operation mode has to be created
* called flex1 and flex2.
* The program does not switch workprocesses, if the workprocess number
* gets too low (min. dia: 2, min. btc.: 1)
* The instance name is hardcoded in this program version!
************************************************************************
TABLES: TPFID.
PARAMETERS:
PLUS_4 RADIOBUTTON GROUP AAA,
PLUS_3 RADIOBUTTON GROUP AAA,
PLUS_2 RADIOBUTTON GROUP AAA,
PLUS_1 RADIOBUTTON GROUP AAA,
MINUS_1 RADIOBUTTON GROUP AAA,
MINUS_2 RADIOBUTTON GROUP AAA,
MINUS_3 RADIOBUTTON GROUP AAA,
MINUS_4 RADIOBUTTON GROUP AAA.
DATA: SWITCH_TO_OPMODE LIKE TPFID-BANAME,
RECENT_OPMODE LIKE TPFID-BANAME.
DATA: MIN_DIA TYPE I VALUE '2',
MIN_BTCH TYPE I VALUE '1',
RECENT_DIA TYPE I,
RECENT_BTCH TYPE I,
TARGET_DIA TYPE I,
TARGET_BTCH TYPE I.
DATA: BEGIN OF REQ_TBL OCCURS 20.
INCLUDE STRUCTURE STHCMLIST.
DATA: END OF REQ_TBL.
DATA: BEGIN OF RSP_TBL OCCURS 50.
INCLUDE STRUCTURE STHCMLIST.
DATA: END OF RSP_TBL.
DATA: SUBRC LIKE SY-SUBRC.

* Find out the active operation
CALL FUNCTION 'RZL_MAKE_STRG_READ_REQ'
EXPORTING
NAME = 'RZL_BANAME'
TYP = 'C'
TABLES
REQ_TBL = REQ_TBL.

CALL FUNCTION 'TH_SEND_ADM_MESS'
EXPORTING
LEVEL = 2
SERVER_NAME = 'instance_name' "e.g. hostname_SID_00
SERVER_TYPES = 0
WAIT_FOR_ANSWER = 1
TRACE = 1
IMPORTING
SUBRC = SUBRC
TABLES
IN_DATA = REQ_TBL
OUT_DATA = RSP_TBL
EXCEPTIONS
SEND_ERROR = 1
OTHERS = 2.

READ TABLE RSP_TBL INDEX 1.
RECENT_OPMODE = RSP_TBL-BUFFER+24.

* Determine the switch_to operation mode
IF RECENT_OPMODE = 'flex1'.
SWITCH_TO_OPMODE = 'flex2'.
ELSE.
SWITCH_TO_OPMODE = 'flex1'.
ENDIF.

* Determine the current workprocess number.
SELECT * FROM TPFID WHERE BANAME = RECENT_OPMODE.
ENDSELECT.
RECENT_DIA = TPFID-WPNODIA.
RECENT_BTCH = TPFID-WPNOBTC.

* Is the switch is possible? (min. dia=2, min. batch=1)
IF PLUS_4 = 'X'. TARGET_DIA = RECENT_DIA + 4. ENDIF.
IF PLUS_3 = 'X'. TARGET_DIA = RECENT_DIA + 3. ENDIF.
IF PLUS_2 = 'X'. TARGET_DIA = RECENT_DIA + 2. ENDIF.
IF PLUS_1 = 'X'. TARGET_DIA = RECENT_DIA + 1. ENDIF.
IF MINUS_1 = 'X'. TARGET_DIA = RECENT_DIA - 1. ENDIF.
IF MINUS_2 = 'X'. TARGET_DIA = RECENT_DIA - 2. ENDIF.
IF MINUS_3 = 'X'. TARGET_DIA = RECENT_DIA - 3. ENDIF.
IF MINUS_4 = 'X'. TARGET_DIA = RECENT_DIA - 4. ENDIF.

TARGET_BTCH = RECENT_DIA + RECENT_BTCH - TARGET_DIA.

IF TARGET_DIA < MIN_DIA.
WRITE: 'ERROR: less then ',MIN_DIA, 'dialog process is not permitted'.
EXIT.
ENDIF.

IF TARGET_BTCH < MIN_BTCH.
WRITE: 'ERROR: less then ',MIN_BTCH, 'batch process is not permitted'.
EXIT.
ENDIF.

* Modify the instance definition
SELECT * FROM TPFID WHERE BANAME = SWITCH_TO_OPMODE.
ENDSELECT.
TPFID-WPNODIA = TARGET_DIA.
TPFID-WPNOBTC = TARGET_BTCH.
MODIFY TPFID.
COMMIT WORK.

* Carry out the actual switch
CALL FUNCTION 'RZL_SWITCH_TO_BA'
EXPORTING
BANAME = SWITCH_TO_OPMODE.

Have active URL-s in the list an ABAP report creates

REPORT ZIMRETSS NO STANDARD PAGE HEADING.
************************************************************************
* This report creates a list that has a couple of active URL links
* embedded. By single-clicking on these links a web browser will
* popup and display the corresponding web page.
************************************************************************
DATA: BEGIN OF URL_TABLE OCCURS 10,
L(25),
END OF URL_TABLE.

URL_TABLE-L = 'http://www.yahoo.com'.APPEND URL_TABLE.
URL_TABLE-L = 'http://www.kabai.com'.APPEND URL_TABLE.
URL_TABLE-L = 'http://www.ebay.com'.APPEND URL_TABLE.

LOOP AT URL_TABLE.
SKIP. FORMAT INTENSIFIED OFF.
WRITE: / 'Single click on '.
FORMAT HOTSPOT ON.FORMAT INTENSIFIED ON.
WRITE: URL_TABLE. HIDE URL_TABLE.
FORMAT HOTSPOT OFF.FORMAT INTENSIFIED OFF.
WRITE: 'to go to', URL_TABLE.
ENDLOOP.
CLEAR URL_TABLE.

* Graham Hickson (graham.hickson@db.com) recommended a nice way
* to find the Netscape executable from the windows registry.
* This is his solution:
* DATA: buf_netscape(200) TYPE c.
* CALL FUNCTION 'REGISTRY_GET' "path of NETSCAPE.EXE
* EXPORTING
* key = 'protocol\StdFileEditing\server'
* section = 'NetscapeMarkup'
* IMPORTING
* value = buf_netscape.
* CALL FUNCTION 'WS_EXECUTE'
* EXPORTING
* program = buf_netscape
* commandline = URL_TABLE.

AT LINE-SELECTION.
IF NOT URL_TABLE IS INITIAL.
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
PROGRAM = 'd:\program files\netscape\navigator\program\netscape.exe'
COMMANDLINE = URL_TABLE
INFORM = ''
EXCEPTIONS
PROG_NOT_FOUND = 1.
ENDIF.

Perl script to check the status of the SAP systems through the WEB

#########################################################################################
# This little PERL script runs on a web server that can reach the SAP
# systems on the lan. When called, it checks the status of an SAP system
# and lets us know, whether it is up or down. Sapinfo.exe has to be
# copied to cgi-bin. This particular script runs on NT with IIS.
# Change the first two lines to the location of your Perl to run it on UNIX.
# It be called using the following html tags:
#
#


#


#

#
# And it will look like this:


#########################################################################################
#
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
#
print "";
#
require "cgi-lib.pl";
&ReadParse;
$i = 0;
$b = $in{'SYS'};
#
if ($b =~ /RTC/) {
open (FILE, "sapinfo -3 -h saphost1 -s 00 -u sap* -p passwd1 |");
}
else {
open (FILE, "sapinfo -3 -h saphost2 -s 99 -u sap* -p passwd2 |");
}
#
while ($a = ) {
if ($i == 0) {
print "When you clicked on the button $b was up and running!

";
}
print "$a

";
$i+=1;
}
print "";
if ($i == 0) {
print "When you clicked on the button $b was down!";
}
print "";
#
#########################################################################################

ABAP Program: show and hide windows by request

REPORT ZIMRETTT.
**********************************************************
* This program is not very useful, but interesting.
* When started, it hides the screen, it is running in.
* After a preset time (60 second) it sends a popup window
* asking the user, if he wants it to be awaken. In case the
* user does not answer in 3 seconds, it removes the popup
* window and goes back to sleep.
* Create the following little program and associate it
* with transaction code ZITS:
*
*REPORT ZIMRETST.
*DATA: ANSWER, A(8).
*TABLES: INDX.
*CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
* EXPORTING
* DEFAULTOPTION = 'N'
* TEXTLINE1 = 'Do you want to awake the'
* TEXTLINE2 = ' sleeping window?'
* TITEL = 'You have 3 seconds to answer'
* CANCEL_DISPLAY = ' '
* IMPORTING
* ANSWER = ANSWER.
*IF ANSWER = 'J'.
* A = 'ZIZIZI'.
* EXPORT A TO SHARED BUFFER INDX(ST) ID 'ZAZAZA'.
*ENDIF.
**********************************************************
*
TABLES: INDX.
DATA: A(8) VALUE 'ZAZAZA'.
DATA: MODE LIKE SY-INDEX.
* Put my mark into the shared buffer
EXPORT A TO SHARED BUFFER INDX(ST) ID 'ZAZAZA'.
* Hide myself
CALL FUNCTION 'SAPGUI_SET_PROPERTY'
DESTINATION 'SAPGUI'
EXPORTING PROPERTY = 'VISIBLE'
VALUE = ' '.
* Wait for being called back
DO.
* Sleep for 60 seconds
CALL FUNCTION 'ENQUE_SLEEP'
EXPORTING
SECONDS = 60.
* Ask the user, if he wants me back
CALL FUNCTION 'TH_CREATE_MODE'
EXPORTING
TRANSAKTION = 'ZITS'
IMPORTING
MODE = MODE.
* Wait 3 seconds for the answer
CALL FUNCTION 'ENQUE_SLEEP'
EXPORTING
SECONDS = 3.
* Check if I am wanted back. If not: go back to sleep
IMPORT A FROM SHARED BUFFER INDX(ST) ID 'ZAZAZA'.
* Delete the popu window
CALL FUNCTION 'TH_DELETE_MODE'
EXPORTING
MODE = MODE.
* Exit if asked so
IF A = 'ZIZIZI'.EXIT.ENDIF.
ENDDO.
* No more sleep, redisplay myself
CALL FUNCTION 'SAPGUI_SET_PROPERTY'
DESTINATION 'SAPGUI'
EXPORTING PROPERTY = 'VISIBLE'
VALUE = 'X'.

ABAP Program for refresh dynamically - once a second - a report list (jobs in the dispatcher queue)

REPORT ZIMREEEE NO STANDARD PAGE HEADING.
************************************************************************
* This program displays a list on a screen and refreshes it once in every
* second. The list shows the status of the dispatcher queues:
* the number of jobs waiting for the different services at the moment.
* The remote callable function module should look like this:
*
*FUNCTION Z_ENQUE_SLEEP.
**"-----------------------------
**"*"Local interface:
**"-----------------------------
*CALL FUNCTION 'ENQUE_SLEEP'
* EXPORTING
* SECONDS = 1.
*ENDFUNCTION.
************************************************************************
DATA: BEGIN OF ITAB OCCURS 5.
INCLUDE STRUCTURE THLINES.
DATA: END OF ITAB.
* Run the async. function module the first time
START-OF-SELECTION.
CALL FUNCTION 'Z_ENQUE_SLEEP'
STARTING NEW TASK 'WAIT'
PERFORMING WHEN_FINISHED ON END OF TASK.
WRITE: ''.
* Run the async. function module and display the freshest data
AT USER-COMMAND.
SY-LSIND = SY-LSIND - 1.
CALL FUNCTION 'TH_REQUEST_QUEUE'
TABLES
REQUEST_QUEUES = ITAB.
WRITE: 9
'TYPE WAITING MAXINQ QSIZE SUMWRITETOQ SUMREADFROMQ'.
SKIP.
LOOP AT ITAB.
WRITE: / ITAB.
ENDLOOP.
CALL FUNCTION 'Z_ENQUE_SLEEP'
STARTING NEW TASK 'INFO'
PERFORMING WHEN_FINISHED ON END OF TASK.
* When the async. function module finished, this form will be called
FORM WHEN_FINISHED USING TASKNAME.
RECEIVE RESULTS FROM FUNCTION 'Z_ENQUE_SLEEP'.
* Trigger an event to run the at user-command
SET USER-COMMAND 'BUMM'.
ENDFORM.

abap program for Customized, dynamic login screen

REPORT ZTSTPOOL.
************************************************************************
* Customized dynamic login screen for 3.1 and 4.0 systems
* (SAPMSST can not be edited any more)
* To make it work:
* - Create a 83X11 subscreen area TESTSCR on the bottom of SAPMSYST/0020
* - In the flow logic at the end of the PBA insert:
* CALL SUBSCREEN TESTSCR INCLUDING 'ZTSTPOOL' '0010'.
* - Create the subscreen type screen 0010 with module pool ZTSTPOOL
* - Create the output type fields line1 ... line9 for 0010/ZTSTPOOL
* - Call DISPLAY_DATA from the PBO of 0010/ZTSTPOOL
* - Create a UNIX file with the system description, important messages
* on a shared directory like /usr/sap/trans with the following format:
* Z|SID|Description
* M|SID|System message line1
* M|SID|System message line2
************************************************************************
*
* Data for the communication between the screen and the modules
DATA: MESSAGE(20), LINE1(81), LINE2(81), LINE3(81), LINE4(81),
LINE5(81), LINE6(81), LINE7(81), LINE8(81), LINE9(81).
* The PBO of the subscreen
MODULE DISPLAY_DATA OUTPUT.
* Local data
DATA: L(200), A1(81), A2(81), A3(81).
DATA: DESRCIPTION(6) VALUE 'Z| |',
SYSTEM_MESSAGE(6) VALUE 'M| |'.
DATA: BEGIN OF A.
INCLUDE STRUCTURE RFCSI.
DATA: END OF A.
DATA: BEGIN OF LINE_TBL OCCURS 100.
INCLUDE STRUCTURE SPFLIST.
DATA: END OF LINE_TBL.
*
* Only for testing: run it only for a specific terminal
* CALL FUNCTION 'RFC_SYSTEM_INFO' DESTINATION 'SAPGUI'
* IMPORTING RFCSI_EXPORT = A.
* IF A CS 'RCHEN'.
* End of Only for testing
*
* Create the SID specific search patterns
DESRCIPTION+2(3) = SY-SYSID.
SYSTEM_MESSAGE+2(3) = SY-SYSID.
* Trick to avoid OPEN DATASET (no user->no authorization->open fails)
CALL FUNCTION 'RZL_READ_FILE_LOCAL'
EXPORTING
DIRECTORY = '/usr/sap/trans'
NAME = 'system_descriptions'
TABLES
LINE_TBL = LINE_TBL
EXCEPTIONS
NOT_FOUND = 1.
* If the file is missing: do not display anything
IF SY-SUBRC = 1.
EXIT.
ENDIF.
* Get the system description and important messages from the file
LOOP AT LINE_TBL.
L = LINE_TBL-LINE.
IF L CS DESRCIPTION.
SPLIT L AT '|' INTO A1 A2 A3.
LINE1 = A3.
ENDIF.
IF L CS SYSTEM_MESSAGE.
SPLIT L AT '|' INTO A1 A2 A3.
IF LINE3 IS INITIAL.
LINE3+6 = A3.
ELSE.
IF LINE4 IS INITIAL.
LINE4+6 = A3.
ELSE.
IF LINE5 IS INITIAL.
LINE5+6 = A3.
ELSE.
LINE6+6 = A3.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
* Some hardcoded information added here
LINE8 = 'For more information visit:'.
LINE9 = 'http://company_web_server/basis_support.htm'.
ENDLOOP.
* ENDIF. "Only for testing
ENDMODULE.

ABAP Program for Limit the parallel instances a particular heavy batch job can have

REPORT ZIMRE000.
************************************************************************
* This program limits the number of parallel instances a particular
* heavy batch job (JOB_NAME) can have.
* The program has to be scheduled as the first step of a job, while the
* heavy batch job should be the second step. The first step (this
* program) checks the number of jobs already running, and if it is
* over the limit (MAX_NUM) it reschedules itself to run in X minutes
* (X selected by a radiobutton), and then aborts. A variant with
* the corresponding MAX_NUM, X and JOB_NAME has to be created before
* scheduling the job.
* To prevent a deadlock (too many batch job start at the same time, and
* they think that there are already many jobs running, and they are
* rescheduling themselves to run again X time later - causing the same
* situation again) X is varied by a random +/- 1 minute.
************************************************************************
TABLES: TBTCO.
SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) A.
PARAMETERS: JOB_NAME(30).
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) B.
PARAMETERS: MAX_NUM TYPE N.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN COMMENT /1(50) C.
PARAMETERS: 5_MIN RADIOBUTTON GROUP PERI,
10_MIN RADIOBUTTON GROUP PERI,
30_MIN RADIOBUTTON GROUP PERI,
1_HOUR RADIOBUTTON GROUP PERI,
2_HOURS RADIOBUTTON GROUP PERI,
4_HOURS RADIOBUTTON GROUP PERI,
8_HOURS RADIOBUTTON GROUP PERI.
SELECTION-SCREEN END OF BLOCK BLK.
*
INITIALIZATION.
A = 'THE NAME OF THE BACH JOB:'.
B = 'MAXIMUM NUMBER OF CONCURRENT BATCH JOBS:'.
C = 'RESTART IN:'.
*
START-OF-SELECTION.
DATA: COUNTER TYPE I.
DATA: UZENET(40).
DATA: DATUM TYPE D, TIME TYPE T.
DATA: NEW_DATUM TYPE D, NEW_TIME TYPE T.
DATA: AMOUNT TYPE T.
DATA: NEW_JOBHEAD LIKE TBTCJOB.
DATA: T TYPE I.
* Some preparations
IF 5_MIN = 'X'.
AMOUNT = 300.
ELSEIF 10_MIN = 'X'.
AMOUNT = 600.
ELSEIF 30_MIN = 'X'.
AMOUNT = 1800.
ELSEIF 1_HOUR = 'X'.
AMOUNT = 3600.
ELSEIF 2_HOURS = 'X'.
AMOUNT = 7200.
ELSEIF 4_HOURS = 'X'.
AMOUNT = 14400.
ELSEIF 8_HOURS = 'X'.
AMOUNT = 28800.
ENDIF.
*
GET RUN TIME FIELD T.
GET TIME.
DATUM = SY-DATUM.
TIME = SY-UZEIT.
TIME = TIME + AMOUNT.
IF TIME < dialog="N" source_jobcount="TBTCO-JOBCOUNT" source_jobname="TBTCO-JOBNAME" target_jobname="TBTCO-JOBNAME" new_jobhead="NEW_JOBHEAD" cant_enq_job="9."> 9. EXIT. ENDIF.
ENDDO.
*
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBNAME = NEW_JOBHEAD-JOBNAME
JOBCOUNT = NEW_JOBHEAD-JOBCOUNT
SDLSTRTDT = DATUM
SDLSTRTTM = TIME.
* Abort the second step
UZENET = 'It is not ERROR! Rescheduling!'.
MESSAGE ID '00' TYPE 'A' NUMBER '208' WITH UZENET.
ENDIF.

Display the long raw fields of such SAP tables as D010S (ABAP sources) - Oraperl

#!/usr/local/bin/perl
# Dispaly the long raw fields of such tables
# as d010s (abap sources) ...
# Run the script like this:
# perl q.pl BLOCK D010S PROG SHOWCOLO
# | | | |
# | | | key field value
# | | key field
# | table
# log raw field name
use Oraperl;
$lda = ora_login("SID","sapr3","sap") || die "Cannot logon\n";
$query = "select $ARGV[0] from $ARGV[1] where $ARGV[2] = '$ARGV[3]'";
$csr = &ora_open($lda,$query);
@value = ora_fetch ($csr);
open (FILE, ">zizi");
$offset = 0;
while (1)
{
$blob = $csr->blob_read (0, $offset, 10000);
last unless $blob;
last unless length ($blob);
print FILE $blob;
$offset += length ($blob);
}
&ora_close($csr);
&ora_logoff($lda);

Hide and password-protect any ABAP's source - still runs, but can not be displayed, edited, transported or traced

PROGRAM ZHIDE NO STANDARD PAGE HEADING.
************************************************************************
* This program hides any ABAP's source code and protects it with a
* password. One can still run the abap (the load version is intact)
* but it can not be displayed, edited, traced, transported or generated.
* If the ABAP is not hidden, the program hides it, if it is hidden, it
* unhides it.
* The password is hard-coded in a source code, so the first candidate
* to be hided sholuld be ZHIDE itself.
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK BLOCK.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(8) PWD.
SELECTION-SCREEN POSITION 35.
PARAMETERS: PASSWORD(8) MODIF ID AAA.
SELECTION-SCREEN END OF LINE.
PARAMETERS: PROGRAM(8).
SELECTION-SCREEN END OF BLOCK BLOCK.
*
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'AAA'.
SCREEN-INVISIBLE = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
*
INITIALIZATION.
PWD = 'PASSWORD'.
*
START-OF-SELECTION.
TABLES: TRDIR.
* User name and passsword check
IF SY-UNAME <> 'IMRE' OR PASSWORD <> 'TITOK'.
WRITE: / 'Wrong password'.
EXIT.
ENDIF.
* SAP owned?
IF NOT PROGRAM CP 'Z*' AND NOT PROGRAM CP 'Y*'.
WRITE: / 'Do not hide original SAP programs!'.
EXIT.
ENDIF.
* Exists?
SELECT SINGLE * FROM TRDIR WHERE NAME = PROGRAM.
IF SY-SUBRC <> 0.
WRITE: / 'Program does not exists!'.
EXIT.
ENDIF.
* Does it have a current generated version?
DATA: F1 TYPE D, F3 TYPE D.
DATA: F2 TYPE T, F4 TYPE T.
EXEC SQL.
SELECT UDAT, UTIME, SDAT, STIME INTO :F1, :F2, :F3, :F4 FROM D010LINF
WHERE PROG = :PROGRAM
ENDEXEC.
IF F1 < F3 OR ( F1 = F3 AND F2 < F4 ).
WRITE: / 'The program has no recent generated version!'.
EXIT.
ENDIF.
* Compose a new program name
DATA: NEW_NAME(8), I TYPE I, J TYPE I.
NEW_NAME = PROGRAM.
DO 8 TIMES.
I = SY-INDEX - 1.
NEW_NAME+I(1) = '_'.
* Search for acceptable program name variations
J = 0.
SELECT * FROM TRDIR WHERE NAME LIKE NEW_NAME.
J = J + 1.
ENDSELECT.
IF J = 1.
EXIT.
ENDIF.
NEW_NAME = PROGRAM.
ENDDO.
* Can not generate appropriate program name
IF J > 1.
WRITE: / 'Can not generate appropriate program name'.
EXIT.
ENDIF.
* Check if it is already in d010s (already hidden)
DATA: F5(8).
EXEC SQL.
SELECT PROG INTO :F5 FROM D010S WHERE PROG = :NEW_NAME
ENDEXEC.
IF F5 IS INITIAL.
* There is no such hidden program, hide it
EXEC SQL.
UPDATE D010S SET PROG = :NEW_NAME WHERE PROG = :PROGRAM
ENDEXEC.
ELSE.
* There is already a hidden program there, unhide it
EXEC SQL.
UPDATE D010S SET PROG = :PROGRAM WHERE PROG = :NEW_NAME
ENDEXEC.
ENDIF.

ABAP Program for Yet another customized logon screen - this one with configurable active elements (URL ...)

************************************************************************
* Yet another logon screen modification solution.
* This one is similar to program #90 (same setup steps) but:
* - it runs during logon but also can be run any time from SAP from the
* help menu
* - it displays a list type window with active elements. By clicking
* on those elements the user can start a report, an SAP transaction
* or a web browser displaying a particular web page.
* - the format (color, element type, intensified, program to run ...)
* for the dynamic logon screen for the different SAP systems is
* configured in a single config file residing on a filesystem shared
* between all SAP the systems.
*This is an example config file:
*
* SID|XX|YY|T|#|#|#|#|#|Text|URL
* | | | | | | | | | | |
* | | | | | | | | | | Url, Transaction or Program/type U,T or P
* | | | | | | | | | Text to be displayed
* | | | | | | | | 1/0 Input on/off
* | | | | | | | 1/0 Hotspot on/off
* | | | | | | 1/0 Inverse on/off
* | | | | | 1/0 Intensified on/off
* | | | | 0-7 Color
* | | | R:Regular, U:URL, T:Start transact., P:Start program
* | | Y coordinate (<20)
* | X coordinate (<66)
* System
*
*SID|1|1|R|6|0|0|0|0| SID: SAP 3.1 Development|
*SID|2|3|R|2|1|0|0|0|This is the first line of the important message|
*SID|2|4|R|2|1|0|0|0|This is the second line of the important message|
*SID|2|5|R|2|1|0|0|0|This is the third line of the important message|
*SID|1|7|U|1|0|1|1|0|Click here for more info from the WEB|http://XXX
*SID|1|9|T|1|0|1|1|0|Click here to start transaction SICK|SICK
*SID|1|11|P|1|0|1|1|0|Click here to start program SHOWCOLO|SHOWCOLO
*SID|1|13|S|1|0|1|1|0|Send mail to the BASIS team|imre@kabai.com
*SID|1|18|R|2|0|1|0|0|To display this window from SAP go to Help/webhelp
*
***********************************************************************
FUNCTION Z_POPUP_SYSTEM_INFO_LIST.
*"----------------------------------------------------------------------
*"*"Local interface:
*"----------------------------------------------------------------------
CALL SCREEN 333 STARTING AT 1 3
ENDING AT 65 16.
ENDFUNCTION.
*---------------------------------------------------------------------*
* MODULE STATUS_0333 OUTPUT *
*---------------------------------------------------------------------*
MODULE STATUS_0333 OUTPUT.
SET TITLEBAR '000'.
INCLUDE .
DATA: MESSAGE(20), L1(81), L2(81), L3(81), L4(81),
L5(81), L6(81), L7(81), L8(81), L9(81).
DATA: C.
DATA: L(200), A1(81), A2(81), A3(81), A4(81), A5(81), A6(81).
DATA: DESRCIPTION(6) VALUE 'Z| |',
SYSTEM_MESSAGE(6) VALUE 'M| |'.
DATA: BEGIN OF A.
INCLUDE STRUCTURE RFCSI.
DATA: END OF A.
DATA: BEGIN OF LINE_TBL OCCURS 100.
INCLUDE STRUCTURE SPFLIST.
DATA: END OF LINE_TBL.
* Run only on my pc (good for the testing)
* CALL FUNCTION 'RFC_SYSTEM_INFO' DESTINATION 'SAPGUI'
* IMPORTING RFCSI_EXPORT = A.
* IF A NS 'IMRE'.
* EXIT.
* ENDIF.
* Create the SID specific search patterns
DESRCIPTION+2(3) = SY-SYSID.
SYSTEM_MESSAGE+2(3) = SY-SYSID.
* Trick to avoid OPEN DATASET (no user->no authorization->open fails)
CALL FUNCTION 'RZL_READ_FILE_LOCAL'
EXPORTING
DIRECTORY = '/globaldirectory'
NAME = 'login_screen_list.ctl'
TABLES
LINE_TBL = LINE_TBL
EXCEPTIONS
NOT_FOUND = 1.
* If the file is missing: do not display anything
IF SY-SUBRC = 1.
SET SCREEN 0. LEAVE SCREEN.
ENDIF.
* Get the text from the internal table
SUPPRESS DIALOG.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
NEW-PAGE NO-TITLE NO-HEADING.
DATA: SYS(3),X(2),Y(2),T, COL,INT,INV,HOT,INP,TXT(62),URL(60).
LOOP AT LINE_TBL.
IF LINE_TBL CS SY-SYSID.
SPLIT LINE_TBL AT '|' INTO SYS X Y T COL INT INV HOT INP TXT URL.
*
CASE COL.
WHEN '1'. FORMAT COLOR 1.
WHEN '2'. FORMAT COLOR 2.
WHEN '3'. FORMAT COLOR 3.
WHEN '4'. FORMAT COLOR 4.
WHEN '5'. FORMAT COLOR 5.
WHEN '6'. FORMAT COLOR 6.
WHEN '7'. FORMAT COLOR 7.
ENDCASE.
*
FORMAT INTENSIFIED OFF.
FORMAT INVERSE OFF.
FORMAT HOTSPOT OFF.
FORMAT INPUT OFF.
IF HOT = '1'. FORMAT HOTSPOT ON. ENDIF.
IF INT = '1'. FORMAT INTENSIFIED ON. ENDIF.
IF INV = '1'. FORMAT INVERSE ON. ENDIF.
IF INP = '1'. FORMAT INPUT ON. ENDIF.
*
SKIP TO LINE Y.
IF T = 'U'.
WRITE AT X(2) ICON_SYSTEM_HELP AS ICON.
X = X + 3.
WRITE AT X TXT. HIDE: T, URL.
ELSEIF T = 'T'.
WRITE AT X(2) ICON_EXECUTE_OBJECT AS ICON.
X = X + 3.
WRITE AT X TXT. HIDE: T, URL.
ELSEIF T = 'S'.
WRITE AT X(2) ICON_MAIL AS ICON.
X = X + 3.
WRITE AT X TXT. HIDE: T, URL.
ELSEIF T = 'P'.
WRITE AT X(2) ICON_EXECUTE_OBJECT AS ICON.
X = X + 3.
WRITE AT X TXT. HIDE: T, URL.
ELSE.
WRITE AT X TXT.
ENDIF.
*
ENDIF.
ENDLOOP.
CLEAR: SYS, X, Y, T, COL, INT, INV, HOT, INP, TXT, URL.
ENDMODULE.
*
AT LINE-SELECTION.
READ LINE SY-INDEX.
DATA: LOCATION(200).
IF T = 'U'.
CALL FUNCTION 'REGISTRY_GET'
EXPORTING
KEY = 'protocol\StdFileEditing\server'
SECTION = 'NetscapeMarkup'
IMPORTING
VALUE = LOCATION.
IF LOCATION IS INITIAL.
MESSAGE ID 00 TYPE 'I' NUMBER 208
WITH 'Can not locate Netscape in the registry'.
EXIT.
ENDIF.
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
PROGRAM = LOCATION
COMMANDLINE = URL
INFORM = ''
EXCEPTIONS
FRONTEND_ERROR = 1
NO_BATCH = 2
PROG_NOT_FOUND = 3
ILLEGAL_OPTION = 4.
IF SY-SUBRC <> 0.
MESSAGE ID 00 TYPE 'I' NUMBER 208
WITH 'Can not start Netscape on your pc'.
EXIT.
ENDIF.
ELSEIF T = 'T' AND NOT SY-UNAME IS INITIAL.
CALL TRANSACTION URL.
ELSEIF T = 'P' AND NOT SY-UNAME IS INITIAL.
SUBMIT (URL) AND RETURN.
ELSEIF T = 'S' AND NOT SY-UNAME IS INITIAL.
*
ENDIF.
*---------------------------------------------------------------------*
* MODULE USER_COMMAND_0333 INPUT *
*---------------------------------------------------------------------*
MODULE USER_COMMAND_0333 INPUT.
ENDMODULE.
*---------------------------------------------------------------------*
* MODULE STATUS_0222 OUTPUT *
*---------------------------------------------------------------------*
MODULE STATUS_0222 OUTPUT.
CALL FUNCTION 'Z_POPUP_SYSTEM_INFO_LIST'.
ENDMODULE.

The abap part, that retrieves the data from the SAP systems

REPORT ZPOPLOG NO STANDARD PAGE HEADING.
******************************************************************
* This abap is run by the system monitoring perl script
* to retrtieve the following data from the different SAP
* systems:
* system status (up/down), appservers, user number per appserver,
* session number per appserver, abap dump number today,
* today's error message number from the system log,
* number of active lock entries, number of pending updates
******************************************************************
TABLES: SNAP, VBHDR.
DATA: I TYPE I, C(5), J TYPE I, K TYPE I, L TYPE I, SUBRC LIKE SY-SUBRC.
DATA: MINTA(72) VALUE
'a b c d e f g h i j k l m n o p q r s t u w z x y * | '.
DATA: R(5), HOSTID(8), flag type i.
DATA: BEGIN OF TABTAB OCCURS 10,
line(128),
END OF TABTAB.
DATA: BEGIN OF SUMMARY OCCURS 50.
INCLUDE STRUCTURE SAPWLSUMRY.
DATA: END OF SUMMARY.
DATA: BEGIN OF ENQ OCCURS 50.
INCLUDE STRUCTURE SEQG3.
DATA: END OF ENQ.
DATA: BEGIN OF TAB OCCURS 10.
INCLUDE STRUCTURE ABAPLIST.
DATA: END OF TAB.
DATA: BEGIN OF LISTASCI OCCURS 10,
L(999),
END OF LISTASCI.
DATA: BEGIN OF LIST OCCURS 10.
INCLUDE STRUCTURE MSXXLIST.
DATA: END OF LIST.
DATA: BEGIN OF USR_TBL OCCURS 10.
INCLUDE STRUCTURE BTCSYSLOG.
DATA: END OF USR_TBL.
* System name
tabtab-line = 'Q'.
TABTAB-LINE+2 = SY-SYSID.
* The number of abap dumps
SELECT COUNT(*) INTO I FROM SNAP WHERE SEQNO = '001'
AND DATUM = SY-DATUM.
TABTAB-LINE+7(6) = I.
* The number of active lock entries
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
GCLIENT = '*'
GUNAME = '*'
GNAME = '*'
GARG = '*'
IMPORTING
SUBRC = SUBRC
TABLES
ENQ = ENQ.
DESCRIBE TABLE ENQ LINES J.
TABTAB-LINE+14(6) = J.
* Update records
SELECT COUNT(*) INTO K FROM VBHDR.
TABTAB-LINE+20(6) = K.
* Today's error messages from the system log
SUBMIT RSLG0001 WITH TR_DAY EQ '0'
LINE-SIZE 255 EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = TAB.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
LISTASCI = LISTASCI
LISTOBJECT = TAB.
LOOP AT LISTASCI.
IF LISTASCI CS '|K|' OR LISTASCI CS '|T|'.
L = L + 1.
ENDIF.
ENDLOOP.
TABTAB-LINE+26(6) = L.
CONDENSE TABTAB.
*APPEND TABTAB.
* Number of active users and modes per app. server
CALL FUNCTION 'TH_SERVER_LIST'
TABLES
LIST = LIST.
flag = 0.
LOOP AT LIST.
flag = flag + 1.
* Find out the average response time
HOSTID = LIST-HOST.
CALL FUNCTION 'SAPWL_GET_SUMMARY_STATISTIC'
EXPORTING
PERIODTYPE = 'D'
HOSTID = HOSTID
STARTDATE = SY-DATUM
TABLES
SUMMARY = SUMMARY.
LOOP AT SUMMARY.
IF SUMMARY-TASKTYPE = 'DIALOG'.
R = SUMMARY-RESPTI / SUMMARY-COUNT.
EXIT.
ENDIF.
ENDLOOP.
* Count the users and sessions
CLEAR USR_TBL.
REFRESH USR_TBL.
CALL FUNCTION 'SXMI_XMB_USER_LIST_READ_INT' DESTINATION LIST-NAME
TABLES
USR_TBL = USR_TBL.
LOOP AT USR_TBL.
IF USR_TBL CS 'users logged on with'.
TRANSLATE USR_TBL USING MINTA.
CONDENSE USR_TBL.
if flag > 1.
tabtab = 'Q @ @ @ @ @ @'.
endif.
TABTAB+27 = LIST-NAME.
TABTAB+48 = USR_TBL.
TABTAB+68 = R.
TABTAB+80 = '&'.
CONDENSE TABTAB.
APPEND TABTAB.
ENDIF.
ENDLOOP.
ENDLOOP.
*
LOOP AT TABTAB.
WRITE: / TABTAB.
ENDLOOP.

ABAP Program for This perl displays a self-refreshing web page displaying the vital parameters of multiply SAP systems

#!/opt/perl5/bin/perl
#
# This perl script displays on a single, self-refreshing web page
# the most important parameters of multiply sap systems. By taking a
# look at this page, most of the problems can be noticed
# immediately. The displayed data:
# system status(up/down)
# user number per app. server
# session number per app. server
# average response time per app. server
# number of active locks
# number of update entries
# number of abap dumps (today)
# number of error messages in the system log (today)
#
# The web page gets refreshed once every three minutes.
# The perl script uses SAP's rfc2abap to submit
# the data collector abap (the source code: pr# 93b is in a
# unix text file) in the different systems. A cpic type user
# has to exist in those systems to run the abap.
# The script was used to monitor 14 SAP systems parallel.
#
print "Content-type:text/html\n\n";
use CGI;
print "";
print "";
#
# Print out the time of the last screen refresh
#
$datum = `date`;
@f = split /\s/, $datum;
print "@f[3] @f[1] @f[2] @f[5]


";
#
# Print a main header
#
print "print "cellspacing=\"0\"";
print "";
print "";
print "
";
print "SYSTEM DEPENDENT DATA
";
print "INSTANCE DEPENDENT DATA
";
#
# Print the column headings
#
@h=("SYSTEM","STATUS","SYSLOG ERRORS TODAY","ABAPDUMPS TODAY","LOCKS","UPDATE EN
TRIES","INSTANCE","USERS","SESSIONS","AVERAGE D. RESPONSE TIME");
print "print "";
for ($x = 0; $x < @h; $x++) {
print "";
}
print "";
#
# List of the systems to be monitored(SID, client, host, system number)
# This portion of the script has to be customized
#
@s = (
["DEV", "090", "host1", "00"],
["PRD", "100", "host2", "01"],
["QAS", "110", "host3", "02"],
["EDU", "120", "host4", "03"]
);
#
# Loop on the SAP systems
#
for $k ( @s ) {
#
# Check, that the sysytem is available
#
$stat = `./sapinfo -3 -h@$k[2] -s@$k[3] -g@$k[2] -xsapgw@$k[3] 2>/dev/null`;
if ($stat =~ /SAP/) {
#
# Get the data from the SAP system
# Customize the username and password
#
$data = `./rfc2abap -d@$k[0] -uusername -ppassword -c@$k[1] -h@$k[2] -s@$k[3]
-g@$k[2] -xsapgw@$k[3] -f zpoplog|grep -v Connected`;
}
else {
#
# When the system is down:
#
$data = "Q AAA - - - - - - - - &";
}
$sid = @$k[0];
@d = split /\s/, $data;
for ($x = 0; $x < @d; $x++) {
if (@d[$x] eq "Q") {
# Begin of table row
print "";
}
elsif (@d[$x] eq "@") {
# Empty cell
print "";
}
# End of table row
elsif (@d[$x] eq "&") {
print "";
}
else {
if ($x eq 2) {
# Set the status cell's color and text
if (@d[1] eq $sid){
$stat = "UP";
$color = "#00FF00";
}
else {
$stat = "DOWN";
$color = "#FF0000";
}
# Print the status cell
print "";
}
if ($x eq 1) {
$string = $sid;
}
else {
$string = @d[$x];
}
# Print a regular cell
print "";
}
}
}
print "
";
print "@h[$x]

";
print "$stat
";
print "$string
";

print "";

abap program for The remote script for 96a

#!/bin/ksh
###############################################################################
# File Name: recycle_archivelog.sh
#
# Usage: Run it once an hour on the remote machine from crontab
#
# Description: Compresses the uncompressed archive log files (except for the
# newest one - the file transfer may not have been completed)
# Removes archive logs older than the retention period
# Alerts sysadmin, when the free space in the archive filesystem
# drops under the threshold
###############################################################################
#
retention_per=14
arch_dir=/oracle/SID/saparch
fs=/oracle/SID
threshold=90
#
# Compress all the archive logs but the newest (it may not be complete)
#
newnum=`ls -lt $arch_dir/*.dbf|wc -l`
if [ $newnum -gt 1 ]; then
newest=`ls -lt $arch_dir/*.dbf|head -2|tail -1|awk '{print $9}'`
find $arch_dir -name "*.dbf" ! -newer $newest -exec compress {} \;
fi
#
# Remove the archive logs older then retention_per
#
find $arch_dir -name "*.dbf.Z" -mtime +$retention_per -exec rm -f {} \;
#
# Alert sysadmin, if the free space drops under the threshold
#
used_perc=`bdf|grep $fs|grep -v $fs/|awk '{print $5}'|awk -F\% '{print $1}'`
if [ $used_perc -gt $threshold ]; then
# Run your own paging scripts here
fi

abap program for Automatically save and circulate the offline redos to a remote server - local script

#!/bin/ksh
##############################################################################
# File Name: double_archieve.sh
#
# Usage: Run it from crontab 6 times an hour:
#
# su - SIDadm -c "/sapglobal/SHELL/ARCHIVE/doublearchive.sh" >/dev/null 2>&1
#
# Description: Usually the weekly backup tapes are transferred to a remote
# site, but the current offline redo logs are not. In case of a
# local disaster, rolling forward becomes impossibble, because
# both the database and the locally stored tapes get destroyed.
# This script provides a protection against this situation
# by automatically sending to and circulating the archive logs
# on a remote machine.
# This script runs on the local machine. It archives the offline
# redos locally and sends them to the remote machine as well.
# After sucessfuly archiving and copying them, it deletes
# the redo logs. Once a day it removes the old local brarchive
# logs too.
#
# Dependencies: Requires brarchive V4.5
# SIDadm has to exist on the remote host
# The local SIDadm has to be a trusted user on the remote machine
# A second brarchive par. file is needed for the remote copy on
# the local machine containing:
#
# archive_copy_dir = /oracle/SID/saparch
# remote_host = remote_host_name
##############################################################################
sid=SID
ORACLE_SID=$sid;export ORACLE_SID
ORACLE_HOME=/oracle/$sid;export ORACLE_HOME
#
brarchive=/sapmnt/$sid/exe/brarchive
prof=/oracle/$sid/dbs/remotecopy.sap
pwd=system/dbajan
tlog=/sapglobal/LOG/ARCHIVE/temp_log
plog=/sapglobal/LOG/ARCHIVE/permanent_log
lockfile=/sapglobal/LOG/ARCHIVE/doublearchive_lockfile
pat=successfully
#
hour_minute=`date "+%H%M"`
cleanup_time=1200
brarchive_log_dir=$ORACLE_HOME/saparch
remove_dayold=2
#
# Handle the signals
#
trap "clean_and_exit" 1 2 3 15 25
clean_and_exit ()
{
rm -f $lockfile
echo "Interrupt signal received - exiting" >> $plog
exit 0
}
#
# Check if another instance of double_archive is running
#
if [ -f $lockfile ]; then
echo "Already running - exiting" >> $plog
exit 0
fi
touch $lockfile
#
date >> $plog
#
# Archive the archive logs
#
a=`$brarchive -d disk -s -c -u $pwd|tee $tlog|grep $pat`
if [ "$a" = "" ] ; then
echo Failed to stop archive the remaining files, exiting >> $plog
rm -f $lockfile
exit 0
else
cat $tlog|grep "#SAVED"|awk '{printf(" Local archiving:%s\n",$2)}' >> $plog
fi
#
# Copy the archive logs to the remote machine
#
a=`$brarchive -d stage -s -c -u $pwd -p $prof|tee $tlog|grep $pat`
if [ "$a" = "" ] ; then
echo Failed to copy the arhive files to the remote machine, exiting >> $plog
rm -f $lockfile
exit 0
else
cat $tlog|grep "#SAVED"|awk '{printf(" Remote copy: %s\n",$2)}' >> $plog
fi
#
# Remove the archive logs that has been sucessfully archived and copied
#
a=`$brarchive -d disk -ds -c -u $pwd|tee $tlog|grep $pat`
if [ "$a" = "" ] ; then
echo Failed to delete the double saved archive logs, exiting >> $plog
rm -f $lockfile
exit 0
else
cat $tlog|grep BR015I|awk '{printf(" Deleting: %s\n",$6)}' >> $plog
fi
#
# Once a day remove the old brbackup log files
#
if [ $hour_minute = $cleanup_time ]; then
echo Removing the old brarchive log files >> $plog
find $brarchive_log_dir -name "*.dsv" -ctime +$remove_dayold -exec rm -f {} \;
find $brarchive_log_dir -name "*.sve" -ctime +$remove_dayold -exec rm -f {} \;
find $brarchive_log_dir -name "*.fst" -ctime +$remove_dayold -exec rm -f {} \;
fi
#
rm -f $lockfile

Tree display of the UNIX process table - a click on a node expands the sub-tree of it's children processes

REPORT ZCPUTREE LINE-SIZE 255 NO STANDARD PAGE HEADING.
************************************************************************
* This program displays the UNIX process table as a tree. A click
* on a node (process) will expand the tree and display it's children
* processes. Along with the processes names the process id, owner
* and consumed CPU time is displayed as well. The heart of the program
* is the FIND_CHILD recursive function module, that creates the
* parent/child tree based upon the pid and ppid
************************************************************************
DATA: L(255), F15 TYPE C, LIN TYPE I, LEVEL TYPE I VALUE 2,
BEGIN OF A,
1(6), 2(6), 3(50), 4(6), 5(6),
END OF A,
BEGIN OF B OCCURS 100,
1 TYPE I, 2 TYPE I, 3(50), 4(6), 5(6),
END OF B,
BEGIN OF C OCCURS 100,
1 TYPE I, 2 TYPE I, 3(50), 4(6), 5(6), LEVEL TYPE I,
END OF C,
BEGIN OF TREE OCCURS 100.
INCLUDE STRUCTURE SNODETEXT.
DATA: END OF TREE.
*
START-OF-SELECTION.
SET PF-STATUS 'LIST'.
*
* Get the process table from UNIX
OPEN DATASET '/tmp/AAAA' FOR INPUT IN TEXT MODE.
TRANSFER 'a' TO '/tmp/AAAA'.
CLOSE DATASET '/tmp/AAAA'.
* The filter option and the result of pf might be UNIX specific
* This version is for HP-UX
OPEN DATASET '/tmp/AAAA' FOR INPUT IN TEXT MODE FILTER
'ps -ef|awk ''{if ($5!~/.[:]./){$5=" "}}{print $0}''|awk ''{print $2,
$3,$8,$1,$7}'''.
DO.
READ DATASET '/tmp/AAAA' INTO L.
IF SY-INDEX = 1.
CONTINUE.
ENDIF.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* I am not interested about the vx_inactive_threads (HP specific!)
IF L NS 'vx_inactive_thread'.
SPLIT L AT ' ' INTO A-1 A-2 A-3 A-4 A-5.
MOVE-CORRESPONDING A TO B.
APPEND B.
ENDIF.
ENDDO.
*
* Move the processes to C based upon their parent/child relationship
READ TABLE B INDEX 1.
MOVE-CORRESPONDING B TO C.
C-LEVEL = LEVEL.
APPEND C.
DELETE B INDEX 1.
* Call a recursive function module
PERFORM FIND_CHILD USING C-1.
*
* Fill up the tree-display table
LOOP AT C.
AT FIRST.
TREE-TEXT1 = 'UNIX processes name'.
TREE-TEXT2 = 'Process id and owner'.
TREE-TEXT3 = 'CPU time'.
TREE-TLENGTH1 = 30. TREE-TLENGTH2 = 30. TREE-TLENGTH3 = 30.
TREE-TCOLOR1 = 1. TREE-TCOLOR2 = 2. TREE-TCOLOR3 = 3.
TREE-TLEVEL = 1.
APPEND TREE.
ENDAT.
MOVE-CORRESPONDING C TO A.
TREE-TEXT1 = A-3.
TREE-TEXT2 = A-1. TREE-TEXT2+10 = A-4.
TREE-TEXT3 = A-5.
TREE-TLENGTH1 = 40. TREE-TLENGTH2 = 20. TREE-TLENGTH3 = 10.
TREE-TCOLOR1 = 1. TREE-TCOLOR2 = 2. TREE-TCOLOR3 = 3.
TREE-TLEVEL = C-LEVEL.
APPEND TREE.
ENDLOOP.
*
* Construct and display the tree
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
NODETAB = TREE
EXCEPTIONS
TREE_FAILURE = 1.
SY-LSIND = 0.
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = 'ZCPUTREE'
CALLBACK_USER_COMMAND = 'NODE_SELECT'
IMPORTING
F15 = F15.
*
*---------------------------------------------------------------------*
* FORM FIND_CHILD *
* Recursive f.m. to establish the parent/child relationships *
*---------------------------------------------------------------------*
FORM FIND_CHILD USING VALUE(PARENT_NUMBER) TYPE I.
LOOP AT B.
IF B-2 = PARENT_NUMBER.
* I have found a child - move the parent to the result table and
* try to find the child's children
LEVEL = LEVEL + 1.
MOVE-CORRESPONDING B TO C.
C-LEVEL = LEVEL.
APPEND C.
DELETE B.
PERFORM FIND_CHILD USING B-1.
ENDIF.
ENDLOOP.
* No more children - move one level up
LEVEL = LEVEL - 1.
ENDFORM.
*
*---------------------------------------------------------------------*
* FORM NODE_SELECT *
* This is called, when a node is selected with a double-click *
*---------------------------------------------------------------------*
FORM NODE_SELECT TABLES KNOTEN STRUCTURE SEUCOMM
USING COMMAND
CHANGING EXIT
LIST_REFRESH.
EXIT = ' '.
LIST_REFRESH = 'X'.
ENDFORM.

ABAP Program for Continuously display the rejected lock requests

REPORT ZENQLIST NO STANDARD PAGE HEADING.
***********************************************************************
* Continuously display the rejected lock requests
* Useful tool to detect bottlenecks on particular tables
***********************************************************************
DATA: ENQ_LOCATION(70), LASTLINE TYPE I, FIRSTLINE TYPE I, FLAG TYPE I,
OLDLINE(200).
DATA: BEGIN OF LINE_TBL OCCURS 0.
INCLUDE STRUCTURE SPFLIST.
DATA: END OF LINE_TBL.
DATA: BEGIN OF RES_TBL OCCURS 0.
INCLUDE STRUCTURE SPFLIST.
DATA: END OF RES_TBL.
DATA: BEGIN OF ITAB OCCURS 5.
INCLUDE STRUCTURE THLINES.
DATA: END OF ITAB.
*
START-OF-SELECTION.
* Status for safe exit:
SET PF-STATUS 'SAFESTOP'.
* Figure out the location of the ENQLOG
* Start the enq logging
CALL 'C_ENQUEUE' ID 'OPCODE' FIELD 'X'.
CALL FUNCTION 'Z_ENQUEUE_DELAY'
STARTING NEW TASK 'WAIT'
PERFORMING WHEN_FINISHED ON END OF TASK.
WRITE: ''.
*
AT USER-COMMAND.
IF SY-UCOMM = 'SAFE'.
* Stop the enque logging and exit
CALL 'C_ENQUEUE' ID 'OPCODE' FIELD 'Y'.
SET SCREEN 0.
LEAVE SCREEN.
ENDIF.
SY-LSIND = SY-LSIND - 1.
CALL FUNCTION 'TH_REQUEST_QUEUE'
TABLES
REQUEST_QUEUES = ITAB.
* Read and display the enqlog file
CALL FUNCTION 'ENQUEUE_READ_LOG'
TABLES
LOGLINES = LINE_TBL
EXCEPTIONS
OTHERS = 1.
* Display the last 25 entries
FLAG = 0.
CLEAR RES_TBL. REFRESH RES_TBL.
LOOP AT LINE_TBL.
IF LINE_TBL CS 'SLEEP'.
FLAG = 1.
ELSE.
IF FLAG = 0 AND LINE_TBL CS 'Rejected'.
RES_TBL = OLDLINE.
APPEND RES_TBL.
ELSE.
OLDLINE = LINE_TBL.
DELETE LINE_TBL.FLAG = 0.
ENDIF.
ENDIF.
ENDLOOP.
*
WRITE: / 'List of the last 25 rejected lock requests'.
WRITE: / SY-DATUM, SY-UZEIT.
SKIP.
DESCRIBE TABLE RES_TBL LINES LASTLINE.
FIRSTLINE = LASTLINE - 25.
IF FIRSTLINE <= 1. FIRSTLINE = 1. ENDIF.
IF LASTLINE > FIRSTLINE.
LOOP AT RES_TBL FROM FIRSTLINE TO LASTLINE.
WRITE: / RES_TBL-LINE.
ENDLOOP.
ENDIF.
*
CALL FUNCTION 'Z_ENQUEUE_DELAY'
STARTING NEW TASK 'INFO'
PERFORMING WHEN_FINISHED ON END OF TASK.
*
FORM WHEN_FINISHED USING TASKNAME.
RECEIVE RESULTS FROM FUNCTION 'Z_ENQUEUE_DELAY'.
SET USER-COMMAND 'BUMM'.
ENDFORM.

ABAP Program for Detect object conflicts before importing a transport

REPORT ZTRCONFL NO STANDARD PAGE HEADING.
************************************************************************
* This program subtracts the different objects from a transport data
* file and compares them to the existing objects of the SAP system. The
* result is a list of objects that might conflict with each-other when
* importing the transport.
************************************************************************
PARAMETERS: TRP_FILE(10) DEFAULT 'DEVK900001'.
TABLES: TADIR.
DATA: TP(80) VALUE 'cd /usr/sap/trans/bin;tp GETOBJLIST ', FLAG TYPE I,
OPCODE TYPE X VALUE 2,
BEGIN OF TABL OCCURS 0,
LINE(200),
END OF TABL,
BEGIN OF STRUCC,
PGMID(4), OBJECT(4), OBJ_NAME(30),
END OF STRUCC.
*
TP+37(10) = TRP_FILE.
CALL 'SYSTEM' ID 'COMMAND' FIELD TP
ID 'TAB' FIELD TABL-*SYS*.
WRITE: / 'COLOR CODE:'.
SKIP.
WRITE: / 'RED: OBJECT FROM THE TRANSPORT THAT MIGHT CONFLICTS WITH AN
OBJECT IN A TARGET SYSTEM ' color 6.
WRITE: / 'YELLOW: OBJECT OF THE TARGET SYSTEM THAT MIGHT CONFLICT WITH
AN OBJECT FROM THE TRANSPORT' color 3.
WRITE: / 'BLUE: OBJETC IN A TRANSPORT THAT ARE SAFE TO IMPORT'.
SKIP. ULINE. SKIP.
*
LOOP AT TABL.
IF TABL CP 'R3TR*' OR TABL CP 'LIMU*'.
CONDENSE TABL NO-GAPS.
STRUCC = TABL.
FLAG = 0.
SELECT * FROM TADIR WHERE
OBJ_NAME = STRUCC-OBJ_NAME.
IF FLAG = 0.
WRITE: / STRUCC-PGMID COLOR 6, STRUCC-OBJECT COLOR 6,
STRUCC-OBJ_NAME COLOR 6.
FLAG = 1.
ENDIF.
WRITE: / ' ', TADIR-PGMID COLOR 3, TADIR-OBJECT COLOR 3,
TADIR-OBJ_NAME COLOR 3.
ENDSELECT.
IF FLAG = 0.
WRITE: / STRUCC-PGMID, STRUCC-OBJECT, STRUCC-OBJ_NAME.
ENDIF.
ENDIF.
ENDLOOP.

abap program for Display the true average response time, CPU time, db time ...

REPORT ZTRUERSP NO STANDARD PAGE HEADING.
*********************************************************************
* Display the true average response time.
* The result of this report contains the same data the ST03-workload
* overview screen has with one major difference: the values belonging
* to a defined set of abaps usually running online and taking a very
* long time to complete are ignored during the calculation. These
* abap's response time is not a real dialog response time (even if
* they run in dialog mode) and it can completely offset the actual
* response time of ST03 as well as all the other values (cpu time,
* sequential read ...)
*********************************************************************
TABLES: TRDIR.
DATA: R TYPE P DECIMALS 1, K TYPE P DECIMALS 1, I TYPE I, X TYPE I,
Y TYPE I, ELEM_PER_ROW TYPE I VALUE 8, LASTREC(8), ELAPSTIM(8).
*
DATA: BEGIN OF LIST OCCURS 10.
INCLUDE STRUCTURE MSXXLIST.
DATA: END OF LIST.
DATA: BEGIN OF SUMMARY OCCURS 50.
INCLUDE STRUCTURE SAPWLSUMRY.
DATA: END OF SUMMARY.
DATA: BEGIN OF HI OCCURS 50.
INCLUDE STRUCTURE SAPWLHITL.
DATA: END OF HI.
DATA: BEGIN OF STAB.
INCLUDE STRUCTURE SAPWLSUMRY.
DATA: END OF STAB.
*
PARAMETERS: DATE LIKE SY-DATUM MODIF ID SC1 OBLIGATORY.
PARAMETERS: SERVER(8) MODIF ID SC1 OBLIGATORY LOWER CASE.
PARAMETERS: TRUE_RSP AS CHECKBOX.
SELECT-OPTIONS ABPAP FOR TRDIR-NAME NO INTERVALS.
*
PERFORM CALCULATE.
FORMAT INTENSIFIED OFF.
* box1
PERFORM BOX USING 1 4 'Instance'.
SKIP TO LINE 2. POSITION 2.
* line1
WRITE: /2 'SAP System',
18 SY-SYSID,
29 'First record',
45 '00:00:00',
56 'Date',
72 DATE.
* line2
IF DATE = SY-DATUM.
LASTREC = SY-UZEIT.
ELSE.
LASTREC = '235959'.
ENDIF.

WRITE: / 'Server' UNDER 'SAP System',
SY-HOST UNDER SY-SYSID,
'Last record' UNDER 'First record',
LASTREC USING EDIT MASK '__:__:__' UNDER '00:00:00'.
* line3
READ TABLE LIST INDEX 1.
TRANSLATE LIST-SERV USING 's a p d '.
CONDENSE LIST-SERV NO-GAPS.
WRITE: / 'Instance no.' UNDER 'SAP System',
LIST-SERV UNDER SY-SYSID,
'Elapsed time' UNDER 'First record',
LASTREC USING EDIT MASK '__:__:__' UNDER '00:00:00'.
* box2
PERFORM BOX USING 7 14 'Workload'.
SKIP TO LINE 8. POSITION 2.
* line1
WRITE: /2 'CPU time',
26 STAB-CPUTI LEFT-JUSTIFIED,
38 'Database calls',
62 STAB-PHYCALLS LEFT-JUSTIFIED.
* line2
R = STAB-READDIRCNT + STAB-READSEQCNT + STAB-CHNGCNT.
WRITE: / 'Elapsed time' UNDER 'CPU time',
STAB-ELAPSEDTI UNDER STAB-CPUTI LEFT-JUSTIFIED,
'Database requests' UNDER 'Database calls',
R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line3
WRITE: / ' Direct reads' UNDER 'Database calls',
STAB-READDIRCNT UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line4
WRITE: / 'Dialog steps' UNDER 'CPU time',
STAB-COUNT UNDER STAB-CPUTI LEFT-JUSTIFIED,
'Sequential reads' UNDER 'Database calls',
STAB-READSEQCNT UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line5
R = STAB-RESPTI / STAB-COUNT.
WRITE: / ' AV. response time' UNDER 'CPU time',
R UNDER STAB-CPUTI LEFT-JUSTIFIED,
'Changes' UNDER 'Database calls',
STAB-CHNGCNT UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line6
R = STAB-CPUTI / STAB-COUNT.
WRITE: / ' AV. CPU time' UNDER 'CPU time',
R UNDER STAB-CPUTI LEFT-JUSTIFIED.
* line7
R = STAB-QUEUETI / STAB-COUNT.
K = STAB-READDIRTI + STAB-READSEQTI + STAB-CHNGTI.
K = K / ( STAB-READDIRCNT + STAB-READSEQCNT + STAB-CHNGCNT ).
WRITE: / ' AV. wait time' UNDER 'CPU time',
R UNDER STAB-CPUTI LEFT-JUSTIFIED,
'Time per DB request' UNDER 'Database calls',
K UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line8
R = STAB-READDIRTI / STAB-READDIRCNT.
K = STAB-LOADGENTI / STAB-COUNT.
WRITE: / ' AV. load time' UNDER 'CPU time',
K UNDER STAB-CPUTI LEFT-JUSTIFIED,
' Direct reads' UNDER 'Database calls',
R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line9
R = STAB-READSEQTI / STAB-READSEQCNT.
K = ( STAB-READDIRTI + STAB-READSEQTI + STAB-CHNGTI ) / STAB-COUNT.
WRITE: / ' AV. DB req. time' UNDER 'CPU time',
K UNDER STAB-CPUTI LEFT-JUSTIFIED,
' Sequential reads' UNDER 'Database calls',
R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line10
R = ( STAB-BYTES / 1024 ) / STAB-COUNT.
K = STAB-CHNGTI / STAB-CHNGCNT.
IF TRUE_RSP = 'X'.
WRITE: / ' AV. bytes req.' UNDER 'CPU time' COLOR 6,
R UNDER STAB-CPUTI LEFT-JUSTIFIED COLOR 6,
' Changes and commis' UNDER 'Database calls',
K UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
ELSE.
WRITE: / ' AV. bytes req.' UNDER 'CPU time',
R UNDER STAB-CPUTI LEFT-JUSTIFIED,
' Changes and commis' UNDER 'Database calls',
K UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
ENDIF.
* line11
WRITE: / .
* line12
R = STAB-ROLLINTI / STAB-ROLLINCNT.
WRITE: / 'Roll-ins' UNDER 'CPU time',
STAB-ROLLINCNT UNDER STAB-CPUTI LEFT-JUSTIFIED,
'Av. time/roll in' UNDER 'Database calls',
R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line13
R = STAB-ROLLOUTTI / STAB-ROLLOUTCNT.
WRITE: / 'Roll-outs' UNDER 'CPU time',
STAB-ROLLOUTCNT UNDER STAB-CPUTI LEFT-JUSTIFIED,
'Av. time/roll out' UNDER 'Database calls',
R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* box3
PERFORM BOX USING 23 6 'Task types'.
SKIP TO LINE 24. POSITION 2.
WRITE /2
'Only dialog times! The following long running reports are excluded:'.
FORMAT INTENSIFIED ON.
LOOP AT ABPAP.
Y = 25 + ( ( SY-TABIX - 1 ) DIV ELEM_PER_ROW ).
X = ( ( SY-TABIX - 1 ) MOD ELEM_PER_ROW ) * 9 + 2.
SKIP TO LINE Y. POSITION X.
WRITE ABPAP-LOW.
ENDLOOP.
*
INITIALIZATION.
DATE = SY-DATUM.
SERVER = SY-HOST.
*
*---------------------------------------------------------------------*
* FORM BOX *
*---------------------------------------------------------------------*
FORM BOX USING VALUE(YPOS) HEIGHT TEXT.
*
DATA: WIDTH TYPE I VALUE 84,
R TYPE I, K TYPE I.
* Bottom horizontal line
R = HEIGHT + YPOS.
SKIP TO LINE R.
DO WIDTH TIMES.
WRITE '-' NO-GAP.
ENDDO.
* Top horizontal line with text
K = STRLEN( TEXT ).
R = WIDTH - 2 - K.
SKIP TO LINE YPOS.
WRITE: '--'.
WRITE AT 3(K) TEXT NO-GAP.
DO R TIMES.
WRITE: '-' NO-GAP.
ENDDO.
* Vertical lines
DO HEIGHT TIMES.
SKIP TO LINE YPOS.
WRITE: '|'. POSITION WIDTH. WRITE: '|'.
YPOS = YPOS + 1.
ENDDO.
ENDFORM.
*---------------------------------------------------------------------*
* FORM CALCULATE *
*---------------------------------------------------------------------*
FORM CALCULATE.
* Get the performance data
CALL FUNCTION 'TH_SERVER_LIST'
TABLES
LIST = LIST.
CALL FUNCTION 'SAPWL_GET_SUMMARY_STATISTIC'
EXPORTING
PERIODTYPE = 'D'
HOSTID = SERVER
STARTDATE = SY-DATUM
TABLES
SUMMARY = SUMMARY
HITLIST_RESPTI = HI.
LOOP AT SUMMARY.
IF SUMMARY-TASKTYPE = 'DIALOG'.
MOVE-CORRESPONDING SUMMARY TO STAB.
ENDIF.
ENDLOOP.
* Correction with the abaps
IF TRUE_RSP = 'X'.
LOOP AT HI.
LOOP AT ABPAP.
IF HI-REPORT = ABPAP-LOW.
STAB-CHNGCNT = STAB-CHNGCNT - HI-UPDCNT -
HI-DELCNT - HI-INSCNT.
STAB-CHNGTI = STAB-CHNGTI - HI-UPDTI - HI-DELTI -
HI-INSTI.
STAB-COUNT = STAB-COUNT - 1.
STAB-CPUTI = STAB-CPUTI - HI-CPUTI.
STAB-LOADGENTI = STAB-LOADGENTI - HI-GENERATETI -
HI-REPLOADTI - HI-CUALOADTI - HI-DYNPLOADTI.
STAB-PHYCALLS = STAB-PHYCALLS - HI-PHYDELCNT -
HI-PHYREADCNT - HI-PHYINSCNT - HI-PHYUPDCNT.
STAB-QUEUETI = STAB-QUEUETI - HI-QUEUETI.
STAB-READDIRCNT = STAB-READDIRCNT - HI-READDIRCNT.
STAB-READDIRTI = STAB-READDIRTI - HI-READDIRTI.
STAB-READSEQCNT = STAB-READSEQCNT - HI-READSEQCNT.
STAB-READSEQTI = STAB-READSEQTI - HI-READSEQTI.
STAB-RESPTI = STAB-RESPTI - HI-RESPTI.
STAB-ROLLINCNT = STAB-ROLLINCNT - HI-ROLLINCNT.
STAB-ROLLOUTCNT = STAB-ROLLOUTCNT - HI-ROLLOUTCNT.
STAB-ROLLOUTTI = STAB-ROLLOUTTI - HI-ROLLOUTTI.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDFORM.

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

goodsites