Updating internal table in loop

Hi All,
UID  GRP1  GRP2 UPD1
001     1         1     1
001    1          2     2
001    1          3     3
001    2          4     1
002    1         3      1
002    1         2      2
003    1         4      1
004    1        1      1
004    2        2      1
004    2        5       2
I have a requirement where I have an internal table it_data with four fields UID, GRP1, GRP2 and UPD1
so now the requirement is based on UID and GRP1 the UPD1 field will be updated, so for same UID and for the same GRP1 all the UPD1 will be incremented like 1, 2, 3 and so on..
so in the above example, for UID 001 and GRP1 1 the UPD1 is updated as 1
then for the same UID and the same GRP 1 i.e. 1 the UPD1 will be incremented to 2 and so on.
then for the same UID but for the different/new GRP1 the UPD field will start from 1 again and so on.
I am not able to write the loop statement for this req.

You may try the following code. I cannot check it at the moment, but you should catch the idea.
FIELD-SYMBOLS <l_fs_data> LIKE LINE OF it_data.
DATA:
       l_index TYPE i,
       l_uid   LIKE it_data-uid,
       l_grp   LIKE it_data-grp1.
SORT it_data BY uid grp1.
LOOP AT it_data ASSIGNING <l_fs_data>.
   IF l_uid IS INITIAL OR l_grp IS INITIAL
     OR l_uid NE <l_fs_data>-uid OR l_grp NE <l_fs_data>-grp1.
     l_index = 1.
   ELSE.
     ADD 1 TO l_index.
   ENDIF.
   l_uid = <l_fs_data>-uid.
   l_grp = <l_fs_data>-grp1.
   <l_fs_data>-upd1 = l_index.
ENDLOOP.

