Вы находитесь на странице: 1из 225

BC670 Programming Display Functions BC670

46D 25.07.2003

0
BC670 Programming Display Functions

BC670
Programming Display Functions
SAP AG 2002

The R/3 System Release 4.6C 2001, Q3 Mat. No.: 50041363

0.2
Copyright

Copyright 2002 SAP AG. . , , SAP AG . , , .

SAP AG 2002

: , SAP AG , , . Microsoft, WINDOWS, NT, EXCEL, Word, PowerPoint SQL Server Microsoft Corporation. IBM, DB2, OS/2, DB2/6000, Parallel Sysplex, MVS/ESA, RS/6000, AIX, S/390, AS/400, OS/390 OS/400 IBM Corporation. ORACLE ORACLE Corporation. INFORMIX-OnLine for SAP INFORMIX Dynamic ServerTM Informix Software Incorporated. UNIX, X/Open, OSF/1 Motif Open Group. HTML, DHTML, XML, XHTML W3C, World Wide Web Consortium, Massachusetts Institute of Technology. JAVA Sun Microsystems, Inc. JAVASCRIPT Sun Microsystems, Inc., , Netscape. SAP, SAP Logo, R/2, RIVA, R/3, ABAP, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP.com Logo mySAP.com SAP AG . .

0.3
- I
2
BC600 2 SAP Business Workflow - BC601 5 days SAP Business Workflow

3
BC610 3 SAP Business Workflow

BC615 SAP ArchiveLink BC660

3 BC670 2 ADK - BC680 2 (DART)

BIT530

2 Web-

SAP Business Connector

SAP AG 2002

0.4
- II
2
BC619 3 Application Link Enabling (ALE) BC620 2 SAP Idoc BC095 3 CA210 EDI- 4 BC621 1 SAP Idoc
*BC619 01/2002 BIT300 *BC620 01/2002 BIT320 *BC621 04/2002 BIT350

BC420

5 BC415 2 ABAP *CA926 5 BAPI: JAVA

*CA925 5 BAPI: Visual Basic


*CA925 01/2002 BIT525 *CA926 01/2002 BIT526

SAP AG 2002

0.5
Course Prerequisites

BC400 BC405 BC410 BC660 or equivalent knowledge of SAP Data Archiving

SAP AG 2002

0.6
Target Group

Participants:

Members of data archiving project teams, who have to program customer-specific retrieval solutions

Duration: 2 days

SAP AG 2002

1
Course Overview

Contents:
Course Goals Course Objectives Course Content Course Overview Diagram Main Business Scenario

SAP AG 2002

(C) SAP AG

BC670

1.2
Course Goals

This course will prepare you to:


Understand the logic of archiving and delete

programs
Create customer-specific sequential read

programs
Program business views of an archiving object in

SAP AS
Display in SAP AS original documents belonging

to an R/3 business object that have been archived using SAP ARCHIVELINK

SAP AG 2002

(C) SAP AG

BC670

1.3
Course Objectives

At the conclusion of this course, you will be able to:


Create customer-specific read programs Create business views in SAP AS Explain the procedure required to empty

customer-specific tables using customer-specific archiving objects


Explain the procedure required to extend existing

archiving objects to archive customer-specific tables

SAP AG 2002

(C) SAP AG

BC670

1.4
Course Content

Preface Unit 1 Unit 2 Unit 3 Course Overview Process of Data Archiving ADK Development Tools Unit 5 Unit 6 Unit 4 Program logic Data Archiving Sequential read progams Direct read access to archived data

SAP AG 2002

(C) SAP AG

BC670

1.5
Overview Diagram

Introduction The Data Archiving Process ADK Development Tools Program Logic in Data Archiving Sequential Read Programs Direct Access to Archived Data in SAP AS

START

SAP AG 2002

(C) SAP AG

BC670

1.6
Main Business Scenario

You work in the large enterprise TablesRUs. A large data

archiving project has been installed and you are a member of the project team. Together with the user departments, you have created a requirements catalog.
Customer-specific read programs must be written. Business views must be created in SAP AS.

SAP AG 2002

(C) SAP AG

BC670

2
The Process of Data Archiving

Contents
The Process of Data Archiving Data Object and Archiving Object Access to Archived Data

SAP AG 2002

(C) SAP AG

BC670

2.2
Data Archiving Topic Objectives

At the conclusion of this unit, you will be able to: Describe the process of Data Archiving Explain the relevant components

SAPAG 1999 S P AG 2002

(C) SAP AG

BC670

2.3
Course Overview Diagram

Course Overview The Process of Data Archiving ADK Development Tools Program Logic in Data Archiving Customer-Specific Read Programs Business Views in SAP AS Appendix

SAP AG 2002

(C) SAP AG

BC670

2.4
Data Archiving: Business Scenario

The user department, IT department, and the project team meet to discuss the existing data archiving solution within their enterprise. They also list the options in the standard SAP System for accessing archived data.

SAPAG 1999 S P AG 2002

(C) SAP AG

BC670

2.5
The Archiving Process

R/3 Database

File system

Offline storage

R/3 Database
Documents/ Data objects Archiving object Archive files

Data archiving session


SAP AG 2002

optional / manual

R/3 documents are made up of records, which are stored in different tables in the R/3 database. For the purposes of data archiving, a concrete R/3 document is a data object. The data archiving process is composed of two steps. Creation of archive files - The archiving program writes the files for archiving from the R/3 database to archive files. Deletion of data - The delete program first reads the data in the archive files and then deletes the records from the database. The removal of archive files to a tertiary storage medium can be seen as a third step in the archiving process. This step occurs after the first two steps of the data archiving procedure have been completed. You should consider this third step to be part of the archiving process: It is not generally enough to write the data to be archived to archive files and delete it from the database. The archive files must be stored and managed to guarantee future access when required.

(C) SAP AG

BC670

2.6
Data Objects in R/3

R/3 database tables

R/3 business documents

Table BKPF

001 1000 1900000 1999 KR 1.2.99 5.2.99 ... 001 1000 1900001 1999 KR 1.2.99 5.2.99 ... 001 1000 1900002 1999 KR 1.2.99 5.2.99 ... ...... 001 1000 1900000 1999 50 02 157,60 134,50 001 1000 1900001 1999 50 02 45,30 33,70 001 1000 1900002 1999 50 02 230,00 200,40 ...... 001 1000 1900000 1999 001 A1 175000 01 H 001 1000 1900001 1999 001 A2 175000 02 H 001 1000 1900002 1999 001 A0 400000 01 H ......

1000 1900000 1999

Table BSEG

1000 1900001 1999

1000 1900002 1999 ......

Table BSET

........

unique key

SAP AG 2002

R/3 business documents are distributed across different tables in the R/3 database. The FI document 1000 1900000 1999 represents a concrete data object in R/3. Within the data archiving framework, all table records belonging to a data object are written together (in context) to an archive file and then deleted from the database tables.

(C) SAP AG

BC670

2.7
Archiving Objects (1)

Structure description Table BKPF

The STRUKTURE DEFINITION of an archiving object describes which tables are to be processed during data archiving

Structure description Table BSET

Structure description Table BSEG

Archiving object FI_DOCUMNT

Structure description Table BVOR

Structure description Table BSEC

An ARCHIVING OBJECT is a set of linked business data, which is periodically extracted from the database, archived, and deleted according to individual criteria from the current system.

.........
SAP AG 2002

Additional examples of archiving objects: SD_VBAK SD_VBKA RV_LIKP PP_ORDER Data structure Orders Data structure Sales activities Data structure Deliveries Data structure Production orders

R/3 Release 4.6 contains more than 200 standard archiving objects. Archiving objects are defined by the individual applications. You can create customer-specific archiving objects for customer-specific Z and Y tables.

(C) SAP AG

BC670

2.8
Archiving Objects (2)

Archiving objects FI_DOCUMNT SD_VBAK SD_VBKA SD_VBRK RV_LIKP CO_ITEM AM_ASSET MM_EBAN MM_EKKO IDOC WORKITEM PS_PLAN CO_ORDER ......

Structure definition Information about the points listed on the right is stored in the system for every archiving object Transaction AOBJ Additional flags (for example start at end) Programs for archiving and deletion Customizing technical settings Customizing residence times/application Archiving classes used Read programs

SAP AG 2002

An archiving object must have programs for archiving and deleting. Optional programs include programs for reloading, reporting, filling and emptying indexes, preprocessing and postprocessing. The maintenance transaction is AOBJ. 'Start at end' is an example of an additional indicator that is analyzed after after an archiving session when the deletion job is run. A further indicator enables you to specify whether an index can be created. Application-specific Customizing generally contains criteria to determine whether documents are archivable or not. In addition to these criteria, a document must always have the status 'closed' before it can be archivable.

(C) SAP AG

BC670

2.9
Archiving: Step 1 - Data Archiving

R/3 Database

Archiving program

Archive file

SAP AG 2002

During the first step, the archiving program creates an (initial) archive file. The data to be archived is read from the database by a batch process and written to the archive file. This process continues until one of the following occurs:

1. The archiving is finished: All the data for selection has been read and written 2. The archiving is not yet completed but the archive file has reached the maximum size that was specified in Customizing. 3. The archiving is not yet completed but the archive file contains the specified number of objects that was specified in Customizing. Only data from completed business processes is archivable. Master data can only be archived if a deletion indicator has been set in it. Some archiving objects set the deletion indicator in a specific preprocessing program within the framework of data archiving (for example, the archiving object CO_ORDER).

(C) SAP AG

BC670

2.10 Archiving: Step 2 - Data Deletion Variant 1: Deletion Jobs Parallel to Archiving
Deletion jobs start automatically after an archive file has been closed Prerequisite: Start automat. is selected in technical Customizing for the archiving object

R/3 Database

Archiving program

Delete program Delete program


SAP AG 2002

Archive file Archive file

Archive file

There is one deletion process for each archive file created. The deletion process can be started in three different ways. Variant 1 for starting the delete program: After closing an archive file, ADK opens a new one and continues with the archiving process. The system starts the delete program in parallel, which reads the archived records from the file which has just been closed and deletes them from the database. In this case, the delete jobs and the archiving jobs run in parallel. For this variant, 'Start automatic.' must be set in 'Delete program settings' in technical Customizing of the archiving object.

(C) SAP AG

BC670

10

2.11 Archiving: Step 2 - Data Deletion Variant 2: Delete Jobs Started Manually

Administrator starts the deletion jobs MANUALLY in the data archiving transaction after the archiving session is finished

Prerequisite: Start automat. is not selected in technical Customizing for the archiving object

R/3 Database

Delete program Delete program


SAP AG 2002

Archive Archive file file

Variant 2 for starting the delete program: The delete program is scheduled manually by the administrator once all archive files have been closed. The archiving session is completely finished. There is one deletion process for each archive file created. For this variant, the 'Start at end' indicator is set in the definition of the archiving object. 'Start automatic.' must NOT be set in 'Delete program settings' in the technical Customizing of the archiving object.

(C) SAP AG

BC670

11

2.12 Archiving: Step 2 - Data Deletion Variant 3: Delete Jobs Started Automatically
Delete jobs started AUTOMATICALLY after the archiving session has finished Prerequisite: start at end is set in the definition of the archiving object

R/3 Database

Delete program Delete program

Archive file Archive file

SAP AG 2002

Variant 3 for starting the delete program: The delete program is scheduled manually by the administrator once all archive files have been closed. The archiving session is completely finished. There is one deletion process for each archive file created. For this variant, the 'Start at end' indicator is set in the definition of the archiving object. 'Start automatic.' must NOT be set in 'Delete program settings' in the technical Customizing of the archiving object. Once an indicator has been set in an archiving object, it can not be removed.

(C) SAP AG

BC670

12

2.13
Archiving: Step 3 - Tertiary Storage Media

External storage system

R/3 Database

Archive file Archive file Archive file Archive file Archive file

addressed via SAP ArchiveLink HSM systems File system available only to ADK

Create archive file Delete data Final storage location of archive files

SAP AG 2002

There are various ways to store and administer archive files on external storage media. Archive management always knows the exact location of an archive file. Read/write authorizations are mandatory at UNIX-level for the directories used. Connection to a Hierarchical Storage Management system (HSM): An HSM system simulates an 'infinitely large' file system. The archive files created during an archiving session are stored in the HSM file system. You just have to enter the HSM file system path in archiving object Customizing as the target path for the archive files. Connection to an external archive system via SAP ArchiveLink: If you want to store the archive files on an external storage system via SAP ArchiveLink, the archive files can only be passed to the thirdparty product archive after the data has been successfully deleted from the database. Manual administration: If you do not want to store the archive files on an external archive or in an HSM System, then the IT department can administer the files on tapes or CDs. There is no interface to these files from SAP R/3. Ensure that backup strategies are in place for the relevant storage medium. It may also be necessary to make new copies of the contents of CDs or WORMs after a number of years.

(C) SAP AG

BC670

13

2.14
Archiving Process: Summary

You now know: The steps of the archiving process


Writing data to archive files Deleting data from database Final storage of archive files on tertiary storage media

That archiving objects are the central components of data archiving

SAP AG 2002

(C) SAP AG

BC670

14

2.15Data Archiving and Working with Archived Data Exercises Unit: Data Archiving and Working with Archived Data Topic The Process of Data Archiving Access using SAP AS

At the conclusion of this exercise, you will be able to: Carry out the Customizing required to start the delete jobs Explain the relationship between data objects and archiving objects Create an archive information structure that links 2 tables

1-1

Control the delete job 1-1-1 Which Customizing setting must you implement to prevent the delete jobs from starting immediately so that you can schedule them manually? 1-1-2 Which setting leads to them starting immediately after an archive file has been closed? 1-1-3 Which setting enables you to start the delete jobs automatically after the complete archiving session is finished and all of the archive files have been closed?

1-2

Data Object and Archiving Object 1-2-1 What is a data object? 1-2-2 Where is the definition (within the context of data archiving) of a data object stored?

(C) SAP AG

BC670

15

2.16Data Archiving and Working with Archived Data: Solutions

Unit: Data Archiving and Working with Archived Data Topic The Process of Data Archiving Access using SAP AS

1-1

Solution to question 1-1 1-1-1 Tools, Administration, Management, Data Archiving Enter the archiving object Button <Customizing> Select Technical Settings Settings for delete program: Start autom should not be selected. 1-1-2 Tools, Administration, Management, Data Archiving Enter the archiving object Button <Customizing> Select Technical Settings Settings for delete program: Start autom should be selected. 1-1-3 Call transaction AOBJ Double click the archiving object Select start at end

1-2

Solution to question 1-2 1-2-1 Data object From the ADKs viewpoint, a data object is made up of all of the table records that make up an R/3 business document. 1-2-2 Call transaction AOBJ Select the archiving object Select dialog structure structure definition

(C) SAP AG

BC670

16

3
ADK Development Tools

Contents:
Overview of the ADK programming interface Overview of archiving classes

SAP AG 2002

(C) SAP AG

BC670

3.2
ADK Development Tools: Topic Objectives

At the conclusion of this unit, you will be able to: List the component parts of the ADK programming interface Understand the use and application of archiving classes

SAP AG 1999 2002

(C) SAP AG

BC670

3.3
Course Overview Diagram

Course Overview The Data Archiving Process ADK Development Tools Data Archiving Programming Logic Customer-Specific Read Programs Business Views in SAP AS Appendix

SAP AG 2002

(C) SAP AG

BC670

3.4
ADK Development Tools: Business Scenario

Before work can begin, the developers must have an overview of the ADK programming interface.

SAP AG 1999 2002

(C) SAP AG

BC670

3.5
ADK Programming Interface - ADK API

ADK includes a series of function modules that are are used by all programs on a cross-application basis during data archiving These function modules write data to and read data from archive files. The selection of data for archiving or deletion (that is, database access) must be defined in archiving and deletion programs in the relevant application.

SAP AG 2002

As well as reading and writing data, ADK also undertakes conversion tasks within the framework of data archiving, for example: Codepage changes (for example, HP/UX to AS/400) Format conversion (for example, Compaq/Alpha to HP/UX) Structure changes (for example, additional table fields) Data compression and decompression Since Release 3.0, ADK is the only means of archiving data from R/3 database tables. Archived data from Releases 2.1 and 2.2 are readable.

(C) SAP AG

BC670

3.6
ADK API - Function Group ARCH (1)

ARCHIVE_CLOSE_FILE
ARCHIVE_GET_INFORMATION ARCHIVE_GET_NEXT_OBJECT ARCHIVE_GET_NEXT_RECORD ARCHIVE_GET_NEXT_STRUCT_SPECIF ARCHIVE_GET_OPEN_FILES ARCHIVE_GET_RECORD_INFO ARCHIVE_GET_STATISTICS ARCHIVE_GET_TABLE ARCHIVE_GET_WITH_CURSOR

ADK function modules used in write programs

ARCHIVE_NEW_OBJECT
ARCHIVE_OPEN_FOR_CONVERSION ARCHIVE_OPEN_FOR_DELETE ARCHIVE_OPEN_FOR_MOVE ARCHIVE_OPEN_FOR_READ

ARCHIVE_OPEN_FOR_WRITE
ARCHIVE_POPUP_CUSTOMIZING_DATA

ARCHIVE_PUT_RECORD ARCHIVE_PUT_TABLE
ARCHIVE_READ_OBJECT ARCHIVE_REGISTER_CLASS ARCHIVE_RELOAD_OBJECT_DATA ARCHIVE_ROLLBACK_WORK

ARCHIVE_SAVE_OBJECT
ARCHIVE_SET_RECORD_CURSOR

ARCHIVE_WRITE_STATISTICS

SAP AG 2002

The function group ARCH includes the function modules for access to ADK archive files. The function group AADM contains function modules for managing ADK archive files. The group ARCH is essential for customer developments. Archiving programs are created by the respective applications. The application programs selection and check logic. The application uses the function modules listed above as the interface to ADK.

(C) SAP AG

BC670

3.7
ADK API - Function Group ARCH (2)

ARCHIVE_CLOSE_FILE
ARCHIVE_GET_INFORMATION ARCHIVE_GET_NEXT_OBJECT

ARCHIVE_DELETE_OBJECT_DATA
ADK function modules used in delete programs
ARCHIVE_GET_NEXT_RECORD ARCHIVE_GET_NEXT_STRUCT_SPECIF

