Application Development 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: 

How to access the content of texts collection of a BOPF object?

S0024047324
Discoverer
0 Kudos

I have created a BO holding this structure:

where "TEXTS" is a delegated object of type /BOBF/TEXT_COLLECTION, aiming to store long texts.

This object also holds a transient attribute named "Description" which I intent to fill up with on the object loading using a "Detemination".

In the method "Execute" of the class that implements this Determination, up to now, I have coded this:

  METHOD /bobf/if_frw_determination~execute.
    DATA: lt_key   TYPE /bobf/t_frw_key,
          lt_texts TYPE /bobf/t_txc_con_k.

    TRY.
        DATA(lr_conf) = /bobf/cl_frw_factory=>get_configuration( iv_bo_key = is_ctx-bo_key  ).
*                        CATCH /bobf/cx_frw. " BOPF Exception Class
      CATCH /bobf/cx_frw.
        RETURN.
    ENDTRY.


    DATA(l_assoc_key) = lr_conf->get_content_key_mapping(
                                EXPORTING
                                  iv_content_cat      =  /bobf/if_conf_c=>sc_content_asso                               " Entity Category
*                                  iv_host_content_key =                  " NodeID
                                  iv_do_content_key   =  /bobf/if_txc_c=>sc_association-root-text_content             "NodeID
                                  iv_do_root_node_key =  zif_bo_ppm_survey_c=>sc_node-texts                           " DO Root Node from Host View
                              ).


    lr_conf->get_node_tab(
      IMPORTING
        et_node = DATA(lt_nodes)  " Configuration: Node
    ).
    READ TABLE lt_nodes ASSIGNING FIELD-SYMBOL(<ls_node>) WITH KEY node_name = 'TEXT'.
    IF sy-subrc <> 0.
      RETURN.
    ELSE.
      APPEND INITIAL LINE TO lt_key ASSIGNING FIELD-SYMBOL(<ls_key>).
      <ls_key>-key = <ls_node>-node_key.
    ENDIF.


    io_read->retrieve_by_association(
      EXPORTING
        iv_node                 = zif_bo_ppm_survey_c=>sc_node-texts                 " Node Name
        it_key                  = lt_key            " Key Table
        iv_association          = l_assoc_key       " Name of Association
*        is_parameters           =
*        it_filtered_attributes  =                  " List of Names (e.g. Fieldnames)
        iv_fill_data            = abap_true         " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ")
*        iv_before_image         = abap_false       " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ")
*        it_requested_attributes =                  " List of Names (e.g. Fieldnames)
      IMPORTING
*        eo_message              =                  " Message Object
        et_data                 = lt_texts          " Data Return Structure
*        et_key_link             =                  " Key Link
*        et_target_key           =                  " Key Table
*        et_failed_key           =                  " Key Table
    ).

  ENDMETHOD.

Only the logic for retrieving the text content have been implemented. I still have to code the part that updates de transient attribute, to which I intent to use the io_modify object. However the first part is not working. Would you please help me undertanding why?

I have created an instance that do holds a text, and the testing framework exhibts it succesfully:

But I cannot get it in the Determination.

1 REPLY 1

S0024047324
Discoverer
0 Kudos

I solved this issue. This is the code for that:

  METHOD /bobf/if_frw_determination~execute.
    DATA: lr_text_data      TYPE REF TO data,
          lr_texts          TYPE REF TO data,
          lr_data           TYPE REF TO zppms009,
          lt_changed_fields TYPE /bobf/t_frw_name.
    FIELD-SYMBOLS: <lt_text_data> TYPE ANY TABLE,
                   <lt_texts>     TYPE ANY TABLE.

* Traverse to the ROOT_TEXT node to get the texts
    DATA(lr_serv) = /bobf/cl_tra_serv_mgr_factory=>get_service_manager(
                      iv_bo_key                     = zif_bo_ppm_survey_c=>sc_bo_key
*                      iv_create_sync_notifications  = abap_false
*                      iv_create_assoc_notifications = abap_false
*                      iv_create_prop_notifications  = abap_false
                    ).

