on ‎2022 Mar 03 4:35 PM
Hello everyone
My name is Noah and I have 1.5 years of ABAP experience. My current task is to update the classification characteristics in IE02. I have achieved this using the BAPI BAPI_OBJCL_CHANGE. However, for some of the equipment numbers I receive the following error message: "Inconsistent characteristic value assignment". If I go and change the corresponding number manually, it updates. Can someone please help me with this? Below is my report code.
Thank you in advance and best regards,
Noah
REPORT zpm_equi_class_update.
************************************************************************
* LOCAL CLASS Report DEFINITION
************************************************************************
*=======================================================================
*=======================================================================
* Definition:
* Excepition
CLASS lcl_report DEFINITION CREATE PUBLIC FINAL.
PUBLIC SECTION.
TYPES:
BEGIN OF ty_data,
equipment_number TYPE rm63e-equnr,
trafo_number TYPE string,
trafo_name TYPE string,
END OF ty_data,
tty_data TYPE TABLE OF ty_data WITH KEY trafo_number trafo_name.
TYPES:
BEGIN OF ty_error,
equipment_number TYPE rm63e-equnr,
END OF ty_error,
tty_error TYPE TABLE OF ty_error.
* TYPES:
* BEGIN OF ty_import,
* equipment_number TYPE rm63e-equnr,
* return TYPE bapiret2_t,
* allocvaluesnum TYPE tt_bapi1003_alloc_values_num,
* allocvalueschar TYPE tt_bapi1003_alloc_values_char,
* allocvaluescurr TYPE tt_bapi1003_alloc_values_curr,
* END OF ty_import.
TYPES:
BEGIN OF ty_line,
line TYPE string,
END OF ty_line,
tty_line TYPE STANDARD TABLE OF ty_line WITH NON-UNIQUE KEY line.
CLASS-METHODS:
file_open_dialog
RETURNING
VALUE(rv_path) TYPE string.
METHODS:
constructor
IMPORTING
iv_path TYPE string
iv_head TYPE xfeld,
execute.
PROTECTED SECTION.
DATA:
mv_path TYPE string,
mv_head TYPE xfeld.
z
PRIVATE SECTION.
METHODS:
* change_objectclass
* IMPORTING
* it_values TYPE ty_import
* RETURNING
* VALUE(rt_return) TYPE bapiret2_t,
get_excel
RETURNING
VALUE(rt_data) TYPE tty_data,
update_equipment
IMPORTING
it_data TYPE tty_data,
display_progress_indicator
IMPORTING
iv_lines TYPE i OPTIONAL
iv_tabix TYPE sy-tabix OPTIONAL
iv_message TYPE string.
ENDCLASS.
************************************************************************
* LOCAL CLASS Report IMPLEMENTATION
************************************************************************
*=======================================================================
*=======================================================================
* Definition:
* Excepition
CLASS lcl_report IMPLEMENTATION.
METHOD constructor.
" fill the attributes
me->mv_head = iv_head.
me->mv_path = iv_path.
ENDMETHOD.
* METHOD change_objectclass.
*
* TRY.
*
* " update the equipment classification characteristics
* CALL FUNCTION 'BAPI_OBJCL_CHANGE'
* EXPORTING
* objectkey = CONV bapi1003_key-object( it_values-equipment_number )
* objecttable = 'EQUI'
* classnum = 'ANSCHLUSS'
* classtype = 'IS2'
* TABLES
* allocvaluesnumnew = it_values-allocvaluesnum
* allocvaluescharnew = it_values-allocvalueschar
* allocvaluescurrnew = it_values-allocvaluescurr
* return = rt_return.
*
* " commit the changes
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*
* CATCH cx_root INTO DATA(lx_root).
* MESSAGE lx_root TYPE 'E'.
* ENDTRY.
*
* ENDMETHOD.
METHOD display_progress_indicator.
" local declarations
DATA:
lv_lines TYPE i,
lv_tabix TYPE sy-tabix,
lv_percentage TYPE decfloat16,
lv_message TYPE string.
" initalize the variables with a value
lv_lines = iv_lines.
lv_tabix = iv_tabix.
lv_message = iv_message.
" calculate the progress of the action
lv_percentage = ( lv_tabix / lv_lines ) * 100.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = lv_percentage
text = lv_message.
ENDMETHOD.
METHOD update_equipment.
" local declarations
DATA:
lt_return TYPE bapiret2_t,
lt_allocvaluesnum TYPE tt_bapi1003_alloc_values_num,
lt_allocvalueschar TYPE tt_bapi1003_alloc_values_char,
lt_allocvaluescurr TYPE tt_bapi1003_alloc_values_curr,
lt_error TYPE tty_error.
" loop over the data and update the equipment classification characteristics
LOOP AT it_data REFERENCE INTO DATA(lr_data).
IF lr_data->equipment_number EQ '400174-1'.
BREAK ZENO.
ENDIF.
**********************************************************************
**********************************************************************
*--------------------------------------------------------------------*
* FILL VALUES
*--------------------------------------------------------------------*
**********************************************************************
*********************************************************************
" fill the table with the station number
APPEND INITIAL LINE TO lt_allocvalueschar REFERENCE INTO DATA(lr_valueschar).
lr_valueschar->charact = 'TRAFOSTATION'.
lr_valueschar->charact_descr = 'TRAFOSTATION'.
lr_valueschar->value_char = lr_data->trafo_number.
" fill the table with the station description
APPEND INITIAL LINE TO lt_allocvalueschar ASSIGNING FIELD-SYMBOL(<fs_valueschar>).
<fs_valueschar>-charact = 'TS-BEZEICHNUNG'.
<fs_valueschar>-charact_descr = 'TS-BEZEICHNUNG'.
<fs_valueschar>-value_char = lr_data->trafo_name.
TRY.
" update the equipment classification characteristics
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = CONV bapi1003_key-object( lr_data->equipment_number )
objecttable = 'EQUI'
classnum = 'ANSCHLUSS'
classtype = 'IS2'
TABLES
allocvaluesnumnew = lt_allocvaluesnum
allocvaluescharnew = lt_allocvalueschar
allocvaluescurrnew = lt_allocvaluescurr
return = lt_return.
" commit the changes
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CATCH cx_root INTO DATA(lx_root).
MESSAGE lx_root TYPE 'E'.
ENDTRY.
LOOP AT lt_return REFERENCE INTO DATA(lr_return).
IF lr_return->number EQ 821.
APPEND INITIAL LINE TO lt_error REFERENCE INTO DATA(lr_error).
lr_error->equipment_number = lr_data->equipment_number.
ENDIF.
ENDLOOP.
FREE lt_return.
ENDLOOP.
ENDMETHOD.
METHOD execute.
" get the excel file
me->update_equipment( me->get_excel( ) ).
ENDMETHOD.
METHOD file_open_dialog.
" local declarations
DATA:
lv_window_title TYPE string,
lt_filetable TYPE filetable,
lv_rc TYPE i,
lv_user_action TYPE i.
" set the window title
lv_window_title = 'Bitte Datei auswählen'.
" open the file dialog
cl_gui_frontend_services=>file_open_dialog(
EXPORTING
window_title = lv_window_title
default_extension = '.xlsx'
file_filter = 'Excel-Dateien (*.XLS)|*.XLSX'
multiselection = abap_false
CHANGING
file_table = lt_filetable
rc = lv_rc
user_action = lv_user_action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5
).
IF sy-subrc <> 0.
" do nothing
ENDIF.
TRY.
rv_path = lt_filetable[ 1 ]-filename.
" handle the exception
CATCH cx_root INTO DATA(lx_root).
MESSAGE ID 'R3' TYPE 'E' NUMBER '010' WITH 'Upload file'(e01) INTO DATA(ls_msg).
ENDTRY.
ENDMETHOD.
METHOD get_excel.
" local declarations
DATA:
lv_filename TYPE rlgrap-filename,
lt_truxs_t_text_data TYPE truxs_t_text_data.
" upload the excel file from the frontend
lv_filename = me->mv_path.
" convert the file into a readable data type
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = me->mv_head
i_tab_raw_data = lt_truxs_t_text_data
i_filename = lv_filename
TABLES
i_tab_converted_data = rt_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
" do nothing
ENDIF.
ENDMETHOD.
ENDCLASS.
************************************************************************
* GUI-INTERFACE
************************************************************************
*=======================================================================
* Upload
SELECTION-SCREEN BEGIN OF BLOCK upload WITH FRAME TITLE TEXT-t01.
PARAMETERS p_path TYPE string.
PARAMETERS p_head TYPE xfeld AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN END OF BLOCK upload.
**********************************************************************
* AT SELECTION-SCREEN
**********************************************************************
*=====================================================================
AT SELECTION-SCREEN.
IF p_path IS INITIAL.
MESSAGE ID 'R3' TYPE 'E' NUMBER '010' WITH 'Upload file'(e01) DISPLAY LIKE 'I'.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
TRY.
" open the file dialog and fill the path
p_path = lcl_report=>file_open_dialog( ).
CATCH cx_root INTO DATA(lx_root).
" do nothing
ENDTRY.
**********************************************************************
* START-OF-SELECTION
**********************************************************************
*=====================================================================
START-OF-SELECTION.
IF NOT cl_gui_alv_grid=>offline( ) IS INITIAL.
MESSAGE ID '88' TYPE 'I' NUMBER '997'.
EXIT.
ENDIF.
TRY.
" create an instance of the report class
NEW lcl_report( iv_path = p_path iv_head = p_head )->execute( ).
CATCH cx_root INTO DATA(lx_root).
" display the error message
MESSAGE lx_root TYPE 'I'.
ENDTRY.
Request clarification before answering.
I ran into the same error a few weeks back. In my case the error was a result of a changed characteristic. It used to be a characteristic with multiple allowed values. Someone changed it to only one single value allowed. And in the end table AUSP often contained a record with value space (empty) which was not being overwritten when a change was made with the update function. Instead, a new AUSP record was added and resulted in said error.
To avoid this, i added an empty allowed value in the characteristic list and the problem never arose again.
Not sure if the same applies to your situation but worth looking into it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 59 | |
| 30 | |
| 21 | |
| 11 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.