Select query for KONV and VBAK table

hy Experts.
Please Help me For this Query, i got error on it.
I wnt to take KONV-KBETR (RATE FIELD) for particular  SO number. and i used following query but it gives error i cant relate VBAK & KONV table.
Please do needful
SELECT KBETR KNUMV FROM KONV INTO (ITAB-KBETR, ITAB-KNUMV) WHERE VBAK-KNUMV = KONV-KNUMV AND VBAK-VBELN IN VBELN.
Thnks
Bhavesh Panchal.

Hello Thnks For Reply,
but still i cant take solution. i am making a Sales order Rports. i got all field but i cant fetch filed for RATE and Pending Order Value.
Please check following  Code. if need to change u can.
Thnks
Bhavesh Panchal.
REPORT  ZTESTCODE.
TYPE-POOLS:slis.
TABLES: VBEP , VBAP ,  VBPA , VBKD , VBAK , LIKP , LIPS , VBUP , VBBE, KONV, KNA1.
DATA :BEGIN OF itab  OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
EDATU LIKE VBEP-EDATU,
KNUMV LIKE VBAK-KNUMV,
WMENG LIKE VBEP-WMENG,
BMENG LIKE VBEP-BMENG,
LFIMG LIKE LIPS-LFIMG,
OMENG LIKE VBBE-OMENG,
POSAR LIKE VBAP-POSAR,
NETWR LIKE VBAP-NETWR,
NTGEW LIKE VBAP-NTGEW,
KBETR LIKE KOMV-KBETR,
KUNNR LIKE  VBAK-KUNNR,
NAME1 LIKE  KNA1-NAME1,
*BRGEW LIKE  VBAP-BRGEW,
BSTKD LIKE VBKD-BSTKD,
BSTDK LIKE VBKD-BSTDK,
LFSTA LIKE VBUP-LFSTA,
*KNUMV LIKE VBAK-KNUMV,
*posnr LIKE LIPS-POSNR,
*NETWR LIKE VBAK-NETWR,
BRGEW LIKE VBAP-BRGEW,
LFDAT LIKE LIKP-LFDAT,
*NTGEW LIKE LIKP-NTGEW,
DELIVERY LIKE LIPS-VBELN,
WEIGHT like VBAP-NTGEW,
END OF itab.
*variable for Report ID
DATA: v_repid LIKE sy-repid .
*declaration for fieldcatalog
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fieldcat TYPE slis_fieldcat_alv.
DATA: it_listheader TYPE slis_t_listheader.
declartion for layout
DATA: alv_layout TYPE slis_layout_alv.
*Title displayed when the alv list is displayed
*DATA:  i_title_main TYPE lvc_title VALUE 'FIRST LIST DISPLAYED'.
DATA:  i_title_main TYPE lvc_title VALUE 'Reports : Bhavesh Pacnhal'.
INITIALIZATION.
  v_repid = sy-repid.
  PERFORM build_fieldcatlog.
  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
     SELECT-OPTIONS : VBELN FOR VBAK-VBELN ,
                      KUNNR FOR VBPA-KUNNR ,
                      EDATU for ITAB-EDATU.
  SELECTION-SCREEN: END OF BLOCK b1.
START-OF-SELECTION.
  PERFORM data_retrieval.
  PERFORM build_listheader USING it_listheader.
  PERFORM display_alv_report.
FORM build_fieldcatlog.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'VBELN'.
  wa_fieldcat-seltext_m = 'SalesOrderNo'.
  wa_fieldcat-outputlen = '12'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field for Customer Name.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'NAME1'.
  wa_fieldcat-seltext_m = 'Customer Name'.
  wa_fieldcat-outputlen = '30'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field For Po Number.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'BSTKD'.
  wa_fieldcat-seltext_m = 'PO No'.
  wa_fieldcat-outputlen = '20'.
  append wa_fieldcat to i_fieldcat.
  clear wa_fieldcat.
Field For Order Value
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'NETWR'.
  wa_fieldcat-seltext_m = 'Order Value '.
  wa_fieldcat-outputlen = '12'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field For Po Date.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'BSTDK'.
  wa_fieldcat-seltext_m = 'PO Date'.
  wa_fieldcat-outputlen = '20'.
  append wa_fieldcat to i_fieldcat.
  clear wa_fieldcat.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-fieldname = 'POSNR'.
wa_fieldcat-seltext_m = 'Item No'.
wa_fieldcat-outputlen = '20'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'EDATU'.
  wa_fieldcat-seltext_m = 'Delivery Date'.
  wa_fieldcat-outputlen = '12'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
wa_fieldcat-tabname = 'VBAP'.
wa_fieldcat-fieldname = 'KWMENG'.
wa_fieldcat-seltext_m = 'Order QTY VABP.'.
wa_fieldcat-outputlen = '14'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
Field For Order Qty.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'WMENG'.
  wa_fieldcat-seltext_m = 'Ord.QT.WMEN.'.
  wa_fieldcat-outputlen = '20'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field For Order Qty.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'BMENG'.
  wa_fieldcat-seltext_m = 'Ord.QT.BMEN.'.
  wa_fieldcat-outputlen = '20'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
