Application Development 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: 

Remote enabled FM for list of Materials

Former Member
0 Kudos

Hello All,

I need a remote enabled FM which fetches me a list of materials based on a Plant value as well as a range of Material types...

So far i have found a FM "BAPI_MATERIAL_GETLIST" but it has selection options only for Plant.

Has anyone any idea on this??hs anyone written any remote enabled FM which serves the above task??

regards,

Disha.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Mara has index based on material type, but since you have used join no indexing techniques will be used. WHy dont you split the select into selects on single table. Query mara based on MTART ( assuming you will not be passsing material number all the time ), Store all the entries in a table, Pass this to MARC and get the filtered entries.

20 REPLIES 20

vinod_gunaware2
Active Contributor
0 Kudos

RFC_SELECT_OBJ_VIA_MATCHCODE

RFC_DISPLAY_MATERIAL_MASTER

regards

vinod

Former Member
0 Kudos

Since there is only one table to fetch data from ( MARA ) i think you can create ur own remote enabled function module and write a query which will fetch all the materials from MARA for a given range of material types.

former_member181962
Active Contributor
0 Kudos

In case you don't find one, write your own.

Code:

select *

from mara

where <where cond>.

REgards,

Ravi

0 Kudos

Hi All,,

I wrote a Z FM on the lines of BAPI_MATERIAL_GETLIST..but still im not getting the desired result.....Im not able to undesrtand why teh FM is taking so long to fetch teh list of materials when im calling it form other system(SRM).....

What i need is that i get teh list of materilas form MARA table base don Mat type and then MARC table based on PLant for the fetched netries form MARA..acc i have written the logic in my Z FM ..but still when i call this FM frm My SR system ,it takes almost the same time as BAPI_MATERIAL_GETLIST.....

My query is as follows:

SELECT DISTINCT a~matnr

UP TO maxrows ROWS

INTO TABLE matnr

FROM mara AS a INNER JOIN

marc AS c ON amatnr = cmatnr

WHERE ( a~matnr IN matnrselection

AND a~mtart IN mtypeselection

AND c~werks IN plantselection ).

PLease can nayone tellme whether im missing out anything anywhere???

regards,

Disha.

Former Member
0 Kudos

Mara has index based on material type, but since you have used join no indexing techniques will be used. WHy dont you split the select into selects on single table. Query mara based on MTART ( assuming you will not be passsing material number all the time ), Store all the entries in a table, Pass this to MARC and get the filtered entries.

0 Kudos

Hi All,

i tried this but my problem is im not able to analyse why is it taking more time to fetch the materilas wheni call it from other system (SRM)....Could this b due to RFC/Network probs??

regards,

Disha.

0 Kudos

Try executing the query on the system in which data exists, if it not taking more time, then it is problem with your query.

Further, I hope 'matnrselection' is not blank, if it is blank then no indexing is used.

Former Member
0 Kudos

Hi,

If you are passing material number in the select then it should not take much time, but if you are not then it will take a lot of time to fetch, since the number of entries generally are very high in MARA and much more in MARC ( depends on the type company). if this is the case then it is natural to take large amount of time.

0 Kudos

Hi,

In matnrselection im passing *...so what do u suggest using BAPI_MATERIAL_GETLIST or my Z-FM??

Regards,

Disha.

0 Kudos

Hi,

I would always prefer standard BAPI

1. I don't have to worry about the upgrades and the impact on the custom code

2. Its written for optimum performance and I don't have worry about tuning my custom code

3. No maintenance for me

4. If something is wrong, SAP will fix it

So, as long as the requirement is met, go for the standard BAPI's

Regards,

Ravi

Note : Please mark the helpful answers and close the thread if the question is answered

0 Kudos

As your are passing '*' in matnrselection, no indexing is applied on both the tables, & its taking time for extraction.

Pass some value to matnrselection and see the result.

0 Kudos

Moreover, if you use 'for all entries' instead of join then passing '*' in matnrselection results in no indexing only in first table (with is better than join).

0 Kudos

Hello All,

Thanks a lot for all your responses.

Regards,

Disha.

0 Kudos

hi all,

just a small doubt once again.....i have used the form CHECK_RANGE (as in the FM BAPI_MATERIAL_GETLIST) in my Z-FM...is this needed or i can skip this part in my Z-FM...???

Any thoughts ??

Regards,

Disha.

Former Member
0 Kudos

i dont see anything wrong in using your ZFM.

Former Member
0 Kudos

It is important to validate the data that is flowing into RFC. Validation is necessary if the incoming data is not valid at all.

For ex: SIGN can be 'I' or 'E'. if it is anything else, then you should treat that as an invalid entry.

0 Kudos

Hi All,

I have a created a Z-FM whcih fetches me list of materials based on Plant,material no,material description and material group.

Now my problem is that for the foll conditions ,my code is not working properly:

1> mat no,mat desc and mat grp given.

2>mat no,mat desc given

3>mat desc and mat grp given

4>mat no and mat grp given

Here is my code for review:

-


CONSTANTS: C_MATNRSELECTION LIKE BAPIRET2-PARAMETER

VALUE 'MATNRSELECTION',

C_MATERIALSHORTDESCSEL LIKE BAPIRET2-PARAMETER

VALUE 'MATERIALSHORTDESCSEL',

C_PLANTSELECTION LIKE BAPIRET2-PARAMETER

VALUE 'PLANTSELECTION',

C_MATGRPSELECTION LIKE BAPIRET2-PARAMETER

VALUE 'MATGRPSELECTION'.

TYPES : BEGIN OF TY_MAT,

MATNR TYPE MARA-MATNR,

MAKTX TYPE MAKT-MAKTX,

MATKL TYPE MARA-MATKL,

END OF TY_MAT.

DATA : W_QUERY TYPE STRING,

W_FEHLER LIKE SY-DATAR.

DATA : IT_MATNR TYPE STANDARD TABLE OF TY_MAT ,

WA_IT_MATNR LIKE LINE OF IT_MATNR,

IT_MAT_FINAL TYPE STANDARD TABLE OF TY_MAT,

WA_IT_MAT_FINAL LIKE LINE OF IT_MAT_FINAL.

******************Initialisation*********************

REFRESH MATNRLIST.

REFRESH RETURN.

*****************selection parameter*****************

CLEAR W_FEHLER.

LOOP AT MATNRSELECTION.

PERFORM ZCHECK_RANGE TABLES RETURN

USING SY-TABIX

C_MATNRSELECTION

CHANGING MATNRSELECTION-MATNR_LOW

MATNRSELECTION-MATNR_HIGH

MATNRSELECTION-SIGN

MATNRSELECTION-OPTION

W_FEHLER.

CHECK W_FEHLER IS INITIAL.

MODIFY MATNRSELECTION.

ENDLOOP.

LOOP AT MATERIALSHORTDESCSEL.

PERFORM ZCHECK_RANGE TABLES RETURN

USING SY-TABIX

C_MATERIALSHORTDESCSEL

CHANGING MATERIALSHORTDESCSEL-DESCR_LOW

MATERIALSHORTDESCSEL-DESCR_HIGH

MATERIALSHORTDESCSEL-SIGN

MATERIALSHORTDESCSEL-OPTION

W_FEHLER.

CHECK W_FEHLER IS INITIAL.

MODIFY MATERIALSHORTDESCSEL.

ENDLOOP.

LOOP AT PLANTSELECTION.

PERFORM ZCHECK_RANGE TABLES RETURN

USING SY-TABIX

C_PLANTSELECTION

CHANGING PLANTSELECTION-PLANT_LOW

PLANTSELECTION-PLANT_HIGH

PLANTSELECTION-SIGN

PLANTSELECTION-OPTION

W_FEHLER.

CHECK W_FEHLER IS INITIAL.

MODIFY PLANTSELECTION.

ENDLOOP.

LOOP AT MATGRPSELECTION .

PERFORM ZCHECK_RANGE TABLES RETURN

USING SY-TABIX

C_MATGRPSELECTION

CHANGING MATGRPSELECTION-ZMGRP_LOW

MATGRPSELECTION-ZMGRP_HIGH

MATGRPSELECTION-ZSIGN

MATGRPSELECTION-ZOPTION

W_FEHLER.

CHECK W_FEHLER IS INITIAL.

MODIFY MATGRPSELECTION.

ENDLOOP.

<b>IF ( MATNRSELECTION[] IS NOT INITIAL AND MATERIALSHORTDESCSEL[] IS NOT INITIAL AND MATGRPSELECTION[] IS NOT INITIAL ).

SELECT A~MATNR

A~MATKL

B~MAKTX

INTO CORRESPONDING FIELDS OF TABLE IT_MAT_FINAL

FROM MARA AS A INNER JOIN

MAKT AS B ON AMATNR = BMATNR

WHERE A~MATNR IN MATNRSELECTION

AND ( AMTART = 'GEN' OR AMTART = 'UTI' OR A~MTART = 'CAP' )

AND A~MATKL IN MATGRPSELECTION

AND B~SPRAS = SY-LANGU

AND B~MAKTX IN MATERIALSHORTDESCSEL.</b><b>ELSE.

IF ( MATNRSELECTION[] IS NOT INITIAL AND MATERIALSHORTDESCSEL[] IS NOT INITIAL AND MATGRPSELECTION[] IS INITIAL ).

SELECT A~MATNR

A~MATKL

B~MAKTX

INTO CORRESPONDING FIELDS OF TABLE IT_MAT_FINAL FROM MARA AS A INNER JOIN

MAKT AS B ON AMATNR = BMATNR

WHERE A~MATNR IN MATNRSELECTION

AND ( AMTART = 'GEN' OR AMTART = 'UTI' OR A~MTART = 'CAP' )

AND B~SPRAS = SY-LANGU

AND B~MAKTX IN MATERIALSHORTDESCSEL</b>.

<b>ELSE.

IF ( MATNRSELECTION[] IS INITIAL AND MATERIALSHORTDESCSEL[] IS NOT INITIAL AND MATGRPSELECTION[] IS NOT INITIAL ).

SELECT A~MATNR

A~MATKL

B~MAKTX

INTO CORRESPONDING FIELDS OF TABLE IT_MAT_FINAL

FROM MARA AS A INNER JOIN

MAKT AS B ON AMATNR = BMATNR

WHERE ( AMTART = 'GEN' OR AMTART = 'UTI' OR A~MTART = 'CAP' )

AND A~MATKL IN MATGRPSELECTION

AND B~SPRAS = SY-LANGU

AND B~MAKTX IN MATERIALSHORTDESCSEL.

ELSE.</b>

<b>IF ( MATNRSELECTION[] IS NOT INITIAL AND MATERIALSHORTDESCSEL[] IS INITIAL AND MATGRPSELECTION[] IS NOT INITIAL ).

SELECT A~MATNR

A~MATKL

B~MAKTX

INTO CORRESPONDING FIELDS OF TABLE IT_MAT_FINAL

FROM MARA AS A INNER JOIN

MAKT AS B ON AMATNR = BMATNR

WHERE A~MATNR IN MATNRSELECTION

AND ( AMTART = 'GEN' OR AMTART = 'UTI' OR A~MTART = 'CAP' )

AND A~MATKL IN MATGRPSELECTION

AND B~SPRAS = SY-LANGU.</b>

ENDIF.

*to select the materials from MARA

TRY.

SELECT A~MATNR

A~MATKL

B~MAKTX

INTO CORRESPONDING FIELDS OF TABLE IT_MAT_FINAL

FROM MARA AS A INNER JOIN

MAKT AS B ON AMATNR = BMATNR

WHERE (W_QUERY).

CATCH CX_SY_DYNAMIC_OSQL_ERROR.

ENDTRY.

*to select materials form MARC based on Plant

IF IT_MAT_FINAL IS NOT INITIAL.

SELECT MATNR

INTO CORRESPONDING FIELDS OF TABLE IT_MATNR

FROM MARC

FOR ALL ENTRIES IN IT_MAT_FINAL

WHERE MATNR = IT_MAT_FINAL-MATNR

AND WERKS IN PLANTSELECTION.

ENDIF.

*gathering data in the required o/p format

LOOP AT IT_MATNR INTO WA_IT_MATNR.

LOOP AT IT_MAT_FINAL INTO WA_IT_MAT_FINAL WHERE MATNR = WA_IT_MATNR-MATNR.

WA_IT_MATNR-MATNR = WA_IT_MAT_FINAL-MATNR.

WA_IT_MATNR-MATKL = WA_IT_MAT_FINAL-MATKL.

WA_IT_MATNR-MAKTX = WA_IT_MAT_FINAL-MAKTX.

MODIFY IT_MATNR FROM WA_IT_MATNR.

ENDLOOP.

ENDLOOP.

*assigning data to the final o/p table

IF NOT IT_MATNR[] IS INITIAL.

SORT IT_MATNR.

LOOP AT IT_MATNR INTO WA_IT_MATNR.

CLEAR MATNRLIST.

MATNRLIST-MATERIAL = WA_IT_MATNR-MATNR.

MATNRLIST-MATL_GRP = WA_IT_MATNR-MATKL.

MATNRLIST-MATL_DESC = WA_IT_MATNR-MAKTX.

APPEND MATNRLIST.

ENDLOOP.

ENDIF.

CLEAR : MATNRSELECTION[],

MATERIALSHORTDESCSEL[],

MATGRPSELECTION[].

-


The code in bold is only for teh conditions which are not working(all other combination conditions are woking fine).For the 1st select,im considerig only teh selection for material no,material description and Material group.

Please can anyone suggest something on this??

regards,

Disha.

0 Kudos

Hi,

Anyone any thougts on this???

regards,

Disha.

Former Member
0 Kudos

But a break point at.

IF ( MATNRSELECTION[] IS NOT INITIAL AND MATERIALSHORTDESCSEL[] IS NOT INITIAL AND MATGRPSELECTION[] IS NOT INITIAL ).

check whethere MATNRSEELCTION[] has any entries, similary check other select options, otherwise i dont see anything wrong with your code.

0 Kudos

Hi,

It seems there was some problem when I was using the Text-symbols for teh where condition in my query!!!

Thanks for the attention to my post.

BR,

Disha.