2015-05-16

RTFM, PHP closures revisited

Stockholm 2015-05-16


Some time ago I wrote two posts called Dynamic PHP code by closures and Dynamic PHP code 2. I complained about having to use the eval instruction when I created the closure, this was of course wrong. Now when I need to create another closure from a text script, I decided to read the manual. Instead of  using the function instruction as used in my previous attempt, I found out that create_function allows me to do what I want without eval. So without further ado:


Sometimes the SAP formats values a bit odd e.g. instead of responding 100 for one hundred percent SAP gives *0.00, this is not a value you can import in a numeric declared database column. To solve this and other formatting problems I decided to implement post formatting as PHP closures, an example:
This job executes the SAP bapi BAPI_CURRENCY_GETLIST. If you look at the <columnfunctions> You can see I added formatting functions for three columns; LONG_TEXT,CURRENCY and MESSAGE. 

The PHP code creating the closures from this looks like:
Running the job above results in the following MySQL table:

No comments:

Post a Comment