Read statement fails as internal table is empty - abap

Recently I've come across a Read statement which gives Sy-subrc eq 8. this happens because the internal table has no records and at the same time variables in the WHERE clause are empty too. What I have been wondering is why wouldn't we check if the table is not initial before the read statement?
pleas let me know if we can check the itab is not initial before read statement.
Thanks!

Yes, you can check itab is not initial before read statement. what's bothering you? it's not an issue. And WITH KEY or WITH TABLE KEY clause used with read statement not WHERE.
And if there is no value exist in internal table for given key value then SY-SUBRC will be 4

It's a wrong assumption to make a direct link between READ TABLE on an empty table and SY-SUBRC = 8. If you read the official ABAP documentation, you will see that SY-SUBRC = 8 is related to the variant READ TABLE ... BINARY SEARCH.
So, with READ TABLE ... BINARY SEARCH, SY-SUBRC will be 8 if the searched line doesn't exist but if it was inserted it would be placed after the last line of the table. Of course, that's always the case when the internal table is empty.
Addendum May, 10th: SY-SUBRC = 8 may also occur with READ TABLE on internal tables of type SORTED (because it's using a binary search implicitly).

Related

Retrieving or deleting a row with a blob in Informix 10

I'm using Informix 10. Using this command as suggested by the documentation (well - the closest doc I could find):
select lotofile(ctbufdata, "foo!", "client") from trg_send_stxn where ctstamp1=60004300
(to database syscdr), it gives the error:
7420: Argument (1: lo_id) is invalid.
The same error occurs if I try to unload to filename select * from...
If I try to delete the row with delete from trg_send_stxn where... , the error is:
(U00001) - blob_destroy: error during processing or invalid LO argument
How can I view this blob? (I want to view its contents to figure out where it came from).
Or; how can I delete it or otherwise recover from this apparent corruption.
As suggested in answers -- the command
select ("0x" || substr(ctbufdata::lvarchar,17,8))::INT sbspace
from trg_send_stxn
where ctstamp1=60004300
produces result 0. And dropping the where clause produces 418 rows all 0.
Since trg_send_stxn is an ER queue table, can we assume this is related to your other, ER related question (Informix 10 replication queues not moving)? If so, is this on server A or B - I'd suspect B since this table is send queue related and you're reporting a problem from B to A?
In any case, this sounds like some sort of data corruption, either within the trg_send_stxn table's row (my guess), or in the actual sblob metadata pointed to by this row (ctbufdata column), i.e. in the sbspace.
Try selecting that row and displaying the LO pointer using technique described here (share output here).

Error "not mutually convertible in Unicode program" when adding line to table

I'm trying to add data from a internal table to a custom one.
DATA: BEGIN OF TMP_CTRYGRP_T OCCURS 1000,
CTYGR TYPE /SAPSLL/CTYGR,
TEXT1 TYPE /SAPSLL/TEXT60,
END OF TMP_CTRYGRP_T.
SELECT ctygr, text1 FROM /SAPSLL/CTYGPT INTO TABLE #DATA(lt_countryGroupsTable)
LOOP AT lt_countryGroupsTable ASSIGNING FIELD-SYMBOL(<ls_countryGroups>).
APPEND <ls_countryGroups> TO TMP_CTRYGRP_T.
ENDLOOP.
Then I want to add the line in a custom Table Type ZZ_T_TAB
So I've tried to create a field-symbol of this table, creating an internal table from it, but none of the solutions I've tried was permitting me to add lines in that Custom table (even if the one in the program had the lines).
The problem I mainly encountered was:
are not mutually convertible in a Unicode program.
So my questions are:
Why does that error happen? Googling it didn't provide me an understandable answer
For the moment I'm using an internal table limited to 1000 rows. But I don't really know by advance the number of lines the search could provide. Is there any way to improve that?
How to add lines from any solution to my ZZ_T_TAB then? And afterwards how could I add other fields in the same table, for the rows already existing?
As some of you maybe understood, I'm quite a rookie in ABAP.
So if there's any useful link to understand all of that I would be happy if you can share it with me.
Why don't you directly select into the table?
Don't use OCCURS as it is declared obsolete and already forbidden in classes.
Declare your own structure as type and mark your custom internal table as TYPE STANDARD TABLE OF struct_type. This way, there will be no upper bounds
TYPES:
BEGIN OF struct_type,
CTYGR TYPE /SAPSLL/CTYGR,
TEXT1 TYPE /SAPSLL/TEXT60,
END OF struct_type.
DATA tmp_ctrygrp_t TYPE STANDARD TABLE OF struct_type WITH EMPTY KEY.
Why does that error happen? Googling it didn't provide me an
understandable answer
You cannot use APPEND with non-identical structures. You have to "convert" it before. Look up for the command MOVE-CORRESPODING in ABAP help (F1 on command in editor).
For the moment I'm using an internal table limited to 1000 rows. But I
don't really know by advance the number of lines the search could
provide. Is there any way to improve that?
Do not use OCCURS extension it is deprecated (as lausek wrote), old syntax.
How then to add lines from any solution to my ZZ_T_TAB ? And
afterwards how could I add other fields in the same table, for the
rows already existing?
You can modify a DB table various ways.:
1, Use UPDATE statement to directly update a field value.
2, Use MODIFY statement to modify field values from a (for example) pre-selected
structure.
Look up the UPDATE and MODIFY command in ABAP help, there are really helpful code examples.

Get value from a table and save it inside of a structure

I am new in ABAP and I have to modify these lines of code:
LOOP AT t_abc ASSIGNING <fs_abc> WHERE lgart = xyz.
g_abc-lkj = g_abc-lkj + <fs_abc>-abc.
ENDLOOP.
A coworker told me that I have to use a structure and not a field symbol.
How will be the syntax and why to use a structure in this case?
I have no idea why the co-worker wants that you use a structure in this case, because using a field symbol while looping is usually more performant. The reason could be that you are doing some kind of a novice training and he wants you to learn different syntax variants.
Using a structure while looping would like this
LOOP AT t_abc INTO DATA(ls_abc)
WHERE lgart = xyz.
g_abc-lkj = g_abc-lkj + ls_abc-abc.
ENDLOOP.
Your code is correct, because Field symbol functions almost the same as a structure.
For Field symbol
Field symbol is a pointer,
so there is no data copy action for field symbol, and the performance is better
Well if we changed the value via field symbol, the internal table get changed also
For Structure
Structure is a copy of the data, so there is a data copy action, and the performance is bad if the data row is bigger than 200 bytes (based on the SAP ABAP programming guide for performance)
If changed the data in the structure, the original internal table remains the same because there are 2 copies of the data in memory

Ways of checking if record exists in itab without loop?

Is there a shortcut or should I just loop at the table and check?
I mean I am using an internal table and I want to check if a value is contained in one field of the internal table and I don't want to loop the table to find the value. Is it possible?
To check for a specific value without doing a loop or transferring values to a work area, you can use the READ statement with the addition TRANSPORTING NO FIELDS like so:
READ TABLE itab WITH KEY FIELD = 'X' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
"Read was successful.
ENDIF.
UPDATE: From release 740 ABAP contains the predicate function LINE_EXISTS which is described in this blog post.
It's a built-in function to which you pass a table expression. Using the above example:
IF line_exists( itab[ field = 'X' ] ).
"Do stuff
ENDIF.
Full syntax of table expression in that predicate see here: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abentable_expressions.htm
Selam,
If you are going to use loop in your algorithm, then you can use something like this:
LOOP ITAB WHERE FIELD = 'X'.
"code sample
ENDLOOP.
If you are not going to use a loop in your code, then i don't think there is a specific way to check for a specific value in itab.
Hope its helpful.
Talha

Move FMOIX/FMCOX structures into Internal Table

I am a newbie to ABAP (3 days experience) and I am currently on a task to write reports using ABAP code. It is like moving some data from a specific SAP database to a Business Intelligence staging area.
So the core difficulty is that some data on the SAP server is in the format of dictionary structures (FMOIX, FMCOX, etc.) and I need to move these data into internal tables during program runtime. I was told that OPENSQL would not work in this case.
If you still do not get what I mean, I can suggest several ways, actually given by my supervisor. First is to use GET event, say
GET FMOIX.
IF FMOIX-zhdlt > From_dat and FMOIX-zhdlt < to_dat.
Append FMOIX to itab.
ENDIF.
The thing is that I am still not very clear about this GET event. Is it just a event handler thing, or can it loop through data records?
What I googled for more than two days give me something like
LOOP at FMOIX.
MOVE FMOIX to itab.
ENDLOOP.
So what are the ways to move transactional structure like FMOIX into internal tables, say the internal table name is ITAB?
Your answer would be greatly appreciated. Though I have time, I am totally new.
Thanks a lot.
If your supervisor is suggesting that you use the GET event, it means that your program is (or should be) using a logical database - in this case probably FMF or FMF_BCS.
Doing GET FMOIX reads a set of fields defined in the logical database (as a node). Underneath your GET statement, you can use FMOIX as a structure, e.g. WRITE FMOIX-field1. The program will (implicitly, it's not explicity defined in the code like a LOOP...ENDLOOP is) loop through all the rows returned according to your selection criteria. You should be able to use MOVE-CORRESPONDING to move the contents of each row into a proper structure, and then APPEND that structure to your itab.
Quick link on GET in ABAPDocu
Note: this answer is a bit of a guess, since I've only used a logical database once, and the documentation is a little thin on the ground compared to the volumes out there about standard SELECTs and internal tables.
You can create your internal table in type of that structure such as:
data: itab like table of fmoix with header line.
And you can use this internal table to fill up wherever you are using your select codes.
Such as:
select * from ____
into corresponding fields of itab
where zhdlt gt from_dat
and zhdlt lt to_dat.
I'm not sure this is what you are looking for but I can tell you creating itab in type of that structure can be filled up with all corresponding datas that coming from your select. You cant loop FMOIX because its not a table, its a structure. So is there any specific reason to hold your datas in structures?
Hope it was helpful.
Talha