0% found this document useful (0 votes)
12 views17 pages

SQ 2

Uploaded by

Dheeraj Dheeru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views17 pages

SQ 2

Uploaded by

Dheeraj Dheeru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Communi'y

SAP Community  Groups  Interest Groups  Application Development  Blog Posts

 Building an SAP Query with ABAP Code

Application Development Blog Posts


Learn and share on deeper, cross technology development topics such as integration and connectivity,
automation, cloud extensibility, developing at scale, and security.

Blog  What are you looking for today?

Building an SAP Query with ABAP Code

diwaneamit
Participant

11-20-2015 10:06 AM

 9 Kudos  71,688

SAP Managed Tags: ABAP Development

ABAP code is used with SAP query tool to enhance the query output.

You can write down the code under the Extras tab for the Infoset in the SQ02
Tcode.
You will find various coding events which are similar to classical ABAP report.

The code written in this code area is transmitted to the auto generated query
report. You can write down your code in various coding section as per the use of
them.

DATA Section :

Global Data Declaration will go under this Event.

INITIALIZATION Section :

As the name suggests it is used to initialize the variable with initial values.

AT SELECTION-SCREEN OUTPUT :

This event is triggered before the display of selection screen.

START-OF-SELECTION :
This event is triggered before starting any database accesses. Usually Data
fetching logic goes under it.

RECORD Processing :

Corresponds to the GET coding with Info-sets without a logical database. As there is no
hierarchical view of the data, all the join tables are addressed.

END-OF-SELECTION :

The END-OF-SELECTION code consists of two parts ( Before list output and After list
output ). The first part is processed before the list is output and the second part afterwards. It is
the right section to do aggregated calculations and actions that can only be done when data from
all the selected records has been extracted.

However, there is a problem when queries use code in the END-OF-SELECTION section in
combination with the Sap List Viewer format. In short, the code is never reached.

Free Coding :

The code under this event is executed after all the events are triggered.

Logic to put extra field in the query output:

Let you want a date field to be fetch from a 'B' table and has to be added to your
query output.

Define a Structure in DATA Event:

data: begin of ty_date occurs 0,

date like B-date,

end of ty_date.

The logic to fetch the values for this field will go under the record processing event.
In Record Processing Event write down the following code:

CLEAR ty_date.

CLEAR v_date.

Select date from B into table ty_date. "You can mention your condition
also with where clause

Sort Table ty_date BY date DESCENDING.

Read Table ty_date INDEX 1.

v_date = ty_date-date.

Generate the Infoset.

Changes to the query:

1.Run SQ01 in another session.

2. Open your Query in change mode and select the field group in which has the added extra field.

3.Select extra field.

4 Click on basic list to select that field in your O/p list.

5.Click on Test button, and see if you are getting desired result.

Performing Operations on the final output table data:

You'll find table %G00 with final data to be displayed.

Enter the following ABAP code under Data Section:


data: str type string.

field-symbols: <G00> type table.

field-symbols: <G00_WA> type any.

Enter the below ABAP code under END-OF-SELECTION(after list) Event:

str = '%g00[]'.

ASSIGN (str) TO <G00>.

loop at <G00> assigning <G00_WA>.

...do whatever you like here....

endloop.

You can put your own logic inside the loop to perform. .

Tags:

abap coding extra infoset queryreport SAP sq01 sq02

14 Comments

Former Member


05-08-2016 8:31 AM

 0 Kudos

Hi Amit,

I want to add the condition against the fields in the loop. How to do that ?

Loop at <G00> assigning <G00)WA>

Endloop.

diwaneamit
Participant

05-10-2016 10:53 AM

 0 Kudos

You can write down the code under the END-OF-SELECTION(after list event) by
Looping on the table G00.
Former Member


05-23-2016 6:57 AM

 0 Kudos

Hi Amit,

Thanks for your reply. I got the answer.

regards,

Sam...

Former Member


05-23-2016 6:59 AM

 0 Kudos

very useful document. I used this document for many times.. instead of keep
remembering things, I remember this kind of document , so I can use it, whenever
its required.
frederick_dacostaramos2
Discoverer

06-02-2016 5:44 PM

 0 Kudos

Hi Amit, thanks for your explanation. I´m functional consultant and I´m used to
create infoset/queries. I have an issue now that I need to summarize (collect) the
result of the infoset I created. How can I do it ? How can I refer to the internal table
the infoset creates during runtime and summarize it before is listed in the report
result ? Best Regards and thanks if you have time to save me

diwaneamit
Participant

06-03-2016 6:12 AM

 0 Kudos

Hello Frederick,

The result set for the infoset queries is in G00 Internal table. You can consult with
the abaper to make changes to the data in this final table. For runtime modification
to the final output data of the query we generally write down the code.

Please let me know if you need more information on same.


francis21
Participant

02-28-2017 7:29 AM

 0 Kudos

Is it possible to change, update and delete database table entries using ABAP
coding in SAP Query?

