FUNCTION Z_PO_FIND. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_PO_NUMBER) TYPE EKKO-EBELN OPTIONAL *" VALUE(I_COMPANY_CODE) TYPE EKKO-BUKRS OPTIONAL *" VALUE(I_PURCH_GROUP) TYPE EKKO-EKGRP OPTIONAL *" VALUE(I_DOC_START_DATE) TYPE EKKO-AEDAT DEFAULT '01.01.0001' *" VALUE(I_DOC_END_DATE) TYPE EKKO-AEDAT DEFAULT '31.12.9999' *" TABLES *" T_EKKO STRUCTURE EKKO OPTIONAL *"---------------------------------------------------------------------- RANGES: R_EBELN FOR EKKO-EBELN, R_BUKRS FOR EKKO-BUKRS, R_EKGRP FOR EKKO-EKGRP, R_AEDAT FOR EKKO-AEDAT. DATA: W_WILD TYPE C LENGTH 1 VALUE '*', W_PO_NUMBER LIKE EKKO-EBELN. * Set PO Number range IF I_PO_NUMBER IS NOT INITIAL. SHIFT I_PO_NUMBER LEFT DELETING LEADING '0'. CONCATENATE W_WILD I_PO_NUMBER W_WILD INTO W_PO_NUMBER. R_EBELN-OPTION = 'CP'. R_EBELN-SIGN = 'I'. R_EBELN-LOW = W_PO_NUMBER. APPEND R_EBELN. ENDIF. * Set Company Code range IF I_COMPANY_CODE IS NOT INITIAL. R_BUKRS-OPTION = 'EQ'. R_BUKRS-SIGN = 'I'. R_BUKRS-LOW = I_COMPANY_CODE. APPEND R_BUKRS. ENDIF. * Set Purchasing Group range IF NOT I_PURCH_GROUP IS INITIAL. R_EKGRP-OPTION = 'EQ'. R_EKGRP-SIGN = 'I'. R_EKGRP-LOW = I_PURCH_GROUP. APPEND R_EKGRP. ENDIF. * Set date range R_AEDAT-OPTION = 'BT'. R_AEDAT-SIGN = 'I'. R_AEDAT-LOW = I_DOC_START_DATE. R_AEDAT-HIGH = I_DOC_END_DATE. APPEND R_AEDAT. * Select records from table EKKO SELECT * FROM EKKO INTO T_EKKO WHERE EBELN IN R_EBELN AND BUKRS IN R_BUKRS AND EKGRP IN R_EKGRP AND AEDAT IN R_AEDAT. APPEND T_EKKO. ENDSELECT. ENDFUNCTION.
The Musings and Findings of Software Consultant David Klein (Sydney, Australia)
Tuesday, 2 February 2010
How to Perform Wild Card Matches in SAP ABAP (for a Find or Search Function)
The following BAPI has several optional criteria that are only added to the filter if they have a value. It uses the RANGE keyword and the IN keyword together to build up the query filter. It is an alternative to building a dynamic query (based purely on string concatenation). Note that this works because the range object is null in the final comparison statment in this BAPI so it will not be added to the filter, (e.g. "AND BUKRS IN R_BUKRS" will effectively be "AND BUKRS IN NULL" and so will not be evaluated in the WHERE clause.).
Subscribe to:
Post Comments (Atom)
1 comment:
Excellent post, check out here for further examples of simple range table creation and usage.
Post a Comment