Thursday, July 18, 2013

Just fill in the blanks

Reading the SAP source code is always full of surprises. In this case it was in the SCM system, after finding some useful functionality that was not documented, some additional search on how to maintain the values leads to the following procedure.


It feels like the school books, one just needs to fill in the blanks :-)

Labels:

Tuesday, June 12, 2012

Interview with Ole Andre Haugen and Njål Stabell

I recently got to know an interesting product for mobile SAP development from Neptune Software, a Norwegian software shop. Two things caught my attention, they are a startup in the SAP ecosystem, and they are building SAP HTML5 designer, an ABAP development framework for mobile devices. I am quite interested in both topics so I asked Ole-Andre, the CEO of Neptune Software, if he would be interested in a short interview for the blog and he kindly accepted.

[OAH] Ole Andre Haugen – CEO Neptune Software
[NST] Njål Stabell – CTO Neptune Software


Can you tell us more about you and how you started with SAP?

[OAH] I started with SAP back in 1995 after serving as an officer in the Norwegian armed forces as Instructor and Field Engineer. I have since worked with SAP either as consultant or manager in consultancy firms.
[NST] Actually I started out as a Java developer in the late 90’s and was lured into the SAP world through integration projects and java development on the SAP Internet Sales solution. It took me some years to fully embrace and accept the ABAP language but I now cherish its performance, simplicity and suitability for enterprise business logic.


Can you tell us about your company products and goals?

[OAH] Neptune Software is the result of years and years of real-life SAP projects and experience and not a lab product. We have tried to make our product the optimal development tool that we ourselves would have wanted to use as project developers. The result is a tool that combines the best of the features of the SAP Developer Workbench with the functionality we have always desired. As an example we have reused the idea of data binding from Webdynpro and added far better language support in our solution.

[NST] I would like to add that the trigger of this specific product was the emergence of HTML5 as the “code once run anywhere” de facto standard for mobile development. We could not have delivered the kind of quality we do without the open source development communities producing great frameworks like jQuery Mobile and Phonegap(Cordova).

[OAH] So, our product is an SAP certified HTML5 designer within the SAP Netweaver platform. We provide a server, a “drag & drop” designer and tools for creating Apps for multiple devises based on existing SAP functionality. We have no ambitions to move out of this space - meaning we are not a MEAP but a MADP (Mobile development Application Platform)

Is this your first venture in product development?

[NST] No, I started my career as a product developer for a Scandinavian e-procurement company called Proceedo. The move into project based development was quite a shock when I realized that object orientation and inheritance was kind of useless when you code a user-exit or similar “small” fixes within the SAP environment. Luckily I can capitalize on my former experience now that we have created a huge application in SAP and where ABAP Object really shines.

[OAH] I started a company that delivered a procurement HUB between SAP installations (Customers) in 2002 called LogNet. Even if I have started a lot of SAP consultancy firms, it has always been my passion to create software products rather than just delivering manpower to SAP customers.

I suppose it is not easy for you to market a solution outside the official SAP strategy. How do convince customers that is better to use a non-SAP solution to solve the mobile equation?

[OAH] Not being owned by SAP doesn’t mean we are not an SAP solution. We are actually the only ABAP SAP development product for mobility on the market. And I would like to stress that our solution is certified by SAP. In addition we do not provide a MEAP that is competing with the SAP Mobility platform but only a means for ABAP developers to capitalize on their existing skill sets moving into a more and more mobile reality.

[NST] The new partnerships announced by SAP last month also shows that SAP wants more development options for their platform. Especially the Adobe Phonegap partnering was important for us. Now our customers can use applications built with our tool on the SAP Mobile Platform and benefit from the MDM, Security and functionality like push notifications.

Is SAP platform is a good foundation for building a company that develops applications? What major strengths and weaknesses did you find? 

[OAH] SAP has a great platform when it comes to performance. We are especially impressed with the ICF (Internet Communication Framework) for performance and scalability. We also utilize the standard transport system and security of the SAP system.

