‎2006 Sep 10 3:42 PM
I have an internal table itab1 only with vbelns (actually invoice numbers). Now I want to go to BKPF table, select records into a new internal table itab2 which meets criteria AWTYP = VBRK and AWKEY = itab1-vbeln. Can you please give me a sample code for this with out losing any performance?
Very much appreciated. Points assured for your kind help.
Thanks.
‎2006 Sep 10 3:50 PM
if not itab1[] is initial.
select field1
....
....
into table itab2
from BKPF
for all entries in itab1
where awtyp = 'VBRK' and
awkey = itab1-vbeln.
endif.
if you want to retrieve all the entries from BKPF table you need to select all the primary keys otherwise you might miss some of the records from BKPF.
‎2006 Sep 10 3:50 PM
if not itab1[] is initial.
select field1
....
....
into table itab2
from BKPF
for all entries in itab1
where awtyp = 'VBRK' and
awkey = itab1-vbeln.
endif.
if you want to retrieve all the entries from BKPF table you need to select all the primary keys otherwise you might miss some of the records from BKPF.
‎2006 Sep 10 3:59 PM
Thanks Sid and Naren.
Reg. Sid's reply, I have a question. In order for me not to miss any records, what else I need to do ?
Thanks again.
‎2006 Sep 10 4:03 PM
you need to select all the primary keys from the BKPF table or need mention all the key fields in the where condition.
As in your case you cannot mention all the primary keys in the where condition. you need select all the primay keys fields in the select statement.
Declare itab2 internal table with key fields of BKPF table along with fields needed for your logic.
select the key fields along with needed fields into internal table itab2. By doing this you will all the records from BKPF table
‎2006 Sep 10 4:23 PM
‎2006 Sep 10 4:28 PM
make sure that the order of fields in your internal tables matches with the order of fields in the select statement.
The dump is due to the order of fields in your internal table did not match with order of fields in your select statement.
Reward if this solves your problem.
‎2006 Sep 10 3:54 PM
Hi,
1) You have store all the invoice numbers in an internal table that has the data type AWKEY. Since if we are going to use FOR ALL ENTRIES it will show a syntax error for data type miss match.
DATA: BEGIN OF ITAB_AWKEY OCCURS 0,
AWKEY TYPE BKPF-AWKEY,
END OF ITAB_AWKEY.
LOOP AT ITAB1.
ITAB_AWKEY-AWKEY = ITAB1-VBELN.
APPEND ITAB_AWKEY.
CLEAR: ITAB_AWKEY.
ENDLOOP.
2) use the FOR ALL ENTRIES and get the values from the bkpf..
SELECT BUKRS BELNR GJAHR ....
INTO TABLE ITAB_BKPF
FROM BKPF
FOR ALL ENTRIES IN ITAB_AWKEY
WHERE AWTYP = 'VBRK'
AND AWKEY = ITAB_AWKEY-AWKEY.
3) Performance will not be a problem as there is an index on AWTYP and AWKEY...
Hope this helps..
Thanks,
Naren
‎2006 Sep 10 4:22 PM
As for Naren's suggestion, I created an internal table solely for copying awkey and wrote the remaining code. When I executed the program, it went to dump and I got the following description:
An exception occurred. This exception will be dealt with in more detail below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not caught, which led to a runtime error. The reason for this exception is:
The data read during a SELECT access could not be inserted into the target field.
Either conversion is not supported for the target field's type or the target field is too short to accept the value or the data are not in a form that the target field can accept
(Can you guys please let me the reason if you know for this? Thanks)