Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Archiving Table Data

Former Member
0 Likes
2,505

Hi there....

i am working on a report which archives data of a ztable. the report is using a function module ARCHIVE_OPEN_FOR_DELETE to archive the same. when i execute the fm independently, it is working perfect... but it doesnt work in my program.... on debugging the code, i could find the area which is causing trouble.... but i am unable to figure out whr the problem is.... the problem code is as below :

FORM process_data.

DATA : lv_jobcount LIKE tbtcm-jobcount,

lv_jobname LIKE tbtcm-jobname,

lv_key LIKE admi_jobs-archiv_key,

lt_file LIKE admi_files OCCURS 0 WITH HEADER LINE.

  • If data is not given on selection screen,

  • populate one month older date than current date

IF s_zdats[] IS INITIAL.

s_zdats-sign = 'I'.

s_zdats-option = 'LT'.

s_zdats-low = sy-datum.

s_zdats-low = s_zdats-low - 30.

APPEND s_zdats.

ENDIF.

  • Get data from History table

SELECT * FROM zchm_history

INTO TABLE gt_history

WHERE lenum IN s_lenum

AND ztote IN s_ztote

AND zdats IN s_zdats.

  • open a new archive run to archive data

CALL FUNCTION 'ARCHIVE_OPEN_FOR_WRITE'

EXPORTING

call_delete_job_in_test_mode = p_test

comments = p_coment

create_archive_file = p_create

object = 'ZCHM_HIST'

IMPORTING

archive_handle = gv_handle.

  • Get Job Info

CALL FUNCTION 'GET_JOB_RUNTIME_INFO'

IMPORTING

jobcount = lv_jobcount

jobname = lv_jobname

EXCEPTIONS

no_runtime_info = 1

OTHERS = 2.

IF sy-subrc = 0.

  • Get Archive Key

SELECT * FROM admi_files

INTO TABLE lt_file

WHERE creat_date = sy-datum

AND pathintern = 'ZCHM_HIST_ARCHIV'.

IF sy-subrc = 0.

SORT lt_file BY creat_time DESCENDING.

READ TABLE lt_file INDEX 1.

MOVE lt_file-archiv_key TO lv_key.

  • Lock Table ADMI_JOBS

CALL FUNCTION 'ENQUEUE_EZ_ADMI_JOBS'

EXPORTING

mode_admi_jobs = 'E'

jobname = lv_jobname

jobcount = lv_jobcount

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Update Table ADMI_JOBS

UPDATE admi_jobs SET archiv_key = lv_key

WHERE jobname = lv_jobname

AND jobcount = lv_jobcount.

  • UnLock Table ADMI_JOBS

CALL FUNCTION 'DEQUEUE_EZ_ADMI_JOBS'

EXPORTING

mode_admi_jobs = 'E'

jobname = lv_jobname

jobcount = lv_jobcount.

ENDIF.

ENDIF.

LOOP AT gt_history.

  • initializing a new data object

CALL FUNCTION 'ARCHIVE_NEW_OBJECT'

EXPORTING

archive_handle = gv_handle.

  • putting data records into the data container

CALL FUNCTION 'ARCHIVE_PUT_RECORD'

EXPORTING

archive_handle = gv_handle

record_structure = 'ZCHM_HISTORY'

record_flags = ' '

record = gt_history.

  • writing data object into the archive file

CALL FUNCTION 'ARCHIVE_SAVE_OBJECT'

EXPORTING

archive_handle = gv_handle.

ENDLOOP.

  • creating a statistic list

CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS'

EXPORTING

archive_handle = gv_handle.

  • closing the archive run

CALL FUNCTION 'ARCHIVE_CLOSE_FILE'

EXPORTING

archive_handle = gv_handle.

ENDFORM. " process_data

can someone tel whr the error is in this code. i have already spent lot of time on this perticular part by commenting certain area, uncommenting it and so on.... kindly help....

