ABAP TRANSPORTING clause issue

DATA : BEGIN OF line2,
  cola TYPE i,
  colb TYPE i,
  END OF line2.
DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola , colb.

DO 4 TIMES.
  line2-cola = sy-index.
  line2-colb = sy-index ** 2.
  APPEND line2 TO mytable2.
ENDDO.

line2-colb = 100.
MODIFY mytable2 FROM line2 INDEX 4 TRANSPORTING (colb).
WRITE :/ 'sy-subrc MODIFY1: ',sy-subrc.

line2-cola = 2.
line2-colb = 200.
MODIFY mytable2 FROM line2 INDEX 2.
WRITE :/ 'sy-subrc MODIFY2: ',sy-subrc.

LOOP AT mytable2 INTO line2.
  WRITE :/ line2-cola, line2-colb.
ENDLOOP.

Q1, The following code compiles fine, however, the TRANSPORTING (colb) clause dosen't work.
The code works fine if TRANSPORTING clause is commented out. If uncommented, the code dosen't work why?

Q2, Also TRANSPORTING (cola) generates an error.
gram77Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Onn LightSAP Technical ConsultantCommented:
Dear gramm77

The Transporting Clause works without the round brackets "(" and ")".

Please check the code below for example.

PARAMETERS: p_carrid TYPE sflight-carrid, 
            p_connid TYPE sflight-connid, 
            p_plane1 TYPE sflight-planetype, 
            p_plane2 TYPE sflight-planetype. 

DATA sflight_tab TYPE SORTED TABLE OF sflight 
                 WITH UNIQUE KEY carrid connid fldate. 

DATA sflight_wa TYPE sflight. 

SELECT * 
       FROM sflight 
       INTO TABLE sflight_tab 
       WHERE carrid = p_carrid AND 
             connid = p_connid. 

sflight_wa-planetype = p_plane2. 

MODIFY sflight_tab FROM sflight_wa 
       TRANSPORTING planetype WHERE planetype = p_plane1. 

Open in new window



Thanks and regards
onn

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gram77Author Commented:
MODIFY mytable2 FROM line2 INDEX 4 TRANSPORTING cola.

TRANSPORTING cola: generates error

You cannot use "MODIFY" to change either the primary key or an active            
secondary key. "COLA" is in one of these keys for table "MYTABLE2"            


MODIFY mytable2 FROM line2 INDEX 4 TRANSPORTING colb.

TRANSPORTING colb: works fine.

cola and colb are both primary keys for mytable.

DATA : BEGIN OF line2,
  cola TYPE i,
  colb TYPE i,
  END OF line2.
DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola , colb.
Onn LightSAP Technical ConsultantCommented:
Dear gram77

This is expected as due to the table type "sorted"


The key fields of the primary table key of sorted tables and hashed tables are read-only and must not be modified. This would lead to the invalidation of the internal table administration and attempts to do so usually raise non-handleable exceptions.

As cola is the primary table key it cannot be modified

Note colb is not set to primary key because of the comma (,) in your code

Open in new window

DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola ,  colb.

Open in new window



Thanks and Regards
onn
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

gram77Author Commented:
Excellent
gram77Author Commented:
Lastly, if i place a comma between the two columns, how does SAP treat colb?
Looks like it isn't a primary key.

DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola ,  colb.
Onn LightSAP Technical ConsultantCommented:
Dear gram77

The statement below is a multi part variable declaration for DATA: statement

DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola ,  colb.

Open in new window


so colb is being declared as a generic variable and is not any part of the mytable2 declaration.

If you remove ":" from DATA: it will give the following error

DATA  mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola ,  colb.

Open in new window


Comma without preceding colon (after DATA ?).



thanks and regards

onn
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SAP

From novice to tech pro — start learning today.