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

subroutine

Former Member
0 Likes
851

Hi experts...

at the moment im populating a table locally with in the subroutine...if i want to use the data in the internal table in anotha subroutine shud i have to make the table global or is there anyway to use the data in another subroutine so that i dont have to change the whole program..plz advise

regards

8 REPLIES 8
Read only

Former Member
0 Likes
828

Hi

If you are calling another subroutine within the subroutine in which u r populating data then you can simply pass that table to another one, no need to make it global

sub1

populating data in ITAB.

call sub2 tables ITAB.

endform.

Otherwise you nedd to define it globally.

Regards

Aditya

Read only

Former Member
0 Likes
828

Hi,

just declare the corresponding table globally and then use another subroutine.

Read only

Former Member
0 Likes
828

Hi,

You can pass the table by call by reference or call by value.

form <form_name> using <itab_name> type <table_type>

declare a table type in the global declarations as.

if You have declared :

data : itab type standard table of ty_itab.

then ====>

types : ty_t_itab type standard table of ty_itab.

form <form_name> using itab type ty_t_itab.

...This is 'call by reference'.

Read only

Former Member
0 Likes
828
PERFORM get_batch_status USING p_matnr
                                 p_werks
                                 p_charg
                        CHANGING g_zustd.

FORM get_batch_status  USING    fp_p_matnr  TYPE mcha-matnr
                                fp_p_werks  TYPE mcha-werks
                                fp_p_charg  TYPE mcha-charg
                       CHANGING fp_g_zustd  TYPE mcha-zustd.
  
CLEAR fp_g_zustd.

  SELECT SINGLE zustd
  INTO    fp_g_zustd
  FROM          mch1
  WHERE         matnr    =    fp_p_matnr
  AND           charg    =    fp_p_charg.

The same way u can use it for a internal table

Read only

vinod_vemuru2
Active Contributor
0 Likes
828

Hi Bright,

2 ways.

1. If u r calling another subroutine from current one then u can pass ur internal table in TABLES parameter.

FORM form1.

do some thing to populate li_tab.

PERFORM form2 TABLES li_tab.

ENDFORM form1.

FORM form2 TABLES p_tab.

Do some thing.

ENDFORM form2.

Note: If u are passing some internal table in TABLES

parmeter then it will be call by reference. SO if u change the table content in form2 the same will be reflected after PERFORM form2 in form1

Second way is to declare ur itab as Global internal table. There is no need to change ur code by declaring itab as global. But this can be accessed and changed any where in the program.

I feel first solution will be better option. Always avoid global declarations as much as possible.

Thanks,

Vinod.

Read only

Former Member
0 Likes
828

hi guyz...

thanks for your replyz

this is how i declared

PERFORM X .

Form X

declared lt_likp

*populate the internal table*

-


-


PERFORM Y tables lt_likp.

-


endform

Form Y tables lt_likp...

_----


-


endform.

Error Message----


**lt_likp has no structure **

plz advise...

regards

Read only

Former Member
0 Likes
828

Hi,

Use like this.......

PERFORM Y using lt_likp.

form y using lt_likp type ty_t_likp.

endform.

declare a table type globally as:

types : ty_t_likp type standard table of ty_likp.

[where 'ty_likp' is the type of ' lt_likp'

Read only

Former Member
0 Likes
828

Hi,

Just u use Import and Export parameters like

EXPORT itab1 TO MEMORY ID 'ZCAT'. in one subroutine.

and next in other subroutine u decalare

IMPORT itab1 FROM MEMORY ID 'ZCAT'.

Regards,

Lokesh