Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Generic Internal Table

Former Member
0 Kudos

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

15 REPLIES 15

former_member181966
Active Contributor
0 Kudos

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 this’ll give you idea!!

<b>Pl... award the points.</b>

Good luck

Thanks

Saquib Khan

"Some are wise and some are otherwise"<b></b>

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Right, it does not always work. What kind of error are you getting.

It is working good for me with PA0008.

Regards,

Rich Heilman

0 Kudos

It says, "RSQL error 23 when accessing table HRP1001.". Any altenative?

Thanks,

Sandeep

0 Kudos

I just ran for table HRP1001 and it worked create as well. Not sure what the problem could be.

Regards,

Rich Heilman

0 Kudos

Are you using INTO CORRESPONDING FIELDS?

select * <b>into corresponding fields of table</b> <dyn_table>
           from (p_table).

Regards,

Rich Heilman

0 Kudos

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.

0 Kudos

Does it has anything to do with configuration issue?

0 Kudos

No, no config. It should work as is. Both tables work well with no changes to the above program.

Can you please post your program.

Regards,

Rich Heilman

0 Kudos

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.

0 Kudos

Your code works in my system. What version are you on?

Regards,

Rich Heilman

0 Kudos

ECC 6.0

0 Kudos

So, my above sample program does not work in ECC 6.0 for table PA0008? You are getting the "RSQL error 23 when accessing table" error, right?.

Regards,

Rich Heilman

0 Kudos

Yes.