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

Changing methods or read-only attributes

Former Member
0 Likes
1,496

Hello,

i have to call a Method to change the 'NR'.

  call METHOD go_specific->SET_NR

The Method itself checks if i am in activity mode 01 .. so i'm NOT i'm in 03.. but i want to change the value.

Can i change the coding from the method oder can i simply change the md_activity variable?

Thanks for your help

Cheers

Stefan

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,149

Hello Stefan

Following is a sample report which provides a "solution" for your problem.

BUT: The logic of the factory class implies that the activity is set only once when the instance is created. The <b>INIT_BUS_OBJECT</b> method should not be called twice but this is up to you...

The sample report shows the transition from <b>display -> change </b>activity.

 *&---------------------------------------------------------------------*
*& Report  ZUS_SDN_REBD_RENTAL_OBJECT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_rebd_rental_object.


TYPE-POOLS: reca1, abap.

DATA:
  gs_detail           TYPE rebd_rental_object,
  go_rental_object    TYPE REF TO if_rebd_rental_object,
  go_bus_obj          TYPE REF TO if_reca_bus_object.



START-OF-SELECTION.

" Find rental object instance
  CALL METHOD cf_rebd_rental_object=>find
    EXPORTING
      id_bukrs       = '1000'
      id_swenr       = '00000001'
      id_smenr       = '00000011'
*      ID_ACTIVITY    = RECA1_ACTIVITY-DISPLAY
*      IF_AUTH_CHECK  = ABAP_FALSE
*      IF_ENQUEUE     = ABAP_TRUE
*      IF_USE_ARCHIVE = ABAP_TRUE
    RECEIVING
      ro_instance    = go_rental_object
    EXCEPTIONS
      error          = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


" Store details of rental object locally
  gs_detail = go_rental_object->ms_detail.

  WRITE: / 'Before =', go_rental_object->md_activity.

  go_bus_obj ?= go_rental_object.
" NOTE: <Only for Factory Methods> [Final] (Method Description)!!!
  CALL METHOD go_bus_obj->init_bus_object
    EXPORTING
      is_detail     = gs_detail
      id_activity   = reca1_activity-change
      if_auth_check = abap_false
      if_enqueue    = abap_false
      if_archived   = abap_false  " !!!
    EXCEPTIONS
      error         = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  WRITE: / 'After  =', go_rental_object->md_activity.

END-OF-SELECTION.

Regards

Uwe

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,149

Well, it would depend on what is allowed by the visibility of the attribute or method acting against the attribute. If there is a SETTER method and it is pubic, I guess you can call it, or if the attribute is public, you could simply change it directly, but it really depends on the class and what it is doing.

Regards

RIch Heilman

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,149

Hello Stefan

Check in your class (by the way: could you provide its name?) where the instance attribute MD_ACTIVITY is set. I would guess this happens at the level of the CONSTRUCTOR method. This would imply that there is no method available for changing this attribute.

If the attribute is <i>not public</i> or <i>public yet read-only</i> then you probably have no programmatic means to change its value (except using the debugger).

Regards

Uwe

Read only

0 Likes
1,149

Hi Uwe,

the attribute ist set by the method FIND from CF_REBD_RENTAL_OBJECT. This method only works in activity 02 or 03.

But i need to switch the md_activity to 01 to go on with my programm.

I also tried the same logic as you described:

data: go_specific_activity TYPE REF TO CL_RECA_STORABLE.
go_specific_activity ?= EO_BUSOBJ.
go_specific_activity->IF_RECA_STORABLE~MD_ACTIVITY = '01'.

But it's not allowed to change the read-only attribute out of the class.

Your assumption this morning was right - i'm in RE-fx

Cheers

stefan

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,150

Hello Stefan

Following is a sample report which provides a "solution" for your problem.

BUT: The logic of the factory class implies that the activity is set only once when the instance is created. The <b>INIT_BUS_OBJECT</b> method should not be called twice but this is up to you...

The sample report shows the transition from <b>display -> change </b>activity.

 *&---------------------------------------------------------------------*
*& Report  ZUS_SDN_REBD_RENTAL_OBJECT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_rebd_rental_object.


TYPE-POOLS: reca1, abap.

DATA:
  gs_detail           TYPE rebd_rental_object,
  go_rental_object    TYPE REF TO if_rebd_rental_object,
  go_bus_obj          TYPE REF TO if_reca_bus_object.



START-OF-SELECTION.

" Find rental object instance
  CALL METHOD cf_rebd_rental_object=>find
    EXPORTING
      id_bukrs       = '1000'
      id_swenr       = '00000001'
      id_smenr       = '00000011'
*      ID_ACTIVITY    = RECA1_ACTIVITY-DISPLAY
*      IF_AUTH_CHECK  = ABAP_FALSE
*      IF_ENQUEUE     = ABAP_TRUE
*      IF_USE_ARCHIVE = ABAP_TRUE
    RECEIVING
      ro_instance    = go_rental_object
    EXCEPTIONS
      error          = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


" Store details of rental object locally
  gs_detail = go_rental_object->ms_detail.

  WRITE: / 'Before =', go_rental_object->md_activity.

  go_bus_obj ?= go_rental_object.
" NOTE: <Only for Factory Methods> [Final] (Method Description)!!!
  CALL METHOD go_bus_obj->init_bus_object
    EXPORTING
      is_detail     = gs_detail
      id_activity   = reca1_activity-change
      if_auth_check = abap_false
      if_enqueue    = abap_false
      if_archived   = abap_false  " !!!
    EXCEPTIONS
      error         = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  WRITE: / 'After  =', go_rental_object->md_activity.

