Application Development 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: 

How to get variables in one shot in loop?

Former Member
0 Kudos

Hello Friends,

I have one internal table with fields material and plant like...


Material	Plant
m1		p1
m2		p1
m3		p1
m4		p2
m5		p2
------------------
------------------

By processing this i_tab for each record I am calculating variable v_version and material (as it is) like....


v_1	m1	" for 1st record process of i_tab
v_1	m2	" for 2nd record process of i_tab
v_2	m3	" for 3rd record process of i_tab
v_3	m4	" for 4th record process of i_tab
v_3	m5	" for 5th record process of i_tab
----------
----------

Now i have one function like call Z_VERSION_UPDATE which is called with in this loop with exporting parameter version and update the values in the tables.

My code is like....


LOOP AT i_tab into wa_tab.
	
"	Calculating version here.
	v_version = (some calculation)
	
	CALL FUNCTION 'Z_VERSION_UPDATE'

ENDLOOP.

and I want to make one shot for each version.

When it process for

v_1 m2

Function should update

v_1 m1

v_1 m2

When it process for

v_2 m3

Function should update

v_2 m3

When it process for

v_3 m5

Function should update

v_3 m4

v_3 m5

Means end of same version end it should update both.

Here, version is not field So i cant use AT commands.

Please help me out . Please post the code example.

Regards,

Ronny.

Edited by: Ronny Hanks on Sep 10, 2008 4:14 PM

Edited by: Ronny Hanks on Sep 10, 2008 4:16 PM

Edited by: Ronny Hanks on Sep 10, 2008 4:17 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

data temp_version like v_version.

LOOP AT i_tab into wa_tab.

temp_version = v_version

" Calculating version here.

v_version = (some calculation)

  • Append the version and material details to a temp internal table itab_temp

if sy-tabix ne 1 and temp_version ne v_version.

loop at itab_temp.

CALL FUNCTION 'Z_VERSION_UPDATE'.

endloop.

refresh itab_temp.

endif.

ENDLOOP.

  • Last set to be executed

loop at itab_temp.

CALL FUNCTION 'Z_VERSION_UPDATE'.

endloop.

refresh itab_temp.

Hope it helps.

Thanks,

Mahesh

2 REPLIES 2

Former Member
0 Kudos

Hi,

data temp_version like v_version.

LOOP AT i_tab into wa_tab.

temp_version = v_version

" Calculating version here.

v_version = (some calculation)

  • Append the version and material details to a temp internal table itab_temp

if sy-tabix ne 1 and temp_version ne v_version.

loop at itab_temp.

CALL FUNCTION 'Z_VERSION_UPDATE'.

endloop.

refresh itab_temp.

endif.

ENDLOOP.

  • Last set to be executed

loop at itab_temp.

CALL FUNCTION 'Z_VERSION_UPDATE'.

endloop.

refresh itab_temp.

Hope it helps.

Thanks,

Mahesh

Former Member
0 Kudos

Took assigning previous variable to function.