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 two internal tables

Former Member
0 Likes
565

Hi All,

I have a slight problem, I have two internal tables that I wish to merge into one.

The first i_GFSB contains matnr,werk,verpr,peinh from mbew

The second i_GFSBData has matnr, < i_GFSB-werk>, < i_GFSB-verpr>, < i_GFSB-peinh> ,bwky,verpr,peinh also from mbew

The <> are the fields from i_GFSB that I need to 'insert' into i_GFSBData

Ok,

i_GFSB contains data from a single plant (and the records are distinct)

i_GFSBData contains data for multiple plants (again distinct records)

What I am trying to do is insert the i_GFSB data when the matnr is the same in both tables.

Sounds simple, probably is but this is my first real ABAP program and I am a little confused.

Is there any variable like a python dictionary? If so I could do this in a flash

Cheers all

Ian

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
503

Hi Ian,

Please try this code:


data: wa_gfsb like line of i_gfsb,
      wa_gfsbdata like line of i_gfsbdata,
      lv_tabix type sy-tabix.

* Sort Table by Plant.
sort i_gfsbdata by matnr.

loop at i_gfsb into wa_gfsb.

	read table i_gfsbdata into wa_gfsbdata 
	with key matnr = wa_gfsb-matnr binary search.

	if sy-subrc is initial.
		lv_tabix = sy-tabix.
		
		loop at i_gfsbdata into wa_gfsbdata 
		from lv_tabix.

			if wa_gfsbdata-matnr ne wa_gfsb-matnr.
			   exit.
			else.
				wa_gfsbdata-werks = wa_gfsb-werks.			
				wa_gfsbdata-verpr = wa_gfsb-verpr.
				wa_gfsbdata-peinh = wa_gfsb-peinh.
				modify i_gfsbdata from wa_gfsbdata.
			endif.
			clear wa_gfsbdata.
		endloop.
	endif.
	 
endloop.

Hope this helps.

Ernesto

Edited by: Ernesto Caballero on Apr 6, 2011 4:59 PM

Hi All,

I have a slight problem, I have two internal tables that I wish to merge into one.

The first i_GFSB contains matnr,werk,verpr,peinh from mbew

The second i_GFSBData has matnr, < i_GFSB-werk>, < i_GFSB-verpr>, < i_GFSB-peinh> ,bwky,verpr,peinh also from mbew

The <> are the fields from i_GFSB that I need to 'insert' into i_GFSBData

Ok,

i_GFSB contains data from a single plant (and the records are distinct)

i_GFSBData contains data for multiple plants (again distinct records)

What I am trying to do is insert the i_GFSB data when the matnr is the same in both tables.

Sounds simple, probably is but this is my first real ABAP program and I am a little confused.

Is there any variable like a python dictionary? If so I could do this in a flash

Cheers all

Ian

2 REPLIES 2
Read only

Former Member
0 Likes
504

Hi Ian,

Please try this code:


data: wa_gfsb like line of i_gfsb,
      wa_gfsbdata like line of i_gfsbdata,
      lv_tabix type sy-tabix.

* Sort Table by Plant.
sort i_gfsbdata by matnr.

loop at i_gfsb into wa_gfsb.

	read table i_gfsbdata into wa_gfsbdata 
	with key matnr = wa_gfsb-matnr binary search.

	if sy-subrc is initial.
		lv_tabix = sy-tabix.
		
		loop at i_gfsbdata into wa_gfsbdata 
		from lv_tabix.

			if wa_gfsbdata-matnr ne wa_gfsb-matnr.
			   exit.
			else.
				wa_gfsbdata-werks = wa_gfsb-werks.			
				wa_gfsbdata-verpr = wa_gfsb-verpr.
				wa_gfsbdata-peinh = wa_gfsb-peinh.
				modify i_gfsbdata from wa_gfsbdata.
			endif.
			clear wa_gfsbdata.
		endloop.
	endif.
	 
endloop.

Hope this helps.

Ernesto

Edited by: Ernesto Caballero on Apr 6, 2011 4:59 PM

Read only

0 Likes
503

Hi Ernesto

Yeah thats the ticket, all working fine now.

Thank you very much.

Ian