Standard SAP archiving methods do not allow you to retrieve specific Profitability Analysis (CO-PA) line items. However, you can gain access to them via two methods: using the SAP Archiving Information System or ABAP code. Each has limitations you should know about.
Dear SAP Financials Expert,
Our Profitability Analysis (CO-PA) database is growing very quickly. One of the options we are exploring to mitigate its size is archiving CO-PA data. Our initial analysis suggests that we can create CO-PA reports to retrieve archived data. So far, however, these reports yield summary totals only, without the underlying line items. This appears to be a serious limitation, as our business community is likely to need to review the individual line items. Is it possible to retrieve them from the archive?
—IT Manager, California
Archiving is important but often neglected, so it is encouraging that your company is devoting attention to it. Archiving is particularly important for CO-PA, which is a downstream application. CO-PA collects data from many upstream applications, including Sales and Distribution (SD), Production Planning and Control (PP), Financial Accounting (FI), and Controlling (CO). The accumulation of data from these other modules, in addition to the data generated by CO-PA itself, makes CO-PA notorious for becoming problematically large very quickly.
The basic idea behind archiving is to store data deleted from the online application database in alternative places. The less useful mass of data is not lost, but remains available for retrieval, if necessary.
In CO-PA archiving, data is deleted from line-item (CE1 and CE2) and totals (CE3) tables.If necessary, you can retrieve archived summary total records information by setting the option in the CO-PA report (Extras>Performance), as shown in Figure 1. However, as you observed, the system does not provide an option to retrieve archived CO-PA line items. For example, when you click on Goto>Line Items for the archived selection, the system won't display the line items from the archive database. It may seem odd, but this is normal system behavior, as SAP does not support retrieving archived CO-PA line items as a standard.

Figure 1
CO-PA reports read archived data at the totals level only
Two options, however, exist for retrieving archived CO-PA line items. The first uses the standard SAP tool, Archiving Information System (SAP AS), and the second uses a custom ABAP program. Using SAP AS is the standard SAP method, and has the advantage of not requiring new coding. It also has a disadvantage, however, in that it negates much of the space savings achieved by archiving. By archiving, you aim to save table space. With SAP archiving, you end up storing part of the data in AS tables anyway.
The ABAP method does not compromise space savings and, although it is most useful where requests for archived data are fairly infrequent, is likely the best choice for most users. The following descriptions of both methods will help you decide which is best for your needs. Both methods can be used in any version of Financials.
SAP AS Method
The archiving system is based on the same principles as any other information system, such as those for sales and logistics. SAP AS develops an information structure based on the available fields, known as the field catalog, for the archiving object. See the sidebar, "What is an Archiving Object?," for more details.
To create an information structure, you need a field catalog (a collection of fields from which to choose) for CO-PA line items. Though SAP AS is a standard feature of SAP, you will find that there is no standard field catalog for CO-PA line items. Since each SAP client can define its own characteristics for the CO-PA ledger, the SAP system cannot provide a standard field catalog. Therefore, you must create your own field catalog first.
Use the following steps to create your own field catalog for CO-PA line items:
Step 1. Open Field catalogs. Using transaction SARI, call the SAP AS and choose Customizing. Then click on option Environment>Field catalogs.
Step 2. Create a new field catalog. Name it (for example, Z_COPA1_XXXX) and give it the following settings, as shown in Figure 2:
Archiving object: COPA1_XXXX
(XXXX = name of the operating concern)
File in index: D (File name is data field)
Offset in index: D (Offset is data field)

