Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

doubt help SAP Library Objects

Former Member
0 Likes
659

I don´t understand the next paragraph (help SAP Library)

link sap library

Is there a error? CREF1 to

CREF3

?
If it could not be so,why CREF2?

"The effect of the assignment statement is to copy the reference from

CREF1 to CREF2

. As a result, the reference in CREF3 also points to the object C_COUNTER<1>. No more references point to the object C_COUNTER<2>, and it is automatically deleted by the garbage collection. The internal name C_COUNTER<2> is now free again."

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
634

escuse me, the link is :

<a href="http://help.sap.com/saphelp_nw70/helpdata/en/73/f6b832b3fd11d194f20000e8353423/content.htm">http://help.sap.com/saphelp_nw70/helpdata/en/73/f6b832b3fd11d194f20000e8353423/content.htm</a>

5 REPLIES 5
Read only

Former Member
0 Likes
635

escuse me, the link is :

<a href="http://help.sap.com/saphelp_nw70/helpdata/en/73/f6b832b3fd11d194f20000e8353423/content.htm">http://help.sap.com/saphelp_nw70/helpdata/en/73/f6b832b3fd11d194f20000e8353423/content.htm</a>

Read only

0 Likes
634

I think there isn't any error.

I have tried to explain this.

start-of-selection.

  CREATE OBJECT: cref1, cref2.
"  creates CREF1 .. value = {O:3*PROGRAM=ZTEST_NPCLASS=C1} - first reference
"  creates CREF2 .. vlaue = {O:4*PROGRAM=ZTEST_NPCLASS=C1} - second reference
"  CREF3 .. value = *** illegal reference ***

  move cref2 to cref3.
"  creates CREF1 .. value = {O:3*PROGRAM=ZTEST_NPCLASS=C1}
"  creates CREF2 .. vlaue = {O:4*PROGRAM=ZTEST_NPCLASS=C1}
"  CREF3 .. value = {O:4*PROGRAM=ZTEST_NPCLASS=C1}
" Values of the CREF3 has been set from CREF2 even if we have definition like DATA: cref3 like cref1.

  clear cref2.
" CREF2 .. VALUE = *** illegal reference ***  
" CREF3 .. VALUE = {O:4*PROGRAM=ZTEST_NPCLASS=C1}
" second reference is not yet free because CREF3 is holding that

  cref3 = cref1.
"  creates CREF1 .. value = {O:3*PROGRAM=ZTEST_NPCLASS=C1}
"  creates CREF2 .. VALUE = *** illegal reference ***  
"  CREF3 .. value = {O:3*PROGRAM=ZTEST_NPCLASS=C1}
" second reference is free now.. so, garbage collector will take care of it
  write: 'bye'.

Regards,

Naimesh Patel

Read only

0 Likes
634

Hi abapers,

thank you for you attention.

I have debuger the next code:

REPORT  zcu04_prueba.
CLASS counter DEFINITION.
 PUBLIC SECTION.
  DATA A TYPE I.
  METHODS: increment.

ENDCLASS.

CLASS counter IMPLEMENTATION.
 METHOD increment.
   A = A + 1.
 ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

 DATA: cref1  TYPE REF TO counter,
           cref2  TYPE REF TO counter,
           cref3  LIKE cref1.

1º):

cref1 = 0<>

cref2 = 0<>

cref3 = 0<>

CREATE OBJECT: cref1, cref2.

2º):

cref1 = 9

MOVE cref2 TO cref3.

3º):

cref1 = 9

CLEAR cref2.

4º):

cref1 = 9

cref3 = cref1.

4º):

cref1 = 9

http://help.sap.com/saphelp_nw70/helpdata/en/73/f6b832b3fd11d194f20000e8353423/content.htm

I don´t understand the next sentence (help SAP Library)

"

The effect of the assignment statement is to copy the reference from CREF1 to CREF2

. As a result, the reference in CREF3 also points to the object C_COUNTER<1>. No more references point to the object C_COUNTER<2>, and it is automatically deleted by the garbage collection. The internal name C_COUNTER<2> is now free again."

I don´t understand. I think that the sentence:

"

The effect of the assignment statement is to copy the reference from CREF1 to CREF3

is the correct.

Why it is no correct?

Thanks.

Cordial greetings

Read only

0 Likes
634

Hello Lopez

You are right. There is obviously a mistake in the description of the sample.

Regards

Uwe

Read only

uwe_schieferstein
Active Contributor
0 Likes
634

Hello Lopez

To clarify the question I have pasted the coding here:

DATA: cref1  TYPE REF TO c_counter,
          cref2  TYPE REF TO c_counter,
          cref3  LIKE CREF1.

CREATE OBJECT: cref1, cref2.  " 'pointers' for both instances exist

MOVE cref2 TO cref3.               " cref2 and cref3 point to the same instance

CLEAR cref2.                           " cref3 still filled -> still pointers to both instances exist

cref3 = cref1.                           " cref3 points no longer to instance<2> but instance<1>
                                              " Thus, there is no pointer to instance<2> anymore
                                              " instance<2> will be removed by garbage collector

Regards

Uwe