REPORT ZPARPROC.
************************************************************************
* This program implements parallel processing. Many time consuming
* report can be broken into equal pieces and run parallel, reducing
* the runtime (in this case searching for a string in the source code
* of a set of abaps). The main program (mother) creates CHILD_NU
* number of child programs(1-9),gives each of them a separate task, runs
* them parallel and then collects the end-result. The child program is
* actually embedded in the mother program, so the mother virtually
* gives birth of her children. A child that finished it's part, commits
* suicide: deletes itself at the end.
* Here is the result of a performonce test with 1-9 children processes
* for a light and a heavy task:
*
* children# light(Z* programs)(sec) heavy(R* programs)(sec)
* 1 51 664 100%
* 2 28 357
* 3 22 250
* 4 20 232
* 5 18 207 31%
* 6 19 209
* 7 18 219
* 8 21 202
* 9 20 211
*
* Conclusions:
* The performance starts to deteriorate when the children# exceeds a
* certain, task specific number (the children start to compete
* against each other for the same resources)
* The heavier the task - the more significant the performance gain.
************************************************************************
* The parent's data declaration
TABLES: TRDIR, TBTCO, INDX.
PARAMETERS: CHILD_NU TYPE I DEFAULT '3',
PATTERN(2) DEFAULT 'Z%'.
DATA: C,
CHILD(32) VALUE 'ZCHILD#',
JOBNAME(32),
ABAP_NAME(8).
DATA: BEGIN OF IV_TABLE OCCURS 10, "Table of intervals
LOW LIKE TRDIR-NAME,
HIGH LIKE TRDIR-NAME,
END OF IV_TABLE.
DATA: BEGIN OF ITAB OCCURS 500, "Table of program names
LINE(72),
END OF ITAB.
DATA: BEGIN OF CHILD_NAME_TAB OCCURS 10, "Table of the children's names
L(7), LL(23),
END OF CHILD_NAME_TAB.
DATA: BEGIN OF RESULT_TAB OCCURS 100, "The result of a single child
NAME LIKE TRDIR-NAME,
END OF RESULT_TAB.
DATA: BEGIN OF END_RESULT_TAB OCCURS 100, "The table of the end-results
NAME LIKE TRDIR-NAME,
END OF END_RESULT_TAB.
* Evenly distribute the work between the children
* With EXEC SQL it would be nicer, but less generic
DATA: INDEX TYPE I.
DATA: LINE_NUM TYPE I.
DATA: INTERVAL TYPE I.
DATA: BEGIN OF RANGE OCCURS 1000,
NAME LIKE TRDIR-NAME,
END OF RANGE.
* Timestamp
GET TIME. WRITE:/ SY-UZEIT. SKIP.
* Timestamp
SELECT * FROM TRDIR WHERE NAME LIKE PATTERN. "Fill up the range table
IF NOT TRDIR-NAME IS INITIAL.
RANGE = TRDIR-NAME.
APPEND RANGE.
ENDIF.
ENDSELECT.
SORT RANGE BY NAME.
DESCRIBE TABLE RANGE LINES LINE_NUM.
INTERVAL = LINE_NUM / CHILD_NU. "This will be the length of the
"working range of a single child
INDEX = 0.
DO. "Create the table of distinct ranges: 1 for each child
INDEX = INDEX + 1.
READ TABLE RANGE INDEX INDEX.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IV_TABLE-LOW = RANGE-NAME.
INDEX = INDEX + INTERVAL.
READ TABLE RANGE INDEX INDEX.
IF SY-SUBRC <> 0.
INDEX = LINE_NUM.
READ TABLE RANGE INDEX INDEX.
IV_TABLE-HIGH = RANGE-NAME.
APPEND IV_TABLE.
EXIT.
ENDIF.
IV_TABLE-HIGH = RANGE-NAME.
APPEND IV_TABLE.
ENDDO.
* Create the children
DATA: NUM.
DO CHILD_NU TIMES. "Loop on the children
NUM = SY-INDEX. "The index of the child
CLEAR ITAB. REFRESH ITAB.
READ REPORT SY-REPID INTO ITAB.
LOOP AT ITAB.
C = ITAB+1(1).
IF C <> '@'. "Give birth of a child:
DELETE ITAB. "Filter it out from mamy's belly
ELSE.
SHIFT ITAB LEFT BY 2 PLACES.
MODIFY ITAB.
ENDIF.
ENDLOOP.
*
LOOP AT ITAB. "Give the child identity and a task to work on
REPLACE '#' WITH NUM INTO ITAB.
READ TABLE IV_TABLE INDEX NUM.
REPLACE '&' WITH IV_TABLE-LOW INTO ITAB.
IF SY-SUBRC = 0.MODIFY ITAB.CONTINUE.ENDIF.
REPLACE '$' WITH IV_TABLE-HIGH INTO ITAB.
MODIFY ITAB.
ENDLOOP.
*
CHILD+6(1) = NUM. "At last: create the child
INSERT REPORT CHILD FROM ITAB.
*
JOBNAME = CHILD. "Create a distinct job name to run the child in bg
JOBNAME+8(8) = SY-DATUM.
JOBNAME+16(8) = SY-UZEIT.
*
CHILD_NAME_TAB = JOBNAME. "Save the name of my wonderful child
APPEND CHILD_NAME_TAB.
*
PERFORM CREATE_A_CHILD_JOB. "Start the child
ENDDO.
* Wait for my children to complete their task and get the result
DO.
LOOP AT CHILD_NAME_TAB.
SELECT * FROM TBTCO WHERE JOBNAME = CHILD_NAME_TAB.
ENDSELECT.
IF TBTCO-STATUS = 'F' OR TBTCO-STATUS = 'A'.
REFRESH RESULT_TAB.
IMPORT RESULT_TAB FROM SHARED BUFFER INDX(ST) ID CHILD_NAME_TAB-L.
LOOP AT RESULT_TAB. "Merge the results in one single table
END_RESULT_TAB = RESULT_TAB.
APPEND END_RESULT_TAB.
ENDLOOP.
DELETE CHILD_NAME_TAB.
ENDIF.
ENDLOOP.
IF SY-SUBRC <> 0. EXIT. ENDIF.
ENDDO.
* Hooray, all the children are finished
LOOP AT END_RESULT_TAB.
WRITE: END_RESULT_TAB.
ENDLOOP.
* Timestamp
GET TIME. SKIP. WRITE:/ SY-UZEIT.
* Timestamp
* Schedule the child to run in background
FORM CREATE_A_CHILD_JOB.
DATA: JOBCOUNT LIKE TBTCJOB-JOBCOUNT.
ABAP_NAME = CHILD.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBNAME = JOBNAME
IMPORTING
JOBCOUNT = JOBCOUNT.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
JOBNAME = JOBNAME
JOBCOUNT = JOBCOUNT
AUTHCKNAM = SY-UNAME
REPORT = ABAP_NAME.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBNAME = JOBNAME
JOBCOUNT = JOBCOUNT
STRTIMMED = 'X'.
ENDFORM.
* Here is the child template in the mothers tummy:
*@program zchild#.
*@tables: trdir, indx.
*@data: begin of itab occurs 500,
*@ line(72),
*@end of itab.
*@data: begin of result_tab occurs 100,
*@ name like trdir-name,
*@end of result_tab.
*@data: string(20) value 'loadi'.
*@
*@select * from trdir where name between
*@'&'
*@and
*@'$'.
*@ read report trdir-name into itab.
*@ loop at itab.
*@ if itab-line cs string.
*@ write: trdir-name.
*@ result_tab = trdir-name.
*@ append result_tab.
*@ exit.
*@ endif.
*@ endloop.
*@endselect.
*@* Export the result to shared buffer
*@export result_tab to shared buffer INDX(ST) ID 'ZCHILD#'.
*@* The child commits a suicide after it has finished it's task
*@delete report 'ZCHILD#'.
Subscribe to:
Post Comments (Atom)
Automation Testing
- Manual and Automation testing Challenges
- What you need to know about BVT (Build Verification Testing)
- BVT types
- Learning basics of QTP automation tool and preparation of QTP interview questions
- QuickTest Pro - QTP Functional testing tool review
- Tips you should read before automating your testing work
- Choosing Automation tool for your organization
Blog Archive
-
▼
2010
(342)
-
▼
October
(127)
- free downloadABAP/4 OLE Automation Controller pdf ...
- sap abap program Sample XML Source Code For SAP
- sap abap XML file to word document through SAP
- abap program for How to determine the number of av...
- Handling favorites in ABAP Workbench
- ABAP/4 Programming Quickstart
- Number Range Object in sap
- PERFORMENCE TIPS IN ABAP
- ABAP Tips and Tricks
- ABAP Tips and Tricks
- What is the use of the POSITION and SIZE command i...
- How to find the Driver Program for the given SAPsc...
- How can I set the header and footer in the main wi...
- What the conditional statements used in SAP Scripts?
- What the conditional statements used in SAP Scripts?
- What is the difference between the SAP Script text...
- How can I change the page size of the layout?
- How can I apply shading for the BOXes in SAP Script?
- How can I format the date being displayed in the S...
- How can I format the time in the SAP Script?
- Frequently Used System Variables in SAPScript?
- What are the different types of windows in SAP Scr...
- How can I set the position of the leading sign to ...
- What are the various text formatting options in SA...
- How can I trigger new page in SAPScripts?
- How can I prevent page-break in the message that i...
- How can I copy SAPScripts from one client to another?
- How can I print logos in SAPScripts?
- How can I copy SAPScripts from one client to another?
- How can I Word Wrap the text being displayed in SA...
- How can I display barcodes in SAPScripts?
- I have created a script in language DE. Now I need...
- ABAP Tips and Tricks
- PERFORMENCE TIPS IN ABAP
- ABAP Tips and Tricks
- Number Range Object in sap
- Handling favorites in ABAP Workbench
- abap program for How to determine the number of av...
- ABAP/4 Programming Quickstart
- Some ABAP/4 Query header line variable
- ABAP Quick Viewer
- Creating The Query
- SAP ABAP Queries
- Creating Functional Areas Without a Logical Database
- Creating Functional Areas using a Logical Database
- Creating the ABAP Query
- Creating the User Group in SAP ABAP Queries
- Ranked List and Statistics in abap query
- Data Retrieval Using Program in abap query
- Authorizations in abap query
- What Is SAP Queries
- Authorizations in abap query
- SAP Query (BC-SRV-QUE)
- click on link
- HOW TO DEVELOPE ABAP QUERY
- ABAP/4 Query Hints and Tips IN Abap Query
- ABAP Program: Output of Date Format
- ABAP Programs : Using the events start-of-selectio...
- C program that uses the GUI automatization interfa...
- This ABAP rings the bell on any chosen pc, that ha...
- Method of displaying the hidden ABAPs of SAP - fro...
- abap program for Parallel processing: breaks a rep...
- Simple macro that prevents runnig more than one in...
- abap Program to download/upload table data dynamic...
- Create/Modify/Delete records in any table from CSV...
- Displaying Graphics using an ABAP Program
- ABAP Program: Output of Date Format
- Making a Java Editor in ABAP and compiling it
- Program to Hide ABAP's Source Code and Protects it
- Program to Hide ABAP's Source Code and Protects it
- Using Different Color in ABAP
- Protect part of ABAP code from modifying
- String Handling in ABAP - Removing Unwanted Char
- How to find out Total No of Pages of a Report Outp...
- Split String into two parts at delimiter in sap abap
- Macro to validate Date in abap sap
- How to get the field descriptions of a table?
- Dynamically increase/decrease the number of batch/...
- Have active URL-s in the list an ABAP report creates
- ABAP Program: show and hide windows by request
- Perl script to check the status of the SAP systems...
- abap program for Customized, dynamic login screen
- ABAP Program for refresh dynamically - once a seco...
- ABAP Program for Limit the parallel instances a pa...
- Hide and password-protect any ABAP's source - stil...
- Display the long raw fields of such SAP tables as ...
- ABAP Program for Yet another customized logon scre...
- The abap part, that retrieves the data from the SA...
- abap program for The remote script for 96a
- ABAP Program for This perl displays a self-refresh...
- abap program for Automatically save and circulate ...
- Tree display of the UNIX process table - a click o...
- ABAP Program for Continuously display the rejected...
- abap program for Display the true average response...
- COMMUNICATION INTERFACE IN ABAP COMPLETE
- COMMUNICATION INTERFACE 1
- COMMUNICATION INTERFACE 2
- COMMUNICATION INTERFACE 3
- COMMUNICATION INTERFACE 4
- COMMUNICATION INTERFACE 5
-
▼
October
(127)
No comments:
Post a Comment