Ref_descr ?= cl_abap_typedescr= describe_by_name explanation
Hello Everyone,
Can somebody explain what is happening
in this part of the code. Below the complete code.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
One more request, what are these structures
abap_compdescr_tab, abap_compdescr, cl_abap_structdescr, lvc_s_fcat are these tables? Please kindly let me know
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
if wa_details-name = 'TIMESTMP'.
wa_it_fldcat-fieldname = wa_details-name.
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = r.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat.
append wa_it_fldcat-fieldname to it1.
else.
wa_it_fldcat-fieldname = wa_details-name.
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat.
append wa_it_fldcat-fieldname to it1.
endif.
endloop.
Thanks
Krishna
Hello Krishna
The static method cl_abap_typedescr=>describe_by_name returns an instance of type CL_ABAP_TYPEDESCR.
This class is a superclass of CL_ABAP_STRUCTDESCR (the inheritance hierarchy is:
CL_ABAP_TYPEDESCR -> CL_ABAP_DATADESCR -> CL_ABAP_COMPLEXDESCR -> CL_ABAP_STRUCTDESCR).
In the statement
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
we have a widening cast ('?=') from CL_ABAP_TYPEDESCR (returned value) to CL_ABAP_STRUCTDESCR (descr_ref variable).
Now <i>p_table</i> represents a structure (like 'SFLIGHT'). The components of this structure, i.e. the table fields, are found in the public attribute ref_descr->components.
Please note that it is unnecessary to write
ref_descr->components<b>[]</b>
because in ABAP-OO it is not allowed to use itabs with header lines but exclusively table types.
The other classes (like cl_abap_typedescr, cl_abap_compdescr) are used to get the runtime type information (RTTI) of different DDIC objects.
Regards
Uwe
Similar Messages
-
Hi,
I am using cl_abap_typedescr=>describe_by_name to get the length and field names of a table. But it is returning incorrect values for length. For example, all character fields and numc fields contain double the correct length
REPORT ZCA_BOB_CL_ABAP_STRUCTDESCR.
PARAMETERS P_TABNAM type TABNAME OBLIGATORY.
Data: wa_spfli type spfli,
r_descr type REF TO cl_abap_structdescr,
wa_comp TYPE abap_compdescr.
** Create references to the needed ALV Global Classes
data: lr_events type ref to cl_salv_events_table.
data: gr_table type ref to cl_salv_table.
Data: r_grid TYPE REF TO cl_salv_table.
data: r_title_text TYPE REF TO cl_alv_variant,
r_grid_title TYPE LVC_TITLE.
Data: abap_compdescr_tab TYPE STANDARD TABLE OF abap_compdescr
WITH KEY name.
START-OF-SELECTION.
** ?= means cast
** r_descr ?= cl_abap_typedescr=>describe_by_data( wa_spfli ).
r_descr ?= cl_abap_typedescr=>describe_by_name( P_TABNAM ).
Loop at r_descr->components into wa_comp.
* write:/ wa_comp-name, wa_comp-type_kind, wa_comp-length,
* wa_comp-decimals.
append wa_comp to abap_compdescr_tab.
EndLoop.Hello Bob
Below is the output of your report run on a 4.6c system:
Structure WA_SPFLI:
MANDT C 3 0
CARRID C 3 0
CONNID N 4 0
COUNTRYFR C 3 0
CITYFROM C 20 0
AIRPFROM C 3 0
COUNTRYTO C 3 0
CITYTO C 20 0
AIRPTO C 3 0
FLTIME I 4 0
DEPTIME T 6 0
ARRTIME T 6 0
DISTANCE P 5 4
DISTID C 3 0
FLTYPE C 1 0
PERIOD b 1 0
4.6c = non-Unicode
Your system = Unicode
Thus, the length is apprently the length in bytes.
Simply check and RFC destination (SM59) using button "Unicode Test". You will get the following message on an Unicode system:
Target is a unicode system (character size 2)
Regards
Uwe -
Dears :
i use cl_abap_typedescr=>describe_by_name( tabname ) to create a new structure type. The parameter tabname could be 'MARA' .
and now i want to append a new field such as 'ZTEST' to this structure, is this possible ?
ths in advance!Hi,
This is possible, Use get_components method to get the list of components
Then once yout get this list add one more component to this list.
Then use this list to create your strucutre using the method create.
See the below code.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table.
DATA: ls_comp LIKE LINE OF lt_comp.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
lt_comp = lr_rtti_struc->get_components( ).
LOOP AT it_elements INTO wa_element.
ls_comp-name = wa_element.
ls_comp-type = cl_abap_elemdescr=>get_string( ).
APPEND ls_comp TO lt_comp.
ENDLOOP.
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = lt_comp
p_strict = abap_false
RECEIVING
p_result = lr_rtti_struc.
Regards,
Sesh
Message was edited by:
Seshatalpasai Madala -
Cl_abap_typedescr= describe_by_name and field length
Hello,
When I run the method cl_abap_typedescr=>describe_by_name('MARA') on ECC6, the method works properly but the type definition for the field is wrong.
For example the method returns <b>mara-mandt type c length 6 instead of 3</b>. <i></i>
Is this normal ?Hello Sudha,
I don't see any output_lenght parameter, here is my code
table ?=
cl_abap_typedescr=>describe_by_name( p_table ).
tableDetails[] = ref_table_des->components[].
p_table is a selection parameter.
Do you see anything wrong ? -
Dynamic types with CL_ABAP_TYPEDESCR
Hi,
I have a problem. I want to read out the output_length of dynamic types to evaluate inputs. I do something like the code below.
DATA type_ref TYPE REF TO cl_abap_typedescr.
DATA elem_descr TYPE REF TO cl_abap_elemdescr.
DATA struc_descr TYPE REF TO cl_abap_structdescr.
type_ref = cl_abap_typedescr=>describe_by_data( <fs_lsinto> ).
elem_descr ?= type_ref.
elem_descr->output_length
But sometimes type_ref give back a CL_ABAP_STRUCTDESCR and I get a dump at '?='.
How I can solve my Problem?
SinanHow about something like this.
report zrich_0001.
data type_ref type ref to cl_abap_typedescr.
data elem_descr type ref to cl_abap_elemdescr.
data struc_descr type ref to cl_abap_structdescr.
data comp_tab type abap_compdescr_tab.
data comp_wa like line of comp_tab.
parameters: p_name(30) type c.
type_ref = cl_abap_typedescr=>describe_by_name( p_name ).
if type_ref->type_kind = 'u'. " <- Structure
struc_descr ?= type_ref.
loop at struc_descr->components into comp_wa.
catch system-exceptions move_cast_error = 1.
data: tab_component type string.
concatenate p_name comp_wa-name into comp_wa-name separated by '-'.
elem_descr ?= cl_abap_typedescr=>describe_by_name( comp_wa-name ).
endcatch.
write:/ comp_wa-name, comp_wa-length, elem_descr->output_length.
endloop.
else.
elem_descr ?= type_ref.
write:/ p_name, elem_descr->output_length.
endif.
Regards,
Rich Heilman -
Using CL_ABAP_TYPEDESCR for local itabs?
Can I get the component table of a locally defined internal table using cl_abap runtime class/methods?
Of course...
This is from class documentation available for class CL_ABAP_TABLEDESCR
REPORT typedescr_test.
TYPES:
my_table TYPE HASHED TABLE OF i WITH UNIQUE KEY TABLE LINE.
DATA:
descr_ref TYPE ref to cl_abap_tabledescr.
FIELD-SYMBOLS:
<key_comp_wa> TYPE abap_keydescr.
START-OF-SELECTION.
descr_ref ?= cl_abap_typedescr=>describe_by_name( 'MY_TABLE' ).
WRITE: / 'Typename :', descr_ref->absolute_name.
WRITE: / 'Kind :', descr_ref->type_kind.
WRITE: / 'Length :', descr_ref->length.
WRITE: / 'Decimals :', descr_ref->decimals.
WRITE: / 'Table Kind :', descr_ref->table_kind.
WRITE: / 'Initial Size :', descr_ref->initial_size.
WRITE: / 'Key Def Kind :', descr_ref->key_defkind.
WRITE: / 'Has Unique Key:', descr_ref->has_unique_key.
WRITE: / 'Key Components:'.
LOOP AT descr_ref->key ASSIGNING <key_comp_wa>.
WRITE <key_comp_wa>-name.
ENDLOOP.
Regards,
Abhijit -
Problem creating an internal table dynamically
Hi,
I'm trying to create an internal table dynamically as i would be able to determine the structure of the table based on the user input.
I've used the sample code from this forum ...
REPORT ZRICH_0003 .
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text.
parameters: p_table(30) type c.
selection-screen end of block b1.
Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
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>.
<b>* Select Data from table.
select * into table <dyn_table> from
(p_table).</b>
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
I'm able to get the structure of the table that i want, but when i'm trying to select data from the table into this internal table..as highlighted in the sample code above..i'm getting a short dump...saying that ' the database table is 600 bytes wide but the internal table is only 576 bytes wide.
The internal table is declared as
field-symbols: <dyn_table> type standard table..
Could anyone please tell me how to rectify this.
Thanks in advance,
Harsha.Hi Smitha,
I'm building the internal table by getting the structure using the method
cl_abap_typedescr=>describe_by_name( p_table ).
where p_table is the table name determined dynamically..
Now using this structure, i'm building an internal table by calling the method
call method cl_alv_table_create=>create_dynamic_table
I've checked all the fields after the internal table has been created .. and it contains all the fields of the table that i'm supplying initially..
But when i read data into that internal table, it gives me that dump..I've described it in this post earlier.
Any more suggestions would be very helpful.
Thanks,
Harsha -
I have created a dynamic program which would read any table name as input parameter and print the contents. Its working if I use a small table(3 fields) and the same program is throwing short dump if pass a big table.
Shortdump
"SAPSQL_SELECT_TAB_TOO_SMALL" C
"ZBW_DYNAMIC_ITAB1" or "ZBW_DYNAMIC_ITAB1"
"START-OF-SELECTION"
Error in the line below
61
62 * Select Data from table.
>>>>> select * into table <dyn_table>
64 from (p_table).
65
Program
*& Report ZBW_DYNAMIC_ITAB1
REPORT ZBW_DYNAMIC_ITAB1.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
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>.
Select Data from table.
select * from (p_table) into table <dyn_table>
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.Hi,
The dynamic table that is generated is not converting the exact output length in case of packed numbers.
Foe eg : If there is an packed field of length 7 , the dynamic table is converting it to Char 7 , but the actual output length of Pack 7 is 15.Hence it is giving short dump saying that Internal Table length is not sufficient.
Probably it might have worked for smaller tables for you because you might not have used Packed field in there.
Regards,
Vijay. -
Dynamic field modification in Work Area.
Hi,
I want to insert 1 record in a transparent table. (But for time being, let us assume the table is MARA)
The columns and table name to which data is to be inserted are stored in another transparent table say (z1354_inv_rec_dt).
The data to be inserted is specified in a text file.
The value for MATNR, let us assume is hard coded as 1252.
The value for fields ERSDA, ERNAM, LAEDA and AENAM will be specified in input text file.
Also the table z1354_inv_rec_dt, will have rows with values ERSDA, ERNAM, LAEDA and AENAM.
How do I do this, the code specified in form comparedata is not correct one, but just a starting point for code.
<b>So how do I specify the column of work area at run time and assign value to it.</b>
Then I have to append value from work area to internal table.
And from internal table, I will insert to database.
REPORT ZDYN_INS_MARA.
TYPE-POOLS : abap.
DATA:
lit_z1354_inv_rec_dt TYPE TABLE OF z1354_inv_rec_dt,
* table z1354_inv_rec_dt contains 2 columns column_name and table_name
* values for column_name are ERSDA, ERNAM, LAEDA and AENAM
* value for table_name is MARA.
lwa_invoice LIKE z1354_inv_rec_dt,
lit_mara TYPE TABLE OF mara,
lwa_mara LIKE mara.
* To get column names
DATA :
it_details TYPE abap_compdescr_tab,
wa_details TYPE abap_compdescr,
ref_descr TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS : <fs_mara> TYPE mara.
FIELD-SYMBOLS : <fs_wa_mara> LIKE LINE OF lit_mara.
FIELD-SYMBOLS : <dyn_field>.
DATA: int_tabname(30).
int_tabname = 'MARA'.
*Populate internal table with columns to be added to Database
PERFORM populaterecdt.
ref_descr ?= cl_abap_typedescr=>describe_by_name( int_tabname ).
*Get the column names from the Database tables
it_details[] = ref_descr->components[].
PERFORM comparedata.
*& Form PopulateRecDt
FORM populaterecdt .
SELECT column_name table_name FROM z1354_inv_rec_dt
INTO CORRESPONDING FIELDS OF TABLE lit_z1354_inv_rec_dt
WHERE table_name = 'MARA' .
ENDFORM. " PopulateRecDt
*& Form CompareData
FORM comparedata .
*loop through the DB table which holds the column names to be added
LOOP AT lit_z1354_inv_rec_dt INTO lwa_invoice.
*Loop throught table which holds the column names
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_wa_mara> TO <dyn_field>.
<dyn_field> = '1252' .
LOOP AT it_details INTO wa_details.
IF wa_details-name = lwa_invoice-column_name.
* Assign value to column of work area from text file.
ASSIGN component lwa_invoice-column_name of structure <fs_wa_mara> to <dyn_field>.
*Get value for <dyn_field> from text file
<dyn_field> = 'XYZ212'.
ENDIF.
ENDLOOP.
ENDLOOP.
*append work area t to lit_mara.
*Append work area to internal table.
*insert the internal table to DB
ENDFORM. " CompareData
Here in this loop, I want to assign to the work area for Mara based on the column values, How do I do it.
Regards,
VikasHi,
This problem has been resolved.
DATA:
lit_MARA TYPE TABLE OF MARA,
lit2_MARA TYPE TABLE OF MARA,
lwa_MARA LIKE MARA,
lit_inv TYPE TABLE OF z1354_inv_rec_dt,
wa_inv LIKE z1354_inv_rec_dt,
sctemp(100) TYPE c,
ifs type i,
p_gs_s_rec_line TYPE string.
FIELD-SYMBOLS:
<fs_MARA> TYPE table,
<ld_column> TYPE ANY,
<fs_wa_MARA> LIKE LINE OF lit_MARA.
*Populate Invoice table
SELECT * FROM z1354_inv_rec_dt INTO CORRESPONDING FIELDS OF TABLE
lit_inv WHERE recordtype = 'S' AND table_name = 'MARA' AND
column_seq > 0.
p_gs_rec_line = '1234567890000001'.
lwa_MARA-laufi = '123e'.
FREE lit_MARA.
APPEND lwa_MARA TO lit_MARA.
ASSIGN lit_MARA[] TO <fs_MARA>.
UNASSIGN: <fs_wa_MARA>.
* free lit_MARA[] .
* LOOP AT <fs> ASSIGNING <fs1>.
LOOP AT lit_MARA ASSIGNING <fs_wa_MARA>.
ifs = sy-tabix.
write: / ifs.
LOOP AT lit_inv INTO wa_inv.
WRITE
p_gs_s_rec_line+wa_inv-start_pos_extrac(wa_inv-chars_to_extract)
TO sctemp.
UNASSIGN: <ld_column>.
ASSIGN COMPONENT wa_inv-column_name OF STRUCTURE <fs_wa_MARA>
TO <ld_column>.
<ld_column> = sctemp.
IF ( <ld_column> IS ASSIGNED ).
WRITE: / '.' .
ENDIF.
CLEAR wa_inv.
ENDLOOP.
MOVE <fs_wa_MARA> TO lwa_MARA.
APPEND lwa_MARA TO lit2_MARA.
CLEAR <fs_wa_MARA>.
ENDLOOP.
loop at lit2_MARA into lwa_MARA.
write: / lwa_MARA-filename.
clear lwa_MARA.
endloop.
insert MARA from table lit2_MARA.
if sy-subrc <> 0.
write: / ' Insert :-( '.
endif. -
Hi,
I need to develop a module that takes an infotype as input, does 'select * from <infotype table>' and writes data to a file. This module needs to be generic and should work for any infotype (even custom infotype).
For example, if input is PA0001, it should do 'Select * from PA0001'.
Any suggestions on how to do this?. Do i need to use field symbols?. Please let me know if you have any ideas.
Thanks,
SandeepREPORT Z_TEST.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data, new_line type ref to data, wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
data: test type pa0008 occurs 0.
select * from pa0008 into table test where endda = '99991231'.
Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
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>.
Select Data from table.
select * into corresponding fields of table <dyn_table> from
(p_table).
*select * from
*(p_table) into corresponding fields of table <dyn_table> up to 5 rows where endda = '99991231'.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0. exit. endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write:
<dyn_field>.
endif.
enddo.
endloop. -
Short Dump for Dynamic Select Query
Hello all,
I get a short dump for my dynamic select query at the end of the code. The error is "The types of operands "dbtab" and "itab" cannot be converted into one another."
My code looks like below.
FORM get_ccnum_2 USING p_tabname TYPE dd03l-tabname.
DATA: p_table(30) TYPE c.
FIELD-SYMBOLS: <dyn_wa>,
<t> TYPE table.
DATA: it_fldcat TYPE lvc_t_fcat.
TYPE-POOLS : abap.
DATA: it_details TYPE abap_compdescr_tab,
wa_details TYPE abap_compdescr.
DATA: ref_descr TYPE REF TO cl_abap_structdescr.
DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data,
wa_it_fldcat TYPE lvc_s_fcat.
p_table = p_tabname.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
LOOP AT it_details INTO wa_details.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
APPEND wa_it_fldcat TO it_fldcat .
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <t>.
CREATE DATA new_line LIKE LINE OF <t>.
ASSIGN new_line->* TO <dyn_wa>.
wa_cond = 'CCNUM <> '' '' '.
APPEND wa_cond TO tab_cond.
SELECT * INTO TABLE <t>
FROM (p_table)
WHERE (tab_cond)
ORDER BY (tab_ord).
ENDFORM. " GET_CCNUM_2Hi,
I tried to execute the code using table BSEGC and it gave a short dump..
the actual exception that shows in ST22 IS ..UNICODE_TYPES_NOT_CONVERTIBLE..
I think there is something wrong in the internal table creation..
Instead of using the method cl_alv_table_create=>create_dynamic_table to create the dynamic table I used the following and it worked..
CREATE DATA new_table TYPE TABLE OF (p_table).
* Comment begin " Naren
* ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
* it_details[] = ref_descr->components[].
* LOOP AT it_details INTO wa_details.
* CLEAR wa_it_fldcat.
* wa_it_fldcat-fieldname = wa_details-name .
* wa_it_fldcat-datatype = wa_details-type_kind.
* wa_it_fldcat-intlen = wa_details-length.
* wa_it_fldcat-decimals = wa_details-decimals.
* APPEND wa_it_fldcat TO it_fldcat .
* ENDLOOP.
* CALL METHOD cl_alv_table_create=>create_dynamic_table
* EXPORTING
* it_fieldcatalog = it_fldcat
* IMPORTING
* ep_table = new_table.
* Comment End. " Naren
CREATE DATA new_table TYPE TABLE OF (p_table). " New code by naren
Please Try this..
Thanks
Naren -
Cl_alv_table_create= create_dynamic_table error
Hi Gurus,
Method cl_alv_table_create=>create_dynamic_table
is giving dump.When i am trying to create internal table from fieldcatalog values.Program" "not found.
Please suggest some solution.
Good answers will be rewarded with points.
Thanks,
TwinkleCheck this program as reference .
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
* 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>.
* Select Data from table.
select * into corresponding fields of table <dyn_table>
from (p_table).
* Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Regards,
Rich Heilman -
How to dynamicaly (with variable) create itab - using field symbols?
Hi,
I need to create internal table using variable - field symbols. I think like this, but...
data: begin of itab occurs 0.
include structure <b>s_itab</b>.
end of itab.
s_itab is variable with structure of dbtab.
I need to include variable structure table.
i. e.
My itab then changes structure according variable s_itab.
First can be s_itab like table of bseg, second can be s_itab like table of hrp1001. And then I get desired itab.
Thanks for any ideas. zd.Here is a sample program which should show you everything that you need to know about dynamic internal tables.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
* 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>.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
* Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Regards,
Rich Heilman -
How to Read data base table at runtime
Hi,
i have an internal table with two fields they are
tablename and field name.
itab has some entries.
like :
itab-table name itab-fieldname
kna1 kunnr
mara matnr
vbuk vbeln
tvak auart
i want to read these tables with field names.
like :
loop at itab
select singe * from <itab-tablename> into <jtab>
where <itab-fieldname > = <dyanmic value from prog>.
endloop.
Is it possible to read the db table in the above scenario.
Please try to give me the solution.
Thanks,
srikHi, try this example program.
report zrich_0002 .
data: begin of itab occurs 0,
tabname(20) type c,
fldname(20) type c,
end of itab.
data: ref_descr type ref to cl_abap_structdescr.
data: where_clause(100) type c occurs 0 with header line.
data: it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data: new_table type ref to data,
new_line type ref to data,
it_fldcat type lvc_t_fcat,
wa_it_fldcat type lvc_s_fcat.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
start-of-selection.
itab-tabname = 'T000'.
itab-fldname = 'MANDT'.
append itab.
itab-tabname = 'T001'.
itab-fldname = 'BUKRS'.
append itab.
loop at itab.
* Get the structure of the table.
refresh it_fldcat.
refresh where_clause.
ref_descr ?= cl_abap_typedescr=>describe_by_name( itab-tabname ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
if <dyn_table> is assigned.
refresh <dyn_table>.
unassign <dyn_table>.
endif.
* 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>.
concatenate itab-fldname '<> ''' '''' into where_clause
separated by space.
append where_clause.
select * from (itab-tabname) into table <dyn_table>
where (where_clause).
endloop.
Regards,
Rich Heilman -
Dynamic selection need from a table
Hi,
I have a requirement to select the data from a table dynamically. Only during run time I will know the structure of that table & table name. In this case can anyone give any tips/sample code how it can be accomplished. Help appreciated.
Thanks,
AbhiSure, check out this sample program. It is a dynamic table read.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
* 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>.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
* Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Welcome to SDN. Please remember to award points for helpful answers and mark you post as solved when solved completely. Thanks.
Regards,
Rich Heilman
Fixed Code
Message was edited by: Rich Heilman
Maybe you are looking for
-
URGENT: sap ABAP/4's role in MM
hi every body , i want to know the ABAP/4's involvement wth MM module in real time?& wht type of responsibilities r there by ABAP peoples wth MM? i need clear solutions wth examples asap. points will be rewarded soon....................
-
How do I change my Pages window and document back to standard size? document?
My document format has changed and become very narrow. When I compare it to another Pages document, everything is smaller and the window itself is more narrow with a very large left margin. It looks like a professional textbook document. I printed
-
I nornally use Photoshop CS3 but I have just download the TRY version of PSE8 and would like to open jpg files via Camera Raw, how can I set up the Preferences to be able to do this, is it possible or can I only open raw files via Camera Raw.
-
How to download less than everything?
I have an old ipod with only 2GB which I want to download a small selection of our itunes library onto for my son. When we connect it, the device tries to download the whole library. How can we just download what we want?
-
I changed my apple id on my 4S now i cant download anything
I changed my apple id on my 4S now i cant download anything