Dynamic assign in field symbols

dynamic assign in field symbols

Hi,
DYNAMIC ASSIGN:
If you do not know the name of the field that you want to assign to the field symbol when you write a program, you can use a dynamic ASSIGN statement:
ASSIGN (<f>) TO <FS>.
This statement assigns the field whose name is contained in the field <f> to the field symbol <FS>. You cannot use offset and length in a dynamic ASSIGN.
At runtime, the system searches for the corresponding data object in the following order:
If the ASSIGN statement is in a procedure, the system searches first in its local data.
If it cannot find the object in the local data (or if the ASSIGN statement is not in a procedure), it then looks in the local data of the program.
If the field does not exist in the global data of the program, the system looks in the table work areas declared with the TABLES statement in the main program of the current program group. A program group consists of a main program and all of the programs that are loaded into the same internal session as a result of other program calls.
If the search is successful and a field can be assigned to the field symbol, SY-SUBRC is set to 0. Otherwise, it is set to 4, and the field symbol remains unchanged. For security reasons, you should always check the value of SY-SUBRC after a dynamic ASSIGN to prevent the field symbol pointing to the wrong area.
Searching for the field in this way slows down the program. You should therefore only use the dynamic ASSIGN statement when absolutely necessary. If you know when you create the program that you want to assign a table work area to the field symbol, you can also use the following variant of the dynamic ASSIGN statement:
ASSIGN TABLE FIELD (<f>) TO <FS>.
The system then only searches within the table work areas in the main program of the current program group for the data object that is to be assigned to the field symbol. This addition is forbidden in ABAP Objects, since the latter does not support table work areas.
Suppose we have three programs. The main program:
REPORT demo_field_symbols_dynami_as_1.
TABLES sbook.
sbook-fldate = sy-datum.
PERFORM form1 IN PROGRAM demo_form1.
The other two programs are:
REPORT demo_form1.
FORM form1.
  PERFORM form2 IN PROGRAM demo_form2.
ENDFORM.
and
REPORT demo_form2.
FORM form2.
  DATA name(20) TYPE c VALUE 'SBOOK-FLDATE'.
FIELD-SYMBOLS <fs> TYPE ANY.
  ASSIGN (name) TO <fs>.
  IF sy-subrc EQ 0.
    WRITE / <fs>.
ENDIF.
ENDFORM.
The output looks something like this:
02.06.1998
The program group in the internal session now consists of the programs DEMO, MYFORMS1 and MYFORMS2. The field symbol <FS> is defined in MYFORMS2. After the dynamic ASSIGN statement, it points to the component FLDATE of the table work area SBOOK declared in the main program DEMO.
REPORT demo_field_symbols_dynami_as_2 .
TABLES sbook.
DATA: name1(20) TYPE c VALUE 'SBOOK-FLDATE',
      name2(20) TYPE c VALUE 'NAME1'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN TABLE FIELD (name1) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
ASSIGN TABLE FIELD (name2) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
The output is:
SY-SUBRC:      0
SY-SUBRC:      4
In the first ASSIGN statement, the system finds the component FLDATE of the table work area SBOOK and SY-SUBRC is set to 0. In the second ASSIGN statement, the system does not find the field NAME1 because it is declared by the DATA statement and not by the TABLES statement. In this case, SY-SUBRC is set to 4.
Reference: http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb38d5358411d1829f0000e829fbfe/content.htm
reward points if helpful.
Regards,
Ramya

