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: 

Different behavior: SELECT where IN pattern / check it_tab-f IN pattern

norbert_weber
Explorer
0 Kudos
514

scenario:

I use the pattern 'A++++' in the select-option so_akey.

Table ztab has 5 entries with the following key:

AAB4

AAC4

AAD4

AAE4

A5555

problem

I get different results by using

a) RESULT: 1 line (A5555)

select * from ztab where akey IN so_akey.

write ztab.

endselect.

and b) RESULT 5 lines (all entries)

select * from ztab into TABLE it_ztab.

loop at it_ztab.

check it_ztab-akey IN so_akey.

write ztab.

endloop.

Any ideas?

Actually I need both variants. How can I manipulate so_akey, just before excution comes to b), so b) shows the same results as a) ?

Regards

Norbert

22 REPLIES 22

former_member181962
Active Contributor
0 Kudos
418

loop at it_ztab.

<b>check it_ztab-akey IN so_akey.</b>

write ztab.

endloop.

The high lighted code will be succesfull all the time(For all the five records and hence you are getting five records.

Do this way

select * from ztab into TABLE it_ztab.

loop at it_ztab where akey IN so_akey.

write: it_ztab.

endloop.

0 Kudos
418

Thanks for your quick answer, but that didn't help.

Still the same result of 5 lines in your version.

0 Kudos
418

I forgot to say that using pattern 'A+555' gets the same result in both variants.

0 Kudos
418

Do you get 4 lines with 'A+++'?

The '+' is a place holder for single characters. You should get consistent results with '*', though.

Rob

0 Kudos
418

Yes I do get 4 lines with 'A+++'.

I want to get all records starting with 'A' AND have a length of 5.

Thanks again for your help

Regards

Norbert

0 Kudos
418

HOw about using the like addition?

concatenate 'A%' into v_pattern.

select *

from ztable

into table it_ztab

where: field like v_pattern.

loop at it_ztab.

if strlen(it_ztab-field) = 5.

write:/ it_ztab-field.

endif.

endloop.

0 Kudos
418

you should use BT A1111 and AZZZZ

0 Kudos
418

So option A works, but you'd like to use B because it's more efficient?

Rob

0 Kudos
418

hi,

b) is correct:

your criterium is 'A++++'

-> so all lines beginning with A are selected

-> it's all the same if length is 4,5, or higher1

try it with 'A' OR 'A1' in your table.

i think by a) the field is not inatialized with

blanks!? on DB

What happens by se16 / se16n

Andreas

0 Kudos
418

> So option A works, but you'd like to use B because

> it's more efficient?

>

> Rob

Difficult to explain.

No, it's not a question of efficiency of performance.

It's a quite huge program (> 20.000 lines) and I need both version because it's of lot of work to change the program by using one option only.

0 Kudos
418

> hi,

>

> b) is correct:

> your criterium is 'A++++'

> -> so all lines beginning with A are selected

> -> it's all the same if length is 4,5, or higher1

> try it with 'A' OR 'A1' in your table.

>

> i think by a) the field is not inatialized with

> blanks!? on DB

>

> What happens by se16 / se16n

>

> Andreas

Hi Andeas,

se16 works like a), so why should b) correct?

Thanks for your help.

Regards

Norbert

0 Kudos
418

> you should use BT A1111 and AZZZZ

Thanks for your input.

Good idea, but e.g. A2 is between A1111 and AZZZZ

Regards

Norbert

0 Kudos
418

> HOw about using the like addition?

>

> concatenate 'A%' into v_pattern.

> select *

> from ztable

> into table it_ztab

> where: field like v_pattern.

>

> loop at it_ztab.

> if strlen(it_ztab-field) = 5.

> write:/ it_ztab-field.

> endif.

> endloop.

Thank you for your input.

It seems very complex for me to make a more general code by this, but I'll think about that.

Regards

Norbert

0 Kudos
418

I think there's something else going on here. I get the same results for both options in:


REPORT ztest MESSAGE-ID zc.

TABLES: stxh.

RANGES: r_obj FOR stxh-tdobject.

DATA: BEGIN OF stxh_int OCCURS 0.
        INCLUDE STRUCTURE stxh.
DATA: END   OF stxh_int.

CLEAR   r_obj.
MOVE 'A+++'   TO r_obj-low.
MOVE 'CP'     TO r_obj-option.
MOVE 'I'      TO r_obj-sign.
APPEND  r_obj.

SELECT * FROM stxh
    WHERE tdobject IN r_obj.
  IF stxh-tdobject <> 'AUFK'.
    break rburbank.
  ENDIF.
ENDSELECT.