field For Delivery Qty.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'LFMING'.
  wa_fieldcat-seltext_m = 'DEL QTY.'.
  wa_fieldcat-outputlen = '20'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field For Open Qty from ITAB.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'OMENG'.
  wa_fieldcat-seltext_m = 'OPEN QTY.'.
  wa_fieldcat-outputlen = '20'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field For Pending Weight from ITAB.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'BRGEW'.
  wa_fieldcat-seltext_m = 'Pending Weight'.
  wa_fieldcat-outputlen = '12'.
  append wa_fieldcat to i_fieldcat.
  clear wa_fieldcat.
Field For netweight.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'NTGEW'.
  wa_fieldcat-seltext_m = 'Net Weight'.
  wa_fieldcat-outputlen = '20'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
Field For Actual Delivery.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'LFDAT'.
  wa_fieldcat-seltext_m = 'Actual Delivery'.
  wa_fieldcat-outputlen = '12'.
  append wa_fieldcat to i_fieldcat.
  clear wa_fieldcat.
  wa_fieldcat-tabname = 'ITAB'.
  wa_fieldcat-fieldname = 'KBETR'.
  wa_fieldcat-seltext_m = 'RATE'.
  wa_fieldcat-outputlen = '20'.
  append wa_fieldcat to i_fieldcat.
  clear wa_fieldcat.
Field For Actual Delivery.
wa_fieldcat-tabname = 'LIPS'.
wa_fieldcat-fieldname = 'POSNR'.
wa_fieldcat-seltext_m = 'Delivery ITEM'.
wa_fieldcat-outputlen = '20'.
append wa_fieldcat to i_fieldcat.
clear wa_fieldcat.
Field For Pending Value.
VBUP-LFSTA
wa_fieldcat-tabname = 'VBUP'.
wa_fieldcat-fieldname = 'LFSTA'.
wa_fieldcat-seltext_m = 'Pending Value'.
wa_fieldcat-outputlen = '20'.
append wa_fieldcat to i_fieldcat.
clear wa_fieldcat.
Field For pending weight.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-fieldname = 'ITAB-OMENG * KOMV-KBETR'.
wa_fieldcat-seltext_m = 'Pending VALUE'.
wa_fieldcat-outputlen = '20'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
ENDFORM.                    "BUILD_FIELDCATLOG
FORM data_retrieval.
SELECT VBELN  NETWR KUNNR FROM VBAK INTO (ITAB-VBELN,ITAB-NETWR,ITAB-KUNNR) WHERE VBELN IN VBELN .
SELECT POSNR POSAR BRGEW FROM VBAP INTO (ITAB-POSNR,ITAB-POSAR,ITAB-BRGEW) WHERE VBELN = ITAB-VBELN .
SELECT EDATU FROM VBEP INTO (ITAB-EDATU) WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR.
SELECT NAME1 FROM KNA1 INTO (ITAB-NAME1) WHERE KUNNR = ITAB-KUNNR .
SELECT BSTKD BSTDK FROM VBKD INTO (ITAB-BSTKD,ITAB-BSTDK) WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR.
SELECT VBELN LFIMG FROM LIPS INTO (ITAB-DELIVERY, ITAB-LFIMG) WHERE VGBEL = ITAB-VBELN AND VGPOS = ITAB-POSNR.
SELECT LFDAT NTGEW FROM LIKP INTO (ITAB-LFDAT,ITAB-NTGEW) WHERE VBELN = ITAB-DELIVERY .
SELECT WMENG BMENG FROM VBEP INTO (ITAB-WMENG,ITAB-BMENG) WHERE VBELN IN VBELN .
SELECT SINGLE OMENG FROM VBBE INTO (ITAB-OMENG) WHERE VBELN IN VBELN.
SELECT SINGLE NETWR FROM VBAK INTO (ITAB-NETWR) WHERE VBELN IN VBELN.
SELECT KNUMV FROM VBAK INTO (ITAB-KNUMV) WHERE VBELN IN VBELN.
*SELECT KBETR KNUMV FROM KONV INTO (ITAB-KBETR, ITAB-KNUMV) WHERE KNUMV = VBAK-KNUMV.
*assign VAR1 = itab-kbetr.
*append itab.
*ENDSELECT.
SELECT KBETR KNUMV FROM KONV INTO (ITAB-KBETR, ITAB-KNUMV)WHERE KNUMV = VBAK-KNUMV.
ITAB-KBETR = KONV-KBETR.
ENDSELECT.
APPEND ITAB.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
*ENDSELECT.
ENDFORM.                    "data_retrieval
FORM build_listheader  USING it_listheader TYPE slis_t_listheader.
DATA HLINE TYPE SLIS_LISTHEADER.
  DATA: ls_line TYPE slis_listheader.
bhavesh
HLINE-INFO = 'report Developed by Bhavesh'.
HLINE-TYP = 'H'.
Header
Bhavesh
  CLEAR ls_line.
  ls_line-typ  = 'H'.
