Powered By

Free XML Skins for Blogger

Powered by Blogger

Saturday, October 18, 2008

free download book on abap reporting on all modules

free download book on abap reporting on all modules

Submit ABAP report with SQL traces

You use ST05, Trace Request, to do a SQL trace.

When using SQL trace, it is good to run the program in debugger and just before you execute the SQL, go to ST05 in another session and turn the trace on.

After, or when, the SQL is finished, you can turn the trace off.

Then click on List Trace to see the details.

This is the way to control the traces.

If you just turn the trace on and then execute the program, you will get everything and will be overflooded with unnecessary information.

SAP ABAP Commonly Asked Questions I

What is the difference betwen abap and sap memories?

Data sending between internal sessions is called abap memory using import and export parameters.
Data sending between main sessions using spa/gpa ie (set /get) parameters called sap memory.

2) What is nast?
nast is a message status database table.

3) How to upload logo in sapscripts?
1... create a logo using paint shop and save it as tifffile then using RSTXLDMC (is a program name) used to upload logo
2.....create a logo using paint shop and save it as bmpfile then using SE78 you can do this.

4) What are symbols explain?
Symbols are constants used to save un nessessary work used in documentation
1. system symbols : example: &date& &time& etc
2. text symbols: they are defined using control statements
protect...endprotect, if endif, etc
3. standard symbols : all the messages are stored in TTDTG table
4. program symbols : used in abap program example: &i_mara-matnr& &i_mara-ernam&

5) Difference b/w call transaction and session.
Call transaction Ssession
1. synchronous updation only synchronous updation
optional
2. errors can handled error log is created
explicitely
3. faster slower
4. less amount of data more can transfer
5. updation takes place updation takes place
during program execution once the session being created

6. Difference b/w smartforms and scripts.
Script Smartforms
client dependant independant
not possible multiple page formats are possible
compulsory without main window it can
labels are used labels cannot
not generated once session created function module

7. Errors hanling in call transaction
Two ways
1)... int table decalred having structure BDCMSGCOLL it is having certain variables not texts. ie msgtyp,megid, msgnr,
msgvar1, msgvar2, msgvar3, msgvar4 etc all the text messages are stored using T100 database table.
2)....int table decalred having structure BDCMSGCOLL it is having certain variables . ie msgtyp,megid, msgnr,
msgvar1, msgvar2, msgvar3, msgvar4 etc by declaring function modules format_message or write_message you can handle.

8. Errors handling in session
In SM35 error log is created, there you can handle.

9. Difference b/w select-options, valueranges, parameters.
par----- singlevalue
select-options----range and itself implicitly creates internal table
value-ranges---- just for ranges

10. How to remove duplicate entries?
using COLLECT
or
DELECT DUPLICATE ENTRIES FROM TABLENAME>

11. What are standard texts?
These are predefined texts used for create change and display tcode SO10
Starting with INCLUDE
These are for TERMS AND CONDITIONS .

12. What is the use of select....for all entries?
Avoid nested select or inner joins
uses
fast processing
sorting
delete duplicate entries

13. What is the difference b/w exit and continue?
exit----if it is in the loop comes out of the loop.
----if it is in the subroutine comes out of the routine.
----if it is in the program comes out of the preogram.
continue-----unconditional jumping out of the loop.

14. What is the diffenrence b/w collect and append.
collect----- checks whether it is there or not. if there adds integer, packed, float otherwise remove
append-----just adding

15) What are barcodes?
For security purpose

Tips by : Ramana

What is meant by "Matchcode"?

Matchcodes are defined in two stages in Abap/4 Dictionary:

1) The revelant table and fields are stipulated in matchcode object. A matchcode object describes the set of all possible search paths for a search item.
2) One or more matchcode ID can be defined for a matchcode object. A matchcode ID describes a special search path for a search term.The fields or combination of fields via which the search is to take place is defined in the matchcode ID.

Difference Between LIS, Reports, Abap Query

LIS stands for Logistics Information System.

It is the information systems used to plan, control, and monitor business events at different stages in the decision-making process.

The Logistics Information System is made up of the following information systems which all have a modular structure:

- Sales Information System
- Purchasing Information System
- Inventory Controlling
- Shop Floor Information System
- Plant Maintenance Information System
- Quality Management Information System

Tools are available in Customizing to allow a self-defined information system to be created and tailored to specific requirements.

2) Reports:

SAP Reports are Programmes which are used to fetch data from SAP database under specified selection criteria and show in list viewer. Later you can view, download & take decisions appropriately.

There are many standard reports in SAP for various modules. For SD Module watchout TCode SD01. You can always code your own report they way you want in some cases.

3) ABAP Queries

These are the report which users can prepare without knowledge of the ABAP programming language to define and execute their own reports. Normally Functional Consultants use these ABAP query tool to create and run simple reports by themselves instead of coding by ABAPer. Its flexible and convinent. However you should be well thorough with different tables to map query and fetch data.

SAP Some ABAP/4 Query header line variable

  • &%NAME Name of user executing the query
  • &%DATE Current date when executing the query
  • &%TIME Current time when executing the query
  • &%PAGE Current page number (output 6 characters)

SAP ABAP Quick Viewer

In SAP 4.6x, you can used a simplified ABAP query. The Quick Viewer ( SQVI ) can be used to generate simple report without any programming.

You select fields according to your data source that determine the structure of your report. The report can be executed in basis mode with standard layout or may be edited using drag and drop and other toolbox functions available in WYSIWYG mode.

However, only transparent table are allow to be use in SQVI.

e.g. Your cannot use BSEG as it is a cluster table, instead use BSIS.

  • BKPF - Accounting Document Header
  • BSIS - Accounting: Secondary Index for G/L Accounts

SAP ABAP Proxy communication

Proxy objects implement message interfaces from Integration Repository. Proxies are executable interfaces, which converts non-language-specific interface descriptions into WSDL. i.e., you use proxies to implement the actual message exchange that is described in the Integration Builder.

Types of Proxy objects: You can use message interfaces to create the following proxy objects:

  • ABAP Proxy objects
  • JAVA Proxy objects

During the process of ABAP proxy generation, it gets WSDL (Web Service Description Language) description of message interfaces from the Integration Repository by using HTTP communication.

Proxy Generation:

As part of SAP Web AS 6.40

  • ABAP proxy generation enables you to generate proxies to communicate by using the Web service infrastructure and by using SAP Exchange Infrastructure
  • ABAP proxies that were generated from message interfaces in the Integration Repository (IR) can be used in both infrastructures.
  • This means that if none of the Integration Server services are available for a proxy-to-proxy communication scenario in ABAP, you can use a point-to-point connection using the Web service infrastructure instead.

The prerequisites to configure ABAP Proxy include: (landscape dependent)

  1. The business systems should be based on SAP Web AS 6.20 and SAP Web AS 6.20 kernel patch level above 1253
  2. You have installed the XI Add-On in each of these business systems as described in the Installation Guide SAP Exchange Infrastructure 3.0
  3. The business systems and your central Integration Server are maintained in the System Landscape Directory (SLD).

Configuration required on the Business System:

1. Create a HTTP connection in the business system using transaction SM59

Technical Setting:

· Connection Type: H

· Target Host: System name

· Service Number: HTTP Port name

· Path Prefix: /sap/XI/engine/?type=entry