ARCHIVE_GET_CUSTOMIZING_DATA
ARCHIVE_GET_OPEN_FILES ARCHIVE_GET_RECORD_INFO ARCHIVE_GET_STATISTICS ARCHIVE_GET_TABLE ARCHIVE_GET_WITH_CURSOR

ARCHIVE_GET_NEXT_OBJECT ARCHIVE_GET_NEXT_RECORD ARCHIVE_GIVE_STATISTICS


ARCHIVE_OPEN_FOR_CONVERSION

ARCHIVE_OPEN_FOR_DELETE
ARCHIVE_OPEN_FOR_MOVE ARCHIVE_OPEN_FOR_READ ARCHIVE_POPUP_CUSTOMIZING_DATA ARCHIVE_READ_OBJECT ARCHIVE_REGISTER_CLASS ARCHIVE_RELOAD_OBJECT_DATA ARCHIVE_ROLLBACK_WORK ARCHIVE_SET_RECORD_CURSOR

ARCHIVE_WRITE_STATISTICS
SAP AG 2002

Delete programs are created by the relevant applications. The application uses the function modules listed above as the interface to ADK.

(C) SAP AG

BC670

3.8
Where Can You Find the ADK API in R/3?

Function modules (for ADK processing) that are released for customers are located in the function group ARCH Path: Tools -> ABAP Workbench -> Overview -> Object Navigator -> Function Group ARCH Display the function group Expand the function modules

SAP AG 2002

Documentation on ADK can be found under: BA-ABAP Workbench - BC Extended functin library - Archiving

(C) SAP AG

BC670

3.9
Archiving Classes (1)
Data is archived using an archiving object
1000 19000000 1994 1000 19000001 1994 1000 19000002 1994 1000 19000003 1994 . . . . . . . . . . . . . . . . 1000 19999999 1994

Data is archived using an archiving class


Change1 1994 to 1000 19000001 1994 Change2 1994 to 1000 19000001 1994 Change1 1994 to 1000 19999999 1994 Change1 1994 to 4500000552 1994 Change1 1994 to 1000 19000003 1994 Change1 1994 to 4500000554 1994 Change1 1994 to 4500000551 1994 ........

Data is archived using an archiving object


4500000551 1994 4500000552 1994 4500000553 1994 4500000554 1994 . . . . . . . . . . . . . . . . 4500000999 1994

Table BKPF
SAP AG 2002

Archiving class change documents Table CDHDR

Table VBAK

Use of archiving classes: Within the framework of FI- and SD-document archiving, the function modules for archiving the change document tables are called, and the change documents belonging to the relevant R/3 business objects are stored together with them in the archive file. Archiving classes collect change documents. The archiving class Changedocu archives not only from CDHDR, but also from the second table CDPOS. Data from archiving classes can only be accessed with the function modules belonging to the archiving class itself. These function modules, which are tailored specifically to suit the archiving class data, are developed by the relevant applications. Data that is stored using archiving classes is not transparent for ADK. ADK cannot interpret data. It reads archived data by using an application-specific function module.

(C) SAP AG

BC670

3.10
Archiving Classes (2)

Archiving classes

Function modules and form routines belonging to a business object which is not usually archived on its own, but which is used and archived more than once as a service function within the system. Examples of archiving classes: SAPscript texts Change documents Variant configurations SAP ArchiveLink entries IDOCs Work items HR time data HR travel data CO settlement documents ......

SAP AG 2002 1999

Release 4.6 contains 57 archiving classes. Archiving classes are maintained in transaction ACLA. Class-specific function modules are useful for customer-specific function modules that are required to read data from archiving classes. Form routines are important for the communication between ADK and archiving classes.

(C) SAP AG

BC670

10

3.11
Archiving Classes (3)

Use of Archiving Classes

Archiving classes process complex, cross-archiving object, logical data objects. Data structures are used and archived by various applications.

Archiving classes are created by the responsible persons from the development area

SAP AG 2002

Note: Archiving classes are not developed in the ADK develoment environment, which is released to customers.

(C) SAP AG

BC670

11

3.12
Archiving Classes (4)

Advantages of archiving classes


Reusability without additional workload New archiving classes can be used easilyto extend archiving objects View of the object and not its physical data Retention of data integrity Contain archiving data and archiving methods Central implementation of archiving functionality

SAP AG 2002

Archiving classes reflect an object-oriented approach and encapsulate the methods for accessing data. Because of the data encapsulation, the calling program no longer has to know the specific data structures and heirarchies. By using archiving classes, you can easily archive and read data for which you have no detailed knowledge.

(C) SAP AG

BC670

12

3.13
ADK API: Conclusion

You now know: The scope of the ADK programming interface which is released to customers Archiving classes provide the means to reduce the size of tables which are simultaneously filled by different applications

SAP AG 2002

(C) SAP AG

BC670

13

3.14ADK development tools Exercises Unit: ADK development tools Topic: Assign ADK function modules Assign archiving classes

At the conclusion of this unit, you will be able to: find and assign ADK function modules within the system explain the reason for archiving classes assign the archiving classes used

1-1

ADK function modules 1-1-1 Which function groups contain function modules released for customers? 1-1-2 Take a look at the function modules. 1-1-3 Which are used for deletion, which for archiving?

1-2

Archiving classes 1-2-1 Why were archiving classes developed? Which data is archived/deleted with them? 1-2-2 Who creates archiving classes? Are customers allowed to create archiving classes? 1-2-3 Which archiving classes are used by the archiving object SD_VBKA?

(C) SAP AG

BC670

14

3.15ADK Development Tools Solutions Unit: ADK Development Tools Topic: Assigning ADK function modules Assigning archiving classes

1-1

Solution to question 1-1

1-1-1 The modules are contained in the function group ARCH 1-1-2 Tools, ABAP Workbench, Overview, Object Navigator Select 'Function group' Entry: ARCH Button 'Display Open 'Function modules' 1-1-3 Write: Archive_open_for_write Archive_new_object Archive_put_record Archive_put_table Archive_save_object Archive_write_statistics Archive_close_file Delete: Archive_get_customizing_data Archive_close_file Archive_get_next_object Archive_get_next_record Archive_open_for_delete Archive_delete_object_data Archive_write_statistics 1-2 Solution to question 1-2 a

1-2-1 Archiving classes read and write objects to tables, which are not filled by specific business object, but which are used on a cross-application basis by R/3 . 1-2-2 Archiving classes are created by the responsible application. The development of archiving classes by customers is NOT supported. 1-2-3 Call transaction AOBJ Flag the archiving object SD_VBKA Select dialog structure 'archiving classes used' Result: address, changedocu, cu_config, k_total, k_unitcost, text

(C) SAP AG

BC670

15

(C) SAP AG

BC670

16

4
Data Archiving Programming Logic

Contents:
Definition of archiving objects Constructing archiving progams Function modules in archiving programs Constructing delete progams Function modules in delete programs Important procedures when extending standard archiving objects: example IS-OIL

SAP AG 2002

(C) SAP AG

BC670

4.2 Data Archiving Programming Logic: Unit Objectives

At the conclusion of this unit, you will know: The logic of archiving programs The logic of delete programs The procedure for creating a new archiving object The procedure for extending a standard archiving object

SAP AG 1999 2002

(C) SAP AG

BC670

4.3
Overview Diagram

Course Overview The Data Archiving Process ADK Development Tools Data Archiving Progamming Logic Customer-Specific Read Progams Business Views in SAP AS Appendix

SAP AG 2002

(C) SAP AG

BC670

4.4 Data Archiving Progamming Logic: Business Scenario

The progammers of customer-specific archiving objects want to understand the logic behind SAP data archiving

SAP AG 1999 2002

(C) SAP AG

BC670

4.5
Availability of ADK API
ADK is available as a development tool:

SAP developers: for SAP standard objects Customers: For customer-specific tables - not for SAP standard objects Customers can use a developers key to extend the SAP standard system

Z and Y as an extension to an SAP archiving object

Customers can create access routines to archived data


SAP AG 1999 2002

Analysis reports Direct access to a single document Business views in SAP AS

(C) SAP AG

BC670

4.6
An Archiving Objects Programs

An archiving objects programs

reload program read program and / or preprocessing program postprocessing program write program and delete program

sequential read program single document access using SAP AS

SAP AG 2002

The minimum requirements for an archiving object are a write program and a delete program. Most archiving objects also contain additional reports and a single-document access function using SAP AS. An archiving object can also contain programs for preprocessing, analysis, reloading and postprocessing. Optionally, there is also an index progam for direct access to a single document in an archive file. However, direct single-document access is controlled using the generic functions of the Archive Information System (SAP AS). Index programs are therefore unnecessary. You can create reload programs, but these should only ever be used immediately after an archiving session for situations where the wrong data has been selected for archiving. The deletion indicator is often set for master data in the preprocessing program. Analysis programs make it easier to identify documents for selection and can identify documents that cannot be archived due to business considerations.

(C) SAP AG

BC670

4.7
Creating an Archiving Object

Creating an archiving object

transaction AOBJ

The following entries are mandatory


Step 1: Archiving and delete progams Step 2: Archiving object parameters Step 3: Tables which are archived Step 4: Customizing settings Step 5: Where available: Archiving classes used Step 6: Where available: Available read programs

SAP AG 2002

(C) SAP AG

BC670

4.8
Transaction AOBJ - Release 3.1 to 4.5
Change View Archiving Objects: Overview Table view Edit Goto Selection Utilities System Help

/naobj

New Entries

Navigation

Variable list

Archiving object -->Tables which are archived -->Tables in which you only delete Level 1 -->Maintain network graphic of 10

Object Description of the archiving object Archiving program AM_ASSET Asset - master data, values and movements RAARCH01 AM_STEUER Assets - tax tables RAARCH01 ARCHIVELNK OAARCH04 Link entries from ArchiveLink BANKEN Test for banks BC_ARCHIVE RSAADMAR Archiving of archive management data BC_DBLOGS Archiving changes to Customizing tables RSLDARCH01 BC_SBOOK BC_TRAVEL-Demo: SBOOK SBOOKA BELEG FI document CATPROARCH RSCATPRA CATT - Log/Procedure CA_KBLX Intern. RW docs. (Funds reserv./Fixed price/...) RKBEARWR CCMCALLBCK Callcenter-Callback Archiving Callbacks CCMCLBAA CCMLOGGING CCMCLGAA Call Center-Activity Logging Archive COPA1_IDEA Costing-Based CO-PA, Operating Concern IDEA RK4AIDEA COPA1_R300 Costing-Based CO-PA, Operating Concern R300 RK4AR300 COPA1_S001 Costing-Based CO-PA, Operating Concern S001 RK4AS001 COPA2_IDEA Costing-Based CO-PA, Operating Concern IDEA RK4DIDEA COPA2_R300 Costing-Based CO-PA, Operating Concern R300 RK4DR300 COPA2_S001 Costing-Based CO-PA, Operating Concern S001 RK4DS001 CO_ALLO_ST Completely cancelled documents Entry 1 RKSARSWR of 172 Position...
SAP AG 2002

Navigation steps in transaction AOBJ: Step 1: Archiving object Step 2: Tables which are archived Step 3: Tables in which you only delete Step 4: Maintain network graphic Step 5: Customizing settings Step 6: Archiving classes used Step 7: Read programs Step 8: Customizing transactions Step 9: Info tables belonging to archive files Step 10: Assignment of exit routines at generation

(C) SAP AG

BC670

4.9
Transaction AOBJ - Release 4.6
Dialog structure Archiving object Structure definition Tables which you only del. Maintain network graphic Customizing settings Archiving classes used Read progams Customizing transactions Appl. information tables Exit-routine assignment Object CO_KSTRG CO_ML_BEL CO_ML_DAT CO_ML_IDX CO_ML_ML1 CO_ORDER CO_PROCESS CO_TEST CS_BOM CV_DVS DATAFDLOG EC_PCA_SUM EIS_CF001 EIS_CF002 EIS_CF003 EIS_CF004 EIS_CF005 EIS_CF006 EIS_CF050 EIS_CF501 EIS_CF502 EIS_CF503 Description of archiving object Cost object with master and transaction data Material ledger docs (MLHD/IT/PP/PP...) Material ledger records (CKMLPP, CKMLCR) Index entries material document: ledger Material ledger period records (CKML1) Orders with transaction data Business process incl. transaction data Test only PP object lists Document management system TR-TM: Record accesses to datafeed Profit-Center-Rechnung: Summenstze Archive object for aspect CF001 Archive object for aspect CF002 Archive object for aspect CF003 Archive object for aspect CF004 Archive object for aspect CF005 Archive object for aspect CF006 Archive object for aspect CF050 Archive object for aspect CF501 Archive object for aspect CF502 Archive object for aspect CF503 Position
SAP AG 2002

Entry 1 of 182

(C) SAP AG

BC670

4.10
Minimum Requirements per Archiving Object (1)

Transaction AOBJ - archiving object Enter the available programs Programs for the following processes can or must be available for an archiving object: Preprocessing (optional) Create archive file(s) Delete data from database Postprocessing (optional) Reload data to the database (optional)
SAP AG 2002 1999

Possible functions of preprocessing progams: Set the deletion indicator in the master data (for example, in PP) Determine archivable data (for example, in SD) Archiving objects with postprocessing progams (Release 4.5A): QM_CONTROL PA_PDOC FI_DOCUMNT CATPROARCH

The postprocessing progam for the archiving object FI_DOCUMNT (FI documents) for example, deletes data from the FI indexes. You can find SAP Notes on archiving objects in transaction SARA by choosing the i symbol in the activity screen (schedule archiving, schedule deletion,...).

(C) SAP AG

BC670

10

4.11
Minimum Requirements per Archiving Object (2)

Transaction AOBJ - Archiving object Entering definition flags -> -> -> -> -> -> Build index Start at end Cross-client End dialog Invalid flag No reload files

SAP AG 2002 1999

Cross-application: The transaction SARA is client-specific. You can set this indicator if you want to work on a cross-client basis. End dialog: During archiving, R/3 dialog operations should be stopped in order to avoid data collisions. When scheduling the jobs, the administrator receives a warning that further checks will not be carried out. Invalid: If archiving sessions are incomplete and there is no completed status, you can mark the entry as invalid in archive administration. If the invalid indicator is set for an archiving object, the indicator for invalid archive files cannot be reversed in archive managment. no r. files (from Release 4.0A): When reloading data to the database, new archive files are created if not all of the data from a session was reloaded. If this indicator is set, the system will not create any new files. Prg.generated: Archiving objects that work with statistical or controlling data, generate their programs based on individual user inputs at runtime. Example: MKIS, COPA1_* Build index: The archiving object is usually able to construct an index. There must also be an index build program stored in AOBJ.

(C) SAP AG

BC670

11

4.12
Minimum Requirements per Archiving Object (3)

Transaction AOBJ - structure definition


Enter the tables, from which you want to archive data The entries represent the archiving objects data model

Transaction AOBJ - Customizing settings

Technical settings, such as file sizes, commit counter, delete program variants, connection to external storage system The technical settings can be maintained by the user in transaction SARA

SAP AG 2002

Entries in the structure definition: Record no.: order definition only Parent segment: Name of the next highest structure in the hierarchy. Therefore, for the first record, this field remains empty. From Release 3.0, entries are also only for defining the order. In Release 2.2, archiving was organized hierachically. Segment: Subordinate segment in the archive heirarchy. Name of the structure belonging to the archiving object. This field informs ADK (and its function module) which tables are to be processed. The ADK uses the entries for the following functions: - Metadata for the archive file that is to be written - Information basis for transaction DB15

Structure: If a structure name is entered here, this structure will be used for conversions. This is essential if you are working with logical databases and the structure name entered under segment is a pseudonym for a real structure. ADK uses the entries in the same way as was described for segments (see above). Technical Customizing: From 4.6A, the commit counter can only be maintained in transaction AOBJ.

(C) SAP AG

BC670

12

4.13
Minimum Requirements per Archiving Object (4)

Transaction AOBJ - archiving classes used


Enter the archiving classes that the archiving object uses An entry in transaction AOBJ means that the archiving class is used by the archiving object

Transaction AOBJ - read programs

if the available read programs are entered, then the programs can be called from the context of the archiving transaction SARA

SAP AG 2002

It is necessary to enter the archiving classes in AOBJ so that transaction DB15 and the Archive Information System consider the archiving classes. Transaction DB15 determines the tables that belong to an archiving object or, conversely, the suitable archiving object for a table.

(C) SAP AG

BC670

13

4.14
Minimum Requirements per Archiving Object (5)

Transaction AOBJ - Customizing transactions

Group of transactions in which application-specific Customizing must be carried out In application-specific Customizing, the applications allow criteria for the archivability of data to be entered, which are checked during an archiving session. For transaction data, this is mainly defining residence times. For master data, this is mainly setting deletion indicators . The application-specific settings are carried out within application Customizing.

SAP AG 1999 2002

(C) SAP AG

BC670

14

4.15
Support Components in R/3

R/3 >= 4.5A: Example archiving object BC_SBOOK with progams for

Writing archive files (SBOOKA) Deleting archived data from the database (SBOOKD) Reporting from archive files (SBOOKR) Filling an archive index (SBOOKI)

R/3 < 4.5A: Example archiving object EXAMPLE

Progams similar to SBOOK RSARCH04, RSARCH06, RSARCH19, RSARCH15 Single-document read RSARCH13

SAP AG 2002 1999

Note: The archiving object EXAMPLE only simulates deletion of data from the database. Functionality read single document for SBOOK is realised via SAP AS; The index construct program has a greater documentation character.

(C) SAP AG

BC670

15

4.16
Programming Logic: Archiving (1)

Authorization check Read selection Read Customer-Specific Customizing Data selection Implement check logic from a business logic point of view

SAP AG 2002

Authorization checks include the - authorizations for calling ADK function modules - authorizations for maintaining AOBJ - authorizations for creating and managing jobs - authorizations from the relevant application for writing the archive file - authorizations for maintaining the application-specific archiving Customizing

You must make sure that checks are implemented in exactly the same way as in online operations. The selection of data from the database should be as specific as possible. Avoid reading unnecessary data relating to authorization checks. The person responsible for the archiving must enter the required criteria in the selection screen. In the data selection, the database data is collected according to the selection criteria. The check logic establishes whether data records are archivable. It examines the residence times in application-specific Customizing as well as specific additional internal check logic.

