6 Replies Latest reply: Aug 17, 2006 10:16 AM by Parthasarathy Kannapiran RSS

How to pass a field symbol to subroutine?

Cindy Xu
Currently Being Moderated

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

  • Re: How to pass a field symbol to subroutine?
    Kiran Raorane
    Currently Being Moderated

    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

    • Re: How to pass a field symbol to subroutine?
      Cindy Xu
      Currently Being Moderated

      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.

      • Re: How to pass a field symbol to subroutine?
        Kiran Raorane
        Currently Being Moderated

        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

      • Re: How to pass a field symbol to subroutine?
        Vaishali Patwa
        Currently Being Moderated

        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

      • Re: How to pass a field symbol to subroutine?
        Vaishali Patwa
        Currently Being Moderated

        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.

  • Re: How to pass a field symbol to subroutine?
    Parthasarathy Kannapiran
    Currently Being Moderated

    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

Actions