cancel
Showing results for 
Search instead for 
Did you mean: 

Why the extraction will be excuted serveral times when I create datasource by Funcion Module

Former Member
0 Kudos

Hi Guys

I created a datasource by using function module.

But there is something coufused me.

When I use infopackage to load the data from ecc to bw

There will be serveral data packages which contains same data.

Actually, It should be one data package contain all data. But now I have serveral duplicate.

Below is the code.

I combined MBEW MCHA By materail(MATNR),Plant(BWKEY)and BWTAR.

Actually, I don't need the rsa3 to test (I don't know how to avoid this part in the code,but have to write something I don't think necessary).So I used "Refresh E_T_DATA" in the code.

Accepted Solutions (1)

Accepted Solutions (1)

sander_vanwilligen
Active Contributor
0 Kudos

Hi,

Can you please share the complete coding of the Function Module?

Best regards,

Sander

Former Member
0 Kudos

Hi

I don't know why I canot paste something here, so I upload a txt file

Former Member
0 Kudos

You are receiving same data many times because you are clearing E_T_DATA after selecting from FETCH CURSOR.

And then you are selecting more data from MBEW and MCHA again without any cursors.

So ideally you are selecting from JOIN on 2 tables but then clear out the result set and selecting again.

I think your further selection should be based on data you get from FETCH statement.

Below code is the problem (bold statement):

--------------------------------------------------------------

   FETCH NEXT CURSOR S_CURSOR

               APPENDING CORRESPONDING FIELDS

               OF TABLE E_T_DATA

               PACKAGE SIZE S_S_IF-MAXSIZE.

    IF SY-SUBRC <> 0.

      CLOSE CURSOR S_CURSOR.

      RAISE NO_MORE_DATA.

    ENDIF.

REFRESH  E_T_DATA.

SELECT MATNR BWKEY BWTAR VERPR FROM MBEW INTO CORRESPONDING FIELDS OF TABLE T_MBEW.

SORT T_MBEW BY MATNR BWKEY BWTAR.

DELETE T_MBEW WHERE VERPR = '0.00'.

DELETE T_MBEW WHERE BWTAR = ''.

DELETE ADJACENT DUPLICATES FROM T_MBEW COMPARING ALL FIELDS.

SELECT MATNR WERKS CHARG BWTAR FROM MCHA INTO CORRESPONDING FIELDS OF TABLE T_MCHA.

  SORT T_MCHA BY MATNR WERKS BWTAR.

  DELETE T_MCHA WHERE CHARG = ''.

  DELETE T_MCHA WHERE BWTAR = ''.

  DELETE ADJACENT DUPLICATES FROM T_MCHA COMPARING ALL FIELDS.

----------------------------------------------------------------------

If you are already joining it in OPEN cursor statement why do you have additional selects on the same tables?

Thanks

Amit

Former Member
0 Kudos

Hi Amit

Because there is something I don't need in the result of first select

Like <> '0.00';<>''.

You know if I wirte <> in the select, It will very slow

Former Member
0 Kudos

Also the 2 statements are issue because they always pick the first condition satisfying records only each time.

If you really need to do a select from the same tables again after fetch, then you should do a FOR ALL ENTRIES on E_T_DATA.

something like -

SELECT MATNR BWKEY BWTAR VERPR FROM MBEW FOR ALL ENTRIES IN E_T_DATA INTO CORRESPONDING FIELDS OF TABLE T_MBEW

WHERE MATNR = E_T_DATA-MATNR

AND BWKEY = E_T_DATA-BWKEY

AND BWTAR = E_T_DATA-BWTAR

AND VERPR = E_T_DATA-VERPR.

And

SELECT MATNR WERKS CHARG BWTAR FROM MCHA FOR ALL ENTRIES IN E_T_DATA INTO CORRESPONDING FIELDS OF TABLE T_MCHA

WHERE MATNR = E_T_DATA-MATNR

AND BWTAR = E_T_DATA-BWTAR

AND CHARG = E_T_DATA-CHARG.

You may want to tune the code more. Else I would suggest you can get ride of these extra select statements in your OPEN CURSOR statement only by putting right selections.

Thanks

Amit

Former Member
0 Kudos

Agreed, but OPEN-FETCH CURSOR Statements are used for a reason. So that you don't receive same data again and again. You should not clear E_T_DATA but instead take E_T_DATA data for further selection.

Thanks

Amit

Former Member
0 Kudos

ok,thank you so much

Answers (0)