* -- RETRIEVE_BY_ASSOCIATION - 1.  ROOT to TEXTS
    lr_serv->retrieve_by_association(
      EXPORTING
        iv_node_key             = zif_bo_ppm_survey_c=>sc_node-root  " Node
        it_key                  = it_key                             " Key Table
        iv_association          = zif_bo_ppm_survey_c=>sc_association-root-texts                       " Association
*        is_parameters           =
*        it_filtered_attributes  =
*        iv_fill_data            = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_before_image         = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_invalidate_cache     = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_edit_mode            = /bobf/if_conf_c=>sc_edit_read_only " Change Mode
*        it_requested_attributes =                                    " List of Names (e.g. Fieldnames)
      IMPORTING
        eo_message              =  eo_message                        " Interface of Message Object
*        eo_change               =  lr_change                        " Interface of Change Object
*        et_data                 =  <lt_texts>
*        et_key_link             =  DATA(lt_key_link)                " Key Link
        et_target_key           =  DATA(lt_texts_key)                " --Retrieved key of TEXTS
        et_failed_key           = et_failed_key                      " Key Table
    ).
* -- RETRIEVE_BY_ASSOCIATION - 2.  TEXTS to TEXT
    "Helper method to fetch node and keys
    TRY.
        DATA(lr_conf) = /bobf/cl_frw_factory=>get_configuration( iv_bo_key = zif_bo_ppm_survey_c=>sc_bo_key  ).
*                        CATCH /bobf/cx_frw. " BOPF Exception Class
      CATCH /bobf/cx_frw INTO DATA(lx_error).
        RAISE EXCEPTION lx_error.
    ENDTRY.

    /scmtms/cl_common_helper=>get_do_keys_4_rba(
      EXPORTING
        iv_host_bo_key      =    zif_bo_ppm_survey_c=>sc_bo_key
        iv_host_do_node_key =    zif_bo_ppm_survey_c=>sc_node-texts
        iv_do_node_key      =    /bobf/if_txc_c=>sc_node-text
        iv_do_assoc_key     =    /bobf/if_txc_c=>sc_association-root-text
      IMPORTING
        ev_node_key         =    DATA(l_text_node_key)
        ev_assoc_key        =    DATA(l_text_assoc_key)
    ).

    "Lookup the association metadata to find out more
    "information about the TEXT sub-node:
    lr_conf->get_assoc(
      EXPORTING
        iv_assoc_key = l_text_assoc_key
        iv_node_key  = l_text_node_key
      IMPORTING
        es_assoc     = DATA(ls_text_association) ).
    IF ls_text_association-target_node IS NOT BOUND.
      RAISE EXCEPTION TYPE /bobf/cx_dac.
    ENDIF.
    "Use the node configuration metadata to create the result table:
    CREATE DATA lr_text_data TYPE (ls_text_association-target_node->data_table_type).
    ASSIGN lr_text_data->* TO <lt_text_data>.

    lr_serv->retrieve_by_association(
      EXPORTING
        iv_node_key             = zif_bo_ppm_survey_c=>sc_node-texts  " Node
        it_key                  = lt_texts_key                        " Key Table
        iv_association          = l_text_assoc_key                    " Association
*        is_parameters           =
*        it_filtered_attributes  =
        iv_fill_data            = abap_true                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_before_image         = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_invalidate_cache     = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_edit_mode            = /bobf/if_conf_c=>sc_edit_read_only " Change Mode
*        it_requested_attributes =                                    " List of Names (e.g. Fieldnames)
      IMPORTING
        eo_message              =  eo_message                        " Interface of Message Object
*        eo_change               =  lr_change                        " Interface of Change Object
        et_data                 =  <lt_text_data>
*        et_key_link             =  DATA(lt_key_link)                 " Key Link
        et_target_key           = DATA(lt_text_key)                   " --Retrieved key of TEXT (DO)
        et_failed_key           = et_failed_key                       " Key Table
    ).