LS_LINE-KEY: not used for this type
  ls_line-info = 'Sales ORDER Report'.
  APPEND ls_line TO it_listheader.
bhavesh
***Selection
  CLEAR ls_line.
  ls_line-typ  = 'S'.
  ls_line-key  = 'Key 1'.
  ls_line-info = 'SFEL'.
  APPEND ls_line TO it_listheader.
  ls_line-key  = 'Key 2'.
  ls_line-info = 'SFEL'.
  APPEND ls_line TO it_listheader.
***Action
  CLEAR ls_line.
  ls_line-typ  = 'A'.
LS_LINE-KEY: not used for this type
  ls_line-info = 'Status list'.
  APPEND ls_line TO it_listheader.
  ENDFORM.                    "BUILD_LISTHEADER
*ENDFORM.                   "build_listheader
FORM display_alv_report.
  v_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = v_repid
   I_CALLBACK_PF_STATUS_SET          = 'STATUS'(002)
     i_callback_user_command           = 'USER_COMMAND'
   i_callback_top_of_page            = 'TOP_OF_PAGE'
     i_grid_title                      = 'SFEL SALES EXPEDITING REPORT'
     i_background_id         = 'ALV_BACKGROUND'
  I_GRID_SETTINGS                   =
  IS_LAYOUT                         = LAYO
  IS_LAYOUT                         = ALV_LAYOUT
    it_fieldcat                       = i_fieldcat[]
  IT_EXCLUDING                      =
  IT_SPECIAL_GROUPS                 =
  IT_SORT                           =
  IT_FILTER                         =
  IS_SEL_HIDE                       =
    i_default                         = 'ZLAY1'
    I_SAVE                            = 'A'
    is_variant                        = i_variant
    IT_EVENTS                         = V_EVENTS
    TABLES
      t_outtab                          = itab[]
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.
ENDFORM.                    "display_alv_report
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_listheader[].
     i_logo             = 'ENJOYSAP_LOGO'.
   I_END_OF_LIST_GRID       =
ENDFORM.                    "TOP_OF_PAGE

