Application Development and Automation 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: 
Read only

bapi that displays dbase tables

Former Member
0 Likes
1,155

Hi guys!

Is there a standard bapi that retrieves records when you specify the table as parameter?

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,097

Hi Maui,

u do not require a BAPI for the purpose...

and most probably there isn't any available since BAPI have standardised interface with pretty strict data typing.

Wht u can do instead is to use dynamic programing (field-symbols) to create a dynamic select query which is quite simple...

Regards,

Mahesh

Hi guys!

Is there a standard bapi that retrieves records when you specify the table as parameter?

Thanks!

10 REPLIES 10
Read only

Former Member
0 Likes
1,098

Hi Maui,

u do not require a BAPI for the purpose...

and most probably there isn't any available since BAPI have standardised interface with pretty strict data typing.

Wht u can do instead is to use dynamic programing (field-symbols) to create a dynamic select query which is quite simple...

Regards,

Mahesh

Read only

0 Likes
1,097

thanks mahesh!

yup that's my next option. i thought there was an existing bapi so i could just call the function module and pass the records into the internal table.

Read only

0 Likes
1,097

Please check below code:

type-pools : abap.
field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.
data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
   parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

   perform get_structure.
   perform create_dynamic_itab.
* Creates a dyanamic internal table **
   perform get_data.
   perform write_out.

form get_structure.

  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-inttype = xdetails-type_kind.
<b>       xfc-intlen  = xdetails-length / 2.
       xfc-decimals = xdetails-decimals / 2.</b>
       append xfc  to ifc.
  endloop.

endform.

form create_dynamic_itab.
* Create dynamic internal table and assign to FS

   call method cl_alv_table_create=>create_dynamic_table
    exporting
             it_fieldcatalog = ifc
    importing
             ep_table        = dy_table.

   assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
   create data dy_line like line of <dyn_table>.
   assign dy_line->* to <dyn_wa>.

endform.

form get_data.

* Select Data from table.
  select * into table <dyn_table>
     from (p_table).

endform.

form write_out.
* 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.

endform.

If you are on non-unicode system, you can ignore dividing the length by 2 in the above highlighted portion.

Kind Regards

Eswar

Read only

0 Likes
1,097

Thanks Eswar!

Im a bit confused of using dynamic tables. I'll study and try your codes too.

Read only

0 Likes
1,097

Eswar's code is bang on!!!

u can use tht.

Read only

Former Member
0 Likes
1,097

hi

you can try the following function modules:

1. RFC_READ_TABLE , to read the contents of a given table with a selection criteria. This function is remote enabled, so my guess is it should fit your requirement.

2. LDB_INFO, to read the structure for a given logical database.

regards.

Read only

Former Member
0 Likes
1,097

You can use RFC_READ_TABLE for reading a table.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

former_member186741
Active Contributor
0 Likes
1,097

there is an rfc which does exactly what you want: RFC_GET_TABLE_ENTRIES.

Read only

Former Member
0 Likes
1,097

thanks guys!

Read only

Former Member
0 Likes
1,097

Hi maui,

1. just copy paste to get a taste of it.

2. It also includes an INDEPENDENT FORM/subroutine

whose inputs are

TABLE NAME / STRUCTURE NAME

and from those, it consructs dynamic table.

3. just copy paste

4.

REPORT abc.

*----


COMPULSORY

FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.

FIELD-SYMBOLS: <dynline> TYPE ANY.

DATA: lt TYPE lvc_t_fcat.

DATA: ls TYPE lvc_s_fcat.

FIELD-SYMBOLS: <fld> TYPE ANY.

DATA : fldname(50) TYPE c.

*----


parameters : tabname LIKE dd02l-tabname DEFAULT 'T001' OBLIGATORY.

*----


START-OF-SELECTION.

*----


PERFORM

PERFORM mydyntable USING lt.

PERFORM GET_DATA.

PERFORM SHOW_DATA.

BREAK-POINT.

*----


  • FORM

*----


FORM GET_DATA.

SELECT * FROM (TABNAME)

INTO TABLE <DYNTABLE>.

ENDFORM. "GET_DATA

*----


  • FORM

*----


FORM SHOW_DATA.

loop at <dyntable> ASSIGNING <dynline>.

sy-subrc = 0.

write 😕 .

WHILE SY-SUBRC = 0.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYNLINE> TO <FLD>.

WRITE : <FLD>.

ENDWHILE.

endloop.

ENDFORM. "SHOW_DATA

*----


  • INDEPENDENT FORM

*----


FORM mydyntable USING ptabname.

*----


Create Dyn Table From FC

FIELD-SYMBOLS: <fs_data> TYPE REF TO data.

FIELD-SYMBOLS: <fs_1>.

FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.

DATA: lt_data TYPE REF TO data.

data : lt TYPE lvc_t_fcat .

DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.

*----


CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'

EXPORTING

tabname = tabname

TABLES

ddfields = ddfields.

.

*----


CONSTRUCT FIELD LIST

LOOP AT ddfields.

ls-fieldname = ddfields-fieldname.

APPEND ls TO lt.

ENDLOOP.

ASSIGN lt_data TO <fs_data>.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt

IMPORTING

ep_table = <fs_data>

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

*----


Assign Dyn Table To Field Sumbol

ASSIGN <fs_data>->* TO <fs_1>.

ASSIGN <fs_1> TO <fs_2>.

ASSIGN <fs_1> TO <dyntable>.

ENDFORM. "MYDYNTABLE

regards,

amit m.