Application Development and Automation 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: 
Read only

Function/Subrutine and where clause

Former Member
0 Likes
702

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
Read only

Clemenss
Active Contributor
0 Likes
671

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
Read only

former_member156446
Active Contributor
0 Likes
671

I doubt if its possible..

check the syntax of select.

Read only

Clemenss
Active Contributor
0 Likes
672

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

Read only

Former Member
0 Likes
671

Its not possible.

Regards,

Chandru

Read only

0 Likes
671

Hi all,

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

Regards,

Kit