[NST] We are of course limited to the SAP customers in the world, and as we use the ABAP stack the look and feel of the designer is based on the standard SAP GUI. We find that the familiarity between our product and standard SAP ABAP tools really helps ABAP developers getting started.

Do you code ABAP? 

[BOTH] Yes, a lot.

Have you tried SAPUI5? What do you think of it? Do you think it will be the building block for all new SAP user interfaces?

[NST] We actually imported the SAPUI5 framework into our solution and made a few SAPUI5 plugins to test how it would play along our solution. It worked perfectly and we are now in touch with the managers of SAPUI5 in Waldorf and are awaiting the licensing decisions before we move any further.

[OAH] For desktop solutions it will definitely have a more appealing and modern look than Webdynpro. I believe that when the browsers in the enterprise have decent HTML5 support – HTML5 will be the preferred choice for most UI development.

I can see you choose JQuery Mobile to use in your product. I also see that SAP uses JQuery Mobile in several places, at least in the SUP and in Portal on Devices (do you know more?). Do think SAP will also adopt JQuery Mobile more officially or it will move to SAPUI5 once this toolkit supports mobile?

[NST] SAPUI5 actually packages jQuery Mobile for mobility development. SAP made a partnering announcement with Sencha Touch so we’ll see what that means for jQuery Mobile in the SAP context in the coming year. For our solution, the jQuery Mobile framework is a better fit. It is more HTML oriented and less Java script dependent when it comes to development.

[OAH] I believe SAPUI5 will have most impact on the desktop. SAP really needs a facelift for their portal and business client.

Are there some new SAP technologies do you think can be particularly interesting to independent developers?

[NST] Apart from the SAPUI5 the new Netweaver Neo is interesting. If we have had a push for mobility and HANA this year, my predictions is that Cloud computing will be the hot thing next year.

Can you tell us more about your marketing channels? Do you get many inquiries from the website?

[OAH] We get great help from SAP through the Eco Hub and they help with setting up webinars with SAP partners. Our trial version strategy has been a success and we have our solution installed on more than 200 SAP systems worldwide.

[NST] Also channels like Linkedin are great for marketing. These days it is a lot easier to find the right audience than it was only a few years ago.

Have you participated in SAP events? Which kind of events you found better to show your products?

[OAH] We participated on Teched and Sapphire in Madrid last year and will attend Teched in Las Vegas in October. Other than that we have been to the local SAP user group events in Scandinavia which has resulted in actual contracts.

How do you see the SAP independent developers space?

[NST] For ABAP developers we can highly recommend the Assembly kit that comes with the certification. It gives you the tool you need for packaging and delivering ABAP add-ons in a smooth and professional manner.

[OAH] SAP provides their Software and Technology partners with both the tools and the marketing assistance you will need starting up. So if you
have a great idea and some means of funding I say go for it.

Thanks guys for this interview. I think you are one of the coolest  startups in the SAP space and I hope you have a lot of success with your product.

Labels: , ,

Thursday, February 02, 2012

SAP development with jQuery Mobile

One of the hot topics for me last year was doing SAP development for mobile platforms. There is a huge quantity and quality of enterprise information inside SAP servers and the new wave of mobile devices opens so many new ways of interacting with that data and business processes. I did not write much on that topic in the blog but on onsap you can find many questions and answers related to the technologies I was using.

There are many platforms and toolkits for mobile development (and that is a good topic for another blog post that I hope to write one day). My choice of platform is jQuery Mobile for the frontend development and business server pages (BSP) for the backend development. With this stack it is possible to develop solutions using the platforms companies already have (ECC and other solutions based on Netweaver) and using an open toolkit that is evolving quickly and at the same time is stable and tested in a large number of devices.

As a result of some of that work we, at Cognitiva, are releasing an open-source package with some utilities to help development of jQuery Mobile on SAP. It includes sample applications like the one show in action in the video below, and it also includes a search help widget that is described in detail in this SDN blog post.

If you have interest in mobile apps give this technology a try. The source code is available in this repository and it is possible to run a demo application with the free Netweaver developer edition.