(C) SAP AG

BC670

16

4.17
Programming Logic: Archiving (2)

Write data object: ADK API used

Archive_open_for_write

Do Archive_new_object

Archive_put_record TEXT_ARCHIVE_OBJECT (Archiving FM belonging to an archiving class)

Archive_save_object Enddo

Archive_write_statistics Archive_close_file

SAP AG 2002

ARCHIVE_NEW_OBJECT prepares a data container in the main memory. This function module also ensures communication with any archiving classes. ARCHIVE_PUT_RECORD writes a record in the prepared data container. TEXT_ARCHIVE_OBJECT is the archiving function module for the archiving class TEXT. It is used to collect archiving class data for an object and to store it in its own data area on the main memory. In ARCHIVE_SAVE_OBJECT, ADK takes the records from the data container and compresses it. From the archiving classes, ADK requests the compressed archiving class data for the object and writes it to the ADK file. At present, ADK cannot subsequently decompress this data. ARCHIVE_CLOSE_FILE releases all resources and starts the delete program if Start autom. has been selected in Customizing. If you forget the Archive_Close_File, the last archive file is not closed.

(C) SAP AG

BC670

17

4.18
ADK API: ARCHIVE_OPEN_FOR_WRITE

Interface parameter export

archive_handle

Interface parameter import


call_delete_job_in_test_mode, create_archive_file object, comments

Function module functionality:


Create archive file in the file system Create archive handle

SAP AG 2002

ADK has multi-instance capability. Each handle addresses one instance. In one program, more than one archive can be read in parallel. The handle, as it is used in ADK, is comparable with a file handle in the file management system. In transaction AOBJ Customizing settings you can specify whether the delete program for the archived data is to be called automatically. The archiving function modules use platform-independent filenames to create new archive files. In transaction AOBJ Customizing settings, you can specify the platform-independent filenames that are to be used for your archiving object. If you have not defined a filename, the system will automatically use the platform-independent filename ARCHIVE_DATA_FILE to create the server-independent filename. The import parameters mentioned do not come from the technical settings for the archiving object. They are selection parameters. In the Comments parameter, you can enter a text that is automatically saved as management data during the session. The function module informs the archiving classes used and makes an entry in the archive management that signifies that an archiving session is in progress.

(C) SAP AG

BC670

18

4.19
ADK API: ARCHIVE_NEW_OBJECT

Interface parameter import archive_handle

Function module functions: Initializes a new data object Discards the processed data

SAP AG 2002

This function module should always be called if a new data object is to be prepared for writing to an archive. There can only be one data object per handle. When this function module is called, all of the data from the current data object is forgotten, and all of the accompanying archiving classes are informed that the following operations with this handle belong to a new data object. The archiving classes will forget all of the information about the current data object. The system does not check whether you have stored the current data object with the function module ARCHIVE_SAVE_OBJECT.

(C) SAP AG

BC670

19

4.20
ADK API: ARCHIVE_PUT_RECORD

Interface parameter import


archive_handle record_flag record_structure record

Function module functions:

With this function module, you can transfer a data record to the data object that was previously requested with the function module ARCHIVE_NEW_OBJECT. All of the data records that you pass to the data object are written togetherto the archive file when you call the function module ARCHIVE_SAVE_OBJECT .

SAP AG 2002

The import parameter record_flag is available for any supplementary information. For example, FI uses it to mark records that are to be deleted. The import parameter record_structure is given the name of the structure that is to be transferred. This name must be stored in the structure definition in AOBJ. The actual transferred data is transferred to the import parameter record. If the structure named under record_structure is not the same as the record in record_real, the system may issue the runtime error Archive cannot be read For complex data objects, you might have to first read and analyse all of the data records, before you can decide whether this data object is to be archived. You do not have to remember the data records, or even re-read the data records from the database. You can use the function mode to transfer the data records to the data object immediately. If you realize that the data records that you transferred should not be archived, call the function module ARCHIVE_NEW_OBJECT. This ensures that the data that you transferred is discarded. The data that you transferred to the archiving classes for archiving is also discarded.

(C) SAP AG

BC670

20

4.21
ADK API: ARCHIVE_PUT_TABLE

Interface parameter import


archive_handle record_structure

Interface table

table

Function module functionality:

With this function module, you transfer an internal table to thedata object that was called previously with the function module ARCHIVE_NEW_OBJECT. Each line of the internal table is placed in the data object asa separate data record. All transferred data records are written together to the archive file when you call the function module ARCHIVE_SAVE_OBJECT

SAP AG 2002

In the record_structure parameter, you enter the name of the name of the structure/table whose objects are to be written. The data is transferred to an internal table via the table interface. If required, an archiving program typically selects all line items for one document in an internal table. This internal table can be transferred, record by record, in its entirety to ADK.

(C) SAP AG

BC670

21

4.22 Comparison ARCHIVE_PUT_RECORD - ARCHIVE_PUT_TABLE

Writes one record each More coding Lower performance as records are processed per record

Writes array of records Less coding required as no loop construction Better performance as records not written individually

SAP AG 2002

(C) SAP AG

BC670

22

4.23
ADK API: ARCHIVE_SAVE_OBJECT

Interface parameter export


archive_name object_offset

Interface parameter import

archive_handle

Function module functionality :

This function module writes a data object to the archive file. As well as the data transferred with the function module ARCHIVE_PUT_RECORD, the data that was transferred via the archiving classes will also be taken into account.

SAP AG 2002

The export parameter object_offset enables you to find the object in the ADK archive file. The parameter archive_name returns the key for the ADK archive file. If the data object does not fit into the current archive file, the system closes the archive file and opens a new archive file. The system then automatically calls the delete progam, unless this option was switched off in transaction AOBJ "Customizing settings".

(C) SAP AG

BC670

23

4.24
ADK API: ARCHIVE_WRITE_STATISTICS

Interface parameter import


archive_handle statistics_only_per_run statistics_only_per_file (from Release 4.6)

Function module functionality :

With this function module, you can create statistics about data objects that you have written to an archive file using function module ARCHIVE_SAVE_OBJECT. These statistics are written as a list and therefore appear in the archiving program log.

SAP AG 2002

You can use the import parameter statistics_only_per_run to request totals statistics for the whole arhiving session. The parameter statistics_only_per_file provides statistics for one archive file and is, for this reason, only useful when used with a delete program. You must call this function module immediately before the function module ARCHIVE_CLOSE_FILE , otherwise you will obtain incorrect values in the number fields. The size of the archive file in MB also appears in the output. If you run the archiving program for a limited selection in test mode, you can use this output to estimate the required disk space.

(C) SAP AG

BC670

24

4.25
ADK API: ARCHIVE_CLOSE_FILE

Interface parameter import

archive_handle

Function module functionality :

The function module closes the archive file. The resources which were allocated for a handle are released. The handle is then invalid and can no longer be used. Every additional operation with this handle triggers the exception WRONG_ACCESS_TO_ARCHIVE

SAP AG 2002

This function module is not only called when writing archives, but also within every ADK function.

(C) SAP AG

BC670

25

4.26
Example Report SBOOKA (1)
REPORT sbooka. * data declaration TABLES: sbook. DATA: button(1) create(1) no_delete(1) handle sbook_itab data_object_id

TYPE TYPE TYPE LIKE TYPE LIKE

c, c VALUE 'X', c VALUE 'X', sy-tabix, TABLE OF sbook WITH HEADER LINE, arch_idx_s-obj_id.

* selection criteria and parameters SELECTION-SCREEN BEGIN OF BLOCK arch_booking WITH FRAME TITLE text-101. SELECT-OPTIONS: o_carrid FOR sbook-carrid DEFAULT 'LH ', o_order FOR sbook-order_date DEFAULT '19000101' TO '20020101'. SELECTION-SCREEN END OF BLOCK arch_booking.
SAP AG 2002

(C) SAP AG

BC670

26

4.27
Example Report SBOOKA (2)
SELECTION-SCREEN BEGIN OF BLOCK arch_control WITH FRAME TITLE text-102. PARAMETERS: no_file LIKE button RADIOBUTTON GROUP radi, del_test LIKE button RADIOBUTTON GROUP radi DEFAULT 'X', del_prod LIKE button RADIOBUTTON GROUP radi. SELECTION-SCREEN END OF BLOCK arch_control. PARAMETERS comments TYPE admi_text LOWER CASE DEFAULT 'This is test data for archiving with BC_SBOOK'(103). * select data from the database SELECT * FROM sbook INTO TABLE sbook_itab * build ADK parametersIN o_carrid AND WHERE carrid from chosen button IF no_file = 'X'. createIN ' '. no_delete = ' '. order_date = o_order. IF del_test = 'X'. create = 'X'. no_delete = 'X'. IF del_prod = 'X'. create = 'X'. no_delete = ' '.
SAP AG 2002

ENDIF. ENDIF. ENDIF.

(C) SAP AG

BC670

27

4.28
Example Report SBOOKA (3)
* open a new archive session to archive data CALL FUNCTION 'ARCHIVE_OPEN_FOR_WRITE' EXPORTING call_delete_job_in_test_mode = no_delete comments = comments create_archive_file = create object = 'BC_SBOOK' IMPORTING archive_handle = handle. LOOP AT sbook_itab. CONCATENATE sy-mandt sbook_itab-carrid sbook_itab-bookid INTO data_object_id. * initialize a new data object CALL FUNCTION 'ARCHIVE_NEW_OBJECT' EXPORTING archive_handle = handle object_id = data_object_id. " optional: ADK index
SAP AG 2002

(C) SAP AG

BC670

28

4.29
Example Report SBOOKA (4)
* put data records into ADK's data container CALL FUNCTION 'ARCHIVE_PUT_RECORD' EXPORTING archive_handle = handle record_structure = 'SBOOK' record = sbook_itab. * * * * * * * * further (depending) records from other tables usually follow loop at <depending table X> where ... call function 'ARCHIVE_PUT_RECORD' ... endloop. loop at <depending table Y> where ... call function 'ARCHIVE_PUT_RECORD ... endloop.

* write data object into the archive file CALL FUNCTION 'ARCHIVE_SAVE_OBJECT' EXPORTING archive_handle = handle. ENDLOOP.
SAP AG 2002

(C) SAP AG

BC670

29

4.30
Example Report SBOOKA (5)

create the default spool list CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS' EXPORTING archive_handle = handle. * close the archive session CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING archive_handle = handle.

SAP AG 2002

(C) SAP AG

BC670

30

4.31
Programming Logic Data Deletion (1)
Archive_get_customizing_data Archive_open_for_delete Do

Archive_get_next_object Do

Archive_get_next_record call archiving classes check commit counter

Enddo Archive_delete _object_data If cut = cust_cut Perform Delete endif

Enddo If cut > 0 Perform Delete endif Archive_close_file


SAP AG 2002 1999

possible remaining amount processing

Function module ARCHIVE_GET_NEXT_OBJECT transfers the ADK data to the main memory. Form DELETE: Delete data from the database according to the read structure.

(C) SAP AG

BC670

31

4.32
ADK API: ARCHIVE_GET_CUSTOMIZING_DATA

Interface parameter export


commit_count_for_delete_prg maintain_index

Interface parameter import

object (archiving object)

Function module functionality:

This function module delivers set values from the archiving-object-Customizing to the archiving progam. Currently only those values are passed which are important for the delete program. However, the counter for the Commit Work can also be used for the reload progam.

SAP AG 2002

(C) SAP AG

BC670

32

4.33
ADK API: ARCHIVE_OPEN_FOR_DELETE

Interface parameter export

archive_handle

Interface parameter import


object test_mode

Function module functions:

This function module opens archives to delete from the database the data they contain. The status of the archive files is modified accordingly in archive administration.

SAP AG 2002

The import parameter object specifies the name of the archiving object containing records for deletion. The parameter test_mode specifies whether it is a live or test run. The parameter copies the indicator from the relevant delete program variant that was specified on the selection screen of the delete program. The parameter aindflag controls the interaction with the archive information system. All active archive information structures are updated during the deletion run. Within the scope of the delete job, the function module ARCHIVE_CLOSE_FILE transfers, on request, (technical settings in Customizing for the relevant archiving object) the archive files that have been created using SAP ArchiveLink for storage to an external storage system.

(C) SAP AG

BC670

33

4.34
ADK API: ARCHIVE_GET_NEXT_OBJECT

Interface parameter export


object (Archivierungsobjekt) object_offset archive_name

Interface parameter import

archive_handle

Function module functions:

This function module reads the next data object for a handle from an archive that has been opened for read access

SAP AG 2002

The import parameter object contains the name of the archive objects processed. The parameters archive_offset and archive_name are relevant for writing an index. The data belonging to an archiving class is automatically passed on to the relevant archiving class. This means that the data can be called by the archiving class immediately after the function module has been called. Long texts and change documents are typical archiving classes. You can only use function modules ARCHIVE_GET_NEXT_RECORD and ARCHIVE_GET_NEXT_STRUCT_SPECIF to access data once a data object has been read from an archive. The same functions are present in this function module as in the function module ARCHIVE_OPEN_FOR_READ , because a new archive file is automatically opened for read access when the current file has been read completely. This means that the same exceptions can be triggered as in the function module ARCHIVE_OPEN_FOR_READ. You should take this into account when writing your programs.

(C) SAP AG

BC670

34

4.35
ADK API: ARCHIVE_GET_NEXT_RECORD (1)

Interface parameter export


record record_strucure

Interface parameter import


archive_handle automatic_conversion

SAP AG 2002

The export parameter record contains the name of the work area into which the data is to be imported. Record_structure contains the name of the table or structure that is being processed. The data record that is returned by the ADK is unstructured and must be copied into a suitable work structure. When ARCHIVE_GET_NEXT_RECORD is called, temporary automatic conversion takes place, if required, such as adjustment of structure changes; adjustments to heterogeneous system environments (codepage), and so on.

(C) SAP AG

BC670

35

4.36
ADK API: ARCHIVE_GET_NEXT_RECORD (2)

Function module functionality :

This function module allows you toread sequentially the data records contained in a data object At the first call after the function module ARCHIVE_GET_NEXT_OBJECT has been called, the first data record is automatically returned, and, from then on, each further record is returned until there are no more records to be read from the data object.

SAP AG 2002

To read an archive file sequentially, it is sufficient to read the next data object in an external DOloop using function module ARCHIVE_GET_NEXT_OBJECT so that function module ARCHIVE_GET_NEXT_RECORD can read the data object in an internal DO-loop.

(C) SAP AG

BC670

36

4.37
ADK API: ARCHIVE_DELETE_OBJECT_DATA

Interface parameter import

archive_handle

Function module functionality :

This function module calls the delete methods for all of the registered archiving classes belonging to the archiving object. The archived data from all classes is then automatically deleted from the database.

SAP AG 2002

The function module ARCHVE_GET_NEXT_OBJECT must be called for each object - directly in the loop. The ADK API of the archiving objects themselves does not provide any delete methods. You must progam and call this functionality yourself. This means that you must use the delete program to delete from the database all of the data that was written to data objects in the archiving progam by ARCHIVE_PUT_RECORD.

(C) SAP AG

BC670

37

4.38
Example Report SBOOKD (1)
REPORT sbookd.

* data declaration CONSTANTS: object DATA: handle buffer sel_files_itab sbook_wa sbook_itab commit_cnt object_cnt arkey object_id offset index_tab index_flag sum_objects stat_itab tabfield
SAP AG 2002

LIKE arch_obj-object VALUE 'BC_SBOOK'. LIKE TYPE TYPE LIKE TYPE LIKE TYPE LIKE LIKE LIKE TYPE LIKE TYPE TYPE LIKE sy-tabix, arc_buffer, TABLE OF arch_files, sbook, TABLE OF sbook, arch_usr-arch_comit, i, arch_idx_s-archivekey, arch_idx_s-obj_id, arch_idx_s-obj_offset, TABLE OF arch_idx_s WITH HEADER LINE, arch_usr-arch_index, i VALUE 0, TABLE OF arch_stat, arch_stat.

The variable buffer is divided into the following parts: buffer_segment and buffer_rname. The name of the table for deletion is contained in buffer_rname. buffer_segment specifies the work area containing the record for deletion.

(C) SAP AG

BC670

38

4.39
Example Report SBOOKD (2)

PARAMETERS: testrun DEFAULT 'X' AS CHECKBOX. * open a new archive session to delete data CALL FUNCTION 'ARCHIVE_OPEN_FOR_DELETE' EXPORTING object = object test_mode = testrun IMPORTING archive_handle = handle EXCEPTIONS OTHERS = 01. IF sy-subrc <> 0. WRITE / 'No file can be accessed'(001). EXIT. ENDIF.

" do not delete " from database

SAP AG 2002

(C) SAP AG

BC670

39

4.40
Example Report SBOOKD (3)
* get customizing data from the archive object CALL FUNCTION 'ARCHIVE_GET_CUSTOMIZING_DATA' EXPORTING object = object IMPORTING commit_count_for_delete_prg = commit_cnt maintain_index = index_flag. * loop to get the next data object from the archive file (s) CLEAR object_cnt. DO. ADD 1 TO object_cnt. CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT' EXPORTING archive_handle = handle IMPORTING object_id = object_id object_offset = offset archive_name = arkey EXCEPTIONS end_of_file = 01.
SAP AG 2002

(C) SAP AG

BC670

40

4.41
Example Report SBOOKD (4)
IF sy-subrc = 1. EXIT. ENDIF. * build an index to allow for random access to data objects *** This index is optional. Try to use the Archive Information *** System SAP AS instead. IF index_flag IS INITIAL. * no index is to be built according to customizing ELSEIF testrun IS INITIAL. MOVE: object_id TO index_tab-obj_id, arkey TO index_tab-archivekey, offset TO index_tab-obj_offset. APPEND index_tab. PERFORM save_index_tab ON COMMIT. ENDIF.

SAP AG 2002

(C) SAP AG

BC670

41

