Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SE37 use of wildcard

former_member654002
Participant
0 Kudos

Hi Abapers,

I start to build function module on SE37.

I have 3 imput parameters all of then optional. I need to use a wildcard on two of then.

How can i do that? I thought that we must use % but i tryed on SE37 and i get not any result.

Thank you and Best regards

João Fernandes

1 ACCEPTED SOLUTION

MariaJoãoRocha
Contributor
0 Kudos

Hi,

One option is to work with ranges:

in your FM:

ranges: r_aufnr for aufk-aufnr,

             r_erdat for sy-datum,

             r_aedat for sy-datum.

if i_aufnr is not iinitial.

  r_aufnr-option = 'EQ'.

  r_aufnr-sign = 'I'.

  r_aufnr-low = i_aufnr.

  append r_aufnr.

endif.

the same for the dates.

select * from aufnk where ...

and aufnr in r_aufnr

and erdat in r_erdat

and aedat in r_aedat.

Regards,

Maria João Rocha

14 REPLIES 14

PeterJonker
Active Contributor
0 Kudos

Can you share your code ?

Former Member
0 Kudos

Hi Joao,

I think you should use *.

Or try searching for an FM that do search. try looking at the FM CRM_BSP_COMP_SEARCH.

Regards,

Ashvin

former_member654002
Participant
0 Kudos

Hi,

Thank you for your answers

Here is the code

SELECT * FROM aufk WHERE auart EQ 'P1' AND werks EQ 'NDCM' and aufnr EQ i_aufnr and erdat EQ I_erdat

     and aedat EQ I_Aedat.

*  SELECT * FROM aufk WHERE auart EQ 'P1' AND werks EQ 'NDCM' and aufnr EQ i_aufnr.

       SELECT SINGLE * FROM jest WHERE objnr EQ aufk-objnr AND

       stat EQ 'I0002' AND inact EQ ' '.

     IF sy-subrc EQ 0.

       MOVE aufk-aufnr TO zitemprod-aufnr.

       SELECT SINGLE * INTO CORRESPONDING FIELDS OF zitemprod

         FROM afko WHERE aufnr EQ aufk-aufnr.

      select * from afvc where aufpl eq afko-aufpl and STEUS = 'PP10'.

          select * from crhd where OBJID = afvc-arbid.

            move 'PT' to zitemprod-spras.

            move crhd-arbpl to zitemprod-arbpl.

        SELECT SINGLE * INTO CORRESPONDING FIELDS OF zitemprod

            FROM mean WHERE matnr EQ zitemprod-plnbez AND EANTP EQ 'IC'.

        SELECT SINGLE * INTO CORRESPONDING FIELDS OF zitemprod

            FROM afpo WHERE aufnr EQ zitemprod-AUFNR.

            append zitemprod.

          endselect.

      endselect.

     ENDIF.

   ENDSELECT.

   SORT zitemprod.



ENDFUNCTION.


Best regards


former_member654002
Participant
0 Kudos

Sorry

miss this part

FUNCTION Z_WS_CENT_PAL.

*"----------------------------------------------------------------------

*"*"Interface local:

*"  IMPORTING

*"     VALUE(I_AUFNR) TYPE  AUFNR OPTIONAL

*"     VALUE(I_ERDAT) TYPE  ERDAT OPTIONAL

*"     VALUE(I_AEDAT) TYPE  AEDAT OPTIONAL

*"  EXPORTING

*"     VALUE(RETURN) TYPE  BAPIRETURN

*"  TABLES

*"      ZITEMPROD STRUCTURE  ZDOLMAORDEMPROD

*"----------------------------------------------------------------------

TABLES: aufk, jest, afko, makt, MEan, afvc, crhd.

0 Kudos

Hi

and why do you need a wildcard?

MariaJoãoRocha
Contributor
0 Kudos

Hi,

One option is to work with ranges:

in your FM:

ranges: r_aufnr for aufk-aufnr,

             r_erdat for sy-datum,

             r_aedat for sy-datum.

if i_aufnr is not iinitial.

  r_aufnr-option = 'EQ'.

  r_aufnr-sign = 'I'.

  r_aufnr-low = i_aufnr.

  append r_aufnr.

endif.

the same for the dates.

select * from aufnk where ...

and aufnr in r_aufnr

and erdat in r_erdat

and aedat in r_aedat.

Regards,

Maria João Rocha

Former Member
0 Kudos

Hi Joao,

For wildcard, you need to use LIKE in where clause instead of WHERE field EQ 'V%'.

It should be WHERE field1 LIKE 'V%'. Seems you are using EQ

Cheers!!

Raju Shrestha

former_member654002
Participant
0 Kudos

Hi,

Thank you for your interest.

I need a wildcard because in some cases i need to call the function and some fields are optional. So i need to call "any" parameter.

With

and aufnr LIKE i_aufnr and erdat LIKE I_erdat

     and aedat LIKE I_Aedat.


i get an error "The pattern used as a LIKE condition can only be specified in a type C field.



Best regards



João Fernandes


0 Kudos

Hi

Wildcard is usefull only if you want to select a value having a certain string else it's useless, you can use a range:

If your input data are optional:


FUNCTION Z_WS_CENT_PAL.

*"----------------------------------------------------------------------

*"*"Interface local:

*"  IMPORTING

*"     VALUE(I_AUFNR) TYPE  AUFNR OPTIONAL

*"     VALUE(I_ERDAT) TYPE  ERDAT OPTIONAL

*"     VALUE(I_AEDAT) TYPE  AEDAT OPTIONAL

You can use ranges


RANGES: R_AUFNR FOR AUFK-AUFNR.

RANGES: R_ERDAT FOR AUFK-ERDAT.

RANGES; R_AEDAT FOR AUFK-AEDAT,

:

These ranges will be filled only if the input data will be filled:



IF NOT I_AUFNR IS INITIAL.

  R_AUFNR(3) = 'IEQ'.

  R_AUFNR-LOW = I_AUFNR.

  APPEND R_AUFNR.

ENDIF.

IF NOT I_AEDAT IS INITIAL.

  R_AEDAT(3) = 'IEQ'.

  R_AEDAT-LOW = I_AEDAT.

  APPEND R_AEDAT.

ENDIF.

IF NOT I_ERDAT IS INITIAL.

  R_ERDAT(3) = 'IEQ'.

  R_ERDAT-LOW = I_ERDAT.

  APPEND R_ERDAT.

ENDIF.


So your selection will be:


SELECT *

   FROM aufk

      WHERE auart = 'P1'

           AND werks = 'NDCM'

           AND aufnr  IN R_aufnr

           AND erdat  IN R_erdat

           AND aedat IN R_Aedat.


Max

0 Kudos

Hi,

Already indicated this solution!

Regards,

Maria João Rocha

0 Kudos

Sorry

I didn't see your answer

Ok

so João Fernandes

if you need to transfer a value or nothing, and if nothing means to select all values, it's better to use the range as Maria João Rocha has suggested instead of wildcard

Max

UweFetzer_se38
Active Contributor
0 Kudos

Hi Joao,

not an answer to your question, but an advice:


SELECT *

  SELECT SINGLE *

  SELECT SINGLE *

  select *

    select *

      SELECT SINGLE *

      SELECT SINGLE *

    endselect.

  endselect.

ENDSELECT.

For performance reasons please don't use nested SELECTs and don't use "SELECT *".

former_member654002
Participant
0 Kudos

Thank you Max and Maria João.

I am gone use your solution and i will tell you the results.

Thank you uwe for your advice.

In this case what would be the best practice for the code?

Best regards

0 Kudos
  1. Instead of the nested SELECTs use database JOINs if possible
  2. only read the table fields which you really need, don't use "*" (all fields)