How To – Get APD Record Count in an Internal Table
A few days back, in the project that I am working on, we had a requirement to get the count of records that were being extracted from our BW system through flat files.
The client wanted a sort of reconciliation on the count of records in the extracted file and the count of records that BW said was extracted. Don’t ask me if there would be any difference…..
We were using both Open Hubs and Analysis Processes to extract files to application path. Counting the records extracted through an Open Hub was not a problem since we have the RSBKREQUEST or RSBKREQUEST_V tables. But, the APDs don’t have any such tables that we knew of that would give us the number of records transferred. Now, don’t tell me there is a table for APD, it would mean I wasted a full day running in circles to get the tables.
The number of records extracted is displayed in the execution log of the APD monitor whenever an APD is executed,
The log is also accessible through the transaction RSANW_MONITOR.
This meant that the log was being stored somewhere. Debugging the APD execution as well as the monitor screen entry didn’t turn out anything and I being an average ABAP programmer I didn’t understand most of the code.
The message class RSAN_RT and message number 650 had the entry “File was overwritten. &2 records were written.”, but I was not able to figure out how the record count was populated in the ‘&2’.
Getting a little deeper we gathered that the application log messages were stored in the BAL* tables. The BALHDR table with the ‘log number’ as the key also contains a log entry header data for every run of the Analysis process and the BALDAT table contains the log data in a compressed format.
The actual log entries can be read to different internal tables, by using the function module “APPL_LOG_READ_DB_WITH_LOGNO”. The log number can be passed as the input,
and the corresponding log entries can be retrieved from the different internal tables to which the function module saves the log information.
The internal table ‘MESSAGES’ contains the actual log entries for the record count, and the record entry for the message class RSAN_RT and message number 650(as mentioned above)contains the number of records extracted, in the column MSGV2.
The following piece of code (with necessary changes) would give us the number of records extracted during the last run by an Analysis Process.
* tables to get application log information
TYPES: BEGIN OF lognumbers_tab,
item LIKE balhdr-lognumber,
END OF lognumbers_tab.
DATA: t_lognum_tab TYPE STANDARD TABLE OF lognumbers_tab,
wa_lognum_tab TYPE lognumbers_tab.
DATA: t_messages_tab TYPE TABLE OF balm,
wa_messages_tab TYPE balm.
DATA: t_balhdr TYPE TABLE OF balhdr,
wa_balhdr TYPE balhdr.
DATA rec_count TYPE i.
DATA n_logs LIKE sy-dbcnt.
* Select the latest run for the process ID from APD LOG table
SELECT arun end_time start_time
UP TO 1 ROWS
INTO (l_arun, l_end_time, l_start_time)
WHERE process = wa_rsant_process-process
AND process_version = ‘A’
ORDER BY start_time DESCENDING.
SELECT SINGLE * FROM balhdr
WHERE extnumber = l_apd_arun.
wa_lognum_tab-item = wa_balhdr-lognumber.
APPENDwa_lognum_tab TO t_lognum_tab.
CALL FUNCTION ‘APPL_LOG_READ_DB_WITH_LOGNO’
number_of_logs = n_logs
lognumbers = t_lognum_tab
* HEADER_DATA = t_HEADER_DATA_TAB
* HEADER_PARAMETERS = t_HEADER_PARAMETERS_TAB
messages = t_messages_tab
* MESSAGE_PARAMETERS = t_MESSAGES_PARAMETERS_TAB
IF n_logs = 0.
* PERFORM RAISE_ERROR USING ‘E’ ‘S&’ ‘115’ ” CHANGING RETURN.
** fill info structure
LOOP AT t_messages_tab INTO wa_messages_tab WHERE
msgid EQ ‘RSAN_RT’
AND msgno EQ ‘650’.
p_l_apd_rec_count = wa_messages_tab-msgv2.