Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8533

Dynamic where clause possible field type issue

$
0
0

Hi all maybe someone has some idea on an issue that I have concerning a dynamic where clause.

 

The requirement I have is to query a table only to see if records exist.

The table, fields and values are all taken from a customising table.

 

The code I use for the where clause is

*   Build the query WHERE clause
     CONCATENATE 'MANDT' ' = ' sy-mandt ' AND ' INTO lw_where_clause RESPECTING BLANKS.
     LOOP AT li_parameter_tab INTO lw_parameter.
       lw_tabix = sy-tabix.
       READ TABLE li_field_tab INTO lw_field INDEX lw_tabix.
       IF ( lw_tabix = 1 ).
         CONCATENATE lw_where_clause lw_parameter ' = ' '''' lw_field '''' INTO lw_where_clause RESPECTING BLANKS.
       ELSE.
         CONCATENATE ' ' lw_where_clause ' AND ' lw_parameter ' = ' '''' lw_field '''' INTO lw_where_clause RESPECTING BLANKS.
       ENDIF.
     ENDLOOP.

The actual clause looks good when being debugded.


The issue is with the lw_field parameter, during testing I found that if the lw_field was not surrounded by quotes some values would through a short dump.


In my test example I was using

Table = LFB1

BURKS = 9999

LIFNR = 123456

This seemed to work, with no short dump, in my actual data I also has LIFNRs of for example 123456_1, these would always through a short dump, I am assuming because of the _, so then I encased the fields in quotes. This stopped the short dump, but I noticed that I would not get any positive hits from my query even though I knew there were matching records in the database.

The issue is that LIFNR is a char10 field, in the example above if I used 0000123456 as LIFNR everything would be fine, this I think would be possible to achive.

Except that the table used could be any table and the fields any fields from that table (although normally key values).

I have the table and structure of the table in field symbol variables, could I use this somehow to get the type of the fields that I have passed and then create variables of these types and 'copy'/'move' the data from lw_field into this new variable, in the hope that I could remove the quotes from the where clause, hoping that would mean the query would function as I need.

Is this possible or is there another way of creating the where clause that would work out of the box.


Any help would be appreciated.


Ian


Viewing all articles
Browse latest Browse all 8533

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>