2006 Jul 03 2:15 PM
Hi,
I would like to know if there is a way to <b>generically</b> import an object stored into memory.
Indeed, IMPORT.. FROM MEMORY doesn't seem to accept any reference of field-symbols or anything of that sort.
The class CL_ABAP_EXPIMP_MEM looks like it only provides description of the content.
Thanks in advance.
Best regards,
Guillaume
2006 Jul 03 2:21 PM
Hai
Check the following Code
IMPORT - Get data
Variants
1. IMPORT f itab FROM MEMORY.
2. IMPORT f itab FROM DATABASE dbtab(ar) ID key.
3. IMPORT DIRECTORY INTO itab FROM DATABASE dbtab(ar) ID key.
4. IMPORT f itab FROM DATASET dsn(ar) ID key.
Variant 1
IMPORT f itab FROM MEMORY.
Additions
1. ... TO g (for each field f to be imported)
2. ... ID key
Effect
Imports data objects (fields or tables) from the ABAP/4 memory (see EXPORT ). Reads in all data without an ID that was exported to memory with "EXPORT ... TO MEMORY." . In contrast to the variant IMPORT FROM DATABASE , it does not check that the structure matches in EXPORT and IMPORT .
The return code value is set as follows:
SY-SUBRC = 0 The data objects were successfully imported.
SY_SUBRC = 4 The data objects could not be imported, probably
because the ABAP/4 memory was empty.
The contents of all objects remain unchanged.
Addition 1
... TO g (for each field f to be imported)
Effect
Takes the field contents stored under f from the global ABAP/4 memory and places them in the field g .
Addition 2
... ID key
Effect
Imports only data stored in ABAP/4 memory under the ID key .
The return code value is set as follows:
SY-SUBRC = 0 The data objects were successfully imported.
SY_SUBRC = 4 The data objects could not be imported, probably
because an incorrect ID was used.
The contents of all objects remain unchanged.
Variant 2
IMPORT f itab FROM DATABASE dbtab(ar) ID key.
Additions
1. ... TO g (for each field f to be imported)
2. ... MAJOR-ID maid (instead of ID key )
3. ... MINOR-ID miid (together with MAJOR-ID maid )
4. ... CLIENT h (after dbtab(ar) )
5. ... USING form
Effect
Imports data objects (fields, field strings or internal tables) with the ID key from the area ar of the database dbtab (see also EXPORT )
The return code value is set as follows:
SY-SUBRC = 0 The data objects were successfully imported.
SY_SUBRC = 4 The data objects could not be imported, probably
because an incorrect ID was used.
The contents of all objects remain unchanged.
Example
Import two fields and an internal table:
TABLES INDX.
DATA: INDXKEY LIKE INDX-SRTFD,
F1(4), F2 TYPE P,
BEGIN OF TAB3 OCCURS 10,
CONT(4),
END OF TAB3.
INDXKEY = 'INDXKEY'.
IMPORT F1 F2 TAB3 FROM DATABASE INDX(ST) ID INDXKEY.
Notes
The structure of fields, field strings and internal tables to be imported must match the structure of the objects exported to the dataset. In addition, the objects must be imported under the same name used to export them. If this is not the case, either a runtime error occurs or no import takes place.
Exception: You can lengthen or shorten the last field if it is of type CHAR , or add/omit CHAR fields at the end of the structure.
Addition 1
... TO g (for each field f to be imported)
Effect
Takes the field contents stored under the name f from the database and places them in g .
Addition 2
... MAJOR-ID maid (instead of ID key )
Addition 3
... MINOR-ID miid (together with MAJOR-ID maid )
Effect
Searches for a record with an ID that matches maid in the first part (length of maid ) and - if MINOR-ID miid is also specified - is greater than or equal to miid in the second part.
Addition 4
... CLIENT h (after dbtab(ar) )
Effect
Takes the data from the client h (only with client-specific import/export databases).
Example
TABLES INDX.
DATA F1.
IMPORT F1 FROM DATABASE INDX(AR) CLIENT '002' ID 'TEST'.
Addition 5
... USING form
Effect
Does not read the data from the database. Instead, calls the FORM routine form for each record read from the database without this addition. This routine can take the data key of the data to be retrieved from the database table work area and write the retrieved data to this work area schreiben; it therefore has no parameters.
Note
Runtime errors
Depending on the operands or the datsets to be imported, various runtime errors may occur.
Variant 3
IMPORT DIRECTORY INTO itab FROM DATABASE dbtab(ar) ID key.
Additions
1. ... CLIENT h (after dbtab(ar) )
Effect
Imports an object directory stored under the specified ID with EXPORT into the table itab .
The return code value is set as follows:
SY-SUBRC = 0 The directory was successfully imported.
SY_SUBRC = 4 The directory could not be imported, probably because an incorrect ID was used.
The internal table itab must have the same structure as the Dictionary structure CDIR (INCLUDE STRUCTURE ).
Addition 1
... CLIENT h (after dbtab(ar) )
Effect
Takes data from the client h (only with client-specific import/export databases).
Example
Directory of a cluster consisting of two fields and an internal table:
TABLES INDX.
DATA: INDXKEY LIKE INDX-SRTFD,
F1(4), F2 TYPE P,
BEGIN OF TAB3 OCCURS 10,
CONT(4),
END OF TAB3,
BEGIN OF DIRTAB OCCURS 10.
INCLUDE STRUCTURE CDIR.
DATA END OF DIRTAB.
INDXKEY = 'INDXKEY'.
EXPORT F1 F2 TAB3 TO
DATABASE INDX(ST) ID INDXKEY. " TAB3 has 17 entries
...
IMPORT DIRECTORY INTO DIRTAB FROM DATABASE INDX(ST) ID INDXKEY.
Then, the table DIRTAB contains the following:
NAME OTYPE FTYPE TFILL FLENG
-
F1 F C 0 4
F2 F P 0 8
TAB3 T C 17 4
The meaning of the individual fields is as follows:
NAME : Name of stored object OTYPE : Object type ( F : Field, R : Field string / Dictionary structure, T : Internal table) FTYPE : Field type ( C : Character, P : Packed, ...)
Field strings and internal tables have the type C. TFILL : Number of internal table lines filled FLENG : Length of field in bytes
With internal tables: Length of header line.
Variant 4
IMPORT f itab ... FROM DATASET dsn(ar) ID key.
Note
This variant is not to be used at present.
IMPORT DYNPRO - Import a screen
Basic form
IMPORT DYNPRO h f e m ID id.
Effect
Imports the screen specified in the field id . Loads the screen information into the structure h (screen header, structure D020S ) and into the internal tables f (field list, structure D021S ), e (flow logic, structure D022S ) and m (matchcode information, structure D023S ).
The return code value is set as follows:
SY-SUBRC = 0 The screen was successfully imported.
SY_SUBRC = 4 The screen does not exist.
Thanks & regards
Sreeni
2006 Jul 03 2:21 PM
Hai
Check the following Code
IMPORT - Get data
Variants
1. IMPORT f itab FROM MEMORY.
2. IMPORT f itab FROM DATABASE dbtab(ar) ID key.
3. IMPORT DIRECTORY INTO itab FROM DATABASE dbtab(ar) ID key.
4. IMPORT f itab FROM DATASET dsn(ar) ID key.
Variant 1
IMPORT f itab FROM MEMORY.
Additions
1. ... TO g (for each field f to be imported)
2. ... ID key
Effect
Imports data objects (fields or tables) from the ABAP/4 memory (see EXPORT ). Reads in all data without an ID that was exported to memory with "EXPORT ... TO MEMORY." . In contrast to the variant IMPORT FROM DATABASE , it does not check that the structure matches in EXPORT and IMPORT .
The return code value is set as follows:
SY-SUBRC = 0 The data objects were successfully imported.
SY_SUBRC = 4 The data objects could not be imported, probably
because the ABAP/4 memory was empty.
The contents of all objects remain unchanged.
Addition 1
... TO g (for each field f to be imported)
Effect
Takes the field contents stored under f from the global ABAP/4 memory and places them in the field g .
Addition 2
... ID key
Effect
Imports only data stored in ABAP/4 memory under the ID key .
The return code value is set as follows:
SY-SUBRC = 0 The data objects were successfully imported.
SY_SUBRC = 4 The data objects could not be imported, probably
because an incorrect ID was used.
The contents of all objects remain unchanged.
Variant 2
IMPORT f itab FROM DATABASE dbtab(ar) ID key.
Additions
1. ... TO g (for each field f to be imported)
2. ... MAJOR-ID maid (instead of ID key )
3. ... MINOR-ID miid (together with MAJOR-ID maid )
4. ... CLIENT h (after dbtab(ar) )
5. ... USING form
Effect
Imports data objects (fields, field strings or internal tables) with the ID key from the area ar of the database dbtab (see also EXPORT )
The return code value is set as follows:
SY-SUBRC = 0 The data objects were successfully imported.
SY_SUBRC = 4 The data objects could not be imported, probably
because an incorrect ID was used.
The contents of all objects remain unchanged.
Example
Import two fields and an internal table:
TABLES INDX.
DATA: INDXKEY LIKE INDX-SRTFD,
F1(4), F2 TYPE P,
BEGIN OF TAB3 OCCURS 10,
CONT(4),
END OF TAB3.
INDXKEY = 'INDXKEY'.
IMPORT F1 F2 TAB3 FROM DATABASE INDX(ST) ID INDXKEY.
Notes
The structure of fields, field strings and internal tables to be imported must match the structure of the objects exported to the dataset. In addition, the objects must be imported under the same name used to export them. If this is not the case, either a runtime error occurs or no import takes place.
Exception: You can lengthen or shorten the last field if it is of type CHAR , or add/omit CHAR fields at the end of the structure.
Addition 1
... TO g (for each field f to be imported)
Effect
Takes the field contents stored under the name f from the database and places them in g .
Addition 2
... MAJOR-ID maid (instead of ID key )
Addition 3
... MINOR-ID miid (together with MAJOR-ID maid )
Effect
Searches for a record with an ID that matches maid in the first part (length of maid ) and - if MINOR-ID miid is also specified - is greater than or equal to miid in the second part.
Addition 4
... CLIENT h (after dbtab(ar) )
Effect
Takes the data from the client h (only with client-specific import/export databases).
Example
TABLES INDX.
DATA F1.
IMPORT F1 FROM DATABASE INDX(AR) CLIENT '002' ID 'TEST'.
Addition 5
... USING form
Effect
Does not read the data from the database. Instead, calls the FORM routine form for each record read from the database without this addition. This routine can take the data key of the data to be retrieved from the database table work area and write the retrieved data to this work area schreiben; it therefore has no parameters.
Note
Runtime errors
Depending on the operands or the datsets to be imported, various runtime errors may occur.
Variant 3
IMPORT DIRECTORY INTO itab FROM DATABASE dbtab(ar) ID key.
Additions
1. ... CLIENT h (after dbtab(ar) )
Effect
Imports an object directory stored under the specified ID with EXPORT into the table itab .
The return code value is set as follows:
SY-SUBRC = 0 The directory was successfully imported.
SY_SUBRC = 4 The directory could not be imported, probably because an incorrect ID was used.
The internal table itab must have the same structure as the Dictionary structure CDIR (INCLUDE STRUCTURE ).
Addition 1
... CLIENT h (after dbtab(ar) )
Effect
Takes data from the client h (only with client-specific import/export databases).
Example
Directory of a cluster consisting of two fields and an internal table:
TABLES INDX.
DATA: INDXKEY LIKE INDX-SRTFD,
F1(4), F2 TYPE P,
BEGIN OF TAB3 OCCURS 10,
CONT(4),
END OF TAB3,
BEGIN OF DIRTAB OCCURS 10.
INCLUDE STRUCTURE CDIR.
DATA END OF DIRTAB.
INDXKEY = 'INDXKEY'.
EXPORT F1 F2 TAB3 TO
DATABASE INDX(ST) ID INDXKEY. " TAB3 has 17 entries
...
IMPORT DIRECTORY INTO DIRTAB FROM DATABASE INDX(ST) ID INDXKEY.
Then, the table DIRTAB contains the following:
NAME OTYPE FTYPE TFILL FLENG
-
F1 F C 0 4
F2 F P 0 8
TAB3 T C 17 4
The meaning of the individual fields is as follows:
NAME : Name of stored object OTYPE : Object type ( F : Field, R : Field string / Dictionary structure, T : Internal table) FTYPE : Field type ( C : Character, P : Packed, ...)
Field strings and internal tables have the type C. TFILL : Number of internal table lines filled FLENG : Length of field in bytes
With internal tables: Length of header line.
Variant 4
IMPORT f itab ... FROM DATASET dsn(ar) ID key.
Note
This variant is not to be used at present.
IMPORT DYNPRO - Import a screen
Basic form
IMPORT DYNPRO h f e m ID id.
Effect
Imports the screen specified in the field id . Loads the screen information into the structure h (screen header, structure D020S ) and into the internal tables f (field list, structure D021S ), e (flow logic, structure D022S ) and m (matchcode information, structure D023S ).
The return code value is set as follows:
SY-SUBRC = 0 The screen was successfully imported.
SY_SUBRC = 4 The screen does not exist.
Thanks & regards
Sreeni
2006 Jul 03 2:28 PM
Sure you can use field symbols. Check the example program below.
Program 1
report zrich_0001.
data: itab type table of string with header line.
field-symbols: <fs> type table.
itab = 'This is the line 1'. append itab.
itab = 'This is the line 2'. append itab.
assign itab[] to <fs>.
export <fs> to memory id 'ZRICHTEST'.
submit zrich_0002 and return.
Program 2
REPORT ZRICH_0002 .
data: itab type table of string with header line.
field-symbols: <fs> type table.
data: wa type string.
assign itab[] to <fs>.
import <fs> from memory id 'ZRICHTEST'.
loop at <fs> into wa.
write:/ wa.
endloop.
Regards,
Rich Heilman
2006 Jul 03 2:45 PM
Hi,
Thanks a lot !
By the way, I managed to get it to work with the following :
<b>Program 1</b>
DATA : tbl_usr01 TYPE TABLE OF usr01.
SELECT * FROM usr01
UP TO 50 ROWS
INTO TABLE tbl_usr01.
EXPORT tbl_usr01 TO MEMORY ID 'usr'.
<b>Program 2</b>
DATA: ta_data_ref TYPE REF TO DATA.
FIELD-SYMBOLS: <ft> TYPE table.
CREATE DATA ta_data_ref TYPE TABLE OF ('usr01').
ASSIGN ta_data_ref->* TO <ft>.
IMPORT tbl_usr01 TO <ft> FROM MEMORY ID 'usr'.
The only remaining problem is that in the Program 2, I would like to create the reference based on the content of the memory.
Would it be possible to inspect - somehow - the content of the memory cluster and get the type using ABAPDESCR classes... ?
I tried CL_ABAP_EXPIMP_MEM class but it doesn't give me the result I am expecting...
If not, I will store the type in a string before EXPORT... TO MEMORY and read it
Thanks again.
Best regards,
Guillaume
Message was edited by: Guillaume Garcia
2006 Jul 04 12:26 AM
why not export the description too?
Program 1
DATA : tbl_usr01 TYPE TABLE OF usr01.
SELECT * FROM usr01 UP TO 50 ROWS
INTO TABLE tbl_usr01.
EXPORT TABNAME FROM 'USR01' TO MEMORY ID 'usrTAB'.
EXPORT tbl_usr01 TO MEMORY ID 'usr'.
Program 2
DATA TNAME TYPE TABNAME.
DATA: ta_data_ref TYPE REF TO DATA.
FIELD-SYMBOLS: <ft> TYPE table.
IMPORT TABNAME TO TNAME FROM MEMORY ID 'usrTAB'.
CREATE DATA ta_data_ref TYPE TABLE OF (TNAME).
ASSIGN ta_data_ref->* TO <ft>.
IMPORT tbl_usr01 TO <ft> FROM MEMORY ID 'usr'.
2006 Jul 05 8:23 AM
Hi,
This is precisely what I meant by I will store it in a string.
Best regards,
Guillaume
2007 Dec 03 5:28 PM
Hi,
I would like to know if there is a way to import an object stored into memory supported in OO context.
I look the class CL_ABAP_EXPIMP_MEM , but i don't understand how to use it.
Can we help me.
Thanks in advance.
Best regards,
Francesco