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

help to move data to table

Former Member
0 Likes
964

Hi,

i have 2 tables the first with pernr and comments and seconed

just with pernr (1 row for every pernr)and i wont to move the comments to lines in second table what is the best way to do it?

table 1

pernr        comments
11	          eeeee
22	           jjjjj
22                 ccccc
33	          aaaaa           
33	          bbbbb
33                 tttttttt

i wont

i have in this table just pernr and i wont to add the data

like that to line 1,2,3

table 2

pernr            line 1             line 2         line3
11               eeeee            
22                jjjjj                ccccc
33               aaaaa            bbbbb        tttttttt

how i can do that?

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
943
LOOP AT ITAB2.

READ TABLE ITAB1 WITH KEY ITAB1-PERNR = ITAB2-PERNR.

MOVE ITAB1-FIELD5 TO ITAB2-FIELD5.

ENDLOOP

Just loop at one table. check for the record with the key and move the rest of the contents.

I hope it helps.

thanks

LOOP AT ITAB2.

READ TABLE ITAB1 WITH KEY ITAB1-PERNR = ITAB2-PERNR.

MOVE ITAB1-FIELD5 TO ITAB2-FIELD5.

ENDLOOP

Just loop at one table. check for the record with the key and move the rest of the contents.

I hope it helps.

thanks

7 REPLIES 7
Read only

Former Member
0 Likes
944
LOOP AT ITAB2.

READ TABLE ITAB1 WITH KEY ITAB1-PERNR = ITAB2-PERNR.

MOVE ITAB1-FIELD5 TO ITAB2-FIELD5.

ENDLOOP

Just loop at one table. check for the record with the key and move the rest of the contents.

I hope it helps.

thanks

Read only

0 Likes
943

hi Alchemi

i thanks but its that simple because when u do read the table

its always read the first line and i need to read (if have) the second line for same employee and so on?

Regards

Read only

0 Likes
943

Try this way


field-symbols : <fs> type any.
refresh : itab2.

loop at itab1.
  at new pernr.
    move 1 to v_flg.
  endat.
  move itab1-pernr to itab2-pernr.
  concatenate 'ITAB2-LINE' v_flg to v_field.
  condense v_field no-gaps.
  assign ( v_field ) to <fs>.
  write itab1-comments to <fs>.
  v_flg = v_flg + 1.
  at end of pernr,
     clear v_flg.
     append itab2.
  endat.
endloop.

, a®

Read only

Former Member
0 Likes
943

hi check this ...

REPORT ZZ__GRAPH.

data: begin of itab occurs 0,

matnr like mara-matnr,

meins like mara-meins,

mtart like mara-mtart,

end of itab.

select matnr

meins

mtart

from mara

into table itab

up to 5 rows.

loop at itab.

write: itab-matnr.

endloop.

write:/ .

loop at itab.

write at (18) itab-meins.

endloop.

write:/ .

loop at itab.

write at (18) itab-mtart.

endloop.

<REMOVED BY MODERATOR>

regards,

venkat.

Edited by: Alvaro Tejada Galindo on Mar 18, 2008 3:10 PM

Read only

Former Member
0 Likes
943

Crude, but it works.


DATA:
  BEGIN OF rec1,
    pernr(05),
    cmt(10),
  END OF rec1,
  it_tab1 LIKE STANDARD TABLE OF rec1.
DATA:
  BEGIN OF rec2,
    pernr(05),
    cmt1(10),
    cmt2(10),
    cmt3(10),
  END OF rec2,
  it_tab2 LIKE STANDARD TABLE OF rec2.
DATA:
  cnt TYPE i.

START-OF-SELECTION.

  CLEAR rec1.
  rec1-pernr = '11'.
  rec1-cmt   = 'eeeee'.
  APPEND rec1 TO it_tab1.
  rec1-pernr = '22'.
  rec1-cmt   = 'jjjjj'.
  APPEND rec1 TO it_tab1.
  rec1-cmt   = 'ccccc'.
  APPEND rec1 TO it_tab1.
  rec1-pernr = '33'.
  rec1-cmt   = 'aaaaa'.
  APPEND rec1 TO it_tab1.
  rec1-cmt   = 'bbbbb'.
  APPEND rec1 TO it_tab1.
  rec1-cmt   = 'tttttttt'.
  APPEND rec1 TO it_tab1.

  CLEAR rec2.
  rec2-pernr = '11'.
  APPEND rec2 TO it_tab2.
  rec2-pernr = '22'.
  APPEND rec2 TO it_tab2.
  rec2-pernr = '33'.
  APPEND rec2 TO it_tab2.

  LOOP AT it_tab2 INTO rec2.
    CLEAR cnt.
    LOOP AT it_tab1 INTO rec1
        WHERE pernr = rec2-pernr.
      cnt = cnt + 1.
      CASE cnt.
        WHEN 1.
          rec2-cmt1 = rec1-cmt.
        WHEN 2.
          rec2-cmt2 = rec1-cmt.
        WHEN 3.
          rec2-cmt3 = rec1-cmt.
      ENDCASE.
    ENDLOOP.
    MODIFY it_tab2 FROM rec2.
  ENDLOOP.

  LOOP AT it_tab2 INTO rec2.
    WRITE:/ rec2-pernr,
            rec2-cmt1,
            rec2-cmt2,
            rec2-cmt3.
  ENDLOOP.

Read only

Former Member
0 Likes
943

Hi,

Please try this.


ITAB2[] = ITAB1[].

LOOP AT ITAB1.
  LOOP AT ITAB2 WHERE PERNR = ITAB1-PERNR.
     MOVE ITAB2-FIELD1 TO ITAB3-FIELD1.
     MOVE ITAB2-FIELD2 TO ITAB3-FIELD2.
     MOVE ITAB2-FIELD3 TO ITAB3-FIELD3.
     APPEND ITAB3.
  ENDLOOP.
ENDLOOP

Regards,

Ferry Lianto

Read only

0 Likes
943

hi

ferry welcome back!!!

Thanks