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

READ TABLE using index with dynamic internal tables - multiple fields

Former Member
0 Likes
6,528

Have 2 internal tables where one field has slightly different fieldname as one is based on a TO and other ona transfer requirement. Based on which tramsaction is called determines which table to access. Tried doing this with field symbols but get no joy. Getting mixed up with my field symbols statments.

FIELD-SYMBOLS: <fs> TYPE ANY,
                              <fs_tab> type STANDARD table.

*---Set screen fields----------------------------------------------
  IF sy-tcode = 'ZRFB13'.
    assign GT_LTAP to <fs_tab>.
  ELSEIF sy-tcode = 'ZRFB14'.
    ASSIGN GT_LTBP TO <fs_TAB>.
  ENDIF.


  READ TABLE <FS_TAB> ASSIGNING <FS> INDEX G_COUNT .

  IF sy-subrc = 0.
    IF sy-tcode = 'ZRFB13'.
      xr_scr_0902-s_item  = <fs>-tapos.
      xr_scr_0902-fld_skip = <fs>-skip.
      xr_scr_0902-s_matnr = <fs>-matnr.
      xr_scr_0902-s_batch = <fs>-charg.
      xr_scr_0902-s_qty   = <fs>-qty.
      xr_scr_0902-s_uom   = <fs>-uom.
      xr_scr_0902-s_styp  =<fs>-vltyp.
      xr_scr_0902-s_bin   = <fs>-vlpla.
   ELSEIF SY-TVCODE = 'ZRFB14'.
      xr_scr_0902-s_item  = <fs>-tbpos.
      xr_scr_0902-fld_skip = <fs>-skip.
      xr_scr_0902-s_matnr = <fs>-matnr.
      xr_scr_0902-s_batch = <fs>-charg.
      xr_scr_0902-s_qty   = <fs>-qty.
      xr_scr_0902-s_uom   = <fs>-uom.
  ENDIF.
ENDIF.

Syntax error is ' The data object <fs> has no structure and therefore no component called TAPOS

Is there any way I can do this without using ASSIGN COMPONENT as do not really want to assign fields when multiple fields involved? Can I reference a data object or is there something else I can do?

Any pointers would be appreciated.

Regards

Larissa

7 REPLIES 7
Read only

Former Member
0 Likes
2,452

Hi

Or you assign field by field, or u define the field-symbol like the structure having the fields u're transfering instead of to define as generic type:

FIELD-SYMBOLS: <fs> TYPE <structure>.

Max

Read only

0 Likes
2,452

Problem is that my structure will be different at runtime based on which transaction has been run.

Read only

0 Likes
2,452

That means u have to assign field by field

If you have a rule for mapping where u can indicate the link between source and target field perhaps u can create some lines of code valid for all cases.

Max

Edited by: max bianchi on Jan 14, 2010 3:04 PM

Read only

Former Member
0 Likes
2,452

Hi larissa,

First of all have a look at this points

<< Cut and paste without attribution from

http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb387a358411d1829f0000e829fbfe/content.htm removed >>

Manas Mishra

Edited by: Kumar Manas Mishra on Jan 14, 2010 3:43 PM

Edited by: Kumar Manas Mishra on Jan 14, 2010 3:45 PM

Edited by: Kumar Manas Mishra on Jan 14, 2010 3:47 PM

Edited by: Rob Burbank on Jan 14, 2010 9:58 AM

Read only

Former Member
0 Likes
2,452
FIELD-SYMBOLS:<fs_vbreve> TYPE t_vbreve.

LOOP AT it_vbreve ASSIGNING <fs_vbreve>.

    READ TABLE it_vbrevr WITH KEY vbeln = <fs_vbreve>-vbeln
                                  posnr = <fs_vbreve>-posnr
                                  BINARY SEARCH
                                  TRANSPORTING NO FIELDS.
    IF sy-subrc EQ 0.
      <fs_vbreve>-del = 'N'.
    ELSE.
      UNASSIGN <fs_vbkd>.
      READ TABLE it_vbkd ASSIGNING <fs_vbkd>
                                    WITH KEY vbeln = <fs_vbreve>-vbeln
                                             posnr = <fs_vbreve>-posnr
                                             BINARY SEARCH.
      IF sy-subrc EQ 0.
        READ TABLE it_fplt WITH KEY fplnr = <fs_vbkd>-fplnr
                                    BINARY SEARCH
                                    TRANSPORTING NO FIELDS.
        IF sy-subrc EQ 0.
          <fs_vbreve>-del = 'N'.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

-


DATA : v_ktokd LIKE kna1-ktokd,
         v_kunnr LIKE kna1-kunnr.


  FIELD-SYMBOLS: <k1> TYPE STANDARD TABLE.
  DATA: k2      TYPE fknvi  ,
        l_index TYPE sytabix.

  IF ( sy-tcode = 'XD01'  OR  sy-tcode = 'VD01' ) AND
     i_knvv-vkorg EQ '1000'.
    ASSIGN ('(SAPMF02D)XKNVI[]') TO <k1>.
    IF <k1> IS ASSIGNED.
      LOOP AT t_knvi.

        MOVE: sy-tabix TO l_index.
        IF t_knvi-taxkd IS INITIAL AND
           t_knvi-aland EQ 'US'.
          t_knvi-taxkd = '6'.
          MODIFY t_knvi TRANSPORTING taxkd.

          READ TABLE <k1> INTO k2 INDEX l_index.
          k2-taxkd = '6'.
          MODIFY <k1>  FROM k2 INDEX l_index.
        ENDIF.
        CLEAR: k2     ,
               l_index.
      ENDLOOP.
      UNASSIGN <k1>.
    ENDIF.
  ENDIF.

Read only

2,452

Decided to do it another way as if I have to assign the fields then no point doing field symbols.

Many thanks anyway.

Read only

Former Member
0 Likes
2,452

Decided to do something else but awarded points to the most relevant answer.