1 1 1 1 1 Rating 0% (0 Votes)
In previous article I've shown how to move characteristics from reference data to screen values table, this method is doing opposite way from screen values table to reference data structure.
 
Importing:

IT_VALUES TYPE TT_API_VALI -> screen values table
I_ATNAM TYPE API_VALI-ATNAM -> Characteristic Name

Changing:

C_DATA TYPE REF TO DATA

Exceptions:

NO_DATA_TO_CHANGE

Implementation:

  method move_screen_val_to_ref_data.
    field-symbols<ms> type any,
                   <any> type any,
                   <table> type any table,
                   <line> type any,
                   <p> type any,
                   <val> type api_vali.
    datam_p(16type p.
    datamo_type type ref to cl_abap_elemdescr.
    datam_format type cabn-atfor.
    datam_currency type rctmv-waers.

    if c_data is initial.
      raise no_data_to_change.
    endif.


    "get characteristic ID
    call function 'COC1_FEATURE_CHECK'
      exporting
*       feature_id                  = atinn
        feature_neutral_name        i_atnam
      
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 m_p to <p>.

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

      assign component i_atnam of structure <ms> to <table>.
      if sy-subrc eq 0.
        refresh <table>.
        loop at it_values assigning <val>.
          insert initial line into table <table> assigning <line>.
          if sy-subrc eq 0.

            case m_format.
              when 'NUM' or 'DATE' or 'TIME'.
                assign component 'LOW' of structure <line> to <any>.
                if sy-subrc eq 0.
                  free mo_type.
                  mo_type ?= cl_abap_typedescr=>describe_by_datap_data <any> ).
                  case mo_type->type_kind.
                    when 'D' or 'T'.
                      <p> <val>-atflv.
                      unpack <p> to <any>.
                    when others.
                      <any> <val>-atflv.
                  endcase.
                endif.

                assign component 'HIGH' of structure <line> to <any>.
                if sy-subrc eq 0.
                  free mo_type.
                  mo_type ?= cl_abap_typedescr=>describe_by_datap_data <any> ).
                  case mo_type->type_kind.
                    when 'D' or 'T'.
                      <p> <val>-atflb.
                      unpack <p> to <any>.
                    when others.
                      <any> =  <val>-atflb.
                  endcase.
                endif.
                assign component 'UNIT_FROM' of structure <line> to <any>.
                if sy-subrc eq 0.
                  <any> <val>-atawe.
                endif.
                assign component 'UNIT_TO' of structure <line> to <any>.
                if sy-subrc eq 0.
                  <any> =  <val>-ataw1.
                endif.
              when 'CURR'.

                assign component 'LOW' of structure <line> to <any>.
                if sy-subrc eq 0.
                  if <val>-atawe is initial.
                    select single msehi into m_currency from cabn where atnam eq i_atnam.
                  else.
                    m_currency <val>-atawe.
                  endif.
                  call function 'KKEK_CONVERT_FLOAT_TO_CURR'
                    exporting
                      float_imp      <val>-atflv
                      curr_imp       
m_currency
                    
importing
                      curr_field_exp <any>
                    
exceptions
                      overflow       1
                      others         2.
                  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
                  endif.

                endif.
                assign component 'HIGH' of structure <line> to <any>.
                if sy-subrc eq 0.
                  if <val>-ataw1 is initial.
                    select single msehi into m_currency from cabn where atnam eq i_atnam.
                  else.
                    m_currency <val>-ataw1.
                  endif.
                  call function 'KKEK_CONVERT_FLOAT_TO_CURR'
                    exporting
                      float_imp      <val>-atflb
                      curr_imp       
m_currency
                    
importing
                      curr_field_exp <any>
                    
exceptions
                      overflow       1
                      others         2.
                  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
                  endif.

                endif.
                assign component 'CURRENCY_FROM' of structure <line> to <any>.
                if sy-subrc eq 0.
                  <any> m_currency.
                endif.
                assign component 'CURRENCY_TO' of structure <line> to <any>.
                if sy-subrc eq 0.
                  <any> m_currency.
                endif.
              when 'CHAR'.
                assign component 'LOW' of structure <line> to <any>.
                if sy-subrc eq 0.
                  <any> <val>-atwrt.
                endif.
                assign component 'OPTLOW' of structure <line> to <any>.
                if sy-subrc eq 0.
                  <any> 'EQ'.
                endif.

            endcase.

            assign component 'OPTLOW' of structure <line> to <any>.
            if sy-subrc eq 0.
              case <val>-atcod.
                when or or space.
                  <any> 'EQ'.
                when or or 9.
                  <any> 'GE'.
                when or or 8.
                  <any> 'GT'.
                when 6.
                  <any> 'LT'.
                when 7.
                  <any> 'LE'.
                when others.
                  <any> 'EQ'.
              endcase.
            endif.
            assign component 'OPTHIGH' of structure <line> to <any>.
            if sy-subrc eq 0.
              case <val>-atcod.
                when or .
                  <any> 'LT'.
                when or 5.
                  <any> 'LE'.
              endcase.
            endif.

          endif.
        endloop.
      endif.
    endif.
  endmethod.                    "move_screen_val_to_ref_data