2006 Jul 06 11:25 PM
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,
Sandeep
Does it has anything to do with configuration issue?
2006 Jul 06 11:30 PM
You can use the FM
call function 'HR_READ_INFOTYPE'
just pass the IT from selection screen and thats sit.
It should work ...
<b>
FYI</b>
call function 'HR_READ_INFOTYPE'
exporting
TCLAS = 'A'
pernr = peras-pernr
infty = '0001' ( From selection screen )
begda = int_absence-date
endda = int_absence-date
BYPASS_BUFFER = ' '
IMPORTING
SUBRC =
tables
infty_tab = <b>int_0001</b> ( You need to make this table dynamically )
exceptions
infty_not_found = 1
others = 2
Hope thisll give you idea!!
<b>Pl... award the points.</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise"<b></b>
2006 Jul 07 1:34 AM
Please see the example program. It accepts a table name and creates a dynamic internal table. I think you can use this to solve your issue. Yes, you will need to use field symbols and a dynamic internal table.
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
2006 Jul 10 4:49 PM
Rich,
The code that you suggested works for most of the infotypes and its great. But, it does fail for some infotypes such as PA0008, HRP1001 etc. Any idea?
Thanks,
Sandeep
2006 Jul 10 4:50 PM
2006 Jul 10 4:53 PM
It says, "RSQL error 23 when accessing table HRP1001.". Any altenative?
Thanks,
Sandeep
2006 Jul 10 4:55 PM
2006 Jul 10 4:56 PM
2006 Jul 10 5:01 PM
Yes i tried that. I also tried doing
select * from pa0008 into table test where endda = '99991231'.
where 'test' is an internal table of type pa0008. It worked fine. But, when i use dynamic work area it breaks.
2006 Jul 10 5:02 PM
2006 Jul 10 5:08 PM
2006 Jul 10 5:17 PM
REPORT 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.
2006 Jul 10 6:01 PM
2006 Jul 10 6:25 PM
2006 Jul 10 6:28 PM
2006 Jul 10 6:45 PM
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |