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

Performing a Select Using 'IN' with an Internal Table

Former Member
0 Likes
2,905

Hello

I defined an internal table called tempbeh. I am able to fill the table with values.

However, I do get an error with the second select. There is a problem with the code snippet

AND beh_unique_id NOT IN tempbeh..

I am being told that the row structure of the table tempbeh is not correct.

I do NOT get any errors when I remove the code

AND beh_unique_id NOT IN tempbeh.

Any ideas........ I'd do a prayer if somebody could help, and make me understand why I get an error in the first place.

Thank you very much....Robert

Here is the code:



DATA: BEGIN OF tempbeh OCCURS 1,
        beh like zwopti_bv_out-BEH_UNIQUE_ID,
      END OF tempbeh.
...
 SELECT beh_unique_id FROM zwopti_bv_out
      INTO tempbeh
      WHERE udate IN s_dat.
      APPEND tempbeh.
    ENDSELECT.


SELECT
    zw~beh_unique_id zw~udate
    zw~utime zw~longitude zw~latitude
    zw~process zw~state zw~hint_nr
    zw~hint_txt zw~anl_unique_id
    zw~stp_unique_id zw~ordernr
    zw~order_laufnr zw~aedat
    zw~zztransp_nr
    zw~adrkey z5~tournr
    z10~abfallart
    z5~rmnr
    zwopti_eapos_in~sequence
    equi~zzgroesse
    zws09~behkennung
    zws09~beschreib



    FROM zwopti_bv_out AS zw
    Inner JOIN zwt05 AS z5 ON zw~ordernr = z5~tourid
    LEFT OUTER JOIN zwt10 AS z10
    ON zw~ordernr = z10~tourid AND zw~order_laufnr = z10~tourelemnr
    LEFT OUTER JOIN zwopti_eapos_in
    ON zw~quell_key = zwopti_eapos_in~quell_key
    INNER JOIN equi ON zw~beh_unique_id = equi~equnr
    INNER JOIN zws09 ON equi~zzfatyp = zws09~behkennung


      INTO  TABLE lt_bv_out
      WHERE beh_unique_id     IN s_sernr
      AND   equi~zzgroesse    IN s_behgr
      AND   zw~zztransp_nr    IN s_tid
      AND   stp_unique_id     IN s_stpl
      AND   zw~adrkey         IN x_adrkey
      AND   z5~tournr         IN s_tour
      AND   zw~hint_nr        IN s_hint
      AND   zws09~behkennung  IN s_behart
      AND   beh_unique_id NOT IN tempbeh.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
1,785

First - get out of the habit of using tables with header-lines - it's bad programming practice. Define tempbeh as a RANGE. Then it will have components - SIGN, OPTION, LOW and HIGH. Just like select options, and then it will work with IN.

And you should give it a better name - perhaps indicating that it is a range:

DATA: r_tempbeh TYPE RANGE OF zwopti_bv_out-beh_unique_id.

DATA: lt_tempbeh TYPE STANDARD TABLE zwopti_bv_out-beh_unique_id
                           WITH NON-UNIQUE KEY header_line.

DATA: ls_r_tempbeh LIKE LINE OF r_tempbeh.

SELECT beh_unique_id FROM zwopti_bv_out
      INTO TABLE lt_tempbeh
      WHERE udate IN s_dat.

ls_r_tempbeh-sign = 'I'.
ls_r_tempbeh-option = 'EQ'.
LOOP AT lt_tempbeh INTO ls_r_tempbeh-low.
  INSERT ls_r_tempbeh INTO TABLE lt_tempbeh.
ENDLOOP.

....
" Now the important bit of your WHERE clause
           AND   beh_unique_id NOT IN ls_r_tempbeh.

matt

Hello

I defined an internal table called tempbeh. I am able to fill the table with values.

However, I do get an error with the second select. There is a problem with the code snippet

AND beh_unique_id NOT IN tempbeh..

I am being told that the row structure of the table tempbeh is not correct.

I do NOT get any errors when I remove the code

AND beh_unique_id NOT IN tempbeh.

Any ideas........ I'd do a prayer if somebody could help, and make me understand why I get an error in the first place.

Thank you very much....Robert

Here is the code:



DATA: BEGIN OF tempbeh OCCURS 1,
        beh like zwopti_bv_out-BEH_UNIQUE_ID,
      END OF tempbeh.
...
 SELECT beh_unique_id FROM zwopti_bv_out
      INTO tempbeh
      WHERE udate IN s_dat.
      APPEND tempbeh.
    ENDSELECT.


SELECT
    zw~beh_unique_id zw~udate
    zw~utime zw~longitude zw~latitude
    zw~process zw~state zw~hint_nr
    zw~hint_txt zw~anl_unique_id
    zw~stp_unique_id zw~ordernr
    zw~order_laufnr zw~aedat
    zw~zztransp_nr
    zw~adrkey z5~tournr
    z10~abfallart
    z5~rmnr
    zwopti_eapos_in~sequence
    equi~zzgroesse
    zws09~behkennung
    zws09~beschreib



    FROM zwopti_bv_out AS zw
    Inner JOIN zwt05 AS z5 ON zw~ordernr = z5~tourid
    LEFT OUTER JOIN zwt10 AS z10
    ON zw~ordernr = z10~tourid AND zw~order_laufnr = z10~tourelemnr
    LEFT OUTER JOIN zwopti_eapos_in
    ON zw~quell_key = zwopti_eapos_in~quell_key
    INNER JOIN equi ON zw~beh_unique_id = equi~equnr
    INNER JOIN zws09 ON equi~zzfatyp = zws09~behkennung


      INTO  TABLE lt_bv_out
      WHERE beh_unique_id     IN s_sernr
      AND   equi~zzgroesse    IN s_behgr
      AND   zw~zztransp_nr    IN s_tid
      AND   stp_unique_id     IN s_stpl
      AND   zw~adrkey         IN x_adrkey
      AND   z5~tournr         IN s_tour
      AND   zw~hint_nr        IN s_hint
      AND   zws09~behkennung  IN s_behart
      AND   beh_unique_id NOT IN tempbeh.

9 REPLIES 9
Read only

matt
Active Contributor
1,786

First - get out of the habit of using tables with header-lines - it's bad programming practice. Define tempbeh as a RANGE. Then it will have components - SIGN, OPTION, LOW and HIGH. Just like select options, and then it will work with IN.

And you should give it a better name - perhaps indicating that it is a range:

DATA: r_tempbeh TYPE RANGE OF zwopti_bv_out-beh_unique_id.

DATA: lt_tempbeh TYPE STANDARD TABLE zwopti_bv_out-beh_unique_id
                           WITH NON-UNIQUE KEY header_line.

DATA: ls_r_tempbeh LIKE LINE OF r_tempbeh.

SELECT beh_unique_id FROM zwopti_bv_out
      INTO TABLE lt_tempbeh
      WHERE udate IN s_dat.

ls_r_tempbeh-sign = 'I'.
ls_r_tempbeh-option = 'EQ'.
LOOP AT lt_tempbeh INTO ls_r_tempbeh-low.
  INSERT ls_r_tempbeh INTO TABLE lt_tempbeh.
ENDLOOP.

....
" Now the important bit of your WHERE clause
           AND   beh_unique_id NOT IN ls_r_tempbeh.

matt

Read only

Former Member
0 Likes
1,785

hi,

Try this code...

SELECT

zwbeh_unique_id zwudate

zwutime zwlongitude zw~latitude

zwprocess zwstate zw~hint_nr

zwhint_txt zwanl_unique_id

zwstp_unique_id zwordernr

zworder_laufnr zwaedat

zw~zztransp_nr

zwadrkey z5tournr

z10~abfallart

z5~rmnr

zwopti_eapos_in~sequence

equi~zzgroesse

zws09~behkennung

zws09~beschreib

FROM zwopti_bv_out AS zw

Inner JOIN zwt05 AS z5 ON zwordernr = z5tourid

