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: 

Tables in the subroutine

Former Member
0 Kudos

Hi All,

Can I declare tables in the subroutine?

Since I am accessing table fields in the subroutine I need to declare them in subroutine.

Is it a bad practice or what?

Regards,

Shaily

5 REPLIES 5

Former Member
0 Kudos

Hi Shaily,

Yes u can definitely use tables in a subroutine.

The syntax goes like this :

PERFORM subroutine_name TABLES itab1 USING field1 changing field2.

In this the TABLES should always preceed the USING and CHANGING addition.

then in the definition of subroutine, the code goes like this :

FORM subroutine_name TABLES itab1 structure <Structure same as that of itab> USINg field1 CHANGING field2.

Hope it helps.

Regards,

Himanshu

Former Member
0 Kudos

variable declared with tables statement are always global , whether u declare it in the main prog or a subroutine.. they are always accessable globally.,..

so it is always recommended to declare tables in the main prog.

No rewards Plz..

former_member404244
Active Contributor
0 Kudos

Hi,

check the belowcode...

do like this

PERFORM send_file_as_email_attachment

TABLES t_mess_bod

t_mess_att

USING p_email

'Example .xls documnet attachment'

'PDF'

v_attachment_name

v_attachment_desc

p_sender

v_sender_type

CHANGING v_error

v_reciever.

Reward if helpful.

Regards,

Nagaraj

Former Member
0 Kudos

hi,,

all tables which u are using in a subrotine should be declared in program n not in subroutine as u r calling sub routines using perform statement using tables keyword u must call. if u dont declare them in main program u ll get an error stating dat tables ........... are not declared.

generally wat objects u require locally are declared in a sub routine using keyword LOCAL.

if useful reward some points.

with regards,

Suresh Aluri.

0 Kudos

My subroutine is in a include , which is again in standard User exit(FM).

I cannot declare the tables in the FM global data as it is standard Program.

Should I use subroutine also within this Include is a doubt for me...

Only problem is I wanted if use the statement :

<b>Tables: mara,mard.</b>

I want to confirm if this is not a bad practice.

Shaily