4.42
Example Report SBOOKD (5)
* loop to get data records from ADK's data container DO. CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD' EXPORTING archive_handle = handle IMPORTING record = buffer-segment record_structure = buffer-rname EXCEPTIONS end_of_object = 01. IF sy-subrc = 1. EXIT. ENDIF. * keep data records in mind; take their structure into account CASE buffer-rname. WHEN 'SBOOK'. MOVE buffer-segment TO sbook_wa. APPEND sbook_wa TO sbook_itab. " will be deleted in db * when ... " further structures ENDCASE. ENDDO.
SAP AG 2002

(C) SAP AG

BC670

42

4.43
Example Report SBOOKD (6)
IF testrun IS INITIAL AND object_cnt = commit_cnt. PERFORM delete_from_table. " actual delete from database CLEAR object_cnt. " restart counting up to ENDIF. " value of commit counter ENDDO. IF testrun IS INITIAL AND object_cnt > 1. PERFORM delete_from_table. " deleting last package ENDIF. * provide statistics tabfield-tabname = ' '. tabfield-count = sum_objects. APPEND tabfield TO stat_itab. tabfield-tabname = 'SBOOK'. APPEND tabfield TO stat_itab. CALL FUNCTION 'ARCHIVE_GIVE_STATISTICS' EXPORTING archive_handle = handle TABLES table = stat_itab.
SAP AG 2002

(C) SAP AG

BC670

43

4.44
Example Report SBOOKD (7)
* write statistics CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS' EXPORTING archive_handle = handle statistics_only_per_file = 'X'. * get all processed files for update of index status CALL FUNCTION 'ARCHIVE_GET_ARCHIVE_FILES' EXPORTING archive_handle = handle TABLES archive_files = sel_files_itab. * close the archive session CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING archive_handle = handle.

SAP AG 2002

(C) SAP AG

BC670

44

4.45
Example Report SBOOKD (8)
* set status "index created" in SARA administration IF index_flag IS INITIAL. * no index has been built according to customizing ELSEIF testrun IS INITIAL. CALL FUNCTION 'ARCHIVE_ADMIN_SET_STATUS' EXPORTING files_are_converted = ' ' index_created = 'X' TABLES archive_files = sel_files_itab. ENDIF. *---------------------------------------------------------------- ----* * FORM DELETE_FROM_TABLE * *---------------------------------------------------------------- ----* * global: sbook_itab, sum_objects *---------------------------------------------------------------- ----* FORM delete_from_table. DATA: tabcount TYPE i VALUE 0. DELETE sbook FROM TABLE sbook_itab. " delete job restartable COMMIT WORK.
SAP AG 2002

Commit Work then triggers the actual deletion of data from the archiving classes. The delete routine belonging to the archiving classes is called via a Perform ... On Commit, that is the actual deletion only takes place at a database commit. The collection of data belonging to an archiving class which is to be deleted, occurs via a call of ARCHIVE_DELETE_OBJECT_DATA. This function module is started once per call of ARCHIVE_GET_NEXT_OBJECT .

(C) SAP AG

BC670

45

4.46
Example Report SBOOKD (9)
DESCRIBE TABLE sbook_itab LINES tabcount. sum_objects = sum_objects + tabcount. REFRESH sbook_itab. ENDFORM. " DELETE_FROM_TABLE *---------------------------------------------------------------- ----* * Form SAVE_INDEX_TAB * *---------------------------------------------------------------- ----* * global: index_tab * *---------------------------------------------------------------- ----* FORM save_index_tab. DELETE arch_idx_s FROM TABLE index_tab. INSERT arch_idx_s FROM TABLE index_tab. REFRESH index_tab. ENDFORM. " SAVE_INDEX_TAB

SAP AG 2002

(C) SAP AG

BC670

46

4.47
ADK API: Additional Customer-Relevant FMs

Archive_get_information

Archive_open_for_move

SAP AG 2002 1999

Archive_get_information This function module enables you to determine the latest information about an archive handle. This includes the question of when the archive files were written, what their underlying structure is, and so on. This data is important, for example, for tailoring your own reporting programs if a tables data structure has changed. Archive_open_for_move This function module enables you to read archive files in order to write data objects from these archive files to new archive files. You must call it if you want to reload individual data objects from archive files to the R/3 System.

(C) SAP AG

BC670

47

4.48
Standard Tables and Customer-specific Tables

Standard table with customer-specific append structure

Combination of standard tables and customer-specific Y-/Z-tables

Customer-specific Y-/Z tables, which logically belong to R/3 standard tables customerspecific Z-table ZC, standard independent table of C standard table C

A P standard P table E A N D

standard table B

customerspecific Z-table ZZZ

Extension not always necessary

Create customer-specific archiving object

Extension necessary, contact your SAP consultant

SAP AG 2002

Note: In R/3 standard tables, you are only allowed to delete using R/3 standard programs!

(C) SAP AG

BC670

48

4.49 Procedure for Extending a Standard Archiving Object

List the modifications that have been carried out Analyse the modifications to see whether changes are required to existing archiving objects or archiving classes Categorize the customer-specific tables with the help of the data model used (where does the table sit in the data model) Check whetherdependencies on other archiving objects have been created

SAP AG 2002 1999

Note: To ensure that the standard archiving progams continue to function correctly, the extensions must be carried out in the customer namespace in a new progam. Note: When extending a standard archiving object, ensure that the performance of the standard archiving progam is not reduced.

(C) SAP AG

BC670

49

4.50
Extension: Dependencies

Starting point:

New dependencies by introducing new documents New dependencies due to customer-specific requirements

Possible consequences:

Maintain new checks in existing archiving programs: User exits possible for SD archiving objects Update the network graphic for documentation

SAP AG 2002

Some industry-specific requirements call for modifications to the transport process. For example, in IS-OIL, it was necessary, to introduce a new delivery-related document. Delivery documents must not be archived until the new subsequent document has been closed. User exits in SD are discussed in course BC660.

(C) SAP AG

BC670

50

4.51
Extension: Append Structure in Standard Table

Starting point:

New fields were inserted into the standard tables using the Append/Include technique

Consequences:

As long as the archiving object or archiving classes write the original table entries, no changes are required to write or dele te programs. Analysis programs must be adjusted in case the fields have to be displayed. Check whether dependencies have arisen.

SAP AG 2002

Check the archiving program to see whether structures are written instead of the original tables. If so, the archiving program transfers the table entries to these structures. In this case, the archiving program and the structures must be adjusted in line with the changed data.

(C) SAP AG

BC670

51

4.52
Extension: New Tables for Standard Documents

Starting point:

Information on standard documents is stored in customer specific tables

Consequences:

Use transaction AOBJ to extend the archiving object structure to include customer-specific tables Copy and adjust the write- and delete progams Copy and adjust the reporting progam (optional) Monitor potential new dependencies

SAP AG 2002

(C) SAP AG

BC670

52

4.53
Example Extension to MM_MATBEL (1)

Add-on IS-OIL For goods movements in the oil industry, you must enter temperature and density data in the database for every material item. This data is stored in its own table, which must be archived and deleted together with the standard tables MKPF and MSEG.

SAP AG 2002 1999

(C) SAP AG

BC670

53

4.54
Example Extension to MM_MATBEL (2)

Standard data model: MKPF -> MSEG Extended data model IS-OIL: MKPF -> MSEG -> MSEGO1 -> MSEGO2

SAP AG 2002

In the above data model of MM-data, there is also NAST data. Within the context of data archiving, this data is deleted only.

(C) SAP AG

BC670

54

4.55
Example Extension to MM_MATBEL (3)

Analyze dependencies

In contrast to the standard system, the material document may stll i be required in certain situations (not mseg-oiexgnum) for a process called netting, which follows billing/invoice verifica tion. In the section oil_put_oiaqb, the system checks whether this process has been completed Cross-application dependencies to other archiving objects are not given

SAP AG 2002 1999

(C) SAP AG

BC670

55

4.56
Example Extension to MM_MATBEL (4)
Analyze the standard archiving program with reference to flow logic and performance optimization

Program searches for the optimum strategy to select the documents to be archived (selection via header- or item data) If the selection uses item data, the system uses a database view Program works with dynamic SQL Program redetermines the selection criteria to keep the data for selection to a minimum Program works with central authorization checking, to restrict the amount of data to be selected and processed Program writes header data individually with ARCHIVE_PUT_RECORD and all item data from a document with ARCHIVE_PUT_TABLE

SAP AG 2002 1999

Note: From a check logic viewpoint, MM_MATBEL should be seen as a simply structured archiving object.

(C) SAP AG

BC670

56

4.57
Example Extension to MM_MATBEL (5)

Adjustments to standard archiving program


Insert required data definition Insert processing log for new data Insert selection of new data Insert archivability checks Insert the writing of table records in the archive files, after the assigned tables have been written in the standard system.

SAP AG 2002 1999

(C) SAP AG

BC670

57

4.58
Example Extension to MM_MATBEL (6)

Adjustments to standard delete program


Insert required data declaration Fill the internal tables for new data after data has been read from the archive file(s)

Programming similar to standard table processing The new progam code is inserted behind the processing of the master table Programming similar to standard table processing The new progam code is inserted behind the processing of the master table

Insert a delete sequence for the new data

SAP AG 2002 1999

In some cases, data has to be deleted only. Such data is not transferred to the archive file, but simply deleted from the database. An example of this is the message control data for MM and SD documents.

(C) SAP AG

BC670

58

4.59
Extension: Summary (1)

Adjusting the archiving programs


Copy the standard program in the customer namespace. Analyze the archiving program carefully. Determine to which already archived table the new table logically belongs. Determine where in the archiving program the master table is processed. Extend the definition of the required data structures. Extend the selection of data from the Z table If necessary, extend the archivability checks. Extend the transfer of data from the Z table to ADK

SAP AG 2002 1999

Note: A careful analysis of the archiving program is essential, because the programs are generally optimized with regard to performance. To avoid problems in future, check that the performance of the write and delete programs is still satisfactory after the new tables have been added. User exits are not offered so that performance can be further optimized and new structures can be included in the standard system at any time. New developments may lead to future changes in the underlying program logic of the standard archiving objects. For example, the SD document programs have already been redesigned.

(C) SAP AG

BC670

59

4.60
Extension: Conclusion (2)

Adjusting the delete program

Determine the point at which the data records are to be deleted

CASE-structure after calling the function module ARCHIVE_GET_NEXT_RECORD List of delete calls

Extend the delete calls to include your own table(s)

SAP AG 2002 1999

(C) SAP AG

BC670

60

4.61
Extension: Conclusion (3)

Adjusting a reporting program (optional)


Extending the output structure Extending the output of the data

SAP AG 2002 1999

(C) SAP AG

BC670

61

4.62
Extension: Evaluation

We recommend that you do not extend a standard archiving object. If this is unavoidable, contact your SAP consultant. Recommended procedure:

Use a customer-specific archiving object to archive your own Y or Z tables that belong to a standard archiving object. Write reports that read and merge the archive files belonging to the standard object and to customer-specific object.

SAP AG 2002 1999

After modifying a standard archiving object, you should check whether the same level of throughput performance can be maintained as before you made the modification.

(C) SAP AG

BC670

62

4.63
Data Archiving Programming Logic : Conclusion

You now know: The logic of an archiving progam The logic of a delete progam Procedure for creating a new archiving object Procedure for extending an archiving object

SAP AG 2002

(C) SAP AG

BC670

63

4.64 Unit: Program Logic in Data Archiving Topic: Archiving STICKET


At the conclusion of this exercise, you will be able to: Write data from the customer table STICKET to an archiving file

Your enterprise has the customer table STICKET. This table has been identified as a critical table, and is to be reduced in size. First, you must write an archiving program.

1-1

Create an archiving program for STICKET. Use program SBOOKA as template. Program name: ZBCSTICKxxA. XX stands for your group number. Type: Executable program Status: Test program Application: Basis 1-1-1 Create an archiving program that archives records from the table STICKET. Selection parameters: Airline (carrid) and booking number (bookid).

1-1-2 Configure your program so that the user can decide - Whether to create an archive file - Whether to use the test run variant or live run variant if the deletion program is to be run immediately. 1-1-3 Write an archive file only if the parameter has been set as follows. Sequence of function modules: Open archive file for write job Initialize new data object Transfer data record Save data object 1.1.4 Ensure that the statistics are written with the standard statistics module before you close the archive file.

2.1

Create deletion program for STICKET. Use the program SBOOKD as a template. Program name: ZBCSTICKxxD. xx stands for your group number. BC670 64

(C) SAP AG

