2013-03-27

One year of blogging

One year ago (24th of Mars) I wrote my first blog post . This first birthday is just one of three jubilees  I celebrated the last months, I became a member of the gold club , I celebrated my sixtieth birthday and now one year as a blogger. In the light of the other jubilees one year as a blogger is maybe not so much write about.

When I started blogging my intention was to learn and understand what blogging was all about, and this has really been a learning experience. First thing I learned ‘It takes longer time to write posts than I anticipated’. I chose to write about my professional life which the last years have been concentrated around Business Intelligence and extracting data from mainly SAP ERP systems into my Data Warehouse application. Consequently most posts are about those topics. It’s not just to write, you have to test and verify what you write is correct and that is time consuming. Still when I reread post I find errors, it is no easy task to write IT technical articles. I think we all have seen examples that do not work, not even compile. A colleague wrote to me the other day ‘You have a syntax error on line 1...’. You have to pay attention to the most minute details, and that is not something I’m good at, I am a bit offhand and absent-minded (in extreme some would say), and that is not good qualities when writing IT-technical stuff. I have written 69 posts during this year, I think this is impressive since this is no twitter posts (some of them took more than a full day to write).

Another thing I learned and that was as expected, it’s fun to write posts, but I like to write i think this as a prerequisite for blogging. One very surprising and extremely positive finding, blog posts are very suitable for general documentation of applications and programs. I find myself going back to examples in my blog when I forgot a detail.

If you publish you want readers, even if my purpose was not to reach out or market myself I  became more or less obsessed with statistics, I still check every day (more than once) how many are visiting my blog, the number is growing, January was all time high, 556 visits.

Of course you want feedback, but I was not expecting any, and I was more or less right. So far I got one positive feedback, (for which I’m very proud of and very thankful). I got one troll, one who wanted to sell/market a software product and a prank (from a colleague) and that’s all.

I will probably continue to blog, it’s a nice way of document interesting parts of my daily work. I will take on a new mission in short future. and I do not know yet to what extent that mission will lend itself to blog posts. Anyway that I will write a post about when time is due.

           

2013-03-21

PHP 5.4.13 and PHP 5.5.beta

We just successully upgraded from PHP 5.4.11 to PHP 5.4.13 and those two might-be bugs I found in PHP 5.4.11 still remains so I should report the bugs. But today PHP 5.5.beta1 was released, so I will make an effort to install 5.5beta first to see if the bugs is still there and if so report them in PHP 5.5 instead.

2013-03-17

1974-01-12 in disguise

The twelfth of January nineteenseventyfour I IPLed Atlas Copco’s computer alone for the first time. IPL initial Program Load is booting or starting an IBM mainframe computer. During the IPL you had to enter the date i.e. 74-01-12. This american computer  an IBM-360 with it’s american operating system (DOS/360 or maybe DOS/VS) talked american, so it expected the date in american date format 12/01/74 a small detail I had misunderstood. I thought these illogical americans just had reversed the order dayofmonth/month/year, the thought that the american date format was month/dayofmonth/year didn’t even occur to me so I started the computer with the date first of December nineteenhunderedseventyfour, and this was the  twelfth of January. Then I run the nightly batch of jobs.It took almost two weeks to correct the complete and utterly mess I had created. You may ask ‘were there no sanity test at all in the OS or the applications?’ No it wasn’t, there were a few cryptic messages on the console which didn’t tell me thing. In Sweden as in the rest of the more developed world we had since long adopted to standards of the SI system , conceived by the french after their great revolution 1789. After this my first (but not last) fuckup with computers I only used the YY-MM-DD format and if possible YYYY-MM-DD  when some years later I started to program myself.

1985 I installed my application DBAP (DataBase Administrations Processor) at the special materials department at an american company (which I forgot the name of) in Minneapolis. During the training they objected to my date format and asked me to change it into the american standard format which I bluntly refused. The day after one of the guys said ‘I been thinking about this date format and it’s actually great, you just sort on the field and it comes out right! Internally dates was stored as days from 1900-01-01, so that was correct no matter of display format, but the guy had grasped the idea. And he persuaded the other guys they should keep the european  date format. Did I plant a seed or did it fell into oblivion? I sure would like to know that and the name of the company, if you happen to know please drop me a line.

I’m not the only one who have fucked up due to different unit of measure standards. If the SI metric system had been universally adopted the Hubble Telescope would not have had glasses. Nowadays Nasa and the american scientific community try to use the metric SI system.

2013-03-15

PHP 5.4 at last

I often compare software with perishables like milk. Who wants sour milk? Mostly new software versions are better than the previous one. Not utilising new features is wasting money if you ask me. Of course you have to test new versions well before deployment, that goes without saying. This is especially true if you like me are prepared to throw Beta versions into production, and yes I have thrown in Alpha versions too. But only after careful and tedious testing. Not only can you give your audience a better user experience sooner, using bleeding edge software will give you a learning experience and sometimes direct contact with the developers.