diwaneamit
Participant

03-13-2017 10:26 AM

 0 Kudos

Hello Francis,

You can make all the mentioned operations on the result set of the infoset queries
which we received in G00 Internal table.

former_member204457
Active Participant

06-13-2017 2:39 PM

 0 Kudos
Hi Amit, In the Query there's a field with label SAP List Viewer where user can put
the layout for the output. I created a parameter in the infoset called 'layout' and
basically hidden SAP List Viewer now I want to transfer the value from my own
parameter (i.e. layout) to the value of the SAP List Viewer which in the code is
%ALVL...can this be done. Thank you

former_member216356
Explorer

09-27-2017 3:04 PM

 0 Kudos

Hello Amit,

How to transport this infoset from dev to Q with ABAP code in it

diwaneamit
Participant

11-14-2017 6:59 AM

 0 Kudos

Hello Vijay,

You can check this link

https://archive.sap.com/discussions/thread/1574223
former_member667525
Explorer

03-20-2020 5:35 PM

 0 Kudos

If I write the logic to limit o/p with a limit on selection screen input

loop <g00> to <gw>

Some operation

Endloop

If I write this in end of selection after list my selection screen layout got changed.

I need the layout as below


rafael_lopez011
Explorer

04-02-2020 2:53 PM

 0 Kudos

Hi,

Can I call METHOD set_table_for_first_display? I am trying but I have issues


calling screen 100.

Thanks,

Babek907
Explorer

12-15-2022 10:43 AM

 0 Kudos

Hi Amit Diwane,
Could you please look at below mentioned issue?

https://answers.sap.com/questions/13774899/add-abap-code-in-infoset-query-
getting-error-messa.html

 You must be a registered user to add a comment. If you've already


registered, sign in. Otherwise, register and sign in.

Comment

Labels In This Area


- SAP 1 A Dynamic Memory Allocation Tool 1 A Unit Test for function Module 1

ABAP 15 ABAP 7.4 4 ABAP API 1 abap cds 2 ABAP CDS VIEW 1

ABAP CDS Views 14 ABAP class 1 ABAP Cloud 1 ABAP Development 7

ABAP Environment & RAP 1 abap for sap hana 1 ABAP in Eclipse 2

ABAP Keyword Documentation 2 ABAP OOABAP 3 ABAP Programming 2

ABAP RESTFul API 2 ABAP RESTful Application Programming Model 1

abap technical 1 ABAP test cockpit 7 ABAP test cokpit 1 adobe form 1

ADT 1 Advanced Event Mesh 1 AEM 2 AI 1 AL11 1 ALV 1

alv oo 1 API and Integration 2 APIs 21 APIs ABAP 1

App Dev and Integration 2 Application Development 2 application job 1

archivelinks 1 aRFC 1 AUNIT 2 authorization 1

Automatic PO during Goods Receipt 1 Automation 11 B2B Integration 1

BADI 1 Batch Management 1 BTP 1 BTP Destination 1 buffer 1

Business Application Studio 1 Business objects 1

Business Technology Platform 1 cache 1 CAP 4 CAP CDS 1


CAP development 2 CAPM 1 Career Development 9 CDS Access Control 1

CL_GUI_FRONTEND_SERVICES 1 cl_gui_html_viewer 1 CL_SALV_TABLE 2

Clean Core 1 Cloud Extensibility 13 Cloud Native 13

Cloud Platform Integration 1 CloudEvents 2 CMIS 1 coding 1

Connection 1 container 1 Customer Experience 1 Customer Portal 1

CVA 1 Debugging 2 developer challenge 1 Developer extensibility 1

Developing at Scale 9 DMS 1 download 1 dynamic logpoints 1

Dynpro 1 Dynpro Width 1 Eclipse ADT ABAP Development Tools 1 EDA 1

EML Operation In RAP 1 Event Mesh 1 Events 1 Excel 2 Expert 1

export 1 Field Symbols in ABAP 1 Figma 1 Fiori 1 Fiori App Extension 1

Forms & Templates 1 Function module 1 General 1 Getting Started 1

GitHub 1

Popular Blog Posts

Get Started with the ABAP Development Tools for SAP NetWeaver
OlgaDolinskaja

Product and Topic Expert


 175146  12  1441

Become an ABAP in Eclipse Feature Explorer and earn the Explorer Badge
ThFiedler

Product and Topic Expert

 30643  147  368

Six kinds of debugging tips to find the source code where the message is raised
JerryWang

Product and Topic Expert

 220368  56  321

Top Kudoed Authors

sheenamk  5

thomas_jung  3

horst_keller  3

abo  2

pokrakam  2

OlgaDolinskaja  2

former_member814706  1

DominikTylczyn  1

KevinR  1

vodela  1

View all
Follow

Privacy Terms of Use

Copyrigh7 Legal Disclosure

Trademark Suppor7

Cookie Preferences

You might also like