2007 Sep 05 6:16 PM
hi
I want to know how to declare an internal table which will be global for the class step by step.
I want to use this internal table and modify the values inside this at runtime using the methods.
Please tell me how to proceed further
Points for all helpful answers
Message was edited by:
Grame Smith
2007 Sep 05 8:38 PM
Just create a table type in the Data Dictionary (SE11), then create an attribute of TYPE <createdtabletype>.
Regards
2007 Sep 05 8:38 PM
Just create a table type in the Data Dictionary (SE11), then create an attribute of TYPE <createdtabletype>.
Regards
2007 Sep 05 8:47 PM
Hello Grame
If you want to use the itab as <b>public </b>attribute or as parameter in public methods then you must use a table type that is defined either in the DDIC or within a type-pool.
However, if the itab is a <b>private </b>attribute (yet still global within the class!) then you can define your own table type in the <i>local definitions</i> sections.
Regards
Uwe
2007 Sep 06 3:41 AM
Hi
Can you please guide me how to create the type-pool, I have already created a type-pool for this purpose.. t_data
When I declare the internal table as an attribute SAG_DATA saying 'type table of t_data' I dont get any error
Even I am able to use the internal table in methods... using exporting and importing options..
No errors during activation too but finally when I execute this class it says syntax errors during generation... when i get in to see the errors i see the errors like not able to convert types..
Please help me on this
2007 Sep 06 5:07 AM
Hi Grame,
Please see HELP link
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3138358411d1829f0000e829fbfe/content.htm
TYPE-POOLS <pool>.
This statement allows you to use all the data types and constants defined in the type group <pool> in your program. You can use several type groups in the same program.
Let the type group HKTST be created as follows in the ABAP Dictionary:
TYPE-POOL hktst.
TYPES: BEGIN OF hktst_typ1,
col1(10) TYPE c,
col2 TYPE i,
END OF hktst_typ1.
TYPES hktst_typ2 TYPE p DECIMALS 2.
CONSTANTS hktst_eleven TYPE i VALUE 11.
This type group defines two data types HKTST_TYP1 and HKTST_TYP2, as well as a constant HKTST_ELEVEN with the value 11.
Any ABAP program can use this definition with the TYPE-POOLS statement:
TYPE-POOLS hktst.
DATA: dat1 TYPE hktst_typ1,
dat2 TYPE hktst_typ2 VALUE '1.23'.
WRITE: dat2, / hktst_eleven.
The output is:
1,23
11
The data types defined in the type group are used to declare data objects with the DATA statement and the value of the constant is, as the output shows, known in the program.
+++++++
Also read previous posting
Regards,
Aby
2007 Sep 06 10:22 AM
If it's an INTERNAL table which doesn't imply persistence (i.e the data being stored / worked on isn't permanent) then a MUCH MUCH better idea is to use a Dynamic table even if you aren't going to use a GRID.
For example in your application program code something like this
TABLES : VAPMA.
TYPES: BEGIN OF s_elements,
vbeln TYPE vapma-vbeln,
posnr TYPE vapma-posnr,
matnr TYPE vapma-matnr,
kunnr TYPE vapma-kunnr,
werks TYPE vapma-werks,
vkorg TYPE vapma-vkorg,
vkbur TYPE vapma-vkbur,
status(5) TYPE c,
END OF s_elements.
DATA: my_line TYPE s_elements.
CREATE OBJECT z_object EXPORTING z_object = z_object.
CALL METHOD z_object->build_dynamic_structures
EXPORTING
my_line = my_line
calling_program = sy-repid
IMPORTING
dy_table = dy_table
CHANGING
it_fldcat = it_fldcat.
in your class definition have these methods
METHOD build_dynamic_structures.
caller = calling_program.
CALL METHOD me->return_structure
EXPORTING
my_line = my_line.
CALL METHOD me->create_dynamic_fcat
IMPORTING
it_fldcat = it_fldcat.
CALL METHOD me->create_dynamic_table
EXPORTING
it_fldcat = it_fldcat
IMPORTING
dy_table = dy_table.
ENDMETHOD. "build_dynamic_structures
METHOD return_structure.
lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( my_line ).
zogt[] = lr_rtti_struc->components.
ENDMETHOD. "return_structure
METHOD create_dynamic_fcat.
LOOP AT zogt INTO zog.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-dataTYPE = zog-TYPE_kind.
wa_it_fldcat-intTYPE = zog-TYPE_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
case sy-tabix.
When 2. "edit fields if using a grid --not necessary for standard pgm
wa_it_fldcat-edit = 'X'.
When 4.
wa_it_fldcat-edit = 'X'.
when 6.
wa_it_fldcat-edit = 'X'.
when others.
wa_it_fldcat-edit = ' '.
endcase.
APPEND wa_it_fldcat TO it_fldcat .
ENDLOOP.
ENDMETHOD. "create_dynamic_fcat
METHOD create_dynamic_table.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = dy_table.
Now fill you dynamic table with data
for example
FORM populate_dynamic_itab.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
SELECT vbeln posnr matnr kunnr werks vkorg vkbur
UP TO 200 rows
FROM vapma
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.
In your data definition
<dyn_table> TYPE STANDARD TABLE,
<orig_table> TYPE STANDARD TABLE,
<dyn_wa> TYPE ANY.
Now this will be available both to the class / methods in the class AND your application program.
Remember in OO you can't have tables with header lines anyway.
I think the dynamic table approch works best for "non persistent" data and can be used with ANY structure whether in the ddic or not.
<b>If you want to do it by the the standard method</b>
Then proceed as follows
In your class in the PUBLIC section (SE24)
code something like this for your internal table structure
types:
begin of s_matord,
matnr type vbap-matnr,
arktx type vbap-arktx,
kunnr type vapma-kunnr,
vbeln type vapma-vbeln,
posnr type vapma-posnr,
audat type vapma-audat,
auart type vapma-auart,
kwmeng type vbap-kwmeng,
vrkme type vbap-vrkme,
netwr type vbap-netwr,
end of s_matord .
types:
zmatord type standard table of s_matord .
Now in a method where we want to use this table
(method in the class is get_orders_for_material)
set the parameters as follows
Material (import) type vapma-matnr
MATORD (export) type zmatord.
now in your application program
code
TYPES:
begin of s_matord,
matnr type vbap-matnr,
arktx type vbap-arktx,
kunnr type vapma-kunnr,
vbeln type vapma-vbeln,
posnr type vapma-posnr,
audat type vapma-audat,
auart type vapma-auart,
kwmeng type vbap-kwmeng,
vrkme type vbap-vrkme,
netwr type vbap-netwr,
end of s_matord .
DATA: matord type table of s_matord,
obj type ref to zcl_sales_order. "Your class
Instantiate our Sales order from parameter
create object obj exporting vbeln = p_vbeln.
now when you call your method
<b>call method obj->get_orders_for_material
exporting material = p_matnr
importing matord = matord.</b>
Your data will be in matord. It doesn't have a header line but you can use a field symbol or xxxx[] = yyyy[] type of construct to read the table line by line.
Here's the METHOD defined in the class
<b>method GET_ORDERS_FOR_MATERIAL.
data: t_matord type standard table of s_matord,
l_matord type s_matord.
select amatnr aauart avbeln aposnr aaudat akunnr
barktx bkwmeng bvrkme bnetwr
into corresponding fields of table t_matord
from ( vapma as a
inner join vbap as b
on avbeln eq bvbeln
and aposnr eq bposnr )
where a~matnr eq material.
matord[] = t_matord[].
endmethod.</b>
Works in reverse as well --the method can READ your table that you pass to it - you need to set of course correct export / import / changing parameters.
In the method use the xxxx[] = yyyyy[] construct to get the data into a table.
Don't make this stuff more complicated than you need. I often read posts in the OO forum where people seem to make a great problem out of what should be a fairly simple solution.
Using this approach you don't have to worry about DDIC fields or type pools either.
I prefer the Dynamic table approach myself as it's totally more general but the "Classical" way still works as shown above.
Cheers
jimbo
2007 Sep 07 5:52 PM
Thanks for the answers
I found a good solution to my problem
1. Either goto SE24 and create table types and declare them for your internal table type.
2. Declare local structures in your table... then create a type table for it
types: t_data type table of ts_data
Then in the attributes give the type as t_data or Se12 created table type.