Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Kindly check my codes on WHERE cond.

Whenever I used wildcard % in searching it shows the result. But when I enter a value, like in firstname, it didn't show up. Is there something wrong with the WHERE condition and using LIKE?

DATA: lv_len TYPE n,

lv_gbdat TYPE gbdat. " Birthdate

**Pass Value

IF employee_number IS INITIAL.

employee_number = '%'.

ENDIF.

IF first_name IS INITIAL.

first_name = '%'.

ENDIF.

IF last_name IS INITIAL.

last_name = '%'.

ENDIF.

IF gender IS INITIAL.

gender = '%'.

ENDIF.

    • Prepare Employee Number

IF employee_number NE '%'.

    • Get length

lv_len = STRLEN( employee_number ).

lv_len = 8 - lv_len.

    • Add Leading 0

DO lv_len TIMES.

SHIFT employee_number RIGHT.

ENDDO.

OVERLAY employee_number WITH '00000000'.

ENDIF.

    • Get Data

SELECT pernr

vorna

nachn

gesch

gbdat

INTO (result-pernr,

result-vorna,

result-nachn,

result-gender,

lv_gbdat)

FROM pa0002

WHERE pernr LIKE employee_number

AND vorna LIKE first_name

AND nachn LIKE last_name

AND gesch LIKE gender.

    • Get age

result-age = sy-datum(4) - lv_gbdat(4).

    • Check age filter

IF age IS NOT INITIAL.

CHECK age = result-age.

ENDIF.

APPEND result.

CLEAR result.

ENDSELECT.

ENDIF.

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question