Field Symbol Code.docx

Embed Size (px)

Citation preview

  • 7/29/2019 Field Symbol Code.docx

    1/3

    m working on field symbols in the abap program. I am trying to modify the records of the internal table. I aw to field pointers and going to through several threads, add the code in the program but not getting thesired results. I would appreciate your help in this regard.

    ere is the code..

    ta: begin of dept_itab occurs 0,deptid like p0001-kostl,pstl2 like csks-pstl2,end of dept_itab.

    d-symbols: like line of dept_itab.

    e dept_itab table is populated then, few dept records have the record PSTL2 value to be updated. I am trying to do u

    ld pointers.

    op at dept_itab assigning .

    select single * from csks where kostl = dept_itab-deptid.

    -deptid = dept_itab-deptid.-pstl2 = csks-pstl2.

    append . ??? how to append the record in the field symbol - Error heredloop.

    en I need to store the updated records back to dept_itab.

    ence I added..fresh dept_itab.sing dept_itab to ove to dept_itab.

    ow to correct this? It has large number of records and to improve the perormance I am applying this tech

    not dept_itab[] is initial.lect * from csks into table i_csks " Here still we have performance issue, ve key of

    for all entries in dept_itab " kokrs, kostl datbi but you only key kowhere kostl = dept_itab-deptid.

    dif.

    rt i_csks by kostl.

    op at dept_itab assigning .ad table i_csks with key kostl = -deptid binary search

    sy-subrc eq 0.s_dept>-deptid = dept_itab-deptid.s_dept>-pstl2 = csks-pstl2.modify dept_itab from .dif.dloop.

    field-symbol is a pointer to a place in memory and can be used instead of an explicit workarea. In the followatements, the two LOOP AT statements achieve the same result.

    DATA: ls_structure TYPE ts_structure.

  • 7/29/2019 Field Symbol Code.docx

    2/3

    FIELD-SYMBOLS: TYPE ts_structure.

    With a workarea, we must move the workarea changes

    ack into the tableLOOP AT lt_table_1 INTO ls_structure.ls_structure-field_1 = 'X'.MODIFY lt_table_1 FROM ls_structure.

    ENDLOOP.

    With a field-symbol, we are directly changing the

    able field

    LOOP AT lt_table_2 ASSIGNING .-field_1 = 'X'.

    ENDLOOP.

    ccess Using Field Symbols

    en you read table entries using READ or in a LOOP, you can assign them to a field symbol using the addition

    ... ASSIGNING

    e field symbol points directly to the assigned line in memory. Unlike work areas, in which the contents of the line are onlyailable indirectly, field symbols allow you to read and change table entries directly.

    member when you access internal tables using field symbols that you must not change the contents of the key fields of sortedshed tables. If you try to assign a new value to a key field using a field symbol, a runtime error occurs. Note that you cannot usM statement with field symbols, since the statement is always applied to work areas.

    dvantages of Field Symbols

    en you read from an internal table, there are no overheads for copying the table line to the work area. When you change an ile with the MODIFY statement, you must first fill a work area with values, and then assign them to the internal table. If you wod symbols instead, you do not have this overhead. This can improve performance if you have large or complex internal tableskes it easier to process nested internal tables .

    verheads of READ

    te that internal overheads arise when you access internal tables using field symbols. After a READ statement with a field symstem has to register the assignment. When you delete a table line to which a field symbol is pointing, the system also has toassign the field symbol to prevent it from pointing to an undefined area.

    en you read individual table lines, it is worth using field symbols with the READ statement for tables with a line width of 1000 more. If you also change the line using the MODIFY statement, using field symbols is worthwhile from a line width of 100 bytewards.

    verheads of LOOPminimize the overheads incurred by using field symbols in loop processing, the system does not register the assignment of erent line to the field symbol. Instead, it registers a general assignment between a line of the table and the field symbol. When p is finished, the line processed in the last loop pass is assigned to the field symbol.

    nsequently, it is worth using field symbols in a LOOP when the internal table has as few as 10 lines. However, it is not possibssign the field symbol to another field or unassign it altogether within the loop. If you include the statements ASSIGN, UNASSthe ASSIGNING addition for the same field symbol within the loop block, a runtime error occurs.

    xample

    http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3605358411d1829f0000e829fbfe/frameset.htmhttp://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3605358411d1829f0000e829fbfe/frameset.htm
  • 7/29/2019 Field Symbol Code.docx

    3/3

    DATA: BEGIN OF LINE,COL1 TYPE I,COL2 TYPE I,

    END OF LINE.

    DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.

    FIELD-SYMBOLS LIKE LINE OF ITAB.

    DO 4 TIMES.LINE-COL1 = SY-INDEX.LINE-COL2 = SY-INDEX ** 2.

    APPEND LINE TO ITAB.ENDDO.

    READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING .-COL2 = 100.

    READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING .DELETE ITAB INDEX 3.

    IF IS ASSIGNED.WRITE ' is assigned!'.ENDIF.

    LOOP AT ITAB ASSIGNING .WRITE: / -COL1, -COL2.ENDLOOP.

    The output is:

    1 1

    2 100

    4 16

    The example fills a sorted table ITAB with 4 lines. The second line is assigned to the field symbol (which hsame type), and modified using it. The third line is assigned to and then deleted. Consequently, the logicalexpression in the IF statement is untrue. is used to display the table lines in the LOOP. Afterwards, it pointhe third line of the table.