Similar Messages

  • Dynamic select with field symbols

    Hi guys,
    I have 2 tables.
    First table is the popup fields using fm popup_get_values:
    tab1-tabname
    tab1-fieldname
    tab1-value
    Second table is the input fields to be displayed in the popup box:
    tab2-transactno
    tab2-docno
    tab2-customer
    tab2-postdate
    etc... (it has many fields)
    Let's say currently i loop at tab2 and assign each value of the individual fields to a variable each:
    loop at tab2
    v_transactno = tab2-transactno
    v_docno = tab2-docno
    etc...
    endloop.
    My question is how do i assign each variable to the popup fields according to the fieldname so that it can get its corresponding value correctly?
    How can this be done dynamically?
    Can the loop above be done dynamically as well coz it has alot of fields to cater for?
    Please help me solve this problem. Futher similar examples would be much appreciated as well.
    Thank you very much!

    Hi
    see the concept of field sysmbols and do accordingly
    Field Symbols
    Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.
    Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.
    Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects.
    All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.
    You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.
    Field symbols provide greater flexibility when you address data objects:
    If you want to process sections of fields, you can specify the offset and length of the field dynamically.
    You can assign one field symbol to another, which allows you to address parts of fields.
    Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.
    You can also force a field symbol to take different technical attributes from those of the field assigned to it.
    The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.
    While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.
    For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.
    check the below links u will get the answers for your questions
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
    Syntax Diagram
    FIELD-SYMBOLS
    Basic form
    FIELD-SYMBOLS <fs>.
    Extras:
    1. ... TYPE type
    2. ... TYPE REF TO cif
    3. ... TYPE REF TO DATA
    4. ... TYPE LINE OF type
    5. ... LIKE s
    6. ... LIKE LINE OF s
    7. ... TYPE tabkind
    8. ... STRUCTURE s DEFAULT wa
    The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
    Effect
    This statement declares a symbolic field called <fs>. At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.
    You can only use one of the additions.
    Example
    Output aircraft type from the table SFLIGHT using a field symbol:
    FIELD-SYMBOLS <PT> TYPE ANY.
    DATA SFLIGHT_WA TYPE SFLIGHT.
    ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
    WRITE <PT>.
    Addition 1
    ... TYPE type
    Addition 2
    ... TYPE REF TO cif
    Addition 3
    ... TYPE REF TO DATA
    Addition 4
    ... TYPE LINE OF type
    Addition 5
    ... LIKE s
    Addition 6
    ... LIKE LINE OF s
    Addition 7
    ... TYPE tabkind
    Effect
    You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
    This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
    In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
    Effect
    Assigns any (internal) field string or structure to the field symbol from the ABAP Dictionary (s). All fields of the structure can be addressed by name: <fs>-fieldname. The structured field symbol points initially to the work area wa specified after DEFAULT.
    The work area wa must be at least as long as the structure s. If s contains fields of the type I or F, wa should have the structure s or at least begin in that way, since otherwise alignment problems may occur.
    Example
    Address components of the flight bookings table SBOOK using a field symbol:
    DATA SBOOK_WA LIKE SBOOK.
    FIELD-SYMBOLS <SB> STRUCTURE SBOOK
    DEFAULT SBOOK_WA.
    WRITE: <SB>-BOOKID, <SB>-FLDATE.
    Regards
    Anji

  • Coloring of Particular Cells in a dynamic internal table(field symbols)

    Hi,
         I have a requirement to introduce color into some particular cells in a dynamic internal table(Field symbol) based on some conditions.I know that color can be introduced at cell level in the case of static internal table.But, can anybody tell me whether it is possible to introduce color to particular cells in the dynamic internal table(Field Symbol) .Please suggest me on this issue.
    Thanks in advance,
    Rajesh

    Hi,
    This is the sample coding for the colour cell report.
    Kindly go through it. It will helps u.
    REPORT YMS_COLOURTEST .
    DATA: BEGIN OF TP OCCURS 10, ID, NR(8), TEXT(255), END OF TP.
    DATA: LENGTH TYPE I VALUE 8, " Length of list
    TESTSTRING(15) TYPE C VALUE '012345678901234',
    WIDTH TYPE I. " Width of list
    DATA: TXT_REPORT LIKE DOKHL-OBJECT.
    START-OF-SELECTION.
    PERFORM HEADING.
    PERFORM OUTPUT_BODY.
    FORM HEADING.
    FORMAT INTENSIFIED OFF. " Remove any INTENSIFIED
    ULINE AT (WIDTH). " Upper frame border
    FORMAT COLOR COL_HEADING INTENSIFIED." Title color
    WRITE: / SY-VLINE. " Left border
    WRITE: 'No |Colour |intensified |intensified off|',
    'inverse' NO-GAP.
    WRITE: AT WIDTH SY-VLINE. " Right border
    ULINE AT (WIDTH). " Line below titles
    FORMAT COLOR OFF.
    ENDFORM.
    FORM OUTPUT_BODY.
    DO LENGTH TIMES.
    PERFORM WRITE_LINE USING SY-INDEX.
    ENDDO.
    ENDFORM.
    FORM WRITE_LINE USING COUNT TYPE I.
    DATA: HELP(14) TYPE C,
    COUNT1 TYPE I.
    COUNT1 = SY-INDEX - 1.
    WRITE: / SY-VLINE NO-GAP.
    WRITE: (4) COUNT1 COLOR COL_KEY INTENSIFIED NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    CASE COUNT1.
    WHEN '0'.
    HELP = 'COL_BACKGROUND'.
    WHEN '1'.
    HELP = 'COL_HEADING'.
    WHEN '2'.
    HELP = 'COL_NORMAL'.
    WHEN '3'.
    HELP = 'COL_TOTAL'.
    WHEN '4'.
    HELP = 'COL_KEY'.
    WHEN '5'.
    HELP = 'COL_POSITIVE'.
    WHEN '6'.
    HELP = 'COL_NEGATIVE'.
    WHEN '7'.
    HELP = 'COL_GROUP'.
    ENDCASE.
    WRITE: HELP COLOR COL_KEY INTENSIFIED NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED OFF NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    WRITE: TESTSTRING COLOR = COUNT1 INVERSE NO-GAP.
    WRITE AT WIDTH SY-VLINE NO-GAP.
    ENDFORM.
    Thanks,
    Shankar

  • Sum for Dynamic Fields in a Dynamic Table with Field Symbol

    Hi All,
    I currently have an report which I am looking to update with some totals.  The information is currently output in an ALV which is fed data from a dynamic table defined with a field symbol.  The modification that needs to be applied is a summation per currency code where each of the fields to be summed is a dynamically named field at runtime.  I am now just looking to see if anyone has any recommendations on how to obtain these totals it would be appreciated.  I have no problem doing the leg work in piecing the solution together but am just stuck on which approach I should be investigating here.  I have looked into several options but do to the fact that the totals are for dynamic fields in a dynamic table and it is a field symbol I am having some difficulties thinking of the easiest approach to obtain these totals.
    Below is a simple sample of what the report currently looks like and what we are looking to add.
    ====================================================================================
    As-Is Report:
    DETAILED DATA ALV
    Company Code  |  Plant  |  2006 Total  |  2007 Total  |  2008 Total |  CURRENCY
    0001          |   ABCD  |    1,500     |    1,200     |    1,700    |    USD
    0001          |   BCDE   |    2,300     |    4,100     |    3,600    |    GBP
    0003          |   DBCA  |    3,200     |    1,600     |    6,200    |    USD
    Addition 1:
    TOTALS PER CURRENCY
    Currency                |  2006 Total  |  2007 Total  |  2008 Total |
    USD              |    4,700     |    2,800     |    7,900    |
    GBP                       |    2,300     |    4,100     |    3,600    |
    Addition 2:
    CONVERSIONS TO USD
                                          |  2006 Curr   |  2006 USD    |  2008 Curr   |  2006 USD   |
    USD                       |  4,700 USD   |  4,700 USD   |  7,900 USD  |  7,900 USD  |
    GBP   (1.5GBP/1 USD)    |  2,300 GBP   |  1,150 USD   |  2,300 GBP  |  1,800 USD  |
    ====================================================================================
    Any recommendations will be appreciated.

    Hi,
    We cannot use the key word SUM in the loop at assigning statement.
    The way i see is
    When  you are creating the first dynamic internal table , create one more with  the structure below:
    Currency | 2006 Total | 2007 Total | 2008 Total |
    Then while populating the data into first itab,also move the contents to the second itab using collect statement.

  • Dynamic assignment of field in a Structure

    Hello there,
    i'm looking for a solution of the following Problem:
    I have a structure STRUC with several fields e.g. Name, Street, City
    In my program i get dynamically the fieldname and the corresponding value.
    With these information i like to do the following assignment:
    STRUC-<fieldname> = 'Hello world'. (which is not working in ABAP)
    How can i do an assignment like this? I only found a way to read colums dynamically from a structure but not the oppside way.
    ASSIGN COMPONENT <fieldname> of structure <STRUC> to <fieldvalue>.
    I need something like this
    ASSIGN <fieldvalue> to COMPONENT <comp> of structure <STRUC>.
    Does anybody has an idea?
    Many thanks in advance!
    Josef

    Hello together,
    the problem is solved here is the example coding:
    data: lv_value(80) type c,
            fieldname(20) type c.
    field-symbols: <value> type any.
    fieldname = 'TEXT'.
    concatenate 'STRUC-' fieldname into lv_value.
    assign (lv_value) to <value>
    if sy-subrc = 0.
      <value> = 'Hello world'.
    endif.
    unassign <value>
    result: struc-text = 'Hello World'.

  • EXTREME Dynamic List of Field Symbols

    Hi All,
    This requirement have created lots of issues fo me and oculd not reach it, hence i am here :
    Internal table 1 with 'a' columns                    Internal Table 2  with 'b' columns
    a1    a2     a3                                                b1      b2      b3
    11     22    150                                               10      20       30
    Note: BOTH ARE FIELD-SYMBOL INTERNAL TABLE of TYPE ANY and HAVE NO STRUCTURE UNTIL RUNTIME
    What I want is a
    - Get a List of How many columns are in FIELD SYMBOL Internal Table 1 at RUNTIME.
    - DYNAMIC MAPPING TABLE that reads the HEADER OF COLUMNS and its DATA maps them in a Internal table at RUNTIME.
    Col1    Col2     Col3    Col4
    a1      11         b1        10
    a2      22         b2        20
    a3      150       b3       30

    Hi,
    - Get a List of How many columns are in FIELD SYMBOL Internal Table 1 at RUNTIME.
    You will have to use RTTS class for that. Something like:
    lo_sdescr ?= cl_abap_typedescr=>describe_by_data_ref( lo_data ). "lo_data containing ref. to your field-symbols
    LOOP AT lo_sdescr->components INTO ls_component.
    ENDLOOP
    - DYNAMIC MAPPING TABLE that reads the HEADER OF COLUMNS and its DATA maps them in a Internal table at RUNTIME.
    I don't see the need of a dynamic itab here, since the number/type of column seems to be fixed...
    If needed, build it up using RTTS as well.
    Kr,
    m.

  • Screen value not assign in field symbol

    Hi gurus,
             I create a field symbol for module pool programming for assigning screen value. I create a tab in main screen and three subscreen for tab.  in first screen values perfectly asign in field symbol but second subscreen FS1,FS2,FS3 values not assign.
    Atthe time of save three subscreen values stored in internal table, then insert into ztable.
    PERFORM SAVE_DATA USING '15' 'GTAB-IO_CODE' 'GTAB-IO_PER' 'GATB-IO_VAL'.
    PERFORM SAVE_DATA USING '26' 'GTAB-IO_SCODE' 'GTAB-IO_SPER' 'GTAB-IO_SVAL'.
    FORM SAVE_DATA USING X TYPE I
                         FS1 TYPE STRING
                         FS2 TYPE STRING
                         FS3 TYPE STRING.
    *FORM SAVE_DATA USING X TYPE I FS1 TYPE STRING.
      CLEAR SNO.
      CLEAR C.
      ITAB-MANDT = SY-MANDT.
      ITAB-BUKRS = '1000'.
      ITAB-DOCNO = '0001000005'.
      ITAB-BUDAT = SY-DATUM.
      DO X TIMES.
      IF X EQ '15'.
        FS1 = 'GTAB-IO_CODE'.
        FS2 = 'GTAB-IO_PER'.
        FS3 = 'GTAB-IO_VAL'.
      ELSEIF X EQ '26'.
        FS1 = 'GTAB-IO_SCODE'.
        FS2 = 'GTAB-IO_SPER'.
        FS3 = 'GTAB-IO_SVAL'.
      ENDIF.
        C = C + 1.
        SNO = SNO + 10.
        ITAB-SLNO = SNO.
        ZCOMRP_ORTRN-SLNO = SNO.
        CONCATENATE FS1 C INTO FS1.
        ASSIGN  (FS1) TO <FS>.
        ZCOMRP_ORTRN-PRCOD = <FS>.
        ITAB-PRCOD = <FS>.
        CONCATENATE FS2 C INTO FS2.
        ASSIGN  (FS2) TO <FS>.
        ZCOMRP_ORTRN-KBETR = <FS>.
        ITAB-KBETR = <FS>.
        CONCATENATE FS3 C INTO FS3.
        ASSIGN  (FS3) TO <FS>.
        ZCOMRP_ORTRN-DMBTR = <FS>.
        ITAB-DMBTR = <FS>.
       INSERT ZCOMRP_ORTRN.
        APPEND ITAB.
        INSERT  ZCOMRP_ORTRN FROM ITAB.
        CLEAR FS1.
        CLEAR FS2.
        CLEAR FS3.
       CLEAR C.
      ENDDO.
      PERFORM CLEAR.
    ENDFORM.                    " SAVE_DATA

    solved

  • Dump GETWA_NOT_ASSIGNED assigning a Field Symbol

    i have
    DATA: W_PROG3(30) VALUE '(SAPLV56U)I_XVTTK[]'.
    ASSIGN (W_PROG3) TO  is executed i got a dump.
    Only in this case i got a dump.
    I hope somebody could help me with this

    Hello,
    I have the same Problem with another Table.  To evaluate the Problem I wrote a little testprogram with the following code:
    *& Report  ZL_FROELICHM_TEST1                                          *
    report  ZL_FROELICHM_TEST1                      .
    data: VBSK_I like  VBSK.
    data: T_KOMDLGN  like KOMDLGN occurs 10 with header line,
          T_VBFS     type table of VBFS,
          T_VBLS     type table of VBLS.
    call function 'GN_DELIVERY_CREATE'
      exporting
        VBSK_I   = VBSK_I
      tables
        XKOMDLGN = T_KOMDLGN[]
        XVBFS    = T_VBFS
        XVBLS    = T_VBLS.
    perform ASSIGN.
    *&      Form  assign
          text
    -->  p1        text
    <--  p2        text
    form ASSIGN .
      data:           NAME_TAB1(30) type C value '(SAPLV50S)XKOMDLGN'.
                     KOMDLGN type table of KOMDLGN with header line.
      field-symbols:  .
      if SY-SUBRC = 0.
       KOMDLGN = <KOMDLGN>.
      endif.
    assign: (NAME_TAB1) to <KOMDLGN>.
    if SY-SUBRC = 0.
       KOMDLGN[] = <KOMDLGN>.
    endif.
    check not KOMDLGN[] is initial.
    endform.                    " assign
    If you call Funktion 'GN_DELIVERY_CREATE' then the ASSIGN dumps.  If you don't call it, then the ASSIGN gives you a returncode 4.  The funktion works within the GN_DELIVERY_CREATE, however, the relevant coding is in the Program SAPMV50A in the performroutine USEREXIT_REFRESH_DOCUMENT.  I get the dump when the exit is called by WS_DELIVERY_UPDATE, or RV_DELIVERY_CREATE.  These functions don't know the Table XKOMDLGN.
    So, if you find a solution to your problem, please let me know.  I think I have the same problem.
    Greetings,
    Maria Frölich.

  • ASSIGN TO FIELD SYMBOL

    Hi,
    in user exit EXIT_SAPLVEDA_001.
    data: wa_xvbap like line of xvbap.
          FIELD-SYMBOLS: <fs_xvbap> like wa_xvbap.
          ASSIGN '(SAPLVEDA)XVBAP' TO <fs_xvbap>.
    getting error of type incompatible..
    any ideas?
    Thanks
    Giri

    Hi,
    you are trying to assign a string '(SAPLVEDA)XVBAP' to a field symbol with type XVBAP. You are just missing brackets.
    ASSIGN ('(SAPLVEDA)XVBAP') TO <fs_xvbap>.
    Cheers

  • How to dynamically assign type to a field-symbol?

    Hi,
    I have two fields in one table, one for field name and one for table name.  These can be fields in different
    tables. I need to fetch value of this field in that table. So the type of this variable can change dynamically.
    I am trying to assign type of this field dynamically to a field-symbol. I have to use this field symbol in a
    select statement.  Currently it is showing a dumb, as the field type is dec7.  For some other types it is
    working fine.
    Regards,
    Sunil

    Hi all,
    I have the same problem.
    I tried with your helps but i can't fix them.
    A message is raised "Field <fs_bet> unknown" when i used code below
    FIELD-SYMBOLS: <fs_bet> TYPE any.
    DATA: c_bet TYPE string.
    DATA it_0008 type STANDARD TABLE OF pa0008 WITH HEADER LINE.
    DO 40 TIMES.
      CONCATENATE 'BET0' index into c_bet.
      ASSIGN (c_bet) to <fs_bet> CASTING TYPE pad_amt7s  .
      select * from pa0008 into it_0008
         where <fs_bet> = '1000'
         and pernr = 32.
         append it_0008.
      ENDSELECT.
    ENDDO.
    Please help me to solve it.
    Thanks so much,
    Sophie Tran

  • Problem with slis_t_specialcol_alv Field Symbol Assignment

    I have created a dynamic internal table (runtime determined number of columns) to contain data to be displayed in an ALV. I’ve also made ensured that the last column of the dynamic itab is of type <b>'slis_t_specialcol_alv'</b> and named <b>‘CINFO’</b> to contain color information for that particular row. In the code below the dynamic itab is pointed to by field symbol <dyn_table> while the work area for it would be <dyn_wa>.
    Somewhere down the line I attempt to assign the ‘CINFO’ component of the current row of the itab to a field symbol called <fs_cinfo> typed as ‘slist_t_specialcol_alv’ (Same as CINFO).
    I used the code:
    ASSIGN COMPONENT 'CINFO' OF STRUCTURE <dyn_wa> TO <fs_cinfo>.
    This gives me the runtime error:
    <i>Type conflict in the ASSIGN statement in the program "ZHRR001_TEMMATRIX".
    You attempted to assign a field to a typed field symbol,
    but the field does not have the required type.    </i>     
    I am unsure why this happens as both the component CINFO and FS <fs_cinfo> are of type slist_t_specialcol_alv.
    For some odd reason though during debugging, I took a look at the <dyn_wa> structure and the component type of CINFO was displayed as “C”???
    Here is the relevant portion of code (creation of dynamic itab and attempting to assign <fs_cinfo>)
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa>.
    FIELD-SYMBOLS: <fs_cinfo> TYPE slist_t_specialcol_alv.
    DATA: lw_cinfo TYPE slis_specialcol_alv.
    DATA:          li_fldcat TYPE lvc_t_fcat,
                   lw_fldcat TYPE lvc_s_fcat.
    *Create internal table fields (they will be called Field1, Field2, etc)
    *Last column will be named 'CINFO' to contain row color information
    DO l_alvcolumncount TIMES.
      index = sy-index.
      IF index <> l_alvcolumncount.
        CLEAR lw_fldcat.
        CONCATENATE 'Field' index INTO lw_fldcat-fieldname .
        CONDENSE lw_fldcat-fieldname NO-GAPS.
        lw_fldcat-datatype = 'STRING'.
    *    lw_fldcat-intlen = 5.
        APPEND lw_fldcat TO li_fldcat .
      ELSE.
        CLEAR lw_fldcat.
        lw_fldcat-fieldname = 'CINFO'.
        CONDENSE lw_fldcat-fieldname NO-GAPS.
        lw_fldcat-datatype = 'slis_t_specialcol_alv'.
        APPEND lw_fldcat TO li_fldcat.
      ENDIF.
    ENDDO.
    * Create dynamic internal table and assign to FS
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = li_fldcat
      IMPORTING
        ep_table        = new_table.
    ASSIGN new_table->* TO <dyn_table>.
    *Create dynamic work area and assign to FS
    CREATE DATA new_line LIKE LINE OF <dyn_table>.
    ASSIGN new_line->* TO <dyn_wa>.
      ASSIGN COMPONENT 'CINFO' OF STRUCTURE <dyn_wa> TO <fs_cinfo>.
    * Color this cell
      lw_cinfo-fieldname = fieldname.
      lw_cinfo-color-col = 6.
      APPEND lw_cinfo TO <fs_cinfo>.
    Message was edited by: Sow Yong Wong

    Hello Sow
    There is a big problem in the program: you are mixing types used for FM-based ALV (SLIS_...) and ABAP-OO based ALV (LVC_...).
    For ABAP-OO based row colouring you have to define your itab like this:
    TYPES: ty_s_outtab.
      INCLUDE TYPE kna1. " just an example
    TYPES: rowcolor(4)  TYPE c.
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab TYPE STANDARD TABLE of ty_s_outtab
                       WITH DEFAULT KEY.
    In the layout (LVC_S_LAYO) you have to set <b>ls_layout-info_fname = 'ROWCOLOR'</b>.
    ROWCOLOR has to be filled according to <b>Cxyz</b> whereas
    - x = color
    - y = inverse on/off
    - z = intensified on/off
    For documentation please refer to <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907">An Easy Reference to ALV Grid Control</a>
    Regards
      Uwe

  • How to use Field-symbol with dynamic select query

    Can anybody tell me, how to use field-symbols in the dynamic select query.

    FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.
    1. ... typing
    2. ... STRUCTURE struc DEFAULT dobj
    The FIELD-SYMBOLS statement declares a field symbol <fs>. The name conventions apply to the name fs. The angle brackets of the field symbols indicate the difference to data objects and are obligatory. You can declare field symbols in any procedure and in the global declaration section of an ABAP program, but not in the declaration section of a class or an interface. You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.
    After its declaration, a field symbol is initial - that is, it does not reference a memory area. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand. Otherwise an exception will be triggered.
    eg.
    FIELD-SYMBOLS <fs> TYPE ANY.
    DATA: BEGIN OF line,
            string1(10) VALUE '0123456789',
            string2(10) VALUE 'abcdefghij',
          END OF line.
    WRITE / line-string1+5.
    ASSIGN line-string1+5(*) TO <fs>.
    WRITE / <fs>.
    output:
    56789
    56789
    reward if helpful
    anju

  • How to access dynamic fields in a field symbol

    hi
    how do i access the dynamic fields created in side a field-symbol....
    wht i mean is i have a table, whose workarea i assign to field symbol. but this table is runtime, altough i have debugged and found the values in this table, I want to accees the field symbol in a generic way.
    say the table has 3 fields now fld1 fld2 and fld3 so i want to access the field symbol <fs> as <fs>-(name) where name can be anything fld1 or fld2 whichever i assign....
    thanks. Let me know if you have any further questions.

    Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.
    Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to a field symbol before you can address it in a program.
    Field symbols are similar to de-referenced pointers in the C programming language (that is, pointers to which the content operator * is applied). In ABAP, data references represent a real equivalent to pointers in the sense of variables that contain a memory address and can be used without the contents operator.
    All operations programmed with field symbols are applied to the field assigned to it. A MOVE statement between two field symbols, for example, assigns the contents of the field assigned to another source field symbol to the field assigned to the target field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before the MOVEstatement.
    You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks during the field assignment whether the assigned field matches the type of field symbol.
    Field symbols provide greater flexibility when you address data objects:
    ·        You can assign one field symbol to another, which allows you to address subfields.
    ·        Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.
    ·        You can also force a field symbol to take different technical properties than those of the field assigned to it (casting).
    The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.
    While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.
    For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. The MOVE statement (with your own auxiliary variables, if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.
    To declare a field symbol, use the statement
    FIELD-SYMBOLS  .
    For field symbols, the angle brackets are part of the syntax. They identify field symbols in the program code.
    If you do not specify any additions, the field symbol.
    in a static ASSIGN and:
    ASSIGN (dobj) TO  from the second loop pass onwards.

  • Building Field Symbols Dynamically

    Hi All,
    Has anyone tried to build field symbols dynamically? something like this...
      DATA: field_symbol(13) TYPE c,
            v_lines          TYPE sy-tabix,
            v_count(2)       TYPE n.
      FIELD-SYMBOLS: <f2> TYPE ANY.
      DESCRIBE TABLE itab LINES v_lines.
      DO v_lines TIMES.
        v_count = v_count + 1.
        CONCATENATE '<fs_new_sf' v_count '>' INTO field_symbol.
        ASSIGN (field_symbol) TO <f2>.
        CONCATENATE '<fs_new_sf' v_count '>' INTO field_symbol.
        ASSIGN (field_symbol) TO <f2>.
        ASSIGN  COMPONENT v_sf01 OF STRUCTURE s_MARA TO <f2>.
      ENDDO.
    V_SF01 could be anything from MATNR to any field in table MARA.
    Although the above code is correct syntactically, and though there is no program termination either.
    the statement
    ASSIGN (field_symbol) TO <f2>.
    fails to assign the field symbol.
    Thanks,
    S-ray

    Hi Sudheer,
    There is a program termination because does not exist a field symbol called <fs_new_sf1> or <fs_new_sf2>... <fs_new_sfn> when you assign (field_symbol) TO <f2>.
    You should look for Dymamic Type specification, something like this:
    DATA: dref TYPE REF TO DATA.
    FIELD-SYMBOLS: <dobject> TYPE any.
    PERFORM declareData USING dref 'SFLIGHT'.
    ASSIGN dref->* to <dobject>.
    FORM declareData USING dref TYPE REF TO DATA
                           tname TYPE string.
    Create a data object of type 'tname'
    CREATE DATA dref TYPE (tname).
    ENDFORM.
    regards,
    Alejandro.

  • How to fill Dynamic work area or field symbol?

    HI All,
    I have created dynamic work area(field symbol) by using following code. Now I want to fill the work area with values which are there in other internal table.
    * Create dynamic internal table/structure
      call method cl_alv_table_create=>create_dynamic_table
        exporting
          it_fieldcatalog = it_fieldcat
        importing
          ep_table        = dyn_table.
      assign dyn_table->* to <fs_table>.
    * Create dynamic work area and assign to Field Symbol
      create data dyn_line like line of <fs_table>.
      assign dyn_line->* to <fs_wa>.
    My <FS_WA> contains:
    ROW1
    ROW2
    ROW3
    ROW4 as fields in it without having any data.
    I have other internal table.. where I have FIELDS and Data like following:
    FIELD1  FIELD2   FIELD3
    ID1 ROW1 A1
    ID1 ROW2 A2
    ID1 ROW3 A3
    ID1 ROW4 A4
    ID2 ROW1 B1
    ID2 ROW2 B2
    ID2 ROW3 B3
    ID3 ROW1 C4
    Important thing that I have to share with you is... Source table of my Internal table and Source structure to create my dynamic table are same.
    This dynamic table has fields... with "FIELD2" values.
    Thanks,
    Naveen.I

    Create a dynamic internal table
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = lt_fcat
        IMPORTING
          ep_table        = lt_dy_table.
    Create dynamic work area and assign to FS
      ASSIGN lt_dy_table->* TO <fs_dyn_table>.
      CREATE DATA lt_dy_line LIKE LINE OF <fs_dyn_table>.
      ASSIGN lt_dy_line->* TO <fs_dyn_wa>.
    Define WA
      CREATE DATA dref TYPE (iv_struc_name).
      ASSIGN dref->* TO <fs_final>.
    Populate dynamic table from the file
      OPEN DATASET iv_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc = 0.
        DO.
          READ DATASET iv_path INTO ls_str.
          IF sy-subrc <> 0.
            ev_failed = abap_true.
            EXIT.
          ENDIF.
          SPLIT ls_str AT ';' INTO TABLE lt_dyn_tab.  " columns
          LOOP AT lt_dyn_tab INTO ls_dyn_tab.
            READ TABLE lt_struc_fld INTO ls_struc_fld INDEX sy-tabix.
            IF sy-subrc EQ 0.
              MOVE ls_struc_fld-fieldname TO ls_fieldname.
              ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_dyn_wa> TO <fs_val>.
              IF sy-subrc = 0.
                <fs_val> = ls_dyn_tab.
              ENDIF.
              ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_final> TO <fs_val>.
              IF sy-subrc = 0.
                <fs_val> = ls_dyn_tab.
              ENDIF.
            ENDIF.
          ENDLOOP.
          APPEND <fs_dyn_wa> TO <fs_dyn_table>.
          APPEND <fs_final> TO et_table.
          UNASSIGN: <fs_val>.
        ENDDO.
      ENDIF.
      CLOSE DATASET iv_path.

Maybe you are looking for