02-26-2021 3:29 PM
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.
02-26-2021 3:50 PM
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.
02-26-2021 3:29 PM
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!
02-26-2021 3:50 PM
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.
02-26-2021 10:46 PM
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.
02-27-2021 8:20 AM
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.
02-27-2021 10:27 AM
02-27-2021 3:38 PM
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...