BOPF Development
April 6, 2019

  1. Design / Prototype
  2. Create Dictionary Objects
  3. Create Interface View (CDS)
  4. Business Object Generation (CDS – Object Model Annotations )
  5. Generated Business Object
  6. BOPF – Development
    • Determination
    • Validation
    • Action
    • Alternative Key
  7. Test BOPF Object using BOBT
  8. Access Control (CDS)
  9. Consumption View (CDS)
  10. OData Service Generation and Registration
  11. Test OData Service using SAP Gateway Client
  12. UI development

As per Phone Book Application requirement, we will develop following:

  1. Determinations
    • GENERATE_PBID: Generate Phone Book ID
    • UPDATE_H_ADMIN: Update Creation and Change timestamp.
    • UPDATE_I_ADMIN: Update Creation and Change timestamp.
  2. Validations
    • CHECK_EMAIL: Validate E-Mail ID
    • CHECK_TELENO: Validate Telephone Number
  3. Actions
    • COPY: Copy or Duplicate the selected contact
  4. Alternative Keys
    • PB_ID: Phone Book ID as alternate key

Determinations

Generate Phone Book ID

This determination will generate next Phone Book ID in series and update the same to buffer.

Step 1: Navigate to Business Object >> Go To Root Node >> Select Determinations Tab at the bottom or Click on Determinations Link on the Side.

  1. Once you are in Determinations Tab then click on New to create a determination.
  2. Based on Name system will propose Implementation Class, but you can change the class name or re-generate the proposal.
  3. Click on Finish
  4. Save and Activate

Step 2: Click on Triggers Configured or you can double click on the new determination from Outline View or you can select the new determination from Node, to further configure it.

Step 3: In determination configuration, you can see that determination will be executed After Modification, it is associated with Header Node, and is only triggered for Create and Update action. As there is no need to generate new Phone Book ID for Delete action.

Step 4: If it is required, you can mention dependencies in ‘Dependency’ tab of determination configuration view. This will ensure that dependent determinations will be executed before this determination. Other than this there no control on the sequence of determination execution. Best practice suggests that there should not be any inter-dependent determinations.

Step 5: As soon as the determination is activated, the implementation class is auto-generated with the necessary interface. Navigate to the class.

Step 6: Implement the business logic for the Determination in the method Execute.

*----------------------------------------------------------------------*
* Method Name                : /BOBF/IF_FRW_DETERMINATION~EXECUTE
* Method description         : Generate Phone Book ID
*----------------------------------------------------------------------*
  METHOD /bobf/if_frw_determination~execute.
    " Internal tab for Header Data
    " Created using reference to Generated Table Type
    DATA(lt_head) = VALUE zt2812_i_pb_head_nd( ).

    " Get Phone Book Head Data
    io_read->retrieve(
      EXPORTING
        iv_node                 = is_ctx-node_key " Node Name
        it_key                  = it_key          " Key Table
      IMPORTING
        et_data                 = lt_head         " Data Return Struct.
    ).

    " For Each Node Instance
    LOOP AT lt_head REFERENCE INTO DATA(lr_head).
      IF lr_head->pb_id IS INITIAL. " Phone Book ID is Initial
        " Generate Phone Book ID
        CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            nr_range_nr      = zif_2812_pb_global=>gc_nr_pb_intrvl
            object           = zif_2812_pb_global=>gc_nr_pb_id
          IMPORTING
            number           = lr_head->pb_id
          EXCEPTIONS
            interval_not_found      = 1
            number_range_not_intern = 2
            object_not_found        = 3
            quantity_is_0           = 4
            quantity_is_not_1       = 5
            interval_overflow       = 6
            buffer_overflow         = 7
            OTHERS                  = 8.
        IF sy-subrc EQ 0.
          lr_head->pb_owner = sy-uname.
          GET TIME STAMP FIELD DATA(lv_timestamp).
          lr_head->pb_created_at = lv_timestamp.
          lr_head->pb_changed_at = lv_timestamp.
        ELSE.
          " Phone Book ID is marked as mandatory
          " Framework will throw error if it is not supplied
        ENDIF.

        io_modify->update(
          EXPORTING
            iv_node           = is_ctx-node_key       " Node
            iv_key            = lr_head->key          " Key
            is_data           = lr_head               " Data
        ).
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