I have used all beta versions of PHP since 2001 in production. During the years I have submitted about 5-6 bug reports of those about 2 have classified as bogus, 1 or 2 was fixed (in hours) I reported late night and had a fix in early morning, for the rest of bugs I was not able to give enough info, I’m sorry for that. I learnt a lot from my testing with early alpha releases. Of course you should only put in non-production releases into production if you are prepared to take the full responsibility for failures and burn a lot of midnight oil. It can be very lonely when  you screw up, and that is when  not if .

Anyway this was not the case with PHP5.4, only recently I finally put PHP5.4 (11) in production. I have had problems with SAPRFC and SAPNWRFC. They were not compatible with PHP5.4. SAPRFC I could fix myself, but SAPNWRFC was a too hard nut for me to crack. But recently I found out that the creator and maintainer of SAPNWRFC Piers Harding  had fixed the incompatibilities, so I just downloaded and compiled, tested ( I found one PHP bug, more of that later) and deployed PHP5.4.11 in production beginning of this week.

Thank you so much Piers and Axel Bangert  new maintainer of SAPRFC who have fixed the ‘official’ version of SAPRFC.

In the coming weeks I will upgrade to PHP5.4.12 and start work with PHP5.5.X, I’m especially interested in 5.5 generators, since my PHP job scheduling system ADAP utilize iterators a lot, hopefully generators can be of use.

I think I found a bug in PHP5.4.11, unfortunately I cannot bug report in PHP5.4.11, I have to upgrade to PHP5.4.12 first.

PHP5.4.11 thinks my array is a string and convert my string index to ‘0’ here it is:

This piece of code:

 

Gives the following result:  

The array index $ci=’LOTSIZE’ trigger the buggy warning message and the invalid result $nval=”” when directly indexing the array >>  $fce->$sapTable[$ci]  <<.  

Offloading the array to $nvalarr before indexing with ‘LOTSIZE’ gives the correct result $nval=16.000. Now I missed this error in my tests, we only found this in production. If you are a production planner you know the implications of nullify LOTSIZE, fortunately we stopped this before much harm was done.  

Apart from this small bug PHP5.4 works like a charm for me, so PHP5.5 here I come :))

UPDATE!

I found another possible bug in php 5.4.13

2013-02-28

Business Intelligence Ping Pong

This morning I had this request from a user.

- I need a list of all materials in our plant with purchase prices. Can you fix that?

- Sure

select matnr, purch_price, currcd for materials

I sent the Excel by mail.

-But I need this for all products with quantity?

- You want a BOM exploded list?

- Yes

- Oki

select

a.product,a.component, a.qty, c.purch_price, c.currcd.

from bom_tree a inner join materials  c

on a.component = c.matnr

order by a.product,a.component

I sent the Excel by mail.

-Hello again, I also need lotsize, can you add that

select

a.product,a.component, a.qty, c.lotsize, c.purch_price, c.currcd.

from bom_tree a inner join materials  c

on a.component = c.matnr

order by a.product,a.component

I sent the Excel by mail.

- This is a nice report, but where is the price in swedish crowns?

- There is no price in swedish crowns.

- I also need the purchase price in swedish crowns using company year currency rate, can you add this?

- Shure

select

a.product,a.component, a.qty, c.lotsize, c.purch_price, c.currcd

,round(coalesce(c.purch_price * d.factor,0),2) as 'PRICE_IN_SEK'

from bom_tree a

inner join materials  c on a.component = c.matnr

left join cur_rate d on d.f_currcd = c.currcd and d.t_currcd = 'SEK' and d.year = '2013' and d.ratetype  = 'ACAB'

order by a.product,a.component

I sent the Excel by mail.

-Hello again, I like the report but I also need unit price. Can you add that?

-Yes

select

a.product,a.component, a.qty, c.lotsize, c.purch_price, c.currcd

,round(coalesce(c.purch_price * d.factor,0),2) as 'PRICE_IN_SEK'

,round(coalesce(c.purch_price * d.factor / c.lotsize,0),2) as 'UNIT_IN_SEK'

from bom_tree a

inner join materials  c on a.component = c.matnr

left join cur_rate d on d.f_currcd = c.currcd and d.t_currcd = 'SEK' and d.year = '2013' and d.ratetype  = 'ACAB'

order by a.product,a.component

I sent the Excel by mail.

- Hello, I really like the report, but I also need the description of the component. Can you add?

-Yes.

select

a.product,a.component, c.descr, a.qty, c.lotsize, c.purch_price, c.currcd

,round(coalesce(c.purch_price * d.factor,0),2) as 'PRICE_IN_SEK'

,round(coalesce(c.purch_price * d.factor / c.lotsize,0),2) as 'UNIT_IN_SEK'

