This website is not affiliated with, sponsored by, or approved by SAP AG.

Create Dynamic select based on table entries?possible???

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Create Dynamic select based on table entries?possible???

Postby GIGA » Tue Nov 04, 2003 5:13 pm

Hi All,

I am trying to achieve below goal.

I have created one table which contains 4 fields.
1 . from field name
2. to field name
3. option
4. value

ex. data in the table will be
1. VBEP-EDATU (Schedule line date).
2. VBEP-BDDAT ( Requirement date)
3. <
4. space

Now i need to build a select statement based on these four values in my program as
select * from vbep where edatu < bddat.

if i am adding one more extra field in the table do i need to modify my program. or dynamic building of select will take care of it.

Kindly reply.
GIGA
GIGA
 

Postby maulik » Tue Nov 04, 2003 5:25 pm

I don't think this work.

Here's an example from the documentation on how to do it.

Dynamic conditions

DATA: COND(72) TYPE C,
ITAB LIKE TABLE OF COND.

PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C.

DATA WA TYPE SPFLI-CITYFROM.

CONCATENATE 'CITYFROM = ''' CITY1 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.
APPEND COND TO ITAB.

LOOP AT ITAB INTO COND.
WRITE COND.
ENDLOOP.

SKIP.

SELECT CITYFROM
INTO WA
FROM SPFLI
WHERE (ITAB).

WRITE / WA.

ENDSELECT.
maulik
 
Posts: 138
Joined: Wed Aug 20, 2003 12:51 pm
Location: Stamford, CT, USA

Postby Guest » Wed Nov 05, 2003 9:30 am

Thanks .

now i am using this syntax .
c = 'WA_VBEP-WADAT.'.
concatenate 'EDATU' 'LT' C into string separated by space.
itab-text = string.
append itab.

data: wa_vbep like vbep.
select * from vbep
into wa_vbep
where (itab).

I am getting the dump which says that '

The current ABAP/4 program attempted to execute an ABAP/4 Open SQL
statement containing a WHERE condition of the form WHERE (itab) or
WHERE ... AND (itab). The part of the WHERE condition specified at
runtime in the internal table itab contains an invalid
value "WADAT". Literals are allowed as values, but not variables.


where i am going wrong.

Kindly help.
GIGA
Guest
 

Postby Guest » Wed Nov 05, 2003 10:02 am

Anonymous wrote:Thanks .

now i am using this syntax .
c = 'WA_VBEP-WADAT.'.
concatenate 'EDATU' 'LT' C into string separated by space.
itab-text = string.
append itab.

data: wa_vbep like vbep.
select * from vbep
into wa_vbep
where (itab).

I am getting the dump which says that '

The current ABAP/4 program attempted to execute an ABAP/4 Open SQL
statement containing a WHERE condition of the form WHERE (itab) or
WHERE ... AND (itab). The part of the WHERE condition specified at
runtime in the internal table itab contains an invalid
value "WADAT". Literals are allowed as values, but not variables.


where i am going wrong.

Kindly help.
GIGA


I think up to Basis Releas 6.10 (and I assume you are on 4.6c) it is not possible to define a dynamic where condition with variables only with literals (as the error message states) . So in my opinion you did nothing wrong it just does not work that way.
As a possible workaround I would suggest to define a generated subroutine pool (search for that keyword).
Christian
Guest
 

Postby Hans-Hermann » Wed Nov 05, 2003 10:44 am

Christian is right, you will have to use a literal:
Code: Select all
concatenate '''' wa_vbep-wadat '''' into c.
...
Hans-Hermann
 

Postby Guest » Wed Nov 05, 2003 4:08 pm

Thanks guys..
it's working.

GIGA
Guest
 

Re: Create Dynamic select based on table entries?possible???

Postby Crawling5 » Thu Jan 27, 2011 3:03 pm

I think that your error is because you concatenate a "." at the end of the variable and you also put an explicit "." at the end of the WHERE statement.

Regards
Crawling5
 
Posts: 1
Joined: Thu Jan 27, 2011 3:00 pm

Re: Create Dynamic select based on table entries?possible???

Postby VLozano » Fri Jan 28, 2011 2:32 am

Image
Tuly Idiots
Because we know we are part of the problem
VLozano
 
Posts: 5140
Joined: Mon Sep 13, 2004 8:17 am
Location: Idiocity

Re: Create Dynamic select based on table entries?possible???

Postby Rich » Fri Jan 28, 2011 4:58 am

VLozano wrote:Image


Image what ? Or is that dead as well ??? :cry:
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com
Rich
 
Posts: 7112
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool

Re: Create Dynamic select based on table entries?possible???

Postby Gothmog » Fri Jan 28, 2011 5:20 am

One of Vic's famous necroposting images - but the forum it's hosted on must be blocked from your site.
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1942
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: Create Dynamic select based on table entries?possible???

Postby YuriT » Sat Jan 29, 2011 6:17 pm

Hmmm. Is this a record? 8 years.
YuriT
 
Posts: 885
Joined: Fri Feb 03, 2006 6:40 am
Location: Basel/Riga


Return to ABAP

Who is online

Users browsing this forum: Google Adsense [Bot] and 8 guests



cron


This website is not affiliated with, sponsored by, or approved by SAP AG.