Type: Executable program Status: Test program Application: Basis 2.1.1 2.1.2 Enter a parameter that determines whether the deletion run is to be a test run, or whether data is really to be deleted. Sequence of function modules: Retrieve file for deletion Read Customizing data (Commit counter/Start deletion job Loop 1: Read archiving record object from data container Loop 2: Copy record in buffer and run deletion routine if the deletion indicator is set. Output statistics Close file No index is to be built.

2.1.3

(C) SAP AG

BC670

65

Unit: Data Archiving Programming Logic Topic: Customizing and Testing BCSTICKxx
At the conclusion of this unit, you will be able to: Create an archiving object in transaction AOBJ Test a new archiving object The customer-specific table STICKET exists in your organization. This table is recognized as being a critical table. The size of this table needs to be reduced. After you have written the necessary programs, you must create the archiving object in your system.

1-1

Create the archiving object ZBCSTICKxx. (XX represents your group number.) 1-1-1 Create the archiving object in transaction AOBJ. Specify BC as the work area and use input help to select application component Basis. Enter your archiving and delete programs Publicize the structure definitions: You are processing the table STICKET Maintain the Customizing settings: 1-1-4-1 1-1-4-2 Your logical filename should link to the path Archive_data_file Enter the file size 100 MB and leave the number of objects blank

1-1-2 1-1-3 1-1-4

1-1-4-3 After data archiving, the file is not going to be stored in an external optical archive. 1-1-4-4 Do not start the delete program immediately, but rather manually. Create 2 delete program variants: TESTxx for a test delete run and PRODxx for the production delete run

(C) SAP AG

BC670

66

2-1

Start an archiving and delete run in transaction SARA for your newly created archiving object. Additional task Display the archived data via SAP AS 2-2-1 In the Archive Information System, create an archive information structure for your newly created archiving object. 2-2-2 Activate your archive information structure. Fill your archive information structure with the data from your archiving session. Display the data in the Archive Explorer.

2-2

(C) SAP AG

BC670

67

4.65Data Archiving Programming Logic Solutions Unit: Data Archiving Programming Logic Topic: Archiving STICKET

1-1

Tools, ABAP Workbench, Development, ABAP Editor Enter SBOOKA, Button Copy Enter ZBCSTICKxxA. (xx represents your group number.) Copy all available parts of the program Save as local object Exchange table SBOOK for STICKET Exchange the archiving object BC_SBOOK for ZBCSTICKxx Note: Pay attention to upper/lower case 1-1-1 to 1-1-4 see example solution: Program ZZBC670_Archiving

2-1

Tools, ABAP Workbench, Development, ABAP Editor Enter SBOOKD, Copy button. Enter ZBCSTICKxxD. (xx represents your group number.) Copy all available parts of the program Save as local object Exchange table SBOOK for STICKET Exchange archiving object BC_SBOOK for ZBCSTICKxx Note: Pay attention to upper/lower case 2-1-1 to 2-1-3 see example solution: Program ZZBC670_Delete

REPORT ZZBC670_archivieren. * data declaration TABLES: STICKET. DATA: BUTTON(1) TYPE C, CREATE(1) TYPE C VALUE 'X', NO_DELETE(1) TYPE C VALUE 'X', HANDLE LIKE SY-TABIX, STICKET_ITAB TYPE TABLE OF STICKET WITH HEADER LINE. * selection criteria and parameters SELECTION-SCREEN BEGIN OF BLOCK ARCH_BOOKING WITH FRAME TITLE TEXT-101. SELECT-OPTIONS: O_CARRID FOR STICKET-CARRID DEFAULT 'LH ', O_BOOKID FOR STICKET-BOOKID. SELECTION-SCREEN END OF BLOCK ARCH_BOOKING.

(C) SAP AG

BC670

68

SELECTION-SCREEN BEGIN OF BLOCK ARCH_CONTROL WITH FRAME TITLE TEXT-102. PARAMETERS: NO_FILE LIKE BUTTON RADIOBUTTON GROUP RADI, DEL_TEST LIKE BUTTON RADIOBUTTON GROUP RADI DEFAULT 'X', DEL_PROD LIKE BUTTON RADIOBUTTON GROUP RADI. SELECTION-SCREEN END OF BLOCK ARCH_CONTROL. PARAMETERS COMMENTS TYPE ADMI_TEXT LOWER CASE DEFAULT 'This is test data for archiving with BC_SBOOK'(103). * create cursor for data selection DATA: DB_CURSOR TYPE CURSOR. OPEN CURSOR WITH HOLD DB_CURSOR FOR SELECT * FROM STICKET WHERE CARRID IN O_CARRID AND BOOKID IN O_BOOKID. * build ADK parameters from chosen button IF NO_FILE = 'X'. CREATE = ' '. NO_DELETE = ' '. ENDIF. IF DEL_TEST = 'X'. CREATE = 'X'. NO_DELETE = 'X'. ENDIF. IF DEL_PROD = 'X'. CREATE = 'X'. NO_DELETE = ' '. ENDIF. * open a new archive session to archive data CALL FUNCTION 'ARCHIVE_OPEN_FOR_WRITE' EXPORTING CALL_DELETE_JOB_IN_TEST_MODE = NO_DELETE COMMENTS = COMMENTS CREATE_ARCHIVE_FILE = CREATE OBJECT = 'ZBCSTICK20' IMPORTING ARCHIVE_HANDLE = HANDLE. DO. * get next records (up to 100) FETCH NEXT CURSOR DB_CURSOR INTO TABLE STICKET_ITAB PACKAGE SIZE 100. IF SY-SUBRC NE 0. EXIT. ENDIF. * initialize a new data object CALL FUNCTION 'ARCHIVE_NEW_OBJECT' EXPORTING ARCHIVE_HANDLE = HANDLE. * put data records into ADK's data container CALL FUNCTION 'ARCHIVE_PUT_TABLE' EXPORTING ARCHIVE_HANDLE = HANDLE RECORD_STRUCTURE = 'STICKET' TABLES TABLE = STICKET_ITAB. * write data object into the archive file CALL FUNCTION 'ARCHIVE_SAVE_OBJECT' EXPORTING ARCHIVE_HANDLE = HANDLE. ENDDO. * close database cursor CLOSE CURSOR DB_CURSOR. * create the default spool list CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS' EXPORTING ARCHIVE_HANDLE = HANDLE. * close the archive session CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING ARCHIVE_HANDLE = HANDLE.

(C) SAP AG

BC670

69

REPORT ZZBC670_LOESCHEN. * data declaration CONSTANTS: OBJECT LIKE ARCH_OBJ-OBJECT VALUE 'ZBCSTICK20'. DATA: HANDLE LIKE SY-TABIX, BUFFER TYPE ARC_BUFFER, STICKET_WA LIKE STICKET, STICKET_ITAB TYPE TABLE OF STICKET, RECORD_ITAB TYPE TABLE OF STICKET, COMMIT_CNT LIKE ARCH_USR-ARCH_COMIT, OBJECT_CNT TYPE I, SUM_OBJECTS TYPE I VALUE 0, STAT_ITAB TYPE TABLE OF ARCH_STAT, TABFIELD LIKE ARCH_STAT. PARAMETERS: TESTRUN DEFAULT 'X' AS CHECKBOX. " from database * open a new archive session to delete data CALL FUNCTION 'ARCHIVE_OPEN_FOR_DELETE' EXPORTING OBJECT = OBJECT TEST_MODE = TESTRUN IMPORTING ARCHIVE_HANDLE = HANDLE EXCEPTIONS OTHERS = 01. IF SY-SUBRC <> 0. WRITE / 'No file can be accessed'(001). EXIT. ENDIF. * get customizing data from the archive object CALL FUNCTION 'ARCHIVE_GET_CUSTOMIZING_DATA' EXPORTING OBJECT = OBJECT IMPORTING COMMIT_COUNT_FOR_DELETE_PRG = COMMIT_CNT. * loop to get the next data object from the archive file(s) CLEAR OBJECT_CNT. DO. ADD 1 TO OBJECT_CNT. CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT' EXPORTING ARCHIVE_HANDLE = HANDLE EXCEPTIONS END_OF_FILE = 01. IF SY-SUBRC = 1. EXIT. ENDIF. CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = HANDLE RECORD_STRUCTURE = 'STICKET' ALL_RECORDS_OF_OBJECT = 'X ' TABLES TABLE = RECORD_ITAB. APPEND LINES OF RECORD_ITAB TO STICKET_ITAB. IF TESTRUN IS INITIAL AND OBJECT_CNT = COMMIT_CNT. PERFORM DELETE_FROM_TABLE. " actual delete from database CLEAR OBJECT_CNT. " restart counting up to ENDIF. " value of commit counter ENDDO. IF TESTRUN IS INITIAL AND OBJECT_CNT > 1. " do not delete

(C) SAP AG

BC670

70

PERFORM DELETE_FROM_TABLE. ENDIF.

" deleting last package

* provide statistics TABFIELD-TABNAME = ' '. TABFIELD-COUNT = SUM_OBJECTS. APPEND TABFIELD TO STAT_ITAB. TABFIELD-TABNAME = 'STICKET'. APPEND TABFIELD TO STAT_ITAB. CALL FUNCTION 'ARCHIVE_GIVE_STATISTICS' EXPORTING ARCHIVE_HANDLE = HANDLE TABLES TABLE = STAT_ITAB. * write statistics CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS' EXPORTING ARCHIVE_HANDLE = HANDLE STATISTICS_ONLY_PER_FILE = 'X'. * close the archive session CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING ARCHIVE_HANDLE = HANDLE. *---------------------------------------------------------------------* * FORM DELETE_FROM_TABLE * *---------------------------------------------------------------------* * global: STICKET_itab, sum_objects *---------------------------------------------------------------------* FORM DELETE_FROM_TABLE. DATA: TABCOUNT TYPE I VALUE 0. DELETE STICKET FROM TABLE STICKET_ITAB. " delete job restartable COMMIT WORK. DESCRIBE TABLE STICKET_ITAB LINES TABCOUNT. SUM_OBJECTS = SUM_OBJECTS + TABCOUNT. REFRESH STICKET_ITAB. ENDFORM. " DELETE_FROM_TABLE

(C) SAP AG

BC670

71

Unit: Data Archiving Programming Logic Topic: Customizing and testing the archiving object

1-1

Create archiving object ZBCSTICKxx for STICKET. 1-1-1 Call transaction AOBJ Button <New entries > Object name: ZBCSTICKxx / Text: Archiving object for STICKET/Group xx 1-1-2 Write program: ZBCSTICKxxA / Delete program: ZBCSTICKxxD Save archiving object Return to initial screen 1-1-3 Flag the archiving object ZBCSTICKxx Double click on the dialog structure 'structure definition' Enter STICKET in the field Segment Save the archiving object Return to initial screen 1-1-4 Flag the archiving object ZBCSTICKxx Double click on the dialog structure 'Customizing settings' 1-1-4-1 1-1-4-2 1-1-4-3 1-1-4-4 Enter logical filename: Archive_data_file Enter 'Size of archive file': Size in MB 100 No entry under connection to archive system Entry under delete program settings: Mark Not scheduled Entry for test run variants: TESTxx Entry for production run variants: PRODxx. For both variants: Button <Variants> Supply the variants with suitable deletion indicator: Test X Productive: no entry

(C) SAP AG

BC670

72

2.1

Tools, administration, management, Data Archiving. Enter archiving object ZBCSTICKxx Test archiving progam: Button <Archiving> Maintain variant groupxx; the course instructor will tell you which data is to be archived Return to initial screen 'Create archive files' Button <Start date>

Choose: Immediately Save and return to initial screen 'Create archive files' Button <Spoolparameter> Printer: LP01 Hardware type: printer Save and return to initial screen 'Create archive files' Button <execute> The system will create the archiving jobs. Monitor jobs with button <Job overview> Return to screen: Archive management: entry screen Test delete progam: Button <Delete> Start data 'immediately' and maintain spool parameter with LP01 as above Button 'Archive selection' From the popup which appears, select your own archiving session Save Button <execute> The system will create the delete jobs. Monitor jobs with button <Job overview > Return to screen: Archive management: entry screen 2.2 Additional exercise: Displaying archived data using SAP AS 2.2.1 Create archive information structure for object ZBCSTICKXX. Button<Info system> in transaction SARA Button <Customizing> Entry name TASBCSTICKXX Button<Create> Field catalog: BCSTICKXX Transfer fields by saving Button <Activate> Return to initial screen in Archive Information System Button <Status per Infostructure> Select Infostructure and Button <Build structure> Button <Archive Explorer> (C) SAP AG BC670 73

Enter ZBCSTICKXX. Infostructure is selected by the system Display data

(C) SAP AG

BC670

74

5
Sequential Read Programs

Contents:
Logic of sequential read progams Logic of reading from archiving classes Creating a sequential read program with and without archiving classes

SAP AG 2002

(C) SAP AG

BC670

5.2
Sequential Read Programs : Unit Objectives

At the conclusion of this unit, you will be able to: Create a sequential read program Display archiving classes in a read program

SAP AG 1999 2002

(C) SAP AG

BC670

5.3
Course Overview Diagram

Course Overview The Data Archiving Process ADK Development Tools Data Archiving Programming Logic Customer-Specific Read Programs Business Views in SAP AS Appendix

SAP AG 2002

(C) SAP AG

BC670

5.4
Sequential Read Programs: Business Scenario

You have to create customer-specific read programs for your own archiving objects, as well as for standard R/3 archiving objects. The programmers have to learn the logic of read programs. The new read programs must also be able to read and display archiving classes.

SAP AG 1999 2002

(C) SAP AG

BC670

5.5
Overview: Access to Archived Data

Direct access to a document from the application (FI_DOCUMNT and MM_MATBEL) Archive Information System (SAP AS) ABAP Evaluation reports

retrieved from the application customer-specific reports

SAP AG 2002 1999

Single document access from the application is available for FI DOCUMNT, and from Release 4.0, from MATBEL. Programs for reporting archive files are provided by the application and are available in transaction SARA.

(C) SAP AG

BC670

5.6
Sequential Read Programming Logic

Archive_open_for_read Archive_get_next_object

Archive_get_next_record

Archive_close_file

SAP AG 2002 1999

The read logic in delete programs is similar to that in read programs. The function module ARCHIVE_OPEN_FOR_DELETE is replaced with ARCHIVE_OPEN_FOR_READ.

(C) SAP AG

BC670

5.7
ADK API: ARCHIVE_OPEN_FOR_READ

Interface parameter export

object (archiving object)

Interface parameter import

archive_handle (pointer to the selected archiving sessions)

Function module functionality:


Authority-Check on S_ARCHIVE Prepares and dsiplays a dialog box that displays all archiving sessions: The user selects the relevant archiving session. Creates Archive_handle

SAP AG 2002

ADK has multi-instance capability. Each handle addresses an instance. In a program, more than one archive can be read in parallel. The handle, as it is used in ADK, can be compared to the file handle in the file management system. In addition to the S_ARCHIVE authorization check, there may be application-specific authorizations that should be checked.

(C) SAP AG

BC670

5.8
ADK API: ARCHIVE_GET_NEXT_OBJECT

Interface parameter export

archive_handle (pointer to the selected archiving sessions)

Interface parameter import


object_offset (where is the object in the archive file) archive_name (key to the archive file)

Function module functions::

Reads the first or next data object and transfers the data from the archive to ADK.

Exception: End of file


SAP AG 2002

The function module reads the next data object in the archive file. Information such as object_offset and archive_name are necessary if SAP AS is to be able to access a document directly. The information defined here is relevant for direct access to a document using the function module ARCHIVE_READ_OBJECT (see unit Direct access via SAP AS). The function module operates in the same way, regardless of whether it is called from a read, delete or reload program.

(C) SAP AG

BC670

5.9
ADK API: ARCHIVE_GET_NEXT_RECORD

Interface parameter export

archive_handle (pointer to the selected archiving sessions)

Interface parameter import


record (content of an individual table record in the object) record_structure (table name, from which record is taken)

Function module functionality :

Retrieves the table records belonging to an object in a buffer area

Exception: End of object

SAP AG 2002

(C) SAP AG

BC670

5.10
ADK API: ARCHIVE_GET_TABLE (1)

Interface parameter import


archive_handle record_structure all_records_of_object automatic_conversion

Interface Table

Table

Function module functions


This function module was developed to simplify the implementatio of n the read operation. Several data records are read for the struct re that u is specified with record_structure and then stored in an interna table. l

SAP AG 2002

The parameter record_structure transfers the name of the structure or table containing the objects to be read. ALL_RECORDS_OF_OBJECT = ' ' In this case, the function module functions in a similar way to the function module ARCHIVE_GET_NEXT_STRUCT_SPECIF. All records are simply read sequentially for the specified structure until the structure changes. All read data records are placed in the internal table TABLE. Reading continues with ARCHIVE_GET_NEXT_RECORD. This automatically reads the next unread data record. Similarly, when the function module ARCHIVE_GET_TABLE is called, it reads from the next unread data record. ALL_RECORDS_OF_OBJECT =X In this case, the function module reads all data records for the specified structure in the whole data object. The data objects read are stored in table TABLE. It does not matter if between the data records with the specified structure RECORD_STRUCTURE there are data records with other structures. All data records for the specified structure are collected in the current data object, regardless of their place in the current data object. Further reading is possible with ARCHIVE_GET_NEXT_RECORD. In this case, regardless of the data records that were read with ARCHIVE_GET_TABLE; the next data record is read from when ARCHIVE_GET_NEXT_RECORD was called. If ARCHIVE_GET_NEXT_RECORD was not yet called, the first data record is read.

(C) SAP AG

BC670

10

5.11 Comparison ARCHIVE_GET_RECORD - ARCHIVE_GET_TABLE

Reads one record More coding required, since CASE query must be processed Operations in main memory (Move data to work area) ->lowers performance

Reads array of records By default, supplies all records of the same type that occur in sequence in the ADK file in a file -> Less coding Performance improved with mass processing

SAP AG 2002

The parameter all records enables all records to be read that belong to a specific type, regardless of whether they are arranged sequentially in the ADK file or not. The records are made available to the read program in the same sequence as they were transferred by PUT_RECORD or PUT_TABLE.

(C) SAP AG

BC670

11

5.12
ADK API: ARCHIVE_CLOSE_FILE

Interface parameter export

archive_handle (pointer to the selected archiving sessions)

Function module functionality :


Closes the archive file Releases the resources of an archive handle

SAP AG 2002

The archive handle is invalid after the function module is run and cannot be reused. Each additional operation with this handle triggers the exception WRONG_ACCESS_TO_ARCHIVE .

(C) SAP AG

BC670

12

5.13
Sequential Access Logic (1)
ADK/AOBJ: Definition: Archiving object X

A Table B Table C Table


1

ARCHIVE_OPEN_FOR_READ

ABAP program with internal tables


A

Data container with current data object A B B B C C


4

ARCHIVE_GET_NEXT_RECORD 3

ARCHIVE_GET_NEXT_RECORD 3

Archive file
ARCHIVE_GET_NEXT_OBJECT
2

ARCHIVE_GET_NEXT_RECORD

ARCHIVE_CLOSE_FILE

SAP AG 2002

Step 1: Check whether the named archive file is available. Open files. Step 2: The first object is transferred from the archive file to an area in the main memory that is only accessible to ADK. Step 3 From the main memory area, the object is transferred record by record to a variable of the read program. The contents of the variables of the read program. The contents of the variables can then be processed as required. You can work with ARCHIVE_GET_TABLE as well as with ARCHIVE_GET_NEXT_RECORD.

(C) SAP AG

BC670

13

5.14
Sequential Access Logic (2)
Declaration Internal tables (itabA, itabB, itabC) open existing archive file(s) for read access ARCHIVE_OPEN_FOR_READ export: archiving object import: archive_handle read next object from archive file in ADK data container ARCHIVE_GET_NEXT_OBJECT export: archive_handle [import: archive_key, offset] read next record from container in ABAP report ARCHIVE_GET_NEXT_RECORD export: archive_handle import: record_structure, record write record in list close archive files ARCHIVE_CLOSE_FILE export: archive_handle
SAP AG 2002

loop as long as records are available

loop as long as data objects are available

The function module ARCHIVE_OPEN_FOR_READ supplies the data sequentially according to the order in which they are stored in the ADK archive file. If you want a different order, you must sort them in the main memory.

(C) SAP AG

BC670

14

5.15
Example Report SBOOKR (1)
report sbookr. * data declaration data: handle like sy-tabix, buffer like arc_buffer, sbook_wa like sbook, number_of_records_read type i. * open existing archive files call function 'ARCHIVE_OPEN_FOR_READ' exporting object = 'BC_SBOOK' importing archive_handle = handle exceptions others = 1.

if sy-subrc <> 0. write: / 'File open error'.


SAP AG 2002

(C) SAP AG

BC670

15

5.16
Example Report SBOOKR (2)
exit. endif. clear number_of_records_read. * loop to get the next data object from the archive file (s) do. call function 'ARCHIVE_GET_NEXT_OBJECT' exporting archive_handle = handle exceptions end_of_file = 1 others = 2. if sy-subrc <> 0. exit. endif. * get data records from the data container do.

SAP AG 2002

If the last archive file was read to the end, end of file is triggered.

(C) SAP AG

BC670

16

5.17
Example Report SBOOKR (3)

call function 'ARCHIVE_GET_NEXT_RECORD' exporting archive_handle = handle importing record = buffer-segment record_structure = buffer-rname exceptions end_of_object = 1 others = 2. if sy-subrc <> 0. exit. endif. add 1 to number_of_records_read. enddo. enddo.

SAP AG 2002

In step 3, the data from the main memory is transferred to a work area in the program using ARCHIVE_GET_NEXT_RECORD. The data in one object belongs to various tables.

The work area in our example is arc_buffer. Arc_buffer is split into buffer_rname, which contains the name of the table to which the transferred record belongs, and buffer_segment, in which the data is to be stored. Up to Release 4.6C, the segments have a size of 8K.

(C) SAP AG

BC670

17

5.18
Example Report SBOOKR (4)

write: / 'Number of records read:', number_of_records_read. uline. write / 'Last record read:'. case buffer-rname. when 'SBOOK'. sbook_wa = buffer-segment. write: / 'CARRID :', sbook_wa-carrid, / 'BOOKID :', sbook_wa-bookid, / 'CONNID :', sbook_wa-connid, / 'FLDATE :', sbook_wa-fldate, / 'CUSTOMID :', sbook_wa-customid, / 'ORDER_DATE:', sbook_wa-order_date, / '...'. * when ... * If the archive object contained more than one table * (different buffer-rname), more cases would be needed. endcase.

SAP AG 2002

Buffer_segment is an unstructured area from which the data must be transferred to a structured work area. How the work area is defined depends on the table record that is currently being read. If you are working with the function module ARCHIVE_GET_TABLE, the transfer to a work area is omitted since the internal table forms the work area and includes the correct records from the table for an object.

(C) SAP AG

BC670

18

5.19
Example Report SBOOKR (5)

* close the archive session call function 'ARCHIVE_CLOSE_FILE' exporting archive_handle = handle.

SAP AG 2002

(C) SAP AG

BC670

19

5.20
Programming Logic: Read Archiving Classes

Archive_open_for_read

Archive_get_next_object

Archive_get_next_record CU_CONFIG_READ_ARCHIVE_OBJECT (Archiving class Variant configuration) TEXT_SELECT_ ARCHIVE_OBJECT (Archiving class TEXT) READ_TEXT (Archiving class TEXT)

Archive_close_file

SAP AG 2002 1999

The data that was stored together with an archiving object using the archiving module or an archiving class cannot be accessed directly by ADK. The data is transferred to ADK by the read module in the archiving class.

(C) SAP AG

BC670

20

5.21
Where to Find Archiving Classes in R/3

From Release 3.1G Management in Transaction ACLA From Release 4.6C Report Class_Browser

Naming convention for archiving function module

<archiving class>_archive_object

No naming convention for read function module

Possible name <archiving class>_read_archive_object Identical to the read function module, which also reads the database: For example: Read_text for archiving class texts

SAP AG 2002 1999

Report Class_Table_Search enables the assignment of table and archiving class. It outputs not only the respective archiving classes but also the relevant function group. The listed naming conventions are applicable within the function group for the function modules. Function module for reading an archiving class: There is no naming convention for the function module for reading data. Procedure 1. Specify the function group of the archiving class in transaction ACLA. 2. Determine the function modules of the function group. 3. Determine the read function module using the program documentation.

Function module for archiving an archiving class: To call the function module, choose Tools -> ABAP Workbench -> Development -> Function Builder. Use the naming convention described above.

(C) SAP AG

BC670

21

5.22
Reading Archiving Classes

Determining the function group of the archiving class


Release 3.0: Transaction AOBJ Release 3.1 bis 4.6: Transaction ACLA

Determining the read module of the rachiving class


Transaction SE80, enter function group Display function modules Read documentation

SAP AG 2002

Note: The Archive_handle must also be included with the function modules for the archiving classes.

(C) SAP AG

BC670

22

5.23
Read Archiving Classes (2)

Clarify which fields are to be displayed

What fields does the used structure contain?

Analyze the archived data using the archiving progam Determine where data is to be read

Logical assignment of contents to the archived tables

Determine where data is to be displayed

Logical assignment of contents to the archived tables

SAP AG 2002 1999

There is a link to the function module documentation which explains the interface. The function module must be released. The interfaces can be complex - for example, the archiving class TEXT supplies data for headers and line items. Logical assignment of data: Position texts from orders can, for example, only be read if the relevant order positions are available in the program.

(C) SAP AG

BC670

23

5.24
Read Archiving Classes (3)

Build the archiving class into the relevant report


Optional: Create checkbox field Output yes/no. Create necessary data structures. Read data using function module. If necessary: Collect data in advance using the selection module Display the data in list format.

SAP AG 2002 1999

You can use the documentation to determine which data structures are to be created and the interface for the read module. You are advised to make archiving class data available as an option by adding a checkbox, rather than having to process it in the read program, since, generally, this data is not of interest to all users.

(C) SAP AG

BC670

24

5.25
Example: Output Texts (1)

* DEFINITION DATA * Texts / Classes tables: thead, tline. types: begin of vb_text, head like thead, lines like tline occurs 5, end of vb_text. data: l_tname like thead-tdname occurs 0 with header line, l_text type vb_text occurs 0 with header line, xvbbk like thead occurs 0 with header line, xvbbp like thead occurs 0 with header line. data: xlines like tline.

SAP AG 2002

(C) SAP AG

BC670

25

5.26
Example: Output Texts (2)
* Select the texts in an internal table after * Calling the function module ARCHIVE_GET_NEXT_OBJECT call function 'TEXT_SELECT_ARCHIVE_OBJECT' exporting archive_handle = archive_handle object = 'VBBK' text object header tables selections = xvbbk. call function 'TEXT_SELECT_ARCHIVE_OBJECT' exporting archive_handle = archive_handle object = 'VBBP' tables selections = xvbbp. loop at xvbbk. xvbbp = xvbbk. append xvbbp. endloop.
SAP AG 2002

text object line item

(C) SAP AG

BC670

26

5.27
Example: Output Texts (3)

* Read the text data and output in list format if text = 'X'. format color col_heading intensified. write: /2 text-130. format color col_background intensified. write: / sy-uline(105). format color col_heading intensified. write: / sy-vline, 2 text-135, 9 sy-vline, 10 text-140, 105 sy-vline.

SAP AG 2002

(C) SAP AG

BC670

27

5.28
Example: Output Texts (4)
sort xvbbp. loop at xvbbp. call function 'TEXT_READ_ARCHIVE_OBJECT' exporting archive_handle = archive_handle id = xvbbp-tdid language = xvbbp-tdspras name = xvbbp-tdname object = xvbbp-tdobject client = sy-mandt importing header = l_text-head tables lines = l_text-lines exceptions not_found =1 wrong_access_to_archive = 2 others = 3.
SAP AG 2002

(C) SAP AG

BC670

28

5.29
Example: Output Texts (5)
format color col_background intensified off. i = i + 1. j = i mod 2. if j = 0. format color col_normal intensified off. else. format color col_normal intensified. endif. write: / sy-vline, 2 l_text-head-tdobject, 9 sy-vline. if not l_text-lines[] is initial. loop at l_text-lines into xlines. write: 10 xlines-tdline. endloop. write: 105 sy-vline. endif. endloop. write: / sy-uline(105). endif. endform.
SAP AG 2002

(C) SAP AG

BC670

29

5.30
Archived Data and Data from the Online Database

Selection and output of data from the online database Create checkbox: Do you want to edit archived data in the report? Optional:

Call ADK function module to read archived data Output archived data

SAP AG 2002

You can use check boxes to make processing as sophisticated as you want.

(C) SAP AG

BC670

30

5.31
Exercise Read Sales Activities - Data Model
VBUK Header status VBELN

VBKA Sales activity VBELN

Change documents

VBUV Incomplete. log

VBFA Document flow

VBPA

NAST Messages

Address list
SADLSTWU SADLSTADM ...

SAPScript texts

VBPA2 Partner

Central address management SAP AG 2002

(C) SAP AG

BC670

31

5.32
Exercise Read Sales Activities: Table Structure
VBKA
VBELN ERDAT ERZET ERNAM AEDAT AEZET AENAM KTAAR VBTYP ...... SD document no. of a sales activity in sales support Date on which the record was created Entry time Name of person who created the object Last changed on Time last change was made Name of person who changed object Sales Activity Type for Sales Support SD document category

VBPA
VBELN POSNR PARVW KUNNR LIFNR PERNR PARNR ADRNR ABLAD LAND1 ADRDA Sales document number Item number of the SD document Partner function Customer number Account number of vendor or creditor Personnel Number Number of contact person Address Unloading point Country key Address indicator

VBFA
VBELV POSNV VBELN POSNN VBTYP_N RFMNG MEINS Preceding sales and distribution document Preceding item of an SD document Subsequent sales and distribution document Subsequent item of an SD document Document category of subsequent document Referenced quantity in base unit of measure Base unit of measure

2002 SAP AG

(C) SAP AG

BC670

32

5.33
Sequential Read Programs: Unit Conclusion

You are now able to: Create sequential read programs for an archiving object Report archiving classes belonging to an archiving object in read programs

SAP AG 2002

(C) SAP AG

BC670

33

5.34Customer-specific reporting Exercises Unit: Customer-Specific Reporting Topic: Program for archived sales activities, Read without archiving classes
At the conclusion of these exercises, you will be able to: Create a program that reads the archived sales activities without using archiving classes

You have archived sales activities and want to create a reporting program for them.

1-1

Reporting program for archived sales activities Copy the report Z00VBKAREAD to your report ZxxVBKAREAD This report already contains a column header. The program also contains data definitions for all of the tables used in SD_VBKAD

1-2

Use the list header to familiarize yourself with the list layout. Look at the SD_VBKA data model on the last page in this unit. Here, you can also find the definition structure for tables VBKA, VBPA, VBFA.

1-3

Build the function module ARCHIVE_OPEN_FOR_READ into your program

1-4

Build the function module ARCHIVE_GET_NEXT_OBJECT into your program

(C) SAP AG

BC670

34

1-5

With the help of the function module ARCHIVE_GET_TABLE, read each table from SD_VBKA . Record_structure is respectively:VBKA VBFA VBPA Call the function module 3 times with each new Record_structure. (Export parameter record_structure) Process all of the records belonging to an object (export parameter all_record_of_object). Pass the archive_handle (export parameter archive_handle). Import a table with the hitlists of the individual table records. The table, to which the data is transferred, is for VBFA and VBPA the internal table 'X<original table name>'. For VBKA, the structure YVBKA is imported. YVBKA is then assigned to XVBKA.

1-6

Close the archive file with the function module ARCHIVE_CLOSE_FILE

1-7

Output the data in the format of a layout in a form routine OUTPUT_DOC_INFO.

1-7-1 Output the data from XVBKA: the required names can be found in the appendix. 'document no.' starting at position 2 'sales activity type' starting at position 14 'creation date' starting at position 21 'created by' starting at position 40 'change date' starting at position 56

1-7-2 Loop via XVBPA 'partner function' starting at position 21 'contact person number' starting at position 40 'address' starting at position 47

1-7-3 Loop via XVBFA 'document number of subsequent document' starting at position 60 'type of subsequent document' starting at position 71

(C) SAP AG

BC670

35

2-1

Test the program in transaction SE38

3-1

If the data is output correctly, enter your program in transaction AOBJ as a read program for SD_VBKA and test it again by calling it from transaction SARA.

(C) SAP AG

BC670

36

Unit: Customer-Specific Reporting Topic: Program for sales activities for a sales order Read with archiving classes
At the conclusion of these exercises, you will be able to: Create a program to read archived sales activities using the archiving class TEXT

You have archived sales activities and want to create a reporting program for them.

1-1

Output archived sales activities with texts Copy the program Z00VBKAREADTEXT to your program ZxxVBKAREADTEXT

1-2

Build into the program (in the output form routine after the output of the last table) the reporting of texts that have been archived with a sales activity.

1-2-1 First collect the texts belonging to an object by calling the function module SELECT_TEXT_ARCHIVE_OBJECT Export parameter: Archive_handle Import parameter: Entries - Text_entries Table: txt_tab

(C) SAP AG

BC670

37

1-3

If the call is successful and text_entries > 0 Read the actual texts Loop via table txt_tab For each record, call function module TEXT_READ_ARCHIVE_OBJECT Export parameter: ID: txt_tab.tdid language: txt_tab-tdspras name: txt_tab-tdname object: tst_tab-tdobject archive_handle A table (lines) is returned containing the texts found. It is read according to text lines. .

1-4

Output the data: Loop via Text_lines Text at position 4 (text_lines-tdline)

(C) SAP AG

BC670

38

5.35Customer-specific reporting Solutions Unit: Customer-Specific Reporting Topic: Program for archived sales activities, Read without archiving classes

1-1

Tools, ABAP Workbench, Development, ABAP Editor Copy Z00VBKAREAD to ZxxVBKAREAD. (XX represents your group number)

1-2

Information in appendix

1-3 to 1-7

See sample program ZSDVBKAREAD

2-1

Tools, ABAP Workbench, Development, ABAP Editor Enter ZxxVBKAREAD. (XX represents your group number.) Execute program

3-1

Call transaction AOBJ Mark SD_VBKA Dialog structure read progams Enter ZxxSDVBKA Save

(C) SAP AG

BC670

39

REPORT ZSDVBKAREAD . *&---------------------------------------------------------------------* *& archive read program for sales activites *& * *&---------------------------------------------------------------------* TABLES: VBKA, VBFA, VBPA. DATA: "XVBKA LIKE VBKA OCCURS 0 WITH HEADER LINE, YVBKA LIKE VBKA OCCURS 0 WITH HEADER LINE, XVBFA LIKE VBFA OCCURS 0 WITH HEADER LINE, YVBFA LIKE VBFA OCCURS 0 WITH HEADER LINE, XVBPA LIKE VBPA OCCURS 0 WITH HEADER LINE, BEGIN OF XVBKA. INCLUDE STRUCTURE VBKA. DATA: END OF XVBKA. DATA: AR_HANDLE TYPE SY-TABIX. CALL FUNCTION 'ARCHIVE_OPEN_FOR_READ' EXPORTING OBJECT = 'SD_VBKA' IMPORTING ARCHIVE_HANDLE = AR_HANDLE EXCEPTIONS OTHERS = 8. IF SY-SUBRC <> 0. WRITE: / 'error open file'. STOP. ENDIF. WRITE /. DO. CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT' EXPORTING ARCHIVE_HANDLE = AR_HANDLE EXCEPTIONS OTHERS = 6. . IF SY-SUBRC <> 0. EXIT. ENDIF. * * * * * Table VBKA has only one record for each sales activity. In the data structure you find VBKA AFTER VBUK. Therefore you must read several records, im you use function module 'ARCHIVE_GET_NEXT_RECORD'. The program performance will be better, if you use function module ARCHIVE_GET_TABLE to find and read the VBKA record. CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE RECORD_STRUCTURE = 'VBKA' ALL_RECORDS_OF_OBJECT = 'X' TABLES TABLE = YVBKA EXCEPTIONS OTHERS = 4. READ TABLE YVBKA INDEX 1 INTO XVBKA. CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE *

(C) SAP AG

BC670

40

RECORD_STRUCTURE = 'VBFA' ALL_RECORDS_OF_OBJECT = 'X' TABLES TABLE = XVBFA EXCEPTIONS OTHERS = 4. CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE RECORD_STRUCTURE = 'VBPA' ALL_RECORDS_OF_OBJECT = 'X' TABLES TABLE = XVBPA EXCEPTIONS OTHERS = 4. PERFORM OUTPUT_DOC_INFO. ENDDO. CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE. FORM OUTPUT_DOC_INFO. WRITE: /1 XVBKA-VBELN, 15 XVBKA-KTAAR, 22 XVBKA-ERDAT, 40 XVBKA-ERNAM, 56 XVBKA-AEDAT. LOOP AT XVBPA. WRITE: /22 XVBPA-PARVW, 40 XVBPA-PARNR, 56 XVBPA-ADRNR. ENDLOOP. LOOP AT XVBFA. WRITE: /56 XVBFA-VBELN, 71 XVBFA-VBTYP_N. ENDLOOP. ENDFORM.

(C) SAP AG

BC670

41

Unit: Customer-specific reporting Topic: Program for archived sales activities Read with archiving classes

1-1

Tools, ABAP Workbench, Development, ABAP Editor Copy Z00VBKAREADTEXT to ZxxVBKAREADTEXT.(XX represents your group number)

1-2 to 1-4

see sample program ZSDVBKAREADTEXT

(C) SAP AG

BC670

42

REPORT ZSDVBKAREADTEXT . *&---------------------------------------------------------------------* *& archive read program for sales activites * *& * *&---------------------------------------------------------------------* TABLES: VBKA, VBFA, VBPA. PARAMETERS: AUSGTEXT AS CHECKBOX. DATA: YVBKA LIKE VBKA OCCURS 0 WITH HEADER LINE, XVBFA LIKE VBFA OCCURS 0 WITH HEADER LINE, YVBFA LIKE VBFA OCCURS 0 WITH HEADER LINE, XVBPA LIKE VBPA OCCURS 0 WITH HEADER LINE, BEGIN OF XVBKA. INCLUDE STRUCTURE VBKA. DATA: END OF XVBKA. DATA: TXT_TAB LIKE THEAD OCCURS 0 WITH HEADER LINE. DATA: TEXT_LINES LIKE TLINE OCCURS 0 WITH HEADER LINE. DATA: TEXT_ENTRIES LIKE SY-TFILL. DATA: AR_HANDLE TYPE SY-TABIX. CALL FUNCTION 'ARCHIVE_OPEN_FOR_READ' EXPORTING OBJECT = 'SD_VBKA' IMPORTING ARCHIVE_HANDLE = AR_HANDLE EXCEPTIONS OTHERS = 8. IF SY-SUBRC <> 0. WRITE: / 'no archive files'. STOP. ENDIF. WRITE /. DO. CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT' EXPORTING ARCHIVE_HANDLE = AR_HANDLE EXCEPTIONS OTHERS = 6. IF SY-SUBRC <> 0. WRITE: / ' no object'. EXIT. ENDIF. * * * * * Table VBKA has only one record for each sales activity. In the data structure you find VBKA AFTER VBUK. Therefore you must read several records, im you use function module 'ARCHIVE_GET_NEXT_RECORD'. The program performance will be better, if you use function module ARCHIVE_GET_TABLE to find and read the VBKA record. CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE RECORD_STRUCTURE = 'VBKA' ALL_RECORDS_OF_OBJECT = 'X' TABLES TABLE = YVBKA EXCEPTIONS

(C) SAP AG

BC670

43

OTHERS XVBKA = YVBKA.

= 4.

CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE RECORD_STRUCTURE = 'VBFA' ALL_RECORDS_OF_OBJECT = 'X' TABLES TABLE = XVBFA EXCEPTIONS OTHERS = 4. CALL FUNCTION 'ARCHIVE_GET_TABLE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE RECORD_STRUCTURE = 'VBPA' ALL_RECORDS_OF_OBJECT = 'X' TABLES TABLE = XVBPA EXCEPTIONS OTHERS = 4. PERFORM OUTPUT_DOC_INFO. ENDDO. CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING ARCHIVE_HANDLE = AR_HANDLE. *---------------------------------------------------------------------* * FORM OUTPUT_DOC_INFO *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* FORM OUTPUT_DOC_INFO. DATA: XSTADM_LINES TYPE N. DATA: TEXTNAME LIKE THEAD-TDNAME. WRITE: /1 XVBKA-VBELN, 15 XVBKA-KTAAR, 22 XVBKA-ERDAT, 40 XVBKA-ERNAM, 56 XVBKA-AEDAT. LOOP AT XVBPA. WRITE: /22 XVBPA-PARVW, 40 XVBPA-PARNR, 56 XVBPA-ADRNR. ENDLOOP. LOOP AT XVBFA. WRITE: /56 XVBFA-VBELN, 71 XVBFA-VBTYP_N. ENDLOOP. IF AUSGTEXT = 'X'. * Select text belonging to the current document CALL FUNCTION 'TEXT_SELECT_ARCHIVE_OBJECT' EXPORTING ARCHIVE_HANDLE = AR_HANDLE IMPORTING ENTRIES = TEXT_ENTRIES TABLES SELECTIONS = TXT_TAB EXCEPTIONS OTHERS = 2. IF TEXT_ENTRIES > 0 AND SY-SUBRC = 0. * loop through all text entries *

(C) SAP AG

BC670

44

LOOP AT TXT_TAB. * Read the text CALL FUNCTION 'TEXT_READ_ARCHIVE_OBJECT' EXPORTING ARCHIVE_HANDLE = AR_HANDLE ID = TXT_TAB-TDID LANGUAGE = TXT_TAB-TDSPRAS NAME = TXT_TAB-TDNAME OBJECT = TXT_TAB-TDOBJECT TABLES LINES = TEXT_LINES EXCEPTIONS OTHERS = 3. * Display the text on screen LOOP AT TEXT_LINES. WRITE: / TEXT_LINES-TDLINE. ENDLOOP. SKIP 3. ENDLOOP. ENDIF. ENDIF. ENDFORM.

(C) SAP AG

BC670

45

6
Direct Read Access to Archived Data

Contents:
Logic of direct read access using SAP AS Creating a business view for MM_MATBEL in SAP AS

SAP AG 2002

(C) SAP AG

BC670

6.2
Direct Read Access: Unit Objectives

At the conclusion of this unit, you will be able to: Create business views for archiving objects in SAP AS

SAP AG 1999 2002

(C) SAP AG

BC670

6.3
Course Overview Diagram

Course Overview The Data Archiving Process ADK Development Tools Data Archiving Programming Logic Customer-Specific Read Programs Business Views in SAP AS Appendix

SAP AG 2002

(C) SAP AG

BC670

6.4
Direct Read Access : Business Scenario

You have to create a business view for an archiving object in SAP AS.

SAP AG 1999 2002

(C) SAP AG

BC670

6.5
Archive Reporting with SAP AS

Methods independent of archiving object Generic solution for presenting archived data Direct single document access Configurable

SAP AG 2002 1999

The archived data can always be presented in a technical view. Business views are available in the standard system for selected objects and customers can create their own additional business views. The available function modules can serve as frameworks. Specific archiving sessions can be selected for reporting purposes. Also, specific archive information structures can be selected as reporting inputs. At technical view level, additional functions such as search, sort and summarize are provided.

(C) SAP AG

BC670

6.6
Field Catalogs

Field catalog

Contains from the archiving objects database tables

Key fields Fields that are important for customers search functionality

Field catalog fields are available to the Archive Information System. Field catalogs are provided by the applications. Customers can define their own field catalogs to meet their specific requirements.

SAP AG 1999 2002

(C) SAP AG

BC670

6.7
Creating Field Catalog for MM_MATBEL

Field catalog for MM_MATBEL

Create field catalog


Fld. catalog Fi-Docs. Zcoitem Mmatbel Description Fi-Docs. Controlling Material docs Arch.object FI_DOCUMNT CO_ITEM MM_MATBEL File D K D Offset D K D

SAP AG 2002

Archive information structures are based on field catalogs. There is one table per archive information structure, which incorporates all records from all of the selected archiving sessions. By making file and offset entries, you can guarantee the uniqueness of the key for all archiving sessions. Explanation of the entries in the slide: FI documents are unique for every application key, as the fiscal year is part of the key. Therefore, the archive key and the offset do not have to be included in the key. In other applications, keys can be reassigned after an archiving session. Therefore, for example in SD, the name of the archive file (which is declared as part of the key in SAP AS), guarantees uniqueness over more than one archiving session. Cost centers may have many line items that do not fit into a data object. In order to keep the key unique, the offset in an archive file is incorporated into a key.

(C) SAP AG

BC670

6.8
Standard Field Catalog MM_MATBEL
Field selection includes all fields that you want to use for your search fld.no.
10 20 25 30 40 50 ..... 110 120 .....

target fld. key


MBLNR MJAHR ZEILE VGART BLDAT BUDAT MATNR WERKS x x x

source tab. source fld.


MSEG MSEG MSEG MKPF MKPF MKPF MSEG MSEG MBLNR MJAHR ZEILE VGART BLDAT BUDAT MATNR WERKS

mand.

When the field catalog is created, the key fields from table MSEG must be assigned to table MKPF using the function additional source fields.
SAP AG 2002 1999

This field catalog contains fields from table MKPF and fields from table MSEG. If more than one table is used, the function additional source fields is used. The field catalog key fields from table MSEG must also be present in table MKPF and are assigned to table MKPF using the function additional source fields.

(C) SAP AG

BC670

6.9
Alternative Field Catalog for MM_MATBEL (2)
The material number is your search criterion. Possible field selection for the field catalog Fld.no. Target fld. Key 10 20 30 matnr mblnr mjahr x x x Source tab. Source fld. mand. mseg mseg mseg matnr mblnr mjahr x

The pointer to additional source fields is omitted.

SAP AG 2002

(C) SAP AG

BC670

6.10
SAP AS Components

SAP R/3 application

customer

sets up

n field catalogs per archiving object carry fields over to n archive information structures based on a field catalog

Reporting program

SAP AG 2002

The field catalogs are assigned to archiving objects. They contain fields from the archiving object tables. These fields can be incorporated in archive information structures. Standard field catalogs are delivered with the archive information system. You should only create customer-specific field catalogs as exceptions. Archive information structures are the foundation for reporting within the Archive Information System. They are defined using the Archive Retrieval Configurator and are based on the field catalogs. Customers incorporate into the archive information structures the key fields that uniquely identify an object and the data fields that meet their information requirements. These fields are filled with the archived data and thereby allow the archive files to be reported. Archive information structures must be activated. When they are activated, a transparent table with defined data structures is created in R/3. A reporting program is also generated. The table is filled with data during the deletion part of the archiving session. The table can also be filled in a separate process as an administrative function. Reporting is based on this data.

(C) SAP AG

BC670

10

6.11
Archive Information Structures

Archive information structure

The archive information structure contains an extract of the archived data. Information structures are dependent on the archiving object . . There can be more than one information structure for each archiving object. There is a transparent database table for each information structure.

SAP AG 2002 1999

Several field catalogs can be defined for one archiving object. Several archive information structures can also be defined for one archiving object. However, an archive information structure always refers to one specific field catalog. Fields used in archive information structures must be contained in the assigned field catalog.

(C) SAP AG

BC670

11

6.12
Filling the Archive Information Structures

R/3 Database

Delete program Delete program

Archive file Archive file

Archive file Archive file

Variant 1: fill during delete run

Variant 2: fill after explicit instruction from SAP AS

SAP AG 2002

Both variants are equally valid. Automatic fill during delete program run: If an information structure is active, it s filled automatically during the archiving sessions delete program run. By explicitly activating and deactivating the information structures before the start of the delete program run, you can specify that only those information structures that are always going to be used as a means of accessing information are to be filled. Explicit instruction from SAP AS: You can fill the archive information structure tables at any time with data from existing archive files. To do this, go to SAP AS administration.

(C) SAP AG

BC670

12

6.13
Data Display in SAP AS

Reporting data from the archive information structure

The structure table entries are displayed on the screen as in SE16. No access to the ADK file is required for this display.

Double-click a table line for direct access to the data object in the ADK archive

The data display is possible for all archiving objects in a tech nical view. This view lists the individual tables with their values. You can program a business view of the data.

SAP AG 2002

The standard system in Release 4.6 contains business views for 14 objects. Further business views are planned. Customer-specific business views can also be created by the customer.

(C) SAP AG

BC670

13

6.14
Reporting Archive Info Structures: Archive Explorer
Transaction SARI selection screen
List for archive info structure T_CO_ORDER Order Cap. ...... to Short text Maximum hits .......... ...... to .......... to ....................

The system generates a reporting program for each information structure Archive access is not required for this step

.................... 500

Trefferliste

Reporting program

List for archive information structureT_CO_ORDER Order 100000 100001 100002 100003 .... Date of Entry 12.10.1998 12.10.1998 12.10.1998 12.10.1998 Short Text service car lot 97-5 repair 76A8/67 98-5 service car lot 97-6 TechEd KA 98

SAP AG 2002

Call transaction SARI Button Archive Explorer Select the desired archiving object and archive information structure. The system displays the table records from the archive information structure table. The display is the same as the table view in transaction SE16.

No access to archive files is required for this list of structure records containing an extract of archived data. From this list you can branch to an objects technical view. This view is possible for all objects that can be accessed in SAP AS.

(C) SAP AG

BC670

14

6.15
Access to Individual Data Objects: Technical View

List for archive information structure T_CO_ORDER Order 100000 100001 100002 100003 .... Date of Entry 12.10.1998 12.10.1998 12.10.1998 12.10.1998 Short Text Service Repair 76A8/67 98-5 Service TechEd KA 98

Display data object from archive: Table view 000143-001CO_ORDER Table AUFK Table COBRA Table COBRB Table COKA 1 1 2 1 Order master data Sett. rule for order settlement Dist. rules sett. rule order Sett. CO-Object: Control data

Display data object Select the desired display function Display master data Technical view X

List for archive info structure T_CO_ORDER Amount in object curr. Amount currency Document key Fiscal year Class Version 345.00 345.00 0 OR0000000100095 1998 94 0 List for archive info structure T_CO_ORDER CO 0001 0001 Doc. no 200000005 200000006 PR 1 1 Per 10 10 Amount 1,200.00 345.00 Curr UNI UNI

SAP AG 2002

By double clicking, you can access the archived document directly from the list display. You access individual data record in the offset, which is stored in the archive information structure. The relevant archive file is read directly. For direct access to the archived data, the system checks the authorization objects S_ARCHIVE and S_TABU_DIS. For more information on the creation of customer-specific authorization objects, refer to SAP Note 175901.

(C) SAP AG

BC670

15

6.16
Access to Individual Data Objects: Business View

List for archive information structure T_CO_ORDER Order 100000 100001 100002 100003 .... Date of Entry 12.10.1998 12.10.1998 12.10.1998 12.10.1998 Short text Service Repair 76A8/67 98-5 Service TechEd KA 98

Display internal: Master data xxx

Display data object Select the desired display function Display master data Business view X
Order Short text 100003 Order type PFE1 TechED KA 98 Rel DLT 0 SETC

Systemstatus Status number

Control data Currency Order category DEM 1

SAP AG 2002

The business view of a data record is created using function modules. They are listed in table AIND_STR5.

(C) SAP AG

BC670

16

6.17 Programming Logic: Direct Single-Document Access

Archive_read_object

Archive_get_next_record READ_TEXT (Archiving class TEXT)

Archive_close_file

SAP AG 2002 1999

ARCHIVE_READ_OBJECT includes ARCHIVE_OPEN_FOR_READ and ARCHIVE_GET_NEXT_OBJECT and searches the required data object in the archive file. Before calling the function module again, ARCHIVE_CLOSE_FILE must be called for the returned handle.

(C) SAP AG

BC670

17

6.18
ADK API: ARCHIVE_READ_OBJECT
Interface parameter import

Object Archive key Offset archive_handle

Interface parameter export

Function module functionality: This function module reads a specific data object from an archiving object in an archiving file and returns a handle for further processing. If the archive file was stored using ArchiveLink, it is also possible to read the data object using this function module. The different forms of processing are dealt with by this function module. After the data object has been read by ARCHIVE_READ_OBJECT, you can access the data using the function module ARCHIVE_GET_NEXT_RECORD or using the handle.

SAP AG 2002

The name of the archiving object is transferred in the interface parameter object. The archive key supplies the archive file and the offset of the required doucment in the arhcive file. In turn, the information for offset and archive key are copied from the archive information structure table from SAP AS. Note: The function module is intended for interactive reporting - that is - for the display on screen of a specific document. It is not intended for reading documents in archive files in the context of sequential evaluations.

(C) SAP AG

BC670

18

6.19
Structure of a Read Program with Direct Access
Declaration Internal tables (itabA. itabB, itabC) Determine Archive key and Offset select single archive_key offset from IndexTable where ... import: archive_key, offset Include object in the ADK work area ARCHIVE_READ_OBJECT export: archive_key, offset import: archive_handle Include in progam the next record belonging to object ARCHIVE_GET_NEXT_RECORD export: archive_handle import: record_structure, record Output record Close archive files ARCHIVE_CLOSE_FILE export: archive_handle

Loop, so long as records are present

SAP AG 2002

If necessary, you must also read an archiving class

(C) SAP AG

BC670

19

6.20
Views in SAP AS

Lists belonging to archive info structure T_CO_ORDER Order 100000 100001 100002 100003 .... Date of entry 12.10.1998 12.10.1998 12.10.1998 12.10.1998 Short text Service Repair 76A8/67 98-5 Service TechEd KA 98

Display internal order: master data xxx

Display data object Select desired display functionality

Order Short text

100003 Order type PFE1 TechED KA 98 Rel DLT 0 SETC

Technical view Display data from FM copied screen X

System status Status number

Field Alternative in table AIND_STR5

Contol data Currency Order category DEM 1

SAP AG 2002

The business view of a data record is created using function modules. They are listed in the table AIND_STR5.

(C) SAP AG

BC670

20

6.21
Dialog Box Business View

Create a dialog box text for selecting the business view

Table entry with name of the display function module in table AIND_STR5

Object name: <processed archiving object > Display function module: Name of the function module created Line: Defines the sequence in the dialog box text: Display text in the dialog box, link to application-specific view

SAP AG 2002 1999

Create entries: 1) Call table AIND_STR5 via Tools -> ABAP Workbench -> Overview -> Data Browser 2) Button CREATE 3) Carry out entries for Object Function Line Text 4) Button SAVE -> entry written in table