Update Header Admin Data

This determination will update ‘Created At’ and ‘Changed At’ timestamp.

Using the above steps create determination UPDATE_H_ADMIN, it will be triggered ‘After Modify’, it is associated with Header Node, it is enabled for action Create and Update.

Business Logic

*----------------------------------------------------------------------*
* Method Name                : /BOBF/IF_FRW_DETERMINATION~EXECUTE
* Method description         : Update Admin Head Data
*----------------------------------------------------------------------*
  METHOD /bobf/if_frw_determination~execute.
    " Internal tab for Header Data
    " Created using reference to Generated Table Type
    DATA(lt_head) = VALUE zt2812_i_pb_head_nd( ).

    " Get Phone Book Head Data
    io_read->retrieve(
      EXPORTING
        iv_node                 = is_ctx-node_key " Node Name
        it_key                  = it_key          " Key Table
      IMPORTING
        et_data                 = lt_head         " Data Ret. Struct.
    ).

    LOOP AT lt_head REFERENCE INTO DATA(lr_head).
      GET TIME STAMP FIELD DATA(lv_timestamp).
      lr_head->pb_changed_at = lv_timestamp.

      " Update Data to Node
      io_modify->update(
        EXPORTING
          iv_node           = is_ctx-node_key       " Node
          iv_key            = lr_head->key          " Key
          is_data           = lr_head               " Data
      ).
    ENDLOOP.
  ENDMETHOD.

Update Item Admin Data

This determination will update ‘Created At’ and ‘Changed At’ timestamp.

Step 1: Navigate to Business Object >> Go To Root Node >>Select Item Node.

Step 2: Select Determinations Tab at the bottom or Click on Determinations Link on Side

Using remaining steps from GENERATE_PBID determination, create determination UPDATE_I_ADMIN, it will be triggered ‘After Modify’, it is associated with Header Node, it is enabled for action Create and Update.

Business Logic

*----------------------------------------------------------------------*
* Method Name                : /BOBF/IF_FRW_DETERMINATION~EXECUTE
* Method description         : Update Admin Item Data
*----------------------------------------------------------------------*
  METHOD /bobf/if_frw_determination~execute.

    " Internal tab for Item Data
    " Created using reference to Generated Table Type
    DATA(lt_item) = VALUE zt2812_i_pb_item_nd( ).

    " Get Item Data
    io_read->retrieve(
      EXPORTING
        iv_node                 = is_ctx-node_key  " Node Name
        it_key                  = it_key           " Key Table
      IMPORTING
        et_data                 = lt_item          " Data Ret. Struct.
    ).

    " For Each Node Instance
    LOOP AT lt_item REFERENCE INTO DATA(lr_item) .
      GET TIME STAMP FIELD DATA(lv_timstmp).
      IF lr_item->pb_created_at IS INITIAL.
        lr_item->pb_created_at = lv_timstmp.       " Created At
      ENDIF.


      lr_item->pb_changed_at = lv_timstmp.         " Last Changed At

      " Update Data to Node
      io_modify->update(
        EXPORTING
          iv_node           = is_ctx-node_key      " Node
          iv_key            = lr_item->key         " Key
          is_data           = lr_item              " Data
      ).

    ENDLOOP.
  ENDMETHOD.

<< Development List


Validations

CHECK_EMAIL

This will validate the E-Mail address

Step 1: Navigate to Business Object >> Go To Root Node >> Select Validations Tab at the bottom or Click on Validations Link on Side.

  1. Once you are in Validations Tab then click on New to create a validation.
  2. Based on Name system will propose Implementation Class, but you can change the class name or re-generate the proposal.
  3. Click on Finish
  4. Save and Activate

Step 2: Click on Triggers Configured or you can double click on the new validation from Outline View or you can select the new validation from Node, to further configure it.

In the validation configuration, you can see that validation is associated with consistency check, Header Node, and is only triggered for Create and Update action. As there is no need to validate on the Delete action.

Step 3: As soon as the validation is activated, the implementation class is auto-generated with the necessary interface. Navigate to the class.

Step 4: Implement the business logic for the Validation in the method Execute.