Logon Security

On the Logon/Security tab page, enter the following logon data:

· User: XIAPPLUSER (for example); this user should represent the sending business system (see also the SAP XI Security Guide under Service Users for Message Exchange).

· Password: the password you have specified for this user

· Client: SAP XI Integration server

· Language: Language required

2. Configuration Business system as local Integration Engine.

1. Go to Transaction SXMB_ADM

2. Choose Edit --> Change Global Configuration Data.

3. Select Role of Business System: Application system

4. Corresponding Integration server: dest://. Here XI_XIR_CONNECTION created in step 1. Dest://XI_XIR_CONNECTION.

5. Under Specific Configuration Data you can specify additional configuration data

    • Select the relevant category under Specific Configuration Data.
    • Choose Change Specific Configuration Data.
    • For ABAP Proxies, Add the following configuration:
      1.Category RUNTIME
      2.Parameters: IS_URL
      3.Current Value: dest://XI_XIR_CONNECTION

3. Connection between Business System and System Landscape Directory

  • Create RFC destination (TCP/IP) LCRSAPRFC and SAPSLDAPI for the SLD connection.
  • To create RFC Destination: LCRSAPRFC
    • Connection Type: T
    • Choose the Technical settings tab page and do the following:
      In the Program ID field under Registered Server Program, enter LCRSAPRFC
      This program ID must correspond to a program ID specified in the RFC engine settings of the SAP J2EE Engine on the Integration Server host.
  • Repeat the above step for RFC destination for SAPSLDAPI

4. Maintaining the SAP J2EE Connection Parameters for LCRSAPRFC and SAPSLDAPI in SAP J2EE engine

  • Goto J2EE Engine
  • Choose Cluster --> Server --> Services. JCo RFC provider
  • Under RFC destination specify the following:
    Program ID: LCRSAPRFC
    Gateway Host:
    Gateway Service:
    Number of process: 3
  • Under Repository specify the following: Application Server:

5. Maintain SLD access details in Transaction SLDAPICUST


If there is an HTTP error during connection, check the error using the transaction SLDCHECK in the Business system. Also ensure that HTTP connection is working fine.


In XI Adapter use HTTP connection rather than giving R/3 input details, as this is easier to transport and for maintenance. One receiver adapter can be used for all Interfaces connecting to a Business system.

Demo Scenario

This document describes Time bound file processing scenario where in, a file containing the employee personal details is picked from a FTP server system (Sender/Source) and sent to SAP System (Receiver/Target) via Exchange Infrastructure. Server ABAP proxy is configured to post the data to an application on target SAP System which will save the records into database.

Let us have design in Integration repository. The following screen illustrates the outbound message structure in which employee data type is encapsulated.

In this example a small difference is maintained between the source message structure and target structure to show the need of mapping. Find below the mapping where in Full name is constructed after concatenating the Last name and First name.

Finally we require a message interface, which will encapsulate the message mapping between source structure and target structure.

Before completing the configuration in Integration Directory, let us create a ABAP proxy object in Target SAP system.

Go to Transaction: SPROXY where in you get to see all the objects designed in Integration Repository. As Proxies implement message interfaces in Integration Repository, navigate to the required inbound message interface, as we are creating a Server proxy. Right click to create the Proxy as shown in the below screenshot.

You can observe a Proxy-interface getting created in Target system with ‘Properties’, ‘Generation’, ‘Structure’ and ‘Type Mappings’.

You observe that Structures resembling inbound data types, message types get created in the system. As the target structure can get multiple records of Employee personal details in this scenario, observe that a Table type of ZEMPLOYEE_IB_EMPLOYEE_TAB getting created. This can be transferred to required application in SAP for successful processing of the records, ultimately saving them into database.

You can observe the compatible equivalent elements of inbound data type created.

Finally you need to implement the Proxy. For this double click ‘Implementing Class’ on ‘Properties’ tab to lead you to method ‘EXECUTE_ASYNCHRONOUS’. This is default method that gets created with Implementing Class where in you need to code as per the business logic. Find below the screenshot of the sample code that reads the data from Employee internal table and inserts the data into database.

Now it is the time for configuration. Logon to XI integration directory to start creating the collaborative profiles and agreements to route the message from source system and then placing a proxy call to server proxy to post the data to target SAP System.

First we need a Sender Communication channel, which will be able to pick up the file from source FTP server. Find below the attributes of the communication channel, which is of type ‘File’.

Then create a receiver communication channel to place a proxy call. Though we use XI Adapter for placing the proxy call, we will call this communication as ‘Adapter less’ communication. The reason is, usually an adapter is used to specify transport protocol where in this is used to define the mode of communication and message protocol where in this is used to convert the message format from XML to native format and other wise.

As XI adapter is defined with HTTP as transport protocol and XI as message protocol, both are default protocols of XI environment, hence we say it is adapter less communication.

To complete the configuration we have to define collaborative profiles and agreements, which include Sender Agreement, Receiver Agreement, Interface Determination and Receiver Agreement. Find below the screenshots explaining the same.

Now prepare the file with Employee personal details resembling outbound message type as shown below:

This file is placed on FTP server to wait for the XI server to pick of the file at regular intervals, hence we can call the scenario to be Time bound file processing.

After the defined periodicity as per Sender communication channel, the file is picked for processing and can be found through ABAP stack of XI through the transaction code SXI_MONITOR. This is explained in the screenshot below:

Shortly you will notice that the message got successfully processed and data is posted in the database.

The record that got posted is related to SSN 999 that can be viewed in the database.

SAP ABAP/4 Program: Describe Select-Options

When printing a report, you can print the search conditions or report parameters that the user entered. For instance, if a report output was restricted to plants between 1011 and 1501, you may want to print "Plants Between 1011 and 1501" on the report. This procedure describes the selected parameters.

Describe Select-Options


select-options: sel_opt for sy-datum.
.
.
.
loop at sel_opt.
perform describe_select_options using 'Date'
sel_opt-sign
sel_opt-option
sel_opt-low
sel_opt-high
changing datedesc.
write: / datedesc.
endloop.
.
.
.
*&---------------------------------------------------------------------*
*& Form DESCRIBE_SELECT_OPTIONS
*&---------------------------------------------------------------------*
form describe_select_options using
field_name type c "name to describe field (e.g. "Date")
sel_opt_sign like sel_opt-sign
sel_opt_option like sel_opt-option
sel_opt_low like sel_opt-low
sel_opt_high like sel_opt_high
changing descline type c. "line that will hold the one-line description
if sel_opt_sign = 'i'.
concatenate 'Include' field_name into descline separated by space.
else.
concatenate 'Exclude' field_name into descline separated by space.
endif.
case sel_opt_option.
when 'EQ'.
concatenate descline '=' sel_opt_low into descline
separated by space.
when 'BT'.
concatenate descline 'between' sel_opt_low 'and' sel_opt_high
into descline separated by space.
when 'NB'.
concatenate descline 'not between' sel_opt_low 'and' sel_opt_high
into descline separated by space.
when 'NE'.
concatenate descline '!=' sel_opt_low into descline
separated by space.
when 'GE'.
concatenate descline '>=' sel_opt_low into descline
separated by space.
when 'LE'.
concatenate descline '<=' sel_opt_low into descline
separated by space.
when 'GT'.
concatenate descline '>' sel_opt_low into descline
separated by space.
when 'LT'.
concatenate descline '<' sel_opt_low into descline
separated by space.
endcase.
endform. " describe_select_options

