error in validation in post service in abap

53 Views Asked by At
METHOD zmckinsolset_create_entity.

  DATA: lt_entity_data TYPE TABLE OF zmckinsol,
        ls_entity_data TYPE zmckinsol,
        lv_age         TYPE i,
        lv_error_text  TYPE string.

  " Deserialize payload and get entity data
  CALL METHOD io_data_provider->read_entry_data
    RECEIVING
      et_data = lt_entity_data.

  " Loop through each entity in the payload
  LOOP AT lt_entity_data INTO ls_entity_data.

" Read the value of the "Age" field from the payload
lv_age = ls_entity_data-age.

" Perform validation: Check if the "Age" field has more than 4 digits
IF lv_age IS NOT INITIAL AND lv_age > 9999.
  lv_error_text = |Age { lv_age } should be up to 4 digits.|.
  RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
    EXPORTING
      text = lv_error_text.
ENDIF.

" Continue with other validation checks or entity processing here

  ENDLOOP.

ENDMETHOD.

Here is the code I write to add validation in Age field so that it will accept only 4 integers.

But it will give some error that the addition TYPE type can only be specified once.

Please solve this error for me.

0

There are 0 best solutions below