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

Wednesday, February 15, 2012

Off topic: how time evaluation (SAP RPTIME00) sets the retrocalculation date for payroll

One insteresting question today: 
How does the TM RPTIME00 time evaluation engine sets the retrocalculation date RRDAT on the IT0003 to trigger a payroll recalculation?

the answer is simple, but as always the thingy is tricky
In form SET_PAYROLL_RECALCULATION. if the retro switch for TM is set the the evaluation period of TM is checked, and a routine checks whether for each recalculated day a change has occurred in the ZL table compared to the existing ZL of the previous calculation.
the oldes change date in ZL i writte to RRDAT of IT0003

the enabling of the retro switch "SW_FUNC-RLG" happens through the statement
CHECK      RPR 
in the Time evaluation schema


Here the routine.
*---------------------------------------------------------------------*
*       FORM SET_PAYROLL_RECALCULATION                              *
*---------------------------------------------------------------------*
*$*$ Bestimmt RR-Datum für L&G von Sicht des RPTIME00
*$*$ Lücke: Falls RR-Datum von L&G schon für die Vorperiode sitzt wird
*$*$     nicht die RPTIME-spezfische Rückrechnungserkennung durchlaufen.
*       Vorgehen:
*       1. Ist die aktuelle Periode von L&G schon abgerechnet?
*          Wenn nein: stop.
*       2. Liegt das RR-Datum-LG vor Beginn der aktuellen Periode?
*          Wenn ja: stop.
*       3. Bestimme den Tag, an dem sich Daten fuer L&G geaendert
*          haben. (FORM CHECK_RECALCULATION)
*$*$ Punkt 5 wird nun in EXPORT_PERSON überprüft, da die RR-Relevanz für
*$*$ L&G auch dann für das Setzen des Matchcode W gebraucht wird, wenn
*$*$ schon ein RR-Datum für L&G gesetzt ist.
**      5. Ist das RR-Datum-LG kleinergleich dem RR-Datum-ZE?
**         Wenn ja: stop.
*       6. Es muss eine RR fuer L&G gesetzt werden.
*---------------------------------------------------------------------*
FORM SET_PAYROLL_RECALCULATION.
  DATA: SET_RECALC_DATE TYPE D.

  CHECK SW_FUNC-RLG EQ '1'.

* Check ob L&G den Monat schon abgerechnet hat:
  CHECK P0003-ABRDT GE ACT_PERIOD-BEGDA.

* Check ob L&G schon eine RR sitzen hat, die vor Beginn der Per. ist:
  CHECK P0003-RRDAT IS INITIAL OR P0003-RRDAT GE PER-BEGDA.

* Ueberpruefen, ob RR zu setzen ist: This one compars the ZL with the original ZL
  PERFORM CHECK_RECALCULATION USING SET_RECALC_DATE.
* nur wenn Datum kleiner als P0003-rrdat
  CHECK SET_RECALC_DATE NE HIGH-DATE.

* This check is now done in EXPORT_PERSON
* check p0003-rrdat gt set_recalc_date or p0003-rrdat is initial.
                                       "XAYP30K136788

* -- RR ist von Sicht des RPTIME00 zu setzen:
* P0003-RRDAT = SET_RECALC_DATE.                             "YLLK63068
* MODIFY P0003 INDEX 1.                                      "YLLK63068
  IF SET_P0003-RRDAT IS INITIAL                             "YLLK63068
      OR SET_RECALC_DATE LT SET_P0003-RRDAT.                "YLLK63068
    SET_P0003-RRDAT = SET_RECALC_DATE.                      "YLLK63068
  ENDIF.                                                    "YLLK63068
ENDFORM.                               "OF SET_RECALCULATION.

Interestingly enough function check RLG has no coding but is handled in a very special way that puzzles me every time i have to look it up. So this time i write it down, so hopefully it will be the last time i have to look it up.

form RPTASI00_FILL_VARIABLES_FROM_F filles the "SW_FUNC" fields dynamically (with assigns)
the table FIELDS that containes information on what field to set is saved on the cluster with the generated TM schema:

  perform clear_variables_from_fields.                     "note757356
  perform get_schema(rpuscgt0)
                    using vschema '1'
                          print sw-schema_update
                          space space
                          returncode.
  read table as-source with key schem = vschema.            "PH4K008260
  if returncode = 0.                                        "NOTE202647
    perform fill_variables_from_fields.                     "PH4K008260
  endif.     