*----------------------------------------------------------------------*
* Method Name                : /BOBF/IF_FRW_VALIDATION~EXECUTE
* Method description         : Validate E-Mail Adress
*----------------------------------------------------------------------*
  METHOD /bobf/if_frw_validation~execute.
    " Internal tab for Header Data
    " Created using reference to Generated Table Type
    DATA(lt_head) = VALUE zt2812_i_pb_head_nd( ).

    " Get Phone Book Head Data
    io_read->retrieve(
      EXPORTING
        iv_node                 = is_ctx-node_key " Node Name
        it_key                  = it_key          " Key Table
      IMPORTING
        et_data                 = lt_head         " Data Return Structure
    ).

    " Instantiate Message Object
    IF eo_message IS NOT BOUND.
      eo_message = /bobf/cl_frw_factory=>get_message( ).
    ENDIF.

    LOOP AT lt_head REFERENCE INTO DATA(lr_head).
      " Validate
      me->validate_email(
        EXPORTING
          iv_emailid = lr_head->pb_email_id  " Email Address
        IMPORTING
          es_msg     = DATA(ls_msg)          " Structure of message
      ).

      " Add Message
      IF NOT ls_msg IS INITIAL.
        eo_message->add_message(
          EXPORTING
            is_msg       = ls_msg            " Message
            iv_node      = is_ctx-node_key   " Node 
            iv_key       = lr_head->key      " Instance key 
        ).
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

CHECK_TELENO

This will validate the the telephone number

Step 1: Navigate to Business Object >> Go To Root Node >>Select Item Node.

Step 2: Select Validations Tab at the bottom or Click on Validations Link on Side

Using remaining steps from CHECK_EMAIL validation and create validation CHECK_TELENO, it is associated with Header Node, consistency check and it is enabled for the action Create and Update.

Business Logic

*----------------------------------------------------------------------*
* Method Name                : /BOBF/IF_FRW_VALIDATION~EXECUTE
* Method description         : Validate Telephone#
*----------------------------------------------------------------------*
  METHOD /bobf/if_frw_validation~execute.
    " Internal tab for Item Data
    " Created using reference to Generated Table Type
    DATA(lt_item) = VALUE zt2812_i_pb_item_nd( ).

    " Get Phone Book Head Data
    io_read->retrieve(
      EXPORTING
        iv_node                 = is_ctx-node_key " Node Name
        it_key                  = it_key          " Key Table
      IMPORTING
        et_data                 = lt_item         " Data Return Structure
    ).

    " Instantiate Message Object
    IF eo_message IS NOT BOUND.
      eo_message = /bobf/cl_frw_factory=>get_message( ).
    ENDIF.

    LOOP AT lt_item REFERENCE INTO DATA(lr_item).
      " Validate
      me->validate_teleno(
        EXPORTING
          iv_telephone = lr_item->pb_telephone  " Telephone#
        IMPORTING
          es_msg     = DATA(ls_msg)             " Structure of message
      ).

      " Add Message
      IF NOT ls_msg IS INITIAL.
        eo_message->add_message(
          EXPORTING
            is_msg       = ls_msg            " Message
            iv_node      = is_ctx-node_key   " Node
            iv_key       = lr_item->key      " Instance
        ).
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

Validation has to be associated with the consistency group. A consistency group is executed before save and prevent it in case of errors, this way we do not need the same validations as ASction Validation again.

In ADT based BOPF development, consistency group is auto created as soon as validation is activated. For this scenario, Z2812_I_PB_HEAD_ND (SAVE_PREVENTION) is generated.

Validations from both nodes are assigned to same consistency group.

<< Development List


Actions

COPY

This will copy the selected phone book contacts.

Step 1: Navigate to Business Object >> Go To Root Node >> Select Actions Tab at the bottom or Click on Actions Link on Side.

  1. Once you are in Validations Tab then click on New to create an action.
  2. Based on Name system will propose Implementation Class, but you can change the class name or re-generate the proposal.
  3. Click on Finish
  4. Save and Activate

Step 2: As soon as action is activated the associated implemented class is generated with the necessary interface, if it does not exists. Navigate to the class.

Step 3: Implement the business logic in the method Execute.

