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

passing internal table

Former Member
0 Likes
2,700

Hi,

I have a requirement like this

i have to retrive internal table from subroutine

(i.e. I have a internal table in include prg)

I want to retrive that internal table using subroutine how i can write subroutine prog.

If any body knows tell me

Like this

perform get_it using <variable> changing <internal table>

Internal table is in include prg.

Thanks

Regards,

Nandha

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,450

Hi nandha,

1. try this code (just copy paste)

REPORT abc.

*----


Can be in Include

DATA : BEGIN OF itab OCCURS 0,

bukrs LIKE t001-bukrs,

pernr LIKE pa0001-pernr,

END OF itab.

*----


DATA : t LIKE table of itab with header line.

PERFORM myform TABLES t.

*----


FORM myform TABLES tb STRUCTURE itab.

ENDFORM. "myform

*----


2. Specifically Note the following :

a) as u said ITAB is already defined in an include.

thats ok.

b) in form definition, use statement

Tables STRUCTURE Itab

(this will tell the form about the strucutre/defn

of table which is going to pass)

I hope it helps.

regards,

amit m.

27 REPLIES 27
Read only

Former Member
0 Likes
2,450

perform get_it using var

tables itab.

if itab is in global include then you can access that..

regards

vijay

Read only

Former Member
0 Likes
2,450

WRITE like this.

perform mod1 TABLES itab.

FORM mod1 TABLES p_tab1 STRUCTURE itab.

do the coding.

ENDFORM.

Reward points if it is helpful

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
2,450

Hi,

Declare the internal table in main program globally.

I hope you will have includes statement for calling the include from the main program.

If it is available in include,no need of retriving it again.You can directly use the internal table in the main program.

Kindly reward points by clikcing the star on the left of reply,if it is useful.

Read only

abdul_hakim
Active Contributor
0 Likes
2,450

Hi

Pass the program name using IN PROGRAM addition to your subroutine call..

Regards,

Abdul

Read only

Former Member
0 Likes
2,450

Hi nandha,

1. ur requirement is not clear.

2. are u asking the code for PERFORM

or subroutine defintion FORM.

regards,

amit m.

Read only

0 Likes
2,450

HI,

I need both coding

Thanks

Regards,

Nandha

Read only

0 Likes
2,450
perform getdata using var
                TABLES itab.

form getdata using p_var
          table p_itab STRUCTURE itab.
do necessary code here...
endform.
Read only

Former Member
0 Likes
2,451

Hi nandha,

1. try this code (just copy paste)

REPORT abc.

*----


Can be in Include

DATA : BEGIN OF itab OCCURS 0,

bukrs LIKE t001-bukrs,

pernr LIKE pa0001-pernr,

END OF itab.

*----


DATA : t LIKE table of itab with header line.

PERFORM myform TABLES t.

*----


FORM myform TABLES tb STRUCTURE itab.

ENDFORM. "myform

*----


2. Specifically Note the following :

a) as u said ITAB is already defined in an include.

thats ok.

b) in form definition, use statement

Tables STRUCTURE Itab

(this will tell the form about the strucutre/defn

of table which is going to pass)

I hope it helps.

regards,

amit m.

Read only

0 Likes
2,450

Hi,

Thanks for the reply.according to you your just getting itab not passing variable with itab.

Here i want to pass variable with internal table

that is

perform subrotin using pernr changing instead of variable <itab>.

here i am passing variable(pernr) to the subrotine and i want the internal table for that specific pernr detail from include(subroutine)

for this how i can write.

i tried this

perform get_vleave_info using pernr job_n changing itab1 totdays.

its not working

Thanks

Regards,

Nandha

Read only

0 Likes
2,450

for passing internal tables you need to pass tables statement...

perform get_vleave_info using pernr job_n
                         changing totdays
                          tables  itab1 .

FORM get_vleave_info  USING    P_PERNR
                               P_JOB_N
                      CHANGING P_TOTDAYS
                      TABLES   P_ITAB1 STRUCTURE ITAB.
"write your code here...

ENDFORM.                    " get_vleave_info

Read only

0 Likes
2,450

Hi,

This code is raising error

Field table is unknown.not defined

