Top Banner
SAP ABAP - Sample Report Program On WRITE, COLOR, HOTSPOT Keywords. REPORT ztest_events_list_report. START-OF-SELECTION. WRITE 'Click me!' COLOR = 5 HOTSPOT. AT LINE-SELECTION. WRITE: / 'You Just Clicked Me', sy-listi, / 'You are on list', sy-lsind. IF sy-lsind < 2. SKIP. WRITE: 'More ...' COLOR = 3 HOTSPOT. ELSE. SKIP. WRITE: 'THAT''s THE END' COLOR = 1. ENDIF. OUTPUT: On Clicking “More…”
41
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SAP ABAP

SAP ABAP - Sample Report Program On WRITE, COLOR, HOTSPOT Keywords.REPORT ztest_events_list_report.

START-OF-SELECTION.WRITE 'Click me!' COLOR = 5 HOTSPOT.

AT LINE-SELECTION.

WRITE: / 'You Just Clicked Me', sy-listi,/ 'You are on list', sy-lsind.

IF sy-lsind < 2. SKIP.WRITE: 'More ...' COLOR = 3 HOTSPOT.

ELSE.SKIP.WRITE: 'THAT''s THE END' COLOR = 1.

ENDIF.

OUTPUT:

On Clicking “More…”

Page 2: SAP ABAP

MORE PROGRAMS ON REPORT PROGRAMMING:

In this tutorial you will learn how to create HOTSPOT using ABAP, this HOTSPOT will allow you to click on the text and then pass the value to be used as a parameter for your query.

Here’s the ABAP Sample code to create the HOTSPOT. In this example, we will retrieve the customer name and address.

ZREPORT_HOTSPOT.

*&———————————————————————**& FREESAPTUTORIAL.COM*&———————————————————————*tables:vbak,kna1.

START-OF-SELECTION.

select single kunnr into (vbak-kunnr) from VBAK.

write :/ vbak-kunnr HOTSPOT on.“Event when user click on the text on the“ScreenAT LINE-SELECTION.

select single land1 name1 into(kna1-land1, kna1-name1) from kna1where kunnr = vbak-kunnr.

write:/ kna1-land1, kna1-name1.

Today I want to share some ABAP code samples that you can use to convert numbers or amount into words using SPELL_AMOUNT function module.

Here’s the ABAP Sample code:

data:lw_spell LIKE spell,saywords(150),lv_text TYPE ltext,p_amt TYPE eban-preis,p_amt2(15),p_waers type eban-waers.

START-OF-SELECTION.

p_amt = ‘123450′.p_waers = ‘USD’.

SELECT SINGLE ktext INTO lv_textFROM tcurtWHERE spras = sy-languAND waers = p_waers.

TRANSLATE lv_text to UPPER CASE.

CALL FUNCTION ‘SPELL_AMOUNT’EXPORTINGamount   = p_amtcurrency = p_waersfiller   = ‘ ’language = sy-languIMPORTINGin_words = lw_spell.

DATA: lv_cent TYPE spell.lw_spell-decimal = lw_spell-decimal / 10.IF lw_spell-decimal IS NOT INITIAL.

Page 3: SAP ABAP

CALL FUNCTION ‘SPELL_AMOUNT’EXPORTINGamount   = lw_spell-decimal*        currency = lw_vbak-waerkfiller   = ‘ ’language = sy-languIMPORTINGin_words = lv_cent.ENDIF.

IF NOT lv_cent-word IS INITIAL.CONCATENATE lw_spell-word ‘AND’ lv_cent-word ‘CENTS’lv_text INTO saywordsSEPARATED BY space.ELSE.CONCATENATE lw_spell-word  lv_text INTO saywordsSEPARATED BY space.ENDIF.WRITE p_amt to p_amt2 CURRENCY p_waers.

WRITE:/ p_amt2, saywords.

“end code

Run the program and you will see the number has been converted into words.

Run the program

