Object recursion (of sorts) fails on PERSDATA

'Mark Pyc' Mark.Pyc at bhint.com
Mon Mar 22 08:43:58 EST 2004


G'day WFers,
 
Disclaimer: My HR knowledge is limited - there may be a simple solution.
Release: Enterprise 620
 
I have a requirement to build a notification in HR when a user changes
their name through ESS. This message should include the following:
"This is to notify you that employee Staff no &P0002-PERNR& from
&P0001-ORGEH& has changed their name from {Previous ANRED Previous VORNA Previous NACHN} to &P0002-ANRED& &P0002-VORNA& &P0002-NACHN&. Please amend your records
accordingly."
 
To set this up I have used subtyped object PERSDATA. When I tested the
method 'FindPredecessor' in SWO1 it returned what I wanted. I then set up
virtual attributes for the pervious Form Of Address, First Name and Last
Name and in the implementation I tried initially to use a call to SELF for
the method.  When I tested the new attributes they were the same as the
current instance!?!?!
 
Debugging showed that the object reference returned by the method was the
same as the current object - D'oh!. Assuming this was a case of the BOR
not being real OO and failing to handle recursion (suspect incorrect use
of global memory variables) I took the code out of the method directly and
wrapped it in a function module (in an effort to get a new memory
allocation and prevent overwrite of global variables). This code is
included here for reference:
 
FUNCTION ZHR_PERSDATA_PREVIOUS2.
*"--------------------------------------------------------------------
*"*"Local interface:
*"       IMPORTING
*"             REFERENCE(I_OBJKEY) TYPE  SWOTOBJID-OBJKEY
*"       EXPORTING
*"             REFERENCE(O_FOA) TYPE  Q0002-ANREX
*"             REFERENCE(O_FIRSTNAME) TYPE  P0002-VORNA
*"             REFERENCE(O_LASTNAME) TYPE  P0002-NACHN
*"--------------------------------------------------------------------
  DATA:
    O_CURR TYPE SWC_OBJECT,
    O_PREV TYPE SWC_OBJECT,
    PREV_KEY TYPE SWOTOBJID-OBJKEY.
 
  SWC_CONTAINER L_CONT.
  SWC_CREATE_CONTAINER L_CONT.
 
** Instanciate Current Object
  SWC_CREATE_OBJECT O_CURR 'PERSDATA' I_OBJKEY.
 
** Determine Previous Instance
  SWC_CALL_METHOD O_CURR 'FindPredecessor' L_CONT.
  SWC_GET_ELEMENT L_CONT 'SingleObject' O_PREV.
 
** Retrieve Relevant Properties
  SWC_GET_PROPERTY O_PREV 'FormOfAddress' O_FOA.
  SWC_GET_PROPERTY O_PREV 'FirstName' O_FIRSTNAME.
  SWC_GET_PROPERTY O_PREV 'LastName' O_LASTNAME.
 
ENDFUNCTION.
 
Testing this in SWO1 now worked - proof of sorts that I was on the right
track. The real bummer is that when I now use this object in a workflow
the workitem text behaves as in the initial case - the "previous object"
reference returned is the same as the current and so the message says
"Employee has changed their name from NEW NAME to NEW NAME". When I
display the Work item, view the container and expand the object it has the
correct values for these attributes!?!?!
 
This is not a case of buffer refresh or incorrect expression references in
the task text.
 
I suspect if I used a method to return the variables it may work, but I
really need these values as attributes so they can be included in a Start
Condition. I realise I can code the read of these attributes myself rather
than using the SELF method call, but I'd really like it to work the way I
think it should.
 
Has anyone suffered a similar plight before??
 
Many thanks for any tips.
 
Have fun,
Mark
 


More information about the SAP-WUG mailing list