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

Read statement

Former Member
0 Likes
704

In the bellow code the Read statement is reading the first record from gt_ship into lw_ship as the TKNUM same for all the 4 different VBELN. As a result I am getting same VBELN,same time(LFDAT) and same time(LFUHR) in the out put.

The gt_stage has the following TKNUM TSNUM TSRFO ADRNRZ fields

gt_ship has the fields CROSS TKNUM VBELN LFDAT LFUHR.

How do I modify my read statement to read all the records from gt_ship to lw_ship?

LOOP AT gt_stage_aux.

CLEAR: lt_vtsp. REFRESH: lt_vtsp.

      • Begin of Insertion ITF06646-DV 20-1-2009 ***

CLEAR LW_SHIP.

READ TABLE gt_ship WITH KEY tknum = gt_stage_aux-tknum

cross = 'X'

INTO lw_ship.

if not lw_ship-cross is initial.

MOVE-CORRESPONDING lw_ship TO gt_stage.

gt_stage-tsnum = gt_stage_aux-tsnum.

gt_stage-tsrfo = gt_stage_aux-tsrfo.

gt_stage-adrnrz = gt_stage_aux-adrnrz.

APPEND gt_stage.

CLEAR GT_STAGE.

ENDIF.

  • ENDLOOP.

CLEAR LW_SHIP.

READ TABLE gt_ship WITH KEY tknum = gt_stage_aux-tknum

CROSS = ' '

INTO lw_ship.

IF lw_ship-cross is initial AND SY-SUBRC = 0.

      • End of Insertion ITF06646-DV ***

SELECT * FROM vtsp INTO TABLE lt_vtsp

WHERE tknum = gt_stage_aux-tknum

AND tsnum = gt_stage_aux-tsnum.

LOOP AT lt_vtsp.

CLEAR l_vbeln.

SELECT SINGLE vbeln INTO l_vbeln

FROM vttp

WHERE tknum = lt_vtsp-tknum

AND tpnum = lt_vtsp-tpnum.

CLEAR LW_SHIP.

READ TABLE gt_ship WITH KEY vbeln = l_vbeln INTO lw_ship.

MOVE-CORRESPONDING lw_ship TO gt_stage.

gt_stage-tsnum = gt_stage_aux-tsnum.

  • Begin of insertion ITF03468-110107-PR

gt_stage-tsrfo = gt_stage_aux-tsrfo.

gt_stage-adrnrz = gt_stage_aux-adrnrz.

  • End of insertion ITF03468-110107-PR

APPEND gt_stage.

ENDLOOP.

ENDIF. "ITF-06646 20.1.2009 DV

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

valter_oliveira
Active Contributor
0 Likes
658

Must use a LOOP instead of a READ, like:


LOOP AT gt_ship INTO lw_ship 
               WHERE tknum = gt_stage_aux-tknum
                 AND cross = 'X'.
ENDLOOP.

4 REPLIES 4
Read only

valter_oliveira
Active Contributor
0 Likes
659

Must use a LOOP instead of a READ, like:


LOOP AT gt_ship INTO lw_ship 
               WHERE tknum = gt_stage_aux-tknum
                 AND cross = 'X'.
ENDLOOP.

Read only

0 Likes
658

i want to read 1 record at a time of gt_ship into lw_ship for 1 record of gt_stage_aux.1st rec to 1st record,2nd record to second record....like that.

Read only

0 Likes
658

Ok, now I got your point. I wrote my previous post just to say that your READ will only return the first match for your specified key.

Since the only connection between your two tables is only tknum that repeats in second table, i can only see the delete solution that was presented by Avinash. But now I make a question. Is it possible to have 5 lines in first table for one tknum and only four in the second for that tknum? If yes, you will have to repeat at least one vbeln (4 vbelns for 5 lines in first table).

Isn't there another field to connect the two tables to know that this vbeln corresponds to that line (not the first vbeln to the first line, the second vbeln to the second line, and so on?

Regards,

Valter Oliveira

Read only

Former Member
0 Likes
658

Hi,,

Try this way..

lt_ship [] = gt_ship [].
LOOP AT gt_stage_aux.
CLEAR: lt_vtsp. REFRESH: lt_vtsp.

CLEAR LW_SHIP.
READ TABLE gt_ship WITH KEY tknum = gt_stage_aux-tknum
cross = 'X'
INTO lw_ship.
if not lw_ship-cross is initial.
Delete gt_ship index sy-tabix.     "      Add this line this will delete the read line 
MOVE-CORRESPONDING lw_ship TO gt_stage.
gt_stage-tsnum = gt_stage_aux-tsnum.
gt_stage-tsrfo = gt_stage_aux-tsrfo.
gt_stage-adrnrz = gt_stage_aux-adrnrz.
APPEND gt_stage.
CLEAR GT_STAGE.

ENDIF.
ENDLOOP.

Check the other way which is specified by Valter Oliveira.

Edited by: Avinash Kodarapu on Feb 1, 2009 7:25 PM