ABAP routine/lookup in update rule

Hello Gurus, I am trying to do a lookup from 2 ODS's into one. I am trying to join sales and delivery data.
My current idea is that I will use the 2LIS_11_V_SSL extractor that has SO, SOitm, DO, DOitm data and bring that into an ODS that has those four items as the key.
During that update, I will need specific fields (mostly key figures - Net Price from the SalesOrder ODS, and Del. Qty from the DelOrder ODS).
The SO and DO ODSs each have a key of SO/SOitm and DO/DOitm respectively.
What I am trying to do is write a routine for each of the necessary fields to do a lookup on the source ODS and bring in the field value according to the SO/SOitm or DO/DOitm key.
A simplified example
<u>Target ODS</u> Initially coming from 2LIS_11_V_SSL (keys)
<b>SO
SOitm
DO
DOitm</b>
Net Price
Del. Qty
<u>SO ODS</u>          
<b>SO              
SOitem</b>          
Net Price       
<u>Del Order ODS</u>
<b>DO
DOitm</b>
Del Qty.
I have the 4 key fields coming from another extractor, need to lookup the key figures from the other ODSs on the load
If I could get some example code on how to do this I would greatly appreciate it! I was told an internal table might do the trick, but after scouring the forums I can't find anything that seems close enough.
Thanks!
Justin
Message was edited by: Justin  Molenaur
Message was edited by: Justin  Molenaur

Ajay (or anyone else)...one more question
Is there a way to limit the number of times that the net price field may be written.
for example, a SO item may be associated with multiple delivery order items, so you only want to write the net price field once PER sales order item. If we did it just like above, everytime a sales order item had multiple delivery order items, there would be multiple net price values for each delivery order item, which is not correct (see spreadsheet).
Sales Order     Sales Order item     Delivery Order     Delivery Order item     Net Price (SO)     Del Qty (Del)
1     10     100     10     15     150
2     10     101     10     25     200
<u>2     20     101     20     <b>50</b>     250
2     20     101     30     <b>50</b>     299</u>
3     10     102     10     23     213
4     10     102     20     27     476
So the challenge would be to create a counter(?) or something that will only allow a SOitm to have only one net price.
Thanks for you help!
Justin
Message was edited by: Justin  Molenaur
Message was edited by: Justin  Molenaur

