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: 

Read Statement in internal table

0 Kudos

program:

REPORT ZDEMO.
DATA: BEGIN OF REC,
COL1 TYPE I,
COL2 TYPE I,
END OF REC.
DATA:ITAB1 LIKE TABLE OF REC WITH NON-UNIQUE KEY COL1.
DO 3 TIMES.
REC-COL1 = SY-INDEX. REC-COL2 = SY-INDEX ** 3.
APPEND REC TO ITAB1.
ENDDO.
LOOP AT ITAB1 INTO REC.
WRITE: / REC-COL1, REC-COL2.
ENDLOOP.
ULINE.
ULINE.
REC-COL1 = 5. REC-COL2 = 8.
READ TABLE ITAB1 FROM REC INTO REC COMPARING COL2.
WRITE: / 'SY-SUBRC = ', SY-SUBRC.
SKIP.
WRITE: / REC-COL1, REC-COL2.

Output:

Ques: why the sy-subrc is coming 4 (not found any entry) while I was searching as: COMPARING COL2. and col2 = 8 is there in the internal table.

1 ACCEPTED SOLUTION

joltdx
Active Contributor

Hi!

Yeah, COMPARING is not working like that. It can be used to compare fields in the found line. Here's the ABAP Documentation.

The sy-subrc = 4 comes from the fact that there is no line matching rec, that is col1=5 and col2=8.

6 REPLIES 6

former_member34
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with our Q&A Tutorial: https://developers.sap.com/tutorials/community-qa.html, as it provides tips for preparing questions that draw responses from our members. Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a picture to your profile you encourage readers to respond: https://www.youtube.com/watch?v=46bt1juWUUM

Many thanks!

joltdx
Active Contributor

Hi!

Yeah, COMPARING is not working like that. It can be used to compare fields in the found line. Here's the ABAP Documentation.

The sy-subrc = 4 comes from the fact that there is no line matching rec, that is col1=5 and col2=8.

Patrick_vN
Active Contributor

Wanting to know what the COMPARING statement does, I checked the documentation.. surprise surprise, it seems like instead of pre-fixes like "lt_", we're gonna use post-fixes "_tab" instead? Is that supposed to be clean code? And wait, we don't need to be consistent either, for the second table doesn't have the post-fix.. 😄

DATA: sflight_tab TYPE SORTED TABLE OF sflight
                  WITH UNIQUE KEY carrid connid fldate,
      sflight_wa  LIKE LINE OF sflight_tab,
      output      TYPE TABLE OF string WITH EMPTY KEY.

matt
Active Contributor
0 Kudos

Ok so sflight_tab means: table of sflight. No real semantic information there. It's not much better than CONSTANTS c_x VALUE 'X'.

Why would we need the initial S?!

I'd use flights, I guess.

Sandra_Rossi
Active Contributor
0 Kudos
(Patrick Van Nierop see Matthew reply to you)

joltdx
Active Contributor
0 Kudos

In general, and on this theme, I believe the ABAP documentation is pretty awesome... It's a good balance between describing in simple terms and explaining "advanced" or "deeper" things. It's not too wordy, but clear and concise.

Then there are things like this. I believe COMPARING is an old thing (though I've never used it). But EMPTY KEY is 7.40, right? So at least the doc should've been touhced...