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

Error when inserting or changing in a sorted table

Former Member
0 Likes
15,052

Hi Experts,

I am getting error as below:

Error when inserting or changing in a sorted table.

A line is to be inserted or changed at position 3 in the sorted

internal table (type SORTED_TABLE)

  "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER".

In doing so, the sorting sequence - determined by the table key - was

  1. destroyed.

Error Program is as follow:

  693       CLEAR r_final1.

  694       REFRESH: i_final1, i_sum.

  695

  696       r_final1-bukrs = r_bkpf-bukrs.    "Company code

  697       r_final1-belnr = r_bkpf-belnr.    "Accounting Document Number

  698       r_final1-gjahr = r_bkpf-gjahr.    "Fiscal Year

  699       r_final1-usnam = r_bkpf-usnam.    "User Name

  700       r_final1-budat = r_bkpf-budat.    "Posting date       "+RT25298

  701       r_final1-cpudt = r_bkpf-cpudt.    "Accounting Document Entry Date

  702       r_final1-bldat = r_bkpf-bldat.    "Document Date in Document

  703

  704 *     Get the user name.

  705       CLEAR r_user.

  706       READ TABLE i_user INTO r_user WITH KEY usnam = r_bkpf-usnam.

  707

  708       IF sy-subrc NE 0.

  709 *       Look up the user name that goes with ID

  710         CALL FUNCTION 'SUSR_USER_ADDRESS_READ'

  711           EXPORTING

  712             user_name              = r_final1-usnam

  713           IMPORTING

  714             user_usr03             = r_user_usr03

  715           EXCEPTIONS

  716             user_address_not_found = 1

  717             OTHERS                 = 2.

  718

  719         IF sy-subrc = 0.

720           r_user-usnam = r_bkpf-usnam.

721           CONCATENATE r_user_usr03-name1 r_user_usr03-name2

722             INTO r_user-name SEPARATED BY space.

>>>>           INSERT r_user INTO i_user INDEX sy-tabix.

724         ENDIF.

725       ENDIF.

726

727 *     Assign User Name into dummy final table

728       r_final1-name1 = r_user-name.

729

730       CLEAR : r_bseg.

731 *     Process the line items for the document

732       LOOP AT i_bseg INTO r_bseg

733                      WHERE bukrs = r_bkpf-bukrs

734                        AND belnr = r_bkpf-belnr

735                        AND gjahr = r_bkpf-gjahr.

736

737 *       Move fields to output

738         r_final1-hkont = r_bseg-hkont.   "General Ledger Account

Please provide me with a solution.

Thanks in Advance.

Regards,

Vikas.

1 ACCEPTED SOLUTION
Read only

former_member585060
Active Contributor
7,809

Hi,

   Use the statement "INSERT r_user INTO TABLE i_user." In your Insert statement TABLE is missing.

Thanks and Regards

Bala Krishna

18 REPLIES 18
Read only

audreystevenson
Product and Topic Expert
Product and Topic Expert
0 Likes
7,809

Moved to the ABAP Development space, where Discussions/Forums about ABAP are located.

Audrey, SCN Team

Read only

0 Likes
7,809

Hi,

where to discuss the new SCN surface?

- need Style ABAP code

- need setting for line space

- need help features

Regards Clemens

Read only

Clemenss
Active Contributor
0 Likes
7,809

Hi,

INSERT r_user INTO TABLE i_user. "No index - sorted means always in sorted order

READ TABLE i_user INTO r_user WITH TABLE KEY usnam = r_bkpf-usnam."increase speed using index

Regards

Clemens

Read only

Former Member
0 Likes
7,809

Thanks for the efforts...but this solution is not working.Am getting another dump.i had updated it down the discussion

Read only

Tamas_Hoznek
Product and Topic Expert
Product and Topic Expert
0 Likes
7,809

If I_USER is defined as a sorted table, then a non-catchable exception will occur if a line to be inserted would disrupt the sort order of the table. I suppose this is what happens here. So the program must be changed to insert the new entry at the correct position according to the sort order.

Read only

former_member186741
Active Contributor
0 Likes
7,809

Clemens has provided the solution. Basically your statement:

INSERT r_user INTO i_user INDEX sy-tabix.

is trying to put an entry into position 3(sy-tabix must have a value of 3) but in doing this it will then contradict the sort order you have got in the definition of i_user.

Changing the insert to:

INSERT r_user INTO i_user INDEX.

will let the sytem determine where the new entry goes.

Read only

