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

EXPORT AND IMPORT QUERY

Former Member
0 Likes
2,211

Hi,

can any one give me an example

using and export and import keywords

using in 2 different programs

with different variabl names exporting and importing

12 REPLIES 12
Read only

anversha_s
Active Contributor
0 Likes
1,550

Hi,

Check this sample code.

A simple example of ABAP memory is using the EXPORT/IMPORT statements.

Here in this program, I get the data, export it to memory,

clear out the internal table in my progam, then reimport the data into it and write out the data.

You probably wounldn't do this in a normal program,

but this is how you can pass data from program a to program b when A Submits program B.

report zxy_0002 .
 
data: it001 type table of t001 with header line.

select * into table it001 from t001.
 
export it001 = it001 to memory id 'ZXY_TEST'.
 
clear it001. refresh it001.
 
import it001 = it001 from memory id 'ZXY_TEST'.
 
loop at it001.
  write:/ it001-bukrs, it001-butxt.
endloop.

rgds

anver

<i>if hlped pls mark points</i>

Read only

Former Member
0 Likes
1,550

HI Kiran

Apart from the info provided by Anversha, please note that while using these commands we have to make sure that the declaration of <b>variables/structures/internal tables</b> whatever we use, should be <b>SAME</b> including the name in all the objects we use.

Eg:

If we are emporting internal table itab1 which has fields fld1, fld2 & fld3 from program1 which can be referred as callee. It should be declared the same in way in calling program(program2 also).

Kind Regards

Eswar

Read only

rahulkavuri
Active Contributor
0 Likes
1,550

DEMO_DATA_EXT_CLUSTER_IMPORT

check this standard pgm

Read only

Former Member
0 Likes
1,550

To read data objects from an ABAP program into ABAP memory, use the following statement:

Syntax

EXPORT <f1> [FROM <g 1>] <f 2> [FROM <g 2>] ... TO MEMORY ID <key>.

This statement stores the data objects specified in the list as a cluster in memory. If you do not use the option FROM <f i >, the data object <f i > is saved under its own name. If you use the FROM <g i > option, the data objet <g i > is saved under the name <f i >. The name <key> identifies the cluster in memory. It may be up to 32 characters long.

The EXPORT statement always completely overwrites the contents of any existing data cluster with the same name <key>.

If you are using internal tables with header lines, you can only store the table itself, not the header line. In the EXPORT statement, the table name is interpreted as the table. This is an exception to the general rule, under which statements normally interpret the table name as a table work area (see Choosing a Table Type).

PROGRAM SAPMZTS1.

DATA TEXT1(10) VALUE 'Exporting'.

DATA ITAB LIKE SBOOK OCCURS 10 WITH HEADER LINE.

DO 5 TIMES.

ITAB-BOOKID = 100 + SY-INDEX.

APPEND ITAB.

ENDDO.

EXPORT TEXT1

TEXT2 FROM 'Literal'

TO MEMORY ID 'text'.

EXPORT ITAB

TO MEMORY ID 'table'.

In this example, the text fields TEXT1 and TEXT2 are stored in the ABAP memory of program SAPMZTS1 under the name "text". The internal table ITAB is stored under the name "table".

To read data objects from ABAP memory into an ABAP program, use the following statement:

Syntax

IMPORT <f1> [TO <g 1>] <f 2> [TO <g 2>] ... FROM MEMORY ID <key>.

PROGRAM SAPMZTS1.

DATA TEXT1(10) VALUE 'Exporting'.

DATA ITAB LIKE SBOOK OCCURS 10 WITH HEADER LINE.

DO 5 TIMES.

ITAB-BOOKID = 100 + SY-INDEX.

APPEND ITAB.

ENDDO.

EXPORT TEXT1

TEXT2 FROM 'Literal'

TO MEMORY ID 'text'.

EXPORT ITAB

TO MEMORY ID 'table'.

SUBMIT SAPMZTS2 AND RETURN.

SUBMIT SAPMZTS3.

The programs SAPMZTS1 and SAPMZTS2 are called using SUBMIT. You can create and maintain the programs called using the SUBMIT statement by double-clicking their names in the statement.

Example for SAPMZTS2:

PROGRAM SAPMZTS2.

DATA: TEXT1(10),

TEXT3 LIKE TEXT1 VALUE 'Initial'.

IMPORT TEXT3 FROM MEMORY ID 'text'.

WRITE: / SY-SUBRC, TEXT3.

IMPORT TEXT2 TO TEXT1 FROM MEMORY ID 'text'.

WRITE: / SY-SUBRC, TEXT1.

Example for SAPMZTS3:

PROGRAM SAPMZTS3.

DATA JTAB LIKE SBOOK OCCURS 10 WITH HEADER LINE.

IMPORT ITAB TO JTAB FROM MEMORY ID 'table'.

LOOP AT JTAB.

WRITE / JTAB-BOOKID.

ENDLOOP.

The program SAPMZTS2 attempts to read a data object TEXT3 from the data cluster "text", which does not exist. TEXT3 therefore remains unchanged. The existing data object TEXT2 is placed in TEXT1. In both cases, SY-SUBRC is 0, since the cluster "text" contains data.

The program SAPMZTS3 reads the internal table ITAB from the cluster "table" into the internal table JTAB. Both tables have the same structure, namely that of the ABAP Dictionary table SBOOK.

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

