Coding in An Infoset PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Coding in an infoset

Wednesday, May 20, 2020


10:00 PM

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. .

Creation of Infoset with Sort and deletion adjacent


duplicates Functionality - Part 1
Creation of Info-Set:
Initial screen by using the transaction code /nSQ02
Provide a name for your Info Set. (For purposes of this example, I'm naming Z_Sales_docu_data.) Then
click the Create button.

Name as ‘Sales Document Demo’... (Demo)

Select radio button Table join using basis table and provide input as VBAK.

Click on Continue button.

Now you can see that table is in the graphical format .To add more tables, you can use Button or
Edit/Insert Table menu options.
Give table name and Enter.
Once you select enter button new table will appear .If table links are not available ,then you have to
manually link those using drag and drop methods.
After that below screen gets displayed.

You can check the table using

button . If table join is correct you’ll get Defined join conditions are correct message.

Select
option.

Select the Create empty field group option.

In your left hand pane all tables that you select will appear .In your right hand side you can see the field
groups.

Add fields which are relevant to the report.


Assign fields to the field groups (shown on the top right of the screen) within the Info-Set by Drag and
dropping the fields from left hand pane to right hand pane of Field groups. These field groups will display
in the SAP Query tool during reporting. Only the fields that you include in your field groups will be
available for field selection in the SAP Query tool that uses this Info-Set as its data source. By default,
these field groups are empty.
Once you add all the required fields, it looks like this.

Then click on

button to add additional code .Following screen will appear.


Click on Code Icon (Shift+F8) displayed on application bar, you will be getting lists events in 'Code
section'.

In Data Section, declare an internal table like below code


FIELD-SYMBOLS <fs_dtab> TYPE STANDARD TABLE.
DATA: sort_f1 TYPE fieldname,
sort_f2 TYPE fieldname,
sort_f3 TYPE fieldname.
In INITIALIZATION Event write the following code.
sort_f1 = 'VBAK-VBELN'.
sort_f2 = 'VBAK-ERDAT'.
sort_f3 = 'VBAK-ERZET'.
In END-OF-SELECTION (after list) Event write the following code.
ASSIGN ('%G00[]') TO <fs_dtab>.
IF <fs_dtab> IS ASSIGNED.
SORT <fs_dtab> BY (sort_f1) (sort_f2) (sort_f3)
ASCENDING.
DELETE ADJACENT DUPLICATES FROM <fs_dtab> COMPARING
(sort_f1).
ENDIF.
Generate the Info-Set by clicking the Generate button

(the red beach ball) on the Application toolbar. A message appears in the status bar, saying that the
Info-Set was generated.
Creation of Infoset is Done!!!
:)

You might also like