Similar Messages

  • Select query for fetching from 3 tables.

    Can we have a single Select query for fetching same fields (kappl,kschl,vkorg,vtweg,spart,kunwe,datbi,knuma,datab,knumh)
    from 3 tables >> KOTE707,KOTE708 and KOTE709 into an internal table for a particular KUNNR?
    Regards,
    Shashank.

    Hi,
    If you have kunnr field in all the 3 tables then it is possible. use inner join as below
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
                p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
             fldate TYPE sflight-fldate,
             carrname TYPE scarr-carrname,
             connid   TYPE spfli-connid,
           END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
                   WITH UNIQUE KEY fldate carrname connid.
    SELECT c~carrname p~connid f~fldate
           INTO CORRESPONDING FIELDS OF TABLE itab
           FROM ( ( scarr AS c
             INNER JOIN spfli AS p ON p~carrid   = c~carrid
                                  AND p~cityfrom = p_cityfr
                                  AND p~cityto   = p_cityto )
             INNER JOIN sflight AS f ON f~carrid = p~carrid
                                    AND f~connid = p~connid ).
    LOOP AT itab INTO wa.
      WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    <b>Reward Points if this helps,</b>
    Satish

  • How to write select query for all the user tables in database

    Can any one tell me how to select the columns from all the user tables in a database
    Here I had 3columns as input...
    1.phone no
    2.memberid
    3.sub no.
    I have to select call time,record,agn from all the tables in a database...all database tables have the same column names but some may have additional columns..
    Eg: select call time, record,agn from ah_t_table where phone no= 6186759765,memberid=j34563298
    Query has to execute not only for this table but for all user tables in the database..all tables will start with ah_t
    I am trying for this query since 30days...
    Help me please....any kind of help is appreciated.....

    Hi,
    user13113704 wrote:
    ... i need to include the symbol (') for the numbers(values) to get selected..
    eg: phone no= '6284056879'To include a single-quote in a string literal, use 2 or them in a row, as shown below.
    Starting in Oracle 10, you can also use Q-notation:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements003.htm#i42617
    ...and also can you tell me how to execute the output of this script. What front end are you using? If it's SQL*Plus, then you can SPOOL the query to a file, and then execute that file, like this:
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    -- Run preliminary query to generate main query
    SPOOL     c:\my_sql_dir\all_ah_t.sql
    SELECT       'select call time, record, agn from '
    ||       owner
    ||       '.'
    ||       table_name
    ||       ' where phone_no = ''6186759765'' and memberid = j34563298'
    ||       CASE
               WHEN ROW_NUMBER () OVER ( ORDER BY  owner          DESC
                              ,        table_name      DESC
                              ) = 1
               THEN  ';'
               ELSE  ' UNION ALL'
           END     AS txt
    FROM       all_tables
    WHERE       SUBSTR (table_name, 1, 4)     = 'AH_T'
    ORDER BY  owner
    ,       table_name
    SPOOL     OFF
    -- Restore SQL*Plus features that interfere with raw output (if desired)
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    -- Run main query:
    @c:\my_sql_dir\all_ah_t.sql
    so that i form a temporary view for this script as a table(or store the result in a temp table) and my problem will be solved..Sorry, I don't understand. What is a "temporary view"?

  • Select Query for smart form-invoice

    Hi Folks,
    I have to fetch the following fields as per the requirement for desiging a invoice smartform.I had copied lb_bill_invoice smartform into z format.
    Can anyone here please give me the select query for the same.
    fields to fetched are as follows:-
    1.vbrp-arktx,
    2.vbrp-fkimg,
    3.konv-kbetr with respect to vbrk-knumv
    4.konv-kwert.
    And also what all I have to give in format interface and global definitions of the smartform.
    please help  me in this regard.
    Points will be given.
    K.Kiran.

    Hi,
    declare the variables V_arktx(40) and v_Qty like vbrp-fkimp  and other varaibles for Kbetr, kwert, knumv on the global definitions.
    select  single arktx fkimg into (v_arktx, v_qty) from vbrp
    where vbeln = LBBIL_IT_REFPURORD-BIL_NUMBER.
    select single knumv into v_knumv from vbrk where where vbeln = LBBIL_IT_REFPURORD-BIL_NUMBER.
    this select has to fire in the item level and in the loop.
    so have to write in the correct place.
    select kbetr kwert into (v_kbetr, v_kwert) from konv
    where where knumv = v_knumv and kposn = LBBIL_IT_REFPURORD-ITM_NUMBER.
    regards,
    anji

  • Select query for fields in selection screen

    SELECT * FROM hrus_d2
               INTO TABLE ta_list
               WHERE us_name IN subs_obj
               and begdat in date_ran.
              and enddat in date_ran
    How can I rewrite the above query for high and low ranges of date_ran field in condition? It doesn't allow in operator with date_ran-low.Can u please help me out

    Hi
    rahul
    SELECT *
    FROM hrus_d2
    INTO TABLE ta_list
    WHERE us_name IN subs_obj
    and begdat = date_ran-low
    and enddat = date_ran -high.
    u can write like this or i amnot getting why u r expliciting this date u can give directly as
    SELECT *
    FROM hrus_d2
    INTO TABLE ta_list
    WHERE us_name IN subs_obj
    date in date_ran.
    plzz reward if i am usefull to u in any way.. plzz dont forget to reward

  • Can any one send select query for this?

    Hi,
    can any one plese send select query for the following query.please send as early as possible.
    Loop through the I_BSID internal table to fill records in I_OUTPUT.Combine data from I_BSID, I_KNKK, I_KNKK_KNKLI, I_KNA1 and I_KNVV into I_OUTPUT based on the linking conditions .Field Description Source are
    I_OUTPUT-BUKRS     Company code     I_BSID-BUKRS
    I_OUTPUT-KUNNR     Customer number     I_BSID-KUNNR
    I_OUTPUT-NAME1     Customer Name     I_KNA1-NAME1
    I_OUTPUT-KNKLI     Credit account     I_KNKK-KNKLI
    I_OUTPUT-KDGRP     Customer Group     I_KNKK-KDGRP
    I_OUTPUT-KLIMK     Credit Limit     I_KNKK_KNKLI-KLIMK
    I_OUTPUT-KVGR1     Business Unit     I_KNVV-KVGR1
    I_OUTPUT-REBZG     Invoice Number     I_BSID-REBZG
    I_OUTPUT-BLDAT     Invoice Date     I_BSID-BLDAT
    I_OUTPUT-WAERS     Document Currency     I_BSID-WAERS
    I_OUTPUT-DUE_DATE     Due Date     Based on below
    Calculation
      Get the Payment terms days combining I_BSID and I_T052 based on the linking conditions mentioned above.    Note : a) Baseline Date : If baseline date I_BSID-ZFBDT is blank , use the Document Date.b) Payment Term Days :If I_BSID-ZBD3T is not blank, take this as Payment Term Days for Due date calculation.
                       If I_BSID-ZBD3T is Blank, then get payment term days from I_T052 based on I_BSID-ZTERM. If there are more than one record in I_T052 for the given Payment term, get the day part from baseline date and select the first record where the day limit I_T052-ZTAGG is greater than the day part.If I_BSID-ZBD3T is blank and I_BSID-ZTERM is also blank, then take Y000 (Due Immediately) as Payment term and proceed with the above logic. Set the payment term field blank while printing.
    Calculate Due date : For Debits, Determine Due Date = Baseline Date + Payment term Days(not discount days)                                                          For  Credits  Due date = Baseline date.Then, move the amount I_BSID-DMBTR to respective buckets (Not yet Due, Current Due, Past due 1-30, Past Due 31-60 etc.)  Based on the due date.
    Thanks&Regards,
    praveen kumar.A

    HI,
    To get Open Items you can use Function module:
    data:i_items TYPE STANDARD TABLE OF rfpos.
    CALL FUNCTION 'CUSTOMER_OPEN_ITEMS'
    EXPORTING
    bukrs = p_bukrs
    kunnr = wa_customer-kunnr
    TABLES
    t_postab = i_items
    EXCEPTIONS
    no_open_items = 1
    OTHERS = 2.
    Table I_items will have all the open items for that Customer in the given company code.
    Well for Clear Items: Try
    GET_CLEARED_ITEMS or FMITPOFM_CLEARED_ITEMS_GET.
    Hope it helps.
    Manish

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

  • How to Create a Parameterized Report - The select "- ALL-" for department and manager not working.

    I downloaded the OEHR Sample Objects application and followed the steps in Oracle® Application Express Advanced Tutorials
    Release 3.2.
    The parameters and report seem to be working correctly except when I enter "all" for department or manager I get no matching hits.
    What's the most efficient way to retrieve "all" if the users selects all for dept and mgr - thus we'd want to return all records in the table.
    Region snipprt
    Enter Search
    Search Employee
    Dept
    - ALL -
    Administration
    Marketing
    Purchasing
    Human Resources
    Shipping
    IT
    Public Relations
    Sales
    Executive
    Finance
    Accounting
    Treasury
    Corporate Tax
    Control And Credit
    Shareholder Services
    Benefits
    Manufacturing
    Construction
    Contracting
    Operations
    IT Support
    NOC
    IT Helpdesk
    Government Sales
    Retail Sales
    Recruiting
    Payroll
    Mgr
    - ALL -
    Steven King
    Neena Kochhar
    Lex De Haan
    Alexander Hunold
    Nancy Greenberg
    Den Raphaely
    Matthew Weiss
    Adam Fripp
    Payam Kaufling
    Shanta Vollman
    Kevin Mourgos
    John Russell
    Karen Partners
    Alberto Errazuriz
    Gerald Cambrault
    Eleni Zlotkey
    Michael Hartstein
    Shelley Higgins
    The following is the sql that was provided as part of the turitoral.
    SELECT
       "OEHR_EMPLOYEES"."EMPLOYEE_ID" "EMPLOYEE_ID",
       "OEHR_EMPLOYEES"."FIRST_NAME" "FIRST_NAME",
       "OEHR_EMPLOYEES"."LAST_NAME" "LAST_NAME",
       "OEHR_EMPLOYEES"."EMAIL" "EMAIL",
       "OEHR_EMPLOYEES"."PHONE_NUMBER" "PHONE_NUMBER",
       "OEHR_EMPLOYEES"."HIRE_DATE" "HIRE_DATE",
       "OEHR_EMPLOYEES"."JOB_ID" "JOB_ID",
       "OEHR_EMPLOYEES"."SALARY" "SALARY",
       "OEHR_EMPLOYEES"."COMMISSION_PCT" "COMMISSION_PCT",
       "OEHR_EMPLOYEES"."MANAGER_ID" "MANAGER_ID",
       "OEHR_EMPLOYEES"."DEPARTMENT_ID" "DEPARTMENT_ID"
    FROM
       "#OWNER#"."OEHR_EMPLOYEES" "OEHR_EMPLOYEES"
    WHERE
         (lower(first_name) like '%' || lower(:P1_NAME) || '%' OR
          lower(last_name) like '%' || lower(:P1_NAME) || '%')
    AND department_id = decode(:P1_DEPT,'%null%',department_id,:P1_DEPT)
    AND manager_id = decode(:P1_MGR,'%null%',manager_id,:P1_MGR)

    Hi,
    Use this..
    SELECT
       "OEHR_EMPLOYEES"."EMPLOYEE_ID" "EMPLOYEE_ID",
       "OEHR_EMPLOYEES"."FIRST_NAME" "FIRST_NAME",
       "OEHR_EMPLOYEES"."LAST_NAME" "LAST_NAME",
       "OEHR_EMPLOYEES"."EMAIL" "EMAIL",
       "OEHR_EMPLOYEES"."PHONE_NUMBER" "PHONE_NUMBER",
       "OEHR_EMPLOYEES"."HIRE_DATE" "HIRE_DATE",
       "OEHR_EMPLOYEES"."JOB_ID" "JOB_ID",
       "OEHR_EMPLOYEES"."SALARY" "SALARY",
       "OEHR_EMPLOYEES"."COMMISSION_PCT" "COMMISSION_PCT",
       "OEHR_EMPLOYEES"."MANAGER_ID" "MANAGER_ID",
       "OEHR_EMPLOYEES"."DEPARTMENT_ID" "DEPARTMENT_ID"
    FROM
       "#OWNER#"."OEHR_EMPLOYEES" "OEHR_EMPLOYEES"
    WHERE
        (:P1_NAME IS NULL OR
            (:P1_NAME IS NOT NULL AND
                    (lower(first_name) like '%' || lower(:P1_NAME) || '%') OR
                    (lower(last_name) like '%' || lower(:P1_NAME) || '%')
        ) AND
        (:P1_DEPT IS NULL OR department_id = :P1_DEPT) AND
        (:P1_MGR IS NULL OR manager_id = :P1_MGR)

  • How to write selection Query for the following requirment.

    Hi All,
    I am new to ABAP, I need a help ,
    I need to select all plants(WERKS) from MARC at Plant/Material level,
    then I need to take all sales organozation(VKORG) from T001w,
    then I need the company code(BUKRS) from TVKO based on VKORG,
    then I need the currency key(WAERS) from T001 based on BUKRS,
    Can any one help me in writing selection Query for the same?
    Thanks All,
    Debrup.

    Hi,
    Its easy for you if you learn SELECT with JOIN to complete your task. So SEARCH the forum with SELECT statement and you will get a lot of examples using which you can write your own.
    If you struck up anywhere revert back.
    Regards
    Karthik D

  • Select query for 6 different tables with vbeln as same selction criteria

    Hi,
    I have a query..
    I am using 6 differnet tables with vbeln being the same primary key on the basis of which i have to match the data.
    I have assign vbeln with different name but in the select query it gives me the error that vbeln2 is not the correct field.
    Can anyone please suggest how can i use the different field name and read the data from the table.

    hi,
    Use alias name for fields / tables in select query, problem will solve
    Regards,
    Praveen Savanth.N

  • Internal tables & select query for clasical report

    hello all,
           i am a novice in ABAP.i need to retrive data from 4 DB tables to do a classical report. i declared internal tables as below and then retrieved the data as per the below select statements. is there any other way in which i can do the same with a comparitively lesser amt of code.
    data: begin of i_vbak occurs 0,
          vbeln like vbak-vbeln,
          kunnr like vbak-kunnr,
          waerk like vbak-waerk,
          end of i_vbak.
    data: begin of i_vbap occurs 0,
          vbeln like vbap-vbeln,
          kwmeng like vbap-kwmeng,
          posnr like vbap-posnr,
          vrkme like vbap-vrkme,
          netpr like vbap-netpr,
          end of i_vbap.
    data: begin of i_lips occurs 0,
          vbeln like lips-vbeln,
          vgpos like lips-vgpos,
          vrkme like lips-vrkme,
          lfimg like lips-lfimg,
          end of i_lips.
    data: begin of i_vbep occurs 0,
          vbeln like vbep-vbeln,
          posnr like vbep-posnr,
          edatu like vbep-edatu,
          end of i_vbep.
    data: begin of i_out occurs 0,
          kunnr like vbak-kunnr,
          vbeln like vbak-vbeln,
          kwmeng like vbap-kwmeng,
          netpr like vbap-netpr,
          waerk like vbak-waerk,
          vrkme like vbap-vrkme,
          lfimg like lips-lfimg,
          posnr like vbep-posnr,
          edatu like vbep-edatu,
          end of i_out.
          RETRIVING THE DATA INTO INTERNAL TABLE                         *
    select vbeln kunnr waerk from vbak into table i_vbak where kunnr in
    s_kunnr and vbeln in s_vbeln.
    select vbeln kwmeng posnr vrkme netpr from vbap into table i_vbap for
    all entries in i_vbak where vbeln = i_vbak-vbeln.
    select vbeln vgpos vrkme lfimg from lips into table i_lips for all
    entries in i_vbak where vbeln = i_vbak-vbeln and vgpos in s_vgpos.
    select vbeln posnr edatu from vbep into table i_vbep for all entries in
    i_vbak where vbeln = i_vbak-vbeln.
    <b>Points are guaranteed for good answers.</b>
    Thanks in advance
    seenu

    Hi,
    If u will use in ALV means  how many tables u want u can put it. After that u can maintain one internal table that's enough. Afterthat  put select queries after that display the internal table fileds.
    If u will ALV  report means u have to code same coding for every report slight changes only there.
    Herewith i am sending sample ALV REPORT it is useful for u.
    REPORT CODING:
    REPORT  YMS_COLOURALV NO STANDARD PAGE HEADING.
    TYPE-POOLS: SLIS, ICON.
    DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
    DATA: BEGIN OF IMARA OCCURS 0,
              LIGHT(4) TYPE C,
              MATNR TYPE MARA-MATNR,
              MTART TYPE MARA-MTART,
              MAKTX TYPE MAKT-MAKTX,
              COLOR_LINE(4) TYPE C,
              TCOLOR TYPE SLIS_T_SPECIALCOL_ALV,  "cell
          END OF IMARA.
    DATA: XCOLOR TYPE SLIS_SPECIALCOL_ALV.
    START-OF-SELECTION.
      PERFORM GET_DATA.
      PERFORM WRITE_REPORT.
    Get_Data
    FORM GET_DATA.
      WRITE ICON_GREEN_LIGHT AS ICON TO IMARA-LIGHT.
          IMARA-MATNR = 'ABC'.
          IMARA-MTART = 'ZCFG'.
          IMARA-MAKTX = 'This is description for ABC'.
      APPEND IMARA.
      WRITE ICON_YELLOW_LIGHT AS ICON TO IMARA-LIGHT.
          IMARA-MATNR = 'DEF'.
          IMARA-MTART = 'ZCFG'.
          IMARA-MAKTX = 'This is description for DEF'.
      APPEND IMARA.
      WRITE ICON_RED_LIGHT AS ICON TO IMARA-LIGHT.
          IMARA-MATNR = 'GHI'.
          IMARA-MTART = 'ZCFG'.
          IMARA-MAKTX = 'This is description for GHI'.
      APPEND IMARA.
      LOOP AT IMARA.
        IF SY-TABIX = 1.
          IMARA-COLOR_LINE = 'C410'.     " color line
        ENDIF.
        IF SY-TABIX = 2.                "  color CELL
          CLEAR XCOLOR.
          XCOLOR-FIELDNAME = 'MTART'.
          XCOLOR-COLOR-COL = '3'.
          XCOLOR-COLOR-INT = '1'.       " Intensified on/off
          XCOLOR-COLOR-INV = '0'.
          APPEND XCOLOR TO IMARA-TCOLOR.
        ENDIF.
        MODIFY IMARA.
      ENDLOOP.
    ENDFORM.                    "get_data
    WRITE_REPORT
    FORM WRITE_REPORT.
      DATA: LAYOUT TYPE  SLIS_LAYOUT_ALV.
      LAYOUT-COLTAB_FIELDNAME = 'TCOLOR'.
      LAYOUT-INFO_FIELDNAME = 'COLOR_LINE'.
      PERFORM BUILD_FIELD_CATALOG.
    CALL ABAP LIST VIEWER (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          IS_LAYOUT   = LAYOUT
          IT_FIELDCAT = FIELDCAT
        TABLES
          T_OUTTAB    = IMARA.
    ENDFORM.                    "write_report
    BUILD_FIELD_CATALOG
    FORM BUILD_FIELD_CATALOG.
      DATA: FC_TMP TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
      CLEAR: FIELDCAT. REFRESH: FIELDCAT.
      CLEAR: FC_TMP.
      FC_TMP-REPTEXT_DDIC    = 'Status'.
      FC_TMP-FIELDNAME  = 'LIGHT'.
      FC_TMP-TABNAME   = 'IMARA'.
      FC_TMP-OUTPUTLEN  = '4'.
      FC_TMP-ICON       = 'X'.
      APPEND FC_TMP TO FIELDCAT.
      CLEAR: FC_TMP.
      FC_TMP-REPTEXT_DDIC    = 'Material Number'.
      FC_TMP-FIELDNAME  = 'MATNR'.
      FC_TMP-TABNAME   = 'IMARA'.
      FC_TMP-OUTPUTLEN  = '18'.
      APPEND FC_TMP TO FIELDCAT.
      CLEAR: FC_TMP.
      FC_TMP-REPTEXT_DDIC    = 'Material Type'.
      FC_TMP-FIELDNAME  = 'MTART'.
      FC_TMP-TABNAME   = 'IMARA'.
      FC_TMP-OUTPUTLEN  = '10'.
      APPEND FC_TMP TO FIELDCAT.
      CLEAR: FC_TMP.
      FC_TMP-REPTEXT_DDIC    = 'Material'.
      FC_TMP-FIELDNAME  = 'MAKTX'.
      FC_TMP-TABNAME   = 'IMARA'.
      FC_TMP-OUTPUTLEN  = '40'.
      FC_TMP-EMPHASIZE = 'C610'.   " color column
      APPEND FC_TMP TO FIELDCAT.
    ENDFORM.                    "build_field_catalog
    Thanks,
    Shankar

  • Query for inserting data into table and incrementing the PK.. pls help

    I have one table dd_prohibited_country. prohibit_country_key is the primary key column.
    I have to insert data into dd_prohibited_country based on records already present.
    The scenario I should follow is:
    For Level_id 'EA' and prohibited_level_id 'EA' I should retreive the
    max(prohibit_country_key) and starting from the maximum number again I have to insert them
    into dd_prohibited_country. While inserting I have to increment the prohibit_country_key and
    shall replace the values of level_id and prohibited_level_id.
    (If 'EA' occurs, I have to replace with 'EUR')
    For Instance,
    If there are 15 records in dd_prohibited_country with Level_id 'EA' and prohibited_level_id 'EA', then
    I have to insert these 15 records starting with prohibit_country_key 16 (Afetr 15 I should start inserting with number 16)
    I have written the following query for this:
    insert into dd_prohibited_country
    select     
         a.pkey,
         b.levelid,
         b.ieflag,
         b.plevelid
    from
         (select
              max(prohibit_country_key) pkey
         from
              dd_prohibited_country) a,
         (select
    prohibit_country_key pkey,
              replace(level_id,'EA','EUR') levelid,
              level_id_flg as ieflag,
              replace(prohibited_level_id,'EA','EUR') plevelid
         from
              dd_prohibited_country
         where
              level_id = 'EA' or prohibited_level_id = 'EA') b
    My problem here is, I am always getting a.pkey as 15, because I am not incrementing it.
    I tried incrementing it also, but I am unable to acheive it.
    Can anyone please hepl me in writing this query.
    Thanks in advance
    Regards
    Raghu

    Because you are not incrementing your pkey. Try like this.
    insert
       into dd_prohibited_country
    select a.pkey+b.pkey,
         b.levelid,
         b.ieflag,
         b.plevelid
       from (select     max(prohibit_country_key) pkey
            from dd_prohibited_country) a,
         (select     row_number() over (order by prohibit_country_key)  pkey,
              replace(level_id,'EA','EUR') levelid,
              level_id_flg as ieflag,
              replace(prohibited_level_id,'EA','EUR') plevelid
            from     dd_prohibited_country
           where level_id = 'EA' or prohibited_level_id = 'EA') bNote: If you are in multiple user environment you can get into trouble for incrementing your PKey like this.

  • Select query for picking data in a dynamic internal table

    Dear All,
    Please help.
    <u>The code is :</u>
    p_table1 = itab_final-tabname1.
            p_field1 = itab_final-fieldname1.         
            SELECT (p_field1) FROM (p_table1) INTO CORRESPONDING FIELDS OF TABLE <dyntable1>.      
    It is working fine when the domain is of CHAR
    The piece of code is not working where domain is DATS, CURR, DEC, etc.
    What shall I do so that it works for other domains also. Please its urgent......
    <u>ERROR that came:</u>
    An exception occurred. This exception will be dealt with in more detail
    below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
    caught, which                                                         
    led to a runtime error. The reason for this exception is:             
    The data read during a SELECT access could not be inserted into the    
    target field.                                                          
    Either conversion is not supported for the target field's type or the  
    target field is too short to accept the value or the data are not in a 
    form that the target field can accept

    Check below code
    REPORT zpwtest .
    *** Tables
    DATA: lt_data TYPE REF TO data.
    DATA: lt_fieldcatalog TYPE lvc_t_fcat.
    data : p_field type string ,
           p_table type string .
    *** Structure
    DATA: ls_fieldcatalog TYPE lvc_s_fcat.
    *** Data References
    DATA: new_line TYPE REF TO data.
    *** Field Symbols
    FIELD-SYMBOLS: <fs_data> TYPE REF TO data,
                   <fs_1> TYPE ANY TABLE,
                   <fs_2>,
                   <fs_3>.
    ls_fieldcatalog-fieldname = 'MANDT'.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
    ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
    APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'CONNID'.
    ls_fieldcatalog-inttype = 'N'.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'FLDATE'.
    ls_fieldcatalog-inttype = 'D'.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'PRICE'.
    ls_fieldcatalog-inttype = 'P'.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'CURRENCY'.
    ls_fieldcatalog-inttype = 'C'.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ASSIGN lt_data TO <fs_data>.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
         EXPORTING
           it_fieldcatalog = lt_fieldcatalog
         IMPORTING
           ep_table = <fs_data>
         EXCEPTIONS
           generate_subpool_dir_full = 1
           OTHERS = 2
    IF sy-subrc <> 0.
    ENDIF.
    *** So <FS_1> now points to our dynamic internal table.
    ASSIGN <fs_data>->* TO <fs_1>.
    *** Next step is to create a work area for our dynamic internal table.
    CREATE DATA new_line LIKE LINE OF <fs_1>.
    *** A field-symbol to access that work area
    ASSIGN new_line->*  TO <fs_2>.
    <b>
    p_field = 'mandt carrid connid fldate price currency' .
    p_table = 'sflight' .
    *** And to put the data in the internal table
    SELECT (p_field)
      FROM (p_table)
      INTO CORRESPONDING FIELDS OF TABLE <fs_1>.
    </b>
    *** Access contents of internal table
    LOOP AT <fs_1> ASSIGNING <fs_2>.
      ASSIGN COMPONENT 5 OF STRUCTURE <fs_2> TO <fs_3>.
      WRITE: / <fs_3>.
    ENDLOOP.

  • Plz help, A select query for table giving foll o/p

    A table has a single column with following data
    Col1
    170
    10
    140
    520
    20
    60
    70
    The select query should return the data in the following format
    Col1 Col2 Col3 Col4
    170 3 1 0
    10 0 0 1
    140 2 2 0
    520 10 1 0
    20 0 1 0
    60 1 0 1
    70 1 1 0

    Using my awesome puzzle solving brain I note that Col2 = 50 Col3 = 20 Col4 = 10.
    But you should be telling US that.
    select col1, floor(col1/50) col2, floor(mod(col1,50)/20) col3, floor(mod(mod(col1,50),20)/10) col4
    from mytable.
    I win the internets!
    Edited by: Dave Hemming on Dec 19, 2008 11:35 AM

  • Select query for sales order for particular customer oder text and storage

    Hi All,
    I am trying to retriev customer order text and customer storage bin from the following select query, but it's giving huge number of records, I want to restrict the number of records.
    Select customer order text, customer storage bin
                       Select STXH–TDOBJECT, STXH–TDID
                       Where  TDOBJECT = VBBP
                              TDID = Y001
                              TDID = Y007
    Please let me know how to restirct the number of records.
    Thanks,
    Ranjan

    Try using the FM 'READ_TEXT'.
    NAME will be the order number concatenated with the item number.
    And you have the ID and OBJECT.  You may also need to use the LANGUAGE.
    Message was edited by:
            Matt Nagel

Maybe you are looking for