01-12-2006 8:35 AM
Dear all,
I have a transparent table.
Now I hardcode its structure like:
TYPES: BEGIN OF PSA_STRUCTURE ,
REQUEST(000030) TYPE C,
DATAPAKID(000006) TYPE N,
PARTNO TYPE INT4,
RECORD TYPE INT4,
...
END OF PSA_STRUCTURE .
It's very rigid.
How can I detrmine the table structure and use it in DATA: ...TYPE... and ...TYPE TABLE OF..., as well as in FIELD-SYMBOLS statements?
Best regards,
Eugene
01-12-2006 10:53 AM
01-12-2006 8:41 AM
Hi Eugene,
1 GET_COMPONENT_LIST
use the above FM
regards,
amit m.
01-12-2006 9:04 AM
Hi Amit,
Thank you for your reply.
But I cannot figure out how to use parameters.
One of importing parameters is
PROGRAM LIKE SY-REPID
In my system the SYST table has no such a field as REPID. What should it be?
And what about another FIELDNAME parameter?
As far as I understood the COMPONENTS table is a returned structure. Is it right?
Best regards,
Eugene
01-12-2006 9:08 AM
Hi again,
1. try this code (just copy paste)
it will help u for the syntax part.
REPORT abc.
*----
DATA : BEGIN OF itab OCCURS 0,
lifnr LIKE lfa1-lifnr,
land1 LIKE lfa1-land1,
name1 LIKE lfa1-name1,
name2 LIKE lfa1-name2,
END OF itab.
DATA : allfields(300) TYPE c.
DATA : fld(100) TYPE c.
DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.
*----
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'ITAB'
TABLES
components = components.
BREAK-POINT.
LOOP AT components.
CONCATENATE 'LFA1~' components-compname '' INTO fld.
CONCATENATE allfields fld INTO allfields SEPARATED BY space.
ENDLOOP.
*----
SELECT (allfields)
FROM lfa1
INTO TABLE itab.
*----
BREAK-POINT.
regards,
amit m.
01-12-2006 9:12 AM
HI,
repid will be in old versions and obsolete.
so u can use sy-cprog in place of sy-repid
and do what amit said.
regs
hyma
01-12-2006 9:20 AM
Amit,
LFA1 table doesn't exist in my BW (not all R/3 tables we can find here). What might be a replacement?
Best regards,
Eugene
01-12-2006 9:26 AM
Hi again,
1 lifnr LIKE lfa1-lifnr,
LFA1 = table
LIFNR = field of the above table.
2. Well, for ur BW system,
u can use
any table and its field name.
3. This was just a sample code
for getting how to use the FM
(its very simple)
regards,
amit m.
01-12-2006 10:15 AM
As I wrote before, the table name is determined during run time, I cannot hardcode it.
It's declared as
DATA: psa_tab_name TYPE text.
How to do it?
Best regards,
Eugene
01-12-2006 8:41 AM
Hi Eugene,
I guess you are new to ABAP. You can define workareas, tables, field-symbols by just using TYPE statement:
eg)
DATA:
it_psa TYPE STANDARD TABLE OF psa_structure,
wa_psa TYPE psa_structure.
FIELD-SYMBOLS:
<fs> TYPE psa_structure.
You can use TYPE for all predefined datatypes, dictionary types and also types defined in your program.
Regards,
Srikanth
01-12-2006 8:45 AM
Dear Eugene Khusainov,
Could please brief me more on your problem. I didn't get it.
Rg,
VM
01-12-2006 8:58 AM
Hi,
In SAP BW I have a table which is used for transfer data from a source system. The structure of the table depends on a list of fields to be transferred.
The table name couldn't be hardcoded, it depends on many factors. But I can determine the table name dynamically.
I need to determine the table structure in the report in order to work with particular fields.
Best regards,
Eugene
01-12-2006 9:03 AM
Dear,
Wait for few momemts i wll let you know the solution.
Wait i wll be right back.
Regards,
Vikas Madaan
01-12-2006 9:12 AM
Dear,
Use this function module to get the sturcture of table at runtime
DB02_GET_TABLE_STRUCTURE_DB2
Regards,
Vikas Madaan
Message was edited by: Vikas Madaan
Message was edited by: Vikas Madaan
01-12-2006 10:19 AM
Hi Vikas,
Your FM works for DB2.
It doesn't recognise my table (Oracle DB).
Best regards,
Eugene
01-12-2006 9:35 AM
As i understand: you have a field list. If so you can do following:
make field catalog something like that
=====================================
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
is_fieldcat-fieldname = 'FIELDNAME'
is_fieldcat-ref_field = 'FIELD NAME IN DDIC TABLE'.
is_fieldcat-ref_table = 'TABLE NAME IN DDIC'.
APPEND is_fieldcat TO it_fieldcat.
========================================
or if your fields based on elementary type look at lvc_t_fcat for required field
After creating field catalogue do following
=======================================
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY.
Create a new Table
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>.
=============================================
Now you have a line and a table based on your field list
01-12-2006 10:53 AM
01-12-2006 11:13 AM
Hi Eugene!
Can you get something out of dynamic creation of structures?
Have a look at some weblogs:
<a href="/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table">Dynamic internal table</a>
<a href="/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap">Dynamic Internal Tables and Structures - ABAP</a>
If you need a list of fields, in a R/3 system table DD03L would help you. Column position defines the field order and rollname ne space should exclude 'include'-lines. Hope that's same in BW.
Regards,
Christian
01-12-2006 11:41 AM
Hi Christian,
Thank you so much!
The last weblog should do the trick.
Unfortunately, there is a bug in the code. I'll post another question about it.
Best regards,
Eugene
01-14-2006 10:43 AM
you can use FM TR_NAMETAB_GET to get the table structure definition.
Regards
Raja
01-17-2006 1:36 PM
Hi Eugene,
Raja's reply has the solution. you can use the FM. It'll work fine.
Cheers,
Sam
01-17-2006 1:57 PM
Hi ,
May be this code can help here you can send the table name and get its components.
type-pools: abap.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
'xfc' is a type of field catalog structure.which is used to create a dynamic table .
Hope this helps.
Rgds,
Prashant
01-18-2006 4:07 AM