What I learnt about PHAP_SEARCH reporting
Hello again! I am back with my HR development exploration blogs. There were some blogs about HR development in the past, so if you`re interested, feel free to search my contributions for them. The main link between the old ones and this one is HR-PD, namely the appraisals.
Topic for today: take selected appraisal documents and export them to Excel documents.
I was asked to build a tool that would let an HR admin to generate existing appraisal documents into Excel files so that they can be archived. So I started thinking – what first, what next, how to put things together so they do what I want.
The “normal way” of doing the job
First I was thinking the normal way: new program, selection screen, for selected records do some operation and done. I started surfing existing SAP standard development for appraisals looking for things that I could reuse. I found transactions PHAP_ADMIN and PHAP_SEARCH with their very complex but also very cool selection screen. Would there be a way how to reuse it?
This selection screen is a wrapped in a function module, good start. But then I realized there are no output parameters that would return the selected values (list of appraisal documents) or the filter values (because then I could use HRHAP_DOCUMENT_GET_LIST_XXL function module which is used in the mentioned transactions).
I evenif somebody can advise me how to do selection screens for appraisals. If you have an idea, answer the thread or post a comment here. Thanks.
Unless I get an advice that would turn the world around, I will assume there is no easy way how to reuse the selection screen. Let me point out that I don`t want to copy it, because it is a screen, coding around the screen, many global variables etc. Copy is not an option. I don`t want any dirt hacks either (like dirty memory read etc.).
That meant that I had to look around for other options. But one thing was bugging me all the time. PHAP_SEARCH is exactly what I want. Would there be a way how to (mis)use it for my task? Then I found the button “Reporting” in the main status and started debugging that one.
The “HR way”
When you click on the “Reporting” button in PHAP_SEARCH, you are presented (by default) with four options what you can do. It is important to emphasize that you can do the thing you select with exactly those appraisal documents you selected in the main ALV, isn`t it cool? That`s exactly what I wanted.
Next I needed to understand how I can add my own functionality there. It turned out that all four default options are BADI implementations. Name of the BADI is HRHAP00_REPORTING (interface IF_EX_HRHAP00_REPORTING) and the four standard options are:
- CL_IM_HRHAP00_REPORTING_00 – Ranking list
- CL_IM_HRHAP00_REPORTING_01 – Print
- CL_IM_HRHAP00_REPORTING_02 – Export to Excel
- CL_IM_HRHAP00_REPORTING_03 – Analyze
So I reduced the task to implementing a BADI, isn`t it nice. No big testing needed, no user interface needed, no documentation needed, it will be just another button in the standard transaction.
Boring implementation details
I needed exactly the same things as for any other BADI: go to SE80 > create classic BADI implementation > give the implementation name, give the definition name.
In the implementation you`re expected to implement three methods. First one is REGISTRATION, which gives the reporting popup window the information if the current context is suitable for this operation. Sounds little awkward. An example would be better: some options you only want to enable if more than two appraisal documents are selected. Such an operation would compare those documents somehow – maybe like the standard Ranking list (standard BADI 00). Other operations make sense from one document onwards. That also tells you what to put into the implementation method body – same thing as in one of those two types used in the standard BADI implementations.
The popup items also have the icon button available. You can specify what happens on that button on-click in the method GET_INFORMATION. Three out of four standard implementations return SE61 TX text with instructions. You can do the same if you want. No return value means no documentation, that`s also fine.
Then I made a mistake and started to be inventive. This BADI uses a filter. But that filter can be easily enhanced (meaning that new implementation comes together with a new filter value). Wrong order of steps and some morning confusion cost me an hour to understand that the right sequence of enters would create the filter value that I can freely specify on BADI implementation “Attributes” tab.
Note: “Enhanceable” flag is important here. Thanks to that you can create new filter value together with a new BADI implementation. The fact that the short text description is missing here is because I put that text in a different language. See the screenshot below from PHAP_ADMIN where that text is also missing and replace with the identifier instead.
So I got “Filter value XYZ violates namespace convention of table T77HAP_FLT_PRP” and started to think how to get a value there. Conclusion: Since the definition has “Enhanceable” flag TRUE, the value comes from the definition. You don`t have to hack in that table and put there a value. Just give the ID and text description (which will then appear in the PHAP_SEARCH > Reporting popup as the option name) and that`s it.
The rest was easy: part of the data available in HAP_T_DOCUMENTS (document headers for the selected ones) and FUNCTION HRHAP_DOCUMENT_GET_DETAIL did the job.
Note: the text here is ZHAP_EXCEL_BADI, because I put the filter value description in the different language (not English). That`s why the text is not available in English and the identifier takes its place. Normally you would get the text you put as a filter value description here.
If you stop looking for alternatives too early, the final result can be pretty poor. Well, not poor for the end-user since he can`t tell, he does not know the other options. But when you know about the alternatives and compare the best one (whatever best means here) with the one you chose, you can be sometimes embarrassed (If you care and think about some self-reflection of course).
Normally (my case) I don`t know all the alternatives. It must be somebody else, more experience in the matter that tells me about the other options. Every time I am found guilty of not thinking enough before starting coding I remind myself about the previous times too and promise myself to be more careful the next time.
It does not matter if you consider yourself to be a junior or a senior, it doesn`t matter what`s on your business card, you can always do better if you spend 20 more minutes thinking that coding.
If this help a single person, it is worth the effort. On the other hand comments always surprise nicely. If you have inputs, I would love to learn more about the topic, so will the other readers. Thanks for reading this thing, cheers Otto