chundru_ravindra
Participant
0 Likes
7,809

Hi,

For Sorted Tables no need to specify Index Number , as the new record will be inserted at corresponding location based on its content because inserting a new record will change Sort Sequence,

Regards,

Ravindra.

Read only

Former Member
0 Likes
7,809

Hi,

As Clemens, Neil and Chundru had said, you must not use index for a sorted table unless you are sure the index position which you are giving will not affect the order of the sorted table.

Regards,

Josh

Read only

0 Likes
7,809

Am still getting a new error as follow after changing my stmt to

INSERT r_user INTO i_user.

the error is as follow:

You attempted to change, delete or create a row in the

internal table "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER", but no

  valid cursor exists

for the table.

Error in an ABAP/4 statement when processing an internal table.

Possible reasons:

1. The relevent ABAP language command does not include the addition

    "...INDEX...", although the statement is not

    inside a "LOOP...ENDLOOP" loop processing this table.

2. In the body of a loop started with "LOOP ... USING KEY ...", an ABAP

    statement has been issued with an implicit index specification. This

    is only permitted in connection with the "USING KEY loop_key"

    addition and applies to the "DELETE itab" and "MODIFY itab"

    statements.

3. The relevent ABAP language command statement was called from within a

    "LOOP...ENDLOOP" loop after a DELETE

  "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER".

Read only

0 Likes
7,809

Am still getting a new error as follow after changing my stmt to

INSERT r_user INTO i_user.

the error is as follow:

You attempted to change, delete or create a row in the

internal table "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER", but no

  valid cursor exists

for the table.

Error in an ABAP/4 statement when processing an internal table.

Possible reasons:

1. The relevent ABAP language command does not include the addition

    "...INDEX...", although the statement is not

    inside a "LOOP...ENDLOOP" loop processing this table.

2. In the body of a loop started with "LOOP ... USING KEY ...", an ABAP

    statement has been issued with an implicit index specification. This

    is only permitted in connection with the "USING KEY loop_key"

    addition and applies to the "DELETE itab" and "MODIFY itab"

    statements.

3. The relevent ABAP language command statement was called from within a

    "LOOP...ENDLOOP" loop after a DELETE

  "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER".

Read only

Former Member
0 Likes
7,809

Am still getting a new error as follow after changing my stmt to

INSERT r_user INTO i_user.

the error is as follow:

You attempted to change, delete or create a row in the

internal table "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER", but no

  valid cursor exists

for the table.

Error in an ABAP/4 statement when processing an internal table.

Possible reasons:

1. The relevent ABAP language command does not include the addition

    "...INDEX...", although the statement is not

    inside a "LOOP...ENDLOOP" loop processing this table.

2. In the body of a loop started with "LOOP ... USING KEY ...", an ABAP

    statement has been issued with an implicit index specification. This

    is only permitted in connection with the "USING KEY loop_key"

    addition and applies to the "DELETE itab" and "MODIFY itab"

    statements.

3. The relevent ABAP language command statement was called from within a

    "LOOP...ENDLOOP" loop after a DELETE

  "\PROGRAM=ZGLFINGLRX_MANUAL_JOURNALAUDIT\DATA=I_USER".

Read only

0 Likes
7,809

If you have declared the table with unique key then, may be its trying to insert a record with same key value.

Read only

former_member585060
Active Contributor
7,810

Hi,

   Use the statement "INSERT r_user INTO TABLE i_user." In your Insert statement TABLE is missing.

Thanks and Regards

Bala Krishna

Read only

0 Likes
7,809

Bala Krishna is right. Insert statement syntax is wrong, Table keyword missing.

Read only

0 Likes
7,809

Hi,

Its working.Thanks a lot for your valuable contribution ..

Read only

0 Likes
7,809

Hi vikas,

all readers are happy, if you

- let us know the solution that worked for you

- close the thread as "solved"

- mark answers as helpful/solved

Regards

Clemens

Read only

Former Member
0 Likes
7,809

Hi Vikas,

Just check you SY-TABIX value when you are inserting record into the table. You read an internal table after that calling a function module , then concatenating values, and then finally inserting record. In between  think that sy-index is getting changed to a number that is beyond the number of records into the internal table.

Try to get SY-TABIX into a local variable just after you read the table, after that use that local variable as an index value while inserting record.

Please check this and let me know if it works.

Read only

Former Member
0 Likes
7,809

Use append to add to a sorted table.  SAP will put the record into the correct sequence.