END-OF-SELECTION.

Regards

Uwe

Read only

0 Likes
1,149

Hi,

Thanks a lot!

do you know why my Object

go_rental_object

found by

METHOD cf_rebd_rental_object=>find

only knows his detail data and not all the other data like measures or characters?

Cheers

Stefan

Read only

0 Likes
1,149

Hello Stefan

Sure I know the answer to your questions since it is my job to know things like this.

RE-FX is basically OO-programming at its best.

<b>Question</b>: Should the rental object know details about its measurements?

<b>Answer</b>: No.

<b>Question</b>: Who Else?

<b>Answer</b>: The measurement mananger.

The rental object simply hold a reference to its measurements manager which can be retrieved using method GET_MEAS_MNGR. Thus, have a look at the following sample report (a modified version of the previously posted one):

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_REBD_RENTAL_OBJECT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_rebd_rental_object.


TYPE-POOLS: reca1, abap.

DATA:
  gs_detail         TYPE rebd_rental_object,
  go_rental_object  TYPE REF TO if_rebd_rental_object, " rental obj
  go_meas_mngr      TYPE REF TO if_rebd_meas_mngr,     " meas manager
  go_bus_obj        TYPE REF TO if_reca_bus_object.    " RE business obj

DATA:
  gt_measurements   TYPE re_t_rebd_meas.


START-OF-SELECTION.

  " Find rental object instance
  CALL METHOD cf_rebd_rental_object=>find
    EXPORTING
      id_bukrs       = '1000'
      id_swenr       = '00000001'
      id_smenr       = '00000011'
*      ID_ACTIVITY    = RECA1_ACTIVITY-DISPLAY
*      IF_AUTH_CHECK  = ABAP_FALSE
*      IF_ENQUEUE     = ABAP_TRUE
*      IF_USE_ARCHIVE = ABAP_TRUE
    RECEIVING
      ro_instance    = go_rental_object
    EXCEPTIONS
      error          = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  " Store details of rental object locally
  gs_detail = go_rental_object->ms_detail.

  WRITE: / 'Before =', go_rental_object->md_activity.

  go_bus_obj ?= go_rental_object.
  " NOTE: <Only for Factory Methods> [Final] (Method Description)!!!
  CALL METHOD go_bus_obj->init_bus_object
    EXPORTING
      is_detail     = gs_detail
      id_activity   = reca1_activity-change
      if_auth_check = abap_false
      if_enqueue    = abap_false
      if_archived   = abap_false  " !!!
    EXCEPTIONS
      error         = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  WRITE: / 'After  =', go_rental_object->md_activity.


* In order to get measurements you have to ask for the measure manager:
  go_meas_mngr ?= go_rental_object->get_meas_mngr( ).
  CHECK ( go_meas_mngr IS BOUND ).

  CALL METHOD go_meas_mngr->get_list
*    EXPORTING
*      IF_FIX_PERIODS     = ABAP_TRUE
*      IF_HIERARCHY       = ABAP_FALSE
*      IF_LAST_OK         = ABAP_FALSE
*      IF_CURRENT_BY_ARCH = ABAP_FALSE
    IMPORTING
      et_list            = gt_measurements.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_structure_name = 'REBD_MEAS'
      i_grid_title     = 'Measurements'
    TABLES
      t_outtab         = gt_measurements
    EXCEPTIONS
      program_error    = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

END-OF-SELECTION.

Let's make a simple quiz:

<b>Question</b>: Who knows the conditions for a rental object?

<b>Answer</b>: Yes, the <i>condition manager</i> (method GET_CONDITION_MNGR).

<b>Question</b>: Who knows the business partners of a rental object?

<b>Answer</b>: Yes, the <i>partner manager</i> (method GET_PARTNER_MNGR).

A final remark: if you have understood this principle you will easily find the right method to retrieve a "manager" instance.

<u><b>Knowing this you have understood OO-programming in RE-FX in its entirety!</b></u>

Regards

Uwe

Read only

0 Likes
1,149

Hi Uwe,

Thanks for Help again.

I tried your coding but i don't get any measures from the mngr...

it's bound but empty. my source-object has some.

But why? The result is the same with every manager i tried.

DATA: 
        go_meas_mngr        TYPE REF TO   if_rebd_meas_mngr,
        go_RESUBM_RULE_MNGR TYPE REF TO   IF_RECA_RESUBM_RULE_MNGR,
        go_CHARACT_MNGR     type REF TO IF_REBD_CHARACT_MNGR.


go_meas_mngr ?= go_rental_object->get_meas_mngr( ).
go_RESUBM_RULE_MNGR ?= go_rental_object->GET_RESUBM_RULE_MNGR( ).
go_CHARACT_MNGR ?= go_rental_object->GET_CHARACT_MNGR( ).

Read only

0 Likes
1,149

Hello Stefan

Difficult to say where the problem is localized. I developed this sample report on our ECC 5.0 IDES system where I used an existing rental unit having several measurements.

I could imagine that it is a <b>customizing </b>problem. You could try and debug the instantiation of the measurement manager. Somewhere within its CONSTRUCTOR method there should be a (private or protected) method call which reads the measurements.

Perhaps you could try a more specific measurement manager like CL_REBD_MEAS_MNGR_RO.

Regards & Good Luck

Uwe

Read only

0 Likes
1,149

Good Morning Uwe,

thank you. I work on an ecc 5.0 ides too.

i found the error.

The managers only works with objects in change mode. In my code i changed mode to create.

cheers

Stefan.