SAP ABAP/4 Program: Output Table Fields to a List

When you're looking at the structure of a table, SAP will let you print the structure, but it won't let you save the structure. This can be annoying. This report outputs the table structure to a list. At this point the user can use the System->List->Save->Local file command to save the list to a file.

Output Table Fields to a List


*&---------------------------------------------------------------------*
*& Report YTABFLDS *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT YTABFLDS .
TABLES: DD02L, DD03L, DD04T.

PARAMETERS THETABLE LIKE DD02L-TABNAME OBLIGATORY.
DATA: BEGIN OF MYTABLE,
TABNAME LIKE DD02L-TABNAME,
AS4LOCAL LIKE DD02L-AS4LOCAL,
AS4VERS LIKE DD02L-AS4VERS,
END OF MYTABLE.

SELECT SINGLE TABNAME AS4LOCAL AS4VERS INTO MYTABLE FROM DD03L
WHERE TABNAME = THETABLE.
WRITE: / MYTABLE-TABNAME, 11 MYTABLE-AS4LOCAL, 13 MYTABLE-AS4VERS.
SELECT * FROM DD03L
WHERE TABNAME = MYTABLE-TABNAME AND
AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS.
WRITE: / DD03L-FIELDNAME, 11 DD03L-KEYFLAG, 13 DD03L-ROLLNAME,
24 DD03L-CHECKTABLE, 35 DD03L-INTTYPE, 37 DD03L-REFTABLE,
48 DD03L-DATATYPE.
SELECT SINGLE * FROM DD04T
WHERE ROLLNAME = DD03L-ROLLNAME AND
AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS AND
DDLANGUAGE = 'E'.

WRITE: 53 DD04T-DDTEXT.
ENDSELECT.

SAP ABAP/4 Program: Outstanding PO Report

This report displays information for outstanding purchase orders. The report has two parts: one is the standard report, and the other is called from the Project Expense report. Note that both reports output GL Account, cost center, and cost object information (from table EKKN) as a single value on the output line. Actually, each line may have several cost centers and cost object to which the invoices were allocated; however, the user only wanted one (any one) to be listed.

Standard Report: The standard report lists info (limited by selection criteria) for purchase order items whose GR and IR are not equal. The report first accesses the header table EKKO, limited by purchasing group and purchase order. It then accesses EKPO, limited by PO item and material selection criteria. An internal table sums keeps subtotals of the related GR/IR quantities and values, read from EKBE, for the given PO and item. In the fill_sums routine, the subtotals are grouped by Credit/Debit indicator (EKBE-SHKZG), account assignment (EKBE-ZEKKN), and PO Doc Category (EKBE-BEWTP). These subtotals are then processed by the fill_outtab routine, which makes the GR/IR totals and compares them. If they are unequal, data is looked up further from EKKN, and the item is output.

Report Called from Project Expense Report: The report called from the Project Expense Report is the same as the standard report except that:

the compare variable is set to value 'A'.
records are outputted if GR < IR, or if both GR and IR are zero
selection criteria is based on the data in the po_itemp select-options list. This list is filled when the report is called
project number is output (project number is looked up in the po_aufnr select-options list which is filled when the report is called)
subtotals are not outputted
Outstanding PO Report


*&---------------------------------------------------------------------*
*& Outstanding POs *
*& *
*& ekbe has GR/IR records. If there is account assignment (ekpo-knttp *
*& is not blank), then ekkn will also have records related to the ekbe *
*& records. First check ekbe to see if GR/IR are unequal. If they are, *
*& list them and show related info. *
*& *
*& The ekkn table may contain several records with different G/L Accts *
*& Cost Centers, and/or Cost Objects. This report selects one record *
*& at random and uses it to get this data. Thus the *
*& report's output is somewhat misleading, as the G/L, Cctr, and CObj *
*& are listed as a single value rather than several values. A better *
*& implementation would list this info in sub-records (e.g. drill-down)*
*&---------------------------------------------------------------------*

REPORT ZGRIROPO LINE-SIZE 250 LINE-COUNT 65 NO STANDARD PAGE HEADING.
TABLES: EKBE, EKPO, EKKO, EKKN, BSIS.
PARAMETERS: COMPARE TYPE C NO-DISPLAY.
SELECT-OPTIONS:
PO_DOC FOR EKPO-EBELN, "Purchase order
PO_ITEM FOR EKPO-EBELP,"Purchase order item
PUR_GRP FOR EKKO-EKGRP,"Purchasing Group
MAT_NR FOR EKPO-MATNR, "material #
SEL_ACCT FOR EKPO-KNTTP, "account assignment category
POSTDAT FOR SY-DATUM NO-DISPLAY, "posting date
"transfer of params from project expense report
PO_ITEMP FOR EKPO-EBELN NO-DISPLAY, "PO/item pair
PO_AUFNR FOR BSIS-AUFNR NO-DISPLAY. "PO/order pair

DATA:
LN TYPE I, "subtotal for cost objects
TOTAL LIKE EKBE-DMBTR,
OLDSAKTO LIKE EKKN-SAKTO,
OLDKOSTL LIKE EKKN-KOSTL,
OLDKSTRG LIKE EKKN-KSTRG,
DO_SUBTOTAL TYPE C,
WROTE_SUBT TYPE C,
BEGIN OF COBJ_SUBTOTAL,
MENGE LIKE EKBE-MENGE,
GR LIKE EKBE-MENGE,
IR LIKE EKBE-MENGE,
ESTGRVAL LIKE EKBE-DMBTR,
IRVAL LIKE EKBE-DMBTR,
OUT LIKE EKBE-MENGE,
ESTOUTVAL LIKE EKBE-DMBTR,
END OF COBJ_SUBTOTAL,
BEGIN OF TOTALS.
INCLUDE STRUCTURE COBJ_SUBTOTAL.
DATA:END OF TOTALS,
EKKOEBELN LIKE EKKO-EBELN, "for ekko data
BEGIN OF MYEKPO, "for ekpo data
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MENGE LIKE EKPO-MENGE,
NETPR LIKE EKPO-NETPR,
KNTTP LIKE EKPO-KNTTP,
TXZ01 LIKE EKPO-TXZ01,
END OF MYEKPO,
BEGIN OF MYEKKN,
* zekkn like ekkn-zekkn,
MENGE LIKE EKKN-MENGE,
VPROZ LIKE EKKN-VPROZ,
SAKTO LIKE EKKN-SAKTO,
KOSTL LIKE EKKN-KOSTL,
KSTRG LIKE EKKN-KSTRG,
END OF MYEKKN,

BEGIN OF SUMS OCCURS 20, "totals for gr and ir
ZEKKN LIKE EKBE-ZEKKN, "Acct assignment serial
BEWTP LIKE EKBE-BEWTP, "PO Doc category
MENGE LIKE EKBE-MENGE, "GR/IR Quantity
DMBTR LIKE EKBE-DMBTR, "GR Value
SHKZG LIKE EKBE-SHKZG, "Debt/Credit indicator
END OF SUMS,

