Check range values from a domain

Check range values from a domain

⚠️ This code works only if range values are restricted to Include Equal (I EQ) and domain values are not range of values.

Example of calling code :


  DATA : lv_wrong_value TYPE domvalue_l.
  
  PERFORM f_check_range_val_from_domain USING 'MTART'
                                              s_mtart[]
                                              CHANGING lv_wrong_value.
  IF lv_wrong_value IS NOT INITIAL.
    SET CURSOR FIELD 'S_MTART-LOW' ##NO_TEXT.
    MESSAGE i001(zz) WITH lv_wrong_value DISPLAY LIKE 'E'.
    " Material type &1 is not valid
  ENDIF.


FORM check_range_val_from_domain USING uv_domain
                                       ur_range TYPE ANY TABLE
                              CHANGING cv_value_in_error.

  DATA : lt_dd07v         TYPE dd07v_tab,
         ls_range         TYPE string,
         lv_val           TYPE domvalue_l,
         lr_domain_values TYPE RANGE OF domvalue_l.

  CLEAR cv_value_in_error.

  CALL FUNCTION 'DD_DOMVALUES_GET'
    EXPORTING
      domname        = uv_domain
    TABLES
      dd07v_tab      = lt_dd07v
    EXCEPTIONS
      wrong_textflag = 1
      OTHERS         = 2.

  IF lt_dd07v IS INITIAL.
    MESSAGE e145(gu) WITH uv_domain.
    "	Le domaine & n'existe pas
  ENDIF.

  lr_domain_values = VALUE #( FOR ls_dd07v IN lt_dd07v ( sign   = 'I' 
                                                         option = 'EQ' 
                                                         low = ls_dd07v-domvalue_l ) 
                            ) ##NO_TEXT.

  LOOP AT ur_range INTO ls_range.

    DATA(lv_length) = strlen( condense( ls_range ) ) - 3.

    IF lv_length > 0.

      lv_val = ls_range+3(lv_length).

      IF lv_val NOT IN lr_domain_values.
        cv_value_in_error = lv_val.
        EXIT.
      ENDIF.

    ENDIF.
  ENDLOOP.

ENDFORM.

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply