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: 

Assigning a value to a field-symbol (workarea of type any)

former_member367551
Participant
0 Kudos

Dear forumers,

I'm having a bit of difficulty in assigning a value to a field-symbol (it should be treated as a workarea of type any), but I'm given a syntax error instead:-

The data object "<LFS_WORKAREA>" has no structure and therefore no component called "LFMON".

What could have gone wrong and how may I resolve this (I must have missed something out)? I will still need <LFS_WORKAREA> to be defined as TYPE ANY.

Please help. I'd appreciate any inputs at all. Thanks.

*&---------------------------------------------------------------------*
*&      Form  FORMAT_POST_PERIOD
*&---------------------------------------------------------------------*
*       Subroutine to format the posting period data
*----------------------------------------------------------------------*
*      --> PI_MBEW     Material valuation data (internal table)
*----------------------------------------------------------------------*
FORM format_post_period  CHANGING    pi_mbew TYPE ANY TABLE.

" Create local field symbols
  FIELD-SYMBOLS:
  <lfs_workarea> TYPE ANY,
  <lfs_lfmon>    TYPE ckmlcr-poper.

" Create local variables
  DATA: lv_index TYPE sy-tabix.
  DATA: lv_lfmon TYPE ckmlcr-poper.

" Format posting periods
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    lv_index = sy-tabix.

    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.

    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.

    MOVE lv_lfmon TO <lfs_workarea>-lfmon.   " the syntax error occurs here  :(

    MODIFY pi_mbew FROM <lfs_workarea>
      INDEX lv_index
      TRANSPORTING lfmon.

    CLEAR: <lfs_workarea>,
           <lfs_lfmon>
           lv_lfmon,
           lv_index.
  ENDLOOP.

ENDFORM.                    " FORMAT_POST_PERIOD

1 ACCEPTED SOLUTION

matt
Active Contributor
0 Kudos

This bit:

MOVE lv_lfmon TO <lfs_workarea>-lfmon. " the syntax error occurs here

Should simply be

<lfmon> = lv_lfmon

btw - it's better to do this:

DATA lp_data TYPE REF TO data.
CREATE DATA lp_data LIKE LINE OF (generic table name)
ASSIGN lp_data->* TO <workarea>.

ASSIGN COMPONENT 'COMP' OF STRUCTURE <workarea> TO <FIELD>.

LOOP AT table INTO <workarea>.
  <FIELD> = new_value.
  MODIFY...
ENDLOOP

as this is more efficient, because ASSIGN is resource heavy.

Also, check out this Uwe Schieferstein's blog about naming conventions, and consider the name of your field-symbols. The fs bit is redundant, since the angle brackets make it clear already that it's a field symbol.

matt

15 REPLIES 15

Subhankar
Active Contributor
0 Kudos
" Format posting periods
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    lv_index = sy-tabix.
 
    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
 
    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.
 
    MOVE lv_lfmon TO <lfs_workarea>-lfmon.   " the syntax error occurs here  :(

 +<lfs_workarea> is of type ANY. So could not identify <lfs_workarea>-lfmon.+

*+Using the statement aasign component do this thicg+*
  *+FIELD-SYMBOLS: <temp> type any+* 
  *+ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <temp>.+*
*+<temp> = lv_lfmon.+*

It will automatically populate the field <lfs_workarea>-lfmon

Edited by: Subhankar Garani on Oct 14, 2009 3:14 PM

Edited by: Matt on Oct 14, 2009 3:20 PM - added tags

matt
Active Contributor
0 Kudos

This bit:

MOVE lv_lfmon TO <lfs_workarea>-lfmon. " the syntax error occurs here

Should simply be

<lfmon> = lv_lfmon

btw - it's better to do this:

DATA lp_data TYPE REF TO data.
CREATE DATA lp_data LIKE LINE OF (generic table name)
ASSIGN lp_data->* TO <workarea>.

ASSIGN COMPONENT 'COMP' OF STRUCTURE <workarea> TO <FIELD>.

LOOP AT table INTO <workarea>.
  <FIELD> = new_value.
  MODIFY...
ENDLOOP

as this is more efficient, because ASSIGN is resource heavy.

Also, check out this Uwe Schieferstein's blog about naming conventions, and consider the name of your field-symbols. The fs bit is redundant, since the angle brackets make it clear already that it's a field symbol.

matt

matt
Active Contributor
0 Kudos

You may also have difficulty with

    MODIFY pi_mbew FROM <lfs_workarea>
      INDEX lv_index
      TRANSPORTING lfmon.

since pi_mbew isn't of a known structure. Just use

    MODIFY pi_mbew FROM <lfs_workarea>
      INDEX lv_index.

0 Kudos

Thanks, Subhankar and Matt for the helpful explanations. Kinda makes sense to me now.

But the problem occurs here at the MODIFY ... TRANSPORTING part.

How may I resolve this instead?

FORM format_post_period  CHANGING    pi_mbew TYPE ANY TABLE.

* Create local field symbols
  FIELD-SYMBOLS:
  <lfs_workarea>   TYPE ANY,
  <lfs_pre_lfmon>  TYPE ckmlcr-poper,
  <lfs_post_lfmon> TYPE ANY.

* Create local variables
  DATA: lv_index TYPE sy-tabix.
  DATA: lv_lfmon TYPE ckmlcr-poper.

* Format posting periods
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    lv_index = sy-tabix.

    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_pre_lfmon>.

    PERFORM convert_lfmon USING    <lfs_pre_lfmon>
                          CHANGING lv_lfmon.

*    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_post_lfmon>.
*    <lfs_post_lfmon> = lv_lfmon.

    <lfs_pre_lfmon> = lv_lfmon.

*    MODIFY pi_mbew FROM <lfs_workarea>
*      INDEX lv_index
*      TRANSPORTING <lfs_post_lfmon>.

    MODIFY pi_mbew FROM <lfs_workarea>
      INDEX lv_index
      TRANSPORTING <lfs_pre_lfmon>.

    CLEAR: <lfs_workarea>,
           <lfs_lfmon>
           lv_lfmon,
           lv_index.
  ENDLOOP.

ENDFORM.                    " FORMAT_POST_PERIOD

Matt, I'm using the naming convention as mentioned in the client's guideline. Can't help this, but will give it a check later.

0 Kudos

Hello Deborah,

Matt has already pointed that out for you in his previous post

Please check it. Hail Matt !!!

Cheers,

Suhas

matt
Active Contributor
0 Kudos

Aww, blush...

Simply don't the bit that specifies the field to change.

Re the standards, just point the powers that be at Uwe's blog...

matt

naimesh_patel
Active Contributor
0 Kudos

You can use the dynamic assignment in the TRANSPORTING addition of the MODIFY.


    MODIFY pi_mbew FROM <lfs_workarea>
      INDEX lv_index
      TRANSPORTING ('LFMON').  " <<

Regards,

Naimesh Patel

Former Member
0 Kudos

Deborah,

I guess you misunderstood the use of field-symbols. Max was right. Field-symbol simply works like a pointer as well.

FORM format_post_period  CHANGING    pi_mbew TYPE ANY TABLE.
 
* Create local field symbols
  FIELD-SYMBOLS:
  <lfs_workarea>   TYPE ANY,   
  <lfs_pre_lfmon>  TYPE ckmlcr-poper,
  <lfs_post_lfmon> TYPE ANY.
 
* Create local variables
  DATA: lv_index TYPE sy-tabix.
  DATA: lv_lfmon TYPE ckmlcr-poper.
 
 
* Create dynamic work area and assign to FS         <---- Create a dynamic workarea from the table you passed
 DATA: dy_line       TYPE REF TO data.                      in as parameter. Then assign the structure of the
  CREATE DATA dy_line LIKE LINE OF pi_mbew.        the workarea  to the field-symbol
  ASSIGN dy_line->* TO <lfs_workarea>.

* Format posting periods
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    lv_index = sy-tabix.
 
    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_pre_lfmon>.
 
    PERFORM convert_lfmon USING    <lfs_pre_lfmon>
                          CHANGING lv_lfmon.
  
    <lfs_pre_lfmon> = lv_lfmon.

 
  *  MODIFY pi_mbew FROM <lfs_workarea>    <---- This is not needed. Each time you update the  
  *    INDEX lv_index                            field-symbol the record in the table gets  updated automatically.
  *   TRANSPORTING <lfs_pre_lfmon>.     You dont need to modify the record in the table .
                                         So remove/comment them

 *   CLEAR: <lfs_workarea>,   <----------- Here you are clearing your own records in 
 *         <lfs_lfmon>                    the table, so remove/comment the field-symbols
 *       lv_lfmon,
 *        lv_index.
  ENDLOOP.
 
ENDFORM.                    " FORMAT_POST_PERIOD

Hope this helps.

0 Kudos

A huge thanks to everyone here for the helpful explanations and inputs. Really really do appreciate all the support given.

Some updates:

I've tried the following, but there are syntax errors returned:-

MODIFY pi_mbew FROM <lfs_workarea>

INDEX lv_index.

You cannot use explicit or implicit index operations on tables with types "HASHED TABLE" or "ANY TABLE".

"PI_MBEW" has the type "ANY TABLE".

The following works just fine (tested successfully as well), as recommended by WCWong:-

*&--------------------------------------------------------------------*
*&      Form  FORMAT_POST_PERIOD
*&---------------------------------------------------------------------*
*       Subroutine to format the posting period data
*----------------------------------------------------------------------*
*      --> PI_MBEW     Material valuation data (internal table)
*----------------------------------------------------------------------*
FORM format_post_period  CHANGING    pi_mbew TYPE ANY TABLE.

  FIELD-SYMBOLS:
  <lfs_workarea> TYPE ANY,
  <lfs_lfmon>    TYPE ckmlcr-poper.

  DATA: lv_lfmon TYPE ckmlcr-poper.

  DATA: lo_workarea TYPE REF TO data.
  CREATE DATA lo_workarea LIKE LINE OF pi_mbew.
  ASSIGN lo_workarea->* TO <lfs_workarea>.

  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.

    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.

    <lfs_lfmon> = lv_lfmon.

    CLEAR lv_lfmon.
  ENDLOOP.

ENDFORM.                    " FORMAT_POST_PERIOD

P/S: I just wished I could award points to everyone here!

Edited by: Deborah Tan on Oct 15, 2009 4:25 AM

matt
Active Contributor
0 Kudos

Most of us aren't in it for the points in any case...

For your solution you've redundant code:

*&--------------------------------------------------------------------*
*&      Form  FORMAT_POST_PERIOD
*&---------------------------------------------------------------------*
*       Subroutine to format the posting period data
*----------------------------------------------------------------------*
*      --> PI_MBEW     Material valuation data (internal table)
*----------------------------------------------------------------------*
FORM format_post_period  CHANGING    pi_mbew TYPE ANY TABLE.
 
  FIELD-SYMBOLS:
  <lfs_workarea> TYPE ANY,
  <lfs_lfmon>    TYPE ckmlcr-poper.
 
  DATA: lv_lfmon TYPE ckmlcr-poper.
 
*  DATA: lo_workarea TYPE REF TO data.   "<--Not needed, because the LOOP AT ASSIGNING below does the work
*  CREATE DATA lo_workarea LIKE LINE OF pi_mbew.
*  ASSIGN lo_workarea->* TO <lfs_workarea>.
 
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
 
    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.
 
    <lfs_lfmon> = lv_lfmon.
 
    CLEAR lv_lfmon.
  ENDLOOP.
 
ENDFORM.                    " FORMAT_POST_PERIOD

Here's a couple of more efficient solutions, using LOOP AT INTO.


