Tracking a background Job Via Spool Generation and use of CDHDR table
Why to monitor background jobs ?
Many a times we schedule background jobs where the data is processed. In the development environment the number of records are less hence the time taken is manageable. When it comes to production environment, the number of record can fall in the range of hundreds of thousands. In such cases, it may be required to generate a spool request everytime a fixed number of records is processed so that the job is monitored in real time and the user has a general idea on the status of job.
What is CDHDR table ?
Also sometimes it is required to retireve the historical data of the changes made to an object, CDHDR table can be used in this case to trace the changes made at the header level.
2. Monitor a background job by spool generation:
FM used to generate spool “GET_PRINT_PARAMETERS” : Read, determine, change spool print parameters and archive parameters.
Signifies print authorization, Default for ‘authorization’.
Signifies number of copies generated in spool
Output value for cover sheet
Name of the spool file
Department on cover page
Spool output device
Spool retention period
Print immediately in spool
New spool request
If you select no_dialog, a dialog will appears allows user to change print parameters. Use space to suppress dialog.
Signifies user name
Defines value to be passed to out_parameters
Has the value BLANK, if the user cancelled the print screen.
You should query against the value VALID, its has only two value either TRUE or FALSE.
IF VALID = FALSE, either the print dialog has been canceled by user or wrong value is passed to function module parameters to print properly, for e.g. printing in the background in a forefront printer.
3. Steps to generate spool:
· Spool generation is done only when the record is processed.
· Once the records are processed, FM to commit the changes is called.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
· Once the changes are saved in database and a fixed number of records are processed or when all the records are processed,call is made to the FM ‘GET_PRINT_PARAMETERS’ as follows:
CALL FUNCTION ‘GET_PRINT_PARAMETERS’
authority = space
copies = ‘1’
cover_page = space
data_set = space
department = space
destination = space
expiration = ‘1’
immediately = space
new_list_id = ‘X’
no_dialog = ‘X’
user = sy-uname
out_parameters = wa_pri_params
valid = lv_valid
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF lv_valid <> space AND sy-subrc = 0.
wa_pri_params-prrel = space.
wa_pri_params-primm = space.
NEW-PAGE PRINT ON
WRITE :/ g_counter, ‘ Number of records processed’.
· Here in this case, we have to create new spool after processing of every 5000 records.
· This generates the spool as follows with ‘G_COUNTER’ containing the count of the number of records processed.
· NEW-PAGE PRINT ON statement is used to print new spool.
· To check the spool GO to TCODE ‘SP01’ -> search the spool generated -> click on the spool to see the output generated.
Output when G_COUNTER is set to ‘5000’ i.e spool after every 5000 records processed.
Spool request selection screen:
You can also select spool request by entering Spool request Number.
Display Spool request by selecting icons under TYPE column.
4. Retrieving Service order historical data from CDHDR table:
The data from the CDHDR table can be retrieved by passing the object class and object id as required. The field required can be entered in the select query and the required details based on the date, time, user id can be used as per the requirement.
Example of the select query:
OBJECT CLASS: CRM_ORDER
OBJECT ID: GUID OF THE SERVICE ORDER
Structure of CDHDR table: