This is just a quick update to my previous post in which I dealt with using the BAPI (Business Programming Application Interface) BAPI_MATERIAL_GETLIST. This update does not change – greatly – the code that makes the rfc (remote function call) call itself. It now gives you the possibility to fill in a form where you can input the number range for which you want to run the query, i.e it is no longer hard coded in the script. You also have to bear in mind that this is ‘quick and dirty’ code. I.e it assumes that :

  • A low and high number will be typed in
  • The material numbers will be numerical (no check is made to verify this)
  • The query will concern one plant code only
  • Also, if no result is returned, you’ll just get an error message (not handled nicely)

Numerical vs Alphanumerical values

As I indicated in my previous post, the BAPI seems to work better if you parse numbers that occupy 18 positions. I.e if you type 200, then it is 000000000000000200 that has to be passed to the query. The script will therefore take whatever number you type in and transform it so that it obeys that rule (left fill with 0 – zeroes).
If on the other hand, in your system you have material masters that are a mixture of numerical and alphanumerical numbers (ot just alphanumerical values), then you will need to change the code in order to deal with those occurences. In other words, just get rid of the following lines or add your bit of code to handle various formats:


// set numerical values to 18 positions
// Take lines below out if MATNR is not NUMERICAL
    for ($i = 0 ; $i = ($matnumlength - strlen($matnrlow)) ; $i++) {
    	$matnrlow = "0" . $matnrlow;
   	}
    for ($i = 0 ; $i = ($matnumlength - strlen($matnrhigh)) ; $i++) {
    	$matnrhigh = "0" . $matnrhigh;
   	}

The plant code

In this script the plant also becomes a variable. I.e you can select it in the form prior to running the query. The plant code is however ‘hard coded’ in the html form (and I think that this is acceptable as you do not add a plant every day). As example plants I have coded Hamburg, Paris and New York. Selecting on of those will respectively parse the values 1000, 2000 and 3000 to the query.

form

If you need to change this to suit your environment, just amend the following lines in the script:





Output

Once you execute the query, the system will simply return a couple of lines indicating the values that it passed to the query and if it finds any, the material numbers corresponding to your search.

result

The code & feedback

As usual, the code is released under Creative Commons License:

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.

You can grab the code here. If you can improve on this code (which should not be too difficult), give back to the community and post your findings. Comments and suggestions are also very welcome.

Privacy Preference Center