Labels: , , ,

Tuesday, October 04, 2011

Using ZAKE to export objects to the filesystem

A script to use ZAKE to export a package to the filesystem. I'm starting to use ZAKE and SAPLink to synchronize the ABAP repository with the mercurial version control system, so the default SVN object was not good for my goal.



Labels: ,

Tuesday, September 20, 2011

Random element from a table in ABAP

One function I find myself using a lot in python is random.choice that gives me a random element from a list. Quick example in python:


>>> import random
>>> for i in range(20):
... print random.choice(['A','B','C','D']),
...
C A D C C D A D C B B B B C B C A C D B


It turns out it is not that difficult to do the same in ABAP.


class lcl_random definition.
public section.
class-methods choice importing it_table type standard table
exporting es_row type any.
endclass.

class lcl_random implementation.
method choice.
data: l_size type i,
l_index type i.

describe table it_table lines l_size.

call function 'QF05_RANDOM_INTEGER'
exporting
ran_int_max = l_size
ran_int_min = 1
importing
ran_int = l_index
exceptions
invalid_input = 1
others = 2.

if sy-subrc = 0.
read table it_table into es_row index l_index.
endif.
endmethod.
endclass.

form test.
data: lt_test type table of char1,
l_test type char1.

l_test = 'A'.
append l_test to lt_test.
l_test = 'B'.
append l_test to lt_test.
l_test = 'C'.
append l_test to lt_test.
l_test = 'D'.
append l_test to lt_test.

do 20 times.
lcl_random=>choice( exporting it_table = lt_test importing es_row = l_test ).
write: l_test.
enddo.
endform.

Labels:

Tuesday, April 12, 2011

Test functions in SE37 with commit execution

A very simple trick that I only learned recently. A couple of times I faced the situation that I had a function that I could call to solve my problem. I would like to do it in SE37, but the function would need a COMMIT to be called after execution. I thought it was not possible to do in SE37 but it actually is. There is an option to test sequences:





So I just need to put my function and to perform the commit I can use the standard function BAPI_TRANSACTION_COMMIT.



Labels:

Monday, March 22, 2010

Finding functions in SAP

In SAP world there is usually more than one way to do something. This is true in functional processes where several transactions can perform the same action. It is also true in the development area where one can find in the SAP database several functions that perform the same (or almost the same) action.

When "shopping" for a function I usually check the number of times the function is used in the standard code. Since this information is available in a table it is easy to build a list the top used functions (in the picture a word map of the top used APO functions without the /SAPAPO/ prefix for easier readability).



Bellow is a minimal report to query the functions and get the usage counter. I think such report is quite useful for day to day work. Consider the following sample case where I want to find a function to display a pop-up message. Using this report I do a query by *POPUP*.



It will display __ entries sorted by the number of times that function is used. As there are many possible functions it is nice to know the ones that are more often used, since those are more likely to work better.



The report code:


report z_top_used_functions.

tables cross.
data:
gt_objs type table of ztopusedfunctions.

selection-screen begin of block 0 with frame title text-002.
select-options:
s_name for cross-name.
selection-screen end of block 0.

selection-screen begin of block 1 with frame title text-001.
parameters:
p_type like cross-type default 'F',
p_max type tbmaxsel default 200.
selection-screen end of block 1.

start-of-selection.
clear gt_objs.
refresh gt_objs.

select name count(*) as counter
from cross
up to p_max rows
into table gt_objs
where type = p_type
and name in s_name
group by name
order by counter descending.

call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_structure_name = 'ZTOPUSEDFUNCTIONS'
tables
t_outtab = gt_objs.


The ztopusedfunctions structure is defined as follows.



Happy coding.

Labels: ,

Monday, January 12, 2009

Another spell for the hacker book


The object oriented programming in APO uses in many cases the singleton pattern. An object static method (class method in standard object oriented talk) is used to obtain the object instance. If it is the first time the object is created and stored in a static attribute (class attribute). Then further calls to the method return the instance stored in the attribute. A practical result of this coding logic is that these objects become global structures of data because as long they were initialized at a given point of time, they are can be accessed at any later time just by calling the static method. For example, the object /SAPAPO/CL_ATPFIELD_BUF can be called in ATP user-exits to get the field catalog (some user-exits don’t have the field catalog available in the input parameters).