BDC

Today I want to teach you how to create a BDC program using SHDB, this recording tool will be useful for you if you want to create an upload program from a flat file into SAP tables.

In this tutorial, I want to record a transaction from QS21, it’s transaction to create MIC (Master inspection Characteristic) in QM module.

To start creating a BDC just follow these steps below.

1. Execute TCODE SHDB. Click On “New Recording”.

2. Now just name the recording as ZR_QS21, the tcode name is QS21 to create Master inspection Characteristic, of course you can enter any other tcode that you want to record, after that click on the “Start Recording” button.

Page 4: SAP ABAP

3. Now you will be entering the recording mode to record transaction Qs21, as you can see on the picture below, you will be taken into this specified tcode.

4. Now just create the MIC as usual, because this is not a tutorial on how to create an MIC, then I will skip the creation process. After you’ve done creating the MIC, you will see this screen below.

BDC is a collection of screens to process the transaction, as you can see there are several screens used to create the MIC. Just double click on the each screen name to see the screen layout.

Page 5: SAP ABAP

5. Don’t forget to click on the “SAVE” button to save the BDC.

6. Now to use the BDC in ABAP, we need to transfer this BDC into an ABAP Program.

7. Execute tcode SHDB again, and locate the BDC we’ve just created. ZR_QS21 and click on the “Program” icon on the tool bar.

8. Now enter the ABAP program name for this BDC, and then choose “Transfer from recording” from the Field Contents block. Click OK or enter to continue.

Page 6: SAP ABAP

9. Type in the program title name and click on the “Source Code” button and press enter.

10. Now you can see the BDC code has been successfully transferred into you ABAP program.

Page 7: SAP ABAP

Usually you will need to modify the program by adding a code to get the flat file and then convert it into an internal table and then you pass the internal table data using this BDC program code that will save it into SAP tables

Whenever we generate a negative value, SAP usually will put the negative sign after the value, now there’s a function module called CLOI_PUT_SIGN_IN_FRONT that could put all the negative sign before or in front of the value.

Here’s the ABAP sample code.REPORT Z_PUT_NEGATIVE_SIGN_FRONT.

Parameter: p_num1 type i,p_num2 type i.

Data: d_sum type i,d_value(10).

d_sum = p_num1 – p_num2.

d_value = d_sum.

Write:/ ‘Before Function: ‘, d_sum.

CALL FUNCTION ‘CLOI_PUT_SIGN_IN_FRONT’CHANGINGVALUE         = d_value.SKIP.

write:/ ‘After Function: ‘, d_value RIGHT-JUSTIFIED.

Run the program and enter value in p_num2 to be greater than p_num1 so that you can get the negative value, as you can see the result before and after the function, where the negative sign is now in front of the number.

Logical Database  - SE36

A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program

Page 8: SAP ABAP

with a set of hierarchically structured table lines which can be taken from different database tables.

Reading a SAP standard logical database (DB M - MRP Documents) in your ABAP/4 program.

start-of-selection.

* get is equal to select * from.... get mdkp.    check field-name.

get mdtb.    check field-name

end-of-selection.

Basically a Logical Database can be used to read the same data for several programs. A Logical Database provides a consistent user interface. In Logical Database Authorizations are carried out centrally Performance is improved

The Logical Database is special type of ABAP program that combines the contents of certain related database tables and retrieve some related data and

make it available to application programs.

 

In other words, a LDB is a method by which ABAP programs read and process the data. The sequence in which the data is supplied to the   program is

determined by a tree structure.

Page 9: SAP ABAP

 

 

The LDB usually consists of the following components:

 Structure

Selections

Database programs

Logical databases have a tree structure.A logical database can contain a maximum of 300 tables.

For example: SAPDBPNP is the name of the database program for the logical database PNP.

How are logical database used:

1.Logical databases when generating an ABAP program

The selection screen generated contains the selections (SELECT-OPTIONS AND PARAMETERS) of both the logical database and