LEFT OUTER JOIN zwt10 AS z10

ON zwordernr = z10tourid AND zworder_laufnr = z10tourelemnr

LEFT OUTER JOIN zwopti_eapos_in

ON zwquell_key = zwopti_eapos_inquell_key

INNER JOIN equi ON zwbeh_unique_id = equiequnr

INNER JOIN zws09 ON equizzfatyp = zws09behkennung

INTO TABLE lt_bv_out

WHERE beh_unique_id IN s_sernr

AND equi~zzgroesse IN s_behgr

AND zw~zztransp_nr IN s_tid

AND stp_unique_id IN s_stpl

AND zw~adrkey IN x_adrkey

AND z5~tournr IN s_tour

AND zw~hint_nr IN s_hint

AND zws09~behkennung IN s_behart

AND beh_unique_id NOT IN tempbeh-beh_unique.

U have to declare the fieldname with the internal table, that is why it shows u error. Now copy the above code and paste it..

Success..

Read only

former_member585060
Active Contributor
0 Likes
1,785

tempbeh it is a internal table not a Select option field, thats why u r getting error.

IN and NOT IN is ued in where clause for SELECT-OPTION fields, which has table structure with fields

SIGN

OPTION

LOW

HIGH

of any field.

Read only

Former Member
0 Likes
1,785

Thanks for the easy and complicated solutions.

Now I am gonna dig into matts solution, because I still have to learn a lot

Thanks a lot guys

Bye

Robert

Read only

Former Member
0 Likes
1,785

Sorry,

AND beh_unique_id <> tempbeh-beh_unique_id.

Use this..

Success...

Read only

0 Likes
1,785

thank you mevin, I'll check it out

but it looks kinda funny........

Edited by: Robert Steiner on Aug 22, 2008 2:36 PM

Read only

0 Likes
1,785

The Ranges is the right procedure.. but if u use internal tables..

use this

AND beh_unique_id NE tempbeh-beh_unique_id.

Success....

Read only

0 Likes
1,785

Thanks for pointing it out............ bye

Read only

former_member404244
Active Contributor
0 Likes
1,785

Hi,

Try like this....

ranges : r_tempbeh for <tablename>-beh_unique_id.

r_tempbeh-sign = 'I'.

r_tempbeh-option = 'EQ'.

SELECT beh_unique_id FROM zwopti_bv_out

INTO tempbeh

WHERE udate IN s_dat.

APPEND tempbeh.

r_tempbeh-LOW = beh_unique_id .

APPEND R_TEMPBEH.

ENDSELECT.

SELECT

zwbeh_unique_id zwudate

zwutime zwlongitude zw~latitude

zwprocess zwstate zw~hint_nr

zwhint_txt zwanl_unique_id

zwstp_unique_id zwordernr

zworder_laufnr zwaedat

zw~zztransp_nr

zwadrkey z5tournr

z10~abfallart

z5~rmnr

zwopti_eapos_in~sequence

equi~zzgroesse

zws09~behkennung

zws09~beschreib

FROM zwopti_bv_out AS zw

Inner JOIN zwt05 AS z5 ON zwordernr = z5tourid

LEFT OUTER JOIN zwt10 AS z10

ON zwordernr = z10tourid AND zworder_laufnr = z10tourelemnr

LEFT OUTER JOIN zwopti_eapos_in

ON zwquell_key = zwopti_eapos_inquell_key

INNER JOIN equi ON zwbeh_unique_id = equiequnr

INNER JOIN zws09 ON equizzfatyp = zws09behkennung

INTO TABLE lt_bv_out

WHERE beh_unique_id IN s_sernr

AND equi~zzgroesse IN s_behgr

AND zw~zztransp_nr IN s_tid

AND stp_unique_id IN s_stpl

AND zw~adrkey IN x_adrkey

AND z5~tournr IN s_tour

AND zw~hint_nr IN s_hint

AND zws09~behkennung IN s_behart.

DELETE LV_BV_OUT WHERE beh_unique_id NOT IN R_TEMPBEH.

Regards,

Nagaraj