CALL METHOD /sapapo/cl_atpfield_buf=>get_atpfield
EXPORTING
iv_ordid = lv_ordid
iv_delps = lv_delps
IMPORTING
et_atpfield = lt_atpfield.


This works because the field catalog is stored in a static attribute of the object.

For global classes (like /SAPAPO/CL_ATPFIELD_BUF) this is very simple, but ABAP also allows the definition of local classes. For example, the main objects for the ATP calculation (LCL_REQUIREMENT_ATP, etc) are classes defined inside program /SAPAPO/SAPLATPT. I always wanted to have access to these objects inside user-exits (because it means having access to all ATP information). Something like this trick for global variables but able to access the objects.

After many failed attempts, this one works fine.


DATA:
l_name(150) TYPE c,
l_tabtype(150) TYPE c,
ldr_reqref TYPE REF TO data.

FIELD-SYMBOLS:
<reqref_t> TYPE ANY TABLE.

l_name = '\PROGRAM=/SAPAPO/SAPLATPT\CLASS=LCL_REQUIREMENT_ATP'.
l_tabtype = '\PROGRAM=/SAPAPO/SAPLATPT\TYPE=TBL_REQREF'.

CREATE DATA ldr_reqref TYPE (l_tabtype).
ASSIGN ldr_reqref->* TO <reqref_t> CASTING TYPE (l_tabtype).

CALL METHOD (l_name)=>get_instances
RECEIVING rt_reqref = <reqref_t>.


Now this pointer <reqref_t> is a pointer to a list of all LCL_REQUIREMENT_ATP object instances relevant for the current ATP check.

Labels: ,

Wednesday, February 20, 2008

Tutorial on ABAP functions for DP macros

It seems that there is no standard function to calculate the statistical mode. So I thought it would make a good example for a short tutorial on creation of ABAP functions to be used in planning macros.

The macro functions are standard functions created with SE37 that must have a specific call signature (input and output parameters and tables). The base parameters are the ones shown in the following figure (later other options are presented).



The VALUE_TAB structure has two fields, one for numbers and one for strings. All input parameters set in the macro are added to this table in the same order as defined in the macro, in the number or string field depending on the data type.

For our exemple the function will receive a list of numbers. The goal is to calculate the mode of the integer part of the numbers. Since the mode can be a list of several numbers, we intend to return the largest integer number of the list.

Bellow is the code for such a function. It just counts the frequency of the numbers (after convertion to integers). The final list is sorted and the mode (or maximum of modes) is returned on the output parameter field F_ARGUMENT. The other parameter F_CALC_ERROR is a flag that should be set in case of errors that cannot be handled (the equivalent of raising an exception).


FUNCTION z_macro_maxmode .
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" VALUE_TAB STRUCTURE /SAPAPO/VALUE_TAB
*" CHANGING
*" REFERENCE(F_CALC_ERROR) TYPE C
*" REFERENCE(F_ARGUMENT) TYPE /SAPAPO/MXSOP-V
*"----------------------------------------------------------------------

TYPES:
BEGIN OF t_histogram,
value TYPE i,
counter TYPE i,
END OF t_histogram.

DATA:
lv_value TYPE i,
ls_hist TYPE t_histogram,
lt_hist TYPE TABLE OF t_histogram WITH KEY value.

LOOP AT value_tab.
IF value_tab-string IS INITIAL.
CLEAR ls_hist.
* just truncated integers to make it simpler
lv_value = trunc( value_tab-value ).
READ TABLE lt_hist WITH TABLE KEY value = lv_value INTO ls_hist.
IF sy-subrc = 0.
* already in the table, increase the counter
ls_hist-counter = ls_hist-counter + 1.
MODIFY TABLE lt_hist FROM ls_hist TRANSPORTING counter.
ELSE.
* insert value for the first time in the table
ls_hist-value = lv_value.
ls_hist-counter = 1.
INSERT ls_hist INTO TABLE lt_hist.
ENDIF.
ENDIF.
ENDLOOP.