FORM format_post_period  CHANGING    pi_mbew TYPE INDEX TABLE. " <-- Table type a little more specific
                                                               "<--now you can use index operations
 
  FIELD-SYMBOLS:
  <lfs_workarea> TYPE ANY,
  <lfs_lfmon>    TYPE ckmlcr-poper.
 
  DATA: lv_lfmon TYPE ckmlcr-poper,
        lv_index TYPE sytabix.
 
  DATA: lo_workarea TYPE REF TO data.
  CREATE DATA lo_workarea LIKE LINE OF pi_mbew.
  ASSIGN lo_workarea->* TO <lfs_workarea>.
 ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
  LOOP AT pi_mbew INTO <lfs_workarea>.
    lv_index = sy-tabix.     
    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.
 
    <lfs_lfmon> = lv_lfmon.
    MODIFY pi_mbew FROM <lfs_workarea>
       INDEX lv_index. " <--INDEX TABLE, so this is permitted.
    CLEAR lv_lfmon.
  ENDLOOP.
 
ENDFORM.                    " FORMAT_POST_PERIOD

matt
Active Contributor
0 Kudos
FORM format_post_period  CHANGING    pi_mbew TYPE ANY TABLE.
 
  FIELD-SYMBOLS:
  <lfs_workarea> TYPE ANY,
  <lfs_lfmon>    TYPE ckmlcr-poper.
 
  DATA: lv_lfmon TYPE ckmlcr-poper.
 
  DATA: lo_workarea TYPE REF TO data.
  CREATE DATA lo_workarea LIKE LINE OF pi_mbew.
  ASSIGN lo_workarea->* TO <lfs_workarea>.
  ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
  LOOP AT pi_mbew INTO <lfs_workarea>.

 
    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.
 
    <lfs_lfmon> = lv_lfmon.
   MODIFY TABLE pi_mbew FROM <lfs_workarea>
                TRANSPORTING ('LFMON'). " Non index form of MODIFY. 
    CLEAR lv_lfmon.
  ENDLOOP.
 
ENDFORM.                    " FORMAT_POST_PERIOD

The dynamic "TRANSPORTING" may not be available until later releases

matt

0 Kudos

THANKS again, Matt, for taking all the trouble in re-explaining here.

I've made the necessary code corrections as suggested.. Thanks a million, really appreciate this a lot!

0 Kudos

Great note.

Actually you helped me to solve my issue related to your observations.

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Deborah,

It is because the field-symbol <LFS_WORKAREA> is generic & its TYPE determined only at RunTime.

I dunno why you have to define the FS as generic, but to solve your problem:

 "MOVE lv_lfmon TO <lfs_workarea>-lfmon.

    MOVE lv_lfmon TO <lfs_lfmon>.

I think Matt has already poured in his valuable comments & i dont have to explain

BR,

Suhas

Former Member
0 Kudos

Hi

If your field-symbol is defined as TYPE ANY, the system can know its routine at runtime only, this explain the syntax error:

" Format posting periods
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    lv_index = sy-tabix.
 
    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
 
    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.
 
    MOVE lv_lfmon TO <lfs_workarea>-lfmon.   " the syntax error occurs here

Anyway u should consider the field-symbol is just a pointer, so after assigning it, the variable and the field-symbols will be the same.

In your code you're using 2 field symbol: one for the workarea of table PI_MBEW (LFS_WORKARE) and one (LFS_LFMON) for the field LFMON of field-symbol lfs_workarea (and so for the table PI_MBEW).

So, just as many guys said, u need to transfer the value to this last field-symbol, in this way it'll be automatically tansfered to workarea:

" Format posting periods
  LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
    lv_index = sy-tabix.
 
    ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
 
    PERFORM convert_lfmon USING    <lfs_lfmon>
                          CHANGING lv_lfmon.
 
 *   MOVE lv_lfmon TO <lfs_workarea>-lfmon.   " the syntax error occurs here
    MOVE lv_lfmon TO <lfs_lfmon>. 

Max