Technical Articles
Simple Report by calling function module SE16N_EXTERNAL_CALL
Purpose
I have been asked to make simple reports just for retrieving data from tables with all nice functions which you can use at SE16N, SE16H sort of SE transactions .
Well, there are many fancy UI report tools that you can create a fancy report, which are something like POWL or Fiori List, FPM, and WebUI. Of course, if you are good at using conventional SAP report tools like Report Painter, SAP QUERY, QuickView, and so on .. Wouldn’t be any problem considering that SAP has been providing lots of report tools for user to avoid building SAP reports from scratch.
But, What is the simplest way to meet user’s requirements if end users do not want to know how to use the fancy report tools, and just want to call a transaction? And want to something like SE16N outputs and the out-of-box functions only ? Moreover, user wants simple UI interface with customer selection criteria & layout variant on top of the SE16N ?
Adopting SAP stand functions
Answer is simple, Call SE16N_EXTERNAL_CALL.
Here is the very simple steps to make a customer SE16N report.
- Create a report transaction
- Create a report calling FM ‘SE16N_EXTERNAL_CALL’
- Restricted the selection criteria and input parameters,
Optionally, you can preset the layout, filter, group by, sub-sum, and all functions come with SE16N
Example
In my reference program, I restricted 2 selection-options as input Selection Criteria
REPORT xxxxxx….
**// Definition
TABLES lfbk.
DATA : lr_stab TYPE TABLE OF se16n_seltab WITH HEADER LINE.
DATA lc_se16n_tab TYPE se16n_tab VALUE ‘LFBK’.
*—–> Pick selection criteria from field list of table LFBK
SELECT-OPTIONS : s_bankn FOR lfbk–bankn .
SELECT-OPTIONS : s_lifnr FOR lfbk–lifnr NO INTERVALS NO–EXTENSION.
**// START-OF-SELECTION.
START-OF-SELECTION.
*—-> you can check of the authorization of tcode SE16N, but it’s optional.
*** Authorization Check
** Check for SE16N access when it called by customer t-codes
* IF sy-tcode NE ‘SE16N’. “1757450
* CALL FUNCTION ‘AUTHORITY_CHECK_TCODE’
* EXPORTING
* tcode = ‘SE16N’
* EXCEPTIONS
* ok = 0
* not_ok = 1.
* IF sy-subrc NE 0.
* MESSAGE e059(eu) WITH ‘SE16N’. ” no authority
* ENDIF.
* ENDIF. “1757450
*—-> Build Selection Tab for Sel-Option S_BANKN & S_LIFNR
** Build SelTab
lr_stab[] = CORRESPONDING #( s_bankn[] ).
** Fill the Field Name in SelTab
lr_stab–field = ‘BANKN’.
MODIFY lr_stab TRANSPORTING field WHERE field EQ space .
lr_stab[] = CORRESPONDING #( BASE ( lr_stab[] ) s_lifnr[] ).
lr_stab–field = ‘LIFNR’.
MODIFY lr_stab TRANSPORTING field WHERE field EQ space .
*—–> Call the SE16N function Module
**// END-OF-SELECTION.
END-OF-SELECTION.
**// Call SE16N with a restriction of selection criteria
CALL FUNCTION ‘SE16N_EXTERNAL_CALL’
EXPORTING
i_tab = lc_se16n_tab
* i_variant = p_vari
* I_HANA_ACTIVE =
* I_DBCON =
* I_OJKEY =
* i_max_lines = p_max_l
* I_GUI_TITLE =
* I_FCAT_STRUCTURE =
* I_LAYOUT_GROUP =
* I_NO_LAYOUTS =
* I_DISPLAY_ALL = ‘ ‘
* I_TEMPERATURE = ‘ ‘
* I_TEMPERATURE_COLD = ‘ ‘
* I_SESSION_CONTROL =
* I_EDIT = ‘ ‘
* I_NO_CONVEXIT = ‘ ‘
* I_CHECKKEY = ‘ ‘
* I_FORMULA_NAME = ‘ ‘
TABLES
it_seltab = lr_stab
* IT_SUM_UP_FIELDS =
* IT_GROUP_BY_FIELDS =
* IT_ORDER_BY_FIELDS =
* IT_AGGREGATE_FIELDS =
* IT_TOPLOW_FIELDS =
* IT_SORTORDER_FIELDS =
* IT_CALLBACK_EVENTS =
* IT_OUTPUT_FIELDS =
* IT_HAVING_FIELDS =
EXCEPTIONS
no_values = 1
OTHERS = 2.
*// No Need to populate error
IF sy–subrc <> 0.
MESSAGE w002(wusl).
* Implement suitable error handling here
ENDIF.
Output
This screen becomes ….
Like These with the same layout of SE16N
With this kind of simple ABAP report, you can limit user’s access to SE16N and assign different access of SAP tables by the Authorization object S_TCODE.
Hope this makes SAP life a bit easier.
Comment : It’s been over 10 years since the last time when I built ABAP reports , so my coding style might be old-fashioned,
A few things:
If you use the {} button on the blog editor, it makes your code more readable, like this.
As far as your 10 year old coding style - time for an upgrade! 😀
HEADER LINE tables are obsolete and have been for 20 years or so. You should not use them in new code. You should a work area of type SE16N_SELTAB. Of course you need to change some of your table handling.
Likewise, TABLES is obsolete. You can replace it with
DATA LFBK TYPE LFBK.
Or, better,
DATA G_LFBK TYPE LFBK.
yep I stopped using WITH HEADLINE. I just used that as I am so lazy to make a WA in MODIFY statement 🙂
Thanks for your advise.
Thanks for sharing!
I'd argue that using SAP Query (SQ01) is actually much simpler in this case. It requires 0 code, you literally just select your tables and drag-and-drop the fields. Personally, I think SQ01 is awesome but I'm not sure if there is a solid replacement for it in HANA world.
Obviously, SAP Query or QuickView are much easier to someone like us who know the tools, and simply we can assign a ztcode to the query. Unfortunately, End users like the uniform ALV layout of SE16N ...exactly same one. 🙂
SQ01 queries also provide ALV output and you could even expose every single table field, so it'll be exactly like SE16 but without a need to enter the table name. Tbh I doubt the users really, really need to see all 200 DB table fields. I bet something else is going on there. The advantage of queries is that you can enrich the data with details from another table and it actually handles some stuff like text tables out of the box. Dunno, I'd talk to those users and try to get to the bottom of their actual needs. Design Thinking is a good technique for that. 🙂
The below nine lines of code works for "transparent" tables at SAP_ABA Re750 SP9.
I got this somewhere on the web or in one of Paul Hardy's A2F books. Sorry, but I can no longer remember (I turned 71 this week).
REPORT zccu_read_any_table.
PARAMETERS p_tab TYPE tabname.
CHECK p_tab IS NOT INITIAL.
SELECT SINGLE tabname FROM dd02l
WHERE tabname = @p_tab
AND tabclass = 'TRANSP'
INTO @DATA(tabname).
CHECK sy-subrc = 0.
cl_salv_gui_table_ida=>create( iv_table_name = tabname )->fullscreen( )->display( ).
*----------------------------------------------------------------------*
****** End of REPORT "zccu_read_any_table" *******
*----------------------------------------------------------------------*
Maxx
Yes I know this code. Had been used code like this since late '90 🙂 I guess this code still woks in S/4 HANA as well.
Thanks for your sharing