Similar Messages

  • Is it possible to update internal table from database table

    Hello All:
              I know how to update database table from internal table in one shot (batch) but is the reverse possible? Can I update some fields in an internal table from a database table in one shot (without looping) because my internal table is huge? Could you please provide me any ideas how to acheive something like this? Thanks in advance and answers will be rewarded.
    thanks.
    Mithun

    Hello my friend,
    You can do it MAYBE , i think you can reverse the update doing a ROLLBACK, but only after you update....not after the program finishes..
    To update some fields at once use:
    UPDATE DBTABLE FROM TABLE IT_TABLE
    Hope this helps!!
    Gabriel

  • Updating internal table with CSV file

    I have a flat file as below:
    aaaa, bbbb, asdc, dfgfhg, sdfsg, sdf, sdf, sdf, dfg, sdf, sgf, drgftfgh, sgf, drgtf, swftgd, sgf,
    'sjhdfjhf','2003-10-11 07:52:37','167','alkjd',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'dkjffdj ,',NULL,NULL,NULL,'1',NULL,NULL,'AR, dfkj ',
    Where we can see it is separated by commas.I want to upload this one into onr internal table.I used GUI_UPLOAD and gave the logic as folows:
    TYPES: BEGIN OF ttab,
    rec(1000) TYPE c,
    END OF ttab.
    TYPES: BEGIN OF tdat,
    aaaa type char10
    bbbb type char10,
    asdc  type char10,
    dfgfhg  type char10,
    sdfsg  type char10,
    sdf  type char10,
    sdf  type char10,
    sdf  type char10,
    dfg   type char10,
    sdf    type char10,
    sgf  type char10,
    drgftfgh  type char10,
    sgf  type char10,
    drgtf  type char10,
    swftgd  type char10,
    sgf  type char10,
    END OF tdat.
    DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.
    DATA: idat TYPE TABLE OF tdat WITH HEADER LINE.
    DATA: file_str TYPE string.
    PARAMETERS: p_file TYPE localfile.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    static = 'X'
    CHANGING
    file_name = p_file.
    START-OF-SELECTION.
    file_str = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = file_str
    TABLES
    data_tab = itab
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    LOOP AT itab.
    CLEAR idat.
    SPLIT itab-rec AT ',' INTO idat-aaaa
    idat-bbbb ,
    idat-asdc  ,
    idat-dfgfhg  ,
    idat-sdfsg  ,
    idat-sdf  ,
    idat-sdf  ,
    idat-sdf  ,
    idat-dfg   ,
    idat-sdf    ,
    idat-sgf  ,
    idat-drgftfgh  ,
    idat-sgf  ,
    idat-drgtf  ,
    idat-swftgd  ,
    idat-sgf  ,
    APPEND idat.
    ENDLOOP.
    Now the issue is when I use the statement SPLIT itab-rec AT ',' this is not updating the table idat properly.Because the flat file contains the value as 'dkjffdj ,', too.
    Can anyone give me some solution to update the internal table.

    hI
    or you delete ' from csv file before uploading it or after uploading it, in this last case u can use statament replace:
    REPLACE ''' WITH SPACE INTO ITAB-FIELD.
    Max

  • ALV GRID update internal table

    Hi all,
    I have an internal table display in a ALV GRID. Only one column is editable. When I change the field value, ALV GRID display the change, but when I click on refresh return the old value.
    I've checked in DEBUG mode and when I click on refresh (in the PAI module), the internal table haven't data modified.
    For example: the field qta have value 15. I change it in 18 and then press Refresh. In debug, the field qta still have the value 15.
    What I have to do?

    Hi
    The Example prg is using Classes, then you need to use the same approach in the way i mentioned below...
    You need to Update the ITAB with the Modifeid values.
    *       CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION .
      PUBLIC SECTION .
        METHODS:
    **Handler to Check the Data Change
        HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED
                             OF CL_GUI_ALV_GRID
                             IMPORTING ER_DATA_CHANGED
                                       E_ONF4
                                       E_ONF4_BEFORE
                                       E_ONF4_AFTER.
    ENDCLASS.                    "lcl_event_handler
    DEFINITION
    **Handle Data Change
      METHOD HANDLE_DATA_CHANGED.
        DATA: X_CHANGE TYPE LVC_S_MODI,
              X_FINAL TYPE T_FINAL,
              X_OCRC TYPE ZSD_OC_HOLD,
              L_FLAG.
        LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO X_CHANGE.
          IF X_CHANGE-FIELDNAME = 'ZZOCHOLDRC'.
            READ TABLE IT_FINAL INTO X_FINAL INDEX X_CHANGE-ROW_ID.
            IF SY-SUBRC = 0.
              READ TABLE IT_OCRC INTO X_OCRC WITH KEY
                                             ZZOCHOLDRC = X_CHANGE-VALUE
                                            TRANSPORTING ZZRCDESC.
              IF SY-SUBRC = 0.
                X_FINAL-ZZRCDESC = X_OCRC-ZZRCDESC.
                MODIFY IT_FINAL FROM X_FINAL INDEX X_CHANGE-ROW_ID
                                             TRANSPORTING ZZRCDESC.
                L_FLAG = 'X'.
              ENDIF.
            ENDIF.
          ENDIF.
          IF X_CHANGE-FIELDNAME = 'ZZPROMDT'.
            READ TABLE IT_FINAL INTO X_FINAL INDEX X_CHANGE-ROW_ID.
            IF SY-SUBRC = 0.
              X_FINAL-ZZPROMDT = X_CHANGE-VALUE.
              MODIFY IT_FINAL FROM X_FINAL INDEX X_CHANGE-ROW_ID
                                           TRANSPORTING ZZPROMDT.
              L_FLAG = 'X'.
            ENDIF.
          ENDIF.
        ENDLOOP.
        IF L_FLAG = 'X'.
          CLEAR V_DATA_CHANGE.
          V_DATA_CHANGE = 'X'.
        ENDIF.
      ENDMETHOD.                    "data_changed
    **you need to SET the HANDLER after the method first display.
      CREATE OBJECT G_HANDLER.
      SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.
    try this
    vijay

  • Updating internal table in dynamic way

    Hi,
    I want to update one internal table dynamically.I have two internal table.
    One internal table has the records which are field names of the 2nd internal table.
    suppose:
    Itab1 is as follows:
    F1                                           F2
    aaa                                        bbb
    Itab2 as follows:
    aaa                         bbb
    This means the ITAB1 records are the fields of ITB1.Now I want to update ITAB2 when I found ITAB1-F1 is the field of ITAB2 dynamically.
    Can anyone give some code hint to do so.

    you can use below code for this. I write it in notepad some changes may be necessary.
    data: lv_c(30).
    field-symbols: <f1> type any.
    loop at itab1.
    concatenate 'itab2' itab1-fieldname into lv_c.
    assign (lv_c) to <f1>.
    if assign successful this means this field exists
    if sy-subrc = 0
    move value to <f1>.
    *modify itab2.
    endif.
    endloop.
    Edited by: Gungor Ozcelebi on Jul 1, 2009 3:37 PM

  • Multiple checkbox selection in ALV and updating internal table

    Dear Expert,
    Can anyone tell me how to handle the multiple checkbox selection in ALV Grid report and then updating the internal table.
    I tried the option but it works only when i select only 1 row in ALV.
                    DO L_LINES TIMES.
                      read table icoas index rs_selfield-tabindex.
                      if sy-subrc = 0.
                        ICOAS-NOCHK = 'X'.
                        modify ICOAS INDEX rs_selfield-tabindex TRANSPORTING NOCHK.
                      ENDIF.
                    ENDDO.
    Requires help....
    Regards & Thanx,
    Bhupathi.

    Hi,
    Use this method to capture the check box event. Write this once you create your grid using CREATE OBJECT grid1.
    DATA:      GRID1 TYPE REF TO CL_GUI_ALV_GRID,
    CALL METHOD grid1->register_edit_event
      EXPORTING
        i_event_id = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
      EXCEPTIONS
        ERROR      = 1
        others     = 2
    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 T_GRIDDETAILS INTO WA_GRIDDETAILS.
        IF WA_GRIDDETAILS-CHECKBOX = 'X'.
                  "Do your operation
        ENDIF.
        CLEAR WA_GRIDDETAILS.
      ENDLOOP.

  • Update internal table data from table control

    Hi GURUS,
    I need help regarding one of my requirement.
    I need to display data from the internal table on the screen and when the user selects a record/multiple records from screen and clicks on approve button i need to update one of the field from N to Y in the corresponding Ztable. Once the record is updated from Ztable , that should no longer be visible for the user on the screen.
    I am using table control wizard to display data. I am able to update the Ztable, but that record is not refreshing from the user screen. Any suggestions would be approved.
    Also please let me know if table control is the best way to do this/ alv grid control??

    hi
       REFRESH CONTROL Control-Name FROM SCREEN '0100'  -> use this command to refresh the table control
    to know more, read into
    https://forums.sdn.sap.com/click.jspa?searchID=2934287&messageID=673474
    Re: URGENT HELP REQ IN TABLE CONTROL WIZARD
    if helpful, reward
    Sathish. R

  • Question in ABAP syntax, read & insert data from internal table, while loop

    Hi, SDN Fellow.
    I am from Java background and learnt ABAP, I don't usually write much ABAP code.
    I am trying to implement the following logic in a RFC now.
    I have one z-custom database table, the structure as the following:
    It has two columns, with these sample data.
    Says datable table is ZEMPMGRTAB.
    EmployeeID,ManagerID
    user10,user1
    user9,user1
    user8,user1
    user7,user2
    user6,user2
    user5,user2
    user4,user2
    user2,user1
    The logic is this:
    I have a input parameter, userid. I am using this parameter to have a select statement to query the record into export table,EXPTAB 'LIKE' table ZEMPMGRTAB.
    SELECT * FROM  ZEMPMGRTAB
      into table EXPTAB
       WHERE  EMPLOYEEID  = USERID.
    Say, my parameter value, USERID ='USER4'.
    Referring to the sample data above, I can get the record of this in my EXPTAB,
    EmployeeID,ManagerID
    user4,user2
    Now, I want to iterately use the EXPTABLE-ManagerID
    as the USERID input in SELECT statement, until it has no return result. Then, insert the new records in
    EXPTAB.
    In above new loop case, we will get this table content in EXPTAB,
    EmployeeID,ManagerID
    user4,user2
    user2,user1
    I kind of think of the pseudocode logic as below:
    (These may not be a valid ABAP code, so I need help to convert/correct them)
    DATA:
    IWA TYEP ZZEMPMGRTAB,
    ITAB
    HASHED TABLE OF ZZEMPMGRTAB
    WITH UNIQUE KEY EMPLOYEEID.
    SELECT * FROM  ZEMPMGRTAB
      into table ITAB
       WHERE  EMPLOYEEID  = USERID.
    *Question 1: I cannot insert a internal table to export table, it is *incompatible type, what is the alternative way fo this?
    *Question 2: How can I access thedata of the internal table like this,ITAB-MANAGERID? As if I can, I would do this:
    * IWA-EMPLOYEEE = ITAB-EMPLOYEEID. IWA-MANAGERID = IWA-MANAGERID. INSERT IWA INTO TABLE EXPTAB.
    * Question 3: Is the 'NE NULL' - 'not equal to NULL' is right syntax?
    IF ITAB NE NULL.
    INSERT ITAB INTO EXPTAB.
    ENDIF
    * Question 4: Is my WHILE loop setup right here? And are the syntax right?
    WHILE ITAB NE NULL.
    SELECT * FROM  ZEMPMGRTAB
      into table ITAB
       WHERE  EMPLOYEEID  = ITAB-MANAGERID.
    IF ITAB NE NULL.
    INSERT ITAB INTO EXPTAB.
    ENDIF
    REFRESH ITAB.
    ENDWHILE.
    Assume all the syntax and logic are right, I should get this result:
    EmployeeID,ManagerID
    user4,user2
    user2,user1
    If I have a new entry in datable table,ZEMPMGRTAB like this:
    user1,user0
    My pseudocode logic will get this result:
    EmployeeID,ManagerID
    user4,user2
    user2,user1
    user1,user0
    I truly appreciate if you can help me to validate the above syntax and pseudocode logic.
    Thanks in advance.
    KC

    Hi,
    FUNCTION ZGETSOMEINFO3.
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(USERID) TYPE  AWTXT
    *"     VALUE(FMTYPEID) TYPE  AWTXT
    *"  EXPORTING
    *"     VALUE(RETURN) TYPE  BAPIRETURN
    *"  TABLES
    *"      APPROVERT STRUCTURE  ZTAB_FMAPPROVER
    *"      ACTOWNERT STRUCTURE  ZTAB_FMACTOWNER
    DATA: T_RESULT TYPE STANDARD TABLE OF ZTAB_FMAPPROVER.
    **Question 1: For this line, I got an error says "Program ''USERID" *not found. Is the syntax right, as the USERID is a parameter for the function.
    perform add_line(USERID).
      ENDFUNCTION.
    form add_line using i_user type ZTAB_FMAPPROVER.EMPLOYEEID
                        changing T_RESULT TYPE ZTAB_FMAPPROVER.
    data: ls_row type ZTAB_FMAPPROVER.
    * Get record for i_user
    select single * into ls_row from ZTAB_FMAPPROVER
    where EmployeeID = i_user.
    if sy-subrc NE 0.
    * Do nothing, there is not manager for this employee
    else.
    * Store result
    QUESTION 2: I am still got stuck on this line of code. It still *says that "T_RESULT" is not an internal table "OCCURS n" *specification is missing. I thought the line: "T_RESULT TYPE *ZTAB_FMAPPROVER" means declare internal table, T_RESULT as type of ZTAB_FMAPPROVER". Am I understand it wrongly?
    append ls_row to t_result.
    * Call recursion
    perform add_line using ls_row-ManagerID
                              changing t_result.
    endif.
    endform.
    Thanks,
    KC

  • Grid with classes not updating Internal Table

    Hi everyone
    I´m developing a Grid with classes.
    The first field in the Grid is a checkbox, I want it to response like a User action when I select or deselect it, but it´s not working. The Internal Table data isn´t updating the info in this field.
    Can someone give me some light please??
    Also I´m thinking in Add a Button like a Submit, so when the user clicks it I can get the last data captured in all fileds. Do you think it may be better??
    Thanks in advanced.
    Emmanuel

    Welcode to SCN
    Please check this link

  • Update internal table.

    Hi Gurus.
    I have a program MODULE POOL and he call ALV OO.
    PROCESS BEFORE OUTPUT.
       MODULE status_9400.
       MODULE inicializa_dados_9400.
       MODULE set_alv_atributos_9400.
       MODULE inicia_objetos_9400.
       MODULE show_alv_9400.
    PROCESS AFTER INPUT.
       MODULE user_command_9400.
       MODULE exit_command_9400 AT EXIT-COMMAND.
    *&      Module  SHOW_ALV_9400  OUTPUT
    MODULE show_alv_9400 OUTPUT.
    DATA: e_posicao TYPE lvc_s_stbl.
    *- Gerando o objeto do ALV
      IF vg_grid8 IS INITIAL.
        CREATE OBJECT vg_grid8
          EXPORTING
            i_parent      = vg_contain8
            i_appl_events = c_x.
        CALL METHOD vg_grid8->set_table_for_first_display
          EXPORTING
            is_variant           = wa_variante
            i_save               = c_a
    *        i_default            = c_x
            is_layout            = wa_layoutcl
            is_print             = wa_printcl
            i_buffer_active      = space
            it_toolbar_excluding = t_excludingcl
          CHANGING
            it_fieldcatalog      = t_fieldcatcl[]
            it_outtab            = pt_alv_itm_ata_ex
            it_sort              = t_sortcl.
        IF sy-subrc NE 0.
    *-    ERRO na execução do ALV
          MESSAGE e007(zbc001).
        ENDIF.
        CLEAR t_f4.
        PERFORM f_det_fldswtf4_8 USING 'ZITEM_ATA' CHANGING t_f4.
        PERFORM f_set_events_ata_ex.
      ENDIF.
      vg_grid8->set_ready_for_input( ).
      e_posicao-row = c_x.
      e_posicao-col = c_x.
      CALL METHOD vg_grid8->refresh_table_display
        EXPORTING
          is_stable = e_posicao.
      CALL METHOD vg_grid8->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    endmodule.
    My problem Is :When I insert data in field of screen and  click in OK in PAI module the filed appears empity in internal table  ,but I insert data in Screen .
    How Can I show the data insert in screen , in my internal table Too.?
    Thanks Gurus.

    Try registering the events before calling set_table_for_first_display and add this after calling the ALV:
      SET HANDLER g_application->handle_tf_user_command FOR
                  tf_grid.
      SET HANDLER g_application->handle_tf_data_changed FOR
                  tf_grid.
      SET HANDLER g_application->handle_tf_data_changed_finish FOR
                  tf_grid.
    I know, ALVs can make you nuts...

  • Update value of internal table in table control

    hi friends,
                  i have two text field and a button in a screen.if give the value and click the button it should get updated in the table control which is in the next screen.plz
    help me with some sample coding.

    Hi,
    As I can understand, you want
    1. To enter details in two fields. You want to enter data there and then press an enter Button.
    2. This two fields are part of table control in the next screen and it has some data present there. You want to add data of this two fields in the Internal table.
    THere are few options.
    1. Define a Global internal Table.
    2. Fetch Data in that internal Table in your 1st Screen Say 100 with the 2 text fields.
    3. On click of the button. In PAI append data of the fields in the Global Internal Table.
    4. Display internal table by looping on it in the next screen say 200.
    Hope this is the answer you are looking for.
    Try to solve, if you can't then send me message or email.
    Cheers.
    Darshan
    <b><i>** Please reward points if this helps u. It motivates us to write more answer and put more efforts.</i></b>

  • Im trying to update db table in  user exit, with the internal table

    Im trying to update db table in user exit, with the internal table
    my scenario:
    loop at itekpo.
    updating itekpo -
    > at the end of user exit the db table ekpo have to be updated
    endloop.
    Im updating internal table, using 
    MODIFY itekpo TRANSPORTING INCO1 INCO2  WHERE ebeln = itekpo-ebeln
    where itekpo is internal table, but it is not updating the db table 'ekpo'.
    i also tried updating ekpo directly !
    Thanks in advance

    Hi,
    you can search in the forum itself,
    Try this link for instance
    https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=tocreateaBADI&adv=false&sortby=cm_rnd_rankvalue
    You can find a code for finding BADI as a report with the following Transaction
    finding badis
    How to find BADIs
    Reward if helpful
    Regards
    Byju

  • Internal table updation

    Hi,
    Internal table declaration
    data: begin of test occurs 0,
           salesorg type vkorg,
           palnt    type werks,
          end of test.
    Internal table Data
    Sales org     Plant
    XXX           PPP
    YYY           OOO
    ZZZ           III
    Now the plant of all records should be changed to 'PPP' <b>without looping the test table.</b>
    <u><i>Need syntax for changing plant in all records to PPP without using loop statement.</i></u>
    Regards,
    Sreedevi P

    Hi Sreedevi,
       I don't think you can do that modification of the only one field without looping the internal table.
    Looping the internal table is the best alternative.
    Loop at test.
      test-plant = 'PPP'.
      Modify test transporting plant.
    Endloop.
    Reward if helpful.
    Regards,
    Tushar
    Message was edited by: Tushar  Marshall Dass

  • To eliminate the duplicate entries while looping into final internal table

    Hi friends,
    IAam facing the follwoing problem.
    Get Shipment for the Delivery number
          SELECT tknum
                 vbeln
                 INTO TABLE lt_vttp
                 FROM vttp
                 FOR ALL ENTRIES IN lt_vbfa
                 WHERE vbeln = lt_vbfa-vbelv.
        IF sy-subrc EQ 0.
          SELECT vbeln kunnr
                 FROM likp
                 INTO TABLE lt_likp
                 FOR ALL ENTRIES IN lt_vttp
                 WHERE vbeln = lt_vttp-vbeln.
      endif.
    now iam my internal table lt_vttp i have following values
       shipment             delivery
          1000                  2000
          1000                 2001
    in my internal table lt_likp i have the follwoing values
          delivery              shipto
           2000                  ABC
           2001                  ABC
    now iam looping those values in a final internal table.
      LOOP AT lt_likp INTO ls_likp.
        CHECK sy-subrc EQ 0.
         READ TABLE lt_vttp INTO ls_vttp WITH KEY vbeln = ls_likp-vbeln BINARY SEARCH.
        CHECK sy-subrc EQ 0.
             SELECT SINGLE * FROM vttk INTO ls_vttk
                    WHERE tknum = ls_vttp-tknum.
                  CHECK sy-subrc EQ 0.
                APPEND ls_vttk TO lt_vttk.
       endloop.
    Now my problem is if the shipment is same and the shipto is same then need to eliminate the duplicate records.
            in internal table iam getting 2records with same shipment and shipto combination.
           but instead if both the shipment and shipto are same then i should elimate the duplicate entries.
    and for the same shipment if i have differnt shipto then i neeed those 2 value.
    can any body tell me how can i get that.
    Regards
    Priyanka.

    Hi Priyanka,
    In your code you are using seelct statement inside the loop which will affect the performance.
    So, declare a another internal table which contains your both shipment and shipto elements with other required fields, say the name is lt_new.
    sort lt_new by shipment shipto.
    delete adjacent duplicates from lt_new comparing shipment shipto.
    "then use for all entries to choose values from VTTK.
    Hope this helps you.
    Regards,
    Manoj Kumar P

  • Best way to update custom table

    Hello experts,
    Iu2019m writing a report program and after pulling data from a custom table Iu2019m modifying certain fields within internal table and then eventually update custom table. The way Iu2019m updating custom table is working fine. However Iu2019m concern about performance issues because Iu2019m doing update on custom table within loop.
    Here is my code for reference.
    *&      Form  update_contracts
          text
    -->  p1        text
    <--  p2        text
    FORM update_contracts .
    Update record in an internal table first
      loop at izsc_compliance into wa_zsc_compliance..
        wa_zsc_compliance-zapproval = c_accepted.
        wa_zsc_compliance-CHANGED_DT = sy-datum.
        wa_zsc_compliance-CHANGED_TM = sy-uzeit.
        wa_zsc_compliance-CHANGED_BY = sy-uname.
        modify izsc_compliance from wa_zsc_compliance index sy-tabix.
        write:/ sy-tabix, wa_zsc_compliance-vbeln_new, wa_zsc_compliance-zapproval.
        if p_test is initial.
          move wa_zsc_compliance to zsc_compliance.
          update zsc_compliance.
        endif..
      endloop.
    Write records to database
      if p_test = 'X'.
        skip.
        write:/ 'Test mode'.
      endif.
    ENDFORM.                    " update_contracts
    Iu2019m not certain if there is any better way by not doing update within loop and update custom table outside this loop.
    Many thanks in advance.

    Hi,
    Yes, there is a better way to update the custom table. That will be more performance oriented and will be a much cleaner approach. As, I am not much aware of the custom table structure which you have in your program, the best way that I can suggest is to remove the update statement from that check. I guess you are checking against the mode - test or production. Once you have done the check, put the selected entries in an internal table which is same as database table. And then in a single command - a single array operation as it is commonly called, you can update the custom table.
    Have a look at the following link
    [Overwriting Several Lines Using an Internal Table|http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3a94358411d1829f0000e829fbfe/content.htm]
    [Inserting or Changing Lines|http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3ac8358411d1829f0000e829fbfe/content.htm]
    You can also scan the forum for multiple links and references and sample examples.
    Hope this will help. The above approach will be much more performance oriented and will help to optimize. Also, check where exactly you are providing the locking feature if at applicable in your business functionality.
    Regards,
    Samantak.

Maybe you are looking for

  • JNDI lookup for Crystal Reports at runtime

    How to run a rpt to fetch data from database connection defined in Tomcat's JNDI resources ? We are using JDBC(JNDI) Data source while designing the report in the Crystal Report designer and we want to use 'Connection Name' at runtime for jndi lookup

  • HT1918 Got a problem in my iTunes account and I can not purchase through

    Got a problem in my iTunes account and I can not purchase through

  • How to block a particular website in mozilla firefox?

    I just want to block a particular website from mozilla firefox browser. The steps given in the option are not working really. let me know in details the procedure to block a particular website.

  • Can't install Lion on MacPro 5.1

    Help! First time in my 20 years Mac-life I have such a crazy problem. Downloaded Lion from Mac App Store and sucsessfuly installed on iMac i5 quad and MacMini 1.83 Core2Duo. When I tried to install on Mac Pro  6-core 3.33Ghz/24Gb - After restart Mac

  • LDOMs on T2000 and T2540 , guest domains from FC LUN's

    Hi, I have some T2000 servers and ont 2540 FC storage. each servers have one HBA only, and 73 GB of mirrored internal disk space I would like to implement LDOM's here. I would like to confirm if we can have the guest domains booted off from the SAN s