Application Development 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: 

How to export data in export parameter

Former Member
0 Kudos

Hi,

I have written the below code.Now i want to export data into an export parameter which is a structure.

tables: t005t , t005.

data: BEGIN OF ty_countrylist occurs 100,

landx like t005t-landx,

intca like t005-intca,

END OF ty_countrylist.

SELECT t005tlandx t005intca into CORRESPONDING FIELDS OF TABLE ty_countrylist

from T005t

INNER JOIN t005 on ( t005tland1 = t005land1 ).

Can some one suggest how can that be done. The export parameter is a structure with two elments.

T_EX_COUNTRY---1)LANDX- LANDX[CHAR(15)] and 2) ISOCODE- INTCA[CHAR(2)].

I have tried creating internal table and work areas but it didnt work.

13 REPLIES 13

MarcinPciak
Active Contributor
0 Kudos

I guess T_EX_COUNTRY is a structure right? If so this is the way to do it.


data: BEGIN OF t_ex_country,
landx like t005t-landx,
intca like t005-intca,
END OF t_ex_country.

t_ex_country-landx = '01'.
t_ex_country-intca = '01'.

export structure = t_ex_country to MEMORY ID 'STRUCT'.

clear t_ex_country.
write: / 'After export and clear',
       t_ex_country-landx,
       t_ex_country-intca.

import structure = t_ex_country from MEMORY ID 'STRUCT'.

write: / 'After import',
       t_ex_country-landx,
       t_ex_country-intca.

Regards

Marcin

0 Kudos

This is the way i have implemented.Error that i am getting is : Type "ty_COUNTRY" is unknown.

FUNCTION Z_COUNTRYLIST_GET.

*"----


""Local Interface:

*" EXPORTING

*" VALUE(T_EX_COUNTRY) TYPE ZCONTRY

*"----


tables: t005t , t005.

data: BEGIN OF ty_COUNTRY occurs 150,

landx like t005t-landx,

intca like t005-intca,

END OF ty_COUNTRY.

**data: it_countrylist TYPE SORTED TABLE OF ty_countrylist WITH UNIQUE KEY intca.

data: wa_countrylist TYPE ty_COUNTRY.

SELECT t005tlandx t005intca into CORRESPONDING FIELDS OF TABLE ty_COUNTRY

from T005t

INNER JOIN t005 on ( t005tland1 = t005land1 ).

READ TABLE ty_COUNTRY INTO wa_countrylist

WITH TABLE KEY intca = wa_countrylist-intca.

APPEND ty_countrylist TO T_EX_COUNTRY.

ENDFUNCTION.

0 Kudos

Change this

data: wa_countrylist TYPE ty_COUNTRY.

with this


data: wa_countrylist LIKE LINE OF ty_COUNTRY.

It is because ty_country is an intenral table not a type. That's wy your structure must be like line of this table.

Regards

Marcin

0 Kudos

Hi deepika.

I have make changes in ur code . now it contains no error.

just copy and paste it in ur function editor window.

and then do tell me.

FUNCTION Z_COUNTRYLIST_GET.
*"----------------------------------------------------------------------
""Local Interface:
*" EXPORTING
*" VALUE(T_EX_COUNTRY) TYPE ZCONTRY
*"----------------------------------------------------------------------
TABLES: t005t , t005.
DATA: BEGIN OF ty_country1 OCCURS 150,
landx LIKE t005t-landx,
intca LIKE t005-intca,
END OF ty_country1.
data: ty_country like STANDARD TABLE OF ty_country1 WITH HEADER LINE with key intca.
**data: it_countrylist TYPE SORTED TABLE OF ty_countrylist WITH UNIQUE KEY intca.

"data: wa_countrylist TYPE ty_COUNTRY.
DATA: wa_countrylist LIKE ty_country.
data: t_ex_country like STANDARD TABLE OF ty_country.

SELECT t005t~landx t005~intca INTO CORRESPONDING FIELDS OF TABLE ty_country
FROM t005t
INNER JOIN t005 ON ( t005t~land1 = t005~land1 ).

READ TABLE ty_country INTO wa_countrylist WITH  KEY intca = wa_countrylist-intca.

APPEND wa_countrylist TO t_ex_country.

ENDFUNCTION.

and do tell me what do u want from these two lines.

means after selecting data what do u want from the filled internal table and on which criteria.

plz tell so that i made it change according to ur need.

after these two lines

READ TABLE ty_country INTO wa_countrylist WITH  KEY intca = wa_countrylist-intca.

APPEND wa_countrylist TO t_ex_country.

Edited by: tahir naqqash on Feb 3, 2009 6:56 PM

0 Kudos

Hi Tahir,

Even this didnt work.Its giving me an error "T_EX_Country has already been declared".

My main motive is to extract country names and thier ISO codes from the table and put them in an export parameter.Now the export parameter that i have created is a structure which has two elements.

One for Country names which is Char(15) and another for ISO codes which is Char(2). That is why i have written those two lines of code. That is, i am trying to put the fetched data into an internal table and then reading the internal table into a work area and finally then that work area is appended to the export parameter.

Basically me requirement is to put the data that is fetced from the table into my export parameter so that i can access that data for further processing.

0 Kudos

>

> Hi Tahir,

>

> Even this didnt work.Its giving me an error "T_EX_Country has already been declared".

>

> My main motive is to extract country names and thier ISO codes from the table and put them in an export parameter.Now the export parameter that i have created is a structure which has two elements.

