1 1 1 1 1 Rating 0% (0 Votes)
Our characteristics update screen was displayed, data was changes so we need to read the reference data and put the values into BAPI structures in order to be able to save the values to database.
I will use here BAPI_CLASS_READ to read all possible characteristics and COC1_FEATURE_CHECK to get characteristic details.
 
Importing:

I_DATA TYPE REF TO DATA

Changing:

CT_OBJVALUESNUM TYPE TT_BAPI1003_ALLOC_VALUES_NUM
CT_OBJVALUESCHAR TYPE TT_BAPI1003_ALLOC_VALUES_CHAR
CT_OBJVALUESCURR TYPE TT_BAPI1003_ALLOC_VALUES_CURR

Exceptions:

NO_DATA_TO_PASS 

Implementation:

  method move_ref_data_to_bapi_tables.
    field-symbols<ms> type any,
                   <any> type any,
                   <any2> type any,
                   <table> type any table,
                   <line> type any,
                   <p> type any,
                   <val> type api_vali,
                   <charact> type bapi1003_charact_r,
                   <char> type bapi1003_alloc_values_char,
                   <curr> type bapi1003_alloc_values_curr,
                   <num>  type  bapi1003_alloc_values_num.
    datam_p(16type p.
    datamo_type type ref to cl_abap_elemdescr.
    datam_format type cabn-atfor.
    datam_currency type rctmv-waers.
    datam_atinn type api_vali-atinn.
    datam_objectkey type bapi1003_key-object.
    datam_objecttable type bapi1003_key-objecttable.
    datam_classnum type bapi1003_key-classnum.
    datam_classtype type bapi1003_key-classtype.
    datamt_classcharacteristics type standard table of bapi1003_charact_r.
    datams_return type bapiret2.

    if i_data is initial.
      raise no_data_to_pass.
    endif.

    refreshct_objvalueschar[]ct_objvaluescurr[]ct_objvaluesnum[].

    assign i_data->to <ms>.
    if sy-subrc eq 0.

      assign component 'CLASSTYPE' of structure <ms> to <any>.
      if sy-subrc eq 0.
        m_classtype <any>.
      endif.

      assign component 'CLASS' of structure <ms> to <any>.
      if sy-subrc eq 0.
        m_classnum <any>.
      endif.

      call function 'BAPI_CLASS_READ'
        exporting
          classtype            m_classtype
          classnum             
m_classnum
*         LANGUISO             = LANGUISO
*         LANGUINT             = SY-LANGU
          keydate              sy-datum
        importing
*         CLASSBASICDATA       = CLASSBASICDATA
*         CLASSDOCUMENT        = CLASSDOCUMENT
*         CLASSADDITIONAL      = CLASSADDITIONAL
*         CLASSSTANDARD        = CLASSSTANDARD
          return               ms_return
        
tables
*         classdescriptions    = mt_classdescriptions
*         classlongtexts       = mt_classlongtexts
          classcharacteristics mt_classcharacteristics
*         classcharactvalues   =   mt_classcharactvalues
        .

      loop at mt_classcharacteristics assigning <charact>.
        "get characteristic ID
        call function 'COC1_FEATURE_CHECK'
          exporting
*           feature_id                  = atinn
            feature_neutral_name        <charact>-name_char
          
importing
            format                      m_format
            feature_id                  
m_atinn
*           feature_neutral_name        = atnam
*           conversion_exit             = l_atkon
*           number_of_positions         = l_anzst
*           set_get_parameter           = l_atpid
          exceptions
            invalid_class_type          1
            missing_feature_information 2
            no_feature_found            3
            no_feature_valid            4
            no_language                 5
            others                      6.

        if sy-subrc <> 0.
*   Error
*    raise characteristic_unknown.
        endif.

        assign component <charact>-name_char of structure <ms> to <table>.
        if sy-subrc eq 0.

          loop at <table> assigning <line>.
            case m_format.
              when 'NUM' or 'DATE' or 'TIME'.
                insert initial line into table ct_objvaluesnum assigning <num>.
                if sy-subrc eq 0.
                  <num>-charact <charact>-name_char.
                  assign component 'LOW' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <num>-value_from zcl_abapblog_com_classific=>convert_char_value(
                                                     i_atnam       <charact>-name_char
                                                     i_value_new   
<any>
                                                        
).
                  endif.
                  assign component 'HIGH' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <num>-value_to zcl_abapblog_com_classific=>convert_char_value(
                                                      i_atnam       <charact>-name_char
                                                      i_value_new   
<any>
                                                      
).
                  endif.
                  assign component 'UNIT_FROM' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <num>-unit_from <any>.
                  endif.
                  assign component 'UNIT_TO' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <num>-unit_to <any>.
                  endif.

                  unassign<any><any2>.
                  assign component 'OPTLOW' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    case <any>.
                      when 'EQ'.
                        <num>-value_relation 1.
                      when 'GE'.
                        assign component 'OPTHIGH' of structure <line> to <any2>.
                        if sy-subrc eq 0.
                          case <any2>.
                            when 'LT'.
                              <num>-value_relation 2.
                            when 'LE'.
                              <num>-value_relation 3.
                            when space.
                              <num>-value_relation 9.
                          endcase.
                        else.
                          <num>-value_relation 9.
                        endif.
                      when 'GT'.
                        assign component 'OPTHIGH' of structure <line> to <any2>.
                        if sy-subrc eq 0.
                          case <any2>.
                            when 'LT'.
                              <num>-value_relation 4.
                            when 'LE'.
                              <num>-value_relation 5.
                            when space.
                              <num>-value_relation 8.
                          endcase.
                        else.
                          <num>-value_relation 8.
                        endif.
                      when 'LT'.
                        <num>-value_relation 6.
                      when 'LE'.
                        <num>-value_relation 7.
                    endcase.
                  endif.
                endif.
              when 'CURR'.
                insert initial line into table ct_objvaluescurr assigning <curr>.
                if sy-subrc eq 0.
                  <curr>-charact <charact>-name_char.
                  assign component 'LOW' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <curr>-value_from zcl_abapblog_com_classific=>convert_char_value(
                                                                          i_atnam       <charact>-name_char
                                                                          i_value_new   
<any>
                                                                          
).

                  endif.
                  assign component 'HIGH' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <curr>-value_to zcl_abapblog_com_classific=>convert_char_value(
                                                                               i_atnam       <charact>-name_char
                                                                               i_value_new   
<any>
                                                                               
).

                  endif.
                  assign component 'CURRENCY_FROM' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <curr>-currency_from <any>.
                  endif.
                  assign component 'CURRENCY_TO' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <curr>-currency_to <any>.
                  endif.

                  unassign<any><any2>.
                  assign component 'OPTLOW' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    case <any>.
                      when 'EQ'.
                        <curr>-value_relation 1.
                      when 'GE'.
                        assign component 'OPTHIGH' of structure <line> to <any2>.
                        if sy-subrc eq 0.
                          case <any2>.
                            when 'LT'.
                              <curr>-value_relation 2.
                            when 'LE'.
                              <curr>-value_relation 3.
                            when space.
                              <curr>-value_relation 9.
                          endcase.
                        else.
                          <curr>-value_relation 9.
                        endif.
                      when 'GT'.
                        assign component 'OPTHIGH' of structure <line> to <any2>.
                        if sy-subrc eq 0.
                          case <any2>.
                            when 'LT'.
                              <curr>-value_relation 4.
                            when 'LE'.
                              <curr>-value_relation 5.
                            when space.
                              <curr>-value_relation 8.
                          endcase.
                        else.
                          <curr>-value_relation 8.
                        endif.
                      when 'LT'.
                        <curr>-value_relation 6.
                      when 'LE'.
                        <curr>-value_relation 7.
                    endcase.
                  endif.
                endif.
              when 'CHAR'.
                insert initial line into table ct_objvalueschar assigning <char>.
                if sy-subrc eq 0.
                  <char>-charact <charact>-name_char.
                  assign component 'LOW' of structure <line> to <any>.
                  if sy-subrc eq 0.
                    <char>-value_char <any>.
                    <char>-value_neutral <any>.
                  endif.
                endif.
            endcase.
          endloop.
        endif.
      endloop.
    endif.

  endmethod.                    "move_ref_data_to_bapi_tables