from bom_tree a

inner join materials  c on a.component = c.matnr

left join cur_rate d on d.f_currcd = c.currcd and d.t_currcd = 'SEK' and d.year = '2013' and d.ratetype  = 'ACAB'

order by a.product,a.component

I sent the Excel by mail.

-Hello, now I only need the material overhead for the component?

-???

- If you look into transaction CK11 you find  the overhead in there . Can you add it?

This is what I call BI ping pong , and it is not that bad. I’m playing this match now. We paused for the night, and the SQL in here is not the actual SQL  but a slight transcription for clarity . It is iterative development by interaction and it’s fast. When the user contacted me we were not sure what he wanted, but now at least I have a pretty good idea. And we have not spent many minutes on the development. When I have figured out what the material overhead is, this user will come back and say - ‘I want to compare this report with the figures from last year’. And then we already have a very good, tested and working prototype for the OLAP app the user wanted without anyone of us knowing it from the beginning, (the user actually does not know this yet, but I will suggest a Qlikview app tomorrow).

The conventional (and boring) approach; start a project with lots of eventual users creating demand specifications etc. etc. will take longer time, cost more money and deliver a less satisfactory result.    

2013-02-12

RFC READ TABLE and count(*)

Sometimes you need to know the amount of rows in a table before you access the table. If your only weapon in your arsenal is rfc_read_table, you have a problem, it can’t be done. I circumvented this limitation by inserting this piece of code:

Instead of returning the selected part of the table the program now returns the row count, if the parameter ROWCOUNT is set to a negative number. The result is returned in the file TABLE_ROWS.CSV. Admittedly this is a crude hack but it does the job. I am not sure of the (copy)rights of RFC_READ_TABLE so I just publish this addition to the program, but it’s a no-brainer to to figure out how to apply the snippet. (You do not have to be a brain surgeon to create the snippet either.)

This is an example how I pick up the rowcount  for the DD03T table:

In the first job I specify a negative rowcount which activate the ABAP code snippet above in my RFC_READ_TABLE and the rowcount is stored in the TABLE_ROWS.CSV file which is picked up by the ‘TABLEROWS’ tag in the subsequent job ‘calcIterator’ job. When you know how many rows there are in table it’s easy to download the table in chunks. And that I show in another post.

 

2013-01-17

MD_STOCK_REQUIREMENTS_LIST_API performant bulk use

Stock figures; what is in stock and what is available is a challenge in any ERP system. You should not calculate stock figures yourself but use an available function or API. In SAP I have used BAPI_MATERIAL_AVAILABILITY, but now I learnt MD_STOCK_REQUIREMENTS_LIST_API is a better RFC function for this.
It is simple to set up a job in ITL (Integration Tag language) that extracts the stock figures.
This job selects the materials (from a MySQL table the <forevery> job iterator) we like to fetch stock figures for. The job runs the MD_STOCK_REQUIREMENTS_LIST_API for each material and creates a MySQL database table if not exists for the E_MDSTA output and loads the data. If the table exists it is truncated prior to loading.
This job does the work correctly, but it took +70 minutes for 23000 materials . The problem here is that the SAP part of the job is iterated once for each material, it means log on to SAP extract the data and then log off from SAP and all this sequentially. This takes an awful long time (+70 minutes). The best way to solve this is to make an ABAP RFC to do the job. But this time we will to do this without ABAP coding.  
First we like to parallel process the materials in chunks, that is easily fixed:
Adding chunksize and parallel attributes chops the <forevery> array into 1000 row chunks and parallel process them but not more than 10 at a time. This do not however fix the problem with logging on and off to SAP for each material. This can be fixed either by introducing initialization  and termination routines to the <forevery> job iterator or create a piggyback iterator. The piggyback iterator is the simplest solution and requires no PHP coding.  
Now we have a job that chops up the <forevery> into chunks and parallel process each chunk, but this time the job iterator is pushed down to the SAP communicator sap2.php, which now only log on once for the entire chunk. But there is a snag, since we are parallel process the chunks we cannot truncate the target table in this job. We must create a truncate job that we run first.
And that is what this job does. The <prereq> statement intercepts execution if the @TABLE not exists in MySQL. (It would be nice with ‘TRUNCATE IF EXISTS’ command in SQL).
And that’s it, now we extract stock figures for 23000 material in less than 8 minutes, without any ABAP code. This could most likely be optimized below 5 minutes, (see ‘ when fast is not enough ’).
Mixing iterators can create some amazing functionality. If you take a close look at the example above you will find there is quite a lot of functionality packed in there with little code. Creating a job for each chunk with job templates is an alternative, but it is harder to control the parallel processing.
If you like this post I suggest you also read:
My series on Integration Tag language ‘ Job Scheduling with PHP 1-4 ’.