MODIFY ALL LINES IN INTERNAL TABLE

Hi,
How to modify more than one line in an internal table? I tried using update, failed as update is not for internal tables. Your help is appriciated .
thank you,
surya.

To change one or more lines using a condition, use the following statement:
<b>MODIFY itab FROM wa TRANSPORTING f1 f2 ... WHERE cond.</b>
This processes all of the lines that meet the logical condition cond. The logical expression cond can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure. If the table lines are not structured, the first operand can also be the expression TABLE_LINE. The comparison then applies to the entire line. If the line type of the internal table contains object reference variables as component comp or if the entire line type is a reference variable, the attributes of the attr object to which the respective line reference points can be specified as comparison values using comp->attr or table_line->attr.
The work area wa, which must be compatible with the line type of the internal table, contains the new contents, which in turn will be assigned to the relevant table line using the TRANSPORTING addition. Unlike the above MODIFYstatement, the TRANSPORTING addition is not optional here. Furthermore, you can only modify the key fields of the internal table if it is a standard table. If at least one line is changed, the system sets sy-subrc to 0, otherwise to 4.
REPORT demo_int_tables_modify .
DATA: BEGIN OF line,
        col1 TYPE i,
        col2 TYPE i,
      END OF line.
DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.
DO 4 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  INSERT line INTO TABLE itab.
ENDDO.
line-col1 = 2.
line-col2 = 100.
MODIFY TABLE itab FROM line.
LOOP AT itab INTO line.
  WRITE: / line-col1, line-col2.
ENDLOOP.
The list output is:
         1        1
         2      100
         3        9
         4       16
The program fills a hashed table with a list of square numbers. The MODIFY statement changes the line of the table in which the key field col1 has the value 2.
I hope it helps.
Best Regards,
Vibha
*Please mark all the helpful answers

