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

data from tables in function module

Former Member
0 Likes
1,090

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

1 ACCEPTED SOLUTION
Read only

former_member188827
Active Contributor
0 Likes
1,045

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.

10 REPLIES 10
Read only

matt
Active Contributor
0 Likes
1,045

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

Read only

Former Member
0 Likes
1,045

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

Read only

Former Member
0 Likes
1,045

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

Read only

Former Member
0 Likes
1,045

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.

Read only

former_member188827
Active Contributor
0 Likes
1,046

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.

Read only

0 Likes
1,045

thanks,,,,abapuser.

i just copy pasted your code and it worked fine....

solved my problem...

Read only

Former Member
0 Likes
1,045

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

Read only

0 Likes
1,045

Hai Firends,

Thanks alot for your solutions and ideas and time.... your help is greatly rewarded...

Thanks SDN !!!!

Thanks,

Simraan.

Read only

matt
Active Contributor
0 Likes
1,045

>

> 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.

Read only

Former Member
0 Likes
1,045

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.