Archived discussions are read-only. Learn more about SAP Q&A

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

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

  • SAP Moderator
replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question