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

Issue with Perform statment using internal table

Former Member
0 Likes
639

Hi all,

I have an internal table itab

DATA: ITAB LIKE TABLE OF MARA .

DATA: ITAB1 LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA: WA_ITAB LIKE LINE OF ITAB.

WA_ITAB-MTART = '10'. WA_ITAB-MATKL = '1'.APPEND WA_ITAB TO ITAB.

WA_ITAB-MTART = '20'. WA_ITAB-MATKL = '12'.APPEND WA_ITAB TO ITAB.

PERFORM TEST2 USING ITAB.

loop at itab into wa_itab.

write : wa_itab-mtart.

endloop.

form TEST2 using p_itab LIKE ITAB[].

DELETE P_ITAB INDEX 1.

endform. " TEST2

I get only the second record.

My question is after coming out perform the itab needs to have 2 records

with in the form test2 i'm deleting 1 record but as soon as its comes out of form itab needs to have 2 records

I don't want to change the contents of itab.

contents of itab before entering the perform and coming out of form must be same but with in the form i need to delete few records for some other purpose

can anyone let me know how to do this

Thanks

Kajol

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
592

Hi,

We can use the Pass by value or pass by value and return.

what you have done in program is pass by b refernce.

We can aslo use the TABLES sattement or Instead of using

use CHANGING.

BOLD ones are changes in code-

DATA: ITAB LIKE TABLE OF MARA .

DATA: ITAB1 LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA: WA_ITAB LIKE LINE OF ITAB.

WA_ITAB-MTART = '10'. WA_ITAB-MATKL = '1'.APPEND WA_ITAB TO ITAB.

WA_ITAB-MTART = '20'. WA_ITAB-MATKL = '12'.APPEND WA_ITAB TO ITAB.

loop at itab into wa_itab.

write : wa_itab-mtart color 3.

endloop.

skip.

PERFORM TEST2 changing ITAB[].

loop at itab into wa_itab.

write : wa_itab-mtart color 4.

endloop.

form TEST2 changing value(p_itab1) like itab[] .

data:

lv_tab like p_itab1.

DELETE lv_TAB INDEX 1.

endform. " TEST2

delcare one more internal table inside FORM and ENDFORM and then perfiorm on this.

Reward if helpful.

Best Wishes,

Chandralekha

Edited by: Chandralekha on Jul 5, 2008 7:22 AM

4 REPLIES 4
Read only

Former Member
0 Likes
593

Hi,

We can use the Pass by value or pass by value and return.

what you have done in program is pass by b refernce.

We can aslo use the TABLES sattement or Instead of using

use CHANGING.

BOLD ones are changes in code-

DATA: ITAB LIKE TABLE OF MARA .

DATA: ITAB1 LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA: WA_ITAB LIKE LINE OF ITAB.

WA_ITAB-MTART = '10'. WA_ITAB-MATKL = '1'.APPEND WA_ITAB TO ITAB.

WA_ITAB-MTART = '20'. WA_ITAB-MATKL = '12'.APPEND WA_ITAB TO ITAB.

loop at itab into wa_itab.

write : wa_itab-mtart color 3.

endloop.

skip.

PERFORM TEST2 changing ITAB[].

loop at itab into wa_itab.

write : wa_itab-mtart color 4.

endloop.

form TEST2 changing value(p_itab1) like itab[] .

data:

lv_tab like p_itab1.

DELETE lv_TAB INDEX 1.

endform. " TEST2

delcare one more internal table inside FORM and ENDFORM and then perfiorm on this.

Reward if helpful.

Best Wishes,

Chandralekha

Edited by: Chandralekha on Jul 5, 2008 7:22 AM

Read only

Former Member
0 Likes
592

Hi,

Pls Change your code like below .

DATA: ITAB LIKE TABLE OF MARA .

DATA: ITAB1 LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA: WA_ITAB LIKE LINE OF ITAB.

WA_ITAB-MTART = '10'. WA_ITAB-MATKL = '1'.APPEND WA_ITAB TO ITAB.

WA_ITAB-MTART = '20'. WA_ITAB-MATKL = '12'.APPEND WA_ITAB TO ITAB.

PERFORM TEST2 using itab.

loop at itab into wa_itab.

write : wa_itab-mtart.

endloop.

form TEST2 using value(p_itab) LIKE ITAB.

DELETE P_ITAB INDEX 1.

endform. " TEST2

Hope you will get your Result.

Regards,

Sujit

Read only

Former Member
0 Likes
592

Hi,

As given above answer

you pass itab BY VALUE Instead of REFERENCE.

Then internal table values will not be changed within the subroutine. Scope is within that subroutine only. So, changes will not affect the ITAB in main program.

DATA: ITAB LIKE TABLE OF MARA .
DATA: ITAB1 LIKE MARA OCCURS 0 WITH HEADER LINE.
DATA: WA_ITAB LIKE LINE OF ITAB.


WA_ITAB-MTART = '10'. WA_ITAB-MATKL = '1'.APPEND WA_ITAB TO ITAB.
WA_ITAB-MTART = '20'. WA_ITAB-MATKL = '12'.APPEND WA_ITAB TO ITAB.

PERFORM TEST2 USING ITAB.

loop at itab into wa_itab.

write : wa_itab-mtart.

endloop.

form TEST2 using  value(p_itab)  LIKE ITAB[].

DELETE P_ITAB INDEX 1.
endform. " TEST2

Regards,

Rajitha.

Read only

Former Member
0 Likes
592

hi Kajol,

form TEST2 using p_itab LIKE ITAB[].

DELETE P_ITAB INDEX 1.

endform. " TEST2

you have written like this.. but for this coding you will be getting a warning message that p_itab should not be changed..

as you are just using 'using' parameter not 'changing ' parameter in this.

in form you are deleteing a record of internal table without giving attention to the warining..

as its delete statement, it will do its work of deletion.

and if you don want to change itab data then

itab1[] = itab[].

then do modification with itab1..

hope this will help u out..