BEGIN OF OUTTAB OCCURS 1000, "output list
EBELN LIKE EKPO-EBELN, "PO Doc
EBELP LIKE EKPO-EBELP, "PO item
ZEKKN LIKE EKKN-ZEKKN, "account serial #
SAKTO LIKE EKKN-SAKTO, "G/L acct
KOSTL LIKE EKKN-KOSTL, "cost center
KSTRG LIKE EKKN-KSTRG, "cost object
MENGE LIKE EKPO-MENGE, "Quantity (total)
TXZ01 LIKE EKPO-TXZ01, "short text
GR LIKE EKPO-MENGE, "GR Quantity
ESTGRVAL LIKE EKBE-DMBTR,
GRVAL LIKE EKBE-DMBTR, "GR Value
IR LIKE EKPO-MENGE, "IR Quantity
IRVAL LIKE EKBE-DMBTR, "IR Value
OUT LIKE EKPO-MENGE, "Outstanding IR quantity
OUTVAL LIKE EKPO-BRTWR, "Outstanding IR value
ESTOUTVAL LIKE EKPO-BRTWR, "Estimated Outstanding IR Value
END OF OUTTAB.

AT SELECTION-SCREEN.
IF PUR_GRP IS INITIAL AND PO_DOC IS INITIAL.
MESSAGE E007(ZS).
ENDIF.

START-OF-SELECTION.
* should do authorization checking here **
SELECT EBELN FROM EKKO "select POs from pur grp and po doc
INTO EKKOEBELN
WHERE LOEKZ = ' ' AND "not to be deleted
EKGRP IN PUR_GRP AND "criteria
EBELN IN PO_DOC
ORDER BY EBELN.
* should do authorization checking here **
SELECT EBELN EBELP MENGE NETPR KNTTP TXZ01
FROM EKPO "select POs from material criteria
INTO MYEKPO
WHERE LOEKZ = ' ' AND "not to be deleted
KNTTP IN SEL_ACCT AND
EBELN = EKKOEBELN AND
EBELP IN PO_ITEM AND
MATNR IN MAT_NR
ORDER BY EBELN EBELP.
IF COMPARE = 'A'. "only use PO/item pairs passed from proj exp
LOOP AT PO_ITEMP
WHERE HIGH = MYEKPO-EBELN AND LOW = MYEKPO-EBELP.
ENDLOOP.
CHECK SY-SUBRC = 0. "PO/item pair was listed
ENDIF.
* should do authorization checking here **
PERFORM FILL_SUMS.
PERFORM FILL_OUTTAB. "fill info for output
CLEAR OUTTAB.
ENDSELECT.
ENDSELECT.
PERFORM WRITE_OUTTAB.
*---------------------------------------------------------------------*
* FORM FILL_SUMS *
*---------------------------------------------------------------------*
FORM FILL_SUMS. "fill sums table with GR/IR data from ekbe
CLEAR SUMS. CLEAR SUMS[].
SELECT ZEKKN BEWTP MENGE DMBTR SHKZG FROM EKBE INTO SUMS
WHERE EBELN = MYEKPO-EBELN AND EBELP = MYEKPO-EBELP.
CHECK SUMS-SHKZG <> ' '.
IF SUMS-SHKZG = 'H'. "negative value
SUMS-MENGE = - SUMS-MENGE.
SUMS-DMBTR = - SUMS-DMBTR.
ENDIF.
SUMS-SHKZG = ' '.
COLLECT SUMS.
ENDSELECT.
ENDFORM.

*---------------------------------------------------------------------*
* FORM FILL_OUTTAB *
*---------------------------------------------------------------------*
FORM FILL_OUTTAB.
* preconditions: myekpo is set at current PO and item
* sums has gr/ir totals, by zekkn sub-index
CLEAR OUTTAB.
LOOP AT SUMS.
IF SUMS-BEWTP = 'E'. "goods receipt
OUTTAB-GR = OUTTAB-GR + SUMS-MENGE.
OUTTAB-GRVAL = OUTTAB-GRVAL + SUMS-DMBTR.
ELSEIF SUMS-BEWTP = 'R'. "invoice receipt
OUTTAB-IR = OUTTAB-IR + SUMS-MENGE.
OUTTAB-IRVAL = OUTTAB-IRVAL + SUMS-DMBTR.
ELSE.
* perform write_bewtp_unhandled.
ENDIF.
ENDLOOP.
IF COMPARE = SPACE.
CHECK OUTTAB-GR <> OUTTAB-IR. "if gr/ir is equal, stop processing
ELSE. "COMPARE = 'A'.
CHECK ( OUTTAB-IR < OUTTAB-GR OR
( OUTTAB-GR = 0 AND OUTTAB-IR = 0 ) ).
ENDIF.
OUTTAB-EBELN = MYEKPO-EBELN.
OUTTAB-EBELP = MYEKPO-EBELP.
OUTTAB-MENGE = MYEKPO-MENGE.
OUTTAB-TXZ01 = MYEKPO-TXZ01.
OUTTAB-OUT = OUTTAB-GR - OUTTAB-IR.
OUTTAB-OUTVAL = OUTTAB-GRVAL - OUTTAB-IRVAL.
OUTTAB-ESTGRVAL = OUTTAB-GR * MYEKPO-NETPR.
OUTTAB-ESTOUTVAL = OUTTAB-ESTGRVAL - OUTTAB-IRVAL.
IF MYEKPO-KNTTP <> ' '. "account assignment: need to use ekkn
IF EKPO-VRTKZ = '2'. "multiple account distributed by percentage
WRITE: / 'This program does not handle accounts distributed',
'by percentage. Pls check manually (PO number',
EKPO-EBELN, ')'.
EXIT.
ENDIF.
* Fill in random info from ekkn.
SELECT SINGLE MENGE VPROZ SAKTO KOSTL KSTRG FROM EKKN
INTO MYEKKN WHERE
EBELN = MYEKPO-EBELN AND EBELP = MYEKPO-EBELP.
OUTTAB-SAKTO = MYEKKN-SAKTO.
OUTTAB-KOSTL = MYEKKN-KOSTL.
OUTTAB-KSTRG = MYEKKN-KSTRG.
APPEND OUTTAB. CLEAR OUTTAB.
ENDIF. "account assignment
ENDFORM.