Similar Messages

  • Large line to internal tables from  tab delimited file

    Dear All
    I am trying to upload the large file of tab delimited data into a SAP internal table. I am basically stuck with the fact that there are multiple lines and multiple columns in tab delimited file. There are around 300 columns which are tab delimited and separated
    For e.g  (* indicates tab)
    1material*****************1**9888**********5**********34*********3*********346************************-->upto 5000 columns
    1material*****************1**99338************4***********************************6************7************-->upto 5000 columns
    1material*****************1**22888********************5*********7*********************6*****7**************-->upto 5000 columns
    1material*****************1**44844************************5***5*********************************************-->upto 5000 columns
    1material***********34****1**54*******33********33*****33**************************************************-->upto 5000 columns
    1material*****************1**99888*****************************************************************************-->upto 5000 columns
    below upto 500 rows or more
    I want to read this file into a columner internal table.
    I am trying several ways . I have file on APP server. However Line breaks after 1024 characters or comes on another line.
    Currently I am not able to load it in single line of internal table. The structure of file is dynamic .. not static
    Amol

    Hi Amolsonaikar,
    you may try like this:
    TYPES:
      begin of line,
        t_field type table of string,
      end of line,
      t_line type table of line.
    DATA:
      lt_line  type t_line,
      lv_line type string,
      lt_field type table of string.
    open dataset 'XYZ' for input in text mode encoding default.
    while sy-subrc = 0.
      read dataset into lv_line.
      split lv_line at '|' into lt_field.
      append lt_field to lt_line.
    endwhile.
    Regards,
    Clemens

  • New Line after every 900 lines in internal table

    HI,
    I have an internal table and that is sorted by company code. i.e it is grouped according to company code.
    Now i want to check in particular groups of company code if the lines of internal table is > 900 or not.
    And if it > 900 i have to insert new line.
    How to do that?

    Hi
    Please check  the code..I think it will solve ur problem
    TYPES : BEGIN OF x_data,
             name TYPE char10,
            END OF x_data.
    data: i_data  TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
          wa_data TYPE x_data,
          counter TYPE n LENGTH 2 .
    DO 5 TIMES.
    CLEAR : wa_data.
      counter = counter + 1.
    CONCATENATE 'subha' counter INTO wa_data-name.
    APPEND wa_data to  i_data.
    ENDDO.
    CLEAR : counter,
            wa_data .
    DESCRIBE TABLE i_data LINES counter.
    IF counter > 4.
      counter = 5.
      wa_data-name = 'TEST'.
    INSERT wa_data INTO i_data INDEX counter.
    ENDIF.
    CLEAR: wa_data.
    LOOP at i_data INTO wa_data .
      WRITE : / wa_data-name.
    ENDLOOP.
    Use 900 instead  4 and 901 instead of 5.

  • Question reg. modifying latest record in internal table

    Can you tell me if it is possible to modify the last appended record to the internal table?
    I just want to modify the record in the internal table which is appended at the latest. Please tell me the logic for this.
    Thanks a lot,
    Krishen

    Hi try with this:
    DATA line TYPE I.
    DATA wa_itab TYPE LINE OF it_itab.
    DESCRIBE TABLE IT_TABLE LINE line.
    READ TABLE IT_TABLE INTO wa_itab INDEX line.
    WA_TABLE-FIELD = 'new value'.
    MODIFY TABLE IT_TABLE FROM wa_itab
           TRANSPORTING field.
    Best regards.

  • Modify column in an internal table

    Hi Friends,
    I have an internal table itab1 which has a column called zpo_number .
    I am getting the PO from a BAPI call storing in a field w_ponumber.
    I have the code below . THe table itab1 has rows all having the same matnr .
    How can I modify all the rows of the table with the same w_ponumber ?
    Thanks!
    Loop at itab1
    babpi call get po number
    w_ponumber.
    MODIFY itab1
    endloop.

    simplicity change to your original code provided:
    Loop at itab1
    babpi call get po number
    w_ponumber.
    itab1-z_ponumber  = w_ponumber.
    MODIFY itab1
    endloop.
    Or -
    Loop at itab1
    babpi call get po number
    itab1-z_ponumber.
    MODIFY itab1
    endloop.

  • Dynamically inserting new line in Internal table

    Hi,
      Can anyone help me how to insert a new line dynamically to the internal table.
    Assume there are 5 records that has been added to ITAB.
    In that if a particular field in that ITAB crosses the limit 10 then i have to split that line into two lines with the same data except that Par.field as 5 and the other record has 5.
    In the third record that particular field has value 10.
    Loop at ITAB.
       Once i found that field has 10 then how to insert a new line dynamically over here to add another record.
    endloop.

    Hi..
    Hi..
    try this..
    loop at itab.
    if  ( i found that field <f1> has 10 ).
        w_line2 = itab-f1+5(5).
        w_line3 = itab-f1.
    ***********First  line********   
        itab-f1 = itab-f1+0(5).
        modify itab index sy-tabix from itab transporting f1.
    ***********second  line********    Hi..
    try this..
    loop at itab.
    if  ( i found that field <f1> has 10 ).
        w_line2 = itab-f1+5(5).
        w_line3 = itab-f1.
    ***********First  line********   
        itab-f1 = itab-f1+0(5).
        modify itab index sy-tabix from itab transporting f1.
    ***********second  line********   
        itab-f1 = w_line2.
        insert itab INDEX SY-TABIX.
    **********third line**************
        itab-f1 = w_line3.
         insert itab INDEX SY-TABIX.
    endloop.  
        itab-f1 = w_line2.
        insert itab INDEX SY-TABIX.
    **********third line**************
        itab-f1 = w_line3.
         insert itab INDEX SY-TABIX.
    endloop.

  • Efficiently deleting lines from internal table based on column comparison

    Hi all,
    let's assume, I have the following internal table MY_TAB:
    COL_1 | COL_2 | COL_3
    A       1       1
    B       2       2
    C       3       3
    D       3       4
    E       3       5
    I'd like to delete all rows, where the values in COL_2 and COL_3 are equal. That is, in the above table, the rows for A, B and C.
    What's the most performant / fastest and efficient way to do this?
    Thanks for any hints in advance!
    Best regards,
    Philipp

    I do not understand other proposal.
    The are two solutions possible
    LOOP AT itab INTO wa.
       IF ( wa-col2 = wa-col3).
         DELETE itab INDEX sy-tabix.
       ENDIF.
    ENDLOOP.
    If memory is not an issue and if many lines are to be deleted, then the APPEND in a new table is better.#
    I would use that one in all cases where the conditions are complicated.
    LOOP AT itab INTO wa.
       IF ( wa-col2 <> wa-col3).
         APPEND wa TO itab2.
       ENDIF.
    ENDLOOP.
    refresh itab.
    itab[] = itab2[].
    Siegfried

  • All values in internal table are not displaing in the script print program

    Hi,
    I am calling the script program.In main window all values in the internal table are not displaying. I wrote
    write-form statement in loop. But not all the values are getting displayed. Only thel ast values getting dispalyed. 
    *& Report  ZSCRIPT_116719
    REPORT  ZSCRIPT_116719.
    ************Table decleration***************
    TABLES: mara, mbew, makt.
    loop at i_makt into wa_makt.
      endloop.
    loop at i_MARA into wa_mara.
      endloop.
    LOOP AT I_MBEW INTO WA_MBEW.
      ENDLOOP.
    lv_price = 0.
    ********************Total Price******************
      LOOP AT i_mbew INTO wa_mbew.
        lv_price = lv_price + wa_mbew-stprs.
      ENDLOOP.
    end-of-selection.
    CALL FUNCTION 'OPEN_FORM'
    EXPORTING
      APPLICATION                       = 'TX'
      ARCHIVE_INDEX                     =
      ARCHIVE_PARAMS                    =
      DEVICE                            = 'PRINTER'
      DIALOG                            = 'X'
       FORM                              = 'ZSCRIPT_719'
       LANGUAGE                          = SY-LANGU
      OPTIONS                           =
      MAIL_SENDER                       =
      MAIL_RECIPIENT                    =
      MAIL_APPL_OBJECT                  =
      RAW_DATA_INTERFACE                = '*'
      SPONUMIV                          =
    IMPORTING
      LANGUAGE                          =
      NEW_ARCHIVE_PARAMS                =
      RESULT                            =
    EXCEPTIONS
       CANCELED                          = 1
       DEVICE                            = 2
       FORM                              = 3
       OPTIONS                           = 4
       UNCLOSED                          = 5
       MAIL_OPTIONS                      = 6
       ARCHIVE_ERROR                     = 7
       INVALID_FAX_NUMBER                = 8
       MORE_PARAMS_NEEDED_IN_BATCH       = 9
       SPOOL_ERROR                       = 10
       CODEPAGE                          = 11
       OTHERS                            = 12
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'START_FORM'
    EXPORTING
      ARCHIVE_INDEX          =
       FORM                   = 'ZSCRIPT_719'
       LANGUAGE               = SY-LANGU
      STARTPAGE              = ' '
       PROGRAM                = 'ZSCRIPT_116719'
      MAIL_APPL_OBJECT       =
    IMPORTING
      LANGUAGE               =
    EXCEPTIONS
      FORM                   = 1
      FORMAT                 = 2
      UNENDED                = 3
      UNOPENED               = 4
      UNUSED                 = 5
      SPOOL_ERROR            = 6
      CODEPAGE               = 7
      OTHERS                 = 8
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    *LOOP AT I_MBEW INTO WA_MBEW.
    CALL FUNCTION 'WRITE_FORM'
    EXPORTING
       ELEMENT                        = 'DATA'
       FUNCTION                       = 'SET'
       TYPE                           = 'BODY'
       WINDOW                         = 'MAIN'
    IMPORTING
      PENDING_LINES                  =
    EXCEPTIONS
       ELEMENT                        = 1
       FUNCTION                       = 2
       TYPE                           = 3
       UNOPENED                       = 4
       UNSTARTED                      = 5
       WINDOW                         = 6
       BAD_PAGEFORMAT_FOR_PRINT       = 7
       SPOOL_ERROR                    = 8
       CODEPAGE                       = 9
       OTHERS                         = 10
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    *ENDLOOP.
    If I give only one value it is showing the output. When I am fetching the data for range of values it i sshowing start_form is not there.
    Plz let me know how to get the aa  internal table values  to be displayed

    hi
    I shortened your program a bit. So we can go to essentials of your question.
    You said you put in it in a loop.
    What i see in your prog is:
    REPORT zscript_116719.
    ************table decleration***************
    TABLES: mara, mbew, makt.
    LOOP AT i_makt INTO wa_makt.
    ENDLOOP.
    LOOP AT i_mara INTO wa_mara.
    ENDLOOP.
    LOOP AT i_mbew INTO wa_mbew.
    ENDLOOP.
    lv_price = 0.
    ********************total price******************
    LOOP AT i_mbew INTO wa_mbew.
      lv_price = lv_price + wa_mbew-stprs.
    ENDLOOP.
    END-OF-SELECTION.
      CALL FUNCTION 'OPEN_FORM'
        EXPORTING
          form     = 'ZSCRIPT_719'
          language = sy-langu.
      CALL FUNCTION 'START_FORM'
        EXPORTING
          form     = 'ZSCRIPT_719'
          language = sy-langu
          program  = 'ZSCRIPT_116719'.
    *LOOP AT I_MBEW INTO WA_MBEW.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element  = 'DATA'
          function = 'SET'
          type     = 'BODY'
          window   = 'MAIN'.
    *endloop.
    1. Your loop is not a loop with this '*' in front of it.
    2. Are you printing &wa_mbew-???& variables in your sap-script
    3. is itab I_MBEW properly filled
    Let me know.
    Gr. Frank

  • Delete lines from internal table

    Hello experts!
    I have two internal tables.
    select options sa_tknr and gt_versand_plan.
    sa_tknr-low contents transportation-Nr.
    gt_versand_plan has transportation-Nr too (gt_versand_plan-tknum).
    How can I delete all transportation-Nr from
    gt_versand_plan which dont' appear in sa_tknr-tknum.
    THX
    sas

    Hi
    check this statement.
    <b>delete gt_versand_plan where not tknum in sa_tknr.</b>
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • Inserting blank line in internal table

    Hi
    I am inserting a report  from a internal table for eg the content of my internal table is
    data : abc
    event initialization.
    perform read_data.
    Now I want  1 blank line after every line in the internal table for eg
    data:abc
    event initialization
    perform read_data.
    How to insert a blank line in an internal table?
    Edited by: priya singh on Feb 4, 2009 9:37 AM

    hi,
    DATA: BEGIN OF i_pernr OCCURS 1 ,
    pernr TYPE pa0002-pernr,
    vorna TYPE pa0002-vorna,
    nachn TYPE pa0002-nachn,
    END OF i_pernr.
    TYPES : BEGIN OF string1  ,
         a TYPE char100,
        END OF string1.
    DATA : wa_string TYPE string1,
           it_stirng TYPE TABLE OF string1.
    START-OF-SELECTION.
      SELECT pernr vorna nachn FROM pa0002 INTO TABLE i_pernr UP TO 20 ROWS.
      LOOP AT i_pernr.
        CONCATENATE i_pernr-pernr i_pernr-vorna i_pernr-nachn INTO wa_string-a SEPARATED BY '|'.
        APPEND wa_string TO it_stirng.
        APPEND INITIAL LINE TO it_stirng.
      ENDLOOP.
      BREAK-POINT.
    Thanks

  • Unicode error:a line of internal table and a data object are not mutually c

    Hi Friends,
        This is the issue in upgradation from 4.6c to ECC6.0
        I have an internal table itab which has include structure say 'xyz' . In xyz there is a field of type int4 as third field. I have a field as l_line which is a string.
    data : begin of itab occurs 0.
             include structure zxyz.
    data: end of itab.
    data: l_line type string.
    In the program I am getting the unicode error as:
    " A line of "itab" and "l_line" are not mutually convertible in unicode program." at he following line.
    loop at itab into l_line.
    endloop.
    Thanks,
    Ali.

    Hi Narendran,
    I did the same earlier, but the field l_line is again used in the another line as follows
    IF l_line CS w_group.----
    (1)
    where     w_group         LIKE zstr-cctr_group.
    here zstr-cctr_group is same as one of the fields of structure xyz.
    in line 1 it is giving warning as
    l_line is incompatible and it must be C,N,D,T or string.
    Thanks,
    Ali

  • ASSIGN to add new lines to internal tables

    Hello,
    within our code, I have found several occurrences of the obsolete ASSIGN LOCAL COPY which I would like to replace with up-to-date coding. Particularly, we have the following code segment:
    DATA: ct_table TYPE INDEX TABLE.
    FIELD-SYMBOLS: <ls_new_row> TYPE ANY,
                   <lv_field>   TYPE ANY.
    ASSIGN LOCAL COPY OF INITIAL LINE OF ct_table TO <ls_new_row>.
    ASSIGN COMPONENT '1' OF STRUCTURE <ls_new_row> TO <lv_field>.
    <lv_field> = ...
    ASSIGN COMPONENT '2' OF STRUCTURE <ls_new_row> TO <lv_field>.
    <lv_field> = ...
    INSERT <ls_new_row> INTO TABLE ct_table.
    What is the most efficient non-obsolete code equivalent for this?
    --Florian

    You might also use the command INSERT INITIAL LINE INTO TABLE itab ASSIGNING <fs>.
    You will encounter problems with this solution if the internal table has key components as the system will not allow you to change these in this setup after the insertion.

  • Modify the structure of internal table which created dynamically!!!

    HI All,
    I am creating internal table dynamically using the below syntax.  Now I need to remove few of the fields from the internal table structure. Could you please help me how to go ahead in these cases?
    * Create table dynamically for local data
      CREATE DATA gv_table_l TYPE TABLE OF (<fs_tabname>).
      CREATE DATA gv_wa_l    TYPE (<fs_tabname>).
      ASSIGN gv_table_l->*   TO <fs_local_tab>.
      ASSIGN gv_wa_l->*      TO <fs_local_wa
    >.
    Please let me know if you have any thoughts.
    Thanks,
    Raghu.

    Hi ,
    check this wiki
    [Internal Table|http://wiki.sdn.sap.com/wiki/display/Snippets/Howtocreateinternaltable+dynamically]
    in your case ...
    1.Get filed list based on the type ...make use of  "cl_abap_datadescr=>describe_by_type('MARA'), check for syntax or sample programs...
    2.Delete fields which you dont want to be in your internal table....
    3.Create internal table using method " CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE" ref attached link for sample code by Pinaki...
    regards
    Prabhu

  • Regarding passing of the modified data back to internal table form alv

    Hi,
       My requirement is i hav a fld in my alv grid checkbox which iam checking when i output the list on the alv grid and I hav to execute an action on all the checked rows the poblem is even iam checking the checkbox it is not being passed back to internal table.I hav used methods to create and display alv grid.This is really urgent can anyone provide any inf on this .
    Thanks and Regards,
    Rajashree

    Hello Tathagata,
    I have a similar problem.
    I need to react on a change of an input-field of the
    grid-control.
    When i call the method "->check_changed_data"
    i allways get e_valid == 'X'.
    The problem is, i have to react in any case, when the
    user presses <ENTER> and if the user has changed
    a field-entry, i have to read additional data
    and store it into the internal datarow of
    the grid-table.
    I have'nt found an event like "ON DATA CHANGED" ...
    How can i solve this problem.
    Thank You very much in advance
    Michael

  • Urgent : How to modify the line type and table type

    I am working on ALV Grid Control, i need to know how to modify the line type values to table type.
                 ls_celltab-fieldname = 'ZSAVINGS '.
                 ls_celltab-style = l_mode.
            INSERT ls_celltab INTO TABLE pt_celltab.
    Here ls_celltab is line type and pt_celltab is table type.
    Please give me the suggestion ASAP.
    C.Bharath Kumar

    Hi,
    Here is the example
    DATA: BEGIN OF LINE,
            LAND(3)  TYPE C,
            NAME(10) TYPE C,
            AGE      TYPE I,
            WEIGHT   TYPE P DECIMALS 2,
          END OF LINE.
    DATA ITAB LIKE SORTED TABLE OF LINE
              WITH NON-UNIQUE KEY LAND NAME AGE WEIGHT.
    LINE-LAND = 'G'.   LINE-NAME   = 'Hans'.
    LINE-AGE  = 20.    LINE-WEIGHT = '80.00'.
    INSERT LINE INTO TABLE ITAB.
    LINE-LAND = 'USA'. LINE-NAME   = 'Nancy'.
    LINE-AGE  = 35.    LINE-WEIGHT = '45.00'.
    INSERT LINE INTO TABLE ITAB.
    Regards
    Sudheer

Maybe you are looking for

  • Error in Executing UTL_FILE package

    I have following procedure DECLARE v_FileHandle UTL_FILE.FILE_TYPE; BEGIN -- Open the file /tmp/utl_file.txt for writing. If the -- file does not exist, this will create it. If the file -- does exist, this will overwrite it. v_FileHandle := UTL_FILE.

  • WSSecurity on Dynamic EndpointReference URL in BPEL

    BPEL version 1.1 SOA Suite 11.1.1.6 AIA 3.0 I am trying to invoke R12 SOA gateway service using dynamic endpoint reference within my bpel code. <binding.*location*> in composite.xml is removed. I am constructing ws-security header xml inside bpel and

  • RSS feed generation with CRM data

    Hi folks, I got a question from my customer if RSS feed generation is possible with CRM data. He thinks about a scenario where for example an Intranet user can subscribe a RSS feed that provides information if certain CRM data changed, eg. a new Busi

  • Create New Project and put photo in from another project folder

    This is what I thought was going to be a relative task. Move a batch of photos from one project folder into another new empty one. I can highlight and select the photos in question and select Edit and Copy. Go to new project folder,but No Paste funct

  • Laptop squealing/chirping noise

    My product number is E1P05AV. I've had this laptop for almost a year now and have had the hard drive replaced because I thought that it was the cause of this sound. As of right now I have an ssd, so I know that it is not the culprit. I've done some r