*----------------------------------------------------------------------*
* Method Name                : /BOBF/IF_FRW_ACTION~EXECUTE
* Method description         : Copy Order request
*----------------------------------------------------------------------*
  METHOD /bobf/if_frw_action~execute.
    DATA: lr_head_copy TYPE REF TO data,
          lr_item_copy TYPE REF TO data.

    " Internal tab for Header & Item Data
    " Created using reference to Generated Table Type
    DATA(lt_head) = VALUE zt2812_i_pb_head_nd( ).
    DATA(lt_item) = VALUE zt2812_i_pb_item_nd( ).

    " Get Phone Book Head Data
    io_read->retrieve(
      EXPORTING
        iv_node                 = is_ctx-node_key " Node Name
        it_key                  = it_key          " Key Table
      IMPORTING
        et_data                 = lt_head         " Data Return Structure
    ).

    " Get Phone Book Item Data
    io_read->retrieve_by_association(
      EXPORTING
        iv_node                 = is_ctx-node_key  " Node Name
        it_key                  = it_key           " Key Table
        iv_association          = zif_2812_i_pb_head_nd_c=>sc_association-z2812_i_pb_head_nd-_itemdata " Name of Association
        iv_fill_data            = abap_true
      IMPORTING
        et_data                 = lt_item          " Data Return Structure
    ).

    " For Each Node Instance
    LOOP AT lt_head REFERENCE INTO DATA(lr_head).
      ASSIGN lr_head->* TO FIELD-SYMBOL(<fs_head>).

      " Create Copy of Head
      DATA(ls_head_copy) = VALUE zs2812_i_pb_head_nd( ).
      ls_head_copy-pb_email_id   = <fs_head>-pb_email_id.
      ls_head_copy-pb_first_name = <fs_head>-pb_first_name.
      ls_head_copy-pb_last_name  = <fs_head>-pb_last_name.


      " Create Data Ref to Copy of Head
      CREATE DATA lr_head_copy TYPE zs2812_i_pb_head_nd.
      ASSIGN lr_head_copy->* TO FIELD-SYMBOL(<fs_head_copy>).
      IF <fs_head_copy> IS ASSIGNED.
        <fs_head_copy> = ls_head_copy.
      ENDIF.

      " Create New Phone Book Entry
      io_modify->create(
        EXPORTING
          iv_node            =  is_ctx-node_key             " Node to Create
          is_data            =  lr_head_copy                " Data
        IMPORTING
          ev_key             = DATA(lv_pb_copy_key)
      ).

      LOOP AT lt_item REFERENCE INTO DATA(lr_item) WHERE parent_key = lr_head->key.
        ASSIGN lr_item->* TO FIELD-SYMBOL(<fs_item>).

        " Create Copy of Item
        DATA(ls_item_copy) = VALUE zs2812_i_pb_item_nd( ).
        ls_item_copy-pb_category  = <fs_item>-pb_category.
        ls_item_copy-pb_telephone = <fs_item>-pb_telephone.

        " Create Reference to Item Copy
        CREATE DATA lr_item_copy TYPE zs2812_i_pb_item_nd.
        ASSIGN lr_item_copy->* TO FIELD-SYMBOL(<fs_item_copy>).
        IF <fs_item_copy> IS ASSIGNED.
          <fs_item_copy> = ls_item_copy.
        ENDIF.

        io_modify->create(
          EXPORTING
            iv_node            =  zif_2812_i_pb_head_nd_c=>sc_node-z2812_i_pb_item_nd                  " Node to Create
            is_data            =  lr_item_copy                                                         " Data
            iv_assoc_key       =  zif_2812_i_pb_head_nd_c=>sc_association-z2812_i_pb_head_nd-_itemdata " Association
            iv_source_node_key =  zif_2812_i_pb_head_nd_c=>sc_node-z2812_i_pb_head_nd                  " Parent Node
            iv_source_key      =  lv_pb_copy_key                                                       " NodeID of Parent Instance
        ).
      ENDLOOP.
    ENDLOOP.
  ENDMETHOD.

<< Development List


Alternative keys

PB_ID

This key will allow us to find node instance using Phone Book ID.

Step 1: Navigate to Business Object >> Go To Root Node >> Select
Alternative Keys Tab at the bottom or Click on Alternative Keys Link on Side.

  1. Once you are in Alternative Keys Tab then click on New to create.
  2. Click on Finish

Step 2: You can double click on the new Alternative Key from Outline View or you can select the new alternative key from Node, to further configure it.

Step 3:

  1. Maintain Field Name (from Node Attributes)
  2. Save and Activate

<< Development List

<< Top