SELECT * FROM stxh
  INTO TABLE stxh_int
  ORDER BY tdobject.

LOOP AT stxh_int.
  IF stxh_int-tdobject IN r_obj.
    IF stxh_int-tdobject <> 'AUFK'.
      break rburbank.
    ENDIF.
  ENDIF.
ENDLOOP.

Rob

0 Kudos
418

Hi Rob,

Thank you for your patience.

I thing you w'll get different results if you use a pattern wich selects less records with e.g. 'A++++' than

'A+++'.

I tried the following and there are still differences between select and loop:

REPORT ZNW_TEST_6 .

TABLES: stxh.

DATA it_stxh_so LIKE stxh OCCURS 0 WITH HEADER LINE.

DATA it_stxh LIKE stxh OCCURS 0 WITH HEADER LINE.

DATA: i_cnt TYPE i.

SELECT-OPTIONS:

so_tdobj FOR stxh-tdobject.

************************************************************************

START-OF-SELECTION.

*******************

SELECT * FROM stxh

WHERE tdobject IN so_tdobj.

WRITE stxh.

ADD 1 TO i_cnt.

ENDSELECT.

ULINE.

WRITE: 'SELECT:', i_cnt.

ULINE.

ULINE.

i_cnt = 0.

SELECT * FROM stxh INTO TABLE it_stxh.

LOOP AT it_stxh.

CHECK it_stxh-tdobject IN so_tdobj.

WRITE it_stxh.

ADD 1 TO i_cnt.

ENDLOOP.

ULINE.

WRITE: 'LOOP:', i_cnt.

0 Kudos
418

OK - I see what you mean. Now I get different results (but I really don't know why).

You could get the second example to work like the first one if you exclude entries that don't have the same length as the range table LOW field (assuming there's only one entry in it).

Rob

0 Kudos
418

This is messy, but it should do what you want. I wasn't able to test this, so you'll have to check it thoroughly:


REPORT ztest MESSAGE-ID 00.

SELECT-OPTIONS so_akey FOR ztab-akey.

DATA: counter TYPE i,
      l1      TYPE i,
      l2      tyep i.

DESCRIBE TABLE so_akey LINES counter.
IF counter <> 1.
  MESSAGE e001.
ELSE.
  READ TABLE so_akey INDEX 1.
  l1 = strlen( so_akey-low ).
ENDIF.

SELECT * FROM ztab INTO TABLE it_ztab.
LOOP AT it_ztab.
  l2 = strlen( it_ztab-akey ).
  CHECK it_ztab-akey IN so_akey AND
        l2 = l1.
  WRITE ztab.
ENDLOOP.

Rob

0 Kudos
418

> OK - I see what you mean. Now I get different results

> (but I really don't know why).

>

> You could get the second example to work like the

> first one if you exclude entries that don't have the

> same length as the range table LOW field (assuming

> there's only one entry in it).

>

> Rob

Hi Rob,

Thank you for your help.

Actually I hoped there is more general solution for this problem, because the user is free to fill the option parameter.

I'll start a support case and will be back here when I got an answer.

Best Regards

Norbert Weber

Former Member
0 Kudos
418

Is the actual key length 4, 5 or longer?

Rob

0 Kudos
418

Actually it's a CHAR 10, filled from the left.

Thanks for your help

Regards

Norbert

Former Member
0 Kudos
418

Try the follow:

Instead of select-options for so_akey, use parameters with default value 'A++++'.

select * from ztab where akey LIKE p_akey.

write ztab.

endselect.

Hope this helps.

thanks,

vamshi tallada

norbert_weber
Explorer
0 Kudos
418

Well, I did some research:

In help 'CP' I found this statement:

"... 'ABC' CP 'ABC+' is false, ..."

That is exactly what I expected from:

b) "check it_ztab-akey IN so_akey"

but this checks 'AAB4' CP 'AAB4+' as TRUE!

Why it's not working as described?

BECAUSE: it_ztab-akey is type char(10)!!

Using a STRING works as expected!

Here in my test only the char10 variante says 'true'.

Best Regards

Norbert

DATA: cc1(10), cc2(10).

DATA: strc1 TYPE string, strc2 TYPE string .

IF 'ABC' CP 'ABC+'.

WRITE 'Konstante: ABC CP ABC+ = true'.

ENDIF.

cc1 = 'ABC'.

cc2 = 'ABC+'.

IF cc1 CP cc2.

WRITE 'Variable cC1 char 10: ABC CP ABC+ = true'.

ENDIF.

strc1 = cc1.

strc2 = cc2.

IF strc1 CP strc2.

WRITE 'Variable strC1 string: ABC CP ABC+ = true'.

ENDIF.