the program.                                                              

                                                                          

The only database-specific selections displayed on the selection screen are those needed by the program for data retrieval purposes.

2. Logical databases at run-time of an ABAP program                                  

                                                                                  

 At run-time, the system processes the events in the program and in the logical database in the following order:

Before displaying the selection screen, certain initializations (e.g. calculating default values such as key date, etc.) are performed for the selection screen

by the logical database and the program. The selection screen is displayed and the user enters data in the input fields.

The logical database and the program check that the input is correct and complete, but also that the user has the appropriate authorizations. If an error

occurs, some fields are made ready for input again, so that the user can make the necessary correction(s).                                                            

                                                                                  

In the event START-OF-SELECTION, the ABAP program performs any  preliminary work (for example, importing files).

The logical database reads the selected data and the  program processes it within the GET events according to  the sequence specified by the structure.

In the event END-OF-SELECTION, the ABAP program performs any  concluding operations (for example, calculating totals, exporting files).

Page 10: SAP ABAP

3 . Designing the selection screens                                               

The standard selection screen of a logical database has a standard layout where SELECT-OPTIONS and PARAMETERS appear in the sequence they are

declared, each on a new line. The system automatically generates such a screen for each program that does not have its own selection screen entered in

the attributes. You can define your own selection screens for any logical database . If the attributes of a   program include the number of its own selection

screen, the system uses this screen as a model when generating. Any program-specific selections appear after the database selections. The flow logic for

such screens is also generated automatically and therefore cannot be modified. You cannot delete database selections.

Functions of LDB:

Data retrieval :

             The personnel data of each employee is loaded into the main memory where it can be accessed for processing.

Screening :

              Employees can be selected according to the organizational criteria entered on the selection screen.

             E.g…Hourly wage earners in a particular personnel sub area.

           

               There are two types of screening..Person selection and data selection period. Person selection defines those employees for whom a report is to be

run.    E.g..Monthly wage earners in a specific personnel sub-area.

             E.g..Personnel number range

             E.g..Features of org.Assignment…Employees who assigned to certain cost center.

              E.g..Employee status..Active or inactive.

             The data selection period delimits the time period for which data is evaluated. When you enter the data selection period,the provide  loop retrieves

the infotype records whose validity period overlaps with at least one day of this period.Logical databases for increasing efficiencyWhy else would you want to create a logical database? Consider that the logical databases already available to you begin with a root node and proceed downward from there. If the data object you wish to construct consists of items that are all below the root node, you can use an existing logical database program to extract the data, then trim away what you don’t want using SELECT statements—or you can increase the speed of the logical database program considerably by redefining the logical database for your object and starting with a table down in the chain. Either way, you’ll eliminate a great deal of overhead.

Logical database structuresThere are three defining entities in an SAP logical database. You must be clear on all three in order to create and use one.

Table structure: Your logical database includes data from specified tables in SAP. There is a hierarchy among these tables defined by their foreign keys (all known to SAP), and you are going to define a customized relationship between select tables. This structure is unique and must be defined and saved.

Data selection: You may not want or need every item in the referenced tables that contributes to your customized database. There is a selection screen that permits you to pick and choose.

Database access programming: Once you’ve defined your logical database, SAP will generate the access subroutines needed to pull the data in the way you want it pulled.

Creating your own logical databaseABAP/4 (Advanced Business Application Programming language, version 4) is the language created by SAP for implementation and customization of its R/3 system. ABAP/4 comes loaded with many predefined logical databases that can construct and table just about any conventional business objects you might need in any canned SAP application. However, you can also create your own logical databases to construct any custom objects you care to define, as your application requires in ABAP/4. Here’s a step-by-step guide:

1. Call up transaction SLDB (or transaction SE36). The path you want is Tools | ABAP Workbench | Development |

Programming Environment | Logical Databases. This screen is called Logical Database Builder.