Similar Messages

  • How to calculate the runntime of a routine in an update rule

    I'm facing a performance problem with the loading of an ODS.  After some analysis I'm almost sure that the problem is due two routines (in the update rule) that are looking into master data tables 200.000 times ( quantity of records loaded every day).  But before moving that logic back into the extractor I need to be sure that the runntime will be reduced.  Is there any way to obtain the amount of time spent by those routines?.  I have been checking into the transactions ST03N and STAD but I'm not able to find this information.
    Thank you very much in advance.
    My best regards.
    Pablo Mazzucchi

    Hi,
    For performance problem you can try to get the look data in an internal table at start routine and use them and read for the fields you need which will help you in decreasing the run time vs hitting the database direclty for getting the look up information.
    This will bring you a noticable change in run time of data load.
    Lets wait if some other has routines to get run time of the routine
    Thanks,
    Arun.

  • How to get the PSA name in a Start Routine in the Update Rules of a Cube.

    Hi all.
    I have an InfoSource that loads data directly in an Infocube.
    In the Start Routine of the Update Rules I need to retrieve the PSA table name for that InfoSource, to access it and check some data.
    I can't use the PSA name you seen in the DataFlow because it will change once the update rules are transported to another system.
    Please advice.
    Thanks!!!

    Hi,
    we do it as follows:
    first get the request ID:
    DATA: tp_request(30)   VALUE 'REQUEST'.
    FIELD-SYMBOLS: <wa> TYPE ANY, <tp_req> TYPE ANY, <tp_dtp> TYPE ANY.
    READ TABLE datapak ASSIGNING <wa> INDEX 1.
    IF sy-subrc <> 0. ABORT = 4. ENDIF.
    ASSIGN COMPONENT tp_request  OF STRUCTURE <wa> TO <tp_req>.
    IF sy-subrc <> 0. ABORT = 4. ENDIF.
    requnr = <tp_req>.
    then we get the table with
    SELECT odsname_tech FROM rstsodspart WHERE request = requnr.
    you may need to adjust this code, I've just pasted the relevant parts...
    another way is to get this info from RSTSODS where the different versions are maintained...
    let me know if you need further detail about this stuff...
    hope this helps...
    Olivier.
    Message was edited by:
            Olivier Cora

  • Filtering records using a start routine inside the update rules for a dmart

    Hi
    I am using a start routine inside the update rules. I want to filter out all records that have 0 in all three fields. My problem is that it not only filters these records, but also filter records with negative values, which I do not want. Only 1 field has a negative value, the other 2 have 0.
    I have tried:
    DELETE DATA_PACKAGE where  /BIC/ZBILLCONS = 0 and /BIC/ZBREVPRIM = 0  and /BIC/ZBREVSUBO = 0 .
      DELETE DATA_PACKAGE where ( /BIC/ZBILLCONS = 0 and /BIC/ZBREVPRIM = 0  and /BIC/ZBREVSUBO = 0 ).
    also tried:
    delete DATA_PACKAGE where /BIC/ZBILLCONS IS INITIAL and
    /BIC/ZBREVPRIM IS INITIAL and  /BIC/ZBREVSUBO IS INITIAL.
    The records are going to 1 cube and 1 ODS, I only have the start routine in 1 update rule. I  view the filtering in the PSA.
    Has anyone ran into this before?

    Try
    delete data_package where /BIC/ZBILLCONS = '0' and /BIC/ZBREVPRIM = '0' and /BIC/ZBREVSUBO = '0' .
    OR
    delete data_package where /BIC/ZBILLCONS EQ '0' and /BIC/ZBREVPRIM EQ '0' and /BIC/ZBREVSUBO EQ '0' .
    Good luck!

  • ABAP assistance - start routine logic in update rule

    I have used an existing update rule and have based my logic around the same.  The purpose of the rule is to look up customer master data and get a subset of customer numbers from the transaction records so that the values for customer number from the transactional data will not be updated if it does not match with existing master data customer numbers.
    The loads are full and we drop the data before we load.
    I have listed the logic below (the number at the front is to be considered as the line number) and a list of open questions that I have thereafter:
    Start routine logic:
    1  DATA: l_index LIKE sy-tabix.
    2  DATA: BEGIN OF ls_customer,
    3        customer TYPE /BI0/OICUSTOMER,
    4        objver TYPE RSOBJVERS,
    5     END OF ls_customer,
    6      lt_customer LIKE TABLE OF ls_customer.
    7  REFRESH: lt_customer.
    8  LOOP AT DATA_PACKAGE.
    all customers from data package
    9    ls_customer-custno = DATA_PACKAGE-custid.
    10  ls_customer-objver = 'A'
    11    APPEND ls_customer TO lt_customer.
    12   ENDLOOP.
    12  SORT lt_customer.
    13  DELETE ADJACENT DUPLICATES FROM lt_customer.
    14   IF NOT lt_customer[] IS INITIAL.
    15    SELECT /BI0/OICUSTOMER RSOBJVERS
    16      FROM /BI0/PCUSTOMER
    17      INTO CORRESPONDING FIELDS OF TABLE lt_customer
    18      FOR ALL ENTRIES IN lt_customer
    19      WHERE ls_customer-custno = DATA_PACKAGE-custid
    20      AND ls_customer-objver = 'A'
    21    SORT lt_customer BY customer ASCENDING                    
    22  ENDIF.
    Questions
    Line
    1 - what is the purpose of this line? What is it that is being declared
    2 - in some code I have seen this line with OCCURS 0 at the end what does this mean with and without the term?
    4 - I am using the Data Element name is this correct or should I use the field name?
    3 - 5 here I declare an internal structure/table is that correct?
    6 - here I declare a work area based on the internal table is that correct?
    7 - What would happen if I avoided using the REFRESH statement?
    8 - 12 - Is this syntactically correct, I am trying to get a set of data which is the customer numbers which match the master data customers and the master data record is án active version and than appendíng to the work area?
    13 - My understanding is this will reduce the number of records in the work area is this correct and needed?
    14 - 22 I am trying to identify my required set of data but feel I am repeating myself, could someone advise?
    Finally what logic would I actually need to write in the key figure object, could I use something like:
    Result = lt_customer.
    Thanks
    Edited by: Niten Shah on Jun 30, 2008 8:06 PM

    1. This line is not required
    2. OCCURS 0 is the OLD way of defining an internal table with that structure.  As it is, it just defines a flat structure.
    3. Data element is usually best
    3-5 Yes
    6. No.  Here you are declaring a table of the type of the flat structure.  Just as the ABAP says!
    7. Nothing.  But by putting this in, you ensure that you know the state of the table (empty) before you start looping through the data package
    8-12. You can tell if it is syntactically correct by pressing Ctrl-F2 when in the editor.  Looks ok.
    13. Ensures your list of customers contains no duplicated.  The code up to this point is building a list of all the unique customers in the data package.
    14-22. Goes to the database and brings back ONLY those customers which are found in the master data.  Looks ok.
    This is a start routine (that's why you've got a data package).  You don't use result.  You should update the datapackage.  But this you haven't done.  Double click on the table name /BIC/PCUSTOMER to get the correct field names.
    So you have to loop through the data package again, and check if the customer in the datapackage is lt_customer.  If it is, fine, otherwise you blank it and report an error, or set an error message or whatever.
    I wouldn't do it like this.  I'd do something like this:
    STATICS: st_customer TYPE HASHED TABLE OF TYPE /bi0/oicustomer
                                  WITH UNIQUE KEY TABLE_LINE.
    * st_customer retains its value between calls, so only populate if empty
    * In one run of the infopackage, this will mean you do only one read of
    * the master data, so very efficient.
    IF st_customer IS INITIAL.
      SELECT customer FROM /BI0/PCUSTOMER
                              INTO TABLE st_customer
                              WHERE objvers EQ 'A'. " Only active values
    ENDIF.
    * Go through data package
    LOOP AT DATA_PACKAGE.
    * Check whether the customer exists.
      READ TABLE st_customer TRANSPORTING NO FIELDS
                  WITH TABLE KEY table_line = DATA_PACKAGE-custid.
      CHECK sy-subrc IS NOT INITIAL.
    * If you get here, the customer isn't valid.  So I'm just setting it blank
      CLEAR DATA_PACKAGE-custid.
      MODIFY DATA_PACKAGE. " Updates the datapackage record
    ENDLOOP.
    Even this is not fully optimised, but it's not bad.
    I strongly suggest that you get yourself sent on the basic ABAP programming course if you're going to do a lot of this.  Otherwise, read the ABAP documentation in the help.sap.com, and, from the editor, get the cursor on each ABAP keyword and press F1 to read the ABAP help.
    matt

  • Need hints to bring BC400(ABAP) knowledge to BW update rules/routines.

    Hi,
    I have just completed the BC400 (ABAP) course at SAP but the instructor had no clue about BW.
    From se80, he thought how to create packages, programs, functions modules, classes/Interfaces, etc. but whenever, I asked how these fit into the BW update rules and transfer rules, he said he knew nothing about BW.
    For example, how do I bring in a program written in se80 into my update rule or transfer routine which updates and ODS or cube?
    i.e. The main reasoning for learning this BC400(ABAP) is to be comfortable in writing update rule or transfer routine to update ODS/Cubes in BW but the instructor failed me in making the link between the ABAP class and BW.
    Can you give me some guide on this?
    Can I work in se80 as I was taught and bring codes from there to update a cube?
    i.e. if I need to write an update routine to update a cube from an ODS, can this be done in se80 (on BW)
    I will appreciate any guidelines to bring in my new found knowledge to the BW environment.
    Thanks

    Most Bw transformations are already includes inside programs or cmods or BTEs
    By double cliking on start routines and end routines it already takes you into the ABAP enviroment
    Have a look at the sappress book - user exits and BADIs in BW (it's not a brillaitn book by any means - it's just about passable and is short on detail - but it will get you a head start)

  • ABAP objects for transfer/update rules - does this apply to include stateme

    I have a question about the new requirement for the code in the update/transfer rules to be written in ABAP Objects standards.  Does this still apply if in your update rules you using include programs?  Does this mean that when we upgrade we will have to follow the ABAP Objects standards (ie no header lines)?

    Routines will method based.
    In addition to what Chetan has sent, check this how to also.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6090a621-c170-2910-c1ab-d9203321ee19
    Ravi Thothadri

  • Abap Code help in update rule

    Hi Gurus,
    I have  a requiement, that is if there are 5 line items with in a document and each one has diffeerent tax jurisdiction code, then we should be showing only one tax jurisdiction code for a document. Line items are not displayed in report. The condition to pick up tax jurisdiction code is the one which has least ending zeros among all the lime items with in a document.
    Supppose
    Doc1 Item Tax Jurisdiction code
    1800000002 1 CNQC00000000000
    1800000002 2 CNQC00000000000
    1800000002 3 CN0000000000000
    1800000002 4 CNQC00000000000
    1800000002 5 TXJOHNCLEBUR000
    So here the value of Tax Jurisdiction code is TXJOHNCLEBUR000 as it has least ending zeros compared to other values with in a document.
    Any help how to use the string function and acheive the desired result.
    Thanks,
    Raj.

    Hi Anand,
    Thanks for the reply. we don't expect any non-zeros after seeing first zero. Now i have added another z object which will contain only least zeros for a doc. What I am doing is now after loading the data into the cube from ods  i am doing loop back and updating the new z object. Below is the code I am trying to do
    TABLES: /BIC/AZFGLO10100.
    Defining an internal table as ods table****
    Types: BEGIN OF ITAB_01,
    doc_no LIKE /BIC/AZFGLO10100-AC_DOC_NO,
    item_no LIKE /BIC/AZFGLO10100-ITEM_NUM,
    taxjur LIKE /BIC/AZFGLO10100-TAXJURCODE,
    length like num,  ***** this will hold the length of the zeros
    END OF ITAB_01.
    loading the data from active ods table into defined internal table*****
    select AC_DOC_NO ITEM_NUM TAXJURCODE  from /BIC/AZFGLO10100 into table
      Itab_01 where AC_DOC_NO = /BIC/AZFGLO10100-AC_DOC_NO and
      item_num = /BIC/AZFGLO10100-ITEM_NUM.
    sort itab_01 doc_no item_no
    now I want to use code too populate the vlaue of length field in internal table (which shows how many zeros a tax jurisdiction code has for every corresponding line item)
    then in the update rule of z tax jurisdiction i will wirte a routine such that
    select taxjur into result from itab_01 where doc_no = COMM_STRUCTURE-doc_no and length = min(length).
    now I have one more doubt , the number of items in a document will be varying so how to takecare of this...
    If possible can you please provide me with the abap code that you have mentioned in earlier post.
    Any more help on this is really appreciated.
    Thanks,
    Raj

  • How can I view the code for a routine in an update rule

    on loading data for 0PLANT_ATTR, I am getting an error for No Local Currency found in Plant 1000 and SAles Org 6000. 
    in looking at the update rules for this, I see that there is a routine for the update of the local currency:
    Perform GET_LOCCURRCY_FOR_PLANT
    USING COMM_STRUCTURE-PLANT
    COMM_STRUCTURE-SALESORG
    CHANGING hlp_monitor
    RESULT
    hlp_subrc.
    How do I see the code behind this?  I want to make sure that I understand everything that needs to be populated in Master Data so that I can ask my functional consultant to update all the necessary fields.
    Thanks
    JP

    Hi Riccardo,
    When I double click on it, I get a message at the bottom that says program reindexed. 
    After looking again, I found that when I double clicked on the comm structure, then the routine, I was able to see it.
    Thanks
    JP

  • Attribute or routine first in update rule

    Hi
    In my update rules if i populate a characteristics from master data (Ex: 0MATL_GRP from 0MATERIAL) and write a routine to populate other keyfigure based on the attribute. Will it work when i execute the infopackage.
    My requirement is after populating the 0MATL_GRP only, the key figure should be calculated based on the 0MATL_GRP.
    Hope i am clear.
    Regards
    Annie

    Hi
    Thanks for the replies:
    PB: <b>One more way is..just add 0MAT_GRP in the ODS and in the update rules; select the update method as "Master Data Attr. of" - 0MATERIAL (0MAT_GRP is an attribute of 0MATERIAL), so no need to populate in the start routine.</b>
    Now if i add 0MAT_GRP in ods and in the update rules; select the update method as "Master Data Attr. of" - 0MATERIAL (0MAT_GRP is an attribute of 0MATERIAL)
    And in INCENTIVE keyfigure if i write a routine based on 0MAT_GRP and execute the infopackage, will my requirement be met.
    Condition is: After populating the 0MAT_GRP only my kf routine should run.
    So will execute infopackage will 0MAT_GRP is an attribute of 0MATERIAL) run <b>first?</b> or routine in kf
    Regards
    Annie

  • ABAP Help needed with update rule

    I have created a new keyfigure A and a new keyfigure B in 1 update rule, derived from basic keyfigures. Keyfigure C is calculated by adding A and B together...in the same updaterule.
    keyfigure A and B are filled (recalculated ) as expected but keyfigure C remains empty. Can anybody tell me why?
    regards,
    tom

    Hi Tom
    I think you have written a update rule for all the three keyfigures A, B and C.
    When you write an update routine it is local and the value returned by any routine or calculation can not be accesed by other keyfigure. The Key Figure C will be calculated with values of A and B from the datapacket which are both SPACE(not from the values returned by update routines of A and B). so value of C will always be SPACE or Empty.
    To solve the problem write Start Routine for calculating A B and C
    Please assign points if helpful.
    Neelima
    Message was edited by:
            Neelima Ravipati

  • Routine /Formula in update rule

    Hello
    I am trying to use formula function in update rule but its giving me error
    scenerio here is
    I tried with routine syntax wise itz correct but not working
    here is the example
    fill theIF 'KNART' eq 'ZP01'. internal table "MONITOR", to make
    result value of the routine
    RESULT = 'KNVAL'.IF 'KNART' eq 'ZP01'.
    ENDIF.
    if abort is not equal zero, the update process will be canceled
    ABORT = 0.
    $$ end of routine - insert your code only before this line -
    ENDFORM.
    trying to update with knval( avleble in commication structure) only if other(KNART is eq zp01) i found sysntaxwise code is correct but its giving me shortdump at teh time of loading
    any input will be great help
    cheers
    Praveen

    Hi
    I tried with this code though its syntax wise correct but again its not working
    IF COMM_STRUCTURE-KNART eq 'ZP01'.
    RESULT = COMM_STRUCTURE-KNVAL.
    ELSE.
    RETURNCODE = 1.
    ENDIF.

  • Master Data lookup in Update Rule problem

    Hi all,
    I am currently having a problem loading data to an InfoCube using flat files.
    The architecture is as follows:
    1) The source of the data is a flat file
    2) The data is loaded thru an Update Rule and is of type Full-Update
    3) The Update Rules determines the Profit Center using the Master Data of the WBS-Element
    4) The data is written in an InfoCube
    This solution however does not always work as planned. In the following situation a problem occurs:
    1) The flat file contains WBS-element RD.00753.02.01, which has a Profit Center attribute value 8060
    2) When I load the flat file, the PC value 8060 is written into the row in the InfoCube, which is correct
    3) Then I change the master data of the WBS-element by setting the Profit Center attribute value to 8068
    4) I run the Attribute Change Run
    5) Then i load a flat file again, which also contains WBS-element RD.00753.02.01
    6) The master data attribute value should now write the value 8068 into the InfoCube. HOWEVER, this is when the evil occurs. BW does not write a PC value of 8068, but it write the value 8060. This is wrong.
    Why does BW not take the newest version of the Master Data to performe the attribute value look-up? Or why doesn't BW write the correct Profit Center into the cube?
    Thanks,
    Onno

    Hi Ricardo,
    The debug via PSA simulation of the update indicates that the CORRECT Profit Center value is to be written into the InfoCube.
    However, if I check the contents of the cube (after the load has finished) using the request-id the WRONG Profit Center value is shown. This indicates that the correct Master Data is used, however the update of the Cube is wrong. Why does this happen. the load is of type full-update, so should add a new row in the cube using the value in the data from the UR.
    Onno

  • Lookup in update rules to a R/3 table

    Can I do a look up to a table that physically exists on the R/3 side in my upate rules.
    If yes, how?
    GMAT

    Nope, directly if you need information from the transactional system R/3, you must first create all the DSO, datasource and transformations (tranfer rules, etc) in order to load such information first into BI and use it as reference in your routines, OR if it's few information and you have an excellent comunication infrastructure, you can create a remote function call or even a virtual remote infocube (all depends of your needs) but this is a good solution only if you are going to transfer few data and not frequently (avoid overhead in you BI platform).
    Few reference data and not frequent execution then:
    --> The best solution will an RFC but bear in mind that this will require a more complex mainteinance but is an excellente alternative to maintain a DSO.
    A lot of data and a frequent reference to data from R/3.
    --> Load such information into an DSO in BI and create all the infraestructure to populate from R/3.
    Ebert

  • Database access in update rules

    Hi all,
          I am planning to write an ABAP routine for a update rule. Now I want to know whether I can find out some data from some tables. These data are a part of my master data.
          Let me explain; I have a field in the communication structure called BookID and two dimensions in the cube called BookID and AuthorName. Now both these dimensions are characteristic infoobjects with some master data already uploaded.
          I have to write a update rule routine, where I'll fetch the AuthorName from the BookID. AuthorName is an attribute of BookID.
          Can you tell me if this is possible? If yes, then which are the database tables I need to look at? Also, some code examples will really help.
          If it's not possible, please suggest some way to do it. Currently I have AuthorName as "Master data attrib. of" BookID. But still it doesn't update the records. New records are being created with only BookID. No AuthorName.
          Please help.
    Thanks,
    Satyajit.

    hi,
    are you going to update AuthorName in master data BookID or AuthorName in the cube ? do the AuthorName set as 'navigational' attribute of BookID ?
    Both are possible for update.
    Master data has 3 tables (beside other table) : text, attribute and hierarhy.
    For master data that's not time-dependent, attribute are stored in /bi0/p[infoobject name] - without 0, e.g infoobject 0customer has /bi0/pcustomer table for attribute. for our own created infoobject it's stored in /biC/p[infoobject name], e.g ZCUSTOMER has /bic/pZcustomer table.
    For update in infocube, if you didn't set it as navigational attribute, you may use Update Method 'Master data attrib. of'.
    sample code :
    data : it_data_package like DATA_PACKAGE occurs 0 with header line,
           begin of it_authorname occurs 0,
              /bic/zbookid like /bic/pzbookid-/bic/zbookid,
           end of it_authorname,
           l_tabix like sy-tabix.
    tables : /bic/pzbookid.
    select /bic/zbookid
    from /bic/pzbookid
    into corresponding fields of table it_authorname
    for all entries in data_package
    where /bic/zbookid = data_package-/bic/zauthorname.
    loop at DATA_PACKAGE.
    endloop.