(C) SAP AG

BC670

21

6.22
Table AIND_STR5

OBJECT

FUNCTION

LINE TEXT

MM_MATBEL MM_MATBEL MM_MATBEL RV_LIKP RV_LIKP RV_LIKP SD_VBAK SD_VBAK SD_VBAK SD_VBRK SD_VBRK SD_VBRK

05 MM_MATBEL_DISPLAY_DATA_DYN 40 MM_MATBEL_DISPLAY_DATA 01 05 RV_LIKP_01_DISPLAY_DATA 01 RV_LIKP_01_DISPLAY_DATA2 02 05 SD_VBAK_01_DISPLAY_DATA 01 SD_VBAK_01_DISPLAY_DATA2 02 05 SD_VBRK_01_DISPLAY_DATA 01 SD_VBRK_01_DISPLAY_DATA2 02

matdoc - technical copied screen display data from fm delivery - document display originals order - document display originals billing document display originals

SAP AG 2002

Note: As soon as an application-specific display function has been entered in table aind_str5, the technical view no longer appears. If you want to provide both options, you must also create an entry for the technical view in aind_str5. This entry has the value space for the function. Text can also remain empty.

Entries must be transported manually. You can use the function table entry -> transport entries in transaction SE16 to do this.

(C) SAP AG

