Skip to Content
0
May 03, 2019 at 12:41 AM

SAP BOPF Determination, stop inserting records without setting et_failed_key or raising exception

1161 Views Last edit May 03, 2019 at 01:45 AM 2 rev

I'm new to SAP and ABAP. I need to insert multiple records to the table. I've created a loop in the determination of the coresponding CDS and manually insert records. But the default insert of the determination also executes, inserting an unwanted record to the table. How can I stop the inserting of the record through the default execution path?

I've set the et_failed_key, it will stop the insertion, but generated an error in the front end. So is there a better way od doing this?

Following is the code

class /atu/cl_sf_d_ws_save_and_valid definition
  public
  inheriting from /bobf/cl_lib_d_supercl_simple
  final
  create public .
  public section.
    methods /bobf/if_frw_determination~execute
        redefinition .
  protected section.
  private section.
endclass.

class /atu/cl_sf_d_ws_save_and_valid implementation.
  method /bobf/if_frw_determination~execute.

    clear: et_failed_key,eo_message.

    "Read data with the given keys
    data : lt_data         type /atu/t_sfi_work_station,
           ls_key          type /bobf/s_frw_key,
           lo_cm           type ref to /bobf/cm_frw,
           lv_msg          type string,
           lv_stationno    type int8,
           lv_stationcount type int8,
           lv_counter      type int8.

    io_read->retrieve(
        exporting
            iv_node                 = is_ctx-node_key   " uuid of node name
            it_key                  = it_key            " keys given to the determination
        importing
            et_data                 = lt_data           " itab with node data
            eo_message      = eo_message
      et_failed_key   = et_failed_key
    ).

    loop at lt_data reference into data(lo_inp).
*    If multiple workstation add loop and check the vaules
      if lo_inp->workstationno < 0.
*Get the station count
        lv_stationcount = abs( lo_inp->workstationno ).
*SET Station number
        lv_stationno = 0.
        lv_counter = 1.

        data: iztab type /atu/sf_wkstn.

        while ( lv_counter < lv_stationcount ).

*Add 1 to station number
          add 1 to lv_stationno.
*Check station exists. If not add
          select single count( distinct workstationno ) from /atu/sf_i_work_station
            where workcenter = @lo_inp->workcenter
            and factory = @lo_inp->factory
            and workstationno = @lv_stationno
              into @data(lv_ws_items).
*  If not exists, add the work station
          if lv_ws_items = 0.

*set station no
            lo_inp->workstationno = lv_stationno.

            clear iztab.
            iztab-factory = lo_inp->factory.
            iztab-workcenter = lo_inp->workcenter.
            iztab-workstationno = lv_stationno.
            iztab-active = 'X'.
            insert into /atu/sf_wkstn values iztab.

*Increment the counter to add next station
            add 1 to lv_counter.

          endif.
        endwhile.
        if sy-subrc = 0.
          commit work.
        endif.

*        Set ET Failed key stop BOPF to insert the record
        et_failed_key =  it_key.

      else.
*   Search the CDS for matching data
        select single ( workstationno ) from /atu/sf_i_work_station
        where workcenter = @lo_inp->workcenter
        and factory = @lo_inp->factory
        and workstationno = @lo_inp->workstationno
        and active = 'X'
        into @data(lv_codes).

        if lv_codes is not initial.

          et_failed_key =  it_key.
          if eo_message is not bound.
            eo_message = /bobf/cl_frw_factory=>get_message( ).
          endif.

          message i001(/atu/sf_validat_msg) into lv_msg.

          create object lo_cm type /bobf/cm_frw_symsg
            exporting
              severity     = 'E'
              symptom      = '000'
              message_text = lv_msg.

          eo_message->add_cm(
           exporting
            io_message = lo_cm ).

          return.

        endif.
      endif.
    endloop.

  endmethod.
endclass.