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

How to pass dynamically created variables as subroutine parameters?

Former Member
0 Likes
1,533

Hi,

I have created a table and a structure dynamically, now is it possible to pass thse as parameters to a subroutine either as a field-symbol or as a reference variable?

If Yes, How?

-Sudheer

Hi,

I have created a table and a structure dynamically, now is it possible to pass thse as parameters to a subroutine either as a field-symbol or as a reference variable?

If Yes, How?

-Sudheer

7 REPLIES 7
Read only

Former Member
0 Likes
1,083

In the definition of the subroutine, declare the parameters as field symbols.

Hope this helps.

Thanks,

Balaji

Read only

0 Likes
1,083

Hi Balaji,

I have tried, There is no problem in passing a field symbol in the 'perfom' statement.

      perform fill-table changing <tab_lfa1>. 

But, In the 'form' statement how to declare the formal parameters for the field symbol?

I wrote the form statement like below.


form fill-table changing <fs> type any.

endform.                    " fill-table

Its saying * The name of a data oject can not start with a < and end with > *

-Sudheer

Read only

0 Likes
1,083

As you are trying to pass a table, you will need to keep the TABLES parm in the perform.

In the called FORM, tables p_otab will also be required. This will establish addressability to the table.

The Structure is would I would think is the issue. Since your structure is dynamic, this would indicate that the fields are variable in nature. If when creating the structure you used a standard naming convention, you could then establish addressability to each field if you know how many fields are passed. Perhaps you could add this number as one of the paramaters in the PERFORM.


  perform this_form tables <dynam_table> using fld_cnt.
*&---------------------------------------------------------------------*
*&      Form  this_form
*&---------------------------------------------------------------------*
form this_form tables   p_otab structure <dynam_struc>
                     using my_fld_cnt.
FIELD-SYMBOLS: 
  <f1>   type any,
  <f2>   type any,
  <f3>   type any,
  etc.
data:
 field_nbr(3) type n,
  field_name(32).

* here you can loop to get addressability

  do my_fld_cnt times.
     field_num = sy-index.
     concatenate '<dynam_struc>-MYFLD' field_num into field_name.
     case sy-INDEX.
       when 1.
          assign field_name to <f1>
       when 2.
          assign field_name to <f2>
.
.
.
   etc.
  endcase.
  enddo.
endform.                    " this_form

Read only

0 Likes
1,083

Hi

from the SAP help for form keywords,

Field symbols are special in that their names have to be enclosed in parentheses (<>).

Regards

Saurabh Garg

Read only

Former Member
0 Likes
1,083

I did not test this, but I would think this would work


start-of-selection.

  perform this_form tables <dynam_table>.
*&---------------------------------------------------------------------*
*&      Form  this_form
*&---------------------------------------------------------------------*
form this_form tables   p_otab structure <dynam_struc>.

endform.                    " this_form

<dynam_table> would be your your dynamic table

<dynam_struc> would be your structure of that table.

Read only

Former Member
0 Likes
1,083

Problem not resolved

Read only

0 Likes
1,083

Sudheer,

Can you please provide code for the creation of the dynamic table and structure so I can have a better understanding of your issue.

This will allow me to test locally.

Thanks.