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

internal table question

Former Member
0 Likes
880

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
844

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.

7 REPLIES 7
Read only

Former Member
0 Likes
845

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.

Read only

0 Likes
844

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.

Read only

0 Likes
844

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

Read only

0 Likes
844

Thanks Sid.

Read only

0 Likes
844

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.

Read only

Former Member
0 Likes
844

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

Read only

0 Likes
844

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)