2. Enter an appropriate name in the logical database name field. You have three options on this screen: Create, Display, and Change. Choose Create.

3. You’ll be prompted for a short text description of your new logical database. Enter one. You’ll then be prompted to specify a development class.

4. Now comes the fun part! You must specify a root node, or a parent table, as the basis of your logical database structure. You can now place subsequent tables under the root table as needed to assemble the data object you want. You can access this tree from this point forward, to add additional tables, by selecting that root node and following the path Edit | Node | Create. Once you’ve saved the structure you define in this step, the system will generate the programming necessary to access your logical database. The best part is you don’t have to write a single line of code.

What is SAP Query? Purpose and Advantages of SAP Query?

By Suraj Kumar Pabbathi

Page 11: SAP ABAP

SAP Query is SAP’s tool to define and execute once own reports without knowing ABAP programming language. 

Let us see the key topics to explore SAP Query. 

Topic # Topic1 What is Query?

Purpose of Query.

Advantages of Query2 Infosets/UserGroups/Query in Detail3 Practical session covering important working models - I4 Practical session covering important models-II

Various Lists and Background Scheduling

In this document we shall cover Topic#1. 

What is SAP query and why do we need queries? 

Many times a need arises for SAP Users and Functional Consultants to generate quick reports without getting any ABAP coding done – time taken to complete the coding in development, transport and test it in QA system and then transport to production – is sometimes too long. In such cases, SAP query is a tool provided by SAP for generating these kinds of reports. 

Purpose

The SAP Query application is used to create reports not already contained in the default. It has been designed for users with little or no knowledge of the SAP programming language ABAP.

SAP Query offers users a broad range of ways to define reports and create different types of reports such as basic lists, statistics, and ranked lists.

These outputs can include lists on screens in table format, ALV grids, downloadable spreadsheets, and downloadable flat files. The internal report generator creates an ABAP program corresponding to the definition of the list.

Features:

The SAP Query comprises five components: 

      Queries

      InfoSet Query

      InfoSets

      User Groups

      Translation/Query 

Page 12: SAP ABAP

Classic reporting- the creation of lists, statistics and ranked lists- are covered by theInfoSet Query and Queries components. Other components’ range of functions cover the maintenance of InfoSets, the administration of user groups and also the translation of texts created in the SAP Query. All data required by a user for a report can be read from various tables. 

To define a report, you first have to enter individual texts, such as titles, and select the fields and options, which determine the report layout. In the WYSIWYG (What You See Is What You Get) mode, you can edit the lists using Drag & Drop and various toolbars. 

Overview:

The following sections describes the individual SAP Query components and provides general information about query areas, transport and authorizations 

Menu Path Used For Transaction Code

 SAP Query  Queries Maintaining Queries SQ01

 SAP Query  InfoSets Maintaining InfoSets SQ02

 SAP Query  User Groups Maintaining User Groups SQ03

 Translation  Query Language Comparision SQ07

 Query Components

The Queries component is used by end users to maintain queries.

You can carry out the following tasks:

      Execute Queries and Generate Lists

      Define Queries

      Change Queries

Infosets Components

      InfoSets are special views of data sources.

      An InfoSet describes which fields of a data source can be reported on in queries.

      InfoSets are assigned to user groups.

Page 13: SAP ABAP

      End-users are able to work only with those InfoSets that are relevant to their particular area, as designated by the role or user group that they are assigned to.

      Eg: Vendor master data can be important in purchasing as well as in accountancy. The relevant InfoSet is assigned to both roles/user groups. This means that queries based on this InfoSet can be copied and executed by both groups.

User Groups Components

1. The User Groups component is used to maintain user groups. The system administrator uses it to set up the work environment for end-users.

2. Every user assigned to the user group is able to execute the query.3. Users are not allowed to modify queries from other user groups, although they may, under certain circumstances, copy and execute