0 Likes
1,550

hi all,

<u>without using submit</u>

i have to export the data from one include prg

and then import this data in the second include prg

whether it is possible, but i have to use temporary memory for this export and import.

Read only

0 Likes
1,550

Hi kiran,

hope u went to the rply i had given above.

just export to the memory in one pgm.

In later program download from that memeory.

thats all. there is nothing related to submit and all

rgds

Anver

Read only

Former Member
0 Likes
1,550

hi

good

REPORT demo_program_submit_rep1.

DATA number TYPE i.

PARAMETERS paramet(14) TYPE c.

SELECT-OPTIONS selecto FOR number.

The program DEMOdemo_program_submit_rep1 is called by the following program using various parameters:

REPORT demo_program_submit_sel_screen NO STANDARD PAGE HEADING.

DATA: int TYPE i,

rspar TYPE TABLE OF rsparams,

wa_rspar LIKE LINE OF rspar.

RANGES seltab FOR int.

WRITE: 'Select a Selection!',

/ '----


'.

SKIP.

FORMAT HOTSPOT COLOR 5 INVERSE ON.

WRITE: 'Selection 1',

/ 'Selection 2'.

AT LINE-SELECTION.

CASE sy-lilli.

WHEN 4.

seltab-sign = 'I'. seltab-option = 'BT'.

seltab-low = 1. seltab-high = 5.

APPEND seltab.

SUBMIT demo_program_submit_rep1 VIA SELECTION-SCREEN

WITH paramet eq 'Selection 1'

WITH selecto IN seltab

WITH selecto ne 3

AND RETURN.

WHEN 5.

wa_rspar-selname = 'SELECTO'. wa_rspar-kind = 'S'.

wa_rspar-sign = 'E'. wa_rspar-option = 'BT'.

wa_rspar-low = 14. wa_rspar-high = 17.

APPEND wa_rspar TO rspar.

wa_rspar-selname = 'PARAMET'. wa_rspar-kind = 'P'.

wa_rspar-low = 'Selection 2'.

APPEND wa_rspar TO rspar.

wa_rspar-selname = 'SELECTO'. wa_rspar-kind = 'S'.

wa_rspar-sign = 'I'. wa_rspar-option = 'GT'.

wa_rspar-low = 10.

APPEND wa_rspar TO rspar.

SUBMIT demo_program_submit_rep1 VIA SELECTION-SCREEN

WITH SELECTION-TABLE rspar

AND RETURN.

ENDCASE.

thanks

mrutyun^

Read only

0 Likes
1,550

hi anversh & all,

check whether it is accepting the import in second

prg once u export the value from the first program.

check with simple variable it will be easy.

thx & reply me

Read only

0 Likes
1,550

HI Kiran

I guess you are trying by using 2 session one for EXPORT and IMPORT, in that case use addition <b>FROM DATABASE</b>.

If you execute as one session one after the other, you can avoid the addition.

Kind Regards

Eswar

Read only

0 Likes
1,550

hi eswar & all,

please can u try this

by using <u>2 different prg</u> one for export and another for

import and check whether it is working properly or not

<u> check by using only simple variable (i,c,string)</u>

<u>please send me step by step procedure</u>

if u r using database option the parameter for that is table (check this) but <u>i need simple variables only</u>

Read only

0 Likes
1,550

Hi Kiran

Please try as per below example:

<b>Program1:</b>

DATA: IT_T001 TYPE STANDARD TABLE OF T001.

SELECT * INTO TABLE IT_T001 FROM T001.

EXPORT IT_T001 TO DATABASE INDX(D1) ID 'D1'.

<b>Program2:</b>

DATA: IT_T001 TYPE STANDARD TABLE OF T001.

IMPORT IT_T001 FROM DATABASE INDX(D1) ID 'D1'.

BREAK-POINT.

Kind Regards

Eswar

Read only

0 Likes
1,550

Hi kiran,

report zex1.

DATA : pernr LIKE p0001-pernr.

pernr = '00004556'.

*EXPORT pernr TO MEMORY ID 'PERNR'.

SET PARAMETER ID 'PERNR' FIELD PERNR.

*SUBMIT zex2.

report zex2

DATA : pernr LIKE p0001-pernr.

GET PARAMETER ID 'PERNR' FIELD PERNR.

*IMPORT pernr FROM MEMORY ID 'PERNR'.

WRITE pernr.

First u execute the zex1 program so that pernr value will be stored in memory.

Then u execute zex2 program so that it can get it from memory

*********************************************************

report zex1.

DATA : pernr LIKE p0001-pernr.

pernr = '00004556'.

EXPORT pernr TO MEMORY ID 'PERNR'.

*SET PARAMETER ID 'PERNR' FIELD PERNR.

SUBMIT zex2.

report zex2.

DATA : pernr LIKE p0001-pernr.

*GET PARAMETER ID 'PERNR' FIELD PERNR.

IMPORT pernr FROM MEMORY ID 'PERNR'.

WRITE pernr.

u execute zex1 then u get the o/p which u require

U r saying without using submit u want to retrieve the content of a variable stored in memory location , i think this is not possible by using import and export statements.

Since, export statement keeps the content in local memory, and this memory is visible only with in a program so u cannot use this in another program diretly, if u want to use then, call another program by using submit statement.

If u dont want submit statement to use then, use set parameter id and get parameter id