Persistent Objects: A Quick Reference

...Previous

While adding the field INST_GUID choose the assignment type as Object reference and for the attribute type specify the class name for e.g. ZCL_PERSIST_03 

 

To assign a class indicator, select the corresponding table field of type OS_GUID by double-clicking. Enter the name of the reference attribute for the attribute name. 

 

Screen looks like below. Press Save. 

Activate the Class. Press the Yes Button to activate the class actor as well.

 

Write a Program to create the persistent object. 

Source Code excerpt:
DATA: AGENT TYPE REF TO ZCA_PERSIST_03,
      STUDENT TYPE REF TO ZCL_PERSIST_03,
      REF1 TYPE REF TO OBJECT.
DATA: SNO LIKE ZSTUDENT04-SNO VALUE '1000',
      SNAME LIKE ZSTUDENT04-SNAME VALUE 'HAKIM',
      MARK1 LIKE ZSTUDENT04-MARK1 VALUE '100',
      MARK2 LIKE ZSTUDENT04-MARK2 VALUE '100'.
AGENT = ZCA_PERSIST_03=>AGENT.
TRY.
CALL METHOD AGENT->CREATE_PERSISTENT
  EXPORTING
*    I_INST_GUID =
    I_MARK1     = MARK1
    I_MARK2     = MARK2
    I_SNAME     = SNAME
    I_SNO       = SNO
*  RECEIVING
*    RESULT      =
    .
 COMMIT WORK.
 CATCH CX_OS_OBJECT_EXISTING .
ENDTRY.

Go to SE16 and check the entries.

 

Store the Persistent Object Reference in the database.

Source Code excerpt.
TRY.
CALL METHOD AGENT->IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_OID
  EXPORTING
    I_OID  = '30EA9E25999F0843BE6F7B86063F2916'
  RECEIVING
    RESULT = REF1
    .
 CATCH CX_OS_OBJECT_NOT_FOUND .
 CATCH CX_OS_CLASS_NOT_FOUND .
ENDTRY.
STUDENT ?= REF1.
STUDENT->SET_INST_GUID( STUDENT ).
COMMIT WORK.

Go to SE16 and check the entries. 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image