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

Read table with syntax error

Former Member
0 Likes
824

I would like to have this in my report in ABAP 7:

READ TABLE ti_prococolos WITH KEY

protocol = lc_protocol

status = 'abc'

status = 'ced'.

But I receive the following error, when verifying the syntax:

Key field "STATUS" has been used more than once. This is not allowed .

How can I solve this?

Thanks!

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
657

The READ statement is used to read a specific row of the internal table, in this case it appears that you are saying that you want a record if the STATUS is either abc or def. You can't do that with the READ. You would need to use the LOOP.

Loop at ti_prococolos where protocol = lc_protocal
                                    and ( status = 'abc' or status = 'ced' ).

* do what ever here, and EXIT after since you only want one row.
EXIT.

endloop.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
657

When you read with KEY, the field can have only one value for the FIELD.

In your case, you've to open a loop or use two separate READ statements ie one for each value..

Arya

Read only

ferry_lianto
Active Contributor
0 Likes
657

Hi,

Please try this.


ranges: r_status for ti_prococolos-status.

r_status-sign = 'I'.
r_status-option ='EQ'.
r_status-low = 'abc'.
append r_status.

r_status-sign = 'I'.
r_status-option ='EQ'.
r_status-low = 'ced'.
append r_status.

READ TABLE ti_prococolos WITH KEY
protocol = lc_protocol
status in r_status.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
657

Try:

sort ti_prococolos by protocol status.
READ TABLE ti_prococolos WITH KEY
  protocol = lc_protocol
  status = 'abc'
  BINARY SEARCH.

IF sy-subrc <> 0.
  READ TABLE ti_prococolos WITH KEY
    protocol = lc_protocol
    status = 'ced'
    binary search.
ENDIF.

Rob

Read only

Former Member
0 Likes
657

Thank you!

I used read and if option.