Internal table - move record to first record in table

How can a move a record already in an internal table to the first record in the table? There is no appropriate sort that would make it the first record.

Assuming the record is in the header:
delete itab.
insert itab index 1.
That should be - assuming sy-index already points to the record you want to move.
Rob
Message was edited by: Rob Burbank

Similar Messages

  • WD ABAP: Reset Table To Show the First Record.

    Hi WebDynpro ABAP Experts,
    Settings of tables allow me to display set of 10 records at a time. If i want to select , say 18th record I use paginator to select & use it. i navigate to next view , do some processing here. When I come back to the previous view, i see that table is still showing the 18th Records.  How can i make this TABLE to show the first 10 records again & we want to achieve this without going back to DB.
    or  in other words we want to call the "FIRST ROW" functionality of Paginator that JUMPS to display the first Ten Row.

    Hi Prash,
    If you used supply function for filling the data to the table means you can use the Invalidate method.
    Before leaving the first view you can call the invalidate method. The invalidate method again calls the supply function and your node as well as table getting refreshed.
    Code for Invalidation :
    node_node1 = wd_context->get_child_node( name = 'NODE1' ).
    elem_node1 = node_node1->get_element( ).
    node_node1->invalidate( ).
    Thanks.

  • Can I move cursor to first record without reopen it?

    I want to use the same cursor in my stored procedure
    for many times, but it is time expensive to open this
    cursor. So can I move the cursor to the first record
    when it come to the last without close and reopen this
    cursor?

    You could read your data at once into a collection and then process the collection afterwards as you like:
    For an example see
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm#28373

  • How to select last record or first record value in a formula?

    Post Author: d111
    CA Forum: General
    I am using a query in a report that in addition to other columns, has a column of month labels like:
    There are no unique identifiers or sequence fields that can be used.   There is only 4 columns: the label and 3 percent columns.
    Jan07Feb07Mar07Apr07etc.
    I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
    I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
    I would like to use a formula to just grab the first and last record.  I can't seem to find any information on this anywhere.
    Please advise and thanks.

    Post Author: bettername
    CA Forum: General
    Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
    If so, try these:
    Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
    //Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
    numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
    //...etc etc you fill in the rest!
    if left({YourTable.YourField},3) = "Dec" then the_month:=12;
    date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
    Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
    totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
    If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
    Stick this in the details section, and call it "HoldRecords" and suppress it:
    whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
    Now create another formula, and put it into the report footer:
    evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
    NOTE:  if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
    Hope this helps...

  • Query a table and exit when first record found

    I want to query a table and just want to know if any rows matching my query criteria exist in the table. I just want to find one row, irrespective of order and stop the query right there. How do I do that?

    The most efficient way would be either to use rownum = 1 as part of the condition in your second query, but, as written, both will return multiple rows. Your first will need to have an additional predicate and rownum = 1 in addition to the exists.
    Assuming that the predicate can use an index, then the most efficient approach would be either:
    SELECT 1 FROM table
    WHERE <conditions> and
          rownum = 1or possibly:
    SELECT 1 FROM dual
    WHERE EXISTS (SELECT 1 FROM table
                  WHERE <conditions>)Both will do a range scan on the applicable index, stopping when the find the first matching entry. To my mind, the first is clearer in intent.
    To illustrate the error in your first query, consider:
    SQL> SELECT * FROM t;
            ID DESCR
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
    SQL> SELECT * FROM t
      2  WHERE id = 1 and
      3        rownum = 1;
            ID DESCR
             1 One
    SQL> SELECT * FROM t
      2  WHERE EXISTS (SELECT 1 FROM t
      3                WHERE id = 1);
            ID DESCR
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
             1 One
             2 Two
             3 Three
             4 Four
             5 FiveJohn
    Edited by: John Spencer on Oct 2, 2009 12:06 PM
    Added queries from t

  • Form Personalization - To move to the first record.

    Hi All,
    There is DO_KEY Builtin in Form Personalization.
    But it can not use "FIRST_RECORD" as argument of DO_KEY Builtin.
    And there is no parameter such like "system.first_record" can be reference.
    How to do the FIRST_RECORD by using Form Personalization only?
    (We know it may be done with custom.pll.)
    Any suggestions will be appreciated.
    Best regards,
    Zhxiang

    Hi;
    Please check below which could be helpful on your issue:
    Forms Personalization Document
    Re: Forms Personalization Document
    Re: Form Personalization
    Forms Customization
    Re: Enable Submit Button at User Level and Disable at Block Level
    Regard
    Helios

  • Master-Detail only shows the first record of the Master's data

    I have an ADF Master Table, Detail table. I use ExcuteWithParams on the Master Table. When executed from a button (Button has partial submit = true for button, Master Table has PartialTrigger on button, and Detail table has PartialTrigger on Master table and button), it works fine. However, I want to pass the parameters in pageFlowScope variables, and have the ExecuteWithParams invoked upon page load. When I try to do this, the Detail table only shows the first record of the Master's data, no mater what row is clicked on the Master table.
    Master table now has no PartialTrigger, and Detail table has PartialTrigger on Master table. In my pageDef, I used an invoke action as follows:
    <invokeAction Binds="ExecuteWithParams" id="invokeExecuteWithParams"
    Refresh="always"/>
    What am I missing? I am using verion 11.1.1.3. Any help would be much appreciated.
    Thanks,
    Jessica

    Yes, it works when I drag the data control as a master detail without filtering any data. I want the user to be able to set search criteria to filter the data in the master table (For example, only pull back data with a transaction date between :startdate and :enddate). I can get it to work if I execute from an executewithparams button on the page, but not if I want to invoke the executewithparams upon page load with the parameter set by pageflowscope variables.
    Thank you for responding.
    Jessica

  • How to check if it is first record

    hi..
    i have a block with some items SL,STAFF, NAME..., of multiple record.
    while entering data, i want to check whether this record is first record....
    if it is firs record i have to know the SL of last entry from DB and based on that generate next SL.
    " just let me know how to check whether it is my first record ..????"
    thnx ..

    ManiKanchan wrote:
    it worked
    plz tell me one more thing..
    " how to get the value of a item of previous record...?"
    example.. to know the value of SL of previous record , i tried
    VARIABLE := Get_Record_Property( GET_BLOCK_PROPERTY('BLOCK_NAME',CURRENT_RECORD)-1, 'BLOCK_NAME', :BLOCK_NAME.SL);
    But, did not work...help..!!!Why u thinking of this..
    Best way for sl generation is Sequence. try to use it.
    Other way write this at block-level trigger Pre-Insert
    SELECT NVL(MAX(AD_ID),0)+1 INTO :CUST.AD_ID FROM ACC_DTL;but this isn't good idea.
    Red this Auto generate Invoice Number
    Hopes this helps
    If someone response is helpful or correct, please mark it accordingly.

  • Merge 2 internal tables into one and show first record from common fields

    Hello PPl,
              I have 3 tables kna1 knb1 and knvp i have to join kna1 and knb1 on kunnr and move the data into an internal table it_data then  on the basis of that data in it_data i have to retrieve records FOR ALL ENTRIES from KNVP and move it into it_knvp.
    Then both it_data and it_knvp should be merged in it_alv and from that internal table report has to be displayed.
    [NOTE: i had tried using loop twice but the report got messed up]
    Apart from that for these set of values
    0000000004
    0000000418
    0000000954
    0000001190
    0000001222
    0000001451
    0000001453
    0000001455
    0000001470
    0000001508
    finally knvp is showing records in such a way that for 2 records kunnr is same and so does all the other fields except PARZA and KUNN2 so the req. is to display only the first record among 2.
    Plz help me by providing code for that its urgent......
    Below i m providing my code so far, i hope it will be of some help.
    TREMENDOUS REWARD POINTS GURANTEED!!!!!
    REPORT  zfanz_alv_report_whv.
    TYPE-GROUPS                                                         *
    TYPE-POOLS: slis.
    TYPES                                                               *
    TYPES: BEGIN OF ty_data,
           kunnr TYPE kunnr,
           ort01 TYPE ort01,
           pstlz TYPE pstlz,
           regio TYPE regio,
           bukrs TYPE bukrs,
           zterm TYPE zterm,
           END OF ty_data,
           BEGIN OF ty_knvp,
           vkorg TYPE vkorg,
           vtweg TYPE vtweg,
           spart TYPE spart,
           parvw TYPE parvw,
           parza TYPE parza,
           kunn2 TYPE kunn2,
           lifnr TYPE lifnr,
           END OF ty_knvp,
           BEGIN OF ty_alv,
           kunnr TYPE kunnr,
           ort01 TYPE ort01,
           pstlz TYPE pstlz,
           regio TYPE regio,
           bukrs TYPE bukrs,
           zterm TYPE zterm,
           vkorg TYPE vkorg,
           vtweg TYPE vtweg,
           spart TYPE spart,
           parvw TYPE parvw,
           parza TYPE parza,
           kunn2 TYPE kunn2,
           lifnr TYPE lifnr,
           END OF ty_alv,
           BEGIN OF ty_kna1,
           kunnr TYPE kunnr,
           END OF ty_kna1,
           BEGIN OF ty_knb1,
           bukrs TYPE bukrs,
           END OF ty_knb1.
    *DATA: IT_KNVP TYPE KNVP,
    DATA: it_knvp TYPE STANDARD TABLE OF ty_knvp WITH HEADER LINE.
    DATA: it_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.
    Report data to be shown.
    DATA: it_alv TYPE STANDARD TABLE OF ty_alv WITH HEADER LINE.
    Heading of the report.
    DATA: t_heading TYPE slis_t_listheader.
    *DATA: fieldcatalog type standard table of slis_fieldcat_alv with header
    *line.
    DATA: fieldcatalog TYPE  slis_t_fieldcat_alv WITH HEADER LINE.
    *TABLES
    tables:knvp,kna1,knb1.
                     CONSTANTS                                           *
    CONSTANTS: c_kunnr TYPE char5 VALUE 'KUNNR',
    c_ort01 TYPE char5 VALUE 'ORT01',
    c_pstlz TYPE char5 VALUE 'PSTLZ',
    c_regio TYPE char5 VALUE 'REGIO',
    c_bukrs TYPE char5 VALUE 'BUKRS',
    c_zterm TYPE char5 VALUE 'ZTERM',
    c_vkorg TYPE char5 VALUE 'VKORG',
    c_vtweg TYPE char5 VALUE 'VTWEG',
    c_spart TYPE char5 VALUE 'SPART',
    c_parvw TYPE char5 VALUE 'PARVW',
    c_parza TYPE char5 VALUE 'PARZA',
    c_kunn2 TYPE char5 VALUE 'KUNN2',
    c_lifnr TYPE char5 VALUE 'LIFNR'.
    WORKAREA                                                           *
    DATA: wa_data TYPE ty_data,
          wa_knvp TYPE ty_knvp,
          wa_alv TYPE ty_alv,
          wa_fcat  TYPE slis_fieldcat_alv,
          wa_layout TYPE slis_layout_alv.
    ======================= Selection Screen ==========================
    SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    *DATA: wa_kunnr LIKE kna1-kunnr,
         wa_bukrs LIKE knb1-bukrs,
         wa_vkorg LIKE knvp-vkorg,
         wa_vtweg LIKE knvp-vtweg,
         wa_spart LIKE knvp-spart,
         wa_parvw LIKE knvp-parvw.
    SELECT-OPTIONS                                                      *
    SELECT-OPTIONS s_kunnr FOR kna1-kunnr NO INTERVALS OBLIGATORY
    SELECT-OPTIONS: s_bukrs FOR knb1-bukrs NO-EXTENSION NO INTERVALS,
    s_vkorg FOR knvp-vkorg  NO-EXTENSION NO INTERVALS,
    s_vtweg FOR knvp-vtweg NO-EXTENSION NO INTERVALS,
    s_spart FOR knvp-spart NO-EXTENSION NO INTERVALS,
    s_parvw FOR knvp-parvw NO-EXTENSION NO INTERVALS.
    SELECTION-SCREEN: END OF BLOCK b1.
    AT SELECTION-SCREEN                                            *
    AT SELECTION-SCREEN ON s_kunnr.
      PERFORM validate_data.
    START-OF-SELECTION                                                   *
    START-OF-SELECTION.
      PERFORM get_data.  "fetch data from table and perform join on them
      PERFORM final_table.
      PERFORM build_fieldcatalog.            "populate field catalog
      PERFORM build_layout.
      PERFORM grid_display.                  "display the result in ALV grid
    END-OF-SELECTION                                                     *
    END-OF-SELECTION.
    describe
    SUBROUTINES (FORMS)
    *&      Form  get_data
          Gets the information to be shown in the report.
          Join on tables KNA1, KNB1 and for all enteries in KNVP
    -->  p1        text
    <--  p2        text
    FORM get_data.
      SELECT kna1~kunnr
      kna1~ort01
      kna1~pstlz
      kna1~regio
      knb1~bukrs
      knb1~zterm
      INTO TABLE it_data
      FROM kna1 INNER JOIN knb1
      ON kna1kunnr = knb1kunnr
        WHERE kna1~kunnr IN s_kunnr
       AND knb1~bukrs IN s_bukrs.
      SELECT vkorg
             vtweg
             spart
             parvw
             parza
             kunn2
             lifnr
            INTO TABLE it_knvp FROM knvp
       FOR ALL ENTRIES IN it_data
       WHERE  knvp~kunnr = it_data-kunnr
         AND  vkorg IN s_vkorg
         AND  vtweg IN s_vtweg
         AND  spart IN s_spart
         AND  parvw IN s_parvw.
    ENDFORM. " get_data
    *ENDFORM. " get_data
    *&      Form  FINAL_TABLE
          text
    -->  p1        text
    <--  p2        text
    FORM final_table .
      LOOP AT it_data.
        it_alv-kunnr = it_data-kunnr.
        it_alv-ort01 = it_data-ort01.
        it_alv-pstlz = it_data-pstlz.
        it_alv-regio = it_data-regio.
        it_alv-bukrs = it_data-bukrs.
        it_alv-zterm = it_data-zterm.
        APPEND it_alv.
        CLEAR it_alv.
      ENDLOOP.
      LOOP AT it_knvp.
        it_alv-vkorg = it_knvp-vkorg.
        it_alv-vtweg = it_knvp-vtweg.
        it_alv-spart = it_knvp-spart.
        it_alv-parvw = it_knvp-parvw.
        it_alv-parza = it_knvp-parza.
        it_alv-kunn2 = it_knvp-kunn2.
        it_alv-lifnr = it_knvp-lifnr.
        APPEND it_alv.
        CLEAR it_alv.
      ENDLOOP.
    ENDFORM.                    " FINAL_TABLE
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      IF it_alv[] IS NOT INITIAL.
        wa_fcat-fieldname   = c_kunnr.
        wa_fcat-seltext_l   = 'Customer Master'(001).
        wa_fcat-col_pos     = 1.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_ort01.
        wa_fcat-seltext_l   = 'City'(002).
        wa_fcat-col_pos     = 2.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_pstlz.
        wa_fcat-seltext_l   = 'Postal Code'(003).
        wa_fcat-col_pos     = 3.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_regio.
        wa_fcat-seltext_l   = 'Region'(004).
        wa_fcat-col_pos     = 4.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_bukrs.
        wa_fcat-seltext_l   = 'Company Code'(005).
        wa_fcat-col_pos     = 5.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_zterm.
        wa_fcat-seltext_l   = 'Terms of payment'(006).
        wa_fcat-col_pos     = 6.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_vkorg.
        wa_fcat-seltext_l   = 'Sales Organization'(007).
        wa_fcat-col_pos     = 7.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_vtweg.
        wa_fcat-seltext_l   = 'Distribution Channel'(008).
        wa_fcat-col_pos     = 8.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_spart.
        wa_fcat-seltext_l   = 'Division'(009).
        wa_fcat-col_pos     = 9.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_parvw.
        wa_fcat-seltext_l   = 'Partner function'(010).
        wa_fcat-col_pos     = 10.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_kunn2.
        wa_fcat-seltext_l   = 'Customer number of partner'(011).
        wa_fcat-col_pos     = 11.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_lifnr.
        wa_fcat-seltext_l   = 'Account Number of Vendor'(012).
        wa_fcat-col_pos     = 12.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
       wa_fcat-fieldname   = c_parza.
       wa_fcat-seltext_l   = 'Partner counter'(013).
        wa_fcat-col_pos     = 13.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
    *fieldcatalog-fieldname   = c_kunnr.
       fieldcatalog-seltext_l   = 'Customer Master'(001).
       fieldcatalog-col_pos     = 1.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_ort01.
       fieldcatalog-seltext_l   = 'City'(002).
       fieldcatalog-col_pos     = 2.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_pstlz.
       fieldcatalog-seltext_l   = 'Postal Code'(003).
       fieldcatalog-col_pos     = 3.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_regio.
       fieldcatalog-seltext_l   = 'Region'(004).
       fieldcatalog-col_pos     = 4.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_bukrs.
       fieldcatalog-seltext_l   = 'Company Code'(005).
       fieldcatalog-col_pos     = 5.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_zterm.
       fieldcatalog-seltext_l   = 'Terms of payment'(006).
       fieldcatalog-col_pos     = 6.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_vkorg.
       fieldcatalog-seltext_l   = 'Sales Organization'(007).
       fieldcatalog-col_pos     = 7.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_vtweg.
       fieldcatalog-seltext_l   = 'Distribution Channel'(008).
       fieldcatalog-col_pos     = 8.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_spart.
       fieldcatalog-seltext_l   = 'Division'(009).
       fieldcatalog-col_pos     = 9.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_parvw.
       fieldcatalog-seltext_l   = 'Partner function'(010).
       fieldcatalog-col_pos     = 10.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_kunn2.
       fieldcatalog-seltext_l   = 'Customer number of partner'(011).
       fieldcatalog-col_pos     = 11.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_lifnr.
       fieldcatalog-seltext_l   = 'Account Number of Vendor'(012).
       fieldcatalog-col_pos     = 12.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_parza.
       fieldcatalog-seltext_l   = 'Partner counter'(013).
       fieldcatalog-col_pos     = 13.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
      ENDIF.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  build_layout
          text
    -->  p1        text
    <--  p2        text
    form build_layout .
    Set layout field for field attributes(i.e. input/output)
    wa_layout-stylefname = 'FIELD_STYLE'.
      wa_layout-zebra             = 'X'.
    endform.                    " build_layout
    *&      Form  GRID_DISPLAY
          text
    FORM grid_display. "using t_data type ty_tbl_data.
      IF it_alv[] IS NOT INITIAL.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         i_callback_program                = sy-repid
       IS_LAYOUT                         = wa_layout
         it_fieldcat                       = fieldcatalog[]
        TABLES
          t_outtab                          = it_alv[]
      EXCEPTIONS
            program_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.
      ENDIF.
    ENDIF.
    ENDFORM.                    "GRID_DISPLAY
    *&      Form  VALIDATE_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM validate_data .
      DATA : li_kna1 TYPE STANDARD TABLE OF ty_kna1,
             li_knb1 TYPE STANDARD TABLE OF ty_knb1,
             li_knvp TYPE STANDARD TABLE OF ty_knvp.
      SELECT kunnr
      FROM kna1
      INTO TABLE li_kna1
      WHERE kunnr IN s_kunnr.
      IF sy-subrc <> 0.
        MESSAGE 'Invalid Customer Number'(013) TYPE 'E'.
      ENDIF.
      SELECT bukrs
      FROM t001
      INTO TABLE li_knb1
      WHERE bukrs IN s_bukrs.
        IF sy-subrc <> 0.
          MESSAGE 'Invalid Company Code'(014) TYPE 'E'.
        ENDIF.
        SELECT vkorg
        FROM tvko
        INTO TABLE li_knvp
        WHERE vkorg IN s_vkorg.
          IF sy-subrc <> 0.
            MESSAGE 'Invalid Sales Organization'(015) TYPE 'E'.
          ENDIF.
          SELECT vtweg
          FROM tvtw
          INTO TABLE li_knvp
          WHERE vtweg IN s_vtweg.
            IF sy-subrc <> 0.
              MESSAGE 'Invalid Distribution Channel'(016) TYPE 'E'.
            ENDIF.
            SELECT spart
            FROM tspa
            INTO TABLE li_knvp
            WHERE spart IN s_spart.
              IF sy-subrc <> 0.
                MESSAGE 'Invalid Division'(017) TYPE 'E'.
              ENDIF.
              SELECT parvw
              FROM tpar
              INTO TABLE li_knvp
              WHERE parvw IN s_parvw.
                IF sy-subrc <> 0.
                  MESSAGE 'Invalid Partner function'(018) TYPE 'E'.
                ENDIF.
            ENDFORM.                    " VALIDATE_DATA

    *1----
    FORM get_data.
      SELECT kna1~kunnr
      kna1~ort01
      kna1~pstlz
      kna1~regio
      knb1~bukrs
      knb1~zterm
      INTO TABLE it_data
      FROM kna1 INNER JOIN knb1
      ON kna1kunnr = knb1kunnr
        WHERE kna1~kunnr IN s_kunnr
       AND knb1~bukrs IN s_bukrs.
      CHECK it_data[] IS NOT INITIAL.
      SELECT kunnr
             vkorg
             vtweg
             spart
             parvw
             parza
             kunn2
             lifnr
            INTO TABLE it_knvp FROM knvp
       FOR ALL ENTRIES IN it_data
       WHERE  kunnr = it_data-kunnr
         AND  vkorg IN s_vkorg
         AND  vtweg IN s_vtweg
         AND  spart IN s_spart
         AND  parvw IN s_parvw.
      IF sy-subrc EQ 0.
        SORT it_knvp BY kunnr.
      ENDIF.
    ENDFORM. " get_data
    *2----
    FORM final_table .
      LOOP AT it_data INTO wa_data.
        READ TABLE it_knvp
        INTO wa_knvp
        WITH KEY kunnr = wa_data-kunnr
        BINARY SEARCH .
        IF sy-subrc = 0.
          MOVE-CORRESPONDING wa_data TO wa_alv.
          MOVE-CORRESPONDING wa_knvp TO wa_alv.
          APPEND wa_alv TO it_alv.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " FINAL_TABLE
    Edited by: Faisal Khan on Mar 27, 2008 1:59 PM

  • Only first record in internal table in output

    Hi,
    I have a requirement.
    I loop at an internal table and that tabl (list_selected_records) records.
    Loop at list_of_selected_nodes into wa_selected_nodes.
    node = wa_selected_nodes-node_id.
    node_level = wa_selected_nodes-node_level.
    read table ex_list_of_texts
    into wa_list_of_texts
    with key node_id = node
    binary search.
    IF sy-subrc eq 0.
    node_text = wa_list_of_texts-text.
    ENDIF.
    node_level = node_level - 1.
    Selecting Text for Node selected (Business Scenario)
    READ TABLE list_of_all_nodes into wa_all_nodes WITH KEY NODE_LEVEL = node_level
    BINARY SEARCH.
    if sy-subrc = 0.
    SELECT SINGLE TEXT FROM TTREET into texts WHERE ID EQ wa_all_nodes-tree_id
    AND SPRAS EQ 'EN '.
    IF NOT TEXTS IS INITIAL.
    wa_final-texts = texts.
    append wa_final to it_final.
    CLEAR WA_FINAL.
    endif.
    endif.
    endloop.
    This is my code.
    Now from the select single stmt i fetch a text and add it to be internal table . Once i fetch a one record the loop should be ended and a new iteration for for a second guid should start.
    Once one record , first record is fetched for texts, only that shd appear in alv output but not other. but the loop should contnue for other fields. Please help
    Thanks in Advance.
    SS

    Hi Swarna,
    Use control event AT-NEW inside the loop. This event will triger only once for every new node_id.
    Loop at list_of_selected_nodes into wa_selected_nodes.
    AT-NEW node_id.
    node = wa_selected_nodes-node_id.
    node_level = wa_selected_nodes-node_level.
    read table ex_list_of_texts
    into wa_list_of_texts
    with key node_id = node
    binary search.
    IF sy-subrc eq 0.
    node_text = wa_list_of_texts-text.
    ENDIF.
    node_level = node_level - 1.
    Selecting Text for Node selected (Business Scenario)
    READ TABLE list_of_all_nodes into wa_all_nodes WITH KEY NODE_LEVEL = node_level
    BINARY SEARCH.
    if sy-subrc = 0.
    SELECT SINGLE TEXT FROM TTREET into texts WHERE ID EQ wa_all_nodes-tree_id
    AND SPRAS EQ 'EN '.
    IF NOT TEXTS IS INITIAL.
    wa_final-texts = texts.
    append wa_final to it_final.
    CLEAR WA_FINAL.
    endif.
    endif.
    ENDAT.
    endloop.
    Thanks & Regards,
    Parameswaran.K

  • How to get First record in a table

    Hi,
    I have created a table, at a time 20 records are displayed in the table.
    When the 21-40 records are displayed in the table, and the page is refreshed.. then first 20 records are displayed.
    How can I display the current records i.e., 21-40 records when I refresh the page?
    Please give me a solution for this.
    Thanks.

    Are you talking about the page refresh through OAF code or the refresh button?
    The logic you need to follow is to make sure that you maintain the state of the VO which will maintain the pointer to rows.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Computation only works for FIRST record in detail table

    Hi,
    I am having a weird problem. I have a master/detail form with page computations that work only for the very first record inserted into the detail table. If i try to enter a second or a third record the fields DO NOT get updated with the return values.
    This is driving me nuts and i am on a deadline with this project. HELP!!!!!
    Here is the code for all the computations below. Interestingly enough, only the name computation works for every new detail record. The others work only for the first.
    -- Calulate Social Security PL/SQL Function
    DECLARE
    p_is16to62ssrate NUMBER(6,2);
    p_u16o62ssrate NUMBER(6,2);
    p_dob DATE;
    p_base_date DATE := SYSDATE;
    p_age NUMBER(3);
    p_totalss NUMBER(9,2);
    BEGIN
    SELECT is16to62ssrate, u16o62ssrate
    INTO p_is16to62ssrate, p_u16o62ssrate
    FROM SSC3_RATES
    WHERE ratescheduleid = 1;
    SELECT dob
    INTO p_dob
    FROM SSC3_EMPLOYEES
    WHERE ssno = :P25_SSNO;
    p_age := TRUNC(MONTHS_BETWEEN(p_base_date,p_dob)/12);
    IF (p_age >= 16) OR (p_age <=62) THEN
    p_totalss := (:P25_TOTALWAGES * (p_is16to62ssrate/100));
    ELSIF (p_age < 16) OR (p_age > 62) THEN
    p_totalss := (:P25_TOTALWAGES * (p_u16o62ssrate/100));
    ELSE
    p_totalss := 0.00;
    END IF;
    RETURN p_totalss;
    END;
    -- Calculate Levy PL/SQL Function
    DECLARE
    -- declare local variables to hold rates from rates table
    p_hsdlarate NUMBER(6,2);
    p_hsdlbrate NUMBER(6,2);
    p_hsdlcrate NUMBER(6,2);
    p_hsdldrate NUMBER(6,2);
    p_hsdlaminearnings NUMBER(8,2);
    p_hsdlamaxearnings NUMBER(8,2);
    p_hsdlbminearnings NUMBER(8,2);
    p_hsdlbmaxearnings NUMBER(8,2);
    p_hsdlcminearnings NUMBER(8,2);
    p_hsdlcmaxearnings NUMBER(8,2);
    p_hsdldminearnings NUMBER(8,2);
    p_hsdldmaxearnings NUMBER(8,2);
    p_totalwages NUMBER(8,2);
    p_totallevy NUMBER(8,2);
    BEGIN
    -- Load rate info from table into variables
    SELECT hsdlarate, hsdlbrate, hsdlcrate, hsdldrate, hsdlaminearnings,
    hsdlamaxearnings, hsdlbminearnings, hsdlbmaxearnings,
    hsdlcminearnings, hsdlcmaxearnings, hsdldminearnings,
    hsdldmaxearnings
    INTO p_hsdlarate, p_hsdlbrate, p_hsdlcrate, p_hsdldrate,
    p_hsdlaminearnings, p_hsdlamaxearnings, p_hsdlbminearnings,
    p_hsdlbmaxearnings, p_hsdlcminearnings, p_hsdlcmaxearnings,
    p_hsdldminearnings, p_hsdldmaxearnings
    FROM SSC3_RATES
    WHERE ratescheduleid = 1;
    -- Assign total wages to variable
    p_totalwages := :P25_TOTALWAGES;
    -- Determine applicable levy payment and rate
    IF (p_totalwages < p_hsdlamaxearnings) THEN
    p_totallevy := (p_totalwages * (p_hsdlarate/100));
    ELSIF (p_totalwages >= p_hsdlbminearnings) AND (p_totalwages <= p_hsdlbmaxearnings) THEN
    p_totallevy := (p_totalwages * (p_hsdlbrate/100));
    ELSIF (p_totalwages >= p_hsdlcminearnings) AND (p_totalwages <= p_hsdlcmaxearnings) THEN
    p_totallevy := (p_totalwages * (p_hsdlcrate/100));
    ELSIF (p_totalwages >= p_hsdldminearnings) THEN
    p_totallevy := (p_totalwages * (p_hsdldrate/100));
    END IF;
    RETURN p_totallevy;
    END;
    -- Calculate Total Wages PL/SQL Function
    DECLARE
    t_wages NUMBER(8,2);
    BEGIN
    t_wages := (:P25_WEEK1_WAGE + :P25_WEEK2_WAGE + :P25_WEEK3_WAGE + :P25_WEEK4_WAGE + :P25_WEEK5_WAGE + :P25_BONUS + :P25_OTHER);
    RETURN t_wages;
    END;
    -- Calculate Employee Name PL/SQL Function
    DECLARE
    p_firstname VARCHAR2(20);
    p_lastname VARCHAR2(20);
    p_name VARCHAR2(40);
    p_join VARCHAR2(2) := ', ';
    BEGIN
    SELECT firstname, lastname
    INTO p_firstname, p_lastname
    FROM SSC3_EMPLOYEES
    WHERE ssno = :P25_SSNO;
    p_name := Initcap(p_lastname||p_join||p_firstname);
    RETURN p_name;
    END;
    Regards
    Glenroy Skelton

    Hi,
    The first thing that strikes me is the following IF test:
    IF (p_age >= 16) OR (p_age <=62) THEN
    p_totalss := (:P25_TOTALWAGES * (p_is16to62ssrate/100));
    ELSIF (p_age < 16) OR (p_age > 62) THEN
    p_totalss := (:P25_TOTALWAGES * (p_u16o62ssrate/100));
    ELSE
    p_totalss := 0.00;
    END IF;The first test will be true for every number as all numbers are greater than 16 or less than 62. I'd suggest changing the OR to an AND or use BETWEEN
    Andy

  • INSERT of two records into different tables (pk value from first to second)

    Hi there!
    Have probably stupid question
    Need to insert one record into table with primary key and then insert into other table record with value of primary key field from first record
    How can I do it?
    Thanks a lot!!!

    You have several possibilities. Most easiest one is listed first :)
    SQL> create table a (a number);
    Table created.
    SQL> alter table a add constraint a_pk primary key (a);
    Table altered.
    SQL> create table b (a number);
    Table created.
    SQL> alter table b add constraint  b_a_fk foreign key (a) references a(a);
    Table altered.
    SQL> insert into a values (0);
    1 row created.
    SQL> insert into b values (0);
    1 row created.Though that may not help always, so the next possibility maybe just using sequence with nextval and currval (currval can be used only in the same session and only after you have issued at least one nextval)
    SQL> create sequence a_seq;
    Sequence created.
    SQL>  insert into a values (a_seq.nextval);
    1 row created.
    SQL> insert into b values (a_seq.currval);
    1 row created.And you can use also famous returning clause. It is a bit easier to show that in the pl/sql block than pure SQL.
    SQL> declare
      2   v number;
      3  begin
      4   insert into a values (a_seq.nextval) returning a into v;
      5   insert into b values (v);
      6  end;
      7  /
    PL/SQL procedure successfully completed.And at last contents of the tables :)
    SQL> select * from b;
             A
             0
             1
             2
    SQL> select * from a;
             A
             0
             1
             2Gints Plivna
    http://www.gplivna.eu

  • Need to display Internal table records on screen without using table contro

    Hi Experts,
    I have a requirement to display internal table on screen which is having three columns (Material no, Serial No and quantity).
    But I can't use table control as it is not supported by hand held devices.
    They are going to use this transaction on hand held devices.
    Thanks In advance.
    Gaurav

    You should be able to use the good old STEP LOOP processing for this... create your three fields in the row then convert them to a STEP-LOOP.
    You can look up in the help how to work with STEP-LOOPs if you are not familiar with it. It was the way to manage table-like information before the age of table controls

  • How to return to first record in table after a while statement?

    Hi,
    I'm trying to multiply data from two different tables to get a distance between two points - I only want to return the result if the distance is less than 0.15 metres. It loops ok the first time but dies once I get into the second while for the second time. I'm sure I have the logic wrong, I just can't figure out the right way. I haven't used Java or programmed in four years so apologises if the answer is ridiculously simple!
    public static void main(String args[])
              try
                   FileOutputStream out = new FileOutputStream("c://output.txt", true);
                   PrintStream p;
    // Connect print stream to the output stream
    p = new PrintStream( out );
                   Connection conn = getConnection();
              System.out.println("1");
              Statement st1 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
              Statement st2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
              ResultSet inact = st1.executeQuery("select Radio, aLocationLatLong, Lat, Lon from Inactive_EK");
              ResultSet act = st2.executeQuery("select Radio, aLocationLatLong, Lat, Lon from Active_EK");
              while(inact.next())
                   R_ID = inact.getString("Radio");     
                   inLt = inact.getDouble("Lat");          
                   inLn = inact.getDouble("Lon");
                   p.println("Inactive: " + R_ID + " " + inLt + " " + inLn);
                   while(act.next())
                        acR_ID = act.getString("Radio");
                        acLt = act.getDouble("Lat");
                        acLn = act.getDouble("Lon");
                        p.println("Active Lat: " + acLt + " " + acLn );
                             double earthRadius = 6378.137;
                             double dLat = Math.toRadians(inLt-acLt);
                             double dLng = Math.toRadians(inLn - acLn);
                             double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                        Math.cos(Math.toRadians(acLt)) * Math.cos(Math.toRadians(inLt)) *
                        Math.sin(dLng/2) * Math.sin(dLng/2);
                             double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
                             double dist = earthRadius * c;
                             if(dist <= 0.15)
                                  p.println("Active Lat: " + acR_ID + " " + acLt + " " + acLn + " " + dist);
                   p.close();
                   st1.close();
                   st2.close();
                   conn.close();
              catch
              (Exception e)
    System.err.println ("Connect problem");
    Thanking you in advance!

    Try something like below: change the script as required.
    create Table T1(Col1 int)
    Insert into T1 Select 1
    Insert into T1 Select 2
    Declare @T1 Table(Col1 int, errmsg varchar(100))
    create Table T2(Col1 int, errmsg varchar(100))
    DELETE T1
    output deleted.*,'error 1' INTO @T1
    Where Col1 = 1
    Select * From @t1
    If exists(Select 1 From @t1)
    Begin
    Insert into T2 Select * From @T1
    Drop table T1,T2
    return ;
    End
    DELETE T1
    output deleted.*,'error 2' INTO @T1
    Where Col1 = 2
    Select * From @t1
    Insert into T2 Select * From @T1
    Select * From T2
    Drop table T1,T2

Maybe you are looking for