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

Similar Messages

  • 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!

  • Start Routine Logic Updating Field in Target ODS

    Hi,
    I am creating a  Start Routine to Update Field (date) from one ODS to another based on the Key Structure: Document Number, Line Item Number.
    I am encountering a situation as follows:
    Source
    Doc Num 1 Line Item 10 Date 1/1/1
    Target
    Doc Num 1 Line Item 10 Date 1/1/1
    DocNum 1 Line Item 20
    DocNum 1 Line Item 30
    DocNum 1 Line Item 40
    The Routine I have now correctly updates line item 10 with the date 1/1/1.
    I am trying to modify the code to only update the target ods if all of the line items are in the source.  In this example Line Item 10 would not get updated since Line Items 20,30,40 are not in the Source ODS. 
    Has anyone encountered something like this.
    Thanks for any help.

    Hi,
    If you have all the line items in target for which you want to do updates  you can do this in transformation start routine.
    Try this first hand logic :
    1. Create a internal tables(say SOURCE_INTERNAL_TABLE and TARGET_INTERNAL_TABLE)
        with fields document number and another field integer say COUNTER
    2. Read active table of source for all the document numbers in source package.
    3. Update the SOURCE_INTERNAL_TABLE for all the document number with appropriate counts
        (All the records of same document number should be in same data package)
    4. Update the TARGET_INTERNAL_TABLE by reading the target ODS as done for source.
    5. LOOP  AT SOURCE_PACKAGE
         if COUNTER in SOURCE_INTERNAL_TABLE and TARGET_INTERNAL_TABLE is not same
         then delete the record from source package itself
       END LOOP
    6. Your next code
        (Please take care that you are not referring the deleted records otherwise it will through a dump)
    If you don't have all the line items in target then you need to bring them somewhere in BI (document number and item number only sufficient with both as a key fields) so as to refer them in your start routine.
    Please update me if anything is wrong or if any corrections in logic.
    Thanks and Regards,
    Prashant Vankudre.

  • 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.

  • Creating a start routine in the transfer rule

    I'VE CREATE a start routine, seel bleow.  Now I want to get at one of the fieds for a Key figure.    How do i do that?    do I need to add it to the transfer structure
    LOOP AT ROUTEDAY INTO WA_ROUTEDAY.
    CALL FUNCTION 'CONVERSION_EXIT_TSTRG_OUTPUT'
    EXPORTING
       input = ROUTEDAY-ROUTE_DAYS
    IMPORTING
         output = WA_DAYS_OUT.
      WA_ROUTEDAY-ROUTE_DAYS_CONV = WA_DAYS_OUT.
      APPEND WA_ROUTEDAY.
    ENDLOOP.

    Hi Mick,
    check these links
    start routine in transfer rules
    Look up to load master data
    excluding
    Start Routine in Transfer Rules
    Sample code in Update Rule to restrict data selection?
    Append Datapak - transfer start routine
    Excluding Blank field in Infopackage Filter
    Trans Routine ABAP help ..
    Hope this might help you.
    ****Assign Points If Helpful****
    Regards,
    Ravikanth

  • How to Code "AND" logic in Update Rule?

    Hi:
    I have minimal ABAP knowledge and need some help....
    I have to use the Query logic and code in my Update rule... (i.e. multiple conditions have to be met)
    IF (COMM_STRUCTURE-Sales_Org = '100' AND  COMM_Structure-Division = 'LA' AND COMM_STRUCTURE-Acct_Grp = '0120')
          RESULT = COMM_STRUCTURE-Credit_Amoutn (I want to assign a specific KF)
    ELSE
         RESULT = 0 (I want to assign Zero)
    ENDIF
    I attempted this logic, but I keep getting an error with 'AND' statement.  I am not sure what is the syntax.
    Can someone please help me out with the  logic/sytax
    Thanks..... Lee

    Hi:
    I responded without checking the logic.... assuming it would work...!~
    Unfortunately it gives me error:
    QUOTE
    E:Incorrect logical expression: ")" must be followed by "AND" or "OR" . .
    UNQUOTE
    Can anyone help me resolving this please....!!!!
    Thanks... lee

  • 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

  • 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

  • ABAP code help for 0PROFIT_CTR  (in Update rules)

    Hi
    Can you please give me the update rules code that would do the following in BW 3.5:
    If Profit Center is 10 digits long, its ok but if Profit Center is 5 digits long, concatenate with 5 zeros.
    Thanks
    Jimi
    Edited by: jimi ogun on Dec 1, 2011 1:44 PM

    Hi Soorej
    I tried teh code in my transfer rules but the result was blank. I guess it was because i didnt insert anything in the RESULT line... This is what i tried to do but i get a syntax error:
    $$ begin of routine - insert your code only below this line        -
    DATA: l_s_errorlog TYPE rssm_s_errorlog_int.
    data : len type i,
          v1(10) TYPE c value 'abcde'.
    len = strlen( v1 ).
    if len = 5.
    CONCATENATE v1 '00000' into v1.
    endif.
      RESULT = /BI0/OIPROFIT_CTR.
    returncode <> 0 means skip this record
      RETURNCODE = 0.
    abort <> 0 means skip whole data package !!!
      ABORT = 0.
    The syntax error i get is below:
    E:Field "/BI0/OIPROFIT_CTR" is unknown. It is neither in one of the
    specified tables nor defined by a "DATA" statement. "DATA" statement.

  • 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.

  • Need Start routine logic

    Hi,
    Can anyone please let me know the code in start routine for the below.
    I want to delete the unwanted datapackage in start routine for the below condition.
    For  system PCR
    For purch.org Z300, only those purchase orders shall be loaded to further layers which have the text "FCM" in the field Incoterms2 (ZPURINC2), the other purchase orders of this purch org and this system can be deleted.
    thankyou........
    Regards...
    Balaji

    Hi,
    Delete Source_package where SYSTEM = 'PCR' and PURCH.ORG = 'Z300' and ZPURINC2 NE 'FCM'.
    Check the definition of source_package in the start routine screen and use the exact infoobjects while defining the Delete statement
    Regards
    Githen

  • Start Routine logic problem !

    Experts ,
    in my start routine,
    my Source-field-fieldname has value "ABC123"
    and i need to assing this value in reverse order like "123ABC" to the Infoobject.
    How do i get this output ?
    thankss

    Hi Honar ,
    Please use this code to reverse the strings.I think you want it like
    Input : "ABA123"
    Output : "321CBA"
    for this use below code
    data : v_Input (20) type c .
    data : v_Output(20) type c.
    LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS> .
    v_Input =   <SOURCE_FIELDS>-FIELDNAME .
    CALL FUNCTION 'STRING_REVERSE'
    EXPORTING
    string =v_Input
    lang = 'E'
    IMPORTING
    RSTRING = v_Output
    EXCEPTIONS
    TOO_SMALL = 1
    OTHERS = 2
    <SOURCE_FIELDS>-FIELDNAME = v_Output .
    ENDLOOP .
    This will work .
    If you have different requirement then please tell me .
    Regards,
    Jaya

  • Start Routine logic to delete records which do not satisfy a condition

    Hello,
    Iam trying to code a start routine to delete the records from the source_package if a certain set of conditions are not met.
    It is failing at the last statement.
    Pls help.
    Thanks
    Jagadish
    code is as follows..
    LOOP AT SOURCE_PACKAGE assigning <SOURCE_FIELDS>.
    IF not (
    ( <SOURCE_FIELDS>-/BIC/ZCLSD_DT BETWEEN <SOURCE_FIELDS>-/BIC/ZWEEKOF
    AND <SOURCE_FIELDS>-/BIC/ZNONWKOF )
      AND
      ( <SOURCE_FIELDS>-/BIC/ZCLSD_DT IS  INITIAL )
    DELETE SOURCE_PACKAGE FROM <SOURCE_FIELDS>.
    (is failing at the delete statement.)
    ENDIF.
    ENDLOOP.

    Thanks Pratap,
    I used an internal table to load the records and used a delete statement out side the LOOP.
    By using a Work Area assignment instead of the Source_fields, The delete statement is giving me an error saying "Conversion of Numeric Value to type Object is not valid".
    Here is the code I have modified...
       TYPES: BEGIN OF LINE,
                WO(6) type c,
              END OF LINE.
       DATA: WA TYPE LINE,
             ITAB TYPE TABLE OF LINE.
    LOOP AT SOURCE_PACKAGE assigning <SOURCE_FIELDS>.
    IF NOT (
    ( <SOURCE_FIELDS>-/BIC/ZCLSD_DT BETWEEN <SOURCE_FIELDS>-/BIC/ZWEEKOF
        AND <SOURCE_FIELDS>-/BIC/ZNONWKOF
      AND
      <SOURCE_FIELDS>-/BIC/ZAPRD_DT IS NOT initial )
    Append <SOURCE_FIELDS>-/BIC/ZWO_NBR to itab.
    ENDIF.
    ENDLOOP.
    loop at itab into WA.
    DELETE SOURCE_PACKAGE where /bic/ZWO_NBR = WA-wo.
    endloop.

  • 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

Maybe you are looking for