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

Regarding Read statement

Former Member
0 Likes
1,228

Hi ,

iam getting syntax error please suggest

read table tbl_bseg with key buzid = ( 'W' OR 'T' OR 'S' ) BINARY SEARCH.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,179

Hi,

YOu can't take the multiple values at at time.

instead take the ranges for those values an compare..

like

Ranges: r_buzid   for xxx-buzid   " consider your table

r_buzid-sign = 'I'
r_buzid-option = 'EQ'
r_buzid-low = 'W'.
append r_buzid.

r_buzid-sign = 'I'
r_buzid-option = 'EQ'
r_buzid-low = 'T'.
append r_buzid.

r_buzid-sign = 'I'
r_buzid-option = 'EQ'
r_buzid-low = 'S'.
append r_buzid.


read table tbl_bseg with key buzid = r_buzid BINARY SEARCH.

hope it works.

Regards!

10 REPLIES 10
Read only

Former Member
0 Likes
1,180

Hi,

YOu can't take the multiple values at at time.

instead take the ranges for those values an compare..

like

Ranges: r_buzid   for xxx-buzid   " consider your table

r_buzid-sign = 'I'
r_buzid-option = 'EQ'
r_buzid-low = 'W'.
append r_buzid.

r_buzid-sign = 'I'
r_buzid-option = 'EQ'
r_buzid-low = 'T'.
append r_buzid.

r_buzid-sign = 'I'
r_buzid-option = 'EQ'
r_buzid-low = 'S'.
append r_buzid.


read table tbl_bseg with key buzid = r_buzid BINARY SEARCH.

hope it works.

Regards!

Read only

Former Member
0 Likes
1,179

Hi,

First make ranges as Prashant said above, then in the loop of range read the table.

Thanks,

Krishna...

Read only

Former Member
0 Likes
1,179

Check the follwoing test code

DATA: BEGIN OF it OCCURS 10,
  name(1),
  END OF it.

it-name = 'A'.
APPEND it TO it.
it-name = 'Z'.
APPEND it TO it.
it-name = 'C'.
APPEND it TO it.
it-name = 'D'.
APPEND it TO it.
it-name = 'X'.
APPEND it TO it.
it-name = 'Y'.
APPEND it TO it.

SORT it BY name.


READ TABLE it INTO it WITH KEY name = 'A' BINARY SEARCH.
IF sy-subrc EQ 0.
  WRITE: / 'Read Table',  it-name.
ENDIF.
*if you want read more records from internal table using one key field than you must use Loop at

LOOP AT it INTO it WHERE name = 'A' OR name = 'C'.
  WRITE: / 'Loop At',  it-name.
ENDLOOP.

Edited by: tahir naqqash on Feb 23, 2009 10:05 AM

Edited by: tahir naqqash on Feb 23, 2009 10:08 AM

Read only

Former Member
0 Likes
1,179

Hi,

Read statement is not conditional . You can use rangrs or loop at the internal table and put the restrictions in where clause. Also , sort the internal table before reading it.Sorting and reading sequence should be same ; otherwise binary search may not work properly.

Read only

Former Member
0 Likes
1,179

hi,

You can use " if " and "Sy-subrc" in combination to "read " the data with all the OR clause.

This time of Read statement that u have used will not work.

Thanks

Suraj

Read only

Former Member
0 Likes
1,179

This message was moderated.

Read only

Former Member
0 Likes
1,179

Hi:

In read syntax, AND / Or is not appilcable so you have to check the required conditions put it under loop.

Regards

Shashi

Read only

Former Member
0 Likes
1,179

hi,

in read staement conditional operators are not allowed.U insert that inro one range variable.then loop on tht range.

Read only

Former Member
0 Likes
1,179

Hi ,

1. If possible, you can get data only for BUZID = 'W' , 'T' or 'S' while selecting the data at first step itself.

2. If step not possible, then you can write following loop statement.

LOOP AT tbl_bseg WHERE ( buzid eq 'W'

or buzid eq 'T'

or buzid eq 'S' ).

Process as per your requirement.

        • Here if you have requirement like, you have to process only 1 record, then just getting once into

        • loop, after first processing you use 'EXIT'.

        • Let me know your requirement.

ENDLOOP.

Read only

Former Member
0 Likes
1,179

Hi ,

1. If possible, you can get data only for BUZID = 'W' , 'T' or 'S' while selecting the data at first step itself.

2. If step not possible, then you can write following loop statement.

LOOP AT tbl_bseg WHERE ( buzid eq 'W'

or buzid eq 'T'

or buzid eq 'S' ).

Process as per your requirement.

        • Here if you have requirement like, you have to process only 1 record, then just getting once into

        • loop, after first processing you use 'EXIT'.

        • Let me know your requirement.

ENDLOOP.