‎2006 Oct 06 2:28 PM
Hi,
I wanna pass a parameters in a FORM but not like usual...
somthing like
PERFORM sub USING TABLE XXXX
BUT XXXX is a text parameters like concatenate 'itab_' table-name into XXXX.
Is it possible? I guess yes but how do it?
Can you please help me
THX
‎2006 Oct 06 2:58 PM
data: begin of itab occurs 0,
fld1 type c,
fld2 type c,
end of itab.
DATA : tmp type c.
field-symbols: <fs> type table.
itab-fld1 = 'A'.
itab-fld2 = 'B'.
append itab.
itab-fld1 = 'C'.
itab-fld2 = 'D'.
append itab.
CONCATENATE 'I_' itab-fld1 into tmp.
assign tmp TO <fs>.
perform passing_table tables <fs>.
This not working as tmp is not a table.
‎2006 Oct 06 2:32 PM
Assign a field symbol and pass the field symbol.
report zrich_0001.
data: begin of itab occurs 0,
fld1 type c,
fld2 type c,
end of itab.
field-symbols: <fs> type table.
start-of-selection.
itab-fld1 = 'A'.
itab-fld2 = 'B'.
append itab.
itab-fld1 = 'C'.
itab-fld2 = 'D'.
append itab.
<b> assign itab[] to <fs>.
perform passing_table tables <fs>.</b>
*&---------------------------------------------------------------------*
*& Form passing_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ITAB text
*----------------------------------------------------------------------*
form passing_table tables xitab.
loop at xitab.
write:/ xitab.
endloop.
endform.
Regards,
Rich Heilman
‎2006 Oct 06 2:36 PM
1. concatenating a string into the xxxx, the actual parameter- is not possible.
2. it will be an undefined object. ( unless you declare it before the call!).
3. you may work around this issue by using a field symbol.
4. declare a field symbol of type any.
5. you may assign it to a object ( xxxx) and dynamically initalize xxxx to the definition of the table.
hope it helps.
‎2006 Oct 06 2:42 PM
Ron,
You wouldn't need to pass the table as such, as long as your FORM can figure out the name of the internal table. Here's some code (slightly different context, but easily adapted) that shows how to refer dynamically to an itab.
parameters:
p_tabnam like dd02l-tabname.
Data references of anonymous type
data:
dr_tab type ref to data,
dr_row type ref to data.
Field symbols
field-symbols:
<row>,
<tab> type standard table.
Reference to data of type passed in the p_tabnam parameter
try.
create data:
dr_row type (p_tabnam).
catch CX_SY_CREATE_DATA_ERROR.
message e017(ZREP) with
'Cannot create row for' p_tabnam.
endtry.
try.
create data:
dr_tab type table of (p_tabnam).
catch CX_SY_CREATE_DATA_ERROR.
message e017(ZREP) with
'Cannot create table for' p_tabnam.
endtry.
Assign dereferenced data reference to field symbols.
assign:
dr_row->* to <row>,
dr_tab->* to <tab>.
Typical processing:
select * from (p_tabnam) into table <tab>.
loop at <tab> into <row>.
...
endloop.
And here's some more code that goes into more detail about how to do stuff with the itab.
field-symbols:
<row_code>,
<row_desc>.
...
concatenate:
'<ROW>-' p_code into row_code_name,
'<ROW>-' p_desc into row_desc_name.
assign:
(row_code_name) to <row_code>,
(row_desc_name) to <row_desc>.
select * from (p_tabn) into table <tab>.
loop at raw_itab into raw_row.
<code> = raw_row-field1.
<desc> = raw_row-field2.
read table <tab> into <row> with key (p_code) = <code>.
if sy-subrc ne 0.
clear <row>.
<row_code> = <code>. "assigns to <row> 'code' field
<row_desc> = <desc>. "assigns to <row> 'desc' field
insert (p_tabn) from <row>. "creates a database-table row
if sy-subrc eq 0.
write: / 'Inserted :', <row_code>, <row_desc>.
endif.
endif.
endloop.
Hope this helps,
John
‎2006 Oct 06 2:58 PM
data: begin of itab occurs 0,
fld1 type c,
fld2 type c,
end of itab.
DATA : tmp type c.
field-symbols: <fs> type table.
itab-fld1 = 'A'.
itab-fld2 = 'B'.
append itab.
itab-fld1 = 'C'.
itab-fld2 = 'D'.
append itab.
CONCATENATE 'I_' itab-fld1 into tmp.
assign tmp TO <fs>.
perform passing_table tables <fs>.
This not working as tmp is not a table.
‎2006 Oct 06 3:01 PM
‎2006 Oct 06 3:06 PM
Do mean something like this where you are passing a literal representation of the field that you want to access? In this case an internal table.
report zrich_0001.
data: begin of itab occurs 0,
fld1 type c,
fld2 type c,
end of itab.
field-symbols: <fs> type table,
<fs_wa>.
start-of-selection.
itab-fld1 = 'A'.
itab-fld2 = 'B'.
append itab.
itab-fld1 = 'C'.
itab-fld2 = 'D'.
append itab.
perform accessing_table using 'ITAB'.
*&---------------------------------------------------------------------*
*& Form accessing_table
*&---------------------------------------------------------------------*
form accessing_table using tablename.
data: xtablename(30) type c.
concatenate tablename '[]' into xtablename.
assign (xtablename) to <fs>.
loop at <fs> assigning <fs_wa>.
write:/ <fs_wa>.
endloop.
endform.
Regards,
Rich Heilman
‎2006 Oct 06 3:07 PM
I got a table with the name of other table.
seltab :
PA0000
PA0001
PA0002
And I want to use a internal table ( call ITAB_PA0000...)to extract data from those table.
PERFORM extract_table tables I_PA0000
using seltab-low.
FORM extract_table TABLES stru
USING tab.
SELECT * FROM (tab) INTO TABLE stru
for all entries in mat
WHERE pernr = mat-pernr.
ENDFORM. " extract_table
Or I guess I can use just a select in a loop but I will have the same problem (string VS table)
‎2006 Oct 06 3:21 PM
I guess I don't need PERFORM. I can do :
CONCATENATE 'I_' seltab-low into tmp.
SELECT * FROM (seltab-low) INTO TABLE tmp
for all entries in mat
WHERE pernr = mat-pernr.
but...
thkx for your help
‎2006 Oct 09 9:07 AM
Hi Rich this is realy helpfull but I got a run time error when I process the programme.
004520 data: xtablename(30) type c.
004530 concatenate mytab '[]' into xtablename.
004540
004550 assign (xtablename) to <fs>.
004560
> loop at <fs> assigning <fs_wa>.
004580 write:/ 'test'.
004590 endloop.
You attempted to access an unassigned field symbol
(data segment 127).
This error may occur for any of the following reasons:
- You address a typed field symbol before it is set using ASSIGN
- You address a field symbol that points to a line in an internal table
that has been deleted
- You address a field symbol that had previously been reset using
UNASSIGN, or that pointed to a local field that no longer exists
- You address a global function interface parameter, even
though the relevant function module is not active,
that is it is not in the list of active calls. You can get the list
of active calls from the this short dump.
Thank for you help