BC670

22

6.23
Function Module Business View

Create function module in customer namespace.

Create function group <zxxxxx>. Create function module <zyyyyy> in function group. Adjust function module in line with the selected object.

SAP AG 2002 1999

Create function group: Tools -> ABAP Workbench -> Overview -> Object Browser

(C) SAP AG

BC670

23

6.24
Function Module Interface

Interface similar to function module KASH_ARCHIVE_DATA_OBJECT_SHOW Passing parameters

I_ARCHIVEKEY Name of archive file as it appears in archive management I_OFFSET Offset of data object in the archive for direct access

SAP AG 2002 1999

(C) SAP AG

BC670

24

6.25
Output of the Business View

Output control options

The list output is programmed directly in the function module. Display on the customer-specific screen, which switches to list processing. You can use an existing program for the list processing.

SAP AG 2002 1999

(C) SAP AG

BC670

25

6.26
Output Directly from the Function Module

Control output without a screen

The list output occurs directly in the function module. Create a list structure using WRITE statements.

SAP AG 2002 1999

As soon as there is more than one function module in the function group, the globally used tables and data must be present in the global area.

(C) SAP AG

BC670

26

6.27
Output Directly from the FM: MM_MATBEL (1)
function mm_matbel_display_data. *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(I_ARCHIVEKEY) LIKE ADMI_FILES-ARCHIV_KEY *" VALUE(I_OFFSET) LIKE ARCH_IDX-OFFSET *" EXCEPTIONS *" OBJECT_NOT_FOUND *"---------------------------------------------------------------------tables: arc_buffer, mkpf, mseg, makt. data: handle like sy-tabix. data: xmaktx like makt-maktx. call function 'ARCHIVE_READ_OBJECT' exporting object = 'MM_MATBEL' archivkey = i_archivekey offset = i_offset importing archive_handle = handle exceptions others = 12.
SAP AG 2002

(C) SAP AG

BC670

27

6.28
Output Directly from the FM: MM_MATBEL (2)

if not sy-subrc is initial. message id sy-msgid type 'I' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. exit. endif. do. call function 'ARCHIVE_GET_NEXT_RECORD' exporting archive_handle = handle importing record = arc_buffer-segment record_structure = arc_buffer-rname exceptions end_of_object = 1. if sy-subrc = 1. exit. endif.
SAP AG 2002

(C) SAP AG

BC670

28

6.29
Output Directly from the FM: MM_MATBEL (3)
case arc_buffer-rname. when 'MKPF'. mkpf = arc_buffer-segment. write: / ' ', mkpf-mblnr, mkpf-mjahr. write: / sy-uline(105). format color col_heading intensified. skip 2. write: /2 Posting date:, 18 mkpf-budat, 66 'Name:', 73 mkpf-usnam. skip 2. write: /2 Items. skip 1. write: /4 'Pos', 10 Amount, 30 'EME',
SAP AG 2002

(C) SAP AG

BC670

29

6.30
Output Directly from the FM: MM_MATBEL (4)
35 'Material', 55 Plant, 60 Loc. write: /35 Material short text, 73 'BwA'. skip 1. when 'MSEG'. mseg = arc_buffer-segment. write: /5 mseg-zeile, mseg-matnr. write: /4 mseg-zeile, 10 mseg-erfmg, 30 mseg-erfme, 35 mseg-matnr, 55 mseg-werks, 60 mseg-lgort.
SAP AG 2002

(C) SAP AG

BC670

30

6.31
Output Directly from the FM: MM_MATBEL(5)

select maktx into xmaktx from makt where matnr = mseg -matnr. endselect. write: /35 xmaktx, 73 mseg-bwart. endcase. enddo. call function 'ARCHIVE_CLOSE_FILE' exporting archive_handle endfunction. = handle.

SAP AG 2002

(C) SAP AG

BC670

31

6.32
Output with Screen and List Processing

Contol output

Create screen for function group Screen-call in function module with switch to list function Fill and output lists

SAP AG 2002 1999

(C) SAP AG

BC670

32

6.33
Screen/List Output: MM_MATBEL (1)
function mm_matbel_display_data_dyn. *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(I_ARCHIVEKEY) LIKE ADMI_FILES-ARCHIV_KEY *" VALUE(I_OFFSET) LIKE ARCH_IDX-OFFSET *" EXCEPTIONS *" OBJECT_NOT_FOUND *"---------------------------------------------------------------------refresh: i_mkpf, i_mseg. call function 'ARCHIVE_READ_OBJECT' exporting object = 'MM_MATBEL' archivkey = i_archivekey offset = i_offset importing archive_handle = handle exceptions others
SAP AG 2002

