‎2008 Jul 05 5:51 AM
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
‎2008 Jul 05 6:10 AM
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
‎2008 Jul 05 6:10 AM
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
‎2008 Jul 05 6:32 AM
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
‎2008 Jul 05 6:37 AM
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. " TEST2Regards,
Rajitha.
‎2008 Jul 05 6:38 AM
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..