79471421

Date: 2025-02-27 01:27:37
Score: 1
Natty:
Report link

Since I can't use @IM_NAME LIKE ZZPATTN in the SELECT statement, I use another alternative: TYPES, RANGE OF and IN. I split the IM_NAME and append them to an internal table, and use IN to get the results. The reason I used TYPES, RANGE OF not TYPE, TABLE OF is to solve error "The line structure of the table "LT_PATTERNS" is incorrect."

Not straightforward as LIKE, but could provide similar result. Here are the sample code:

TYPES:
  ty_pattern TYPE STRING,  " Define type for pattern
  ty_pattern_range TYPE RANGE OF ty_pattern.  " Range table for pattern
DATA:
  lt_patterns TYPE ty_pattern_range,    " Range table for patterns
  lv_pattern TYPE STRING,       " Current pattern
  lv_length TYPE i.

" Initialize the pattern with '*' (wildcard)
lv_pattern = '*'.
CLEAR lt_patterns.
APPEND VALUE #( sign = 'I' option = 'EQ' low = lv_pattern ) TO lt_patterns.  " Add pattern to range

lv_length = strlen( IM_NAME ).  
  WHILE lv_length >= 1.
    lv_pattern = substring( val = IM_NAME len = lv_length ) && '*'.  
    lv_length = lv_length - 1.  " Reduce the length
    APPEND VALUE #( sign = 'I' option = 'EQ' low = lv_pattern ) TO lt_patterns.  
  ENDWHILE.

" Now use the range table in the SELECT statement
  SELECT ZZPRICE, ZZEFDAT INTO ( @PRICE, @EFDAT ) FROM ZZPRICE
        UP TO 1 ROWS
        WHERE ( ZZNAME = @IM_NAME OR ZZPATTN IN @lt_patterns ) 
ENDSELECT.
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @IM_NAME
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user29774157