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

loading data from one internal to another int table based on condition

Former Member
0 Likes
886

Hi all,

I have two internal tables say x and y .

internal table X has quota , trpid, as fields.

internal table Y has quota ,trpid and plants as fieds.

i will loop the internal table Y .

For each loop,

i want to load the quota value from X to Y where X-trpid = Y-trpid.

So can anyone tell me how can i acheive this using READ statemnet.

If this cannot be acheived with READ then please tell me how can i do that.

Hi all,

I have two internal tables say x and y .

internal table X has quota , trpid, as fields.

internal table Y has quota ,trpid and plants as fieds.

i will loop the internal table Y .

For each loop,

i want to load the quota value from X to Y where X-trpid = Y-trpid.

So can anyone tell me how can i acheive this using READ statemnet.

If this cannot be acheived with READ then please tell me how can i do that.

7 REPLIES 7
Read only

Former Member
0 Likes
846

put like this.

loop at itabx.

read table itaby with quota = itabx-quota.

if sy-subrc eq 0.

itabx-value = itaby-value.

modify itabx.

endif.

endloop.

Read only

Former Member
0 Likes
846

loop at Y.

read table X with key TRPID = Y-TRPID.

IF SY-SUBRC EQ 0.

Y-quota = X-quota.

MODIFY Y.

ENDIF.

endloop. " Y

REWARD POINTS IF FOUND USEFUL, Get back in case of query.

Cheers!!!

Message was edited by:

Tripat Pal Singh

Read only

Former Member
0 Likes
846

Hi,

First u need to sort table X ,and use binary search , for better performance.

below is ur code:

sort X by trpid.

loop at y into wa_y.

read table x into wa_x with key trpid = wa_y-trpid binary search.

if sy-subrc = 0.

wa_y-quota = wa_x-quota.

modify y with wa_y transporting quota.---> to overwrite the new QUOTA value in Y

endif.

endloop.

Revert back if any issues,

Reward with points if helpful.

Regards,

Naveen

Read only

Former Member
0 Likes
846

Hi

LOOP AT Y.

READ TABLE X WITH KEY TRPID = Y-TRPID.

IF SY-SUBRC = 0.

Y-quota = X-quota.

MODIFY Y.

ENDIF.

ENDLOOP. "Y

Cheers

~Arun

Reward Points if useful

Message was edited by:

Arun Shekhar

Read only

Former Member
0 Likes
846

HI Hema,

How are the entries related.. is it like for one entry in y table there are more than one entry in x table then you have to use loop with in loop , here are the both the conditions.

1) For each entry in Y there are more than one entries in X

sort y by quota trpid.

sort x by quota trpid.

loop at y.

loop at x where quota eq y-quota

and trpid eq y-trpid.

z-value = x-value.

append z.

endloop.

endloop.

2) For each y there is one entry in x table.

sort y by quota trpid.

sort x by quota trpid.

loop at y.

read table x with key quota = y-quota

trpid = y-trpid binary search.

if sy-subrc eq 0.

z-value = x-value.

append z.

Endif.

endloop.

Mahesh

Read only

Former Member
0 Likes
846

sort it_x by trpid.

loop at it_y assigning <fs_y>.

read table it_x assigning <fs_x> with key trpid = <fs_y>-trpid binary search.

if sy-subrc eq 0.

<fs_y>-quota = <fs_x>-quota.

endif.

endloop.

I think it can help u.

Read only

Neslinn
Participant
0 Likes
846

Hi,

You can code like this:

Data : wrk_tabix like sy-tabix.

IF the same entry is there in X & Y.

sort X by trpid.

loop at y into wa_y.

wrk_tabix = sy-tabix.

read table x into wa_x with key trpid = wa_y-trpid binary search.

if sy-subrc = 0.

wa_y-quota = wa_x-quota.

endif.

modify y with wa_y index wrk_tabix.

endloop.

elseif the same entries are not there, instead of Read statement use LOOP statement for Y.

Reward if helps.

Regards,

Neslin.