ABAP Help on Update Rule Needed

Hello.  I am trying to write a routine on an key figure in an update rule.  Basically, I am trying to load a custom key figure with either a 1 or a 0. 
Here is the pseudocode:
IF
(((GI_DATE - ACT_GI_DTE) < 0) OR
  ((GI_DATE - ACT_GI_DTE) > 3)
THEN
    NEW_KEY_FIGURE = 1
ELSE
    NEW_KEY_FIGURE = 0
ENDIF.
Here is the code I currently have in the routine.  Any ideas on where I am going wrong here?  I am not an ABAP developer so please keep this in mind when responding.
result value of the routine
  CLEAR RESULT.
if the returncode is not equal zero, the result will not be updated
  IF COMM_STRUCTURE-GI_DATE - COMM_STRUCTURE-ACT_GI_DTE < 0 OR
     COMM_STRUCTURE-GI_DATE - COMM_STRUCTURE-ACT_GI_DTE > 3.
     COMM_STRUCTURE-NEW_KEY_FIGURE = 1.
  ELSE.
     COMM_STRUCTURE-NEW_KEY_FIGURE = 0.
  ENDIF.
  RESULT = COMM_STRUCTURE-NEW_KEY_FIGURE.
  RETURNCODE = 0.
if abort is not equal zero, the update process will be canceled
  ABORT = 0.
Thanks for any help you can give.

Hi,
I think you can not put "-" in if command, so code should be like this:
data: datediff type n.
result value of the routine
CLEAR RESULT.
clear datediff.
detediff = COMM_STRUCTURE-GI_DATE - COMM_STRUCTURE-ACT_GI_DTE.
IF datediff < 0 OR datediff > 3.
Result = 1.
ELSE.
Result = 0.
ENDIF.
RETURNCODE = 0.
if abort is not equal zero, the update process will be canceled
ABORT = 0.
Regards,
Andrzej

Similar Messages

  • 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

  • Need help in Update rule coding - URGENT

    Hi Gurus,
              I am creating an update rule there i need to compare some filed with the fields in inforsouce so here what should be the name used for the infosource can i use something like this
    read table TAB where
          <fields1>       =  DATA_PACKAGE-<field1>.
    where DATA_PACKAGE is the infosource
    is this the rite method
    waiting for reply
    Ravi

    Hi,
    Use this in Update Routine.
    IF COMM_STRUCTURE-field1 = 'value1' AND
    COMM_STRUCTURE-field2 = 'value2'.
    RESULT=field3*100.
    ELSE.
    RESULT=field*10.
    END IF.
    here field name will be in format of :     /bic/fieldname
    Regards,
    rik

  • ABAP code in update rules to convert the date

    Hi,
    Could any one send me the ABAP code that is written in the update rules to convert the date (DD/MM/YYYY  -- lenght 10) to YYYYMMDD ---  length 8  format.
    Also please let me know where I should write this code; while creating update rules or while creating infosource.
    Thanks,

    Hi Bharath,
    Hi Bharath,
    I suggest you do the conversion of dates in the transfer rules. Here is the correct code you need:
    * Assuming the source data field is called MYDATE
    * Place the ff. in the routine in the transfer rules:
    concatenate tran_structure-mydate+6(4) tran_structure-mydate+3(2) tran_structure-mydate(2) into result.
    replace MYDATE with the name of the source field (10 chars) in the transfer structure. Hope this helps.

  • URGENT !!! - ABAP code in update rule

    Friends,
    With my limited knowledge in ABAP, I need some help from the forum.
    I need to create a routine in update rule to capture 'date of last GR against a PO delivery schedule'. Let's say
    PO # 1234
    IT # 10
    SCL # 1
    There are multiple partial deliveries against SCL # 1 above and I have to capture the last delivery date and subsequently the last invoice date. If I try to set the rule to capture the 'posting date' based of 'transfer type'  - the GR date field gets overwritten by the last invoice date (the date of last activity). My requirement is to separate the two i.e.
    1) Date of last GR against PO - Item - SCL line
    2) Date of lasr INV against PO - Item - SCL line
    Can any one help me with the code ???
    Thanks,
    AK

    Hi,
    check the following link, gives an example of an update routine.
    http://help.sap.com/saphelp_nw70/helpdata/en/80/1a64fae07211d2acb80000e829fbfe/frameset.htm

  • ABAP porgram in update rule-Job stats

    Hi All,
    I have an ABAP program that is in one of the update rules from source ODS to destination ODS. Source ODS has 20million records. When we are loading the records to destination ODS , Is there any way I can find howmuch time will take to process 1 record and  also when it is running how do I know howmany records it has processed or  howmany  yet to process ? I have tried with SM50 but not able to find much useful information?
    Please help me and if you have any documents please send it to [email protected]
    Regards
    Vennela

    hi Shravani,
    try using this code.. ths is done as a report, you will have to change the fields.
    **get the first 4 chars of the date. date is stored as YYYYMMDD format internally. check with the system year. sy-datum has the system date
    if comm_structure-stat_date+0(4) = sy-datum+0(4).
    **get the month i.e the 5 and 6th characters from the date and compare them
    if comm_structure-stat_date+4(2) > sy-datum+4(2).
      result = 0.
    **ELSE. .... you havent mentioned what u want to do if the month is lesser or equal to the system month
    endif.
    else.
    **Get the first 6 chars of the statistical date.. i.e the year and month.
      result = comm_structure-stat_date+0(6).
    endif.
    Regards
    Sujai

  • Advice on abap routine in update rule

    Hello Experts,
    I have written a routine in update for replacing some 'not allowed characters' with space.
    The abap code is correctly working as a standalone program as is giving the correct results.However,
    when i write the same code in update routine, no change takes place in data, i.e. 'not allowed characters ' are still there in my data.
    Please advice if there is any special change that is to be made while writing the code in update routine.
    if STRLEN( CHECK_TEXT ) <> 0.
        ALLOWED_SPECIAL_CHARACTERS = ' &()*+,-.:;<>=?!@$%~'.
        ALLOWED_CHARACTERS = 'ABCDEFGHIJKLNMOPQRSTUVWXYZ_0123456789'.
          TRANSLATE CHECK_TEXT TO UPPER CASE.
        strl = strlen( CHECK_TEXT ).
        IF CHECK_TEXT CN ALLOWED_CHARACTERS.
           WHILE len1 LE strl.
            IF CHECK_TEXT+len1(1) CN ALLOWED_CHARACTERS.
            CHECK_TEXT+len1(1) = '.'.
             ENDIF.
           add 1 to len1.
          ENDWHILE.
        ENDIF.
    Regards
    Priyanka

    Thanx a lot for a quick reply .
    The main problem that we are facing is this simple code is working fine if it is executed as a report program but if no changes takes place when i move this same code to my update routine.
    (1) According to you i should write this routine in the start routine instead of update rotuine ??
    (2) how would function module help in my case...kindly elaborate a it.
    Here is the complete update rotuine.
    data:
    len1 TYPE i value 0
    R_TEXT(60),
    CHECK_TEXT(60),
    R_TEXT = COMM_STRUCTURE-/BIC/ZC_NTXT1.
    if STRLEN( R_TEXT ) <> 0.
      ALLOWED_SPECIAL_CHARACTERS = ' &()*+,-.:;<>=?!@$%~'.
      CONCATENATE 'ABCDEFGHIJKLNMOPQRSTUVWXYZ_0123456789/'
                  ALLOWED_SPECIAL_CHARACTERS
                  INTO ALLOWED_CHARACTERS.
      CHECK_TEXT = R_TEXT.
      TRANSLATE CHECK_TEXT TO UPPER CASE.
      strl = strlen( R_TEXT ).
    IF CHECK_TEXT CN ALLOWED_CHARACTERS.
          WHILE len1 LE strl.
          subs2 = CHECK_TEXT+len1(1).
            IF subs2 CN ALLOWED_CHARACTERS.
            CHECK_TEXT+len1(1) = '.'.
             ENDIF.
            ENDWHILE.
    endif.
        ENDIF.
    RESULT = CHECK_TEXT.

  • Defining ABAP variables in update rules

    Hello,
    How can I define a variable in ABAP of the same type as an InfoObject? I know it's easy as long as the InfoObject is a part of the communication structure. But this InfoObject is not present neither in the source ODS nor in the target cube. It is a custom InfoObject, not BC.
    Regards,
    Christoffer Owe

    Hello,
    I have not succeeded with that. Trying
    DATA: TmpYearWeek LIKE /BIC/ZWKCLSDT.
    where ZWKCLSDT is my InfoObject, results in
    "E:Field "/BIC/ZWKCLSDT" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement."
    Regards,
    Christoffer

  • Update rules need to populate a characterisitc

    Is there any way to populate Controlling area when i flat file load a cube which has Costcenter in it but not controlling area.It is a compounding characteristic to Costcenter.

    Vinay,
    controlling area should come for source. if youpractising in Bw, you can assign constant value(assume 1000) in UR.
    otherwise, it should come from source i.e. Flat File in your case.
    Nagesh Ganisetti.
    Assign points if it helps.

  • How to write ABAP Routeines in Update/Transfer Rules ?

    Hi Experts,
    Iam new to BW and i don't have ABAP knowledge.Can any body help me ..to write ABAP Routeines in Update rules/Transfer rules.Give me some basic knowledge with proper example.and what type of routeines we need to write ?
    I will appreciate if some one helps me with proper Documentation.My mail id is [email protected]
    Points will be rewarded.
    Thanks in advance,
    Nayanasri.

    Hi Nayanasri,
    It is not mendatory that u need to write Update routines for all update rules. It depends on the requirement. Without update routine u can always manage. My last implementation was for a small chemical firm where i did not use any of the update routine. Suppose if u want to change the records in datapackage depending on certain conditions, then u can go for this. I'm just pasting one of my update routine program
    PROGRAM UPDATE_ROUTINE.
    $$ begin of global - insert your declaration only below this line  -
    TABLES: ...
    DATA:   ...
    $$ end of global - insert your declaration only before this line   -
    The follow definition is new in the BW3.x
    TYPES:
      BEGIN OF DATA_PACKAGE_STRUCTURE.
         INCLUDE STRUCTURE /BIC/CS8YGTGDCL6B.
    TYPES:
         RECNO   LIKE sy-tabix,
      END OF DATA_PACKAGE_STRUCTURE.
    DATA:
      DATA_PACKAGE TYPE STANDARD TABLE OF DATA_PACKAGE_STRUCTURE
           WITH HEADER LINE
           WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
    FORM startup
      TABLES   MONITOR STRUCTURE RSMONITOR "user defined monitoring
               MONITOR_RECNO STRUCTURE RSMONITORS " monitoring with record n
               DATA_PACKAGE STRUCTURE DATA_PACKAGE
      USING    RECORD_ALL LIKE SY-TABIX
               SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS
      CHANGING ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update
    $$ begin of routine - insert your code only below this line        -
    fill the internal tables "MONITOR" and/or "MONITOR_RECNO",
    to make monitor entries
    DELETE DATA_PACKAGE WHERE /bic/yverbr NE  'V2'.
    DELETE DATA_PACKAGE WHERE /bic/ydpbasfs = 0 AND /bic/yoplqty = 0.
    ENDFORM.
    Where the delete statement deletes the records when the field /bic/yverbr noe equals to 'V2' or deletes it when /bic/ydpbasfs equals zero.
    If the explanation is not suffecient, pls post further
    Regards
    Sriram

  • Update Rule Routine: Compare system date

    Can anyone help me with regards to writing some ABAP code in update rule?
    I would like to check if the value of a date characteristics is equal to system date in data source. If its value is equal to system date, assign '0' value to another numeric characteristics. Otherwise, it will get the difference between system date and the date characteristics. I have rewritten the routine as follows. But there is no effects on the result. Am I correct?
    if COMM_STRUCTURE-<date characteristics> = SYST-DATUM.
      RESULT = '0'.
    else.
      RESULT = COMM_STRUCTURE-<numeric characteristics>.
    endif.
    Many thanks in advance.

    I have rewritten the code as follows. ZLASTPURD is a numeric characteristics. The code is written in the routine of ZLASTPURD in update rule. But it takes no effect. The case "COMM_STRUCTURE-/BIC/ZLASTPURD ='0'" means another date characteristics is equal to system date, the value of ZLASTPURD is blank after modifying the code. However, the code is workable for  "RESULT = COMM_STRUCTURE-/BIC/ZLASTPURD.". Is there anything wrong?
    data lastpurdays type I.
    lastpurdays = '1'.
    if COMM_STRUCTURE-/BIC/ZLASTPURD = '0'.
      RESULT = lastpurdays.
    else.
      RESULT = COMM_STRUCTURE-/BIC/ZLASTPURD.
    endif.
    Many thanks in advance.

  • Querying Cubes on Update Rules?

    I have an update rule that currently queries an ODS to get the value of a key figure and then apply that key figure to the cube the update rule is intended for.
    Basically, this is the select statement I use in the routine:
    select defect_quantity from table_a
      where notification = notification
        and notif_item = notif_item.
    Since the ODS is a flat table, this works fine.  However, I am having trouble figuring out how to write this same query against a cube. 
    Is there a way to query a cube with ABAP in an update rule?  Any info or link to how to do this would be appreciated.
    Thanks,
    Brent

    Hi,
    There is simple example:
    **> You must fill G_T_RANGE table with selection conditions for
    **> InfoCube data. In this case char 0VERSION = '1' and
    **> 0CALYEAR = '2005'. 
      CLEAR G_S_RANGE.
      G_S_RANGE-CHANM    = '0VERSION'.
      G_S_RANGE-SIGN     = 'I'.
      G_S_RANGE-COMPOP   = 'EQ'.
      G_S_RANGE-LOW      = '1'.
      APPEND G_S_RANGE TO G_T_RANGE.
      G_S_RANGE-CHANM    = '0CALYEAR'.
      G_S_RANGE-SIGN     = 'I'.
      G_S_RANGE-COMPOP   = 'EQ'.
      G_S_RANGE-LOW      = '2005'.
      APPEND G_S_RANGE TO G_T_RANGE.
    **> You should also provide information for which combination
    **> of characteristic you need value
      CLEAR G_S_SFC.
      G_S_SFC-CHANM    = '0VERSION'.
      G_S_SFC-CHAALIAS = '0VERSION'.
      G_S_SFC-ORDERBY  = 0.
      INSERT G_S_SFC INTO TABLE G_TH_SFC.
      G_S_SFC-CHANM    = '0PROFIT_CTR'.
      G_S_SFC-CHAALIAS = '0PROFIT_CTR'.
      G_S_SFC-ORDERBY  = 0.
      INSERT G_S_SFC INTO TABLE G_TH_SFC.
      G_S_SFC-CHANM    = '0CALYEAR'.
      G_S_SFC-CHAALIAS = '0CALYEAR'.
      G_S_SFC-ORDERBY  = 0.
      INSERT G_S_SFC INTO TABLE G_TH_SFC.
    **> And finaly which keyfigure should be aggregated
      CLEAR G_S_SFK.
      G_S_SFK-KYFNM    = '0AMOUNT'.
      G_S_SFK-KYFALIAS = '0AMOUNT'.
      G_S_SFK-AGGR     = 'SUM'.
      INSERT G_S_SFK INTO TABLE G_TH_SFK.
    **> I_INFOPROV - InfoProvider name. In this case InfoCube name
    **> I_TH_SFC - table with selected chars
    **> I_TH_SFK - table with selected keyfs
    **> I_T_RANGE - table selection conditions
    **> I_PACKAGESIZE - number of records in one function call
    **> You should call this function as many times as parameter
    **> E_END_OF_DATA will receive 'X' which means that last data
    **> packet has been read
    **> G_T_DATA - table with aggregated data from InfoCube
      CALL FUNCTION 'RSDRI_INFOPROV_READ'
        EXPORTING
          I_INFOPROV                   = 'ZINFOCUBE'
          I_TH_SFC                     = G_TH_SFC
          I_TH_SFK                     = G_TH_SFK
          I_T_RANGE                    = G_T_RANGE
          I_PACKAGESIZE                = 10000
          I_ROLLUP_ONLY                = ''
        IMPORTING
          E_T_DATA                     = G_T_DATA
          E_END_OF_DATA                = END_OF_DATA
        CHANGING
          C_FIRST_CALL                 = G_FIRST_CALL
        EXCEPTIONS
          OTHERS                       = 1.
    Krzys

  • To refer logical source in update rules

    Hi,
    I wanted to find the logical source system using abap into my update rule, is it possible.
    Help would be appreciated.
    Thanks,
    SD

    Hi,
    you have only to write something like this:
    case sy-sysid.
    * development system
        when 'dev1'.
            result = 'r3_dev'.
    * test system
        when 'test1'
            result = 'r3_test'.
    endcase.
    dev1 and test 1 are your bi systems. When data comming from one source system you can use this code in each transformation.
    Regards
    Andreas

  • Message RSAU466 when update rules activation

    Hi everybody,
    I did some corrections in an ABAP routine in update rules. When I try to activate them this message appears :
    Message no. RSAU466
    Diagnosis
    When generating the update program for data target XXXXX, InfoSource YYYYY, a syntax error occured in row 1.980.
    System response
    The update rules cannot be activated.
    Procedure
    If the error message Incorrect logical expression. is cut off, do the following to get the complete error message:
    Go into the update rule maintenance, choose Extras -> Display Activated Program and carry out a syntax check there. You can then find out what the error was.
    I've tried to display the acitvated program but this message occurs : Unable to find a tool to process the request
    I don't want to delete and recreate my update rules because thes are very complicated and it's very risky.
    Any idea ?
    Edited by: maredami on Jun 11, 2010 1:55 PM

    Thanks for your help !
    RSAU_UPDR_REACTIVATE_ALL doesnt work (No message exists).
    I've already seen these notes but we don't want to import support packages...
    I've found the generated program of the update rules (GPxxxxxxxxxxxx) and at the line 1980 that is wrote :  S_COB_PRO_PLANT TYPE RSD_S_COB_PRO.
    I have no idea what to do now...

  • Update rule activation......

    Hi,
    I have added one of the fileds in ODS.  This ODS gets data from 6 ODS.
    All the update rules got deactivated.
    Any reason why?
    what we have to do ?
    Will all the activation of all the update rules need to get transported again?
    Thanks & Regards,
    Jeetu

    Hi,
    BW don't know if/how this field should be updated from 1 or several of the 6 ODS'es. Therefore the update rules are inactive and you have to activate them AND updatethe new field if you want or set it to initial if you don't want to update it.
    And yes, you should then transport this.
    Kind regards
    /martin

Maybe you are looking for

  • Java constructor

    Hi! My program is ok but I have problem with my second constructor without parameter. How do I write this constructor? toString method is ok and can reache first constructor but not the second constructor. and how do I call it in my main method. clas

  • FB70 - Payment Terms and discount rates

    Dear Friends, We have a requirement in transaction FB70, in which we wanted to provide 3 different discounts for a given payment term, but the transaction by default provide only 2 discounts. Is there a way in which we can add a third discount for a

  • Two Forests using Same Subnets?

    We've setup a new 2012 R2 forest that we plan to migrate our 2008 R2 resources to over time. Currently it is on our production network, on the same ip ranges as our production forest. I've suggested that we really should put the new domain on new, di

  • E71 messaging stops with same message - any ideas?...

    I have several hotmail accounts running and stop after approx 7 days with the message below. I have deleted and reassigned works temporarily but problem re occurs. Any ideas how to rectify permanently. No settings have changed. Dear Nokia Messaging c

  • Buffalo Linkstation live - Itunes 10.5

    Hi, I have a linkstation live connected to my home router via ethernet. The linkstation live has an Itunes server built in to this. Prior to upgraded to Itunes 10.5.0.142 my computer (Windows7 32bit) could see my linkstation live as an itunes server