Dyanamic select

hello all,
How can i write a dynamic select query for range of values?
regards
T

Hi,
Refer:
http://sapient.wordpress.com/2007/12/11/how-to-use-dynamic-sql-in-abap-report/

Similar Messages

  • DYANAMIC SELECT LIST

    Hi,
    can any one help me how to write dyanamic select list  i.e select (...) from tab
    I have created the dyanamic select list but, if the list contains date fields then when i pass this dyanamic select list in selection it gives dump.
    therefore can any one tell me how to take care of date fields.
    thanks

    Hello,
    U could make use of thei code:
    *--- Arbeitsbereich für interne Tabelle der PSP-Elemente
      FIELD-SYMBOLS:
         TYPE WKGXXX.
      DATA: BEGIN OF SEL_WBS OCCURS 0,
             SIGN(1),
             OPTION(2),
             LOW  LIKE PRPS-POSID,
             HIGH LIKE PRPS-POSID,
          END   OF SEL_WBS.
    *--- beim ersten Unterprogrammaufruf interne Tabellen für dynamischen
    *--- Select füllen
      IF L_T_SELECT_FIELDS IS INITIAL.
    *--- Kostenart                                               "/&-neuneu
        L_T_SELECT_FIELDS_WA-FIELD = 'KSTAR'.
        APPEND L_T_SELECT_FIELDS_WA TO L_T_SELECT_FIELDS.
    *--- Geschäftsjahr
        L_T_SELECT_FIELDS_WA-FIELD = 'GJAHR'.
        APPEND L_T_SELECT_FIELDS_WA TO L_T_SELECT_FIELDS.
    *--- Werttyp
        L_T_SELECT_FIELDS_WA-FIELD = 'WRTTP'.
        APPEND L_T_SELECT_FIELDS_WA TO L_T_SELECT_FIELDS.
    *--- von 1 bis 16
        WHILE L_F_MONAT LE 16.
    *--- Wert gesamt in Kostenrechnungskreiswährung
          L_T_SELECT_FIELDS_WA-FIELD = 'WKG'.
          L_T_SELECT_FIELDS_WA-FIELD+3(3) = L_F_MONAT.
          APPEND: L_T_SELECT_FIELDS_WA TO L_T_SELECT_FIELDS.
          L_F_MONAT = L_F_MONAT + 1.
        ENDWHILE.
      ENDIF.
    If useful reward.
    Vasanth

  • Dyanamic selection screen

    Hi,
    I have a Ztable created my program should create a dynamic selection screen depending on tht ztable
    can you suggest me a solutin for this
    Manohar.

    Hi
    Use this code
    type-pools : abap.
      field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
      data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
      selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001'.
    selection-screen end of block b1.
      start-of-selection.
        perform get_structure.
      perform create_dynamic_itab.      *********Creates a dyanamic internal table*********
      form get_structure.
      data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
      data : ref_table_des type ref to cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?= 
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
        loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
      endform.
      form create_dynamic_itab.
    Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc
                   importing
                      ep_table        = dy_table.
        assign dy_table->* to <dyn_table>.
    Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
      endform.
    Kiran

  • Dyanamic Selection of Fields and prepare internal table dyanamically

    Hi,
    How can we select fields dyanamically and create a dyanamic internal table for the fields created dyanamically.
    like from table KNC1 if user wants data from period 1 to 3 then for the following fields (UM01S,UM01H,UM01U,UM02S,UM02H,UM02U,UM03S,UM03H,UM03U) daynamic internal table should be created accordingly.
    regards,
    BG

    report z_dynamic.
    type-pools : abap.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
    selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001'.
    selection-screen end of block b1.
    start-of-selection.
      perform get_structure.
      perform create_dynamic_itab.
      perform get_data.
      perform write_out.
    Get_Structure Form
    form get_structure.
    data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
    data : ref_table_des type ref to cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
      loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    endform.
    Create_Dynamic_Itab Form
    form create_dynamic_itab.
    Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc
                   importing
                      ep_table        = dy_table.
      assign dy_table->* to <dyn_table>.
    Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    endform.
    Get_Data Form
    form get_data.
    Select Data from table.
      select * into table <dyn_table>
                 from (p_table).
    endform.
    Write_Out Form
    Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index 
             of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    Dynamic Select Statement
    check this code...
    For dynamic table name....
    REPORT demo_select_dynamic_database .
    DATA wa TYPE scarr.
    DATA name(10) TYPE c VALUE 'SCARR'.
    SELECT *
    INTO wa
    FROM (name) CLIENT SPECIFIED
    WHERE mandt = '000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDSELECT.
    For dynamic field list
    REPORT demo_select_dynamic_columns .
    DATA: itab TYPE STANDARD TABLE OF spfli,
                wa LIKE LINE OF itab.
    DATA: line(72) TYPE c,
    list LIKE TABLE OF line(72).
    line = ' CITYFROM CITYTO '.
    APPEND line TO list.
    SELECT DISTINCT (list)
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM spfli.
    IF sy-subrc EQ 0.
    LOOP AT itab INTO wa.
    WRITE: / wa-cityfrom, wa-cityto.
    ENDLOOP.
    ENDIF.
    regards
    vinod

  • Dyanamic Select Query

    Hi,
    Can you pls guide me on the use of Dyanamic WHERE Clause in a Select Query?
    I came across the syntax:
    SELECT * FROM za004 INTO TABLE ia004 WHERE (options).
    Here Options is an internal table of type 'RFC_DB_OPT'
    But I am unable to fill this internal table correctly.
    Can some one pls guild me with sample code.
    Regards,
    Pankaj Bist.

    Check this :
      DATA: BEGIN OF lt_options OCCURS 10.
              INCLUDE STRUCTURE rfc_db_opt.
      DATA: END OF lt_options.
    CONCATENATE 'PERIV EQ ' '''' 'V8' '''' ' AND' INTO   " <-- PERIV is the field name
    lt_options-text.
    APPEND lt_options.
    CONCATENATE 'BDATJ EQ ' '''' l_pyear ''''  INTO
    lt_options-text.
    APPEND lt_options.
    Use lt_options in where condition.

  • Dyanamic Select Statements

    Hi ,
        The following program gives a short dump with exception CX_SY_DYNAMIC_OSQL_SYNTAX. Its ok when we use paremeters in the Dyanamic statements . Please highlight on this regard.
    Thanks in advance,
    Raj
    REPORT  ZMT_DYNAMIC_SELECT                      .
    tables:mara.
    select-options:p_matnr for mara-matnr default '38'.
    data:lv_text(40).
    data:itab type mara occurs 0 with header line.
    concatenate 'matnr' 'in' 'p_matnr' into lv_text separated by space .
    translate lv_text to upper case.
    select * from mara into table itab where (lv_text).
    Loop at itab.
    write:/ itab-matnr.
    check sy-tabix eq 5.
    exit.
    endloop.

    Hi Raja,
    1. Before trying out any dynamic sql,
       first try with hardcoded sql.
    2.  where (lv_text).
       this lv_text is causing the problem.
    3. Since, fieldname = 'value'
       this is the syntax for sql.
    4. Hence, SINGLE QUOTES are important for
       CHARACTER Fields
       and NUMERIC fields don't require
      single quotes.
      DATE require single quotes
      in the format YYYYMMDD
    5. Hence, the problem is only in the
       syntax of dynamic sql.
    regards,
    amit m.

  • FBL5N - Logical databases - Dyanamic selection screen fields

    I am trying to insert "Profit center" from BSEG table of Logical database DDF into the dynamic selection screen of FBL5N.
    Procedure I followed:
    Program -> Attributes -> Logical database -> Extras -> Selection views.
    Interestingly when I add "Profit center" from BSID table instead of BSEG, it appears on dynamic selection screen. But this is not working for BSEG. I have no clue why this is so? If someone can help me in this regard, that would be great.
    P.S: I can not insert Profit center from BSID table as BSEG contains profit center values and BSID is not storing the same info.

    Rob,
    Below is the BSEG contents:
    Company code Document Number Customer     Profit Center
    1000         1800001111      0000100006
    1000         1800001111                   0000000401
    BSID contents:
    Company code Customer     Document Number Profit Center
    1000         0000100006   1800001111                  
    As BSID stores customer info, I believe only line item that has customer info is stored here.
    I guess, that is the reason.
    I will try the option told by prev post. Will keep you guys posted.
    Thanks,
    Phani

  • Dyanamic selection screen accordingly output

    Hi Experts,
    I want to making dyamic selection screen on there  I take two fields only  customer number and date.
    It can be change the position of fields. In following ways.
    First time  selection screen : customer no
                                              Date.
    If I insert first value in customer field then output will come
    In tree Report
    Customer
           Sales order
                                 Items no.     material no.     order qty net price  currency.
    Second  time selection screen : Date
                                                             Customer no.
    If I selected date and inserted values in date field then output will get
    Date
           Sales order
                         items no     material no.     order qty net price  currency.
    This my requirement  , I will try to making by using OOP ALV. Can any one give me any example or any standard such  type of report for help.
    Regards
    Pravin

    Hello Pravin,
    You can try this way:
    1. Create basic selection screen with customer number and date field.
    2. Now on START-OF-SELECTION you can call another screen which will display data in ALV.
    3. Main part is of creating internal table dynamically depending on which field is selected on first selection screen,
    4. So you can use static method cl_alv_table_create=>create_dynamic_table for creating dynamic table.
    5. so load fieldcatalog table with required field as per the field selection and call method as follow:
    DATA table TYPE REF TO DATA.
    FIELD-SYMBOLS <ITAB> TYPE ANY TABLE.
    call method cl_alv_table_create=>create_dynamic_table
    exporting
    it_fieldcatalog = fieldcatalog_tab
    importing
    ep_table = table.
    Now, here table is data object having reference to internal table created dynamically.
    so you can assign that table to field symbol as follows:
    ASSIGN table->* to <ITAB>.
    Now you select data into table <ITAB> and pass it to ALV method SET_TABLE_FOR_FIRST_DISPLAY.
    There are lot of threads on SDN for creating ALV using OOP method.
    Hope this helps!
    Thanks,
    Augustin.

  • Entry Date in Dynamic selection of FBL3N

    HI Experts,
    I need Entry date in dyanamic selection of report FBL3N.
    Can anyone please help me out with this?
    Thanks,
    Nitish

    Hi Nitish,
    This can be done in the IMG path:
    Financial Accounting (New) >General Ledger Accounting (New)>Master Data>G/L Accounts>Line Items>Define Special Fields for Line Item Display.
    After you defined and stored them there, please also run the report BALVBUFDEL.
    About the special fields in general, please refer to the SAP 984305.
    Regards,
    SAPFICO

  • Standard report with po released date

    hi mm experts,
    request pl let me know is there any standard report which gives the po details and release indicator with released date of po.
    pl help.
    regards
    Srihari

    Hi
    U can get Po release date  per release code, use  CDHDR and CDPOS tables in SE16
    Enter transaction as ME28/ ME29N, Enter the range date,enter the object value as PO number (PO number should be 10 digit if the PO is not 10 digit, then add zero value for the prefix).
    Then you can find the release date
    Rest details u can find from ME2N report i.e Po details and Release indicator using dyanamic selection
    Vishal...

  • Dynamic seleciton in report variant FBL1N

    Hi,
    Problem Description
    I am trying use dyanamic selection in report variant of FBL1N but its not working.
    My working
    I am using dyanamic date variant.
    In the selection screen of FBL1N, we have posting date in dynamic selections.
    While creating a variant for the selection screen of FBL1N, I am selecting Posting Date of dyanamic selection and choosing selection variant as "D" (D: Dynamic date calculation) along with Current Date as variable.
    However system is not accepting this and the current date is not coming up while choosing this variant.
    Solution required
    Can anyone please help me out with dyanamic date calculation in dates from dynamic selection in report FBL1N.
    Thanks,
    Nitish

    Dear
    You did not specify in which version you are working.  If you are in new GL instead of using FBL1N you can as well use T.Code S_AC0_52000888 and here you can make dynamic selections.
    Regds

  • Vendors report by account group

    Hi Friends,
    I have a list of vendors in an spreadsheet. I want to generate a report with the vendor number, credit, debit, balance and the account group. I tried the SAP defined reports like ( S_ALR_87012082) i can get the vendor, credit, debit, but not the account group. I can select the account group option in the dyanamic selection but not in the report layout
    Can any one suggest any other transaction where i can generate the desired report
    Thanks in advance
    Genie

    hi,
    use query (tcodes sq01/ sq02)
    -use/create  an  infoset with logical database KDF
    and tables LFA1 and LFC1
    A.

  • PLANT WISE FINANCIAL STATEMENT REQUIRED

    Hi
    Can any one tell me whether any standard report is available in SAP to get the plant wise Financial Statement ( No Business area wise ) as it is having in FBL3N ( thro dyanamic selection ) for GL balances.
    Please reply immediately if possible.
    Thanks and regards
    G. Jana

    As standard you cant get this.
    A Plant would need to be linked to a Profit Center.
    Do you use ERP 6.0
    Perhaps you could add it as a field for document splitting. However you would then have to maintain you business splitting rules as well.
    What is a plant used where you are.

  • Reports for MM/Projects/PM

    Hi Sap Gurus
    Please help i would like to get a report that will show me PR number/ PO number/ Priject spent per plant
    our company is a manufacturing industry, they have new projects erc
    Regards
    Susan

    Hi
    Check PR Report of ME5A with dyanamic selection where you can see the PR & PO Details
    Regards
    Rajesh Dalal

  • Counter in databasetable

    Hi Experts,
    how I can create a function to counter my entries in my database table?
    Regards,
    Mike

    Hi
      I don't know why u required but , simple way can be .
    give input parameter as Table name
    then make dyanamic SELECT query as
    select * form <Table >.
    then catch the value of system field SY-DBCNT.
    put it as Export parameter.
    this may help.
    Regards
    Sachin

Maybe you are looking for