+ All Categories
Home > Documents > SAP Query Example

SAP Query Example

Date post: 18-Oct-2015
Category:
Upload: thkim8
View: 90 times
Download: 2 times
Share this document with a friend
Description:
SAP Query Example
Popular Tags:

of 34

Transcript
  • 5/28/2018 SAP Query Example

    1/34

    Report Development Tools

    Chapter 2: ABAP Query

    Contents

    Learning the Basics of ABAP Query.....................................................................22

    Creating a Report with ABAP Query.....................................................................27

    Running the Query................................................................................................226

    Understanding the Report List ............................................................................227

    Getting the Most from ABAP Query: Tips & Tricks ...........................................227

    Review....................................................................................................................233

    Where to Learn More ............................................................................................233

    2

    In this chapter you willhow to:

    Create a functionain ABAP Query

    Build a basic functarea using a logicadatabase

    Maintain a user gr Create a report usi

    functional area andgroup

  • 5/28/2018 SAP Query Example

    2/34

    Chapter 2: ABAP Query

    Learning the Basics of ABAP Query

    Reporting Made E22

    Learning the Basics of ABAP Query

    In this chapter, you will learn about ABAP Query, a tool that lets you present data fromdatabase tables in report lists. Before getting into how you can use ABAP Query to createreports, it is important to understand its features and basic organization.

    What Is ABAP Query?

    ABAP Query is an easy-to-use reporting tool that lets you query data from one or moredatabase tables and funnel it into a list. With this tool, you can extract data from virtuallyany application or database table in the R/3 System. ABAP Query enables you to create liby moving through menus.

    The output of ABAP Query can be:

    [ Displayed on the screen in a table format[ Displayed on the screen using SAP graphics[ Downloaded to a spreadsheet (for example, Microsoft Excel)[ Downloaded to a flat file[ Saved as an extract that can be viewed later.

    Who Uses ABAP Query?

    ABAP Query is used by two different groups of people. Each group works with differentABAP Query components.

    [ Departmental users:These are end users who create new queries and generate lists.Non-technical users find ABAP Query particularly useful because it does not requireany programming knowledge.

    [ System administrators:System administrators set up the necessary environment for eusers and carry out transports.

    ABAP Query can be used to access just about any data in the database, making it verydesirable for users in many areas of a business. Several R/3 application areas provide apredefined logical database for easier information retrieval.

    How Is ABAP Query Organized?

    As shown in the graphic, ABAP Query has three main components:

    [ Functional areas[ Queries[ User groups

  • 5/28/2018 SAP Query Example

    3/34

    Chapter 2: ABAP Qu

    Learning the Basics of ABAP Qu

    Report Development Tools

    23

    Basic

    List

    Basic

    ListRanked

    List

    Ranked

    ListStatistical

    List

    Statistical

    List

    Functional

    Areas

    Functional

    Areas

    ABAP Query

    User

    Groups

    User

    GroupsQueriesQueries

    Functional Areas

    You need functional areas to offer a preselected set of data to the user, depending on thetask to be accomplished.A functional area defines the tablesand the fields within thosetableswhich can be queried. Functional areas use a logical database, a direct read from table, or a series of table joins to determine the available tables.

    Why create functional areas

    ABAP Query allows you to evaluate data in the R/3 System. However, since the systemcontains several hundred thousand fields in logical databases, in tables, and sequentialdatasets, it is simply not practical to offer all these fields to a user for selection whencreating queries. Therefore, before starting to create queries (using the component

    Maintain Queries), you create functional areas (using the component MaintainFunctional Areas). Functional areas provide the user with a framework for defining aquery quickly and easily.

    Functional groups

    When you create a functional area, you select a logical database from an applicationsystem. However, since one logical database can contain a vast number of fields, youcombine fields together in logical units known as functional groups (see page 25). Afunctional area not only allows you to restrict the number of fields and group themtogether in meaningful units, but it also allows you to define auxiliary fields and procesthem like database fields.

    You can also read the long texts in additional tables (for example, the long text of anairline carrier in the table SCARR) and perform any necessary preliminary work. Thismeans that you can evaluate sequential datasets just as easily as SAP databases. Startingwith Release 4.0, a functional area can have a name of up to 24-characters. Previousreleases were limited to four-character names. SAP now delivers functional areas invarious applications.

  • 5/28/2018 SAP Query Example

    4/34

    Chapter 2: ABAP Query

    Learning the Basics of ABAP Query

    Reporting Made E24

    User Groups

    User groups link users to functional areas and queries and control the functional areas anqueries a user can access. Each functional area is assigned to one or more user groups. Foraccess to ABAP Query, a user must be a member of at least one user group. All members

    a user group can access the same data as well as the same programs (queries) to create lis

    What is a user group?

    A user group is a collection of users that work with comparable data and accomplishsimilar tasks. Changes to functional areas and queries are immediately visible to all use

    The users assigned to a user group can only access the functional areas assigned to theiruser group. When creating a query, the user group controls which functional areas can bused. (However, user groups are irrelevant if a user has full authorization to all R/3 datStarting with Release 4.0, user groups can have 12-character names. Prior releases werelimited to two-character names.

    Queries

    When you create different lists using ABAP Query, you can save the layout for each list. Telement created is called a query. A query is specific to a user group and functional area.When creating a query, you may only select one functional area. Within a query, you musalso specify functional groups in the selected functional area. This means the selected area(and the groups) must contain all the fields you wish to include in the query.

    Using queries

    If appropriate authorizations are in place, you can execute, modify, copy, and delete

    queries. Any modifications to queries affect all users of a user group. That is, if one userdeletes a query, it is lost for all other users as well. All changes or new creations are atonce visible to all users.

    Starting with Release 4.0, queries can have 12-character names. Prior releases were limitto two-character names.

    Queries have three different types of reports or lists:

    [ Basic list: Sorts and totals selected fields as specified by the user in the query. This is tmost common kind of report.

    [ Statistical list:Totals, calculates averages, and allocates percentages based on the fieldin the query.

    [ Ranked list:Ranks fields based on numeric fields, including currency or quantity.A single query may have multiple statistical and ranked lists but only one basic list.

  • 5/28/2018 SAP Query Example

    5/34

    Chapter 2: ABAP Qu

    Learning the Basics of ABAP Qu

    Report Development Tools

    25

    Related Terminology

    [ Logical database: A series of tables that are linked together via a logical databaseprogram.

    [ Functional groups: Part of a functional area. You create functional groups within afunctional area and then assign the fields you want to query to the functional group.

    Logical database

    To retrieve data, ABAP provides an extra read program called a logical database. Thisprogram reads the required data and provides it to you in the correct order. You onlywrite the statements that process the data. To take advantage of this functionality for yoreport program, you must declare the logical database in the report attributes.

    SAP delivers several logical databases in the application areas and gives a user thecapability of creating their own. We strongly recommend that a basis/tools expert beinvolved in the creation of a logical database. To view the delivered SAP logical databas

    follow the menu path: Tools ABAP Workbench Development Programming

    Environment Logical Databases,or use transaction code SE36.

    Functional groups

    If a field is not assigned to a functional group, it cannot be included in a query. Functiongroups have two-character names and are functional-area dependent. There are nonaming restrictions for functional groups.

    How to Access ABAP Query Components?

    From the SAP main menu, choose System

    Services

    ABAP Queryto access ABAP QuerTo access the components of ABAP Query, use the menu paths shown in the followingtable:

    ABAP Query Component Menu Path

    Maintain Queries ToolsABAP WorkbenchUtilitiesABAP QueryQueries

    Maintain Functional Areas ToolsABAP WorkbenchUtilitiesABAPQueryFunctionalAreas

    Maintain User Groups Tools

    ABAPWorkbench

    Utilities

    ABAPQuery

    UserGroups

  • 5/28/2018 SAP Query Example

    6/34

    Chapter 2: ABAP Query

    Learning the Basics of ABAP Query

    Reporting Made E26

    How Does ABAP Query Differ from Other Reporting Tools?

    There are several differences between ABAP Query and other reporting tools:

    [ ABAP Query can access data from any table within SAP. Most other reporting tools caaccess only certain tables.

    [ ABAP Query is ideal for listing data from any application in the system. It can calculaadditional fields such as purchase price variance (PPV) in procurement or agingbuckets in accounts receivable (A/R), and total and sort on any field. These fields arecalculated on each line of a detail report and then totaled by the specified fields (forexample, material or customer).

    [ ABAP Query reports are typically simple listing and totaling reports, unlike a balancesheet or an income statement that requires complex groupings (for example, a cash orrevenue line made up of several accounts on a financial statement). Such complexgroupings would require the query to read tables multiple times to appropriately totaand sort the accounts. Other tools (such as Report Painter/ Report Writer which uses

    sets for these groupings) are better suited for reports with complex groupings.

    What Are the Prerequisites?

    [ An understanding of the data dictionary and perhaps some basic programming: Whan ABAP programming background is not critical to use this tool, knowledge of the ddictionary and some basic programming is helpful. If you are not familiar with the dadictionary or do not possess basic programming skills, you may want to enlist the helpof a basis/tools expert at some point. These skills will come in handy when thefunctional area you are building needs additional tables, additional fields, or table join

    [ Know required database tables and fields:Before starting a query, you should knowthe required tables and fields. To execute a query, data must be present in the tables y

    are accessing. A general understanding of the fields and how they are stored in thedatabase is also helpful. For example, the posted dollar amount in an FI document isstored as an absolute number. The system uses the posting key to determine if the actuvalue is positive or negative. To show the correct amount in your query you will needcreate an additional field in the functional area that checks the posting key to determithe correct amount. The correct amount is then stored in the additional field for yourqueries.

    [ System settings:An administrator must first make the required settings to allow a usto work with ABAP Query.

    [ Authorizations:End users and system administrators must have the appropriateauthorizations to use ABAP Query.

  • 5/28/2018 SAP Query Example

    7/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    27

    Creating a Report with ABAP Query

    In this section a guided tour shows you how to create a report using ABAP Query. Thisstep-by-step approach is built around a sample report (see the graphic below). We suggesyou take a few minutes to familiarize yourself with the scenario and the desired report.

    Example:Bungee Corporation wants to view the account history for several G/Laccounts at a timein a specified format. While they like many of the standard reportsprovided in R/3, they would prefer to change the order of the columns. BungeeCorporation believes that in the future they will include fields from internal tables, andthus would like to begin creating custom reports. Additionally, the company wants to bable to print the General Ledger history.

    Shown below is a preview of the General Ledger History report with all the desiredfunctionality. For this query, we will create a functional area using a logical database. Thian easy and effective way to start creating queries.

    Note:In the example we use Release 4.0B. While this release has a different look-and-feel than prior releases, the underlying concepts and terminology remain the same.

  • 5/28/2018 SAP Query Example

    8/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E28

    The main steps in creating a query are shown in the graphic below.

    Create the queryCreate the query

    Trained Employee Available?

    Assign the functional area

    to the user group

    Assign the functional area

    to the user group

    Create a

    user group

    Create a

    user group

    Generate the

    functional area

    Generate the

    functional area

    Assign required fields to

    functional groups

    Assign required fields to

    functional groups

    Create a

    functional area

    Create a

    functional area1

    2

    3

    4

    5

    6

    Guided Tour

    Step 1: Create a Functional Area

    1. To access the initial screen of ABAP Query, choose System Services ABAP Query.2. Choose Environment Functional

    Areas. 2

  • 5/28/2018 SAP Query Example

    9/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    29

    3. In Functional area, enter a name forthe functional area (for example,ZZ_GL_DETAIL) you want tocreate.

    4. Choose Create.

    5. In the Name field enter adescription for the functional area.

    6. Leave Fixed point arithmeticselectedto ensure that the decimalplaces are correctly set for thecalculations.

    7. In Logical data base, enter the nameof the logical database you want touse for the functional area (forexample, SDF).

    8. To display the tables and fieldsavailable in the logical database,choose Display.

    9. Select Table join.Note: If you prefer to directly reada specific table or use a table joinfor multiple tables, then enter thename of the main table in the Tablefield and select either Direct readorTable join. Only one of two areas(steps 6 and 7 for logical databasesor step 8 for specific tables) shouldbe selected.

    10.Choose Enter.

    43

    5

    6

    78

    10

    9

  • 5/28/2018 SAP Query Example

    10/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E210

    11.Choose the Createbutton (next tothe Functional groupsfolder) to addtwo functional groups to thenewly created functional area

    ZZ_GL_DETAIL.

    12.Create the following twofunctional groups,A1andA2inthe Create Functional Groupswindow:

    [ A1forAccount Master Info[ A2 forAccount Transactions

    13.Choose Enter.

    11

    12

    13

  • 5/28/2018 SAP Query Example

    11/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    21

    Step 2: Assign Required Fields to Functional Groups

    1. Choose Expand to assignfields to the functional groups forqueries. Once the nested detail isin view, the button turns fromgreen to red.

    2. Click lineA1,Account Master Info,to highlight the group for fieldassignment.

    3. To assign the fields to thefunctional groupA1, click theminus (-) sign, next to the field

    names. The icon changes to agreen plus (+) sign. The functionalgroupA1appears next to thegreen icon, indicating that thefields have been assigned to thehighlighted functional group.

    Continue adding fields to thefunctional group by repeatingsteps 1 and 3 (above) for each tablethat contains fields needed foryour queries.

    To select a different functionalgroup to add fields to, double-click on the new functional groupand perform steps 1 and 3 (above).

    Selecting fields for functional groups

    When selecting fields for your functional groups, select the field in the highest possible tablFor example, company code (BUKRS) is available in tables SKB1, SKC1A, SKC1C, BKPF, BSBSEG, and GSEG. The company code should be selected onlyfrom table SKB1 because it is

    the highest table in the logical database hierarchy that contains the company code. If thecompany code is selected from more than one table, it will appear multiple times to the usewhen creating queries. Multiple appearances can be extremely confusing.

    The next two steps involve ABAP programming statements. You may want to ask aBasis/Tools expert to help you if you are not familiar with SELECTstatements and basicABAP code.

    13

    2

  • 5/28/2018 SAP Query Example

    12/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E212

    The next step is to add an additional table that does not exist in the logical database. In this example, theG/L account description is not stored in any of the logical database tables; it is stored in table SKAT.Weneed to add table SKATto table SKA1(shown below) because all the key fields of table SKATare availabin table SKA1.

    4.

    Click on the node for SKA1toselect the table in the ChangeFunctional Area ZZ_GL_DETAILscreen.

    5. Choose Extrasin the toolbar to addan additional table.

    6. Choose Create.

    7.

    InName

    , enterSKAT

    , the table tobe added to the functional area.LeaveAdditional tableselected.

    8. Choose Enter.Note that the selected table isSKA1.

    7

    8

    5

    4

    6

  • 5/28/2018 SAP Query Example

    13/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    21

    9. The system defaults to the SELECTstatement values it can determine.You must complete the missingentries, if any.

    10.Choose Entertwice to return to theChange Functional AreaZZ_GL_DETAILscreen.

    11.Be sure to add the fields from theadditional table to a functionalgroup. The additional tables fieldswill be listed under the table to

    which it was attached. In thisexample, table SKATis attached totable SKA1.

    We will now look at the same logical database (SDF), but at a different table (BSEG). The next step is to aan additional fieldin this example, the dollar amount in table BSEGis stored as an absolute value. Theonline system uses the posting key to determine if the additional field is positive or negative. We need toadd an additional field that would contain the amount with the proper sign so that the final totals arecorrectly calculated.

    9

    10

    11

  • 5/28/2018 SAP Query Example

    14/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E214

    12.Select the line BSEG.13.Choose the Extrasbutton to add an

    additional field.

    14.Choose Create.

    15.In the Name field, enterCorrect_Amount, the name ofthe additional field to be added tothe functional area.

    16.SelectAdditional field.17.Choose Enter.

    13

    14

    15

    12

    16

    17

  • 5/28/2018 SAP Query Example

    15/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    21

    18.In Description, enter anappropriate field description.

    19.In Header, enter the column headertext.

    20.Enter the format of the field byeither manually entering the type,length, output length, anddecimals. Alternatively, you mayspecify the name of the field (forexample, BSEG-DMBTR) whoseformatting this additional fieldshould mirror.

    21.To enter the ABAP code for theadditional field, choose Editor.

    22.Enter the ABAP code that willdetermine the value of theadditional field. In this example,we are checking the debit/creditindicator (BSEG- SHKZG). If wefind an 'S'for debit, then thecorrect amount is equal to the localcurrency amount (BSEG-DMBTR).If it is not a debit, then it is a creditand the local currency amountmust be multiplied by -1.

    Remember to enter the periods at theend of each line!

    23.Choose Save.24.Choose Back.25.Choose Entertwice to return to the

    logical database view of thefunctional area.

    18

    19

    20

    22

    23 2425

    21

  • 5/28/2018 SAP Query Example

    16/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E216

    26.Double-click on the functionalgroupA2to select it.

    27.To add the additional field(CORRECT_AMOUNT) to a

    functional group so that it can beused in queries, expand the BSEGtable to show all the fields. Scrolldown to the bottom and select theCORRECT_AMOUNTfield.

    Step 3: Generate the Functional Area

    1. Choose Generate to generatethe functional area. This is the

    final step in creating the functionalarea.

    2. Choose Backafter the functionalarea has been generated.

    26

    1

    2

    27

  • 5/28/2018 SAP Query Example

    17/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    21

    Step 4: Create User Group

    Step 5 below describes how to create a user group.

    Step 5: Assign the Functional Area to the User Group

    The functional area must be assignedto a user group before it can be usedin a query. From the previous screen(in step 3), choose Environment UserGroups.

    1. In User group, enter X1, the nameof the user group.

    2. If a user group does not exist,choose Create.

    The rest of this example showshow to create a user group. If anexisting user group will be used,chooseAssign users and functionalareas.

    3. In the Userssection, enter the usernames of the users who shouldhave access to the functional areasand queries of this user group. Inthis example, we added the userTbeckerto the user group.

    4. ChooseAssign funct. areasto assignthe appropriate functional areas tothe user group.

    2

    3

    4

    1

  • 5/28/2018 SAP Query Example

    18/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E218

    5. To assign the functional areas tothe user group, select theappropriate checkboxes on the leftside of the screen. In this example,

    we selected functional areas ZZGLand ZZ_GL_DETAIL.

    6. Choose Saveto save theassignments.

    7. Choose Backtwice to return to themain user group screen.

    Now that the functional area and usergroups have been set up, you areready to build the query.

    Step 6: Create the Query

    To go to query maintenance from theUser Groupscreen, choose Environment

    Queries

    1. Make sure you are working in theappropriate user group.

    2. If not, choose the Other User Groupbutton and switch to the correctuser group.

    3. In the Query field, enter a name forthe new query. In this example,enter A1.

    4. Choose Create.

    5

    6 7

    1

    2

    3

    4

  • 5/28/2018 SAP Query Example

    19/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    21

    5. You are now prompted to select afunctional area. The list offunctional areas includes all areasassigned to the user group you are

    working with. Double-click on thefunctional area you wish to use. Inthis example, double-click onZZ_GL_DETAIL.

    6. In Title, enter the title of the query,and in Notesenter any relevantnotes. The notes are for referenceonly and do not appear in thequery.

    7. In Columns, enter the column size(in characters). In Linesenter thedesired number of lines. In thisexample, the number of lines andcolumns is 65and 132respectively. This should match aprint format if the query is to beprinted.

    8. Choose Next Screento continue.

    5

    6

    7

    8

  • 5/28/2018 SAP Query Example

    20/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E220

    9. Select the functional groups fromwhich you want to choose fields.Remember that you are workingwith functional groups, not

    functional areas, in this step.10.Choose Next screento continue.

    11.From each functional group, selectthe fields to be used in the query.

    12.Use Page upor Page Downto scrollthrough the fields. In this example,

    the fields you select would bebased on the desired report output(as shown in the sample report onpage 27).

    13.Choose NextScreento continue.

    9

    10

    11

    12

    13

  • 5/28/2018 SAP Query Example

    21/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    22

    14.From this list, select the fields thatshould be used as variables whenexecuting the query. Some of thesefields may already be variables in

    the logical database. If so, theywill appear twice when executingthe query. You may return to thisscreen and deselect them if theyare duplicated.

    15.If selection fields straddle multiplepages, use Page upor Page Downtoscroll through the fields.

    16.Choose Basic Listto continue.

    14

    15

    16

  • 5/28/2018 SAP Query Example

    22/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E222

    17.Enter the Lineand Sequenceforeach field in the query. In theoutput for this sample report,recall that the account number and

    description appear above thetransaction detail. This is becausewe specified that they would beon line 1. The transaction detail ison line 2. The sequence is theorder in which the fields appearacross the page.

    18.Use Page upor Page Downto scrollthrough the remaining fields.

    To view a full page of fields, choose

    Expand.19.Select and order the sort fields in

    the Sortcolumn.

    20.The Totalbutton is available on allnumeric, currency, and quantityfields. This gives you the option tototal the sort fields.

    21.The counter field is new in Release4.0 and allows you to count thenumber of entries in your query

    for the selected field. This will alsototal on the sort fields.

    22.The Compressed displaycheckboxallows detail transactions to besuppressed on the initial screen(and then expanded if necessary).With compression on, you will seethe account number and a total forthe account. When expanded youwill see all the related transactiondetail.

    23.Choose Next Screento continue.

    18

    17 19 20 2122

    23

  • 5/28/2018 SAP Query Example

    23/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    22

    This screen helps you set up the sortfields.

    24.To get text above each sort break,select Text.

    25.To get totals for a sort level, selectTotal. This option works only ifyou have also selected Total for anumeric field on the previousscreen.

    26.To get counter totals for the sortfield, select Cnt. (counter).

    27.To get a blank line betweenaccount numbers, select BlnkLn.

    28.To get a page break at each newcompany code, select NewPg.

    29.Choose Next Screento continue.

    30.Each sort field for which youselected Text, Total, or Cnt. abovehas a separate screen (as shownhere). You can specify the text thatshould appear next to each total

    and above each sort break.

    31.Choose Next Screento continue.Choose this button through eachof the control-level text screens.

    24 25 26 27 28

    29

    30

    31

  • 5/28/2018 SAP Query Example

    24/34

    Chapter 2: ABAP Query

    Creating a Report with ABAP Query

    Reporting Made E224

    32.Each detail line of your query willhave a line on the List line outputscreen. To get a column header forthe list line, select Header line.

    33.Selecting Ref.checks thereferenced line (for example, line02) which is the detail transactionline for an activity. If there is noactivity for line 02, then line 01issuppressed as well.

    34.If the detail lines for an accountbreak across pages, selecting PageHeaderrepeats the first line (withthe account number anddescription) at the top of the nextpage.

    35.Choose Next Screento continue.

    36.The query gives the standardlength of the field. You now havethe option of shortening it.

    37.If the Posfields are left blank, thedefault is one space between eachfield. Entries in the Pos column

    determine where in the line youwant the field to start. In ourexample, we want the accountnumber to start in characterposition 02and the text incharacter position 12. This meansthere will be 4blank spacesbetween the account number andtext (12 - 2 6 = 4).

    38.Choose Next Screento continue.

    Note:You must remember where the line breaks occur (for example between the G/L account long texand the accounting document number). The long text is on line 1and the document number starts line 2

    32 33 34

    35

    36 37

    38

  • 5/28/2018 SAP Query Example

    25/34

    Chapter 2: ABAP Qu

    Creating a Report with ABAP Qu

    Report Development Tools

    22

    39.This is the column header screen.To change a field header, double-click on the field header in thePage headersection. In this

    example, we double-click on theAmountfield.

    40.Change the description in thepopup box.

    41.Choose Enter.

    42.To enter a date, time, page, orname, put your cursor in the whiteline in the Page headersection andtype &%DATE, &%TIME, &%page, orthe appropriate variable name. Toinsert additional lines, double-click on the white line.

    43.Choose Save.44.Congratulations! Your query is

    now ready to run. Choose Executeto run the query.

    39

    40

    41

    44

    42

    43

  • 5/28/2018 SAP Query Example

    26/34

    Chapter 2: ABAP Query

    Running the Query

    Reporting Made E226

    Running the Query

    To run a query, choose System

    ServicesABAPQuery.

    1. Select the query from the list. Inthis example, user group X1hasonly one query (A1).

    2. Choose Execute.

    3. Enter the variables.In this example, enter:470000in G/L Account3000in Company code19.10.1998in Open items at keydate

    4. Notice that theG/L account numberand Company codefields appeartwice because both the logicaldatabase and the query use thesefields as selection criteria. Be sureto remove this duplication fromthe query.

    5. Dynamic selections are alsoavailable because of the logicaldatabase. These selections shouldalso be used instead of queryselections.

    6. Choose Executeto run the query.

    3

    4

    5

    6

    1

    2

    3

    3

  • 5/28/2018 SAP Query Example

    27/34

    Chapter 2: ABAP Qu

    Understanding the Report

    Report Development Tools

    22

    Understanding the Report List

    The basic list shown here is a simplelisting of detailed transactions for

    specific G/L accounts. In thisexample, 15 transactions have beenposted to the G/L account based onthe selection criteria specified at thetime of executing the query.From the report output, you may:

    [ Expand or collapse the detail withthe Basic Listbutton.

    [ Drill down (sometimes referred toas Report Call) to call up a varietyof reports or transactions from thisquery. Drilldown capability isspecific to the query.

    [ Save the query to a file to be calledup and viewed later.Note that expand/collapse and thereport call capability is notavailable in a saved list.

    Getting the Most from ABAP Query: Tips & Tricks

    Adding Selection Criteria in a Functional Area

    Creating variables

    In the functional area, you can use available selection criteria to customize specific field(variables) for entry at execution time. These new variables work for all queries createdwithin the functional area. You can set up selection options and parameters that work julike the ABAP code statements Select-Optionsand Parameters.

    With these selection options you can make the variables:

    [ Work with their matchcodes[ Mandatory fields[ Display only[ Highlighted[ Set defaults

  • 5/28/2018 SAP Query Example

    28/34

    Chapter 2: ABAP Query

    Getting the Most from ABAP Query: Tips & Tricks

    Reporting Made E228

    The following example explains how to customize the variables from within the functionaarea.

    1. From the SAP main menu choose SystemServicesABAP Query, then ToolsABAWorkbenchUtilitiesABAPQueryFunctionalAreas.

    2. In the Functional area field, enter the name of the functional area to be changed and clithe Changebutton (not shown).

    3. In the Change Functional Areascreen, choose Selections (not shown).4. If the functional area was created using a logical database, the database selection crite

    will appear. Do not add these fields again or try to change them. If the functional areawas created using table joins or direct table reads, this table will be empty which meathere are no pre-defined selection criteria included in the functional area. You will neeto manually add all the desired fields as selection criteria.

    5. Choose Createto add a new field.6. In the Create Selectionwindow, enter the name of the new selection criteria. Use a nam

    that starts with an alpha character.

    7. Select Selection criterion. Since parameters only allow one value, this selection gives yothe most flexibility to enter multiple values and ranges.

    8. Choose Enter.

    4

    5

    6

    7

    8

  • 5/28/2018 SAP Query Example

    29/34

    Chapter 2: ABAP Qu

    Getting the Most from ABAP Query: Tips & Tr

    Report Development Tools

    22

    9. Enter the description and selection text for the field. In this example, Cost Centerisadded.

    10.Enter the name of the field being added in the FORstatement.11.In the Extras statement, enter any criteria for the field. In this example, the cost center

    field is made a mandatory field with matchcode capabilities.

    12.Choose Enter.Using Table Joins in a Functional Area

    Table joins became available with Release 3.0C. If just a few tables are being used to crea functional area, tables joins can be more efficient than logical databases. However,logical databases are essential for hierarchical processing. Table joins should be considefor performance reasons when creating the functional area.

    Only inner table joins are available in the standard 4.0x releases. Left outer tables joins aavailable in Release 4.5x. If left outer joins are needed in a 4.0x system, refer to OSS note130837on how to retrofit this functionality.

    OSS note 48296is also helpful when working with tables joins.

    What follows is an example of starting a functional area with a table join. The example stoat the point where you begin adding fields to the functional groups. For more informationon how to add fields to the functional groups and to finish the configuration of the

    functional area, see page 211.

    1. From the SAP main menu choose SystemServicesABAP Query, then ToolsABAWorkbenchUtilitiesABAPQueryFunctionalAreas.

    2. In the Functional area field, enter the name of the functional area to be created and choCreate.

    11

    9

    10

    12

  • 5/28/2018 SAP Query Example

    30/34

    Chapter 2: ABAP Query

    Getting the Most from ABAP Query: Tips & Tricks

    Reporting Made E230

    3. In the Namefield, enter a description for the functional area.4. In the Tablefield, enter the name of the table (for example, MARD) with which you wan

    to begin the table join. For best results, a high percentage of fields from the table youchoose (for example,MARD) must also be present in the other table (for example,

    MARC).5. Select Table join.6. Choose Enter.

    7. Enter the names of the other tables that are needed in the functional area.8. Choose Define conditionto define the link between the two selected tables.

    3

    45

    6

    7

    8

  • 5/28/2018 SAP Query Example

    31/34

    Chapter 2: ABAP Qu

    Getting the Most from ABAP Query: Tips & Tr

    Report Development Tools

    23

    9. The tables appear in theJoin conditions(right side of the screen).10.Choose Specify conditionsto define the join.

    11.You are prompted for proposals for the table join. Choose Yesand the system willpropose the join conditions.

    12.The proposed join betweenMARDandMARCis the material number and the plant.These are the two key fields onMARC. If both key fields can be matched (as in this casthen the system will always bring back one unique recordif a record is found.

    9 10

    12

    13

  • 5/28/2018 SAP Query Example

    32/34

    Chapter 2: ABAP Query

    Getting the Most from ABAP Query: Tips & Tricks

    Reporting Made E232

    If the proposal did not create the intended join conditions, you may want to defineadditional join conditions. To do this, enter matching numeric values in the two-charactspace next to each field. For example, if Ind.: Flag materialonMARDshould match theIndicator: Flag material onMARC, enter a 02in the two-character space next to each of thfields. ABAP Query only allows join conditions between fields of a similar type.

    13.Choose Backto go back one screen.14.Choose Functional groupon the next screen to begin adding fields to the functional

    groups from the adjoined tables.

    Assigning Reports with Report Call Functionality in a Query

    Each query has Report Callfunctionality for drilling down to other reports. These reports be any of the following:

    [ Report groups created using Report Painter/Report Writer (see chapter 3)[ Drilldown reports created using the Drilldown reporting tool (see chapter 4 and

    appendix F)

    [ ABAP programs[ Other ABAP queries[ Transaction codes (for example, standard reports available in LIS. For more informati

    see chapters 5 and 6)

    Many customers like to drill down to display transaction codes for master records anddetail transactions from queries. To add the Report Callfunctionality to a query:

    1. You must be in Createor Changemode within the query.2. Choose Goto Report assignment.3. Assign any of the report types mentioned above to the query.

    More Helpful Hints for Report Developers

    [ Creating functional areas using table joins, instead of logical databases, is more efficiefor processing if you are using only a few tables. However, logical databases areessential for creating hierarchical lists. You may want to consider the pros and cons ofusing functional areas and logical databases if performance issues are an importantconcern. Due to perceived performance problems, many customers make limited use

    ABAP Query.[ Non-technical users may find it difficult to work with table joins, additional tables, an

    additional fields. People may get discouraged and back away from the tool. Have themore technical team members create the functional areas and user groups. Delegationtasks allows less technical team members to concentrate on creating queries.

  • 5/28/2018 SAP Query Example

    33/34

    Chapter 2: ABAP Qu

    Rev

    Report Development Tools

    23

    [ While ABAP Query is an easy tool to work with, it is important to recognize thatexperience with the tool is valuable toward producing an efficient query.

    [ It is important to control the usage of the tool; not every user in a company should begiven permission to create, change, or access queries. Controlled access to ABAP Queis recommended for optimal system performance and report organization. A reportinteam should be formed to create and change queries. This team should be responsiblefor naming conventions, report creation, and testing. The team should ensure thatduplicate functional areas, queries, and user groups are not created and that thestandards are adhered to.

    [ A report specification form is a valuable tool. A sample form is included in theFundamentals of Reportingguidebook and on the companion CD supplied with thisguidebook set. This form serves as the key channel of communication between thereporting team and the end users that need reports.

    Review

    ABAP Query is an easy-to-use tool for extracting data from the R/3 System. It can be usedwith most tables, both standard and user-defined. With ABAP Query you can list data, toand sort from almost any table or combination of tables. ABAP Query can create basic,statistical, and ranked lists. It works with logical databases, tables joins, or individual tablQueries can be printed, downloaded, used with graphics, saved as extracts, or simplyviewed on the screen.

    The following steps are needed to create a report with ABAP Query:

    1. Create a functional area.2. Assign required fields to functional groups.3. Generate the functional area.4. Create a user group.5. Assign the functional area to the user group.6. Create the query.

    Where to Learn More

    [ R/3 Library (Online help): In Release 4.0B, you will find more information on ABAPQuery. Go to R/3 LibraryBCBasis ComponentsABAP WorkbenchBC ABAPQuery| BC ABAP Reporting Tutorial.

    [ ABAP/4 Query, a comprehensive book from theABAP/4 Development Workbenchdocumentation published by SAP AG. To order printed copies use product number50014371.

    [ BC405: ABAP/4 Development WorkbenchReporting, a five-day training course offered bSAP Education and Training.

  • 5/28/2018 SAP Query Example

    34/34

    Chapter 2: ABAP Query

    Where to Learn More

    Reporting Made E234


Recommended