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

LOOP ON TABLE

Former Member
0 Likes
723

Hellow I have a table person_tab and I declare my table with the same values . in person tab I have names of employee and number of employye and I wont to bring it into my table itab how can I do that

This is my table

TYPES: BEGIN OF 1_itab,

objid TYPE hrobjid,

begda TYPE begdatum,

endda TYPE enddatum,

sobid TYPE sobid,

lastname TYPE pad_nachn,

firstname TYPE pad_vorna,

priox TYPE priox,

END OF 1_itab.

DATA: itab TYPE TABLE OF 1_itab,

wa_itab LIKE LINE OF itab.

DATA: person_tab TYPE RHLDAPP OCCURS 0 WITH HEADER LINE.

DATA: wa_person_tab LIKE LINE OF person_tab .

And person tab is a STRUCTURE type RHLDAPP with values that I bring in in the function CALL FUNCTION 'RH_DIR_ORG_STRUC_GET'

EXPORTING

act_orgunit = obj_tab-objid

act_plvar = '01'

act_date = sy-datum

sort_flag = 'X'

add_flag_pdata = 'X'

TABLES

person_tab = person_tab

EXCEPTIONS

no_active_plvar = 1

OTHERS = 2.

IF sy-subrc <> 0.

<b>And I try like this but it didn’t work I get the names in date very confused

LOOP AT person_tab INTO wa_itab.

MOVE-CORRESPONDING person_tab TO wa_itab.

APPEND wa_itab TO itab.

CLEAR wa_itab.

ENDLOOP.</b>

the problem is that i dont get the field in their place

Thankes for your suggstion

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
689

HI ,

You have to use wa_person_tab while moving data of person_tab.

LOOP AT person_tab INTO wa_person_tab.

MOVE-CORRESPONDING wa_person_tab TO wa_itab.

APPEND wa_itab TO itab.

CLEAR wa_itab.

ENDLOOP.

Regards,

Raghav

7 REPLIES 7
Read only

Former Member
0 Likes
690

HI ,

You have to use wa_person_tab while moving data of person_tab.

LOOP AT person_tab INTO wa_person_tab.

MOVE-CORRESPONDING wa_person_tab TO wa_itab.

APPEND wa_itab TO itab.

CLEAR wa_itab.

ENDLOOP.

Regards,

Raghav

Read only

0 Likes
689

hi what?

Read only

anversha_s
Active Contributor
0 Likes
689

hi,

chnage ur code like this.

LOOP AT person_tab INTO <b>wa_person_tab</b>.

MOVE-CORRESPONDING <b>wa_person_tab</b> TO wa_itab.

APPEND wa_itab TO itab.

CLEAR wa_itab.

ENDLOOP.

rgds

Anver

Read only

amit_khare
Active Contributor
0 Likes
689

Hi,

the problem is the field structure for person_tab & wa_tab or itab are of not same type abd order.

To per form move corresponding , first you have to make the certain fields as required same in both structures.

Try this,

LOOP AT person_tab INTO wa_person_tab.

MOVE-CORRESPONDING wa_person_tab TO wa_itab.

APPEND wa_itab TO itab.

CLEAR wa_itab.

ENDLOOP.

regards,

Amit

Read only

Former Member
0 Likes
689

Hello Sh,

When you say move-corresponding fields from person_tab into wa_itab. The field names should be the same then it will work else you have to code in this way.

loop at person_tab.

wa_itab-lastname = person_tab-lastname.

wa_itab-firstname = person_tab-firstname.

...........

.........

..........

append wa_itab.

endloop.

Read only

Former Member
0 Likes
689

Hi,

You can move all necessary fields from itab1 to itab2 in the following way :

DATA: lw_itab1 LIKE LINE OF itab1.

Loop at itab1 into lw_itab1.

move lw_itab1-field1 to itab2-field1.

move lw_itab1-field3 to itab2-field3.

move lw_itab1-field4 to itab2-field4.

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

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

append itab2.

endloop.

Cheers.

Read only

Former Member
0 Likes
689

Hi,

Declare the fields in itab in the same order as the table person_tab.

loop at person_tab into wa_person_tab.

wa_itab-objid = wa_person_itab-objid .

wa_itab-firstname = wa_person_firstname.

append itab from wa_itab.

endloop.

hope this helps u.

regards,

keerthi.