Thanks

Regards,

nandha

Read only

0 Likes
2,450

can you just show the code what you did?

regards

vijay

Read only

0 Likes
2,450

In Main program

*DATA : itab2 LIKE table of itab3 with header line.

*

  • clear v_totdays.

  • perform get_vleave_info using v_pernr

  • v_job_n

  • changing v_totdays

  • tables itab2.

  • loop at itab2.

  • Write:itab2-v_stdate.

  • endloop.

In Include Program

*FORM get_vleave_info USING V_PERNR

  • V_JOB_N

  • CHANGING V_TOTDAYS

  • TABLES itab1 STRUCTURE itab3.

Data : Begin of itab3 occurs 0,

v_stdate(16) type c,

v_enddate(16) type c,

v_days type i,

end of itab3.

This is the code.

Thanks

Nandha

Read only

0 Likes
2,450
Data : Begin of itab3 occurs 0,
v_stdate(16) type c,
v_enddate(16) type c,
v_days type i,
end of itab3.

DATA : itab2 LIKE table of itab3 with header line.

 clear V_TOtDAYS.
 perform get_vleave_info using v_pernr  v_job_n
                         changing v_totdays
                                  itab2.
 loop at itab2.
 Write:itab2-v_stdate.
 endloop.
In Include Program


FORM get_vleave_info  USING    P_V_PERNR
                               P_V_JOB_N
                      CHANGING P_V_TOTDAYS
                               P_ITAB2 structure itab3.

ENDFORM.                    " get_vleave_info

check this now.....

Read only

0 Likes
2,450

Hi,

Thanks for the reply.

still i am getting error -P_itab2 is not a internal table occurs n missing -- in include program(if i append the internal table P_itab2 )

Thanks

Regards,

Nandha

Read only

0 Likes
2,450

change this

DATA : itab2 LIKE table of itab3 with header line.

to

DATA : itab2 LIKE itab3 occurs 0 with header line.

vijay and try...

Read only

0 Likes
2,450

Hi Nanda,

It is working fine....

Copy and paste this code......

REPORT ZSANJAY_TEST.

DATA : BEGIN OF ITAB3 OCCURS 0,

V_STDATE(16) TYPE C,

V_ENDDATE(16) TYPE C,

V_DAYS TYPE I,

END OF ITAB3.

DATA : ITAB2 LIKE TABLE OF ITAB3 WITH HEADER LINE.

DATA : V_TOTDAYS TYPE I,

V_PERNR TYPE PERNR,

V_JOB_N TYPE I.

CLEAR V_TOTDAYS.

PERFORM GET_VLEAVE_INFO USING V_PERNR V_JOB_N

CHANGING V_TOTDAYS

ITAB2.

LOOP AT ITAB2.

WRITE:ITAB2-V_STDATE.

ENDLOOP.

INCLUDE ZSANJAY_TEST_INCLUDE.

Copy and paste the down code in an include.

----


  • INCLUDE ZSANJAY_TEST_INCLUDE

*----


FORM get_vleave_info USING P_V_PERNR

P_V_JOB_N

CHANGING P_V_TOTDAYS

P_ITAB2 structure itab3.

- Sanjay

Read only

0 Likes
2,450

Hi,

Still same error

Nandha

Read only

0 Likes
2,450

can you paste the code fully ..as you are giving bits and pieces .., but what ever you gave it is working fine...

try to provide maximum..as much as you can...

regards

vijay

Read only

0 Likes
2,450

IN Report prg.

Data : Begin of itab3 occurs 0,

v_stdate(16) type c,

v_enddate(16) type c,

v_days type i,

end of itab3.

DATA : itab2 LIKE itab3 occurs 0 with header line.

clear V_TOtDAYS.

perform get_vleave_info using v_pernr v_job_n

changing v_totdays

itab2.

loop at itab2.

Write:itab2-v_stdate.

endloop.

In Include Program.

FORM get_vleave_info USING P_V_PERNR

P_V_JOB_N

CHANGING P_V_TOTDAYS

P_ITAB2 structure itab3.

Loop at itab.

clear v_stdate.

clear v_enddate.

clear v_days.

