Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
12,086

1.            Introduction

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.

Exporting parameters:

authority

:

Signifies print authorization, Default for ‘authorization’.

copies

:

Signifies number of copies generated in spool

cover_page

:

Output value for cover sheet

data_set

:

Name of the spool file

department

:

Department on cover page

destination

:

Spool output device

expiration     

:

Spool retention period

immediately

:

Print immediately in spool

new_list_id

:

New spool request

no_dialog

:

If you select no_dialog, a dialog will appears allows user to change print parameters. Use space to suppress dialog.

user

:

Signifies user name

IMPORTING parameters:      

out_parameters

:

Defines value to be passed to out_parameters

valid

:

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'
          EXPORTING
                   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
          IMPORTING
                   out_parameters                 = wa_pri_params
                   valid                                = lv_valid
          EXCEPTIONS
                   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
          NEW-SECTION
          PARAMETERS wa_pripar
          NO DIALOG.
          WRITE 😕 g_counter, ' Number of records processed'.

  1. ELSE.
              CLEAR lv_counter.
    ENDIF.

·         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:

Transaction: SP01

You can also select spool request by entering Spool request Number.

Display Spool request by selecting icons under TYPE column.

Another spool request is created after processing of next 5000 records, depending upon conditions.

4.            Retrieving Service order historical data from CDHDR table:

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:

Sample data

4 Comments
Labels in this area