Using ABAP Coding In SAP Standard Query

It is hard to find an easy explanation about ABAP coding in standard queries. In some cases you can’t easily attach additional information to a field in a Query or you need to call and ABAP function module to do an specific calculation, then adding coding to a local field may be a suitable solution.  To demonstrate this we are going to make a standard query with one table using ABAP Coding on it, instead of creating an infoset with three tables (inner join) as usual.

In order to illustrate this I’m going to create a query using MARD table (Materials per Plant) adding names for Plant and Storage Location with ABAP coding. MARD table includes fields WERKS (Plant) and LGORT (Storage Location) and their names are stored on tables T001W and T001L respectively.  A previous knowledge of standard SAP Query and basic ABAP programming is needed for plenty understanding of this guide .    

Infoset Creation

First we launch SQ02 in SAP’s command line to load Infoset Initial Screen:

Then select:

Fill Infoset Name and Direct read of table:

After filling data on screen aboveit is necessary save infoset:

Here second option is marked and click on the button:

Here we proceed to create a custom field in the query clicking on:

For field creation click on button:

 We are going to create 2 fields PLANTN (plant name) and STORN (storage location name):

 

Click on button:

On this screen it is necessary to fill Long text and Header. Field format has to be declared too. There are two ways declaring field format (using a direct field type or using a text):

As a default first field declared get the first number of Sequence Code. Finally click on button to save field:

Then we proceed to create the next field STORN using the same process described above (assigning sequence number 2):

Screen Shot 2016-09-12 at 10.06.14 AM.png

After click on

we have:

In my practice I have found that if you want to include additional coding for each field at every select iteration code should be written in the last field declared. In this case STORN.  It is done clicking on field STONR and then click on

Here we have an ABAP editor where our coding can be written to find Plant and Storage Location names:

After coding we need to check syntax code clicking on:

 

And save:

Then we have to return to main infoset screen:

In order to make our fields and their codes work it is necessary to include Additional Fields to Storage Location Data for Material Field Group. To do this expand “Additional fields” and “Storage Location Data for Material”:

Then drag fields PLANTN and STORN to group 01 “Storage Location Data”:

 

Then we have to generate our infoset clicking on

To save we click on:

Click on:

Finally we assign infoset to User Group.’[u=

After creation this must be assigned to user group:

Next step is creation of query in SQ01 using ZTEST001 infoset.

 

Query Creation

Executing SQ01 we can create our query named “ZTEST”: 

Now click on

and then assign it to infoset created above:

Click on

In the next screen we add a title for query:

 

Then click to next screen

Now check filed group and follow next screen clicking

We have to check fields to be used in our query, then go to next screen

Then marking “Material Number ” as unique selection criteria we  call Basic List design

In order to test it we click on

Then we use a material to test query:

Fields “Plant” and “SLoc” are key fields from MARD, then “Pl” and “Storage Loc Name” are additional fields.

Author: Roberto Cañas

RCANAS2005

Roberto is a responsible IT professional with 15+ years of experience in functional support, configuration and programming in SAP ERP. Now seeking to contribute his skills and expertise in new SAP projects. Proven Skills in the following areas: SAP FICO Configuration and Functional Support SAP MM Configuration and Functional Support SAP SD Configuration and Functional Support SAP ABAP programming of reports, module pools, enhancements, user exits, etc. SAP Administration of Roles and Authorization Objects.

Module(s): ABAP, Basis, Controlling, Enterprise Controlling, Financial Accounting, Human Resources, Logistics Information System, Materials Management, Sales and Distribution