Addition of sales org in select stmt?

friends i need to add the sales org infront of the names of sold 2 party and ship to party..following is the code plz modify!!
FORM write_kunnr_desc USING    p_i_tab1_kunnr p_ind.
  SELECT SINGLE name1 FROM kna1  INTO kna1-name1
                      WHERE kunnr =  p_i_tab1_kunnr.
  IF p_ind = 'SP'.
    CLEAR: v_kunnr_desc,
    v_kunnr_desc = kna1-name1.
    WRITE :/ sy-vline,'Sold-to-Party',27 ': ', kna1-name1,
             168 space,sy-vline.
  ELSEIF p_ind = 'SH'.
    CLEAR: v_kunnr_sp_desc.
    v_kunnr_sp_desc = kna1-name1.
    WRITE :/ sy-vline,'Ship-to-Party',27 ': ', kna1-name1,
            168 space,sy-vline.
  ENDIF.
ENDFORM.                    " write_kunnr_desc
I want to add the sales org(i.e 2200) in front of both sold to party and ship to party……
How do I do it.
VBAK-VKORG – SOLD TO PART SALES ORG
LIKP-VKORG – SHIP TO PARTY SALES ORG.
WHT DO I DO.
PLEASE REPLY RIGHT AWAY……..
ESSAM

Hi
write a select single statement for KNVV table and display the VKORG field and display
FORM write_kunnr_desc USING p_i_tab1_kunnr p_ind.
data: l_vkorg type vkorg.
clear l_vkorg.
SELECT SINGLE name1 FROM kna1 INTO kna1-name1
WHERE kunnr = p_i_tab1_kunnr.
SELECT SINGLE VKORG FROM knvv INTO l_vkorg
WHERE kunnr = p_i_tab1_kunnr.
IF p_ind = 'SP'.
CLEAR: v_kunnr_desc,
v_kunnr_desc = kna1-name1.
WRITE :/ sy-vline, l_vkorg, 'Sold-to-Party',27 ': ', kna1-name1,
168 space,sy-vline.
ELSEIF p_ind = 'SH'.
CLEAR: v_kunnr_sp_desc.
v_kunnr_sp_desc = kna1-name1.
WRITE :/ sy-vline, l_vkorg, 'Ship-to-Party',27 ': ', kna1-name1,
168 space,sy-vline.
ENDIF.
ENDFORM. " write_kunnr_desc
<b>Reward points for useful Answers</b>
Regards
Anji

