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: 

help in daynamic select

Former Member
0 Kudos

hi,

i wont to do one select instead of this both,

in every select i use 2 diff tables in from (table_selection)

one i have 2 use is dim_navatr001 and 2 dim0costcenter .

how i can do that?

Regards

SELECT (field_selection)

FROM (table_selection)

INTO TABLE <dy_actual>

FOR ALL ENTRIES IN l_tab

WHERE dim_navatr001 = l_tab-dim0costcenter

AND dim0calmonth IN g_m_a.

SELECT (field_selection)

FROM (table_selection)

INTO TABLE <dy_actual>

FOR ALL ENTRIES IN l_tab

WHERE dim0costcenter = l_tab-dim0costcenter

AND dim0calmonth IN g_m_a.

i can do that?

Regards

1 ACCEPTED SOLUTION

JozsefSzikszai
Active Contributor
0 Kudos

hi,

did you try on your own before posting?

WHERE ( dim_navatr001 = l_tab-dim0costcenter
OR dim0costcenter = l_tab-dim0costcenter )
AND dim0calmonth IN g_m_a.

ec

10 REPLIES 10

JozsefSzikszai
Active Contributor
0 Kudos

hi,

did you try on your own before posting?

WHERE ( dim_navatr001 = l_tab-dim0costcenter
OR dim0costcenter = l_tab-dim0costcenter )
AND dim0calmonth IN g_m_a.

ec

0 Kudos

Hi Eric,

i try it but i get Dump.

Regards

0 Kudos

what says the dump?

0 Kudos

Hi Eric,

i have 2 database tables that had the same structure exactly

except one field e.g.

datb1

pernr

DIM0COSTCENTER

persg

....

datb2

pernr

DIM_NAVATR001

persg

....

the error is when i do select from datb2 :

An Open SQL clause was specified dynamically. The contained field name

"DIM0COSTCENTER" does not exist in any of the database tables from the FROM

clause.

and for select datb1

An Open SQL clause was specified dynamically. The contained field name

"DIM_NAVATR001" does not exist in any of the database tables from the FROM

clause.

Regards

0 Kudos

OK, I understand it better now...

To select from 2 database tables you either make a JOIN, but I don't think it makes any sense now. The other solution is to build up a dynamic where and call the select twice:

roughly:

dyn_where = 'dim_navatr001 = l_tab-dim0costcenter AND dim0calmonth IN g_m_a'.
PERFORM select USING field_selection.table_selection dyn_where.

dyn_where = ...
PERFORM select USING field_selection.table_selection dyn_where.

FORM select USING ....

SELECT (field_selection)
FROM (table_selection)
INTO TABLE <dy_actual>
FOR ALL ENTRIES IN l_tab
WHERE (dyn_where)

ENDFORM.

Former Member
0 Kudos

try something like this...

SELECT (field_selection)

FROM (table_selection) as a

INNER JOIN (table_selection) as b on adim_navatr001 = bdim0costcenter

WHERE a~dim_navatr001 = l_tab-dim0costcenter

AND dim0calmonth IN g_m_a.

Former Member
0 Kudos

Hi,

Declare an internal table for where cond.

data: begin of wtab,

text type string,

end of wtab,

whrtab type standard table of wtab.

wtab-text = 'dim_navatr001 = l_tab-dim0costcenter AND dim0calmonth IN g_m_a'.

append wtab to whrtab.

perform select_query tables whrtab.

clear wtab.

refresh whrtab.

wtab-taxt = 'dim0costcenter = l_tab-dim0costcenter AND dim0calmonth IN g_m_a'.

append wtab to whrtab.

perform select_query tables whrtab.

form select_query tables whrtab structure wtab.

SELECT (field_selection)

FROM (table_selection)

INTO TABLE <dy_actual>

FOR ALL ENTRIES IN l_tab

WHERE (whrtab).

regards,

Subramanian

0 Kudos

Hi Subramanian PL ,

i try it but i have error :

Table "WHRTAB" must have a character-like row type (data type C, N, D,T, or STRING)

Regards

Former Member
0 Kudos

Are both field_selection and table_selection the same in both SELECTs?

Rob

0 Kudos

Hi Rob,

i have 2 database tables that had the same structure exactly

except one field e.g.

datb1

pernr

DIM0COSTCENTER

persg

....

datb2

pernr

DIM_NAVATR001

persg

....