程序员干货

BOBF-案例一

2018-11-26  本文已影响2人  常威爆打来福

1 案例概述

实现输入product的quantity,price后计算amount,验证product id是否为空。完成prodcut编辑后自动计算order total amount,以及计算create by,create on 等信息。

Data

Determination

Validation

Action

2 Determination

ROOT

    io_modify->do_action(
      EXPORTING
        iv_act_key    = ZIF_STE_ORDER_C=>SC_ACTION-ROOT-CALC_TOTAL_AMOUNT    " Action
        it_key        = it_key    " Key Table
*        is_parameters =
*      IMPORTING
*        eo_message    =     " Message Object
*        et_failed_key =     " Key Table
*        eo_change     =     " Interface of Change Object
*        et_data       =
    ).

ITEM

    DATA: lt_item TYPE zste_t_ord_item,
          ls_item TYPE zste_s_ord_item,
          lt_mod  TYPE /bobf/t_frw_modification,
          lr_item TYPE REF TO zste_s_ord_item.
    FIELD-SYMBOLS: <ls_mod> LIKE LINE OF lt_mod.

    WRITE: ls_item-product_id.
    io_read->retrieve(
      EXPORTING
        iv_node                 =  zif_ste_order_c=>sc_node-item   " Node Name
        it_key                  =  it_key   " Key Table
*        iv_before_image         = ABAP_FALSE    " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ")
*        iv_fill_data            = ABAP_TRUE    " 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_item  " Data Return Structure
*        et_failed_key           =     " Key Table
*        et_node_cat             =     " Node Category Assignment
    ).

    LOOP AT lt_item INTO ls_item.
      ls_item-amount_val = ls_item-price_val * ls_item-quantity_val.
      ls_item-amount_cur = ls_item-price_cur.

      /scmtms/cl_mod_helper=>mod_update_single(
        EXPORTING
         is_data            =  ls_item
         iv_node            =  zif_ste_order_c=>sc_node-item  " Node
         iv_key             =  ls_item-key   " NodeID
         it_changed_fields  =  VALUE #( ( zif_ste_order_c=>sc_node_attribute-item-amount_val )
                                          ( zif_ste_order_c=>sc_node_attribute-item-amount_cur ) )  " List of Names (e.g. Fieldnames)
*          iv_autofill_fields = 'X'    " 'X' -> all not readonly fields will be determined
*          iv_bo_key          =     " Business Object
*        importing
*          es_mod             =     " Change
        CHANGING
          ct_mod             =  lt_mod   " Changes
      ).
    ENDLOOP.

*    LOOP AT lt_item INTO ls_item.
*      ls_item-amount_val = ls_item-price_val * ls_item-quantity_val.
*      ls_item-amount_cur = ls_item-price_cur.
*
*      APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.
*      CREATE DATA lr_item.
*      lr_item->* = ls_item.
*      <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_update.
*      <ls_mod>-association = zif_ste_order_c=>sc_association-root-item.
*      <ls_mod>-source_node = zif_ste_order_c=>sc_node-root.
*      <ls_mod>-node = zif_ste_order_c=>sc_node-item.
*      <ls_mod>-key = lr_item->key.
*      <ls_mod>-data = lr_item.
*    ENDLOOP.

    IF lt_mod IS NOT INITIAL.
      io_modify->do_modify( it_modification = lt_mod ).
    ENDIF.

3 Validation

ITEM

image.png

验证ITEM输入是否存在PRODUCT ID。主要难点在于错误信息显示,实现如下
首先要在T-Code:se91种创建message,/scmtms/cl_msg_helper=>add_message用于显示提示信息

