How to Concatenate Table name and Where condition at runtime

I am passing parameter as User and Zone to Stored Procedure.How to concatenate Table Name
and WHERE CONDITION in SQL Statement.i have different type of users and zones.

Hi !
declare
  cur sys_refcursor;
  r emp%rowtype;
  v_sql varchar2(512);
begin
-- do your logic here
  v_sql := 'select * from emp';
  open cur for v_sql;
  loop
    fetch cur into r;
    exit when cur%notfound;
    dbms_output.put_line(r.ename);
  end loop;
  close cur;
end;In this example you can see how can be done this with cursor vars .. You should concatenate v_sql string according to your requirements.
But as in further posts has already been mentioned , be carefull at publishing such kind of procedures and think on security.
Also when you want dynamicaly change from clause , you should consider using different records to accept data ? Maybe all your tables has the same structure and then this problem will be smaller.
T
T

Similar Messages

  • How to find table name and field name in JSP FORM

    Hi
    In JSP form's like XML publisher responsibility>templet
    In that form how can we see the system-last query . and how to see the table name

    hi yamini,
    plz go to help->record history (for fining table name)
    and
    help->diagnostic->examine (for finding field name)& enter last_query
    in JSP form also same above only i think.
    or check in back end & apply who columns
    Edited by: raghava bandi on Nov 7, 2008 2:05 AM

  • How to find Table Name and Field Names given a Data Source

    Hi,
    I tried ROOSOURCE table in R/3 to find the Extract Structure and Extractor names for a specific data source, let us say 2LIS_02_ITM (PO Item Level).
    I know the extract structure for this data source is MCO2M_0ITM
    I am not able to find where this structure is extracting the data for every field.. I wanted to know the corresponding table name and the respective field names.. Both the existing and Appended fields..
    Thanks,
    Naren

    Hi,
    Check in in LBWE and Click on Maintenance and see the table names
    EKKO
    EKPA
    EKPO
    Tables are use for this DS
    Eg:
    MCEKKO  BEDAT  Document Date
    MCEKKO  BSART  Document Type
    MCEKKO  BSTYP  Doc. Category
    MCEKKO  BUDAT  Accounting date
    MCEKKO  EBELN  Purchasing Doc.
    MCEKKO  EKGRP  Purch. Group
    Note: here EKKO is table
    https://wiki.sdn.sap.com/wiki/display/BI/BW%20SD%20MM%20FI%20DATASOURCES
    thanks
    Reddy
    Edited by: Surendra Reddy on Mar 10, 2010 8:18 AM
    Edited by: Surendra Reddy on Mar 10, 2010 8:19 AM

  • How to find table name and field name thru Tcode

    Hi,
         how to find out table name and field names thru transaction code..........plz point out step by step.

    Hi
    I am not getting your question... as i understand, if you go to SE84 tcode you can get it.
    Go to SE84.Select ABAP Dictionary sub tree. Double click on "database tables'. Give some number in "Maximum number of hits”. DONT GIVE ANY OTHER INPUTS. Just press F8. You will get all table names.
    For fields also do like this by selecting FIELDS sub tree.
    Reward if it is useful.
    Thanks
    Siva Kumar

  • How to remember table names and fields with their meanings..

    Hi gurus,
    How to remember the table names. I mean to ask if there is any meaningful content that we can form out of a table name. For example 
    MARA , VBAK, etc... what are their full forms..
    Coming to the fileds in these tables like MATNR -- EBELN - BUKRS,etc..... how they are actually framed. Is there any full form or is there no alternative except to mug them up..
    Thank you.

    if tables starts with fallowing words
    B-related to FI/CO.
    P- related to HR.
    M-related to MM.
    V-related to SD.
    T-related to Administration relation.
    K-related to customer table.
    L-related to vendor.
    E-related to purchase order details
    vbak-sales document header details table.
    vbap-sales documetnt item details table
    vbrk-billing document header details table
    vbrp-billing document item details table
    revards if usefull.
    regards
    usha.

  • How to use MONTH NAME in where condition in date column?

    Hi dudes,
    this is the table.
    sql>desc ACMINUTESPDFTEST;
    Name Null? Type
    ACDATE DATE
    TYPES VARCHAR2(10)
    here i have tried the following 2 queries,but i could not get the correct result
    select types,seqno,acdate from ACMINUTESPDFTEST where acdate like to_date('NOV','MON');
    or
    select types,seqno,acdate from ACMINUTESPDFTEST where acdate = to_date('NOV','MON');
    (for both the query the output is same)
    TYPES ACDATE
    PINK 01-NOV-10
    but the table having following data:
    TYPES ACDATE
    PINK 14-NOV-10
    WHITE 15-NOV-10
    PINK 01-NOV-10
    Any suggestion why i could not get correct result.

    bharathit wrote:
    Thanks for toon and divya...it solved my problem and my question how will you select between two months..
    select types,acdate from ACMINUTESPDFTEST where to_char(acdate,'MON') >= 'SEP' AND to_char(acdate,'MON') <= 'OCT';
    and i got
    no rows selected
    Edited by: bharathit on Nov 2, 2010 10:37 PMIf you're interested in finding dates in a range of months regardless of the year then try this:
    select ...
    from   ...
    where  to_number(to_char(date_column,'MM')) Between 9 And 10;You could also do something like:
    select ...
    from   ...
    where  to_number(to_char(date_column,'MM')) In (1,4,7,10);If you are interested in dates in a range of months in a particular year however, use something like this:
    select ...
    from   ...
    where  date_column >= date '2010-09-01' and
           date_column < date '2010-11-01' and

  • Field symbols as Table name and in where condition in a select statement

    Hello All,
    I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
    I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
    I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
    Here is my code:
    DATA: TAB       LIKE SY-TNAME,
          TAB_COMP1 LIKE X031L-FIELDNAME,
          TAB_COMP2 LIKE X031L-FIELDNAME,
          NO_OF_FLD TYPE N.
    DATA: BEGIN OF BUFFER,
            ALIGNMENT TYPE F,
            C(8000)   TYPE C,
          END OF BUFFER.
    FIELD-SYMBOLS: <WA>   TYPE ANY,
                  <COMP1> TYPE ANY,
                  <COMP2> TYPE ANY.
    GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
      TAB = TAB_NAME.
    CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
      CASE TAB_NAME.
      WHEN 'OIUH_RV_GL'.
          KEY FIELD
            TAB_COMP1  = 'GL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OPSL'.
          KEY FIELD
            TAB_COMP1  = 'OPSL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'OTAX_GL_SYS_NO'.
            TAB_COMP2  = 'OTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN 'OIUH_RV_GTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'GTAX_GL_SYS_NO'.
            TAB_COMP2  = 'GTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN OTHERS.
            EXIT.
      ENDCASE.
    SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
    ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
    How to add where clause and remove the if condition in the select -- endselect
    SELECT * FROM (TAB) INTO <WA>. 
      ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
      IF NO_OF_FLD = 2.
        ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
      ENDIF.
      IF <COMP1> = OLD_SYS_NO.
        code for updating table would come here
          WRITE: 'MATCH FOUND'.
          EXIT.
      ENDIF.
    ENDSELECT.
    Please advice. Thanks much.
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM

    1. Create single column table for holding field name depending on the table entered.
    2. Take input from user: for e.g. table_name
    3. Using case load single column table with required fields
       for e.g.
      CASE TAB_NAME.
       WHEN 'OIUH_RV_GL'.
             Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
       WHEN 'OIUH_RV_OPSL'.
             Append 'OPSL_GL_SYS_NO'.
       WHEN 'OIUH_RV_OTAX'.
             Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN 'OIUH_RV_GTAX'.
             Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN OTHERS.
          EXIT.
       ENDCASE.
       Now depending on the table name you have required column ready
    4. Create dynamic internal table using following sudo code
       Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
       loop at internal table with all the fields.
        move it to field catalog.
        append field catalog.
       endloop.
    5. Pass this field catalog table to static method create_dynamic_table method
       DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
       call method cl_alv_table_create=>create_dynamic_table
       exporting
          it_fieldcatalog = fieldcatalog_tab
       importing
          ep_table = table.
    6. Now assign table reference to field symbol of type table.
       ASSIGN table->* to <field-tab>.
    7. Also create work area <field-wa> using refrence of table.
       create data object wa LIKE LINE OF <field-tab>.
       ASSIGN wa->* to <field-wa>.
    8. Also define field symbol for field name.
       for e.g. <field_name>
    4. Dynamic internal table is ready
    5. Now execute the select statement as follows:
       SELECT (KEY_FIELD)
         INTO <ITAB> --> created dynamically above
          FROM (TABLE_NAME)
         WHERE (WHERE).  --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
         Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
        In this case you need to append all your where condition line by line in to WHERE.     
    5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
       So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
       loop at internal table containing list of fields into field_wa --> single column field table
           ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
           Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
           Move <your_new_value> to <field-name>. --> Assign new value
            or
            <field-name> = <your_new_value>.
       Endloop.
    6. After completing all the fields one row will be ready in <field_wa>.
       APPEND <field_wa> to <field_tab>.
    Hope this helps you.
    Thanks,
    Augustin.

  • How to pass the Dynamically table name and RELID in IMPORT  x TO y FROM DATABASE dbtab(ar) ID Key

    Hello Expert,
    I wanted to know is there any way through which we can dynamically pass the table name in IMPORT condition.
    For e.g.
    DATA : PCLT TYPE DD03L-TABNAME.
    DATA: SET_RELID TYPE T52RELID-RELID.
    DATA: key TYPE PCLKEY.
    DATA: text_version TYPE PVRSN.
    DATA: BEGIN OF ptext OCCURS 132.
    DATA: line(132).
    DATA: END OF ptext.
    SET_RELID = 'TX'.
    PCLT = 'PCL1'.
    KEY = '00001000004005     9999123119960101000'.
    TEXT_VERSION = '01'.
    IMPORT TEXT_VERSION PTEXT FROM DATABASE <PCLT>(<SET_RELID>) ID KEY.
    If i use this then it gives me error message "The Dictionary structure or table "<PCLT>" is either not active or does not exist."
    Kindly help me in this matter.
    Thanks
    Srikanth

    Hi Srikanth
    I dont know if there is another solution, but this is what i did using a dynamic subroutine, please check it
    just add this lines to your code
    DATA: prog  TYPE c LENGTH 8,
           mess TYPE string,
           sid  TYPE string,
           wrd  TYPE string,
           dir  TYPE trdir,
           OFF(3).
    DATA: lt_code TYPE TABLE OF rssource-line.
    DATA: ls_code TYPE rssource-line.
    perform call_import using pclt set_relid key.
    form call_import USING p_pclt p_set_relid p_key.
       ls_code = 'PROGRAM SUBPOOL.'.
       append ls_code to lt_code.
       ls_code = 'form get_text tables ptext using p_key changing text_version.'.
       append ls_code to lt_code.
       ls_code = 'IMPORT text_version ptext from database'.
       append ls_code to lt_code.
       concatenate p_pclt '(' p_set_relid ')' into ls_code.
       append ls_code to lt_code.
       ls_code = 'id p_key.'.
       append ls_code to lt_code.
       ls_code = 'endform.'.
       append ls_code to lt_code.
       generate subroutine pool lt_code
                           name prog
                           message mess
                           SHORTDUMP-ID sid
                           WORD WRD
                           OFFSET OFF.
       IF SY-SUBRC EQ 0.
         perform GET_TEXT IN PROGRAM (prog) tables ptext
                                              USING p_key
                                              CHANGING text_version .
       ENDIF.
    endform.
    Hope this help
    Regards
    MC

  • How to find table name for the fields from Standard Extractor in CRM system

    How to find table name of fields from the standard extractor in CRM system ?
    e.g. We use LBWE TCode in R/3 system to find table name for the field from Extractor VCSCL(e.g.).
    Likewise is there any way to find table name for the fields from Standard extractor like 0CRM_LEAD_I.

    Hi ,
    Please find the link below for understanding BW CRM analysis.
    http://help.sap.com/bp_biv135/html/bw.htm
    activate the CRM DSs by scenario:
    1) Activate the application component hierarchy (tcode RSA9). Changes made to the application component hierarchy in the CRM system can be transferred to the BW using the "Edit Application Component Hierarchy" (SBIW - Postprocessing of DataSources).
    SAP Note 434886 must be implemented in CRM 3.0 before the application component hierarchy is activated.
    2) Activate the Business Content DataSources (tcode RSA5).
    Select/enter the application component and choose Execute (F8).
    To compare the shipped and active versions, choose the 'Select Delta' pushbutton. If there is no active version of the DataSource, it is selected automatically.
    To activate the shipped version, choose the 'Transfer DataSources' pushbutton.
    3) Management of the versions of the BW-Adapter metadata (tcode BWA5). All DataSources are displayed that are managed by the BW Adapter.
    As in transaction RSA5 (Service API Metadata Activation), the 'Select Delta' function can be used to select the inactive DataSources or compare shipped and active versions.
    You can also go directly to the screen for maintaining DataSources that are managed by the BW Adapter.
    The 'Compare Version' function makes a detailed comparison of the shipped and active versions.
    All BW-Adapter metadata is considered when versions are compared:
    Header information (Table SMOXHEAD)
    Mapping information (Table SMOXRELP)
    Global selection conditions (Table SMOXGSEL)
    Attribute key fields (Table SMOXAFLD)
    Hope this helps.
    Regards,
    csm reddy

  • Update a filed value with powershell script with ordery by and where condition

    Hi
    I have below powershell script to update list columns but  how i update a field value with ordery by a column and where condition
    below is the part of my script
    $list = $web.Lists[$listName]
    $items = $list.items
    $internal_counter = 1
    #Go through all items
    foreach($item in $items)
    if($item["CourtNO"] -eq $null)
    #if($item["CourtNo"] -eq '1')
    $item["CaseNo"] = $internal_counter
    #how to add a column ordery by Title
    # and where Title field value from 1 to 10
    $internal_counter++
    adil

    Hi,
    You mean that you only need to update all items with Title field value in range 1..10 and order by them before run the loop statement update?
    If so, use CAML query to get the items only match the condition.
    #Build Query
    $spQuery = New-Object Microsoft.SharePoint.SPQuery
    $query = '<Where><And><Gte><FieldRef Name="Title" /><Value Type="Text">0</Value></Gte><Lte><FieldRef Name="Title" /><Value Type="Text">10</Value></Lte></And></Where><OrderBy><FieldRef
    Name="Title"/></OrderBy>'
    $spQuery.Query = $query
    $spQuery.RowLimit = $list.ItemCount
    $items = $list.GetItems($spQuery)
    Hope this help!
    /Hai
    Visit my blog: My Blog | Visit my forum:
    SharePoint Community for Vietnamese |
    Bamboo Solution Corporation

  • Query to find out the table name and column name..

    Hi Experts,
    I have an Oracle DB in which has more than 50 tables and 100,000 records. I want to get the record which contains *"ITxtVarValue references a non existing text"* the text.
    Is there any query there to find out the table name and column name of this particular record where it reside?
    Please help. Any help will be rewarded.
    Thanks,
    G

    Using this forum's search function, I found a thread that should give you an idea: How to find out a tablename
    C.

  • Error: No first field of table index in where condition

    I've got following errors while doing code inspector or extended syntax check:
    (Large table VEKP: No first field of table index in where condition).
    My code is like below as per as code-logic.
    What's the necessary changes to do to remove the above code?
    SELECT VENUM
                 BRGEW
                 BTGEW
                 BTVOL
                 VOLEH
                 VHILM
                 LMENG
                 BREIT
                 HOEHE
                 MEABM
                 VPOBJKEY
                 FROM VEKP
                 INTO TABLE i_vekp
                 WHERE vpobjkey = w_mkpf-xblnr.
    IF sy-subrc = 0.
    SORT i_vekp BY venum.
    ENDIF.
    How can I remove the error? How to use index in where clause I'm not getting and on which key? or, should I use the statement "EC C1_NOFIRST to remove the error?
    Kindly guide.

    > should I use the statement "EC C1_NOFIRST to remove the error?
    you can not really ask this question in this forum. This check gives you hints to the most serious problems in database accesses, if you want to override it, then you should better forget about performance.
    If you are not familiar how databases use indexes, then check resources in the net or in books, in
    short they use indexes and the indexes are absolutly necessary with large tables, if you want to get
    good performance.
    But indexes can only be used in the order of their field, until a field is not used in the WHERE-condition, (gap). If the gap is already the first field, then the index can not be used at all.
    In your case there is not first field of any index specified in the WHERE condition, so the SELECT might be slow. Either you can add a condition on a first index field or you have to live with a poor performance.
    Siegfried

  • How get all table name from database

    hi master
    sir
    how get all table name from database

    The big question is 'why'.
    Selecting from view 'dba_tables' will indeed give the list of all tables in the database, but that includes the dictionary tables and the internal tables, and many others that are probably not of interet to a person who needs to ask this question. Besides, the dba_tables view requires access to a DBA account.
    There are several other views: "user_tables" will list all the tables in this user's schema; and "all_tables" will list all the tables this user can access in some way.
    The above do not, of course, include any information about synonyms, sequences, views, indexes and so on.
    The correct answer and the meaningful answer may be two different things.

  • Table name and field name

    hi frds
    Give me table name and field name of OPEN PO QUANTITY ..
    thanks
    Pari Vendhan.R

    See the sample code for the open PO's based on Vendor
    and do accordingly
    *& Report ZMM_PO_REPORT
    REPORT ZMM_PO_REPORT message-Id yb
    NO STANDARD PAGE HEADING
    LINE-COUNT 60(1)
    LINE-SIZE 230.
    D A T A B A S E T A B L E S D E C L A R A T I O N
    TABLES: lfa1, " Vendor Master
    t161, " PO Doc Types
    t024, " Purchase Groups
    ekko. " PO Header
    T Y P E S D E C L A R A T I O N S
    Purchase Orders Main Structure
    TYPES: BEGIN OF s_po,
    ebeln TYPE ebeln, " PO No.
    ebelp TYPE ebelp, " PO Item
    bstyp TYPE bstyp, " PO Category
    bukrs TYPE bukrs, " Company Code
    bsart TYPE bbsrt, " PO Type
    lifnr TYPE lifnr, " Vendor No
    ekgrp TYPE bkgrp, " Purchase Group
    waers TYPE waers, " Currency
    bedat TYPE etbdt, " PO Date
    txz01 TYPE txz01, " Material Text
    werks TYPE ewerk, " Plant
    lgort TYPE lgort_d, " Storage Location
    matkl TYPE matkl, " Material Group
    menge TYPE bamng, " PR Quantity
    meins TYPE bamei, " UOM
    bprme TYPE bbprm, " Price Unit
    netpr TYPE netpr, " Net price
    peinh TYPE peinh, " Price Unit UOM
    pstyp TYPE pstyp, " Item Category
    knttp TYPE knttp, " Account Assignment Category
    END OF s_po.
    Purchase Orders History Structure
    TYPES: BEGIN OF s_account,
    ebeln TYPE ebeln, " PO No.
    ebelp TYPE ebelp, " PO Item
    gjahr TYPE mjahr, " Fiscal Year
    belnr TYPE mblnr, " PO Invoice No
    menge TYPE menge_d, " PR Quantity
    wrbtr TYPE wrbtr, " Price in Local Currency
    dmbtr TYPE dmbtr, " Price in Foreign Currency
    waers TYPE waers, " Currency
    shkzg TYPE shkzg, " Dr/Cr Indicator
    END OF s_account.
    Purchase Orders History Structure(Item Sum)
    TYPES: BEGIN OF s_inv_sum,
    ebeln TYPE ebeln, " PO No.
    ebelp TYPE ebelp, " PO Item
    menge TYPE menge_d, " PR Quantity
    wrbtr TYPE wrbtr, " Price in Foreign Currency
    waers TYPE waers, " Currency
    END OF s_inv_sum.
    Purchase Orders Main Structure
    TYPES: BEGIN OF s_rep,
    lifnr TYPE lifnr, " Vendor No
    ebeln TYPE ebeln, " PO No.
    ebelp TYPE ebelp, " PO Item
    bstyp TYPE bstyp, " PO Category
    bsart TYPE bbsrt, " PO Type
    ekgrp TYPE bkgrp, " Purchase Group
    waers TYPE waers, " Currency
    bedat TYPE etbdt, " PO Date
    txz01 TYPE txz01, " Material Text
    werks TYPE ewerk, " Plant
    lgort TYPE lgort_d, " Storage Location
    matkl TYPE matkl, " Material Group
    menge TYPE bamng, " PR Quantity
    meins TYPE bamei, " UOM
    bprme TYPE bbprm, " Price Unit
    netpr TYPE netpr, " Net price
    peinh TYPE peinh, " Price Unit UOM
    pstyp TYPE pstyp, " Item Category
    knttp TYPE knttp, " Account Assignment Category
    name1 TYPE name1, " Plant
    orewr TYPE netpr, " To be Invoiced Price
    curr TYPE waers, " Inv Doc Currency
    END OF s_rep.
    D A T A D E C L A R A T I O N S
    DATA: gv_title1 TYPE sylisel, " Report title
    gv_dial. " Color flag
    C O N S T A N T S D E C L A R A T I O N S
    CONSTANTS: c_x VALUE 'X', " Flag X
    c_h VALUE 'H', " Debit
    c_vgabe TYPE vgabe VALUE '2'. " Transaction Type
    I N T E R N A L T A B L E S D E C L A R A T I O N S
    DATA: i_po TYPE STANDARD TABLE OF s_po WITH HEADER LINE,
    " Purchase Order
    i_inv TYPE STANDARD TABLE OF s_inv_sum WITH HEADER LINE,
    " PO Invoice Values
    i_rep TYPE STANDARD TABLE OF s_rep WITH HEADER LINE,
    " PO Invoice Values
    i_ekbe TYPE STANDARD TABLE OF s_account WITH HEADER LINE.
    " PO Invoice Values
    S E L E C T I O N S C R E E N *
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_lifnr FOR lfa1-lifnr MATCHCODE OBJECT kred,
    s_ebeln FOR ekko-ebeln MATCHCODE OBJECT mekk,
    s_bsart FOR t161-bsart,
    s_ekgrp FOR t024-ekgrp,
    s_bedat FOR ekko-bedat.
    SELECTION-SCREEN END OF BLOCK b1.
    I N I T I A L I Z A T I O N *
    INITIALIZATION.
    A T S E L E C T I O N - S C R E E N *
    AT SELECTION-SCREEN.
    Validate the screen fields
    PERFORM validate_screen.
    S T A R T - O F - S E L E C T I O N *
    START-OF-SELECTION.
    Fetch main data
    PERFORM fetch_data.
    T O P - O F - P A G E *
    TOP-OF-PAGE.
    Header of the List
    PERFORM header.
    E N D - O F - P A G E *
    Footer
    END-OF-PAGE.
    ULINE.
    E N D - O F - S E L E C T I O N *
    END-OF-SELECTION.
    Display the Report Output data
    PERFORM display_data.
    At Line-Selection
    AT LINE-SELECTION.
    When double clicked on EBELN display the details of Purchase Doc
    PERFORM line_sel.
    *& Form validate_screen
    Validation of Selection Screen fields
    FORM validate_screen .
    Validation of Vendor Number
    CLEAR lfa1-lifnr.
    IF NOT s_lifnr[] IS INITIAL.
    SELECT lifnr UP TO 1 ROWS
    INTO lfa1-lifnr
    FROM lfa1
    WHERE lifnr IN s_lifnr.
    ENDSELECT.
    IF sy-subrc 0.
    MESSAGE e000 WITH 'Invalid Vendor'(002).
    ENDIF.
    ENDIF.
    Validation of PO Number
    CLEAR ekko-ebeln.
    IF NOT s_ebeln[] IS INITIAL.
    SELECT ebeln UP TO 1 ROWS
    INTO ekko-ebeln
    FROM ekko
    WHERE ebeln IN s_ebeln.
    ENDSELECT.
    IF sy-subrc 0.
    MESSAGE e000 WITH 'Invalid Document Number'(003).
    ENDIF.
    ENDIF.
    Validation of PO Document Type
    CLEAR t161-bsart.
    IF NOT s_bsart[] IS INITIAL.
    SELECT bsart UP TO 1 ROWS
    INTO t161-bsart
    FROM t161
    WHERE bsart IN s_bsart.
    ENDSELECT.
    IF sy-subrc 0.
    MESSAGE e000 WITH 'Invalid Purchase Document Type'(004).
    ENDIF.
    ENDIF.
    Validation of Purchasing Group
    CLEAR t024-ekgrp.
    IF NOT s_ekgrp[] IS INITIAL.
    SELECT ekgrp UP TO 1 ROWS
    INTO t024-ekgrp
    FROM t024
    WHERE ekgrp IN s_ekgrp.
    ENDSELECT.
    IF sy-subrc 0.
    MESSAGE e000 WITH 'Invalid Purchasing Group'(005).
    ENDIF.
    ENDIF.
    ENDFORM. " validate_screen
    *& Form fetch_data
    Fetching the PO related data from Database Tables
    FORM fetch_data .
    CLEAR i_po.
    REFRESH i_po.
    SELECT a~ebeln " PO No.
    b~ebelp " PO Item
    a~bstyp " PO Category
    a~bukrs " Company Code
    a~bsart " PO Type
    a~lifnr " Vendor No
    a~ekgrp " Purchase Group
    a~waers " Currency
    a~bedat " PO Date
    b~txz01 " Material Text
    b~werks " Plant
    b~lgort " Storage Location
    b~matkl " Material Group
    b~menge " PR Quantity
    b~meins " UOM
    b~bprme " Price Unit
    b~netpr " Net price
    b~peinh " Price Unit UOM
    b~pstyp " Item Category
    b~knttp " Account Assignment Category
    INTO TABLE i_po
    FROM ekko AS a JOIN ekpo AS b
    ON a~ebeln = b~ebeln
    WHERE a~ebeln IN s_ebeln AND
    a~lifnr IN s_lifnr AND
    a~ekgrp IN s_ekgrp AND
    a~bsart IN s_bsart AND
    a~bedat IN s_bedat.
    SORT i_po BY ebeln ebelp.
    break-point.
    IF NOT i_po[] IS INITIAL.
    Fetch the PO History/Invoice Details from EKBE Table
    CLEAR i_ekbe.
    REFRESH i_ekbe.
    SELECT ebeln " PO No.
    ebelp " PO Item
    gjahr " Fiscal Year
    belnr " PO Invoice No
    menge " PR Quantity
    wrbtr " Price in Local Currency
    dmbtr " Price in Foreign Currency
    waers " Currency
    shkzg " Dr/Cr Indicator
    INTO TABLE i_ekbe
    FROM ekbe
    FOR ALL ENTRIES IN i_po
    WHERE ebeln = i_po-ebeln AND
    ebelp = i_po-ebelp AND
    vgabe = c_vgabe.
    IF sy-subrc = 0.
    SORT i_ekbe BY ebeln ebelp.
    LOOP AT i_ekbe.
    IF i_ekbe-shkzg = c_h.
    i_ekbe-wrbtr = i_ekbe-wrbtr * -1.
    ENDIF.
    MODIFY i_ekbe.
    ENDLOOP.
    break-point.
    Sum up the Item wise Invoice totals
    LOOP AT i_ekbe.
    AT END OF ebelp.
    READ TABLE i_ekbe INDEX sy-tabix.
    SUM.
    MOVE-CORRESPONDING i_ekbe TO i_inv.
    APPEND i_inv.
    ENDAT.
    CLEAR i_inv.
    ENDLOOP.
    SORT i_inv BY ebeln ebelp.
    break-point.
    ENDIF.
    ENDIF.
    Move the Vendor Name and Invoice Values to I_rep Internal Table
    LOOP AT i_po.
    MOVE-CORRESPONDING i_po TO i_rep.
    CLEAR i_inv.
    READ TABLE i_inv WITH KEY ebeln = i_po-ebeln
    ebelp = i_po-ebelp.
    IF sy-subrc = 0.
    i_rep-orewr = ( i_po-menge - i_inv-menge ) * i_po-netpr.
    i_rep-curr = i_inv-waers.
    ELSE.
    i_rep-orewr = i_po-menge * i_po-netpr.
    i_rep-curr = i_po-waers.
    ENDIF.
    break-point.
    Get the Vendor Name
    CLEAR lfa1-name1.
    SELECT SINGLE name1 FROM lfa1 INTO lfa1-name1
    WHERE lifnr = i_po-lifnr.
    IF sy-subrc = 0.
    i_rep-name1 = lfa1-name1.
    ENDIF.
    APPEND i_rep.
    CLEAR i_rep.
    break-point.
    ENDLOOP.
    SORT i_rep BY lifnr ebeln ebelp.
    DELETE i_rep WHERE orewr LE 0.
    break-point.
    ENDFORM. " fetch_data
    *& Form display_data
    Display the Report Output data
    FORM display_data .
    DATA: lv_flag, " New Flag
    lv_rec TYPE i. " No of Records
    CLEAR lv_rec.
    IF i_rep[] IS INITIAL.
    MESSAGE e000 WITH 'No Data found'(022).
    ELSE.
    LOOP AT i_rep.
    Toggle Color
    PERFORM toggle_color.
    IF lv_flag space.
    NEW-LINE.
    ENDIF.
    At New Purchase Document
    AT NEW ebeln.
    WRITE:/1 sy-vline, 2(10) i_rep-ebeln INTENSIFIED OFF.
    lv_flag = c_x.
    lv_rec = lv_rec + 1.
    ENDAT.
    WRITE: 1 sy-vline,
    12 sy-vline,13(4) i_rep-bsart,
    17 sy-vline,18(10) i_rep-lifnr,
    28 sy-vline,29(35) i_rep-name1,
    64 sy-vline,65(4) i_rep-ekgrp,
    69 sy-vline,70(10) i_rep-bedat,
    80 sy-vline,81(5) i_rep-ebelp,
    86 sy-vline,87(40) i_rep-txz01,
    127 sy-vline,128(9) i_rep-matkl,
    137 sy-vline,138(1) i_rep-pstyp,
    139 sy-vline,140(1) i_rep-knttp,
    141 sy-vline,142(4) i_rep-werks,
    146 sy-vline,147(4) i_rep-lgort,
    151 sy-vline,152(13) i_rep-menge UNIT i_rep-meins,
    165 sy-vline,166(3) i_rep-meins,
    169 sy-vline,170(15) i_rep-netpr CURRENCY i_rep-waers,
    185 sy-vline,186(4) i_rep-waers,
    190 sy-vline,191(5) i_rep-peinh,
    196 sy-vline,197(4) i_rep-bprme,
    201 sy-vline,202(15) i_rep-orewr CURRENCY i_rep-curr,
    217 sy-vline,218(4) i_rep-curr,
    222 sy-vline,223(7) i_rep-bstyp centered,
    230 sy-vline.
    NEW-LINE.
    hide: i_rep-ebeln.
    ENDLOOP.
    ULINE.
    FORMAT COLOR OFF.
    WRITE : /2 'Total Number of Purchasing Documents:'(025) COLOR 3,
    lv_rec COLOR 3.
    ENDIF.
    ENDFORM. " display_data
    *& Form header
    Write the Report Header
    FORM header .
    FORMAT RESET.
    header
    WRITE:/1(230) 'LIST OF PURCHASE DOCUMENTS PER VENDOR'(006) CENTERED.
    SKIP.
    FORMAT COLOR COL_HEADING.
    ULINE.
    WRITE:/1 sy-vline,2(10) 'Pur.Doc.No'(006) CENTERED,
    12 sy-vline,13(4) 'Type'(007),
    17 sy-vline,18(10) 'Vendor'(008) CENTERED,
    28 sy-vline,29(35) 'Name'(009) CENTERED,
    64 sy-vline,65(4) 'PGrp'(010) CENTERED,
    69 sy-vline,70(10) 'Doc.Date'(012) CENTERED,
    80 sy-vline,81(5) 'Item'(011),
    86 sy-vline,87(40) 'Material Short Text'(024) CENTERED,
    127 sy-vline,128(9) 'Mat.Group'(013),
    137 sy-vline,138(1) 'I',
    139 sy-vline,140(1) 'A',
    141 sy-vline,142(4) 'Plnt'(014),
    146 sy-vline,147(4) 'SLoc'(015),
    151 sy-vline,152(13) 'Quantity'(016) CENTERED,
    165 sy-vline,166(3) 'UoM'(017),
    169 sy-vline,170(15) 'Net Value'(018) CENTERED,
    185 sy-vline,186(4) 'Curr'(019),
    190 sy-vline,191(5) 'Per'(020),
    196 sy-vline,197(4) 'Unit'(021),
    201 sy-vline,202(15) 'To be Invoiced'(023) CENTERED,
    217 sy-vline,218(4) 'Curr'(019),
    222 sy-vline,223(7) 'Doc.Cat'(026),
    230 sy-vline.
    ULINE.
    ENDFORM. " header
    *& Form toggle_color
    This routine alters the color of the records in the list FORM toggle_color.
    IF gv_dial = space.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    gv_dial = c_x.
    ELSE.
    FORMAT COLOR 1 INTENSIFIED OFF.
    CLEAR gv_dial.
    ENDIF.
    ENDFORM. " toggle_color
    *& Form LINE_SEL
    *When double clicked on EBELN field display the details of Purchase Doc
    FORM line_sel.
    CASE sy-lsind.
    WHEN '1'.
    DATA: lv_field(20),
    lv_value(10),
    lv_bstyp like i_rep-bstyp.
    clear: lv_bstyp,lv_value, lv_field.
    GET CURSOR FIELD lv_field VALUE lv_value.
    IF lv_field = 'I_REP-EBELN'.
    IF NOT lv_value IS INITIAL.
    READ LINE sy-index FIELD VALUE i_rep-bstyp
    INTO lv_bstyp.
    READ CURRENT LINE FIELD VALUE i_rep-bstyp INTO lv_bstyp.
    if lv_bstyp = 'F'.
    SET PARAMETER ID 'BES' FIELD lv_value.
    CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    elseif ( lv_bstyp = 'K' or lv_bstyp = 'L' ).
    SET PARAMETER ID 'VRT' FIELD lv_value.
    CALL TRANSACTION 'ME33' AND SKIP FIRST SCREEN.
    elseif lv_bstyp = 'A'.
    SET PARAMETER ID 'ANF' FIELD lv_value.
    CALL TRANSACTION 'ME43' AND SKIP FIRST SCREEN.
    endif.
    ENDIF.
    ENDIF.
    ENDCASE.
    ENDFORM. " line_sel{code]
    <REMOVED BY MODERATOR>
    kushagra
    Edited by: Alvaro Tejada Galindo on Feb 18, 2008 2:03 PM

  • Table name and field name for accounting and material document in MM

    Hi
    Table name and field name for accounting and material document in MM
    how can we diffreentiate the accounting document in MIGO and MIRO ?

    Hi,
    For Goods reciept documents you can search from the tables  MKPF-Header: Material Document and MSEG-Document Segment: Material,
    and for Invoice documents you can search in  tables   BKPF-Accounting Document Header and BSEG-Accounting Document Segment.
    For differentiating the Accounting documents in MIRO and MIGO based on posting key and document types for GRN -document key is -WE and for MIRO document is -RE.......
    Hope this may help you.....................

Maybe you are looking for

  • How to find permissions of a particular user on a table

    Hi every body i have requirement to check the permissions of a particular user on a table , requirement is i am building a query builder ,wherein i have to load all the tables from database ,before loading the tables i need to check whether the user

  • Why is iTunes pricing so much more than Amazon

    I am curious as to why iTunes pricing is way more expensive than Amazon for both music and movies??

  • Upgrading JVM in 10g and 9 - again

    Hi I need to have Java 1.5 in Oracle Database 10 and 9. I know that there was a disscussion on this in Re: Oracle 9.2 update jvm's jdk? But it was 2007. Has something change in this matter ?? Kuassi wrote "We are looking into this for future releases

  • EM console HA page says "Data Gaurd not configured for this database"

    I am attempting to use EM console's "High Availability Console" to create a standby database, but, the option is not available. Under "Data Gaurd Summary" the page shows "Oracle DataGaurd is not configured on this database." How do I configure this o

  • NXT case structure

    Hey Im making an nxt robot for a competition and it has to go thru two phases for the competition.  Shifting between phase 1 and 2 is controlled by a timer.  the only issue im having is how to setup multiple shift registers for my program Attachments