Adding Additional and Local Fields to ABAP Queries

SQ01 is a tool provided by sap to quickly generate reports using SAP interlinked tables. I am sure most of you are familiar with this tool and probably have used it multiple times during the course of you sap career. But most of us don’t know that we can add custom fields into ABAP query and can write ABAP code to fetch data for those fields or perform calculations using already existing data etc. Below is the step by step instructions on adding custom fields and writing ABAP logic

Note: Assumption is that the user is familiar with ABAP query functionality

Step1: Adding additional fields to Infoset. Transaction – SQ02 to change already created Infoset. Press the EXTRAS button in the application bar and selected ADDITIONAL FIELD from the popup window. Provide Field Name, Header Name, Field Type, Length, Output length and save the query

SQ01-1

SQ01-2

SQ01-4

SQ01-3

STEP2: Adding ABAP code to achieve required functionality for additional field

Right click on the additional field to which ABAP code is to be added and select Field Code Option

 

SQ01-5

SQ01-6

Add the ABAP code to gather information as per the requirement and to display it in the additional field. In our example we are going to display material group (MARA-MATKL) for each bom component

SQ01-7

Step3: Add additional fields to an existing field groups or create a new field group and add all additional fields to that field group

 

SQ01-8

SQ01-9

SQ01-10

Step4: Add additional fields to query layout (selection and listing fields as required) and save the layout. This concludes the process of adding additional fields (with ABAP code) to ABAP queries. Query can be executed anytime and will retrieve information to additional fields based on the logic added to additional fields.

SQ01-11

SQ01-12

Other possible functionality with ABAP queries is to add local fields to perform calculations using data from existing fields in the query. Above query has been extended to bring in component price from MBEW table and local field will be added to display the extended price of component based on quantity

Note: This is just an example to show the steps involved in setting up local fields and adding calculations in ABAP queries

Transaction: SQ01

SQ01-13

SQ01-14

STEP1: Turn on Short Names (EDIT –> SHORT NAMES –> SWITCH ON/OFF) and enter short names for the fields that are to be used in calculations. In our example Comonent Quantity and Component Price will be assigned short names QTY and PRICE

SQ01-15

SQ01-16

Step2: Add Local Fields (EDIT –> LOCAL FIELDS –> CREATE)

SQ01-17

Step3: Make sure to add local field to layout

 

SQ01-18

SQ01 Result with Local and Additional fields

SQ01-19