Dynamic internal table in SAP 3.1I version
hi All,
i am new to this form and have the following question.
Currently i am working in SAP 3.1I version and i am required to create a dynamic internal table.
Basically the table name will be entered by the user on the selection screen and the dynamic internal table has to be of this type (entered by user on the selection screen).
Please let me know whether this is possible in 3.1I version and if its possible then how to achieve this.
Note: this requirement has to be done in 3.1I version hence OO concept (ie)
cl_alv_table_create=>create_dynamic_table doesn't work here.
refer this demo code -
parameter p_table type tabname.
field-symbols <tab> type table.
field-symbols <tab1> type any.
types: begin of itab,
t_name type tabname,
t_ref type ref to data,
end of itab.
data itab1 type table of itab with non-unique key t_name.
perform fetch_data using p_table.
perform print_table using p_table.
*& Form fetch_data
text
-->P_P_TABLE text
FORM fetch_data USING P_TABLE1 type tabname.
data itab2 type itab.
itab2-t_name = p_table1.
create data itab2-t_ref type table of (itab2-t_name) .
assign itab2-t_ref->* to <tab>.
append itab2 to itab1.
select * from (p_table1) up to 25 rows into corresponding fields of table <tab>.
ENDFORM. " fetch_data
*& Form print_table
text
-->P_P_TABLE text
FORM print_table USING P_TABLE1 type tabname.
DATA t_ref1 TYPE REF TO data.
DATA itab2 TYPE itab.
FIELD-SYMBOLS <field> TYPE ANY.
READ TABLE itab1 INTO itab2 WITH KEY t_name = p_table1.
ASSIGN itab2-t_ref->* TO <tab>.
CREATE DATA t_ref1 LIKE LINE OF <tab>.
ASSIGN t_ref1->* TO <tab1>.
DO.
*READ TABLE <tab> ASSIGNING <tab1> INDEX 1.
READ TABLE <tab> ASSIGNING <tab1> INDEX SY-INDEX.
*WRITE:/ p_table1.
NEW-LINE.
IF sy-subrc <> 0.
EXIT.
ENDIF.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <tab1> TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE: <field>,' '.
ENDDO.
ENDDO.
ENDFORM. " print_table
Similar Messages
-
Function module to upload excel to internal table in SAP 7.0 version system
<<Question has been asked and answered many times - please search before asking for function modules for common tasks>>
currently i am using SAP Netweaver7.0 version, i need a Funtion Module to upload an Excel sheet data to an internal table.
please let me know this ASAP.
thanks,
Edited by: Matt on Aug 24, 2009 7:25 AMhi,
the FM you have suggested does not exist in the *version 7.0*
added the FM "ALSM_....",also does not exist
pls suggest a FM for SAP7.0 version -
Dynamic Internal Table creation in SAP version 4.5B
Hi All,
Can anybody please let me know if it is possible to create dynamic internal table in SAP version 4.5 B.
If yes will be of great help if somebody can give the method of doing it or any sample code to follow.
Thanks in advance!!!Hi
Refer this wiki [http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]
Regards
Raj -
How to use dynamic internal table when using gui_upload?
Hi Experts,
my scenario is like i have header data, item data and serial numbers.
so with respect to the quantity in unit of measure ,there will be number of serial numbers..
i have declared the dynamic internal table,but i am not getting the logic to change the structure accordingly with respect to the flat file entries..
is it possible to do or its not possible....any suggestion!!!!i have declared like this....
TYPES: BEGIN OF ty_final,
bldat TYPE string, "Document Date
budat TYPE string, "Psting Date
bktxt TYPE string, "Document Header Text
werks TYPE string, "Plant
lgort TYPE string, "Storage Location
matnr TYPE string, "Material Number
erfmg TYPE string, "Quantity in Unit Of Entry
anln1 TYPE string, "Asset Number
anln2 TYPE string, "Asset Subnumber
sernr TYPE string, "serial Number
END OF ty_final.
DATA : it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
FIELD-SYMBOLS : <fs_final> TYPE table.
ASSIGN it_final TO <fs_final>.
after this i called gui upload and passed internal table it_final..
but i have to change the internal table structure dynamically before the upload function.so that it will match with the flat file...
Regards
KarthickThere are at least two approaches you can use to change/generate new dynamic-structured table. Either with [RTTI + RTTS|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI] or using [CL_ALV_TABLE_CREATE|http://www.sdn.sap.com/irj/scn/advancedsearch?query=cl_alv_table_create] . In this one just determine fieldcatalog of current table and change it accordingly, then regenarate table.
There are plenty of examples in SCN for this. You should not face difficulties applying this.
Regards
Marcin -
How to create Dynamic Internal table in ALV?
Hi all,
I have to create a ALV report based on dynamic internal table. The requirement is that when I enter the months in my selection screen I should get the data relevant to those many months only. For eg if in selection I have given January to March, I should get an ALV output with columns from January to March only.
Please help me with the coding part as I find it a bit confusing.
Please reply immediately.
Regards,
Bhavani.Hi BHAVANI,
first you have to prapare a field catalog [(see this)|http://help.sap.com/saphelp_470/helpdata/en/52/5f060de02d11d2b47d006094192fe3/frameset.htm]
and than you can use a Method cl_alv_table_create=>create_dynamic_table
I hope that help a little.
Regards Bogdan -
Error while creating a dynamic internal table refers to custom field
Hi all,
I am getting the exception TYPE_NOT_FOUND when I try to create a dynamic internal table using:-
DATA: gr_desc TYPE REF TO cl_abap_typedescr.
gr_desc = cl_abap_typedescr=>describe_by_name( p_field ).
The field p_field is a Z-field inside a DB table, (e.g. a user added field in MARA). The statement fails at that point and gives a runtime exception. Any suggestions to how I may solve this problem? Or any alternatives for the same? I guess we face this issue for all custom fields..has SAP released a note for this??
Thanks..that's just the wrong method, you should use DESCRIBE_BY_DATA
gr_desc = cl_abap_typedescr=>describe_by_data( p_field ).
Note: DESCRIBE_BY_NAME is to be used for referencing a DDIC type by its name. Example:
gr_desc = cl_abap_typedescr=>describe_by_name( 'MARA-ZZFIELD' ). -
Dynamic Internal Table creation and population
Hi gurus !
my issue refers to the slide 10 provided in this slideshow : https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae
My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.
Letu2019s use only EKPO, and only field MENGE.
For this, I use Classes cl_abap_elemdescr, cl_sql_result_set and the Data Ref for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.
Here it comes:
DATA: element_ref TYPE REF TO cl_abap_elemdescr,
vl_fieldname TYPE string,
tl_components TYPE abap_component_tab,
sl_components LIKE LINE OF tl_components_alv,
linetype_lcl TYPE REF TO cl_abap_structdescr,
ty_table_type TYPE REF TO cl_abap_tabledescr,
g_resultset TYPE REF TO cl_sql_result_set
u2026
CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
* sg_columns-table_name contains 'EKPO'
* sg_columns-column_name contains 'MENGE'
* getting the element as a component
element_ref ?= cl_abap_elemdescr=>describe_by_name( vl_fieldname ).
sl_components-name = sg_columns-column_name.
sl_components-type ?= element_ref.
APPEND sl_components TO tl_components.
* dynamic creation of internal table
linetype_lcl = cl_abap_structdescr=>create( tl_components ).
ty_table_type = cl_abap_tabledescr=>create(
p_line_type = linetype_lcl ).
u2026
* Then I will create my field symbol table and line. Code has been cut here.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
u2026
* Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
g_resultset = g_stmt_ref->execute_query( stmt_str ).
* Then structure for the Resultset is set
CALL METHOD g_resultset->set_param_struct
EXPORTING
struct_ref = dy_line.
* Fetching the lines of the resultset => Dumpu2026
WHILE g_resultset->next( ) > 0.
ASSIGN dy_line->* TO <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
ENDWHILE.
Anyone has any clue to how prevent my Dump ??
The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that !Hello
I have expanded your sample coding for selecting three fields out of EKPO:
*& Report ZUS_SDN_SQL_RESULT_SET
*& Thread: Dynamic Internal Table creation and population
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1375510"></a>
*& NOTE: Coding for dynamic structure / itab creation taken from:
*& Creating Flat and Complex Internal Tables Dynamically using RTTI
*& https://wiki.sdn.sap.com/wiki/display/Snippets/Creating+Flat+and+
*& Complex+Internal+Tables+Dynamically+using+RTTI
REPORT zus_sdn_sql_result_set.
TYPE-POOLS: abap.
DATA:
go_sql_stmt TYPE REF TO cl_sql_statement,
go_resultset TYPE REF TO cl_sql_result_set,
gd_sql_clause TYPE string.
DATA:
gd_tabfield TYPE string,
go_table TYPE REF TO cl_salv_table,
go_sdescr_new TYPE REF TO cl_abap_structdescr,
go_tdescr TYPE REF TO cl_abap_tabledescr,
gdo_handle TYPE REF TO data,
gdo_record TYPE REF TO data,
gs_comp TYPE abap_componentdescr,
gt_components TYPE abap_component_tab.
FIELD-SYMBOLS:
<gs_record> TYPE ANY,
<gt_itab> TYPE STANDARD TABLE.
START-OF-SELECTION.
continued. -
To populate data in a dynamic internal table
Hi,
I have an internal table <FS_1> which I have created dynamically. Now i need to populate the columns (7th column onwards) in the internal table with my data in GT_REQMT which is an internal table.
Data: L_IDX type I.
L_IDX = 6.
Loop at <FS_1> assigning <FS_2>.
If sy-tabix = 1.
Loop at GT_REQMT.
Add 1 to L_IDX.
*****I need to populate GT_REQMT-DATA to column 7 then 8 etc depending on the number of loops.
Modify <FS_1> from <FS_2>.
Endloop.
Else.
**do other things here**
Endif.
Endloop.
I have search through the forums and weblogs but the solutions are catered to populating the internal tables from SAP database using SQL statements.
I couldn't find anything on populating own data in dynamic table by looping it. Please help. THANKS!!
Cheers,
ChelseaHi!
I have used classes for dynamic internal table, SO i here give you my sample code for your help.
DATA : new_table TYPE REF TO data,
new_line TYPE REF TO data.
FIELD-SYMBOLS : <TAB1> type standard table,
<l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
count = count + 1.
clear wa_fieldcat.
wa_fieldcat-col_pos = count.
wa_fieldcat-fieldname = 'CONDITION'.
wa_fieldcat-coltext = 'Condition Value'.
wa_fieldcat-ref_field = 'KWERT'.
wa_fieldcat-ref_table = 'KONV'.
wa_fieldcat-outputlen = 13.
append wa_fieldcat to it_fieldcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
ASSIGN COMPONENT KWERT OF STRUCTURE <l_line> TO <l_field>.
<l_field> = t_kschlkonv-vtext.
NOw u append internal table
IF its helps you then dont forget to rewards points.
Regards From
Priyank -
Populate data in dynamic internal table
Hi ppl,
I have a requirement where I need to display certain fields in the report output.
The output contains 8 fixed fields (common for all rows in output) and some dynamic fields (number of column varies with rows) which will be determined at runtime.
I am able to create the dunamic internal table....and at runtime I see the fields created in the internal table correctly.
Now my requirement is to fill this table with the data from 2 internal tables.
The values for the 8 common fields comes from the internal table t_output and the values for dynamic fields come from t_dynamic.
Please let me know the logic to merge these 2 internal tables into the dynamic internal table <dyn_table>.
Regards.Hello David,
This has been discussed many times before in this forum. Since the table structure is dynamic the fields are determined at runtime.
To assign data to this table you have to use [ASSIGN COMPONENT ... |http://help.sap.com/abapdocu_70/en/ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ.htm#!ABAP_ALTERNATIVE_4@4@] variant.
Please refer to the example provided in the documentation for details.
BR,
Suhas -
Dynamic internal table column issue
Hi
i have ALV report with dynamic internal table.after i build the internal table and fieldcatalog i have problem i.e. when grid is displayed then one of the column value is coming in the next column.i populated col_pos in field catalog also and in the debug mode data is populated correctly for respective columns in fieldcatalog and dynamic internal table. But when it is displayed i have this problem.
any inputs on this?Hi Moorthy,
Did you perform an ALV consistency check?
Check the below given links as well.
The Consistency Check - ALV Grid Control (BC-SRV-ALV) - SAP Library
SAP ALV Consistency Check
Regards,
Philip. -
Problem with grid display in ALV for dynamic internal tables
Hi,
I am using dynamic internal tables in my program. To display it in grid format after populating it, I have used the following class and method. Here Im getting sy-subrc = 0 but, the grid is not getting displayed. Can some one pls help me with this.,
DATA: W_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: w_tabname TYPE w_tabname.
CREATE OBJECT W_GRID
EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.
CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME = W_TABNAME
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = <FS_1>
IT_FIELDCATALOG = LT_FIELDCATALOG2
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Here, <FS_1> is the field symbol of table type and it holds all my data. and LT_FIELDCATALOG2 is the structure of my fieldcatalog
Thanks and Regards,
AvinashHi Avinash,
Either use parameter
I_STRUCTURE_NAME = W_TABNAME
or
IT_FIELDCATALOG = LT_FIELDCATALOG2
Both are not required.
At the end of ur program simply use a write statement like below. Your program will work.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write /. <----
Thanks,
Edited by: Sap Fan on Oct 6, 2009 7:17 AM -
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 -
Dynamic internal table with repeated structure
Hi,
I have a requirement, in which I need to create a dynamic internal table with the below structure.
Dynamic Int. table structure: fld1 and fld2.
If another internal table (say int2), contains 3 records, then my final output table should contain the below structure.
Value 1 Value 2 Value3
fld1 fld2 fld1 fld2 fld1 fld2
If in case, the int2 table contains 10 records, then my final output table should contain the structure below.
Value 1 Value 2 ..... Value10
fld1 fld2 fld1 fld2 ..... fld1 fld2
Please advice on how to acquire this. Thanks in advance for your help.
Regards,
Swetha.You can do it...but it won't be table... it would be some thing like
itab
ref1-> strycture (field 1 field 2 field 3)
ref2-> structure (field1 field 4 )
ref3-> structure (field5 field7 )
say Define a internal table with a single field to hold a reference of Data
Go on creating Rows of different structures and storing the address into the table... you can use RTTS for same
Use the below link for RTTS (search on wiki for examples).
http://wiki.sdn.sap.com/wiki/display/ABAP/RuntimeTypeServices+%28RTTS%29 -
Passing dynamic internal table to FM using RFC
Dear All,
Is it possible to pass a dynamic internal table to a function module using RFC?
If it is possible than how do i achive this?Basically not, RFC enabled FM parameters must be defined by a LIKE or TYPE clause. so you may try to use a prededined SAP type wide enough (e.g. TAB512 ) and map the data in the FM and caller program (in Unicode try to use tools like class CL_ABAP_CONTAINER_UTILITIES to map data between actual internal table record and RFC used itab "container" type)
For examples look at RFC enabled RFC_GET_TABLE_ENTRIES FM, and look for where-used program.
Regards,
Raymond -
ALV display using dynamic field catalog and dynamic internal table
hi ,
please guide me for ALV display using dynamic field catalog and dynamic internal table.
Thank you.Hi Rahul,
maybe thread dynamic program for alv is helpful for you. More information about the [SAP List Viewer (ALV)|http://help.sap.com/saphelp_nw70/helpdata/EN/5e/88d440e14f8431e10000000a1550b0/frameset.htm]. Also have a look into the example programs SALV_DEMO_TABLE*.
Regards Rudi
Maybe you are looking for
-
IPhone 3G won't charge from USB port
Suddenly I am getting an error sound (no message though) on my computer when I plug my iPhone into its USB port and it no longer charges the battery. I don't have iTunes on this computer (not allowed/work computer) but I have been using the USB conne
-
How to email reports via SMTP server FORMS AND REPORTS 6i and databse 8i
Dear All, through reports builder reports are build but i need to email reports via SMTP server is it possible in 6i are not?if yes the how please rep asap
-
NW 7.0 Ehp2 - Trial version
Hi Are there any plans to release NW 7.0 Ehp2 ABAP Trial Version? i am eagerly waiting for that. from 12 July, 2010, it will be available within the SAP Business Suite 7 Innovation 2010 Ramp-Up. SAP Enhancement Package 2 for SAP NetWeaver 7.0 Thanks
-
Hello, I am exporting a movie from Final Cut Express using Quicktime Conversion. Everything is fine when I play the movie off of the the desktop. However, whenever I transfer the file (either burning to dvd or with an external hard drive) the file so
-
When I put my card into the reader, nothing happens. It doesn't show up in finder so I can't dismount it. The pictures on it aren't readeable all of a sudden, except for two of them, and that's all that would download to iphoto, but I had to connect