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

Select query for char data type

Former Member
0 Likes
1,751

Hi Gurus,

I am trying to fetch records from Z table.

Below the select query.

lv_low = '0900001'

lv_high = '0900002'

select matnr sernr into table lt_sernr

from zsd_upd_deldoc

where sernr >= lv_low and sernr <= lv_high.

but out put shows

9000010

9000011

900002

900001

9000010

9000019

9000019

9000018

9000017

9000014

9000018

9000017

Expecting O/P

900001

900002

Regards

Vinayak Sapkal

13 REPLIES 13
Read only

Former Member
0 Likes
1,642

table zsd_upd_deldoc-sernr length is 18.

Regards

Vinayak Sapkal

Read only

Former Member
0 Likes
1,642

hi,

Try to use the IN operator instead.

Read only

0 Likes
1,642

I tried with select-options and IN, but it shows similar result.

Regards

Vinayak Sapkal

Read only

0 Likes
1,642

hi, try like this

select matnr sernr into table lt_sernr

from zsd_upd_deldoc

where sernr in ('9000','9001').

select option mean all the values between low n high.

n previously also you were trying BETWEEN AND operator.

Read only

0 Likes
1,642

tables: zsd_upd_deldoc.

data: begin of lt_table occurs 0,

sign(1),

option(2),

low(18),

high(18),

end of lt_table.

DATA: ls_doc_id_range LIKE LINE OF lt_table.

FIELD-SYMBOLS: <fs> LIKE LINE OF lt_table.

ls_doc_id_range-sign = 'I'.

ls_doc_id_range-option = 'BT'.

ls_doc_id_range-low = lv_low.

ls_doc_id_range-high = lv_high.

INSERT ls_doc_id_range INTO TABLE lt_table.

  • select matnr sernr into table lt_sernr

  • from zsd_upd_deldoc

  • where sernr >= lv_low and sernr <= lv_high.

select matnr sernr into table lt_sernr

from zsd_upd_deldoc

where sernr in lt_table.

loop at lt_sernr assigning <fs_sernr>.

write: / <fs_sernr>-sernr.

endloop.

O/P

9000010

9000011

900002

900001

9000010

9000019

9000019

9000018

9000017

9000014

9000018

9000017

Regards

Vinayak Sapkal

Read only

0 Likes
1,642

Hi,

Try to do like below and try with the same code.

ls_doc_id_range-option = 'EQ'.

Regards,

Sreenivas.

Read only

0 Likes
1,642

Not succeed ...result shows as below.

O/P

900001

Regards

Vinayak Sapkal

Read only

0 Likes
1,642

Hi,

define the low and high variables with reference to the Z table and pass the values into that. Also check the data base table for how the values have been stored into that. Accordingly write your select query. If you have any conversion routines for that variable use that conversion FM before passing the values to that variables.

Thanks,

Sreeni.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,642

This is same as this question which i had some time ago

Read only

0 Likes
1,642

Database field sernr is type of gernr(Char-18).

If i use numc it will not search record '0900001' it will searches for '000000000000900001'

Regards

Vinayak Sapkal

Read only

0 Likes
1,642

As mentioned by Mark in my thread, type c will create such problems when it access the data via querying ( <,> etc ).

Read only

Former Member
0 Likes
1,642

Hi Vinayak,

Make lv_low and lv_high of type zsd_upd_deldoc-sernr as given below :

DATA : lv_low TYPE zsd_upd_deldoc-sernr,

lv_high TYPE zsd_upd_deldoc-sernr.

As sernr is of NUMC type you can assign numbers or char string to it.

lv_low = 900001.

lv_high = 900002.

Now write a select query

select matnr sernr into table lt_sernr

from zsd_upd_deldoc

where sernr >= lv_low and sernr <= lv_high.

Regards,

Pranjali

Read only

0 Likes
1,642

still shows result as given below.

O/P

9000010

9000011

900002

900001

9000010

9000019

9000019

9000018

9000017

9000014

9000018

9000017

Regards

Vinayak Sapkal