> One for Country names which is Char(15) and another for ISO codes which is Char(2). That is why i have written those two lines of code. That is, i am trying to put the fetched data into an internal table and then reading the internal table into a work area and finally then that work area is appended to the export parameter.

>

> Basically me requirement is to put the data that is fetced from the table into my export parameter so that i can access that data for further processing.

Hello,

What is the functionality of your FM?

I see there are no import parameters to the FM, only export.

Also ZCONTRY is a structure. Then you have to create a Table Type for ZCONTRY in SE11 to use T_EX_COUNTRY as a table.

Else declare T_EX_COUNTRY as tables parameters.


T_EX_COUNTRY	LIKE	T005T
FUNCTION Z_COUNTRYLIST_GET.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      T_EX_COUNTRY STRUCTURE  T005T
*"----------------------------------------------------------------------

ENDFUNCTION.

Can you plz clarify?

Suhas

Edited by: Suhas Saha on Feb 4, 2009 10:41 AM

0 Kudos

My simple objective is to call the FM without any parameters and return the data that is fetched from the table to the calling function.

That is why i dont have import parameters only export

0 Kudos

Hi Deepika.

plz follow up the following steps. i have understood ur problem and now i have made it again changed according to ur need.

Step 1) Create the function. which i think u have already created and paste the code given below

FUNCTION ztn_test_d.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------


    TABLES: t005t , t005.
    DATA: BEGIN OF ty_country1 OCCURS 150,
    landx LIKE t005t-landx,
    intca LIKE t005-intca,
    END OF ty_country1.
    DATA: ty_country LIKE STANDARD TABLE OF ty_country1 WITH HEADER LINE WITH KEY intca.
**data: it_countrylist TYPE SORTED TABLE OF ty_countrylist WITH UNIQUE KEY intca.

    "data: wa_countrylist TYPE ty_COUNTRY.
    DATA: wa_countrylist LIKE ty_country.
    DATA: t_ex_country LIKE STANDARD TABLE OF ty_country.

    SELECT t005t~landx t005~intca INTO CORRESPONDING FIELDS OF TABLE ty_country
    FROM t005t
    INNER JOIN t005 ON ( t005t~land1 = t005~land1 ).

*    READ TABLE ty_country INTO wa_countrylist WITH  KEY intca = wa_countrylist-intca.
*
*    APPEND wa_countrylist TO t_ex_country.

itab_out[] = ty_country[].

  ENDFUNCTION.

Step 2) Instead of writing in function export parameters write this in function " Changing " Tab.

In parameter Name write the "ITAB_OUT" in type parameter write " TYPE" and in Associated type write the " ZDEP_COUNTRY_TABTYPE.

Step 3) Now i will tell u the steps to make the table type ZDEP_COUNTRY_TABTYPE.

0 Kudos

Hello Deepika,

Then the simple solution goes some thing like this:

FUNCTION z_countrylist_get.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      T_EX_COUNTRY STRUCTURE  ZTEST_STRUC
*"----------------------------------------------------------------------

  SELECT t005t~landx t005~intca INTO TABLE t_ex_country
  FROM   t005t INNER JOIN t005 ON t005t~land1 = t005~land1.

  IF sy-subrc = 0.
    SORT t_ex_country BY landx.
  ENDIF.

ENDFUNCTION.

Hope this helps.

Why do you need a FM to write a SELECT stmt? Any specific reason?

@Tahir: Do you need a separate table for this purpose ???

BR,

Suhas

Edited by: Suhas Saha on Feb 4, 2009 11:00 AM

0 Kudos

To Make table type ist u have to make the structure.

Step1) Goto SE 11. Choose DATA TYPE radio button. Write in it ZDEP_COUNTRY_STRUCTURE and then press create button. And now choose the structure radio button.

step2) Now give the both two data elements as u told that country name and it's ISO code and their CHAR Types with length as u mentiond. Activate it. It will show u warnings and then will become active

Step 3) Goto Se11 Again) Choose DATA TYPE radio button. Write in it ZDEP_COUNTRY_TABTYPE which we have to passed in CHANGING Parameter of function. Then press Create And now choose the " TABLE TYPE".

STep 4) Give short Text and in Line Type Give the name of structure which u have made in ist step . ANd activate it .

And now when u call ur function in test program. it will return u the country names with theiir iso codes in table itab_out[].

Sorry Suhas. I missed to remove extra lines of code.

Now Mr. Deepika Just made it As

TABLES: t005t , t005.
    DATA: BEGIN OF ty_country OCCURS 150,
    landx LIKE t005t-landx,
    intca LIKE t005-intca,
    END OF ty_country.

    SELECT t005t~landx t005~intca INTO CORRESPONDING FIELDS OF TABLE ty_country
    FROM t005t
    INNER JOIN t005 ON ( t005t~land1 = t005~land1 ).


itab_out[] = ty_country[].

Edited by: tahir naqqash on Feb 4, 2009 10:37 AM

Edited by: tahir naqqash on Feb 4, 2009 10:39 AM

0 Kudos

And in your main program call function just like this.

REPORT ztn_test.

data: itab type zdep_country_tabtype WITH HEADER LINE.


CALL FUNCTION 'FUNCTION U CREATED'
  CHANGING
    itab_out       = itab[].
          .

and now itab contain the country names with their iso codes.

0 Kudos

I am not calling this FM from another FM. I am calling it from a java program in web dynpro aaplication.

0 Kudos

oops!!!!!!!!!!

i have made this function to call it main program.