message management
DATA: ls_item TYPE zste_s_ord_item,
          lt_item TYPE zste_t_ord_item,
          lv_msg  TYPE string,
          ls_msg  TYPE symsg.
    CLEAR eo_message.

    io_read->retrieve(
      EXPORTING
        iv_node                 =  zif_ste_order_c=>sc_node-item  " Node Name
        it_key                  =   it_key  " Key Table
*        iv_before_image         = ABAP_FALSE    " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ")
*        iv_fill_data            = ABAP_TRUE    " 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_item  " Data Return Structure
*        et_failed_key           =     " Key Table
*        et_node_cat             =     " Node Category Assignment
    ).

    LOOP AT lt_item INTO ls_item.
      IF ls_item-product_id IS INITIAL.
        MESSAGE e001(zste_order) INTO lv_msg.
        MOVE-CORRESPONDING sy TO ls_msg.
        /scmtms/cl_msg_helper=>add_message(
          EXPORTING
*          iv_bopf_location_key =     " Det/Val execution node instance key
            is_msg               =  ls_msg   " Structure of Message Variables
            iv_bo_key            =  is_ctx-bo_key   " Business Object
            iv_node              =  is_ctx-node_key   " Node Name
            iv_key               =  ls_item-key   " Key
            iv_attribute         =  zif_ste_order_c=>sc_node_attribute-item-product_id   " Field Name
            iv_detlevel          = /scmtms/cl_applog_helper=>sc_al_detlev_default    " Application Log: Level of detail
            iv_probclass         = /scmtms/cl_applog_helper=>sc_al_probclass_important    " Application log: Message problem class
*          iv_add_context_info  = ABAP_FALSE    " Generate BO instance specific message context
          CHANGING
            co_message           =   eo_message  " Interface of Message Object
        ).
        /scmtms/cl_common_helper=>insert_key(
          EXPORTING
            iv_key =  ls_item-key   " NodeID
*    is_key =     " Node Key
          CHANGING
            ct_key =   et_failed_key  " Key Table
        ).
      ENDIF.
    ENDLOOP.

4 Action

ROOT

   DATA: lt_item TYPE zste_t_ord_item,
          ls_item TYPE zste_s_ord_item,
          ls_root TYPE zste_s_ord_root_k,
          lt_root TYPE zste_t_ord_root_k,
          lt_mod  TYPE /bobf/t_frw_modification.

    io_read->retrieve_by_association(
      EXPORTING
        iv_node                 =  zif_ste_order_c=>sc_node-root   " Node Name
        it_key                  =  it_key   " Key Table
        iv_association          =  zif_ste_order_c=>sc_association-root-item   " 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_item   " Data Return Structure
*        et_key_link             =     " Key Link
*        et_target_key           =     " Key Table
*        et_failed_key           =     " Key Table
    ).

    io_read->retrieve(
      EXPORTING
        iv_node                 = zif_ste_order_c=>sc_node-root    " Node Name
        it_key                  = it_key    " Key Table
*        iv_before_image         = ABAP_FALSE    " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ")
*        iv_fill_data            = ABAP_TRUE    " 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_root   " Data Return Structure
*        et_failed_key           =     " Key Table
*        et_node_cat             =     " Node Category Assignment
    ).

    LOOP AT lt_root INTO ls_root.
      LOOP AT lt_item INTO ls_item.
        ls_root-total_amount_val = ls_root-total_amount_val + ls_item-amount_val.
        ls_root-total_amount_cur = ls_item-amount_cur.
      ENDLOOP.
      /scmtms/cl_mod_helper=>mod_update_single(
        EXPORTING
          is_data            = ls_root
          iv_node            = zif_ste_order_c=>sc_node-root    " Node
          iv_key             = ls_root-key " NodeID
          it_changed_fields  = VALUE #( ( zif_ste_order_c=>sc_node_attribute-root-total_amount_val )
                                        ( zif_ste_order_c=>sc_node_attribute-root-total_amount_cur ) )  " List of Names (e.g. Fieldnames)
*       iv_autofill_fields = 'X'    " 'X' -> all not readonly fields will be determined
*       iv_bo_key          =     " Business Object
*    IMPORTING
*       es_mod             =     " Change
       CHANGING
          ct_mod             =  lt_mod   " Changes
      ).
    ENDLOOP.

    IF lt_mod IS NOT INITIAL.
      io_modify->do_modify( it_modification = lt_mod ).
    ENDIF.
上一篇下一篇

猜你喜欢

热点阅读