‎2009 Jul 09 6:39 AM
Dear friends,
I am trying a PO smartfrom in the driving program I have hanged in a situation where in the subroutine i am calling a function module (this FM takes a po number and a item number and returns the contition types and values accordingly.)
But the problem:-when i loop the itab its returning only the last feteched item no detials . I think some prob in workarea append king of things....Please help and rectify the code.
data ITAB_KOMV LIKE KOMV OCCURS 1 WITH HEADER LINE.
PERFORM GET_ITEM_DETAILS.
loop at itab_komv.
write :/ itab_komv-kposn, itab_komv-KSCHL, itab_komv-kwert.
endloop.
FORM GET_ITEM_DETAILS.
SELECT EBELN
EBELP
EMATN
TXZ01 "specification ----EKPO--TXZ01
BANFN
ANFNR
WERKS
MEINS
MENGE
NETPR
MWSKZ "tax code
PSTYP
ADRNR
FROM EKPO
INTO CORRESPONDING FIELDS OF
ITAB_EKPO WHERE EBELN EQ PO_NUMBER.
***tax calulattions
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv
.
append itab_ekpo.
endselect.output:-
00140 13000 like that
but it shd give,
00010
00020
.
.
00140..
pls help with the code.
Edited by: Matt on Jul 9, 2009 7:49 AM
‎2009 Jul 09 6:56 AM
which internal table are you looping itab_ekpo or itab_komv?
if it is itab_komv,i think the table gets refreshed every time you call fm 'ZMM_CALCULATE_TAX_ITEM' .its better that u declare another internal table say itab_komv1 and use it in function module and then append line of this table to itab_komv.
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv1
.
loop at itab_komv1.
move-corresponding itab_komv1 to itab_komv.
append itab_komv.
endloop.
‎2009 Jul 09 6:52 AM
The problem looks to be in your function module ZMM_CALCULATE_TAX_ITEM - it's returning only the last item. Why not test it directly in SE37, and see if that really is the case.
matt
‎2009 Jul 09 6:52 AM
Hi Simraan,
use this.
data ITAB_KOMV LIKE KOMV OCCURS 1 WITH HEADER LINE,
wa_komv type komv,
wa_ekpo type ekpo.
PERFORM GET_ITEM_DETAILS.
loop at itab_komv.
write 😕 itab_komv-kposn, itab_komv-KSCHL, itab_komv-kwert.
endloop.
FORM GET_ITEM_DETAILS.
SELECT EBELN
EBELP
EMATN
TXZ01 "specification -
EKPO--TXZ01
BANFN
ANFNR
WERKS
MEINS
MENGE
NETPR
MWSKZ "tax code
PSTYP
ADRNR
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE
ITAB_EKPO WHERE EBELN EQ PO_NUMBER.
Loop at itab_ekpo into wa_ekpo.
***tax calulattions
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = wa_ekpo-ebeln
P_EBELP = wa_ekpo-ebelp
TABLES
it_komv2 = itab_komv
.
Read itab_komv into wa_komv with key ebeln = wa_ekpo-ebeln ebelp = wa_ekpo-ebelp.
if sy-subrc - 0.
move : wa_komv-field1 to wa_ekpo-field1.
Modify itab_ekpo from wa_ekpo transporting field1..
endif.
endloop.
Regards,
Vijay
‎2009 Jul 09 6:53 AM
HI,
You are bound to get the last record because you are writing after the loop.
data ITAB_KOMV LIKE KOMV OCCURS 1 WITH HEADER LINE.
PERFORM GET_ITEM_DETAILS.
loop at itab_komv.
write :/ itab_komv-kposn, itab_komv-KSCHL, itab_komv-kwert.
endloop.
FORM GET_ITEM_DETAILS.
SELECT EBELN
EBELP
EMATN
TXZ01 "specification ----EKPO--TXZ01
BANFN
ANFNR
WERKS
MEINS
MENGE
NETPR
MWSKZ "tax code
PSTYP
ADRNR
FROM EKPO
INTO CORRESPONDING FIELDS OF
ITAB_EKPO WHERE EBELN EQ PO_NUMBER.
***tax calulattions
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv.
append itab_ekpo.
* basically your write statement should be here
*loop at itab_komv.
*write :/ itab_komv-kposn, itab_komv-KSCHL, itab_komv-kwert.
*
*endloop.
endselect.So that with every loop pass of the select statement the conditions are printed for every line item.
What i pointed out to you is the mistake which you are doing.
But the solution is not the correct one.
Within SELECT-ENDSELECT you should never code anything so as to avoid performance problems.
First try to get all data from EKPO into an internal table for the PO.
Do as follows
SELECT EBELN
EBELP
EMATN
TXZ01 "specification ----EKPO--TXZ01
BANFN
ANFNR
WERKS
MEINS
MENGE
NETPR
MWSKZ "tax code
PSTYP
ADRNR
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE
ITAB_EKPO WHERE EBELN EQ PO_NUMBER.
loop at itab_po.
refresh : itab_komv.
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv.
loop at itab_komv.
write :/ itab_komv-kposn, itab_komv-KSCHL, itab_komv-kwert.
endloop.
endloop.I hope you get my point.
Regards,
Ankur Parab
Edited by: Ankur Parab on Jul 9, 2009 11:25 AM
‎2009 Jul 09 6:54 AM
Hello
1. Declare new internal table like itab_komv
2. Add into code:
data ITAB_KOMV LIKE KOMV OCCURS 1 WITH HEADER LINE.
data ITAB_KOMV_1 LIKE KOMV OCCURS 1 WITH HEADER LINE. " add this line
PERFORM GET_ITEM_DETAILS.
loop at itab_komv.
write :/ itab_komv-kposn, itab_komv-KSCHL, itab_komv-kwert.
endloop.
FORM GET_ITEM_DETAILS.
SELECT EBELN
EBELP
EMATN
TXZ01 "specification ----EKPO--TXZ01
BANFN
ANFNR
WERKS
MEINS
MENGE
NETPR
MWSKZ "tax code
PSTYP
ADRNR
FROM EKPO
INTO CORRESPONDING FIELDS OF
ITAB_EKPO WHERE EBELN EQ PO_NUMBER.
***tax calulattions
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv
.
APPEND LINES OF ITAB_KOMV TO ITAB_KOMV_1. " add this line
append itab_ekpo.
endselect.
refresh ITAB_KOMV. " add this line
ITAB_KOMV[] = ITAB_KOMV_1[]. " add this line
It will be work.
‎2009 Jul 09 6:56 AM
which internal table are you looping itab_ekpo or itab_komv?
if it is itab_komv,i think the table gets refreshed every time you call fm 'ZMM_CALCULATE_TAX_ITEM' .its better that u declare another internal table say itab_komv1 and use it in function module and then append line of this table to itab_komv.
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv1
.
loop at itab_komv1.
move-corresponding itab_komv1 to itab_komv.
append itab_komv.
endloop.
‎2009 Jul 09 8:13 AM
thanks,,,,abapuser.
i just copy pasted your code and it worked fine....
solved my problem...
‎2009 Jul 09 6:58 AM
Hi Simran,
You are passing the value of PO and PO items to FM from export parameters.
You have not called this FM within loop.
Hence to the FM, only last record value of your internal table is passed as export parameters.
TO overcome this problem, please call the function module within the loop of inetrnal table.
loop at ITAB_EKPO
***tax calulattions
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv
endloop.
Hope this will solve your problem.
Best Regards,
Deepa Kulkarni
‎2009 Jul 09 7:19 AM
Hai Firends,
Thanks alot for your solutions and ideas and time.... your help is greatly rewarded...
Thanks SDN !!!!
Thanks,
Simraan.
‎2009 Jul 09 8:15 AM
>
> Hai Firends,
> Thanks alot for your solutions and ideas and time.... your help is greatly rewarded...
>
> Thanks SDN !!!!
>
> Thanks,
> Simraan.
Not so far it isn't.
‎2009 Jul 09 7:21 AM
FORM GET_ITEM_DETAILS.
SELECT EBELN
EBELP
EMATN
TXZ01 "specification -
EKPO--TXZ01
BANFN
ANFNR
WERKS
MEINS
MENGE
NETPR
MWSKZ "tax code
PSTYP
ADRNR
FROM EKPO
INTO CORRESPONDING FIELDS OF
ITAB_EKPO WHERE EBELN EQ PO_NUMBER.
***tax calulattions
CALL FUNCTION 'ZMM_CALCULATE_TAX_ITEM'
EXPORTING
P_EBELN = itab_ekpo-ebeln
P_EBELP = itab_ekpo-ebelp
TABLES
it_komv2 = itab_komv[].
append itab_ekpo.
endselect.
use itab_komv[] in tables statement as it is declared with the header line.