Translation/Query Component

      A great deal of text is generated when defining queries, InfoSets, and user groups.

      The SAP Query displays these texts in the language that you chose when you logged on to the SAP system.

      You can compare the text languages using the component Translation/Query.

      A related text in one or more additional languages is made available for each of the texts created when defining the query.

Query Areas

A query area contains a set of query objects (queries, InfoSets, and user groups) that are discrete and consistent.

There are the following query areas:

      Standard area

      Global area

Standard Area

1.Client specific

2.Query objects are not attached to the Workbench Organizer

Advantage :-End users can develop queries (ad-hoc reports) in their own client that are not meant for use in the rest of the system.

Global Area

Page 14: SAP ABAP

1.Cross client

2.Query objects are attached to workbench organizer

Advantage:-The global query area is well suited for centrally developing queries meant for use and distribution throughout the system.

Authorizations

End-users, system administrators, and translators must all be assigned the appropriate authorizations allowing them to work with the SAP Query. 

In order to give individual users targeted, specific rights, the following options are available:

      Roles/user groups

      Authorizations

Steps to create a Query

Step Description TCODE

1 Create a infoset or functional area SQ02

2 Assignment of user group to infoset SQ03

3 Creation of query based on infoset SQ01

Tools for Queries 

The following are the tools to manage, create and change queries.

      Infoset Query

      Queries

      Quick viewer

Working with Infosets, User Groups, Query in detail

By Suraj Kumar Pabbathi, YASH Technologies

In this document we shall cover Topic#2. For topic#1, click here.  

Page 15: SAP ABAP

Infosets Components 

      InfoSets are special views of data sources.

      An InfoSet describes which fields of a data source can be reported on in queries.

Page 16: SAP ABAP

      InfoSets are assigned to user groups.

      End-users are able to work only with those InfoSets that are relevant to their particular area, as designated by the role or user group that they are assigned to.

      Eg: Vendor master data can be important in purchasing as well as in accountancy. The relevant InfoSet is assigned to both roles/user groups. This means that queries based on this InfoSet can be copied and executed by both groups. 

Creating and changing Infosets 

 

Creating Infosets – Prerequisites

Assign Data sources

Infoset Display/Change

Definition of field groups

Obtaining additional information

Creating Selections

Further Codes

Application Specific Enhancements

 Creating Infosets – Prerequisites 

The following questions help in meeting the prerequisites of creating an infoset.

      Which data source corresponds to the requirements?

            For example: Material reports in Materials Management

            Document reports in Financial Accounting

      Which fields do you need to include in the InfoSet?

      Do you need additional information which is not available in the data source? (This means you are going to have to connect additional tables and the definitions of additional fields.)

      Do you need parameters and selection criteria? (Parameters and selection criteria appear on the selection screens of queries that are created using the InfoSet).

      Do you need to include any particular measures such as access protection?

      Do you need to be able to change the long texts and headers for the selected fields? 

Page 17: SAP ABAP

Assign Data sources 

1. Name2. Authorization group: This means that only users authorized to execute programs from this authorization group are able to execute these

queries. Use Tcode: AUTH_DISPLAY_OBJECTS3. Choose Data Source:

     Table join using a table: Is used when Query is prepared for retrieving data from more than one database tables having relationships.

     Reading tables directly: Is used when Query is prepared for retrieving data from one table.

       Logical databases: Is used when Query is prepared for retrieving data based on a Logical database (LDB)

4. Using programs to retrieve data: Here a program can be written with own logic. Declaration in data section of the program will help the query to select the elements of data to be retrieved from database. As per the logic, data is validated, processed. The selection screen can be prepared in Query and data is retrieved for output.

     Sequential datasets

4. Options

      No Automatic Text Recognition

      Fixed Point Arithmetic 

Display/Change Infoset 

      The InfoSet display allows you to examine or change the structure of the InfoSet.

      Assigning additional tables

      Creating additional fields

      Creating additional Structures

      Extras

      Selections

      Further Code

      Application Specific Enhancements 