* return the integer with largest counter (if more than one return the
* largest integer)
SORT lt_hist BY counter DESCENDING value DESCENDING.
READ TABLE lt_hist INDEX 1 INTO ls_hist.

f_argument = ls_hist-value.

ENDFUNCTION.


Now this function can be added to the macro builder (/sapapo/advm). First one registers the function using the following menu option.





A list of parameters is shown. The previous macro only uses the base parameters so no other checkbox is flagged, but here is the place to choose the parameter options.



Then the macro is created with the new function being called like the standard ones.



I've found that moving logic to ABAP functions can be a good way to simplify complex macros.

Labels: , ,

Friday, December 07, 2007

On Debugging Planning Macros

Lately I have been dealing with some planning macros. I am a newbie with these macros but I have a lot of experience with ABAP debugging. That's why I was quite happy with the following trick that allows ABAP debugging of planning macros.

In the macro builder, for a given macro just put the command ADVA in the command window.



It will jump to the ABAP source generated for the macro.



It is a big source file so it may be hard to find the right section to place the breakpoint. I found it helpful to set a stop point in the macro in the step I want to debug.



Then I search the code for PERFORM RESULTS_SHOW.



That's it.

Labels: , ,

Saturday, September 29, 2007

How to use ABAP HTTP_POST

SAP has the function modules HTTP_GET and HTTP_POST to call remote urls. With HTTP_GET one can just had parameters in the URL to send information to the external system. For example, setting the url to


http://myserver.com/mypage?x=1&y=10


sends x=1 and y=10 as parameters to mypage. The problem with HTTP GET is that there is a limit on the ammount of data that can be sent (technically it is unlimited in the new specification, but there are still servers that impose the old limit).

To send large ammounts of data using HTTP one should use the POST method (ABAP function HTTP_POST). To accomplish the same call with HTTP_POST first the length of the data must be calculated


len("x=1&y=10") = 8


then the function must be called with the following parameters


ABSOLUTE_URI http://myserver.com/mypage
REQUEST_ENTITY_BODY_LENGTH 8
REQUEST_ENTITY_BODY x=1&y=10


The function group URL_GENERATION has some data quoting functions to help build valid URLs. Also, the introspector tool is helpful to debug the HTTP calls.

PS. This post was originally in pvl.freezope.org, but that site is down most of the time so I'm moving it here.

Labels: ,

Saturday, February 17, 2007

Quick links

A nice comparative chart of TMS solutions, including TP/VS, from inbound logistics (via @scm).

A simple function module to export any internal table to MS Excel.

Labels: ,

Friday, October 21, 2005

Use the source Luke!

From Andrew Barnard comment in Piers blog:

In the former times, SAP's application logic was written in ABAP - open source - in the sense that anybody could understand it. Now I obverse, despite the benefits of open source - SAP is tending to hide the source in Java classes. The newer product offerings are more closed than the "closed" ABAP applications ever were.

This is a very good point. SAP was open source (meaning open knowledge) even before open source become popular. I'm not sure if they realize how important this was for their success. From my experience, good SAP implementations depend a lot on the ingenuity of consultants that hack the user-exits and BADIs. No matter how clever the consultants are, if they cannot read the source code they cannot invent those hacks (I wonder if APO would not be much more successful if it did not hide so much in the COM routines and optimizers binaries).

Source code, plus the integrated debugger and /h is the gem of SAP. Going away from it is a BAD decision.

Labels:

Monday, July 19, 2004

Perl Periodic Table of Operators

Amazing the perl periodic table of operatores. Any takers for an ABAP version? Well, to be honest, ABAP has a decent number of operators. But on the other hand, I wouldn't like to be the guy maintaining the language parser code (although I would love to read the comments on the file, it must be full of ##$#@$ words ;-)

Labels: , ,