2006 Apr 18 3:19 PM
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
2006 Apr 18 3:23 PM
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.
2006 Apr 18 3:29 PM
Thanks for your quick answer, but that didn't help.
Still the same result of 5 lines in your version.
2006 Apr 18 3:43 PM
I forgot to say that using pattern 'A+555' gets the same result in both variants.
2006 Apr 18 3:55 PM
Do you get 4 lines with 'A+++'?
The '+' is a place holder for single characters. You should get consistent results with '*', though.
Rob
2006 Apr 18 4:00 PM
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
2006 Apr 18 4:04 PM
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.
2006 Apr 18 4:05 PM
2006 Apr 18 4:09 PM
So option A works, but you'd like to use B because it's more efficient?
Rob
2006 Apr 18 4:15 PM
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
2006 Apr 18 4:19 PM
> 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.
2006 Apr 18 4:21 PM
> 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
2006 Apr 18 4:24 PM
> you should use BT A1111 and AZZZZ
Thanks for your input.
Good idea, but e.g. A2 is between A1111 and AZZZZ
Regards
Norbert
2006 Apr 18 4:30 PM
> 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
2006 Apr 18 4:39 PM
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
2006 Apr 18 4:53 PM
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.
2006 Apr 18 5:28 PM
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
2006 Apr 18 5:39 PM
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
2006 Apr 19 6:52 AM
> 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
2006 Apr 18 3:45 PM
2006 Apr 18 3:49 PM
Actually it's a CHAR 10, filled from the left.
Thanks for your help
Regards
Norbert
2006 Apr 18 7:28 PM
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
2006 Apr 19 2:11 PM
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.