Figure 2
Field catalog for CO-PA line items
Step 3. Enter the complete key of the CO-PA line item. Navigate to Field selection and enter the complete key of the CO-PA line item table as shown in Table 1. Note: Be sure to change XXXX to the name of the operating concern in your company.
Field Number
|
Target Field
|
Key
|
Source Table
|
Source Field
|
1
|
PALEDGER
|
X
|
CE1XXXX
|
PALEDGER
|
2
|
VRGAR
|
X
|
CE1XXXX
|
VRGAR
|
3
|
VERSI
|
X
|
CE1XXXX
|
VERSI
|
4
|
PERIO
|
X
|
CE1XXXX
|
PERIO
|
5
|
PAOBJNR
|
X
|
CE1XXXX
|
PAOBJNR
|
6
|
BELNR
|
X
|
CE1XXXX
|
BELNR
|
7
|
POSNR
|
X
|
CE1XXXX
|
POSNR
|
Table 1You may want to add characteristics, such as company code, customer group, or customer, if you wish to include these as selection criteria as shown in Figure 3.

Figure 3
Field selections for the catalog
Step 4. Save the catalog.
Step 5. Build an information structure. Once the field catalog is created, you can create an information structure in Customizing. In the example, I specify Archiving Object COPA1_XXXX and Field Catalog Z_COPA1_XXXX in the example, shown in Figure 4.

Figure 4
Archive information structure for CO-PA line items
You must choose the key fields from the field catalog and any additional characteristics must be defined. Save and activate the information structure, using the Activate icon, which is located between the display and delete icons.
Step 6. Retrieve archived line items. Once the information structure is active and populated, you can retrieve archived CO-PA line items using Archive Explorer. Archive Explorer is standard in all versions of SAP and can be accessed through the Central Management page by clicking the Archive Explorer button, shown in Figure 5. The retrieval screen that comes up is shown in Figure 6.

Figure 5
Access Archive Explorer