Similar Messages

  • Default sales org on selection screen using set and get parameter!!

    Hi,
    I need to default value on selection screen using SET n GET parameter...logic to be used should be:
    Sales Organisation:
    This field should be filled by default using the user parameter id VKO. (using sentence GET PARAMETER and SET PARAMETER)...
    Hope i need to write the code in initialisation and what shud b the content?
    Regards
    Gunjan

    hi,
    TABLES <table name>.
      SET PARAMETER ID VKO FIELD <tablename-fieldname>.
    call transaction 'zxx'.
    try this sample program,
    REPORT BOOKINGS NO STANDARD PAGE HEADING.
    TABLES SBOOK.
    START-OF-SELECTION.
      WRITE: 'Select a booking',
      SKIP.
    GET SBOOK.
      WRITE: SBOOK-CARRID, SBOOK-CONNID,
             SBOOK-FLDATE, SBOOK-BOOKID.
      HIDE:  SBOOK-CARRID, SBOOK-CONNID,
             SBOOK-FLDATE, SBOOK-BOOKID.
    AT LINE-SELECTION.
      SET PARAMETER ID: 'CAR' FIELD SBOOK-CARRID,
                        'CON' FIELD SBOOK-CONNID,
                        'DAY' FIELD SBOOK-FLDATE,
                        'BOK' FIELD SBOOK-BOOKID.
      CALL TRANSACTION 'BOOK'.
    regards,
    siva
    Message was edited by:
            Shan

  • While executing the query sales org not given in Selection screen but still

    Hi ,
    while am executing a query even though am not giving any sales organization  input in selection sceen , and execute , the query will run and pop up windows displays as ' you do not Authorization to read Zsales organization,
    same query i executed last days before  , it worked fine, but now its not working, plz advice

    Hi,
    you might made Sales org Info object as Auth relevant, hence it is giving that error.
    Eirther disable the authorization relevant check in the infoobject maintainance in Bex explorer tab...
    Or create a auth  variable for the infoobject and use it in the query..
    Regards,
    Rangz

  • Material not defined in the sales org

    1 While creating a sales order in VA01 , i am trying to search for a material which i had created ,but that material is not being displayed .
    2 when i select any of the available ,materials there is a error message displayed
    Material [ ] is not defined for Sales Org [ ] ,distr chan [ ] ,Language EN .
    Please help me in fixing these

    Hi,
    It is certain with respect to the error which displayed on your screen, that you have not defined the material to that sales area for which you wanted to process the order.
    So please extend the material to the sales area and also go to the  Additional data tab on the top left, and add  a text for EN language.
    please reward points if it helps you.
    Regards
    krishnavamshi.

  • Sales Org Extension

    Hi Experts,
    I have one requirement where i need to show existing sales org , distribution channel to user , in addition to this i need to show some two additional fields  copy from sales org and copy from Distn Chnl . I need to show the existing sales org for the material being changed in the copy from Sales field  and existing Distn Chnl for that material . so that all the existing characterstics should copied to the new sales organization . please help me how to show the existing sales organisation in copy from sales organisation for a particular material . 
    if i press F4 in Copy from existing Sales org field, i need to show all the existing Sales Organisation for the material being changed as available options.
    i tried creating listbox but it didnt work. Please help me
    Thanks in advance,
    Shrikanth

    Use FM F4IF_INT_TABLE_VALUE_REQUEST to show custom search help options.
    *& Report  ZTEST_SOURAV15
    REPORT ZTEST_SOURAV15.
    TABLES: mara, marc.
    PARAMETERS: matnr TYPE mara-matnr.
    PARAMETERS: werks TYPE marc-werks.
    TYPES : BEGIN OF ty_marc ,
    werks TYPE marc-werks ,
    END OF ty_marc.
    DATA : it_marc TYPE STANDARD TABLE OF ty_marc.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR werks.
      DATA: l_i_dynpfields TYPE STANDARD TABLE OF dynpread INITIAL SIZE 0,
            l_wa_dynpfields  TYPE dynpread.
      l_wa_dynpfields-fieldname = 'MATNR'.
      APPEND l_wa_dynpfields TO l_i_dynpfields.
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname                         = sy-repid
          dynumb                         = sy-dynnr
    *   TRANSLATE_TO_UPPER             = ' '
    *   REQUEST                        = ' '
    *   PERFORM_CONVERSION_EXITS       = ' '
    *   PERFORM_INPUT_CONVERSION       = ' '
    *   DETERMINE_LOOP_INDEX           = ' '
        TABLES
          dynpfields                     = l_i_dynpfields
       EXCEPTIONS
         invalid_abapworkarea           = 1
         invalid_dynprofield            = 2
         invalid_dynproname             = 3
         invalid_dynpronummer           = 4
         invalid_request                = 5
         no_fielddescription            = 6
         invalid_parameter              = 7
         undefind_error                 = 8
         double_conversion              = 9
         stepl_not_found                = 10
         OTHERS                         = 11
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      READ TABLE l_i_dynpfields INTO l_wa_dynpfields
      WITH KEY fieldname = 'MATNR'.
      IF sy-subrc = 0.
        DATA l_matnr TYPE matnr.
        l_matnr = l_wa_dynpfields-fieldvalue.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input        = l_matnr
          IMPORTING
            output       = l_matnr
          EXCEPTIONS
            length_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.
        SELECT werks FROM marc INTO TABLE it_marc WHERE matnr EQ l_matnr.
        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield    = 'WERKS'
            dynpprog    = sy-repid
            dynpnr      = sy-dynnr
            dynprofield = 'P_WERKS'
            value_org   = 'S'
          TABLES
            value_tab   = it_marc.
      ENDIF.
    START-OF-SELECTION.
      WRITE: / ' this is for testing'.

  • How to extend Sales org for a material being Changed

    Hi Experts,
    i need to extend sales org , distribution Channel for a material .
    my table look like this and having 6 fields shown below
      1             2         3               4            5                     6
    Sales org | Des | Distn Chnl | desc |  Copy from So | Copy from Dstn Chnl
    If the user enters the existing value in Copy From SO and Copy Fron Distn Chnl  .  Then i need to copy all the values corresponding to the Existing SO and Distrn Chnl to the Newly entered Sales Org . 
    the table im displaying in ALV , if user perss F4 in copy From SO and Copy From Distn  , i need to show the existing values for the material being changed , this is working fine and i am able to get the existing values.
    After user selects one of the existing value for SO and Distrn channel  , i need to copy all the values to newly created So and distrn Chnl  .
    i dont know how to proceed . Please help me to solve this problem.
    Thanks,
    Shrikanth

    You can use AET to extend the sales area data of BP.  However, it wont add the fields automatically in GUI, But the generated fields are available in the relevant DB tables.
    BP GUI transaction is no more supported . Im not sure why you want to work on GUI.
    Regards,
    Shaik

  • Free Goods determination -acess sequence sales org/ plant/material

    Hi
    I am trying to determine the free goods by choosing the key combination as Sales org/plant/material.
    The system is not determineing the free qty ,instead when i maintain the condition record with customer/Material key combination ,then the system is determineing the free qty.
    I also tried to put acess Sequence Sales org/plant/material above the Acess sequence customer/Material,but still the system not detrmineing the free qty in the order.
    can any one pl gide me how to solve this issue.
    regards
    shashi

    Hi
    Go to the access sequence where Sales org/Plant/Material are maintained as condition table.
    Now select the condition table and then click the node "Fields" on the left hand side of the screen.
    It may give a warning message that "Fields are not yet generated". Just ignore this and Enter once again.
    Do this until it takes you to a screen where you can see fields like KOMK-VKORG, KOMK-WERKS and KOMP-MATNR
    Now create the condition records and check in transaction by creating sales order. It shoudl work.
    Hope this helps.
    You can reward if it helps you

  • Sales org 2 view in material master

    hi gurus,
    Iam not able to see all fields in sales org 2 view in material master and i would like to know how to configure to restrict end users not to change it . thank you in advance.
    regards,
    Gopio

    Hi naga gopathi
    go to Spro->logistics general ->materials management->  there you select the options of material feilds and select the material type and click on till you reach the sales orgn 2  view , .
    In MMR settigs you can see table  wise so i think it should me MARA table. for sales orgn 2 view
    There you check the feilds wat you want is in display or supress mode 
    Regards
    Srinath

  • Creation of Sales org views for customers related to vendor

    Hello All,
                 Can any body tell me is there any functional module which can be used to created the sales org views for customers related to vendors.
    Regards
    Srinivas

    Hi Ravi,
    the number of sales area possible would be 6 sales area,
    yes you can of course use the common master data functionality
    After creating the organizational structure and relevant master records you want to use as the masters, that is, in the distribution channels and divisions you are going to use as a reference, you can group distribution channels and divisions separately for master data (which combines customer master and material master records), group condition records, or both master data and condition records.
    Letu2019s say you have a product range that is not different for the four different distribution channels you have (the channels could be telesales, retail, industry, and wholesale.) Neither is there a difference in the customersu2019 details when they purchase through one or the other. Thus, you will not want to create a multiple of four views of customer master and material master records. Merely create the customer master records and material master records in one of the distribution channels, such as retail. Then assign the other distribution channels you created in the organizational structure setup to this one.
    Donu2019t forget this means you can only create or change master data in the distribution channel that is being referenced. In the scenario above, this means you can only change data for the retail distribution channel. Even if you should access a customer or material master in change mode, press F4 (possible entries), and select telesales, industry, or wholesale, you will receive a message u201CSales area is not defined . . . u201D
    The same is true for the sharing of conditions. If conditions are shared, you need only create a condition in the distribution channel or division you are using as the reference. Obviously, this only pertains to conditions that have the distribution channel and/or division in their key, such as a price based on sales area
    Revert if helpful
    Mohit Singh

  • Determination of country based on Sales Org

    Hi Friends,
    I have sales Organization , I need to determine the country (Land1 field )
    , which table I need to check to that,
    Is there any direct relationship to get this or please provide the path forward to get this.
    Cheers
    Prashant

    parameters : p_vkorg like tvko-vkorg.
    data : v_vkorg like vbak-vkorg.
    data:  v_bukrs like ekpo-bukrs.
    data:  v_land1 like kna1-land1.
           select single vkorg bukrs into (v_vkorg , v_bukrs)
                   from tvko where
                        vkorg = p_vkorg.
                        if sy-subrc eq 0.
                        write:/ v_vkorg, v_bukrs.
                        else.
                        write:/ 'Invalid sales org'.
                        endif.
           select single land1 into v_land1 from t001 where bukrs = v_bukrs.
           write:/ 'Country', v_land1.
    check this ..
    regards,
    vijay.

  • Multiple Alternative ID 's dependent on Sales org

    Hi,
    Our CRM box is used by multiple countries and share the same product master. In addition to the Product ID each country has  its own specific country code.
    To achieve this, we have created multiple settypes and assigned to  alternative ID's.
    Now we dont know how to make these alternative ID's  dependent on Sales org. eg: ZALT1  is for Sales org 10 and ZALT2 for Sales org 11.
    Has anybody faced this requirement and able to find a solution.
    Regards,
    Shaik

    HI
    An alternative ID type can only be maintained in the header area of a product if it refers to a field from a single-line, organization-independent set type. As per my understanding I think Alt id is not supported for distribution dependent set types.
    Hence during the step "Create UI Configuration for ID Type " there is an error.
    Here is a workaround (without Alt ID)
    Create distribution dependent set types.
    follow steps to add distribution dependent set types to product:
    http://sites.google.com/site/rupeshpatil/tweets/prddcconfig
    Now you would need to enhance the product search component to search by these new fields.
    Hope this helps
    RP

  • Sales Org assign to Plant

    Hello Everyone,
    I would need your help to confirm the following is true or clarify some doubts:
    1. I understand that Sales Org (SOrg) is assigned to Plant   , thus :  Sorg := Plant
    2. Does this also Implies : SOrg + Distr Channel := Plant? Not necessary right? For this case, its not true / an invalid assignment right?
    3. Plant is assigned to Sales Org + Distr Channel.  Is it implicit that the Reverse is true? Is it implicit that Always the reverse is true, in general, for Any other organizational unit assignment relationships?   
    I believe that Sales Org := Plant and Plant  := Sales org + Distr Channel  and the reverse of each of both relationships are not true. Please confirm.
    4. Sales Org is Assigned to Plant but Plant is not Assigned to Sales Org right? Plant is also higher level in the organizational structure than Sales Org right?
    Thanks.
    Sincerely
    Bass
    SD Newbie
    Edited by: Bass Aton on Jan 2, 2011 5:20 PM

    Hi,
    I guess this will help you
    How to Configure a New Plant in SAP?
    Plant 0001 is the SAP defaults provide for your reference.
    OX14 - Define Valuation Area (Tick one only- Once your system go live, no more changes) Most company take the SAP recommended choice - Value Material Stock at Plant level Value Material Stock at Plant or Company Level If you valuate material stocks at plant level, the plant is the valuation area. If you valuate material stocks at company code level, the company code is the valuation area. The decision you make applies to the whole client.
    OX10 - Create / Change / View Plants
    OVXB - Create / Change / View Division
    OX18 - Assign Plant to company code e.g. 0001 - 0001 - All Plants Px1 - Plant Px1 Px2 u2013 Plant Px2
    OX19 - Assignment of company code to the Controlling Area
    OB38 - Assign company code to Credit Control Area
    OMJ7 - Assign business area to Plant/Valuation area and division e.g. Plant Px1 - Business Area Bx1 Bx2 Assign Valuation area to the Business Area .e.g. Valuation area Vx1 - Business Area Bx1 Business Area Bx2
    OMS0 - Assign Factory Calendar to the Plant and Business Area The plant plays an important role in the following areas: If you want to create by copying from existing plant: 1. Copy existing plant A to new plant B. All of plant Au2019s data in throughout the IMG will be created/copied for plant B. In some cases with plant A data that is not desired. In step 3 you must go through and correct invalid entries 2. Correct address information 3. Correct data copied to plant B as plant A (a) In Sales and Distribution -> Shipping -> Picking -> Determine Picking Location -> Assign Picking Locations (OVL3), delete entry where Shipping Point = plant A and Plant = plant B and press save. (b) In Sales and Distribution -> Shipping -> Basic Shipping Functions -> Shipping Point Determination -> Assign shipping points u2013 wherever plant B is found the shipping point is plant A. This must be changed to plant B. (c) In Enterprise Structure -> Maintain Structure -> Assignment -> Sales and Distribution -> Assign shipping point to plant u2013 delete plant B shipping point from the plant A assignment. (d) In Enterprise Structure -> Maintain Structure -> Definition -> Sales and Distribution -> Define, copy, delete, check shipping point u2013 copy shipping point plant A to shipping point plant B. Correct the description in the define section of this node. (e) In Sales and Distribution -> Shipping -> Picking -> Determine Picking Location -> Assign Picking Locations (OVL3), copy plant A entry to plant B entry, changing all data to plant B. (f) Check with Reorder buying group to determine MRP controllers for new plant. Remove plant A MRP controllers from plant B, and add controllers received from reorder buying group. IMG is Materials Management -> Consumption Based Planning -> Master Data -> Define MRP controllers (g) Define special procurement. IMG is Materials Management -> Consumption Based Planning -> Master Data -> Define special procurement type. (h) OMGN u2013 Assign customer in u201CSet up stock transport order u2013 [Plant]u201D. OMGN u2013 in u201CSet up stock transport order u2013 [Purchasing Document type]u201D; an entry was created for source plant B and plant A, this entry should have a UB order type and the check box should be off. Each plant needs a plant B UB entry created. (j) OMJ3 u2013 Delete incorrect entry in print parameters. Remove entry where plant = plant B & storage location = plant A. Create entry for plant B storage location B (k) Verify entry for new plant exists in OVLT picking output (l) Verify entry for new plant is correct in VP01 4. Manual configuration (a) Create plant customer number and assign to plant in OMGN. (b) OMJ3 u2013 set correct printer for plant B (c) OPK8 u2013 Set printer for plant for list LG01. This is for production orders. (d) Output determination OVLT (set printer), In addition to above, other changes based on customization in your installation needs to be done as well. Plants Definition : /NSPRO-IMG-Enterprise Structure-Definition-Logistic General-Define,copy,delete,check plant-Define Plant (In this, we are defining plants(s) under company which is defined earlier) /NSPRO-IMG-Enterprise Structure-Definition-Logistic General-Define,copy,delete,check plant- copy,delete,check plant-F6 to copy org. object from plant 0001 to defined plant(s). Storage Location : /NSPRO-IMG-Enterprise Structure-Definition-Materials Management-Maintain Storage Location-New Entries (Define required storage location(s) under different plant(s) ) /NSPRO-IMG-Enterprise Structure-Definition-Materials Management-Maintain Storage Location-Storage Location Description---- New Entries ( enter here addresses of each plants)
    Thanks
    Anil Hooda

  • Sales org is invalid for Account

    Hi expert's
                 I am working on CRM2007 . Whenever  I create a Trade Promotion and select Account type  as "Account" and Planning Account as a BP which I have assigned to sales org,I am getting an error "*Sales org is invalid for Account*."
    Kindly suggest
    Regards
    Subbaraju

    self

  • Reg different kinds of select stmts

    Hi All,
    Hope all are doing gud,
    cud any tell me different kinds of select stmts ????
    regards,
    abc xyz

    hi,
    SELECT
    Basic form
    SELECT result [target] FROM source [where] [GROUP BY fields] [ORDER BY order].
    Effect
    Retrieves an extract and/or a set of data from a database table or view (see Relational database ). SELECT belongs to the OPEN SQL command set.
    Each SELECT command consists of a series of clauses specifying different tasks:
    The SELECT result clause specifies
    whether the result of the selection is a table or a single record,
    which columns the result is meant to have and
    whether the result is allowed to include identical lines.
    The INTO target clause specifies the target area into which the selected data is to be read. If the target area is an internal table, the INTO clause specifies
    whether the selected data is to overwrite the contents of the internal table or
    whether the selected data is to be appended to the contents and
    whether the selected data is to be placed in the internal table all at once or in several packets.
    The INTO clause can also follow the FROM clause.
    You can omit the INTO clause. The system then makes the data available in the table work area (see TABLES ) dbtab . If the SELECT clause includes a "*", the command is processed like the identical SELECT * INTO dbtab FROM dbtab statement. If the SELECT clause contains a list a1 ... an , the command is executed like SELECT a1 ... an INTO CORRESPONDING FIELDS OF dbtab FROM dbtab .
    If the result of the selection is meant to be a table, the data is usually (for further information, see INTO -Klausel ) read line by line within a processing loop introduced by SELECT and concluded by ENDSELECT . For each line read, the processing passes through the loop once. If the result of the selection is meant to be a single record, the closing ENDSELECT is omitted.
    The FROM source clause the source (database table or view ) from which the data is to be selected. It also determines
    the type of client handling,
    the behavior for buffered tables and
    the maximum number of lines to be read.
    The WHERE where clause specifies the conditions which the result of the selection must satisfy. It thus determines the lines of the result table. Normally - i.e. unless a client field is specified in the WHERE clause - only data of the current client is selected. If you want to select across other clients, the FROM clause must include the addition ... CLIENT SPECIFIED .
    The GROUP-BY fields clause combines groups of lines together into single lines. A group is a set of lines which contain the same value for every database field in the GROUP BY clause.
    The ORDER-BY order clause stipulates how the lines of the result table are to be ordered.
    Each time the SELECT statement is executed, the system field SY-DBCNT contains the number of lines read so far. After ENDSELECT , SY-DBCNT contains the total number of lines read.
    The return code value is set as follows:
    SY-SUBRC = 0 At least one line was read.
    SY_SUBRC = 4 No lines were read.
    SY-SUBRC = 8 The search key was not fully qualified.
    (nur bei SELECT SINGLE ). The returned single record is any line of the solution set.
    Example
    Output the passenger list for the Lufthansa flight 0400 on 28.02.1995:
    TABLES SBOOK.
    SELECT * FROM SBOOK
      WHERE
        CARRID   = 'LH '      AND
        CONNID   = '0400'     AND
        FLDATE   = '19950228'
      ORDER BY PRIMARY KEY.
      WRITE: / SBOOK-BOOKID, SBOOK-CUSTOMID,   SBOOK-CUSTTYPE,
               SBOOK-SMOKER, SBOOK-LUGGWEIGHT, SBOOK-WUNIT,
               SBOOK-INVOICE.
    ENDSELECT.
    Performance
    In client/server environments, storing database tables in local buffers (see SAP buffering ) can save considerable amounts of time because the time required to make an access via the network is much more than that needed to access a locally buffered table.
    Notes
    A SELECT command on a table for which SAP buffering is defined in the ABAP/4 Dictionary is normally satisfied from the SAP buffer by bypassing the database. This does not apply with
    - <b>SELECT SINGLE FOR UPDATE
    - SELECT DISTINCT in the SELECT clause ,
    - BYPASSING BUFFER in the FROM clause ,
    - ORDER BY f1 ... fn in the ORDER-BY clause ,
    - aggregate functions in the SELECT clause ,
    - when using IS [NOT] NULL WHERE condition ,</b>
    or if the generic key part is not qualified in the WHERE-Bedingung for a generically buffered table.
    Authorization checks are not supported by the SELECT statement, so you must program these yourself.
    In dialog systems, the database system locking mechanism cannot always guarantee to synchronize the simultaneous access of several users to the same dataset. In many cases, it is therefore advisable to use the SAP locking mechanism .
    Changes to data in a database are only finalized after a database commit (see LUW ). Prior to this, any database update can be reversed by a database rollback (see Programming transactions ). At the lowest isolation level (see the section on the "uncommitted read" under Locking mechanism ), this can result in the dataset selected by the SELECT command not really being written to the database. While a program is selecting data, a second program can add, change or delete lines at the same time. Then, the changes made by the second program are reversed by rolling back the database system. The selection of the first program thus reflects only a very temporary state of the database. If such "phantom data" is not acceptable for a program, you must either use the SAP locking mechanism or at least set the isolation level of the database system to "committed read" (see Locking mechanism ).
    In a SELECT-ENDSELECT loop, the CONTINUE statement terminates the current loop pass prematurely and starts the next.
    If one of the statements in a SELECT ... ENDSELECT loop results in a database commit, the cursor belonging to the SELECT ... ENDSELECT loop is lost and the processing terminates with a runtime error. Since each screen change automatically generates a database commit, statements such as CALL SCREEN , CALL DIALOG , CALL TRANSACTION or MESSAGE are not allowed within a SELECT ... ENDSELECT loop.
    Related OPEN CURSOR , FETCH und CLOSE CURSOR
    SELECT clause
    Variants
    1. <b>SELECT [SINGLE [FOR UPDATE] | DISTINCT] *
    2. SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn
    3. SELECT [SINGLE [FOR UPDATE] | DISTINCT] (itab)</b> Effect
    The result of a SELECT statement is itself a table . The SELECT clause describes which columns this table is supposed to have.
    In addition, you can use the optional addition SINGLE or DISTINCT if you want only certain lines of the solution set to be visible for the calling program:
    SINGLE The result of the selection is a single record . If this record cannot be uniquely identified, the first line of the solution set is selected. The addition FOR UPDATE protects the selected record against parallel changes by other transactions until the next database commit occurs (see LUW and Database locking ). If the database system detects a deadlock, the result is a runtime error.
    DISTINCT Any lines which occur more than once are automatically removed from the selected dataset.
    Note
    To ensure that a record is uniquely determined, you can fully qualify all fields of the primary key by linking them together with AND in the WHERE condition.
    Note
    Performance
    The additions SINGLE FOR UPDATE and DISTINCT exclude the use of SAP buffering .
    The addition DISTINCT requires sorting on the database server and should therefore only be specified if duplicates are likely to occur.
    Variant 1
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] *
    Effect
    In the result set, the columns correspond exactly in terms of order, ABAP/4 Dictionary type and length to the fields of the database table (or view ) specified in the FROM clause .
    Example
    Output all flight connections from Frankfurt to New York:
    TABLES SPFLI.
    SELECT * FROM SPFLI
             WHERE
               CITYFROM = 'FRANKFURT' AND
               CITYTO   = 'NEW YORK'.
      WRITE: / SPFLI-CARRID, SPFLI-CONNID.
    ENDSELECT.
    Example
    Output all free seats on the Lufthansa flight 0400 on 28.02.1995:
    TABLES SFLIGHT.
    DATA   SEATSFREE TYPE I.
    SELECT SINGLE * FROM SFLIGHT
                    WHERE
                      CARRID   = 'LH '      AND
                      CONNID   = '0400'     AND
                      FLDATE   = '19950228'.
    SEATSFREE = SFLIGHT-SEATSMAX - SFLIGHT-SEATSOCC.
    WRITE: / SFLIGHT-CARRID, SFLIGHT-CONNID,
             SFLIGHT-FLDATE, SEATSFREE.
    Variant 2
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn
    Effect
    The order, ABAP/4 Dictionary type and length of the columns of the result set are explicitly defined by the list s1 ... sn . Each si has the form
    ai or ai AS bi .
    Here, ai stands either for
    a field f of the database table or
    a aggregate print.
    bi is an alternative name for the i-th column of the result set.
    When using INTO CORRESPONDING FIELDS OF wa in the INTO clause , you can specify an alternative column name to assign a column of the result set uniquely to a column of the target area.
    An aggregate print uses an aggregate function to group together data from one or all columns of the database table. Aggregate prints consist of three or four components:
    An aggregate function immediately followed by an opening parenthesis DISTINCT (optional) The database field f A closing parenthesis
    All components of a print must be separated by at least one blank.
    The following aggregate functions are available:
    MAX Returns the greatest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    MIN Returns the smallest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    AVG Returns the average value in the column determined by the database field f for the selected lines. AVG can only apply to a numeric field. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    SUM Returns the sum of all values in the column determined by the database field f for the selected lines. SUM can only apply to a numeric field. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    COUNT Returns the number of different values in the column determined by the database field f for the selected lines. Specifying DISTINCT is obligatory here. NULL values are ignored unless all values in a column are NULL values. In this case, the result is 0
    COUNT( * ) Returns the number of selected lines. If the SELECT command contains a GROUP BY clause , it returns the number of lines for each group. The form COUNT(*) is also allowed.
    If ai is a field f , MAX( f ) , MIN( f ) or SUM( f ) , the corresponding column of the result set has the same ABAP/4 Dictionary format as f . With COUNT( f ) or COUNT( * ) , the column has the type INT4 , with AVG( f ) the type FLTP .
    If you specify aggregate functions together with one or more database fields in a SELECT clause, all database fields not used in one of the aggregate functions must be listed in the GROUP-BY clause . Here, the result of the selection is a table.
    If only aggregate functions occur in the SELECT clause, the result of the selection is a single record. Here, the SELECT command is not followed later by an ENDSELECT .
    Notes
    This variant is not available for pooled tables and cluster tables .
    If the SELECT clause contains a database field of type LCHAR or LRAW , you must specify the appropriate length field immediately before.
    Notes
    Performance
    Specifying aggregate functions excludes the use of SAP buffering .
    Since many database systems do not manage the number of table lines and therefore have to retrieve this at some cost, the function COUNT( * ) is not suitable for checking whether a table contains a line or not. To do this, it is best to use SELECT SINGLE f ... for any table field f .
    If you only want to select certain columns of a database table, you are recommended to specify a list of fields in the SELECT clause or to use a View .
    Examples
    Output all flight destinations for Lufthansa flights from Frankfurt:
    TABLES SPFLI.
    DATA   TARGET LIKE SPFLI-CITYTO.
    SELECT DISTINCT CITYTO
           INTO TARGET FROM SPFLI
           WHERE
             CARRID   = 'LH '       AND
             CITYFROM = 'FRANKFURT'.
      WRITE: / TARGET.
    ENDSELECT.
    Output the number of airline carriers which fly to New York:
    TABLES SPFLI.
    DATA   COUNT TYPE I.
    SELECT COUNT( DISTINCT CARRID )
           INTO COUNT FROM SPFLI
           WHERE
             CITYTO = 'NEW YORK'.
    WRITE: / COUNT.
    Output the number of passengers, the total weight and the average weight of luggage for all Lufthansa flights on 28.02.1995:
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Variant 3
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] (itab)
    Effect
    Works like SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn if the internal table itab contains the list s1 ... sn as ABAP/4 source code, and like SELECT [SINGLE [FOR UPDATE] | DISTINCT] * , if itab is empty. The internal table itab can only have one field which must be of type C and cannot be more than 72 characters long. itab must appear in parentheses and there should be no blanks between the parentheses and the table name.
    Note
    With this variant, the same restrictions apply as for SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn .
    Example
    Output all Lufthansa flight routes:
    TABLES: SPFLI.
    DATA:   FTAB(72) OCCURS 5 WITH HEADER LINE.
    REFRESH FTAB.
    FTAB = 'CITYFROM'. APPEND FTAB.
    FTAB = 'CITYTO'.   APPEND FTAB.
    SELECT DISTINCT (FTAB)
           INTO CORRESPONDING FIELDS OF SPFLI
           FROM SPFLI
           WHERE
             CARRID   = 'LH'.
      WRITE: / SPFLI-CITYFROM, SPFLI-CITYTO.
    ENDSELECT.
    check this one:
    http://www.sts.tu-burg.de/teaching/sap_r3/ABAP4/select.htm

  • Select stmt taking long time.

    Hi,
    This select stmt is taking very long time to execute. Can you please guide me to improve it.
    SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
              FROM LIKP
              INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
              INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
              INTO CORRESPONDING FIELDS OF TABLE IT_OUTPUT
              WHERE LIKP~LFDAT IN S_LFDAT
                    AND LIKP~KUNNR IN S_KUNNR
                    AND LIKP~LIFSK = P_LIFSK.
    Thanks
    Veni.

    >> SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
    >> FROM LIKP
    >> INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
    >> INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
    >> INTO CORRESPONDING FIELDS OF TABLE IT_OUTPUT
    >> WHERE LIKP~LFDAT IN S_LFDAT
    >> AND LIKP~KUNNR IN S_KUNNR
    >> AND LIKP~LIFSK = P_LIFSK.
    Based on the select that you have in your post, this is what I see.
    As output, you only need fields from LIKP and only one field from VBAK.
    All your fields on the WHERE clause is on LIKP data.
    You only need LIPS for the Sales document number.
    Can you please make a copy of your program and try this below code?
    It would be interesting to see if the extra vgbel sort would help.
    TYPES:
      BEGIN OF TY_LIKP,
        VBELN TYPE LIKP-VBELN,
        LFDAT TYPE LIKP-LFDAT,
        KUNNR TYPE LIKP-KUNNR,
        KNKLI TYPE LIKP-KNKLI,
        NETWR TYPE VBAK-NETWR,
        VGBEL TYPE LIPS-VGBEL,
      END OF TY_LIKP.
    DATA:
      I_LIKP TYPE STANDARD TABLE OF TY_LIKP
        INITIAL SIZE 0
        WITH HEADER LINE,
      BEGIN OF I_VGBEL OCCURS 0,
        VGBEL TYPE LIPS-VGBEL,
      END OF I_VGBEL,
      BEGIN OF I_VBAK OCCURS 0,
        VBELN TYPE VBAK-VBELN,
        NETWR TYPE VBAK-NETWR,
      END OF I_VBAK.
    FIELD-SYMBOLS:
      <FS_LIKP> TYPE TY_LIKP.
    SELECT LIKP~VBELN LIKP~LFDAT LIKP~KUNNR LIKP~KNKLI LIPS~VGBEL
      INTO CORRESPONDING FIELDS OF TABLE I_LIKP
      FROM LIKP
      JOIN LIPS ON LIPS~VBELN EQ LIKP~VBELN
      WHERE LIKP~LFDAT IN S_LFDAT
      AND   LIKP~KUNNR IN S_KUNNR
      AND   LIKP~LIFSK EQ P_LIFSK.
    IF I_LIKP[] IS NOT INITIAL.
      LOOP AT I_LIKP ASSIGNING <FS_LIKP>.
        CLEAR I_VGBEL.
        I_VGBEL-VGBEL = <FS_LIKP>-VGBEL.
        APPEND I_VGBEL.
      ENDLOOP.
      SORT I_VGBEL.
      DELETE ADJACENT DUPLICATES FROM I_VGBEL.
      IF I_VGBEL[] IS NOT INITIAL.
        SELECT VBELN NETWR INTO TABLE I_VBAK
          FROM VBAK
          FOR ALL ENTRIES IN I_VGBEL
          WHERE VBELN EQ I_VGBEL-VGBEL.
        SORT I_VBAK BY VBELN.
        FREE I_VGBEL.
        LOOP AT I_LIKP ASSIGNING <FS_LIKP>.
            CLEAR I_VBAK.
            READ TABLE I_VBAK WITH KEY VBELN = <FS_LIKP>-VGBEL
                                       BINARY SEARCH.
            IF SY-SUBRC EQ 0.
              <FS_LIKP>-NETWR = I_VBAK-NETWR.
    * Note that you don't need to do the Modify statement here
    * because of the field symbol
            ENDIF.
          ENDIF.
        ENDLOOP.
    * Just ignore I_LIKP-VGBEL from all your reporting needs
      ENDIF.
    ENDIF.

Maybe you are looking for