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

How I can modify a sorted table?

Former Member
0 Likes
3,903

Hi, I make a loop..in a table like..

LOOP AT GT_LIST_2 into list_2.

.....

......

MODIFY gt_LIST_2 FROM LIST_2.

ENDLOOP.

The definition of a table I made like:

DATA: BEGIN OF LIST_2 OCCURS 0,

EBELN LIKE EKBE-EBELN,

EBELP LIKE EKBE-EBELP,

GJAHR LIKE EKBE-GJAHR,

BELNR LIKE EKBE-BELNR,

BEWTP LIKE EKBE-BEWTP,

BUDAT LIKE EKBE-BUDAT,

MENGE LIKE EKBE-MENGE,

WRBTR LIKE EKBE-WRBTR,

WAERS LIKE EKBE-WAERS,

WERKS LIKE EKBE-WERKS,

SHKZG LIKE EKBE-SHKZG,

DMBTR LIKE EKBE-DMBTR,

END OF LIST_2.

DATA gt_list_2 LIKE SORTED TABLE

OF list_2

WITH NON-UNIQUE DEFAULT KEY.

But... When the program arrive to MODIFY has a mistake... I don´t know exactly how I can modify the sorted table, can anybody tell me how I can do this?

Thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,765

Hi

It's very strange because you're trying to modify a table into its loop and it shouldn't have a mistake.

Try to use the index:

LOOP AT GT_LIST_2 into list_2.

TABIX = SY-TABIX.

.............

MODIFY gt_LIST_2 FROM LIST_2 INDEX TABIX

ENDLOOP.

Max

Hi, I make a loop..in a table like..

LOOP AT GT_LIST_2 into list_2.

.....

......

MODIFY gt_LIST_2 FROM LIST_2.

ENDLOOP.

The definition of a table I made like:

DATA: BEGIN OF LIST_2 OCCURS 0,

EBELN LIKE EKBE-EBELN,

EBELP LIKE EKBE-EBELP,

GJAHR LIKE EKBE-GJAHR,

BELNR LIKE EKBE-BELNR,

BEWTP LIKE EKBE-BEWTP,

BUDAT LIKE EKBE-BUDAT,

MENGE LIKE EKBE-MENGE,

WRBTR LIKE EKBE-WRBTR,

WAERS LIKE EKBE-WAERS,

WERKS LIKE EKBE-WERKS,

SHKZG LIKE EKBE-SHKZG,

DMBTR LIKE EKBE-DMBTR,

END OF LIST_2.

DATA gt_list_2 LIKE SORTED TABLE

OF list_2

WITH NON-UNIQUE DEFAULT KEY.

But... When the program arrive to MODIFY has a mistake... I don´t know exactly how I can modify the sorted table, can anybody tell me how I can do this?

Thank you.

10 REPLIES 10
Read only

Former Member
0 Likes
2,766

Hi

It's very strange because you're trying to modify a table into its loop and it shouldn't have a mistake.

Try to use the index:

LOOP AT GT_LIST_2 into list_2.

TABIX = SY-TABIX.

.............

MODIFY gt_LIST_2 FROM LIST_2 INDEX TABIX

ENDLOOP.

Max

Read only

0 Likes
2,765

Hi

I try with SY-INDEX but has a mistake too.

What other statment can I use?

Thank you

Read only

0 Likes
2,765

Hi

Excuse me: but what does it mean to have a mistake?

Remember: if you use a sorted table you haven't to update the fields used to define the key

Max

Read only

0 Likes
2,765

Hi again

The mistake say

You tried to insert or change a line at postion 2 in the internal table "\PROGRAM=ZMMRP046_ALICIA\DATA=GT_LIST_2 " (of the kind sorted table). This violate the sort sequence of the table, wich was laid down when the table was declared.

Could you give other option please

Thank you

Read only

0 Likes
2,765

Hi

I think you're tryng to update the key fields.

You have define your table in this way:

DATA: BEGIN OF LIST_2 OCCURS 0,

EBELN LIKE EKBE-EBELN,

EBELP LIKE EKBE-EBELP,

GJAHR LIKE EKBE-GJAHR,

BELNR LIKE EKBE-BELNR,

BEWTP LIKE EKBE-BEWTP,

BUDAT LIKE EKBE-BUDAT,

MENGE LIKE EKBE-MENGE,

WRBTR LIKE EKBE-WRBTR,

WAERS LIKE EKBE-WAERS,

WERKS LIKE EKBE-WERKS,

SHKZG LIKE EKBE-SHKZG,

DMBTR LIKE EKBE-DMBTR,

END OF LIST_2.

DATA gt_list_2 LIKE SORTED TABLE

OF list_2

WITH NON-UNIQUE DEFAULT KEY.

So all char fields are key fields.

You should use only the fields you haven't to change as key fields.

Your internal table have fields of EKBE, so only the key fields of EKBE should be used to define the key of your internal table.

WITH NON-UNIQUE KEY EBELN EBELP GJAHR BELNR.

Max

Read only

0 Likes
2,765

Please try changing this line of code.



DATA gt_list_2 
         LIKE SORTED TABLE  OF list_2
                  <b>WITH NON-UNIQUE KEY EBELN EBELP.</b>

Regards,

Rich Heilman

Read only

0 Likes
2,765

I try with the definition of:

DATA: BEGIN OF LIST_2 OCCURS 0,

EBELN LIKE EKBE-EBELN,

EBELP LIKE EKBE-EBELP,

GJAHR LIKE EKBE-GJAHR,

BELNR LIKE EKBE-BELNR,

BEWTP LIKE EKBE-BEWTP,

BUDAT LIKE EKBE-BUDAT,

MENGE LIKE EKBE-MENGE,

WRBTR LIKE EKBE-WRBTR,

WAERS LIKE EKBE-WAERS,

WERKS LIKE EKBE-WERKS,

SHKZG LIKE EKBE-SHKZG,

DMBTR LIKE EKBE-DMBTR,

END OF LIST_2.

DATA gt_list_2 LIKE SORTED TABLE

OF list_2

WITH NON-UNIQUE DEFAULT KEY.

but give a error.

and with

DATA gt_list_2

LIKE SORTED TABLE OF list_2

WITH NON-UNIQUE KEY EBELN EBELP.

give the error:

the error that I told you but in position 4

I need to especify the fields that I need to modify??

Thank you again

Read only

0 Likes
2,765

Will there be any case where there will be more than one record for a purchase order/item combonation, if not,



DATA gt_list_2 
        LIKE SORTED TABLE OF list_2
         <b>       WITH UNIQUE KEY EBELN EBELP.</b>

make it a unique key.

Regards,

Rich Heilman

Read only

0 Likes
2,765

With:

DATA gt_list_2 LIKE SORTED TABLE

OF list_2

WITH UNIQUE KEY mandt ebeln ebelp zekkn vgabe gjahr belnr buzei.

I run the program with most than 12 rows...and its seem that will be ok

If I have other problem with more rows..I will told you

Thank you a lot