* -- RETRIEVE_BY_ASSOCIATION - 3.  TEXT to TEXT_CONTENT
    "Helper method to fetch node and keys
    /scmtms/cl_common_helper=>get_do_keys_4_rba(
      EXPORTING
        iv_host_bo_key      =    zif_bo_ppm_survey_c=>sc_bo_key
        iv_host_do_node_key =    zif_bo_ppm_survey_c=>sc_node-texts
        iv_do_node_key      =    /bobf/if_txc_c=>sc_node-text_content
        iv_do_assoc_key     =    /bobf/if_txc_c=>sc_association-text-text_content
      IMPORTING
        ev_node_key         =    DATA(l_content_node_key)
        ev_assoc_key        =    DATA(l_content_assoc_key) ).

    "Lookup the association metadata to find out more
    "information about the TEXT_CONTENT sub-node:
    lr_conf->get_assoc(
      EXPORTING
        iv_assoc_key = l_content_assoc_key
        iv_node_key  = l_content_node_key
      IMPORTING
        es_assoc     = DATA(ls_content_association) ).
    IF ls_content_association-target_node IS NOT BOUND.
      RAISE EXCEPTION TYPE /bobf/cx_dac.
    ENDIF.

    "Use the node configuration metadata to create the result table:
    CREATE DATA lr_texts TYPE (ls_content_association-target_node->data_table_type).
    ASSIGN lr_texts->* TO <lt_texts>.

    lr_serv->retrieve_by_association(
      EXPORTING
        iv_node_key             = l_text_node_key                     " Node
        it_key                  = lt_text_key                         " Key Table
        iv_association          = l_content_assoc_key                 " Association
*        is_parameters           =
*        it_filtered_attributes  =
        iv_fill_data            = abap_true                           " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_before_image         = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_invalidate_cache     = abap_false                         " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
*        iv_edit_mode            = /bobf/if_conf_c=>sc_edit_read_only " Change Mode
*        it_requested_attributes =                                    " List of Names (e.g. Fieldnames)
      IMPORTING
        eo_message              =  eo_message                        " Interface of Message Object
*        eo_change               =  lr_change                        " Interface of Change Object
        et_data                 =  <lt_texts>                        " Text content
        et_key_link             = DATA(lt_key_link)                 " Key Link
        "et_target_key           = DATA(lt_target_key)                " Key Table
        et_failed_key           = et_failed_key                      " Key Table
    ).

* Updating transient texts
    LOOP AT <lt_texts> ASSIGNING FIELD-SYMBOL(<ls_text>).
      ASSIGN COMPONENT 'PARENT_KEY' OF STRUCTURE <ls_text> TO FIELD-SYMBOL(<l_parent_key>).
      IF <l_parent_key> IS ASSIGNED.
        LOOP AT <lt_text_data> ASSIGNING FIELD-SYMBOL(<ls_text_data>).
          ASSIGN COMPONENT 'LANGUAGE_CODE' OF STRUCTURE <ls_text_data> TO FIELD-SYMBOL(<l_language>).
          IF <l_language> IS NOT ASSIGNED.
            CONTINUE.
          ELSEIF <l_language> <> cl_abap_syst=>get_language( ).
            CONTINUE.
          ENDIF.
          ASSIGN COMPONENT 'KEY' OF STRUCTURE <ls_text_data> TO  FIELD-SYMBOL(<l_key>).
          IF <l_key> IS ASSIGNED.
            IF <l_key> = <l_parent_key>.
              ASSIGN COMPONENT 'TEXT_TYPE' OF STRUCTURE <ls_text_data> TO FIELD-SYMBOL(<l_text_type>).
              IF <l_text_type> IS ASSIGNED.
                READ TABLE it_key  ASSIGNING FIELD-SYMBOL(<ls_key>) INDEX 1.
                IF sy-subrc = 0.
                  IF lr_data IS NOT BOUND.
                    CREATE DATA lr_data.
                  ENDIF.
                  ASSIGN COMPONENT 'TEXT' OF STRUCTURE <ls_text> TO FIELD-SYMBOL(<l_text>).
                  IF <l_text> IS ASSIGNED.
                    CASE <l_text_type>.
                      WHEN zif_ppm_survey=>sc_text-generic_type OR zif_ppm_survey=>sc_text-survey_title_type.
                        lr_data->title = <l_text>.
                        APPEND 'TITLE' TO lt_changed_fields.
                      WHEN zif_ppm_survey=>sc_text-survey_description_type.
                        lr_data->description = <l_text>.
                        APPEND 'DESCRIPTION' TO lt_changed_fields.
                    ENDCASE.
                  ENDIF.
                ENDIF.
              ELSE.
                EXIT.
              ENDIF.
            ENDIF.
          ELSE.
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDLOOP.

    IF lt_changed_fields IS NOT INITIAL AND lr_data IS BOUND.
      lr_data->language = cl_abap_syst=>get_language( ).
      APPEND 'LANGUAGE' TO lt_changed_fields.
      io_modify->update(
        EXPORTING
          iv_node           = zif_bo_ppm_survey_c=>sc_node-root  " Node
          iv_key            = <ls_key>-key                       " Key
*                            iv_root_key       =                                   " NodeID
          is_data           = lr_data                            " Data
          it_changed_fields = lt_changed_fields                  " List of Names (e.g. Fieldnames)
      ).
    ENDIF.
  ENDMETHOD.