*---------------------------------------------------------------------*
* FORM WRITE_OUTTAB *
*---------------------------------------------------------------------*
FORM WRITE_OUTTAB.
DESCRIBE TABLE OUTTAB LINES LN.
IF LN = 0.
WRITE: / 'No records found.'.
EXIT.
ENDIF.
SORT OUTTAB BY SAKTO KOSTL KSTRG.
LOOP AT OUTTAB.
IF ( NOT OLDSAKTO IS INITIAL ) AND OUTTAB-SAKTO <> OLDSAKTO AND
WROTE_SUBT = SPACE.
DO_SUBTOTAL = 'X'.
ENDIF.
OLDSAKTO = OUTTAB-SAKTO.
IF ( NOT OLDKOSTL IS INITIAL ) AND OUTTAB-KOSTL <> OLDKOSTL AND
WROTE_SUBT = SPACE.
DO_SUBTOTAL = 'X'.
ENDIF.
IF ( NOT OLDKSTRG IS INITIAL ) AND OLDKSTRG <> OUTTAB-KSTRG.
DO_SUBTOTAL = 'X'.
ENDIF.
OLDKSTRG = OUTTAB-KSTRG.
WROTE_SUBT = SPACE.
IF DO_SUBTOTAL = 'X'.
PERFORM WRITE_COBJ_SUBTOTAL.
CLEAR COBJ_SUBTOTAL.
DO_SUBTOTAL = SPACE.
ENDIF.
ADD-CORRESPONDING OUTTAB TO COBJ_SUBTOTAL.
ADD-CORRESPONDING OUTTAB TO TOTALS.
IF OUTTAB-OUT < 0.
FORMAT COLOR COL_NEGATIVE.
ENDIF.
WRITE: /
OUTTAB-EBELN UNDER TEXT-004, "PO doc
OUTTAB-EBELP UNDER TEXT-005, "PO item
OUTTAB-SAKTO UNDER TEXT-006, "G/L Acct
OUTTAB-KOSTL UNDER TEXT-007, "Cost Center
OUTTAB-KSTRG UNDER TEXT-008, "Cost Object
(13) OUTTAB-MENGE UNDER TEXT-009, "Quantity
(13) OUTTAB-GR UNDER TEXT-010, "GR quantity
(13) OUTTAB-IR UNDER TEXT-011, "IR quantity
(13) OUTTAB-ESTGRVAL UNDER TEXT-017, "Estimated GR Value
* (13) outtab-grval under text-012, "GR Val
(13) OUTTAB-IRVAL UNDER TEXT-013, "IR Value
(13) OUTTAB-OUT UNDER TEXT-014, "Outstandng IR qty
(13) OUTTAB-ESTOUTVAL UNDER TEXT-018, "Estimated Out IR Value
* (13) outtab-outval under text-015. "Outstandng IRval
OUTTAB-TXZ01 UNDER TEXT-019.
IF COMPARE = 'A'.
LOOP AT PO_AUFNR WHERE HIGH = OUTTAB-EBELN.
WRITE: PO_AUFNR-LOW UNDER TEXT-020.
ENDLOOP.
ENDIF.
FORMAT COLOR OFF.
ENDLOOP.
PERFORM WRITE_COBJ_SUBTOTAL.
PERFORM WRITE_TOTALS.
ENDFORM.

*---------------------------------------------------------------------*
* FORM WRITE_HEADERS *
*---------------------------------------------------------------------*
FORM WRITE_HEADERS.
FORMAT COLOR COL_HEADING.
WRITE: / TEXT-004, "PO
12 TEXT-005, "Item
18 TEXT-006, "G/L
29 TEXT-007, "Cost Center
40 TEXT-008, "Cost Object
49 TEXT-009, "Tot Qty
57 TEXT-010, "GR Qty
71 TEXT-011, "IR Qty
85 TEXT-017, "Est GR Value
* 85 text-012, "GR Val
99 TEXT-013, "IR Val
113 TEXT-014, "Outstanding IR Qty
* 127 text-015. "Outstanding IR Val
127 TEXT-018, "Est Out IR Val
141 TEXT-019. "short text
IF COMPARE = 'A'.
WRITE: 183 TEXT-020. "project
ENDIF.
WRITE: / SY-ULINE.
FORMAT COLOR OFF.
ENDFORM.

TOP-OF-PAGE.
WRITE: SY-DATUM, SY-REPID, '/', SY-UNAME.
IF COMPARE = 'A'. "called from proj exp. report
READ TABLE POSTDAT INDEX 1.
WRITE: 85 'Project Expenditure Tracking Report (By PO Number)'.
WRITE: 'Posting date'.
IF POSTDAT-HIGH IS INITIAL.
WRITE: ':', POSTDAT-LOW.
ELSE.
WRITE: 'Between', POSTDAT-LOW, 'and', POSTDAT-HIGH.
ENDIF.
ELSE.
WRITE: 110 'Outstanding Purchase Order'.
ENDIF.
WRITE: 240 'Page:', 248(2) SY-PAGNO, / SY-ULINE.
PERFORM WRITE_HEADERS.

*&---------------------------------------------------------------------*
*& Form WRITE_COBJ_SUBTOTAL
*&---------------------------------------------------------------------*
FORM WRITE_COBJ_SUBTOTAL.
IF COMPARE = ' '.
WRITE: / SY-ULINE.
WRITE: / 'Subtotal' UNDER TEXT-008,
(13) COBJ_SUBTOTAL-MENGE UNDER TEXT-009, "Quantity
(13) COBJ_SUBTOTAL-GR UNDER TEXT-010, "GR quantity
(13) COBJ_SUBTOTAL-IR UNDER TEXT-011, "IR quantity
(13) COBJ_SUBTOTAL-ESTGRVAL UNDER TEXT-017, "Estimated GR Value
(13) COBJ_SUBTOTAL-IRVAL UNDER TEXT-013, "IR Value
(13) COBJ_SUBTOTAL-OUT UNDER TEXT-014, "Outstandng IR qty
(13) COBJ_SUBTOTAL-ESTOUTVAL UNDER TEXT-018. "Estimated Out IRva
SKIP 1.
WROTE_SUBT = 'X'.
ENDIF.
ENDFORM. " WRITE_COBJ_SUBTOTAL
*&---------------------------------------------------------------------*
*& Form WRITE_TOTALS
*&---------------------------------------------------------------------*
FORM WRITE_TOTALS.
WRITE: / SY-ULINE.
WRITE: / 'Total:' UNDER TEXT-008,
(13) TOTALS-MENGE UNDER TEXT-009, "Quantity
(13) TOTALS-GR UNDER TEXT-010, "GR quantity
(13) TOTALS-IR UNDER TEXT-011, "IR quantity
(13) TOTALS-ESTGRVAL UNDER TEXT-017, "Estimated GR Value
(13) TOTALS-IRVAL UNDER TEXT-013, "IR Value
(13) TOTALS-OUT UNDER TEXT-014, "Outstandng IR qty
(13) TOTALS-ESTOUTVAL UNDER TEXT-018. "Estimated Out IRva
ENDFORM. " WRITE_TOTALS

SAP ABAP/4 Program:Un/Lock all users in a client

Sometimes it is useful to be able to lock all the users out of a client; for instance, during a client copy (you can also do this with tp locksys, but you have to issue that command from the OS level, and then you can only use DDIC or SAP* to log on). You can use this program to lock out all users except yourself.

This program (un)locks all the users in a client, except for the current user, and the SAP* user. You might want to add somthing like SELECT-OPTIONS EXEMPTUS FOR USR02-BNAME to allow a list of usernames not to be processed.

Un/Lock all users in a client

*&---------------------------------------------------------------------*
*& Report YUSRLOCK *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT YUSRLOCK MESSAGE-ID Z1 .
TABLES: USR02.
PARAMETERS: LOCK AS CHECKBOX, LISTLOCK AS CHECKBOX.
DATA: UFLAGVAL TYPE I, LOCKSTRING(8) TYPE C.

*-------------- Authorization check -----------------------*
AUTHORITY-CHECK OBJECT 'ZPROG_RUN' ID 'PROGRAM' FIELD SY-CPROG.
IF SY-SUBRC <> 0.
IF SY-SUBRC = 4.
MESSAGE E000 WITH SY-CPROG. "some message about authorization check failure
ELSE.
MESSAGE E005 WITH SY-SUBRC. "some message about authorization check failure
ENDIF.
ENDIF.

