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: 

how to pass table to a form in a generic way?

Former Member
0 Kudos

hi,

There a way to pass table to a form in a generic way ?

(structure table gt_tab1 different structure table gt_tab2 )

like :

perform xxxx using gt_tab1 .

perform xxxx using gt_tab2 .

perform  xxxx lt_tab type ???????????.

thanks.

Ami.

8 REPLIES 8

Former Member
0 Kudos

Hi,

Please refer below syntax.

PERFORM xxxxx TABLES gt_tab1.

Form xxxxx TABLES gt_tab1 STRUCTURE (structure name).

endform.

Regards,

Ashwath


0 Kudos

but as i wrote before structure of tab1 DIFFERENT from  structure of tab2

Ami

JJosh
Active Participant
0 Kudos

Hi,

Try using type casting.

tab2?=itab1. and then pass it to form.

JJosh
Active Participant
0 Kudos

Hi,

PERFORM open_form TABLES <Enter the table to be passed> USING XXX.

Thanks

PeterJonker
Active Contributor
0 Kudos

You can use type ANY TABLE

Form xxxxx    CHANGING lt_table   TYPE ANY TABLE

                                       wa_table TYPE ANY.

endform.

0 Kudos

thanks Peter

but when i am writing the form in this way i cannt loop or read data from  lt_table

thanks Ami

0 Kudos

Hi Ami,


But if you need to read data from the table or loop for specific fields in the structure, then i think a separate perform for each table would be better.


You can pass tables this way to for example a ALV display method.


If you still want to use one perform you will have to use if statements within the perform to be able to determine which table has been passed. That is if each table requires a different processing, which I understand since the structures are different.


it would look something like this then, but it is not perfect. I would go for two performs. It would seperate the different logic, which will make life easier with future changes to the code. (example based on selecting from table USR01 or USR02 depending on checkbox in selscreen). The selected entries are then sent to this perform. I think this would also only work with database tables, not internal tables. But in a similar way you could do this al;so for internal tables I guess.


Form xxxxx    CHANGING lt_table   TYPE ANY TABLE

                                       wa_table TYPE ANY.


Data: lv_struc TYPE string,
         strucname TYPE string,
         lv_length TYPE i,
         off TYPE i,
         l_tabref    TYPE REF TO data,      

         l_rcl_struc TYPE REF TO cl_abap_structdescr.

FIELD-SYMBOLS: <t1_tab> TYPE STANDARD TABLE,
                              <wa_tab1> TYPE usr01,
                              <wa_tab2> TYPE usr02.

  l_rcl_struc ?= cl_abap_structdescr=>describe_by_data( wa_table ).

  lv_struc = l_rcl_struc->absolute_name.

  lv_length = STRLEN( lv_struc ).

  off = lv_length - 6.
  strucname = lv_struc+6(off).

CREATE DATA l_tabref   TYPE TABLE OF (strucname).
  ASSIGN l_tabref->*   TO <t1_tab>.

  IF strucname = 'USR01'.
    LOOP AT <t1_tab> ASSIGNING <wa_tab1>.
      WRITE <wa_tab1>-bname.
    ENDLOOP.

  ELSEIF strucname = 'USR01'.

    LOOP AT <t1_tab> ASSIGNING <wa_tab2>.
      WRITE <wa_tab1>-bname.
    ENDLOOP.

  ENDIF.

endform.

Again it is possible, but I would choose for two seperate performs in stead.

0 Kudos

Hi,

but when i am writing the form in this way i cannt loop or read data from  lt_table

Well you just need to use the ASSIGN COMPONENT '...' statement to fetch a particular column.

FORM xxxx USING it_tab TYPE ANY TABLE.

FIELD-SYMBOLS: <fs> TYPE ANY,

                               <comp> TYPE ANY.

LOOP at it_tab ASSIGNING <fs>.

     "...

     ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> to <comp>.

     IF sy-subrc = 0.

     "...

     ENDIF.

ENDLOOP.

ENDFORM.

I don't think you need further RTTS development for such a basic issue, or did I miss something?

What are you planning to do with those tables inside the form?

Kr,

Manu.