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: 

Function/Subrutine and where clause

Former Member
0 Kudos

Hi,

Is it possible to define a subroutine.function and use it in the SQL where clause in ABAP??

If so, any reference code??

Regards,

Kit

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi Kit,

It is not possible to define a subroutine.function and use it in the SQL where clause in ABAP.

But you can use dynamic where clause. Try F1 on select.


Example

Display of flight connections after input of airline and flight number:


PARAMETERS: carr_id TYPE spfli-carrid,
            conn_id TYPE spfli-connid.

DATA:       where_clause TYPE  STRING,
            and(4),
            wa_spfli TYPE spfli.

IF carr_id IS NOT INITIAL.
  CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
  and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
  CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
    INTO where_clause.
ENDIF.

SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
  WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
           wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT. 

Regards,

Clemens

4 REPLIES 4

former_member156446
Active Contributor
0 Kudos

I doubt if its possible..

check the syntax of select.

Clemenss
Active Contributor
0 Kudos

Hi Kit,

It is not possible to define a subroutine.function and use it in the SQL where clause in ABAP.

But you can use dynamic where clause. Try F1 on select.


Example

Display of flight connections after input of airline and flight number:


PARAMETERS: carr_id TYPE spfli-carrid,
            conn_id TYPE spfli-connid.

DATA:       where_clause TYPE  STRING,
            and(4),
            wa_spfli TYPE spfli.

IF carr_id IS NOT INITIAL.
  CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
  and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
  CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
    INTO where_clause.
ENDIF.

SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
  WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
           wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT. 

Regards,

Clemens

Former Member
0 Kudos

Its not possible.

Regards,

Chandru

0 Kudos

Hi all,

How about define a function in database lavel and execute it in ABAP??

Regards,

Kit