Thursday, February 23, 2012

Buffer problems with HR_READ_INFOTYPE HR_INFOTYPE_OPERATION and the TBUFF


Hi Folks,
i had an enquiry today. the problem is a report that makes some 20000 HR_INFOTYPE_OPERATION function calls on different pernr/persons.
The run time grows exponentially  with the number of pernr processed.

The reason for this is the buffering scheme in the HR_INFOTYPE_OPERATION FUNCTION
Calling the HR_PSBUFFER_INITIALIZE before processing each person leads to a linear run time.
The reason is that with each person processed the PS buffer table grows by several lines.

In SAP HR there are several buffers with this tricky behaviour:
  1. TBUFF: the buffer of the PCLx (PCL1,PCL2...PCL4) tables. The import export macros use a form that buffers the data when reading and writing. It can be cleared with the RP-INIT-BUFFER macro (Table TRMAC)
  2. PS Buffer: already mentioned above int the HR_IT_OPERATION VERSION
  3. PS Buffer HR_READ_INFOTYPE the same buffer as above, (ususally the tables are common parts) can be cleared with HR_INITIALIZE_BUFFER
  4. PNP Buffer the so called PRELP Buffer. This one you cannot clear, and usually it does not create problems, because it is designed to work with huge amounts of data.
One important and interesting thing is that you must know what buffer you  are using (even if indirectly with standard function calls).
So in a PNP program you should not call functions that read the infotypes with the PS buffer or with another buffer. Because you would break the buffer, causing time wasting reads in the best case, and in the worst case reading fake information from the database leading to data corruption.

So in a PNP program you should always call the "read-infotype form in program SAPDBPNP" Possibly with the TRMAC Macro RP-READ-INFOTYPE
While in  masterdata (pa30 and the like) you should use the PS buffer functions and forms. just like     PERFORM READ_INFOTYPE(SAPFP50P) USING...

So watch your buffers, and ...have a happy run time!
Happy hacking!


-- The TRMAC RP-READ-INFOTYPE macro

RP-READ-INFOTYPE    001    ****************************************
RP-READ-INFOTYPE    002    * RP-READ-INFOTYPE                     *
RP-READ-INFOTYPE    003    ****************************************
RP-READ-INFOTYPE    004    * PARAMETERS:                          *
RP-READ-INFOTYPE    005    *   PERNR      REQUESTED PERSONALNUMBER*
RP-READ-INFOTYPE    006    *   INFTY      REQUESTED INFOTYPNUMBER *
RP-READ-INFOTYPE    007    *   INFTY-TABLE OUTPUT-TABLE LIKE PNNNN*
RP-READ-INFOTYPE    008    *   BEGDA      REQUESTED INTERVAL-BEGIN*
RP-READ-INFOTYPE    009    *   ENDDA      REQUESTED INTERVAL-END  *
RP-READ-INFOTYPE    010    ****************************************
RP-READ-INFOTYPE    011    *SET DEBUGGING INTERRUPT ON            *
RP-READ-INFOTYPE    012    PERFORM READ-INFOTYPE(SAPDBPNP)        *
RP-READ-INFOTYPE    013    TABLES &3                      *
RP-READ-INFOTYPE    014    USING  &1 '&2' &4 &5
RP-READ-INFOTYPE    015    *SET DEBUGGING INTERRUPT OFF           *


--- The RP-INIT-BUFFER macro coding from table TRMAC

RP-INIT-BUFFER    001    ****************************************
RP-INIT-BUFFER    002    * RP: initialisierung puffer-tabellen  *
RP-INIT-BUFFER    003    ****************************************
RP-INIT-BUFFER    004    CLEAR:   BUFFER_DIR
RP-INIT-BUFFER    005    REFRESH: BUFFER_DIR
RP-INIT-BUFFER    006    CLEAR:   TBUFF
RP-INIT-BUFFER    007    REFRESH: TBUFF
RP-INIT-BUFFER    008    CLEAR:   BEFORE_IMAGE_PCLX
RP-INIT-BUFFER    009    REFRESH: BEFORE_IMAGE_PCLX
RP-INIT-BUFFER    010    CLEAR:   DEL_PCLX_TAB
RP-INIT-BUFFER    011    REFRESH: DEL_PCLX_TAB
RP-INIT-BUFFER    012    CLEAR: PAYR_BUFFER
RP-INIT-BUFFER    013    REFRESH: PAYR_BUFFER