IF LISTLOCK = 'X'.
WRITE:/ 'List all locked users: '.
SELECT * FROM USR02 WHERE UFLAG = 64.
WRITE: / USR02-BNAME.
ENDSELECT.
EXIT.
ENDIF.
IF LOCK = 'X'.
UFLAGVAL = 64. "lock all users
LOCKSTRING = 'locked'.
ELSE.
UFLAGVAL = 0. "unlock all users
LOCKSTRING = 'unlocked'.
ENDIF.

SELECT * FROM USR02 WHERE BNAME <> 'SAP*' AND BNAME <> SY-UNAME.
IF USR02-UFLAG <> 0 AND USR02-UFLAG <> 64.
WRITE: 'User', USR02-BNAME, 'untouched; please handle manually.'.
CONTINUE.
ENDIF.

** check that user has authority to make these changes
AUTHORITY-CHECK OBJECT 'S_USER_GRP'
ID 'CLASS' FIELD USR02-CLASS
ID 'ACTVT' FIELD '05'.
IF SY-SUBRC <> 0.
IF SY-SUBRC = 4.
WRITE: /'You are not authorized to lock/unlock user ',
USR02-BNAME, USR02-CLASS.
ELSE.
WRITE: /'Authorization error checking user ',
USR02-BNAME, USR02-CLASS, '(return code', SY-SUBRC, ').'.
ENDIF.
ELSE. "has authority
UPDATE USR02 SET UFLAG = UFLAGVAL WHERE BNAME = USR02-BNAME.
WRITE: / 'User', USR02-BNAME, LOCKSTRING, '.'.
ENDIF.

SAP ABAP/4 Program: Output Table Fields to a List

When you're looking at the structure of a table, SAP will let you print the structure, but it won't let you save the structure. This can be annoying. This report outputs the table structure to a list. At this point the user can use the System->List->Save->Local file command to save the list to a file.

Output Table Fields to a List


*&---------------------------------------------------------------------*
*& Report YTABFLDS *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT YTABFLDS .
TABLES: DD02L, DD03L, DD04T.

PARAMETERS THETABLE LIKE DD02L-TABNAME OBLIGATORY.
DATA: BEGIN OF MYTABLE,
TABNAME LIKE DD02L-TABNAME,
AS4LOCAL LIKE DD02L-AS4LOCAL,
AS4VERS LIKE DD02L-AS4VERS,
END OF MYTABLE.

SELECT SINGLE TABNAME AS4LOCAL AS4VERS INTO MYTABLE FROM DD03L
WHERE TABNAME = THETABLE.
WRITE: / MYTABLE-TABNAME, 11 MYTABLE-AS4LOCAL, 13 MYTABLE-AS4VERS.
SELECT * FROM DD03L
WHERE TABNAME = MYTABLE-TABNAME AND
AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS.
WRITE: / DD03L-FIELDNAME, 11 DD03L-KEYFLAG, 13 DD03L-ROLLNAME,
24 DD03L-CHECKTABLE, 35 DD03L-INTTYPE, 37 DD03L-REFTABLE,
48 DD03L-DATATYPE.
SELECT SINGLE * FROM DD04T
WHERE ROLLNAME = DD03L-ROLLNAME AND
AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS AND
DDLANGUAGE = 'E'.

WRITE: 53 DD04T-DDTEXT.
ENDSELECT.

SAP ABAP Program: Output of Date Format

Suppose a date is given in the format 20050428 how to get the output in the format 28th Apr 2005.

FORM set_text_date.

DATA: month(9),
year(4),
date(2).

CASE p_frd+4(2).

WHEN '01'.
month = 'January'.

WHEN '02'.
month = 'February'.

WHEN '03'.
month = 'March'.

WHEN '04'.
month = 'April'.

WHEN '05'.
month = 'May'.

WHEN '06'.
month = 'June'.

WHEN '07'.
month = 'July'.

WHEN '08'.
month = 'August'.

WHEN '09'.
month = 'September'.

WHEN '10'.
month = 'October'.

WHEN '11'.
month = 'November'.

WHEN '12'.
month = 'December'.

WHEN OTHERS.

ENDCASE.

WRITE p_frd+0(4) TO year.

WRITE p_frd+6(2) TO date.

CONCATENATE month date ',' year INTO return_date SEPARATED BY space.

CONDENSE return_date.

ENDFORM.

ABAP Tips by : Kiran

Currently my date is getting printed in format 05262005.
I want the output as 26 May, 2005.
I have tried using Set date mask option but it is not picking up in the output.

Code:

This code yields as 12 march 2006.

DATA: ZTEMP(9).

CLEAR: ZTEMP, ZDD, ZMMM, ZYYYY.

CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'
EXPORTING
INPUT = IS_DLV_DELNOTE-HD_GEN-CREA_DATE
IMPORTING
OUTPUT = ZTEMP.

ZDD = ZTEMP+3(2).
ZMMM = ZTEMP+0(3).
ZYYYY = ZTEMP+5(4).

free download book on abap programming Tutorial

free download book on abap programming Tutorial

SAP ABAP Programming Language

Typen und Objekte

This graphic is explained in the accompanying text




ABAP Syntax

Basic Statements

Processing Large Volumes of Data

Saving Data Externally

Modularization Techniques

Special Techniques

free download BC-ABA pdf book SAP ABAP prog

free download ABAP Programming (BC-ABA) pdf book

BC-ABA pdf free download SAP ABAP prog

ABAP Programming (BC-ABA)

SAP ABAP Sample Test Questions on Programming

#1. What are the 2 boxes in your system for coding for Abap and their logins?

Development System & IDES/Sandbox

# 2. If I get a problem on a report in Production server how can I modify the report.

If the problem in production server we have to alter the program in Developemnt Client and transport it to QA client Test it throughly and then Transport it to Production.

# 3. Tell me about Tokens.

Tokens are Issues sent by the Client to us.

#4 .How to Fix the bugs and where you will do those things.

It Actuall Depends what kind of bugs they asked about:
If it is a problem in Program, then we alter them in the SE38 (Develpment) and transport it after testing to Prd Server.

#5. What is a sandboxes.

SAND BOX is nothing but a test client other than Develpment Client or QA.

#6.How to conncet the from ur office to clinet in US.

It will be configured by the BASIS guys..

In the sap logon pad they will enter the application server id and Routing String and the SERver type in the Sytem Number....
with that we will connect

#7.Tell me about VPN and the connections.

Its a another way to connect to other PC. its a 3rd party utility....

#8. How to login ur system.

Thru SAP Logon enter the client number ,user id & password.

#9 .What is the purpose of SE14.

Database Utility to perform table maintenance such as deleting the table or adjusting the table when there is a structure change.

#10 .What is the purpose of SM30.

SM30 is a table Maintanance for the Ztable Created by us.

#11.In Data dictionary in the table creation,What is the purpose of Technical settings.

To identify the Size of the Table Created and to Set whether buffering needs to be done for the table or not.

#12. What is the purpose of buffering in technical settings and for what type of tables are using buffering.

It will reduce the Network tarffic but disadvantage is it will not update the Server back immediately.

#13. In reporting tell me all the events in a sequentail order.

- Initialization.
- At Selection-Screen
- Start-of-Selection.
- Top-of-Page.
- At Pfn.
- End-of-Page.
- End-of-Selection.

