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

merging data without primary key

former_member476503
Participant
0 Likes
1,004

hiii,

I have 2 internal tables "it_final1" and "It_final_new" and i want to join both tables.

both have same fields like BUKRS,GJAHR,SAKNR.

for IT_FINAL1 i am using "BAPI_GL_GETGLACCPERIODBALANCES" FM to get data.

now i need to merge this.

Please explain ...

i am using below logic for that.

LOOP AT IT_FINAL_NEW .

IF sy-SUBRC = 0.

MOVE-CORRESPONDING IT_FINAL_NEW to IT_FINAL_DIS.

ENDIF.

read table it_final1 with key bukrs = it_final_new-bukrs

gjahr = it_final_new-gjahr.

move-corresponding it_final1 to it_final_dis.

APPEND IT_FINAL_DIS.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

former_member463524
Contributor
0 Likes
962

Hi,

Please try the following,

*Looping at final_new which has all fields except gjahr

LOOP AT IT_FINAL_NEW .

*move wa to destination wa

MOVE-CORRESPONDING IT_FINAL_NEW to IT_FINAL_DIS.

*read internal table having balance value using common field

READ TABLE IT_FINAL1 WITH KEY BUKRS = IT_FINAL_NEW-BUKRS INTO WA.

if sy-subrc = 0.

*assign balance value to final destination balance field

IT_FINAL_DIS-balance = wa-balance.

*append the it

APPEND IT_FINAL_DIS.

*now u got the values from 2 internal tables

endif.

ENDLOOP.

Hope this solves your problem.

Regards,

Meera

8 REPLIES 8
Read only

Former Member
0 Likes
962

hi Sanket

LOOP AT IT_FINAL_NEW into wa_it_final.

read table it_final1 into wa_it_final with key bukrs = it_final_new-bukrs

gjahr = it_final_new-gjahr.

if sy-subrc = 0.

move: wa_final-bukrs to wa_final_dis-bukrs

and so on all the fields.....

APPEND wa_it_final_dis to IT_FINAL_DIS.

endif.

ENDLOOP.

Read only

0 Likes
962

Hi anjali ,

thanks for replying.

I have already tried that.

but the problem is i can fetch only any 1 internal table data in FINAL_DIS.

My output has to display like this

A/C-AA1-AA2-AA3-AA4-TOTAL-BALANCE

101-1000-200-0000-0000-01200-001200

201-0000-200-3000-0000-03200-03200

301-0000-200-0000-1000-01200-01200

401-0000-200-0000-0000-00200-00200

501-2000-200-0000-0000-02200-02200

In IT_FINAL_new i am fetching A/C to total.

In it_final1 i am fetching balance with using FM described above.

Both have same A/C no,comp. code,fisc. year.and total and balance are same.

now i need to fetch in one table.but i can only fetch any 1 internal table data.

Read only

0 Likes
962

Hi anjali ,

thanks for replying.

I have already tried that.

but the problem is i can fetch only any 1 internal table data in FINAL_DIS.

My output has to display like this

A/C-AA1-AA2-AA3-AA4-TOTAL-BALANCE

101-1000-200-0000-0000-01200-001200

201-0000-200-3000-0000-03200-03200

301-0000-200-0000-1000-01200-01200

401-0000-200-0000-0000-00200-00200

501-2000-200-0000-0000-02200-02200

In IT_FINAL_new i am fetching A/C to total.

In it_final1 i am fetching balance with using FM described above.

Both have same A/C no,comp. code,fisc. year.and total and balance are same.

now i need to fetch in one table.but i can only fetch any 1 internal table data.

Read only

0 Likes
962

Hi Naranjat,

I'm not sure if i really got your requirement...

but generally merging data can be achieved by using COLLECT statement:

LOOP AT table_new
   INTO workarea_new.

  READ TABLE table_balances
    INTO workarea_balances
    WITH KEY xxx = workarea_new-xxx.

* merge data
  COLLECT workarea_balances INTO table_new.

* append data
  APPEND workarea_balances TO table_new.

ENDLOOP.

Reagards

REA

Read only

0 Likes
962

hi REA,

I have described my logic above.

I have tried that but its not working.

both table have same fields like BUKRS,GJAHR,SAKNR.

still i cant connect both tables.

Actually I need 1 field(BALANCE) which is based FM"BAPI"which i described above.

which i have fetched in internal table IT_FINAL1 and others in IT_FINAL_NEW1.

Read only

0 Likes
962

Hi Sanket,

could you please give an example of the contents that have to be merged as well as the merged content.

Kind regards

REA

Edited by: Ramy El-Arnaouty on Apr 20, 2011 2:21 PM

Read only

former_member463524
Contributor
0 Likes
963

Hi,

Please try the following,

*Looping at final_new which has all fields except gjahr

LOOP AT IT_FINAL_NEW .

*move wa to destination wa

MOVE-CORRESPONDING IT_FINAL_NEW to IT_FINAL_DIS.

*read internal table having balance value using common field

READ TABLE IT_FINAL1 WITH KEY BUKRS = IT_FINAL_NEW-BUKRS INTO WA.

if sy-subrc = 0.

*assign balance value to final destination balance field

IT_FINAL_DIS-balance = wa-balance.

*append the it

APPEND IT_FINAL_DIS.

*now u got the values from 2 internal tables

endif.

ENDLOOP.

Hope this solves your problem.

Regards,

Meera

Read only

former_member476503
Participant
0 Likes
962

SOLVED