5 REPLIES 5
Read only

former_member222860
Active Contributor
0 Likes
1,427

where's this FM in your code

ARCHIVE_OPEN_FOR_DELETE

Read only

0 Likes
1,427

Hi,

I have managed to find a workaround for the same. But it is not gud enough... lemme explain the issue again...

we are upgrading from 4.6 to 6.0 in 4.6, we were doing archiving and deletion of data in the same program and it was working fine.... but in 6.0, we are not allowed to use archiving and deletion in the same program (see http://help.sap.com/saphelp_nw04/helpdata/en/2a/fa043a493111d182b70000e829fbfe/frameset.htm).

Please suggest a way to use the two in the same program.

regards

Read only

0 Likes
1,427

HI Prem,

For Deletion of Ztables you need to use the following statements.

1. ARCHIVE_GET_CUSTOMIZING_DATA.

2. ARCHIVE_OPEN_FOR_DELETE.

3. ARCHIVE_GET_NEXT_OBJECT

4. ARCHIVE_GET_NEXT_RECORD

5. ARCHIVE_WRITE_STATISTICS

6. ARCHVE_CLOSE_FILE

7. ARCHIVE_ADMIN_SET_STATUS.

Try these function modules.

As advised by Archiving Experts, It is not fair to use both archving and deletion in the same program.

Regards - Swarna.

Read only

Former Member
0 Likes
1,427

working with the workaround...

Read only

0 Likes
1,427

Hi,

This is for your information:

We must not create write and delete functionalities in a single program as we have to define the same with a custom archiving object in the transaction code AOBJ and also it will create a lot of inconsintencies in number of archived entries later.

For the creation of custom write program, please follow the below function modules in sequence:

ARCHIVE_OPEN_FOR_WRITE:

This is the first function module that is called in the write program to create a new archive file. The parameter ARCHIVE_HANDLE gives us the handle to pass in write operations.

ARCHIVE_NEW_OBJECT:

This function module should always be called when a new data object is to be prepared for writing to an archive.

ARCHIVE_PUT_RECORD:

This function module is used to pass a data record to the data object requested beforehand with the function module ARCHIVE_NEW_OBJECT.

ARCHIVE_SAVE_OBJECT:

All data records you pass to the data object are written to the archive file together when you call this function module.

ARCHIVE_WRITE_STATISTICS :

This function module is used in both the write and delete programs to write and display the statistics as the final output when the archive handle is passed an input.

ARCHIVE_CLOSE_FILE:

This function module is used in both the write and delete programs to close the archiving session when the archive handle is passed in this as an input.

And for delete program, please use the below FM in sequnce:

ARCHIVE_GET_CUSTOMIZING_DATA:

This functional module is used in the delete which reads the customizing data of an archiving object

ARCHIVE_OPEN_FOR_DELETE:

This function module opens the eDDAR storage system to delete their data in the database by providing us the archive handle and the selected archived files that we would compare and delete with the SAP data.

ARCHIVE_GET_NEXT_OBJECT:

This function module reads the next data object for an archive handle from the eDDAR storage system which has been opened for reading.

ARCHIVE_DELETE_OBJECT_DATA:

The delete program must use this function module every time after calling the function ARCHIVE_GET_NEXT_OBJECT within the same loop for the same handle to delete the last data object that was read from the archive file.

ARCHIVE_GET_NEXT_RECORD This function module is used to read the data records of a data object for an archive handle sequentially.

ARCHIVE_WRITE_STATISTICS:

This function module is used in both the write and delete programs to write and display the statistics as the final output when the archive handle is passed an input.

ARCHIVE_GIVE_STATISTICS:

This function module is used in delete programs for data archiving to transfer statistical data to the Archive Development Kit (ADK).

ARCHIVE_CLOSE_FILE:

This function module is used in both the write and delete programs to close the archiving session when the archive handle is passed in this as an input.

This will solve the issue.

Thanks,

Shamim