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

Previous data missing after appending an extra record into internal table

Former Member
0 Likes
701

Hi

In the below code Exportdata internal table contains10 fields with 4 line items 10,20,40,50 records.all the 10 fields contain data

IT_EKKO_ekpo has 8 fields with 5 line items 10,20,30,40,50.all the 8 filedls contain data.

export data is having 2 extra fields with data compared to IT_ekko_ekpo.

my intension is to add the 30th line item from IT_ekko_ekpo into exportdata with the 2 extra fields data as initial .

Ater my code though the line item 30 is sucessfully inserted into exportdata with 8 fields data , all the other line items are also having data in only 8fields. the 9th and 10th field data for line items 10, 20, 40, 50 are missing.

How can I solve this issue, I want the other line items apart from 30 to contain the 10 fields data and line item 30 to contain 8 fields data after I append the exportdata table.

LOOP AT IT_EKKO_EKPO INTO wa_ekko_ekpo.

READ TABLE exportdata

INTO wa_exportdata

WITH KEY ebeln = wa_ekko_ekpo-ebeln

ebelp = wa_ekko_ekpo-ebelP

BINARY SEARCH.

IF syst-subrc NE 0.

wa_exportdata-ebeln = wa_ekko_ekpo-ebeln.

wa_exportdata-ebelp = wa_ekko_ekpo-ebelp.

wa_exportdata-konnr = wa_ekko_ekpo-konnr.

wa_exportdata-ktpnr = wa_ekko_ekpo-ktpnr.

wa_exportdata-werks = wa_ekko_ekpo-werks.

wa_exportdata-menge = wa_ekko_ekpo-menge.

wa_exportdata-netpr = wa_ekko_ekpo-netpr.

wa_exportdata-lgort = wa_ekko_ekpo-lgort.

APPEND wa_exportdata TO exportdata.

CLEAR: wa_exportdata.

ENDIF.

ENDLOOP.

  • SORT exportdata BY ebeln ebelp.

3 REPLIES 3
Read only

Former Member
0 Likes
604

Hello

If you use BINARY SEARCH in READ statement you must sort table.

Two ways:

1. Declare table exportdata as sorted table and use INSERT instead of APPEND.

2. Modify code:


...
APPEND wa_exportdata TO exportdata.
SORT exportdata BY ebeln ebelp. " add this
CLEAR: wa_exportdata.
ENDIF.
ENDLOOP.

Read only

0 Likes
604

Hi,

Before appending just write the two additional fields also and pass initial values to it.

This might solve the problem.

Read only

Former Member
0 Likes
604

Hi Selina,

Please check whether you sorted the internal table Exportdata by EBELN EBELP before you do a Binary search on the table.

If you have done this, and still facing the problem, Please post the structures of both internal tables IT_EKKO_ekpo and Exportdata.