Friday, 19 December 2014

Export & Import table Cluster across multiple external session


Generally to access some values across multiple external sessions, abap provides SET & GET parameter but this has specific limitations like large data cannot be stored in the SAP memory. An alternate approach is to store the data which needs to be accessed across multiple sessions in the cluster table and then access the same from a different session. So this can be achieved by EXPORT TO DATABASE & IMPORT FROM DATABASE.
----------------------------------------------------------------------------------------------------------------------------------------
Step1. This is the standard INDX table we will use to store the long data or multiple records in the form of clusters which can be accessed across multiple sessions. Some of the fields are important while storing, retrieving or deleting the information. RELID - species  the area, it is a two character length which can be defined in the customer program, SRTFD  is considered as the field CLUSTD stores the internal table records.


















Step2. Here is the program which stores/insets/exports the internal table records to the table INDX with RELID- ZZ and SRTFD - ZZ_CUST ( mentioned in the export statement).
---------------------------------------------------------------------------------------------------------------
TYPES : BEGIN OF ty_data,
        counter TYPE sy-tabix,
        temp_data TYPE string,
        END OF ty_data.
DATA : lt_data TYPE TABLE OF ty_data,
       key     TYPE indx-srtfd.
FIELD-SYMBOLS : <fs_data> TYPE ty_data.

APPEND INITIAL LINE TO lt_data ASSIGNING <fs_data>.
<fs_data>-counter = 1.
<fs_data>-temp_data = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.


APPEND INITIAL LINE TO lt_data ASSIGNING <fs_data>.
<fs_data>-counter = 2.
<fs_data>-temp_data = 'PQRSTUVWXYZABCDEFGHIJKLMN'.


APPEND INITIAL LINE TO lt_data ASSIGNING <fs_data>.
<fs_data>-counter = 3.
<fs_data>-temp_data = 'ZYXWVUTSRQPONMLKJIHGFEDCBA'.

key = 'ZZ_TEST'.
EXPORT lt_data FROM lt_data TO DATABASE indx(ZZ) ID key.

IF sy-subrc = 0.
  MESSAGE 'INDX table is updated with records with id-ZZ & KEY-ZZ_TEST' TYPE 'I'.

ENDIF.


---------------------------------------------------------------------------------------------------------------



Step3. Just a mapping between the export command in the program and the table fields.






Step4. Here is the import program which runs in a separate external session and tries to access the data stored in the INDX table with specified ID and KEY. IMPORT statement is important. If this  Import statement doesn't find any data in the specified ID and KEY then the SY-SUBRC would be 4.
After importing the data from the INDX table cluster, the program deletes the data from the table. For deletion we have multiple ways provided by standard like DELETE from database or some standard abap class methods that are shown in the program.

----------------------------------------------------------------------------------------------------------

TYPES : BEGIN OF ty_data,
        counter TYPE sy-tabix,
        temp_data TYPE string,
        END OF ty_data.
DATA : lt_data TYPE TABLE OF ty_data,
       key     TYPE indx-srtfd.
FIELD-SYMBOLS : <fs_data> TYPE ty_data.
key = 'ZZ_TEST'.
IMPORT lt_data TO lt_data FROM DATABASE indx(ZZ) ID key.
** After reading the records clear the temporary data from the INDX table
** which can be done in two ways either delete from database or
**calling delete method of the standard class cl_abap_expimp_db
DATA : lr_expimp  TYPE REF TO cl_abap_expimp_db.
CREATE OBJECT lr_expimp.

TRY.
* DELETE FROM DATABASE INDX(ZZ) ID KEY.

CALL METHOD lr_expimp->delete
  EXPORTING
     tabname          = 'INDX'
     client           = '800'
     area             = 'ZZ'
     id               = key
*    GENERIC_KEY      = ABAP_FALSE
    client_specified = abap_true.
CATCH cx_sy_client .
 CATCH cx_sy_generic_key .
 CATCH cx_sy_incorrect_key .
ENDTRY.
**
LOOP AT lt_data ASSIGNING <fs_data> .
  WRITE :/ <fs_data>-counter, <fs_data>-temp_data.

ENDLOOP.
-------------------------------------------------------------------------------------------------------------






Step5. Before export program runs the INDX table is empty for the ID & KEY.




Step6. After the execution of the Export program the INDX table is updated with a record.






Step7. Before the execution of the Import program, the records are still there in the INDX table.





Step8. Execute the Import program which reads the data from the INDX table cluster and tehn delets them from the table.







--------------------------------------------------------------------------------------------------------------------------------------

1 comment:

exim data said...

Get export import data of your competitors along with HS code/ HSN code.
Thanks
Visit
Eximdata for export import data

Comments system

Disqus Shortname