= 12.

(C) SAP AG

BC670

33

6.34
Screen/List Output: MM_MATBEL (2)

if not sy-subrc is initial. message id sy-msgid type 'E' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. do. call function 'ARCHIVE_GET_NEXT_RECORD' exporting archive_handle = handle importing record = arc_buffer-segment record_structure = arc_buffer-rname exceptions end_of_object = 1. if sy-subrc = 1. exit. endif.

SAP AG 2002

(C) SAP AG

BC670

34

6.35
Screen/List Output: MM_MATBEL (3)
case arc_buffer-rname. when 'MKPF'. i_mkpf = arc_buffer-segment. append i_mkpf. when 'MSEG'. i_mseg = arc_buffer-segment. append i_mseg. endcase. enddo. call screen 200. call function 'ARCHIVE_CLOSE_FILE' exporting archive_handle = handle. endfunction.
SAP AG 2002

(C) SAP AG

BC670

35

6.36
Screen/List Output: MM_MATBEL (4)

process before output. module status_0200.

Switch to list processing

module display_list_materialdocuments.
Read/output internal tables header/item data

flow logic screen 200

process after input. module user_command_200.


Empty module/unnecessary, because of switch to list processing

SAP AG 2002

(C) SAP AG

BC670

36

6.37
Screen/List Output: MM_MATBEL (5)

module status_0200 output. suppress dialog. leave to list-processing and return to screen 0. * SET PF-STATUS 'xxxxxxxx'. * SET TITLEBAR 'xxx'. endmodule. " STATUS_0200 OUTPUT

module user_command_0200 input. endmodule. " USER_COMMAND_0200 INPUT

SAP AG 2002

(C) SAP AG

BC670

37

6.38
Screen/List Output: MM_MATBEL (6)
module display_list_materialdocument output. write: /2 'Booking date:', 18 i_mkpf-budat, 66 'Name:', 73 i_mkpf-usnam. skip 2. write: /2 Items. skip 1. write: /4 'Pos', 10 Set, 30 'EME', 35 'Material', 55 Plant 60 'LOrt'. write: /35 'Material short text, 73 'BwA'. skip 1.
SAP AG 2002

(C) SAP AG

BC670

38

6.39
Screen/List Output: MM_MATBEL (7)

loop at i_mseg. write: /4 i_mseg-zeile, 10 i_mseg-erfmg, 30 i_mseg-erfme, 35 i_mseg-matnr, 55 i_mseg-werks, 60 i_mseg-lgort. select maktx into xmaktx from makt where matnr= i_mseg-matnr. endselect. write: /35 xmaktx, 73 i_mseg-bwart. endloop. endmodule. " DISPLAY_LIST_MATERIALDOCUMENT OUTPUT

SAP AG 2002

(C) SAP AG

BC670

39

6.40
Displaying Archived Originals of R/3 Document (1)

Determine which business object type the document is assigned to. Create key variable inprogram. Construct key variable corresponding to key of the businee object type. The key is defined in the Business Object Repository (BOR). Call Function Module ARCHIV_DISPLAY_META

Export: Result:

Name of the business object type Key varialbe Display the archived originals, or a hit list of the originals

SAP AG 2002 1999

As you can access the Business Object Repository in transaction SWO1 SAP ArchiveLink assigns a document type and a business object type to the archived originals The document type identifies the original document. Examples: FIIINVPRELIncoming invoice preliminary posting FIIINVOICE Incoming invoice without verification SDOORDER Order acknowledgement ...... Archived originals are always related to an R/3 business object. The key of the accompanying business object is uniquely identified via the assignment to a business type. This is necessary for search strategies.

(C) SAP AG

BC670

40

6.41
Displaying Archived Originals of R/3 Document (2)

Determine which business object type the document is assigned to.

Report assignment of archived document to object type

Path: Tools -> Business Documents -> Basic Settings -> Links (transaction OAC3) Examples: Doc. type FIIINVOICE FIIINVPREL SDOORDER MMOORDER ...... Description Object type incoming invoice BKPF invoice preliminary posting BKPF order acknowledgement VBAK order EKKO

SAP AG 2002 1999

If the object type is not found in ArchiveLink, you can set a breakpoint in the display transaction for the object at SWU_OBJECT_PUBLISH and debug so that the correct object type is transferred to OBJTYPE. It is also possible to analyze link tables in ArchiveLink. By default, tables TOA01, TOA02, and TOA03 are used. The R/3 key for the object is stored here together with the object type and the document type.

(C) SAP AG

BC670

41

6.42
Display Archived Original of R/3 Document (3)

Create key definitions: <variable with key of the business document >

data: <variable name> like sapb-sapobjid. data: begin of objectid, end of objectid.

key to be passed variable constructed according to the key of the business object type

Construct key according to business object

move <database field 1> to objectid-<xxx>. move <database field 2> to objectid-<zzz>. ...... Object_id = objectid.

SAP AG 2002 1999

(C) SAP AG

BC670

42

6.43
Display Archived Original of R/3 Document (4)

Call function module ARCHIV_DISPLAY_META

call function 'ARCHIV_DISPLAY_META' exporting sap_object = <Business object type> object_id = <variable with key to business document > exceptions others = 1.

The function module displays the archived original. If more than one document is archived per R/3 document, the user obtains a hitlist from which to select the desired original.

SAP AG 2002

(C) SAP AG

BC670

43

6.44
Example: Display Archived Original (1)
function fi_documnt_display_data_originale. *"---------------------------------------------------------------- ----*"*"Local interface: *" IMPORTING *" VALUE(I_ARCHIVEKEY) LIKE ADMI_FILES -ARCHIV_KEY *.......... *"---------------------------------------------------------------- ----.......... data: begin of objectid, oidbukrs like bkpf-bukrs, oidbelnr like bkpf-belnr, oidgjahr like bkpf-gjahr, end of objectid. data: object_id like sapb-sapobjid. .......... call function 'ARCHIVE_READ_OBJECT ..........
SAP AG 2002

(C) SAP AG

BC670

44

6.45
Example: Display Archived Original (2)
do. call function 'ARCHIVE_GET_NEXT_RECORD ........ case arc_buffer-rname. when 'BKPF'. bkpf = arc_buffer-segment. ........ endcase. enddo. .......... * Output data write: / ' ', bkpf-bukrs, bkpf-belnr, bkpf-gjahr. write: / sy-uline(105). format color col_heading intensified. write: / sy-vline, 2 Posting date, 16 sy-vline, 17 Local currency, ..........
SAP AG 2002

(C) SAP AG

BC670

45

6.46
Example: Display Archived Original (3)
write: / sy-vline, 2 bkpf-budat, 16 sy-vline, 17 bkpf-hwaer, .......... * Output archived original of document * Construct key move bkpf-bukrs to objectid-oidbukrs. move bkpf-belnr to objectid-oidbelnr. move bkpf-gjahr to objectid-oidgjahr. object_id = objectid. * Call function module ArchiveLink call function 'ARCHIV_DISPLAY_META' exporting sap_object = 'BKPF' object_id = object_id exceptions others
SAP AG 2002

= 1.

(C) SAP AG

BC670

46

6.47
Addendum: Displaying Archiving Classes

Displaying archiving classes is possible in SAP AS from Release 4.6A. In Release 4.5B, display of PP_ORDER in SAP AS is already implemented. Programmable display functions for archivng classes with direct access without using SAP AS:

Fill an index for the archived data or use a table in SAP AS Implement a reporting program that accesses an individual document in the archiving class using the index.

SAP AG 2002 1999

For more information on the previous development of PM_ORDER, refer to SAP Note 135784. Compare also Note 195425 for development regarding PM_ORDER, PM_QMEL, SM_QMEL, and QM_QMEL. Further Notes on archiving classes in SAP AS: 183774, 181598, 156780

(C) SAP AG

BC670

47

6.48
Single Document Access to Archiving Classes (1)

Program 1: Fill ADK index table Fill:


Archive_open_for_read Do

Archive_get_next_object <Function module for reading the class>

Fill a customer-specific table with ADK- index values

Enddo Archive_close_file

SAP AG 2002 1999

With the function module Archive_get_next_object, you can determine the archive key and the offset of the document. Both of these are required for direct access to a document. With the help of the function module, which reads the archiving class, you obtain the information that is required for an ADK-index. You then store the ADK-index information in a customer-specific table.

(C) SAP AG

BC670

48

6.49
Single Document Access to Archiving Classes (2)

Program 2: Direct access to a document Fill:


Read the ADK index table Archive_read_object

<Function module for reading the class >

Archive_close_file

SAP AG 2002 1999

(C) SAP AG

BC670

49

6.50
Direct Read Access: Unit Conclusion

You are now able to: Integrate a business view for an archiving object in SAP AS Integrate display of archived originals for an R/3 document in SAP AS

SAP AG 2002

(C) SAP AG

BC670

50

6.51SAP AS Business Views Exercises Unit: SAP AS Business Views Topic: Creating a Business View for MM_EBAN
At the conclusion of these exercises, you will be able to: Display archived purchase requisitions via a business view in SAP AS

You have archived purchase requisitions and, in addition to the technical views, the user department wants to have a business view

1.1

Create new function group ZBC670_xx. Here, create function module ZZMM_EBANxx, using as a template ZZMM_EBAN00. The function is part of Basis (Application S). Create the following global data for the function module: Table arc_buffer Field handle like sy-tabix Internal table i_eban like eban Field ok-code like sy-ucomm

Familiarize yourself with the interface

1-1-2 Refresh table i_eban. 1-1-3 Call function module 'ARCHIVE_READ_OBJECT'. The transferred object is MM_EBAN. i_archive key and i_offset are also transferred. The function module returns a handle. 1-1-4 In a loop, call 'ARCHIVE_GET_NEXT_RECORD'. This transfers parts of arc_buffer. The exception is end_of object. After calling the function module, EXIT if the exception is fulfilled. 1-1-5 In a CASE structure, query the contents of ARC_BUFFER_RNAME and fill the internal table i_eban with the data from ARC_BUFFER_SEGMENT. 1-1-6 Close the archive file 1.1.7 (C) SAP AG Call screen 300 and create it using forward navigation. BC670 51

1-1-8 Declare in PBO Module status_0300 that you want to make a list output, not screen processing (suppress screen dialog and leave to list processing). Set the PF-STATUS 'INLI' Create an empty PAI module status_0300 by double clicking. The module involves no processing. After module status_0300, call module display_liste_mm_eban. Create this module using forward navigation, and output the data in it for MM_EBAN

1-1-9 The list layout is as follows: Line 1: Position 2: Position 23: Position 40: Position 50:

Text 'Purchase requisition' BANFN from table EBAN Text 'Document type' BSART from table EBAN 'Purchase requisition items'

Line 4: Position 2: Text Line 7 Position 4: Position 20: Line 8 Position 20: Line 10: Position 4: Position 20: Line 11: Position 20:

Text 'Pos' Text 'Material' Text 'Requested quantity' BNFPO from table EBAN MATNR from table EBAN MNGE from table EBAN

2-1

Create an entry in table aind_str5 for your business view. Enter your function module. Name your view View_xx, where xx is your group number. 3.1 Call the Archive Information System. Select as object MM_EBAN and view the archived documents from the structure table. Branch to the detail view by double clicking, and try to select your business view.

(C) SAP AG

BC670

52

Unit: SAP AS Business Views Topic: Display an Archived Original (Letter) in SAP AS
At the conclusion of these exercises, you will be able to: Use SAP AS to display the optically archived original document for a purchase requisition

The user department wants to see not only the purchase requisition, but also the optically archived original document

1-1

Call your function module from the previous exercise.

2-1

Determine which business object in ArchiveLink belongs to a purchase requisition. The document type used is called MYLETTER.

3-1

In the list output module, create a variable that reflects the key of the business object. Create a second variable object_id , that links to sapb-sapobjid.

4-1

Supply your variable of the business object key with the field BANFN from table EBAN and assign the variable to the variables object_id

5-1

At the end of your list output, call function module 'ARCHIV_DISPLAY_META' Export parameter: sap_object = <business object type defined > object_id = Variable <object_id>

(C) SAP AG

BC670

53

(C) SAP AG

BC670

54

6.52Business Views in SAP AS Solutions Unit: Business Views in SAP AS Topic: Creating a Business View for MM_EBAN

1-1

Tools, ABAP Workbench, Overview, Object Navigator

From menu, choose: Workbench Edit Object Function Group Create. Enter group name: ZBC670_xx Switch to display for function group ZBC670_00 Expand function modules Mark function module ZZMM_EBAN00 Right mouse click: Copy Enter: ZZMM_EBANxx (xx represents your group number) Function group: ZBC670 Button <Copy> Double click ZZMM_EBANxx. Create global data: From menu, choose Goto Global Data. For data definition, see sample solution ZZMM_EBAN 1-1-2 to 1-1-9 2-1 see sample solution ZMM_EBAN

Call transaction SE16 Table: aind_str5, button <execute> Button <create> Object: MM_EBAN Function: ZMM_EBANxx Line: The instructor will give you this; must not be more that 15 per object Text: BANF xx Button <save> Tools, Administration, Administration, Archiving, Button <Info system>, Archive Explorer Object: MM_EBAN Archive info structure: ZAIMM_EBAN Button <execute> Double-click on a document number from the displayed list Select your own business view

3-1

FUNCTION ZZMM_EBAN. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING

(C) SAP AG

BC670

55

*" REFERENCE(I_ARCHIVEKEY) TYPE ADMI_FILES-ARCHIV_KEY *" REFERENCE(I_OFFSET) TYPE ARCH_IDX-OFFSET *"---------------------------------------------------------------------* tables: arc_buffer, eban. global definiert data: handle like sy-tabix. refresh: i_eban. call function 'ARCHIVE_READ_OBJECT' exporting object = 'MM_EBAN' archivkey = i_archivekey offset = i_offset importing archive_handle = handle exceptions others = 12. if not sy-subrc is initial. message id sy-msgid type 'I' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. exit. endif. do. call function 'ARCHIVE_GET_NEXT_RECORD' exporting archive_handle = handle importing record = arc_buffer-segment record_structure = arc_buffer-rname exceptions end_of_object = 1. if sy-subrc = 1. exit. endif. case arc_buffer-rname. when 'EBAN'. i_eban = arc_buffer-segment. append i_eban. endcase. enddo. call function 'ARCHIVE_CLOSE_FILE' exporting archive_handle = handle. ** Ausgabe der Daten ber Dynpro mit Listprocessing call screen 300. ENDFUNCTION.

(C) SAP AG

BC670

56

Logic
PROCESS MODULE MODULE PROCESS MODULE BEFORE OUTPUT. STATUS_0300. display_liste_mm_eban. AFTER INPUT. USER_COMMAND_0300.

MODULE STATUS_0300 OUTPUT. suppress dialog. leave to list-processing and return to screen 0. SET PF-STATUS 'INLI'. * SET TITLEBAR 'xxx'. ENDMODULE. " STATUS_0300 OUTPUT *&---------------------------------------------------------------------* *& Module DISPLAY_LISTE_MM_EBAN OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE DISPLAY_LISTE_MM_EBAN OUTPUT. write: /2 'Bestellanforderung: ', 23 i_eban-banfn, 40 'Belegart:', 73 i_eban-bsart. skip 2. write: /2 'Bestellanforderungspositionen'. skip 1. write: /4 'Pos', 20 'Material'. write: /20 'Anforderungsmenge'. skip 1. write: /4 i_eban-bnfpo, 20 i_eban-matnr. write: /20 i_eban-menge. ENDMODULE. " DISPLAY_LISTE_MM_EBAN OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0200 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0200 INPUT. ENDMODULE. " USER_COMMAND_0200 INPUT

*&---------------------------------------------------------------------* *& Module USER_COMMAND_0300 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0300 INPUT. ENDMODULE. " USER_COMMAND_0300 INPUT

(C) SAP AG

BC670

57

(C) SAP AG

BC670

58

Unit: Business Views in SAP AS Topic: Display an Archived Original (Letter) in SAP AS
At the conclusion of these exercises, you will be able to: Use SAP AS to display the optically archived original document for a purchase requisition.

The user department wants to see not only the purchase requisition, but also the optically archived original document

1-1

Call your function module from the previous exercise.

2-1

Determine which business object in ArchiveLink belongs to a purchase requisition. The document type used is called MYLETTER. Enter transaction SE16; Table TOA01; Search for document type MYLETTER. The object type that is stored in the record is the one being searched for.

3-1 to 5-1: See sample solution function module ZZMM_EBAN_ORIGINALE.

(C) SAP AG

BC670

59

FUNCTION ZZMM_EBAN_ORIGINALE. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" REFERENCE(I_ARCHIVEKEY) TYPE ADMI_FILES-ARCHIV_KEY *" REFERENCE(I_OFFSET) TYPE ARCH_IDX-OFFSET *"---------------------------------------------------------------------refresh: i_eban. data: begin of objectid, oidbanfn like eban-banfn, end of objectid. data: object_id like sapb-sapobjid.

call function 'ARCHIVE_READ_OBJECT' exporting object = 'MM_EBAN' archivkey = i_archivekey offset = i_offset importing archive_handle = handle exceptions others = 12. if not sy-subrc is initial. message id sy-msgid type 'I' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. exit. endif. do. call function 'ARCHIVE_GET_NEXT_RECORD' exporting archive_handle = handle importing record = arc_buffer-segment record_structure = arc_buffer-rname exceptions end_of_object = 1. if sy-subrc = 1. exit. endif. case arc_buffer-rname. when 'EBAN'. i_eban = arc_buffer-segment. append i_eban. endcase. enddo. call function 'ARCHIVE_CLOSE_FILE' exporting archive_handle = handle. move i_eban-banfn to objectid-oidbanfn. object_id = objectid. call function 'ARCHIV_DISPLAY_META' exporting sap_object = 'BUS2105' object_id = object_id exceptions others = 1. if sy-subrc ne 0. exit.

(C) SAP AG

BC670

60

endif. * Ausgabe der Daten ber Dynpro mit Listprocessing call screen 300. ENDFUNCTION.

(C) SAP AG

BC670

61