perform get_date_days using itab-v_start_dt

itab-v_end_dt

changing v_stdate

v_enddate

v_days.

itab1-v_stdate = v_stdate.

itab1-v_enddate = v_enddate.

itab1-v_days = v_days.

Append itab1.

Endloop.

Here itab1 is i am passing from include prg to main prg.I f append itab1.

It's throughing error -Itab1 is not internal table ,the occurs n specification is missing,

Thanks

Nandha

Read only

0 Likes
2,450

how you declared itab1..

please let me know..

regards

vijay

Read only

0 Likes
2,450

Sorry,

This is code for itab1

FORM get_vleave_info USING P_V_PERNR

P_V_JOB_N

CHANGING P_V_TOTDAYS

ITAB1 structure itab3.

Regards

Nandha

Read only

0 Likes
2,450

Hi nandha,

1.

error -Itab1 is not internal table ,the occurs n specification is missing

The error means that ITAB1 is delcared

as a simple variable(field - string)

BUT NOT AS A TABLE.

2. Hence, the delcaration should be somewhat like this.

data : ITAB1 LIKE TABLE OF XYZ WITH HEADER LINE.

(please note the words TABLE OF )

(There is another way also to declarare,

but one can go with this type of declaration)

3. How & Where is the declaration of itab1.

can u show the code.

regards,

amit m.

Read only

0 Likes
2,450

Hi again,

1. it should be like this

FORM get_vleave_info

TABLES P_V_TOTDAYS ITAB1 structure itab3

USING P_V_PERNR P_V_JOB_N.

2. In FORM definition, use the word TABLEs,

not changing

(bcos we want to pass a table)

3. While calling using PERFORM

use the syntax like this.

perrform get_vleave_info

TABLES xyz

using var1 var2.

( xyz should be an INTERNAL TABLE

and not just a variable / field string.

More over it should be of type ITAB3.

)

regards,

amit m.

Message was edited by: Amit Mittal

Message was edited by: Amit Mittal

Read only

0 Likes
2,450

Hi,

Check this part.Kindly reward points if it helps.

In Include Program.

FORM get_vleave_info USING P_V_PERNR

P_V_JOB_N

CHANGING P_V_TOTDAYS

P_ITAB2 structure itab3.

Loop at itab.

clear v_stdate.

clear v_enddate.

clear v_days.

perform get_date_days using itab-v_start_dt

itab-v_end_dt

changing v_stdate

v_enddate

v_days.

<b>P_ITAB2 -v_stdate = v_stdate.

P_ITAB2 -v_enddate = v_enddate.

P_ITAB2 -v_days = v_days.

Append P_ITAB2 .</b>

Endloop.

Read only

0 Likes
2,450
FORM get_vleave_info USING P_V_PERNR
P_V_JOB_N
CHANGING P_V_TOTDAYS
P_ITAB1 structure itab3.
Loop at itab.
clear v_stdate.
clear v_enddate.
clear v_days.
perform get_date_days using itab-v_start_dt
itab-v_end_dt
changing v_stdate
v_enddate
v_days.
p_itab1-v_stdate = v_stdate.
p_itab1-v_enddate = v_enddate.
p_itab1-v_days = v_days.
Append p_itab1.

Endloop.
Read only

0 Likes
2,450

Problem Solved

Code is

Main Prg

Data : Begin of itab3 occurs 0,

v_stdate(16) type c,

v_enddate(16) type c,

v_days type i,

end of itab3.

DATA : itab2 LIKE table of itab3 with header line.

clear V_TOtDAYS.

perform get_vleave_info TABLES itab2

using v_pernr v_job_n

changing v_totdays.

Include Prg

FORM get_vleave_info TABLES ITAB1 structure itab3

USING V_PERNR V_JOB_N changing P_V_TOTDAYS.

Loop at itab.

clear v_stdate.

clear v_enddate.

clear v_days.

perform get_date_days using itab-v_start_dt

itab-v_end_dt

changing v_stdate

v_enddate

v_days.

itab1-v_stdate = v_stdate.

itab1-v_enddate = v_enddate.

itab1-v_days = v_days.

Append itab1.

Endloop.

Thanks

Regards,

Nandha