gram77
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent
ASKER
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.
Looks like it isn't a primary key.
DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola , colb.
Dear gram77
The statement below is a multi part variable declaration for DATA: statement
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
thanks and regards
onn
The statement below is a multi part variable declaration for DATA: statement
DATA : mytable2 LIKE SORTED TABLE OF line2 WITH UNIQUE KEY cola , colb.
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.
Comma without preceding colon (after DATA ?).
thanks and regards
onn
ASKER
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.