Maybe you are looking for

  • Wow the new firmware has made a mess of my Touch, Creative please resp

    Okay, first I find out that some of my music is missing track number tags and is now listed in alpabetical order. Next, Media Source doesnt detect my Touch at all, so I have no easy way to fix my tags. So I have to move the music off my player, tag i

  • IMac 20" - Gradient on display

    I have recently bought a second hand iMac - (20" 2.4Ghz Intel Core Duo - Aluminium). All was great for the first day untill I did my first bit of design on it. The design had a thick red stripe at the top and bottom of the page. I was confused to see

  • Dynamic where condition in Select statement

    Hi, I have 10 fields on selection-screeen. In which ever field the user enters single values or ranges,i should pick that field dynamically and pass that field along with value range to Where condition of Select statement.How can i achieve this? Plea

  • Driver Issues

    Greetings... I have a MSI TD-128 Pro (GeForce3Ti200/128MB DDR), and usually use nVidia's Det drivers.  However, upon trying MSI's 31.00 drvs (based on the Det 30.82), I got better performance, and added features.  Now, MSI has two new sets of drivers

  • HT201514 The backup disk image "/Volumes/Time Capsule-1/Dullahan Mac mini.sparsebundle" is already in use.

    My time capsule cant find its disk to back-up to..I have tryed everything.Need help.. Pinhead