And guess what: the fields table is filled in the generation of the TM schema and written with the generated schema directly to cluster PS.
Here a screen shot.




HTH
happy hacking
cheers

Thursday, February 2, 2012

Mastering the SAP PAL (HR_PAL_): Icons in the PAL application Log

If you want an icon to show up in a PAL log it is sufficient to create a text column (for example in your DDIC structure or in your field catalog). I used a TEXT30 data element.
Then you write one of the codes you find below  (the ones with @xx@ to the text field.
The result is in the picture below




This is really trivial, but useful to know!
Have fun

----- From the type pool "icon"
 
 
ICON_2 ICON_DUMMY                     '@00@'."  PlaceholderIcon
ICON_2 ICON_CHECKED                   '@01@'."  Checked; OK
ICON_2 ICON_INCOMPLETE                '@02@'."  Incomplete
ICON_2 ICON_FAILURE                   '@03@'."  Failed
ICON_2 ICON_POSITIVE                  '@04@'."  Positive
ICON_2 ICON_NEGATIVE                  '@05@'."  Negative
ICON_2 ICON_LOCKED                    '@06@'."  Locked
ICON_2 ICON_UNLOCKED                  '@07@'."  Free; unlock
ICON_4 ICON_GREEN_LIGHT               '@08@'."  Green light; positive
ICON_4 ICON_YELLOW_LIGHT              '@09@'."  Yellow light; neutral
ICON_4 ICON_RED_LIGHT                 '@0A@'."  Red light; negative
ICON_2 ICON_TOTAL_LEFT                '@0B@'."  Extreme left; first ...
ICON_2 ICON_TOTAL_RIGHT               '@0C@'."  Extreme right; last ...
ICON_2 ICON_COLUMN_LEFT               '@0D@'."  Column left; previous ..
ICON_2 ICON_COLUMN_RIGHT              '@0E@'."  Column right; next ...
ICON_2 ICON_PAGE_RIGHT                '@0F@'."  Page right
ICON_2 ICON_PAGE_LEFT                 '@0G@'."  Page left
ICON_2 ICON_PREVIOUS_VALUE            '@0H@'."  Previous value; next ent
ICON_2 ICON_NEXT_VALUE                '@0I@'."  Next value; previous ent
ICON_2 ICON_ANNOTATION                '@0J@'."  Note; remark
ICON_2 ICON_CREATE_NOTE               '@0K@'."  Create note
ICON_2 ICON_DISPLAY_NOTE              '@0L@'."  Display note
ICON_2 ICON_CALCULATION               '@0M@'."  Costing
ICON_2 ICON_GRAPHICS                  '@0N@'."  Graphics
ICON_2 ICON_CREATE_TEXT               '@0O@'."  Create text
ICON_2 ICON_DISPLAY_TEXT              '@0P@'."  Display text
ICON_2 ICON_CHANGE_TEXT               '@0Q@'."  Text
ICON_2 ICON_VARIANTS                  '@0R@'."  Variants
ICON_2 ICON_INFORMATION               '@0S@'."  Information
ICON_2 ICON_ADDRESS                   '@0T@'."  Address
ICON_2 ICON_VIEWER_OPTICAL_ARCHIVE    '@0U@'."  Optical archive viewer
ICON_2 ICON_OKAY                      '@0V@'."  OK; Continue; Choose
ICON_2 ICON_CANCEL                    '@0W@'."  Cancel
ICON_2 ICON_PRINT                     '@0X@'."  Print
ICON_2 ICON_CREATE                    '@0Y@'."  Create
ICON_2 ICON_CHANGE                    '@0Z@'."  Change
ICON_2 ICON_DISPLAY                   '@10@'."  Display
ICON_2 ICON_DELETE                    '@11@'."  Delete
ICON_2 ICON_TEST                      '@12@'."  Test
ICON_2 ICON_SEARCH                    '@13@'."  Find
ICON_2 ICON_COPY_OBJECT               '@14@'."  Copy