SAP ABAP Programming Documentation

This documentation describes how to write application programs within the three-tier client/server architecture of the R/3 System.

This graphic is explained in the accompanying text

R/3 applications are written in the ABAP programming language, and run within the application layer of the R/3 System.

ABAP programs communicate with the database management system of the central relational database (RDBMS), and with the graphical user interface (SAPgui) at presentation level.

Contents

The documentation is divided into five sections:

Introduction to ABAP

This contains the basics of application programming in the R/3 System. This information is essential for an understanding of ABAP programming. Following an overview of the R/3 Basis system, it introduces the essential features of application programs and the ABAP programming language. Finally, it gives a short introduction to how you can create an application program in the ABAP Workbench.

The ABAP Programming Language

This section describes the statements in the ABAP programming language. Beginning with simple statements for data declarations, data processing, and program flow control, it progresses to topics such as modularization and special techniques, explaining which ABAP statements can be used for which purposes.

ABAP User Dialogs

The different screens that can belong to ABAP programs are displayed here. This shows how you can program and control interaction between ABAP programs and users in the form of screens.

Running ABAP Programs

This section explains how ABAP programs are executed in the R/3 System. It shows how you can start programs, the conditions under which you must start them, and the different kinds of program execution.

ABAP Database Access

This section explains how to work with the database in the R/3 System. It describes the parts of the programming language that are converted into SQL statements in the database, and shows how you can program database updates.

ABAP Objects

This is an introduction to ABAP Objects, the object-oriented extension of ABAP. Objects, classes and interfaces are introduced as the basic elements of ABAP objects. It shows how classes can be defined independently using interfaces or inheritance. It then goes on to introduce further components of classes, namely methods and events.

ABAP and JavaScript

The section describes how to link JavaScript programs in ABAP using class CL_JAVA_SCRIPT.

Appendix

The appendix contains summary descriptions and overviews, including a list of all system fields, an ABAP statement reference and a glossary.

Sample Programs

Note that the sample programs in this documentation can be used for testing purposes in every R/3 System starting with Release 4.5. They can be found in Transaction ABAPDOCU . The program structure corresponds to that of this documentation.

Further Reading

SAP Style Guide

Structure link Changing the SAP Standard

Structure link ABAP Workbench: Tools

Structure link ABAP Dictionary

Structure link Remote Communications

Structure link RFC Programming in ABAP

Structure link ABAP as an OLE Automation Controller

Structure link Basis Programming Interfaces

Structure link ABAP Query

SAP ABAP free download abap programming pdf book

free download abap programmin pdf book

SAP ABAP The Employee Example - step by step example

1. Simple class

This example shows how to create a simple employee class. The constructor method is used to initialize number and name of thje employee when the object is created. A display_employee method can be called to show the attributes of the employee, and CLASS-METHOD dosplay_no_of_employees can be called to show the total number of employees (Number of instances of the employee class).

REPORT zbc404_hf_events_1.
*********************************************************************
* L C L _ E M P L O Y E E
*********************************************************************
*---- LCL Employee - Definition
CLASS lcl_employee DEFINITION.
PUBLIC SECTION.
*--------------------------------------------------------------------
* The public section is accesible from outside
*--------------------------------------------------------------------
    TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
END OF t_employee.
    METHODS:
constructor
IMPORTING im_employee_no TYPE i
im_employee_name TYPE string,
      display_employee.
*   Class methods are global for all instances       
CLASS-METHODS: display_no_of_employees.
  PROTECTED SECTION.
*--------------------------------------------------------------------
* The protecetd section is accesible from the class and its subclasses
*--------------------------------------------------------------------
*   Class data are global for all instances     
CLASS-DATA: g_no_of_employees TYPE i.
  PRIVATE SECTION.
*--------------------------------------------------------------------
* The private section is only accesible from within the classs
*--------------------------------------------------------------------
DATA: g_employee TYPE t_employee.
ENDCLASS.
*--- LCL Employee - Implementation
CLASS lcl_employee IMPLEMENTATION.
METHOD constructor.
g_employee-no = im_employee_no.
g_employee-name = im_employee_name.
g_no_of_employees = g_no_of_employees + 1.
ENDMETHOD.
  METHOD display_employee.
WRITE:/ 'Employee', g_employee-no, g_employee-name.
ENDMETHOD.
  METHOD display_no_of_employees.
WRITE: / 'Number of employees is:', g_no_of_employees.
ENDMETHOD.
ENDCLASS.
************************************************************************
* R E P O R T
*********************************************************************
DATA: g_employee1 TYPE REF TO lcl_employee,
g_employee2 TYPE REF TO lcl_employee.
START-OF-SELECTION.
CREATE OBJECT g_employee1
EXPORTING im_employee_no = 1
im_employee_name = 'John Jones'.
  CREATE OBJECT g_employee2
EXPORTING im_employee_no = 2
im_employee_name = 'Sally Summer'.
  CALL METHOD g_employee1->display_employee.
CALL METHOD g_employee2->display_employee.
  CALL METHOD g_employee2->display_no_of_employees.

2. Inheritance and polymorphism

This example uses a superclass lcl_company_employees and two subclasses lcl_bluecollar_employee and lcl_whitecollar_employee to add employees to a list and then display a list of employees and there wages. The wages are calcukated in the method add_employee, but as the wages are calculated differently for blue collar employees and white collar emplyees, the superclass method add_employee is redeifined in the subclasses.

Principles:

Create super class LCL_CompanyEmployees.

The class has the methods:

  • Constructor
  • Add_Employee - Adds a new employee to the list of employees
  • Display_Employee_List - Displays all employees and there wage
  • Display_no_of_employees - Displays total number of employees

Note the use of CLASS-DATA to keep the list of employees and number of employees the same from instance to instance.

Create subclasses lcl_bluecollar_employee and lcl_whitecollar_employee. The calsses are identical, except for the redifinition of the add_employee method, where the caclculation of wage is different.

Methodes:

  • Constructor. The constructor is used to initialize the attributes of the employee. Note that the constructor in the supclasss has to be called from within the constructor of the subclass.
  • Add_Employee. This is a redinition of the same method in the superclass. In the redefined class the wage is calcuated, and the superclass method is called to add the employees to the emploee list.:

The program

REPORT zbc404_hf_events_2 .
*******************************************************
* Super class LCL_CompanyEmployees
*******************************************************
CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
    METHODS:
constructor,
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i,
      display_employee_list,
display_no_of_employees.

PRIVATE SECTION.
CLASS-DATA: i_employee_list TYPE TABLE OF t_employee,
no_of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATION
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
  METHOD add_employee.
* Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
ENDMETHOD.
  METHOD display_employee_list.
* Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
    LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
  ENDMETHOD.
  METHOD display_no_of_employees.
* Displays total number of employees
SKIP 3.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_BlueCollar_Employee
*******************************************************
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.

PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_hours TYPE i
im_hourly_payment TYPE i,
add_employee REDEFINITION.
  PRIVATE SECTION.
DATA:no TYPE i,
name TYPE string,
hours TYPE i,
hourly_payment TYPE i.

ENDCLASS.
*---- CLASS LCL_BlueCollar_Employee IMPLEMENTATION
CLASS lcl_bluecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method