Figure 6
Retrieve CO-PA line items from archive information structure
When you execute the program, the system retrieves archived CO-PA line items and displays them in the tabular format.
Limitations of Using SAP AS
Using SAP AS to retrieve archived CO-PA line items is subject to a few limitations. First, creating the field catalog is a mildly complex task and requires technical knowledge. At best, it is neither straightforward nor intuitive. It should be, however, within the abilities of most people who work directly with CO-PA.
A second limitation arises from the way in which SAP reads archived data. It does so in the intervals of 1,000 records at a time. Even if only a few CO-PA line items are selected for retrieval, the system will still show 1,000 records. If, for example, 20 line items are requested, they will appear along with 980 line items that were not part of the request.
Although this limitation does not pose significant problems, it may cause confusion for users who are unaware of it.
A third caveat is necessary regarding the SAP AS workaround. The archived data is stored in the information structures created. The information structures then cause the mass of data to remain in the SAP system. By storing the archiving data in information structure tables instead of the CO-PA tables, the benefit of reducing data spaces normally gained by archiving is compromised. The excessive data is merely shifted out of CO-PA, rather than being eliminated from the system, possibly defeating the purpose of archiving at all. Of course, if you have a great business need to retrieve archived CO-PA line items, it is better to access them from information structures. This way, at least, your live CO-PA database growth is controlled and managed.
Custom ABAP Method
I am a strong believer in using standard SAP programs and making as few customized changes as possible; however, in this case, creating a custom ABAP program seems like a better suggestion. The custom program reads the archive files sequentially and retrieves the CO-PA line items.
You can use standard SAP function modules ARCHIVE_OPEN_FOR_READ, ARCHIVE_GET_NEXT_OBJECT, ARCHIVE_GET_NEXT_STRUCT_SPECIF, and ARCHIVE_CLOSE_FILE to read the data records from the archive files. The code is shown in Figure 7.
report ZKE24ARCHIVE.
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
.
.
data: w_handle like sy-tabix.
data: it_files like admi_files occurs 0 with header line.
ranges: r_files for admi_files-archiv_key.
.
selection-screen begin of block b1 with frame title text-001.
select-options:
s_bukrs for ce1XXXX-bukrs obligatory,
s_perio for ce1XXXX-perio obligatory,
s_kndnr for ce1XXXX-kndnr,
s_kdgrp for ce1XXXX-kdgrp,
.
selection-screen end of block b1.
.
.
selection-screen begin of block b2 with frame title text-002.
selection-screen begin of line.
selection-screen pushbutton 1(29) ‘Archive Selection’ user-command arcsel.
parameters: p_arc_yn(72).
selection-screen end of line.
selection-screen end of block b2.
select-options: s_files for admi_files-archiv_key no-display.
.
.
.
at selection-screen.
if sy-ucomm eq ‘ARCSEL’.
perform select_archive_files.
endif.
.
.
*----------------------------------------------------------------------*
* Main Program *
*----------------------------------------------------------------------*
start-of-selection.
.
.
perform validate_archive_files.
perform open_archive_files.
perform read_archive_files.
perform close_archive_files.
.
.
perform display_archived_lines_using_alv.
end-of-selection.
*----------------------------------------------------------------------*
* Form SELECT_ARCHIVE_FILES *
*----------------------------------------------------------------------*
form select_archive_files.
if not s_files[] is initial.
call function 'RW_ARCH_CONVERT_RANGE_TO_ADMI'
tables
t_select_options = s_files
t_selected_files = it_files.
endif.
call function 'ARCHIVE_ADMIN_POPUP_DOCUMENTS'
exporting
object = ‘COPA1_XXXX’
show_deleted_run = ‘X’
dialog_type = ‘READ’
tables
selected_files = it_files
exceptions
object_not_found = 01
cancelled_by_user = 02
no_files_selected = 03
unknown_dialog_type = 04.
if sy-subrc ne 0.
refresh it_files.
else.
clear s_files.
refresh s_files.
call function 'RW_ARCH_CONVERT_ADMI_TO_RANGE'
tables
t_selected_files = it_files
t_select_options = s_files.
endif.
endform. " SELECT_ARCHIVE_FILES
*----------------------------------------------------------------------*
* Form VALIDATE_ARCHIVE_FILES *
*----------------------------------------------------------------------*
form validate_archive_files.
call function 'RW_ARCH_CONVERT_ADMI_TO_RANGE'
tables
t_selected_files = it_files
t_select_options = r_files.
endform. " VALIDATE_ARCHIVE_FILES
*----------------------------------------------------------------------*
* Form OPEN_ARCHIVE_FILES *
*----------------------------------------------------------------------*
form open_archive_files.
call function 'ARCHIVE_OPEN_FOR_READ'
exporting
object = ‘COPA1_XXXX’
importing
archive_handle = w_handle
tables
archive_files = r_files
selected_files = it_files
exceptions
file_already_open = 01
file_io_error = 02
internal_error = 03
no_files_available = 04
object_not_found = 05
open_error = 06
not_authorized = 07.
if sy-subrc ne 0.
message e999 with 'Cant open selected archive(s)!'.
else.
free: r_files, it_files.
endif.
endform. " OPEN_ARCHIVE_FILES
*----------------------------------------------------------------------*
* Form READ_ARCHIVE_FILES *
*----------------------------------------------------------------------*
form read_archive_files.
* loop for Objects
do.
call function 'ARCHIVE_GET_NEXT_OBJECT'
exporting
archive_handle = w_handle
exceptions
end_of_file = 01
file_io_error = 02
internal_error = 03
open_error = 04
wrong_access_to_archive = 05.
if sy-subrc ne 0.
exit.
endif.
* Loop for Records
do.
call function 'ARCHIVE_GET_NEXT_STRUCT_SPECIF'
exporting
archive_handle = w_handle
record_structure = 'CE1XXXX'
importing
record = CE1XXXX
exceptions
end_of_level = 01
end_of_object = 02
internal_error = 03
wrong_access_to_archive = 04.
if sy-subrc eq 0.
check: ce1XXXX-bukrs in s_bukrs and
ce1XXXX-perio in s_perio and
. . . Other checks for selection-criteria.
append it_tab. “Internal Table to display using ALV
clear it_tab.
else.
exit.
endif.
enddo. “Next Record
enddo. “Next Object
endform. " READ_ARCHIVE_FILES
*----------------------------------------------------------------------*
* Form CLOSE_ARCHIVE_FILES *
*----------------------------------------------------------------------*
form close_archive_files.
call function 'ARCHIVE_CLOSE_FILE'
exporting
archive_handle = w_handle
exceptions
internal_error = 01
wrong_access_to_archive = 02.
check sy-subrc eq 0.
endform. " CLOSE_ARCHIVE_FILES
Figure 7 Sample custom ABAP code to retrieve CO-PA line items from the archive
The selection criteria for this custom program can be similar to transaction KE24 (display actual line items). In addition, a selection option can be provided to choose the archive files. The program can read the selected archive files and retrieve CO-PA line items. Each line item retrieved from the archive files can be validated against the selection criteria and the results can be displayed in the ALV format, for easy access by business users.
Limitations of Custom ABAP Code
The advantage of developing the custom ABAP program is that the archived data is not stored in SAP table space and is retrieved only when required. I'm assuming business users will need archived information primarily at the totals level, and don't need to access the archived line items very frequently. Frequent requests from archive files, however, may increase the database access and in turn may cause performance to deteriorate. Writing an ABAP program can also involve maintenance overheads, such as developing a code, testing, and routine maintenance for bug fixes.
What Is an Archiving Object?
Technically, an archiving object is defined as the "smallest unit that can be wholly archived and deleted from the database." R/3 stores CO-PA document details in various database tables such as CE1, CE2, and CE3. If you want to archive and delete one CO-PA document, you must also delete corresponding entries from these tables. Additionally, you also must manage the order in which the entries should be deleted to allow for dependencies. To spare the user from managing this process, SAP developed the archiving object. Transaction SARA shows details for an archiving object.
As shown in Figure 1, an archiving object primarily controls configuration parameters for customizing settings, what data to archive, and what programs to use. SAP has developed programs for creating archive files and deleting corresponding entries from the database.

