Sunday, July 6, 2008

Data declaration based on data-type declared in Global class

By Joyjit Ghosh,
Kolkata
, India
.

Prob:

In our project we got one requirement where we need to create a data declaration in custom program based on data type (TY_MARA in this case) declared in global class (Z_TEST).

Solution:

As in this case data type is declared as public. So we have created an object of global class and then used that object to refer the data type in our data declaration.

*& Report Z_TEST_DEMO1
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report z_test_demo1.

data oref type ref to z_test.

create object oref.

data: i_mara type standard table of oref->ty_mara initial size 0
with header line.

select * from mara into table i_mara
up to 10 rows.

check sy-subrc = 0.

loop at i_mara.

write:/ i_mara-matnr.

endloop.


Output:



Note:
This solution only works if data type is declared in the global class as public.

No comments: