How to return an internal table with methods ?
Hi,
I am an Java programmer and very new to ABAP.
How do I return a internal table with a method? I have the table GP1_PRODUCTS and want to return a copy of this table as an internal table called PRODUCTS.
Here is my code that does not work:
class PRODUCTS definition
public
final
create public .
public section.
*"* public components of class PRODUCTS
*"* do not include other source files here!!!
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type GP1_PRODUCTS .
protected section.
*"* protected components of class PRODUCTS
*"* do not include other source files here!!!
private section.
*"* private components of class PRODUCTS
*"* do not include other source files here!!!
ENDCLASS.
CLASS PRODUCTS IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method PRODUCTS->GET_PRODUCT_LIST
* +-------------------------------------------------------------------------------------------------+
* | [<-()] PRODUCTS TYPE GP1_PRODUCTS
* +--------------------------------------------------------------------------------------</SIGNATURE>
method GET_PRODUCT_LIST.
DATA: it_products TYPE STANDARD TABLE OF GP1_PRODUCTS.
select * from GP1_PRODUCTS into table it_products.
PRODUCTS = it_products.
endmethod.
ENDCLASS.
You have to create a table type for your table GP1_PRODUCTS.
If you use global class (created in SE24), than:
Create a Table Type in SE11
Go to SE11, Enter a name like ZPRODUCTS in the Data Type
There will be popup when you press the Create button to decide a type. Select the Table Type
Enter GP1_PRODUCTS in the Line Type.
* method declaration
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type ZPRODUCTS.
If you use local class:
TYPES: ty_products type standard table of GP1_PRODUCTS..
* method declaration
methods GET_PRODUCT_LIST
returning
value(PRODUCTS) type ty_products
Regards,
Naimesh Patel
Similar Messages
-
How to read an internal table with more than one (2 or 3) key field(s).
how to read an internal table with more than one (2 or 3) key field(s). in ecc 6.0 version
hi ,
check this..
report.
tables: marc,mard.
data: begin of itab occurs 0,
matnr like marc-matnr,
werks like marc-werks,
pstat like marc-pstat,
end of itab.
data: begin of itab1 occurs 0,
matnr like mard-matnr,
werks like mard-werks,
lgort like mard-lgort,
end of itab1.
parameters:p_matnr like marc-matnr.
select matnr
werks
pstat
from marc
into table itab
where matnr = p_matnr.
sort itab by matnr werks.
select matnr
werks
lgort
from mard
into table itab1
for all entries in itab
where matnr = itab-matnr
and werks = itab-werks.
sort itab1 by matnr werks.
loop at itab.
read table itab1 with key matnr = itab-matnr
werks = itab-werks.
endloop.
regards,
venkat. -
How to create an internal table with a types structure?
Hi experts,
I've 3 internal tables with the same structure, I think I could put a type structure and put that type inside the body of the internal data, is this possible? If true, how can I put that?
Example:
TYPES: Begin of type_s,
pernr like pa0001-pernr,
end of type_s.
Data: begin of itab_1 occurs 0,
¿¿¿??? reference to type_s
end of itab_1.
Thanks a lot,
Regards,
RebecaHi,
Use like this..
DATA: Begin of type_s,
pernr like pa0001-pernr,
end of type_s.
DATA: BEGIN OF ITAB_1 OCCURS 0.
INCLUDE STRUCTURE type_s.
DATA: END OF ITAB_1.
Otherwise like this.
types: Begin of type_s,
pernr like pa0001-pernr,
end of type_s.
Data: itab_1 type standard table of type_s.
Note: You have to create work area explicitly.
Like this
data wa like itab1.
Edited by: Velangini Showry Maria Kumar Bandanadham on May 26, 2009 1:04 PM -
How to sort an internal table with a header line?
hi all,
i have declared table i_bseg type standard table of bseg with header line.
now i have populated data in i_bseg.
now i am sorting it by bukrs
ie i am writing sort i_bseg by bukrs.
before sorting all i_bseg-belnrs were populated...
but after sorting the contents of the i_bseg is changing.
some of the belnrs are getting deleted..
is there any special way to sort an internal table with header line...?hi,
<b>SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].</b>
The statement sorts the internal table <itab> in ascending order by its key.<b> The statement always applies to the table itself, not to the header line</b>.
If you have an internal table with a structured line type that you want sort by a different key, you can specify the key in the SORT statement:
SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE]
BY <f1> [ASCENDING|DESCENDING] [AS TEXT]
<fn> [ASCENDING|DESCENDING] [AS TEXT].
<b>this is your sort statement: sort i_bseg by bukrs.
you try with this statement: sort i_bseg by bukrs STABLE.</b>
regards,
Ashokreddy -
How to create Dynamic internal table with columns also created dynamically.
Hi All,
Any info on how to create a dynamic internal table along with columns(fields) also to be created dynamically.
My requirement is ..On the selection screen I enter the number of fields to be in the internal table which gets created dynamically.
I had gone thru some posts on dynamic table creation,but could'nt find any on the dynamic field creation.
Any suggestions pls?
Thanks
NaraI don't understand ...
something like that ?
* Form P_MODIFY_HEADER. *
form p_modify_header.
data : is_fieldcatalog type lvc_s_fcat ,
v_count(2) type n ,
v_date type d ,
v_buff(30).
* Update the fieldcatalog.
loop at it_fieldcatalog into is_fieldcatalog.
check is_fieldcatalog-fieldname+0(3) eq 'ABS' or
is_fieldcatalog-fieldname+0(3) eq 'VAL' .
move : is_fieldcatalog-fieldname+3(2) to v_count ,
p_perb2+5(2) to v_date+4(2) ,
p_perb2+0(4) to v_date+0(4) ,
'01' to v_date+6(2) .
v_count = v_count - 1.
call function 'RE_ADD_MONTH_TO_DATE'
exporting
months = v_count
olddate = v_date
importing
newdate = v_date.
if is_fieldcatalog-fieldname+0(3) eq 'ABS'.
concatenate 'Quantité 0'
v_date+4(2)
v_date+0(4)
into v_buff.
else.
concatenate 'Montant 0'
v_date+4(2)
v_date+0(4)
into v_buff.
endif.
move : v_buff to is_fieldcatalog-scrtext_s ,
v_buff to is_fieldcatalog-scrtext_m ,
v_buff to is_fieldcatalog-scrtext_l ,
v_buff to is_fieldcatalog-reptext .
modify it_fieldcatalog from is_fieldcatalog.
endloop.
* Modify the fieldcatalog.
call method obj_grid->set_frontend_fieldcatalog
exporting it_fieldcatalog = it_fieldcatalog.
* Refresh the display of the grid.
call method obj_grid->refresh_table_display.
endform. " P_MODIFY_HEADER -
How to create an internal table with fields from different sources
Hi.
I need to create an internal table where some of the fields are from a database table, and the other fields are user specified. How do i do that?
Example:
DB table ZTAB with fields ZTAB-FIELD1, ZTAB-FIELD2.
I want to create an internal table ITAB with the fields ZTAB-FIELD1, ZTAB-FIELD2 from ZTAB. In addition, I also want to have one more field RECORD_NO, which is not from ZTAB. How do I do it? Could I do something like below?
DATA BEGIN OF ITAB.
INCLUDE STRUCTURE ZTAB.
DATA RECORD_NO TYPE I.
DATA END OF UPLINE.
Or, are there more efficient way of doing it? Thanks.hi KIan,
go:
general type
TYPE : BEGIN OF ty_itab,
field1 TYPE ztab-field1,
field2 TYPE ztab-field2,
*your own fields here:
field TYPE i,
field(30) TYPE c,
END OF ty_itab.
work area
DATA : gw_itab TYPE ty_itab.
internal table
DATA : gt_itab TYPE TABLE OF ty_itab.
hope this helps
ec -
How to use dynamic internal table with FOR ALL ENTRIES
Hello SDNers,
I am having a dynamic internal table & want to use FOR ALL ENTRIES(FAE) using this dyn. table.
This works fine for me:
IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
SELECT field1 field2
FROM TABLE ztable
INTO TABLE itab "Itab is a static table
FOR ALL ENTRIES IN <lt_tmp>
WHERE (lv_dynwhere). "lv_dynwhere -> dynamic where clause
ENDIF.
SAP documentation says:
"The logical expression sql_cond of the WHERE condition can be comprised of several logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically. "
How do we specify the column of the internal table dynamically ? Can we do something like this:
IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
SELECT field1 field2
FROM TABLE
INTO TABLE itab "Itab is a static table
FOR ALL ENTRIES IN <lt_tmp>
WHERE key_field1 = (dynamic token for column1 of <lt_tmp>)
key_field2 = (dynamic token for column2 of <lt_tmp>)
ENDIF.
ENDIF.
Let me know if i am not clear about my requirement.
BR,
SuhasHello Thomas,
What i meant was something like this:
WHERE key_field1 = ('<LT_TMP-COL1>') AND
key_field2 = ('<LT_TMP-COL2>')
I am confused by what SAP means with "dynamic representation of internal table columns" in FAE ?
@Rob: I was referring to SAPNW 7.0 documentation & the phrase (release 6.40 & higher) is missing. Anyways fyi i am on ECC5.0 ABAP release 6.40.
@Subhankar: This is what Marcin had proposed in For all entries and dynamic table.
Thanks,
Suhas
Edited by: Suhas Saha on Apr 6, 2010 11:53 AM -
How to create an internal table with header line in smartforms
Hello Guys,
I need to append the data in my internal table in smartforms by the problem is an error occurred "a table without header line and therefore no component called tdline"
i already declared the data under types declaration tab
types : begin of ts_tline,
TDFORMAT type tdformat,
tdline type tdline,
end of ts_tline.
types : it_tline type table of ts_tline.
and declare these in global data
WA_TLINE type TS_TLINE
XT_TLINE type IT_TLINE
my syntax in program lines :
LOOP AT gy_lines INTO WA_PROJ.
SPLIT wa_proj AT cl_abap_char_utilities=>cr_lf
INTO table IT_SPLIT.
LOOP AT IT_SPLIT.
MOVE it_split-commentext TO xt_TLINE-tdline.
an error occured at this part ****
append xt_TLINE.
ENDLOOP.
ENDLOOP.
what is wrong with my code..it cannot append data to xt_tline.
Please help.Will reward points
Thanks in advance
aVaDuDzcheck this link
this will help u......
http://www.****************/Tutorials/Smartforms/SFMain.htm
reward IF..........
regards
Anbu -
ABAP OO: how to pass a internal table with objects as a method parameter
Hello all,
I have a class "ZCL_VEHICLE", this class contains the attribute WHEELS.
This attribute contains objects of the class ZCL_WHEEL.
(definition: data WHEELS TYPE TABLE OF REF TO zcl_wheel.).
I now need a method that gives this table back (as return or export parameter). How can I define a parameter for this method that will contain this table?
Thanks for the help.
Best regards,
WimHi Wim
Excuse me! I understood you wanted to define it in a program, not in a class.
You can define your type into CLASS (use the same statament: go to TYPES (there's a pushbotton on status gui).
TYPES: MY_WHEELS TYPE TABLE OF REF TO .....
Now you can use this type to create a parameter like that, but you can use that type for an object of class defined as PRIVATE.
Infact if your object is public, you'll use it in a your program, so you'll probably have to define a variable like the type defined in the class.
It shouldn't make sense to define the same type for two times or more (one in the class, the others in each program uses your class). So you should define your type in dictionary (all abap object could use it).
If you think to have to use your class in few program (perhaps in olny one), you shuold consider to create your class as local class.
Max
Message was edited by: max bianchi -
How to fill internal table with no data in debugging mode
Hi all,
I modified one existing program.Now I want to test it.I am not given test data.So in the middle of my debugging, I found that one internal table with no data.My problem is how to fill that internal table with few records in that debugging mode just as we change contents in debugging mode.If I want to proceed further means that internal table must have some records.
Please I dont know how to create test data so I am trying to create values temporarily in debugging mode only.
Thanks,
BalajiHi,
In the debugging do the following..
Click the Table button..
Double click on the internal table name..
Then in the bottom of the screen you will get the buttons like CHANGE, INSERT, APPEND, DELETE..
Use the APPEND button to insert records to the internal table..
Thanks,
Naren -
Internal table with Dynamic and Non dynamic fileds
Hi Experts,
How to get the internal table with Dynamic and Non-Dynamic Fields.
Could u please help me.
Thanks,
VarunHi,
Execute the below sample code or analyze it there is appropriate description provided.
*& Report ZTEST_PRM_DYN_ALV
REPORT ZTEST_PRM_DYN_ALV.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.
start-of-selection.
*build the dynamic internal table
perform build_dyn_itab.
*write 5 records to the alv grid
do 5 times.
perform build_report.
enddo.
*call the alv grid.
perform call_alv.
*Build_dyn_itab
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
*Create fields .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'name1'.
wa_it_fldcat-datatype = 'mara-matnr'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
*clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 6.
append wa_it_fldcat to it_fldcat .
enddo.
*Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
*Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*Form build_report
form build_report.
data: fieldname(20) type c.
data: fieldvalue(5) type c.
data: index(3) type c.
field-symbols: <fs1>.
do p_flds times.
index = sy-index.
*Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
*Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.
*CALL_ALV
form call_alv.
data: wa_cat like line of alv_fldcat.
*clear wa_cat.
wa_cat-fieldname = 'matnr'.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '10'.
append wa_cat to alv_fldcat.
do p_flds times.
clear wa_cat.
wa_cat-fieldname = sy-index.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '6'.
append wa_cat to alv_fldcat.
enddo.
*Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = alv_fldcat
tables
t_outtab = <dyn_table>.
endform.
Hope this will help, reward if found usefull.
Cheers,
Ram. -
Read internal table with key not equal to
Hi,
How can I read internal table with key not equal to some other field.
Basically in read statement we can read only fields equal to others fields.Hi,
Test the following Code you can Use Loop at for this But not Read Table
DATA: BEGIN OF it_test OCCURS 10,
f1(4),
f2 TYPE i,
f3(2),
END OF it_test.
DATA: it_test2 LIKE STANDARD TABLE OF it_test WITH HEADER LINE.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'B'.
APPEND it_test TO it_test.
it_test-f1 = '2000'.
it_test-f2 = 10.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'B'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 40.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
LOOP AT it_test INTO it_test WHERE f3 NE 'A'.
WRITE: / it_test-f1, it_test-f2, it_test-f3.
ENDLOOP.
Kind Regards,
Faisal -
How to pass internal table with data in ABAP OO
Hi experts ,
Here is the problem...
I create a screen 100 and use the internal table to get data from database, and then press the button on screen 100 , it will call screen 200.
I use ABAP OO code in screen 200, and i want to keep the internal table with data that i get from the sceen 100 parts, but it seems that it just supports to create a new internal table and get data from database in ABAP OO. That means i need to create a new table to save the data in internal table ? Or there is any other solution something like exporting or memory id ...
ps . the internal table in screen 100 is declared in global area, the beginning of the code.
Please give me some advice, thanks a lot!
Regards ,
ClaireI have already know how to do, here is my code:
METHODS fill_tree importing itab2 like itab1.
CALL METHOD: me->fill_tree exporting itab2 = itab1.
In METHOD fill_tree,
declare
data: itab3 TYPE STANDARD TABLE OF itab,
itab3[] = itab1[].
It is useful to me, thanks a lot. -
How to pass internal table to method of class
Hi all,
I am new to abap objects, i want to pass one internal table to class.
i am trying in this way.
class c1 definition.
method get_material importing t_stpo type any table
exporting t_mast type any table.
endmethod.
endclass.
class c1 implementation.
method get_material.
select f1 f2 f3 from <tab> into table t_mast
for all entries in t_stpo
where stlnr = t_stpo-stlnr.
endmethod.
endclass.
ERROR:
"stlnr" is not available
if i use this way. its not giing error.
class c1 definition.
method get_material exporting t_mast type any table.
endmethod.
endclass.
class c1 implementation.
method get_material.
select f1 f2 f3 from <tab> into table t_mast
for all entries in it_stpo
where stlnr = it_stpo-stlnr.
endmethod.
endclass.
how to pass internal table with some specific reference may be using like or type <it_xxxx>
thanksTry this.
TYPES : BEGIN OF ty_stpo,
stlnr TYPE stpo-stlnr,
idnrk TYPE stpo-idnrk,
menge TYPE stpo-menge,
END OF ty_stpo,
BEGIN OF ty_mast,
matnr TYPE mast-matnr,
werks TYPE mast-werks,
stlnr TYPE mast-stlnr,
END OF ty_mast,
tt_stpo TYPE TABLE OF ty_stpo,
tt_mast TYPE TABLE OF ty_mast.
DATA : it_stpo TYPE tt_stpo,
it_mast TYPE tt_mast.
* CLASS c1 DEFINITION
CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS : get_bom_numbers EXPORTING ex_stpo type tt_stpo,
get_parent_material IMPORTING im_stpo TYPE tt_stpo
EXPORTING ex_mast TYPE tt_mast.
endclass.
* CLASS c1 IMPLEMENTATION
CLASS c1 IMPLEMENTATION.
METHOD get_bom_numbers.
ENDMETHOD. "get_bom_numbers
METHOD get_parent_material.
ENDMETHOD. "get_parent_material
START-OF-SELECTION.
DATA : obj TYPE REF TO c1.
CREATE OBJECT obj.
CALL METHOD obj->get_bom_numbers
IMPORTING
t_stpo = it_stpo.
CALL METHOD obj->get_parent_material
EXPORTING
im_stpo = it_stpo
IMPORTING
ex_mast = it_mast.
Regards,
Rich Heilman -
How to create an dynamic internal table with the structure of a ddic table
Hi all,
I want to fill ddic-tables (which I already created) in my abap dictionary with data out of CSV-files (which are located on the CRM-Server). The ddic tables have different amount of fields.
I started with creating a table which contains the name of the tables and the path to the matching CSV-file.
At the beginning I'm filling an internal table with part of this data (the name of the ddic-tables) - after that I am looping at this internal table.
LOOP AT lt_struc ASSIGNING <lfs_struc>.
LOOP AT lv_itab1 INTO lv_wa1 WHERE ztab_name = <lfs_struc>.
lv_feld = lv_wa1-zdat_name.
ENDLOOP.
CONCATENATE 'C:\-tmp\Exportierte Tabellen\' lv_feld INTO lv_pfad.
Do.
OPEN DATASET lv_pfad FOR INPUT IN TEXT MODE ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
READ DATASET lv_pfad INTO lv_rec.
IF sy-subrc NE 0.
EXIT.
ENDIF.
enddo.
REPLACE ALL OCCURRENCES OF '"' IN lv_rec WITH ''.
SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
INSERT into (<lfs_struc>) values lr_str_value.
CLOSE DATASET lv_pfad.
endloop.
This is not the whole code, but it's working until
SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
I want to split all the data of lv_rec into an internal table which has the structure of the current ddic-table, but I didn't find out how to do give the internal table the structure of the ddic-table. In the code I used an internal tyble type string but I should be the structure of the matching tabel.
If I try to create an internal table by using a fiel symbol, I am told, that the data types are not matching.
Has anyone an idea?Hi Mayari,
though you were successfull with
METHOD cl_alv_table_create=>create_dynamic_table
I must warn you not to use it. The reason is that the number of tables created is limited, the method uses GENERATE SUBROUTINE statement and this triggers an unwanted database commit.
If you know the DDIC structure, it is (starting with ECC6.0) much easier:
field-symbols:
<table> type standard table.
data:
lr_data type ref to data.
Create data lr_data type table of (<DDIC structure>).
assign lr_data->* to <table>.
The split code can be simplified gaining speed loosing complexity not loosing functionality.
field-symbols:<fs_s> type any.
field-symbols:<fs_t> type any.
SPLIT lv_rec AT ';' INTO table it_string.
loop at it_string assigning <fs_s>.
assign component sy-tabix of wa_string to <fs_t>.
if sy-subrc = 0.
<fs_t> = <fs_s>.
endif.
at last.
append <fs_itwa3> to <ft_itab3>.
endat.
endloop.
Though it may work as Keshav.T suggested, there is no need to do that way.
Regards,
Clemens
Maybe you are looking for
-
Apple USB adapter VS world travel adapter kit!
Firstly, i'm posting this here becausa i didn't find a better place. Well, I need a wall plug for recharging my ipod and since the price difference between these 2 products is only $10 I started to think which one is the best. I mean..obviusly the tr
-
Feature Request: Line Number on Syntax Error
Hi, When I execute a query in the query window and there is a syntax error, I don't get the line number of where the error is as I normally do in SQLPlus. Is this this something that can be added to the error message? thanks -Niels
-
Which iOS-version is the highest for each model (3GS, 4, 4S)?
Can I get iOS5 on iPhone 3GS? Can I get iOS6 on iPhone4?
-
My external drive and DVD/CD devices are missing from my sidebar
The other day, my external Time Machine drive and DVD disappeared from my Sidebar. Time Machine still sees the drive and writes to it routinely. DVDs and CDs can be written to but do not show when done. They can be ejected with the keyboard button bu
-
I would like to have the latest versions of Java Technologies available(Servlets,EJB,JSP,Web Servers - Weblogic,web sphere...). Anybody can help me.