Figure 1
CO-PA reports read archived data at the totals level only
The programs and tables components of an archiving object are predefined by the R/3 system. For every archive object, it lists the archiving programs: write, delete, reload programs, and so on. All of the table entries, which will be deleted, are listed. The correspondences are all predefined.
Customizing parameters, however, are not predefined. You must define these components individually. Customizing parameters for archive objects are categorized as follows:
- Archive object-specific parameters. You can set the parameters for the size of an archive file, settings for delete program, and connection to archive system. For example, you can set the file size of the archive or determine whether the delete program should be executed automatically after the write program.
- Basis customizing for file names/paths. You can set the logical file names and directory paths where these files will be stored. Typically, a colleague on your Basis team will set these parameters using transaction code FILE.
- Application-specific parameters (optional). If you prefer, you can set a few application-specific parameters. For example, in the case of financial documents (archive object FI_DOCUMNT), you can set the retention periods for G/L accounts or minimum retention days for document types.

Mitresh Kundalia
Mitresh Kundalia heads the SAP practice at Quality Systems & Software (www.QSandS.com), a consulting firm specializing in SAP S/4HANA, SAP General Ledger, and complex System Landscape Optimization (SLO)-type reorganizations. Mitresh is widely acknowledged as a leading SAP expert, with multiple publications and an SAP-PRESS book to his credit. He has published more than 50 peer-reviewed articles and white papers, and he has given presentations at various SAP conferences and events. Mitresh is the chief solutions architect of General Ledger Migration Optimizer (GLMO), a leading product to accelerate and jump-start the SAP S/4HANA and SAP General Ledger initiatives; SAP Data Reorganization Optimizer (SDRO), an SLO-type product for managing complex system landscape reorganizations; and Group Currency Activation and Conversion (GCAC), a product suite to manage introduction of parallel currencies and conversion of data in a live SAP system.
You may contact the author at Mitresh@QSandS.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.