Copyright 2024 - BV TallVision IT

Add your own columns to a Sap query ? Involve Abap coding in your reporting setup ? The infoset on Sap Query can be enriched with logic. 

The SAP Query tool is very flexible and powerful, especially where HR reporting is involved. This article explains how a field can be added to your query results, as column in the reports. It assumes you are already quite familiar with SAP query and Infosets.

The first thing to do is add the new column field to the Infoset that will be used for your query (or queries). Through transaction SQ02, change the Infoset you want to add the column to. Note that in most systems, the Infoset can not be changed when it is in the Global area (Cross-client). Make your Infoset available in the Standard area first.

Once you have entered SQ02 in change mode, simply add your field in the “Additional fields” section by clicking on the right mouse button “Create”. Supply a name and set select “Additional field” for this (single column) example.

Then press enter, which will present another popup

Details are supplied, making this a 20-character field called “Characteristic”. The next step is to assign the new field to a group, which will make it available in Query output.

Click on the “Field groups” button and drag/drop the new field to the required group:

At this point, a new column is added and made available to the Infoset and Query, however this is still without selecting it’s content. Click on the right-mouse, context menu and select “Field code”.

Now fill in the coding supplied, which is explained later on:

The coding supplied is custom-made for a certain query field use, which can be re-used for other purposes as well.

* This is where the CHARACTERISTIC value is retrieved from
* the available information on P0001-ORGEH
data: lw_hrp1010 type hrp1010.
field-symbols:  type any.
assign ('SYHR_SPLITS_WA-ENDDA') to  casting type d.
select single * from hrp1010 into lw_hrp1010
  where plvar = '01' and "Active
        otype = 'O' and "Organization
        objid = p0001-orgeh and "Organization
        subty = '0001' and "Subtype of KENMERK
        istat = '1' and "Active
        begda <=  and
        endda >  and
        varyf = space and
        seqnr = 0.
if sy-subrc = 0.
  characteristicfield = lw_hrp1010-hilfm.
  clear characteristicfield.

What effectively happens here is a selection of characteristics from the HRP1010 table, which is set up for Organizations. The Organization number from infotype 0001 is used to fetch information from the HRP1010 table, for which the correct selection date is used. The date is derived from the bottom end and high end of the selection dates on the selection screen, which could be a single date, but it couls just a well be a date range. The customer has chosen that the highest date in the range is to be used for this selection.

The Field-symbols setup is made available to fool the SQ02 tool into thinking it can compile the coding. The easiest approach to determine what is available and what can be done is by putting a break-point in the coding block and having a look around. The query report itself is a report like many others, which means it can be viewed from the report selection screen. Do note that this setup was aimed at adding a single field with selection information that was already available. There are many more abap coding block options on the Infoset to lean on !