CALL METHOD super->constructor.
no = im_no.
name = im_name.
hours = im_hours.
hourly_payment = im_hourly_payment.
  ENDMETHOD.
  METHOD add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list

DATA: l_wage TYPE i.
l_wage = hours * hourly_payment.
    CALL METHOD super->add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_WhiteCollar_Employee
*******************************************************

CLASS lcl_whitecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.

PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_monthly_salary TYPE i
im_monthly_deductions TYPE i,
add_employee REDEFINITION.
  PRIVATE SECTION.
DATA:
no TYPE i,
name TYPE string,
monthly_salary TYPE i,
monthly_deductions TYPE i.
ENDCLASS.
*---- CLASS LCL_WhiteCollar_Employee IMPLEMENTATION
CLASS lcl_whitecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
monthly_salary = im_monthly_salary.
monthly_deductions = im_monthly_deductions.
ENDMETHOD.
  METHOD add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list

DATA: l_wage TYPE i.
l_wage = monthly_salary - monthly_deductions.
    CALL METHOD super->add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
  ENDMETHOD.
ENDCLASS.
*******************************************************
* R E P O R T
*******************************************************

DATA:
* Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
* Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_hours = 38
im_hourly_payment = 75.
* Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
* Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->add_employee
EXPORTING im_no = 1
im_name = 'Karen Johnson'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
  CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.

The resulting report

List of Employees
1 Karen Johnson 2.850
2 John Dickens 7.500


Total number of employees: 2
3. Interfaces

This example is similiar to th eprevious example, however an interface is implemented with the method add_employee. Note that the interface is only implemented in the superclass ( The INTERFACE stament), but also used in the subclasses.

The interface in the example only contains a method, but an iterface can also contain attrbutes, constants, types and alias names.

The output from example 3 is similiar to the output in example 2.

All changes in the program compared to example 2 are marked with red.

REPORT zbc404_hf_events_3 .
*---------------------------------------------------------------------*
* INTERFACE lif_employee
*---------------------------------------------------------------------*
INTERFACE lif_employee.
METHODS:
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i.
ENDINTERFACE.
*******************************************************
* Super class LCL_CompanyEmployees
*******************************************************
CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
INTERFACES lif_employee.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
    METHODS:
constructor,
* add_employee "Removed
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i,
      display_employee_list,
display_no_of_employees.

PRIVATE SECTION.
CLASS-DATA: i_employee_list TYPE TABLE OF t_employee,
no_of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATION
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
  METHOD lif_employee~add_employee.
* Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
ENDMETHOD.
  METHOD display_employee_list.
* Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
    LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
  ENDMETHOD.
  METHOD display_no_of_employees.
* Displays total number of employees
SKIP 3.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_BlueCollar_Employee
*******************************************************
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.

PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_hours TYPE i
im_hourly_payment TYPE i,
lif_employee~add_employee REDEFINITION..
  PRIVATE SECTION.
DATA:no TYPE i,
name TYPE string,
hours TYPE i,
hourly_payment TYPE i.

ENDCLASS.
*---- CLASS LCL_BlueCollar_Employee IMPLEMENTATION
CLASS lcl_bluecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method

CALL METHOD super->constructor.
no = im_no.
name = im_name.
hours = im_hours.
hourly_payment = im_hourly_payment.
  ENDMETHOD.
  METHOD lif_employee~add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list

DATA: l_wage TYPE i.
l_wage = hours * hourly_payment.
    CALL METHOD super->lif_employee~add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_WhiteCollar_Employee
*******************************************************

CLASS lcl_whitecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.

PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_monthly_salary TYPE i
im_monthly_deductions TYPE i,
lif_employee~add_employee REDEFINITION.
  PRIVATE SECTION.
DATA:
no TYPE i,
name TYPE string,
monthly_salary TYPE i,
monthly_deductions TYPE i.
ENDCLASS.
*---- CLASS LCL_WhiteCollar_Employee IMPLEMENTATION
CLASS lcl_whitecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
monthly_salary = im_monthly_salary.
monthly_deductions = im_monthly_deductions.
ENDMETHOD.
  METHOD lif_employee~add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list

DATA: l_wage TYPE i.
l_wage = monthly_salary - monthly_deductions.
    CALL METHOD super->lif_employee~add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
  ENDMETHOD.
ENDCLASS.
*******************************************************
* R E P O R T
*******************************************************

DATA:
* Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
* Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_hours = 38
im_hourly_payment = 75.
* Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Karen Johnson'
im_wage = 0.
* Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
* Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
  CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.

4. Events

This is the same example as example 4. All changes are marked with red. There have been no canges to the subclasses, only to the superclass and the report, sp the code for th esubclasses is not shown.

For a simple example refer to Events in Examples.

REPORT zbc404_hf_events_4 .
*---------------------------------------------------------------------*
* INTERFACE lif_employee
*---------------------------------------------------------------------*

INTERFACE lif_employee.
  METHODS:
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i.
ENDINTERFACE.
*******************************************************
* Super class LCL_CompanyEmployees
*******************************************************

CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
*   Declare event. Note that declaration could also be placed in the
* interface

EVENTS: employee_added_to_list
EXPORTING value(ex_employee_name) TYPE string.
* CLASS-EVENTS: Events can also be defined as class-events
    INTERFACES lif_employee.
METHODS:
constructor,
display_employee_list,
display_no_of_employees,
*     Declare event method
on_employee_added_to_list FOR EVENT employee_added_to_list OF lcl_company_employees
IMPORTING ex_employee_name sender.
  PRIVATE SECTION.
CLASS-DATA:
i_employee_list TYPE TABLE OF t_employee,
no_of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATION
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
  METHOD lif_employee~add_employee.
* Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
*   Raise event employee_added_to_list
RAISE EVENT employee_added_to_list
EXPORTING ex_employee_name = l_employee-name.
  ENDMETHOD.
  METHOD display_employee_list.
* Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
    LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
  ENDMETHOD.
  METHOD display_no_of_employees.
* Displays total number of employees
SKIP 3.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
  METHOD on_employee_added_to_list.
* Event method
WRITE: / 'Employee added to list', ex_employee_name.
ENDMETHOD.
ENDCLASS. 
*******************************************************
* Sub class LCL_BlueCollar_Employee
*******************************************************
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
See code in example 3...
ENDCLASS.
CLASS lcl_bluecollar_employee IMPLEMENTATION.
See code in example 3...
ENDCLASS.
*******************************************************
* Sub class LCL_WhiteCollar_Employee
*******************************************************
CLASS lcl_whitecollar_employee DEFINITION
See code in example 3...
ENDCLASS.
CLASS lcl_whitecollar_employee IMPLEMENTATION.
See code in example 3...
ENDCLASS.
*******************************************************
* R E P O R T
*******************************************************

DATA:
* Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
* Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Karen Johnson'
im_hours = 38
im_hourly_payment = 75.
* Register event for o_bluecollar_employee1
SET HANDLER o_bluecollar_employee1->on_employee_added_to_list
FOR o_bluecollar_employee1.
* Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
* Register event for o_whitecollar_employee1
SET HANDLER o_whitecollar_employee1->on_employee_added_to_list
FOR o_whitecollar_employee1.´

* Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.

Result:


Employee added to list Karen Johnson
Employee added to list John Dickens
List of Employees
1 Karen Johnson 2.850
2 John Dickens 7.500

Total number of employees: 2

Archives