Definition of field groups 

      A field group combines related fields together into a meaningful unit.

Page 18: SAP ABAP

      Fields must be assigned to a field group before they can be used in queries.

      Include all table fields

      Include key fields

      Create empty field groups 

Note:

Logical Database having more than 4 structures has different way of creating field groups.Eg: PNP 

User Groups Components 

      The User Groups component is used to maintain user groups. The system administrator uses it to set up the work environment for end-users.

      Every user assigned to the user group is able to execute the query.

      Users are not allowed to modify queries from other user groups, although they may, under certain circumstances, copy and execute

 

Page 19: SAP ABAP

 

1.Creating infosets or functional areas

       Tcode-SQ02 

 

Page 20: SAP ABAP

 

 Continued...

Working with Infosets, User Groups, Query in detail

...Previous 

Page 21: SAP ABAP

 

 

Page 22: SAP ABAP

 

 

Page 23: SAP ABAP

 

2. To create user groups and assign to infosets

      Tcode-SQ03

 

Page 24: SAP ABAP

  

 

Page 25: SAP ABAP

 

  Continued...

Working with Infosets, User Groups, Query in detail

...Previous  

3. To create a query 

      Tcode-SQ01 

Page 26: SAP ABAP

 

 

Page 27: SAP ABAP

 

 

Steps to create selection criteria to the query

      Tcode-SQ01

Page 28: SAP ABAP

 

 

Page 29: SAP ABAP

 

 

Page 30: SAP ABAP

Step-by-step procedure in configuring SAP Query

SAP R/3 Query tools (SAP Query) are based on the following four main components:

Query Areas Query Groups InfoSets  Administrative Decisions (Company-specific)

Configuration of the Query tools is done in the following manner:

Create Query Groups  Assign Users to Query Groups Create InfoSets  Assign each InfoSet to a Query Group.

Create Query Groups

        Go to Transaction SQ03.

Page 31: SAP ABAP

 

        Ensure that you are in the correct SAP Query area by navigating to Environment  Query Areas

 

        Select the “Standard Area (Client-specific).

        Now in the main screen, enter the name of the Query Group in the User Group field and click on CREATE 

 

Page 32: SAP ABAP

        Enter the description of the User Group in the next popup that appears. 

 

        User Group ZSAPTECH_GRP is created. 

Assign Users to Query Groups 

        Click on the “Assign Users and InfoSets” button 

 

        Enter the SAP User-Ids of all the users you wish to include in the test group.

 

Page 33: SAP ABAP

Click on SAVE to save your entries.

Step-by-step procedure in configuring SAP Query

Continued...

Create InfoSets

         Go to transaction SQ02

        Ensure that you are in the correct SAP Query area by navigating to Environment  Query Areas

 

        Enter the name of the InfoSet you wish to create and click on CREATE. 

Page 34: SAP ABAP

        Enter the title and the logical database on the popup screen that appears. 

 

We have used the LDB F1S (Flight bookings related) for our demo purpose. 

Page 35: SAP ABAP

        Change InfoSet screen appears. 

 

        Expand the tree on the left hand side to view the fields in each table. As seen on the screen, the left side of the screen shows the tables and the fields. The right side displays the field groups.

        Now we need to assign fields to the field groups. These field groups will display in the SAP Query tool during reporting. Please note that only the fields that are included here will be available for field selection in the SAP Query Tool that uses this infoSet as a data source.

        Select the field group on the right side and then drag and drop the fields from the left side to this field group. 

Page 36: SAP ABAP

       

When all the required fields are added, click on SAVE.

        Now generate the InfoSet by clicking on GENERATE. 

Attach each InfoSet to a Query Group

        Go to transaction SQ02

        Enter the InfoSet name created above and click on “User Group Assignment” button. 

Page 37: SAP ABAP

 

        Select the query group “ZSAPTECH_GRP” from the above list and click on SAVE.