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 a field symbol to subroutine?

Former Member
0 Kudos

I'm trying to pass a field symbol to a subroutine.How to declare the field symbol in parameter interface?

1 ACCEPTED SOLUTION

Former Member

Hey,

See the sample code below

REPORT zkar_001.

FIELD-SYMBOLS: <fs> TYPE ANY.

PARAMETERS: test(2) TYPE c.

ASSIGN test TO <fs>.

PERFORM write USING <fs>.

&----


*& Form write

----


FORM write USING p_fs TYPE any.

WRITE 😕 p_fs.

ENDFORM. " write

-Kiran

6 REPLIES 6

Former Member

Hey,

See the sample code below

REPORT zkar_001.

FIELD-SYMBOLS: <fs> TYPE ANY.

PARAMETERS: test(2) TYPE c.

ASSIGN test TO <fs>.

PERFORM write USING <fs>.

&----


*& Form write

----


FORM write USING p_fs TYPE any.

WRITE 😕 p_fs.

ENDFORM. " write

-Kiran

0 Kudos

Kiran, thx for your reply.

But what i'm really want to do is to define the <fs> outside the subroutine and assign value inside. And the program may be somgthing like,

REPORT zkar_001.

FIELD-SYMBOLS: <fs> TYPE ANY.

PARAMETERS: test(2) TYPE c.

PERFORM write USING <fs>.

&----


*& Form write

----


FORM write USING p_fs TYPE any.

<b>ASSIGN test TO p_fs.</b>

WRITE 😕 p_fs.

ENDFORM. " write

When activating, an error message of <b>"p_fs is not defined as a field symbol"</b> will pop up.

0 Kudos

I did get the error. I am not sure how to define the field symbol to meet your requirement. Well, if you have defined <FS> as a global variable then you can directly use it inside the subroutine. See code below.

REPORT zkar_001.

FIELD-SYMBOLS: <fs> TYPE c.

PARAMETERS: test(2) TYPE c.

PERFORM write.

&----


*& Form write

----


FORM write.

ASSIGN test TO <fs>.

WRITE 😕 <fs>.

ENDFORM. " write

-Kiran

*Please mark useful answers

0 Kudos

Before passing the FS to the perform, assign a value to it.

REPORT zkar_001.

FIELD-SYMBOLS: <fs> TYPE ANY.

PARAMETERS: test(2) TYPE c.

***********

assign test to <FS>.

***********

PERFORM write USING <fs>.

&----


*& Form write

----


FORM write USING p_fs TYPE any.

*ASSIGN test TO p_fs.

WRITE 😕 p_fs.

ENDFORM. " write

0 Kudos

Hello Cindy,

If you are not passing any value to the <fs>, then why do you want to use it as a paramter on the perform.

You could create the field symbol inside the form, and assign value and use it within the perform.

Please explain why you want to pass a FS without any value assigned to it.

Former Member
0 Kudos

Hi,

I have a suggesstion ... you generally pass actual parameters to your subroutine in order to manipulate values of the interface. If this being the case, in your scenario you can assign the field-symbol globally and you can pass the parameters directly. After assignment, field-symbols always address to the assigned varaible.

Reward if helpful.

Regards