Correct ABAP Logic in Transformations-Start or Field Routine Error

Hi
I have written this code in start routine to split the data record into 2 if  bic/zdte_trm is not initial.
But i am getting below error please correct me where i was wrong
LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>.
      IF NOT <source_fields>-/bic/zdte_trm = ' '.
* append a new record to source_package with this field initialised
        CLEAR wa_source.
        MOVE <source_fields> TO wa_source.
        CLEAR wa_source-/bic/zdte_trm.
        APPEND wa_source TO SOURCE_PACKAGE.
      ENDIF.
    ENDLOOP.
At a LOOP over an internal table, the table is not allowed to be changed 
  in the loop tail as a whole.                                            
SORT, MOVE, REFRESH, CLEAR are, for example, not allowed.

Hi Saurov,
Thanks for all the help.....
The code is working fine but
I got a strange issue while using this code
DSO Data (Exisiting Data )
Emp ID---Start Date--End Date
1-----01/01/2008----
Data from source system
Emp ID---Start Date--End Date
1-----01/01/2008----01/05/2008
The code is spliting that record into 2 records
1-----01/01/2008----
1-----01/01/2008----01/05/2008
and in source system in can see total 3 records
1-------01/01/2008   (Exisisting Record)
1-------01/01/2008   (New)
1-----01/01/2008----01/05/2008 (New)
The key fields in DSO is Emp Id and End Date
Please,please update me how to resolve this issue

Similar Messages

  • ABAP Logic in Transformations-Start or Field Routine Error

    Hi,
    Below is the field routine in transformations that will calculacte No of Years between 2 dates (Source Field & System Date)
    It is showing me no systex Error but when i started data load ,Load is failing due to below mentioned error
    Routine:
    IF NOT SOURCE_FIELDS-/BIC/ZCYB_DOB IS INITIAL.
    CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    EXPORTING
    I_DATE_FROM = SOURCE_FIELDS-/BIC/ZCYB_DOB
    I_KEY_DAY_FROM = 00
    I_DATE_TO = SYST-DATUM
    I_KEY_DAY_TO = 00
    I_FLAG_SEPERATE = 'X'
    IMPORTING
    E_YEARS = RESULT.
    ENDIF.
    Error:
    The exception CX_STATIC_CHECK is neither caught nor is it declared in
    the RAISING clause of "EXECUTE".
    Please update me where i was doing wrong
    Thanks

    It must have something to do with your input variables - I ran this FM locally using my DOB and today's date and it worked fine.
    make sure your input date types are in the correct format for the FM.

  • ABAP Logic in Transformations-Start or Field Routine

    Hi Experts,
    As i am new to BW Please update me with the ABAP logic  i need to implement in Transformation routine...and please advise me wether i can use that as a Start or field routine for a better performance.
    Target DSO:
    DSO A : Active Table:/BIC/AZDSOA
    Fields (ZLOC,ZPAY_ID,ZNPAY_ID,ZOPAY_ID & ZCHG_DTE)
    Source DSO
    DSO B : Active Table:/BIC/BZDSOA
    (ZLOC,ZPAY_ID)
    DSO C : Active Table:/BIC/CZDSOA
    Fields (ZLOC,ZPAY_ID,ZNPAY_ID & ZCHG_DTE(date))
    While Transfering Data from DSO B-->DSO A
    It should check DSO C for that ZLOC & ZPAY_ID
    If ZCHG_DTE IS Blank then it should pick ZNPAY_ID for that ZLOC & ZPAY_ID from DSO C and update ZNPAY_ID in DSO A
    if ZCHG_DTE IS not Blank then it should pick ZPAY_ID for that ZLOC & ZPAY_ID from DSO C and update ZOPAY_ID & ZCHG_DTE in DSO A
    ZPAY_ID - Pay ID
    ZNPAY_ID -New Pay ID
    ZOPAY_ID -Old Pay ID
    ZCHG_DTE -Change Date
    ZLOC     -Location.
    Logic in words:
    If Change date is Blank then it should pick new pay id for that Location & Pay Id and update NEw pay id field in DSO A
    If Change date is not Blank then it should pick  pay id for that Location & Pay Id and update old pay id field  & change date in DSO A
    Please update me with releavent code
    Thanks

    It must have something to do with your input variables - I ran this FM locally using my DOB and today's date and it worked fine.
    make sure your input date types are in the correct format for the FM.

  • ABAP Logic in Transformations-Start or Field Routine ENHANCEMENT

    Hi
    Currently i am calculacting age of an employee in years and months using FM.
    Source Object (DOB) is DATS and
    Target object (age) is Char (6)
    My requirment is to show age in YY.MM
    If an employee age is 65Y,8M..then it shoud be displayed as 65.08.
    If an employee age is 5Y,8M..then it shoud be displayed as 05.08
    The below code is working fine for the above sceaniro...
    BUT i need  to enhance the code for
    If an employee age is 100Y,8M..then it shoud be displayed as 100.08  and
    If an employee age is 65Y,8M..then it shoud be displayed as 65.08.
    Please update me how to proceed
    DATA: YEARS TYPE TFMATAGE,
              MONTHS TYPE TFMATAGE.
        DATA: Y_NUM(4) TYPE N,
              M_NUM(2) TYPE N.
    IF NOT SOURCE_FIELDS-/BIC/ZDOB IS INITIAL.
          CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
            EXPORTING
              I_DATE_FROM    = SOURCE_FIELDS-/BIC/ZDOB
              I_DATE_TO      = SY-DATUM
              I_FLG_SEPARATE = 'X'
            IMPORTING
              E_MONTHS       = MONTHS
              E_YEARS        = YEARS.
          Y_NUM = YEARS.
          M_NUM = MONTHS.
          CONCATENATE Y_NUM+2(2) '.' M_NUM INTO RESULT.
        ENDIF.

    piece of cake...
    replace
    CONCATENATE Y_NUM+2(2) '.' M_NUM INTO RESULT.
    with
    IF y_num GE 100.
      CONCATENATE Y_NUM+1(3) '.' M_NUM INTO RESULT.
    ELSE.
      CONCATENATE Y_NUM+2(2) '.' M_NUM INTO RESULT.
    ENDIF.

  • ABAP Logic/Structure for a Start and Field Routine in Transformations

    My Requirment is to export data from Data Target to Application Server.
    And for that purpose i built a APD...
    In Transformations to read data from MAster Data Table i had written below Global & Field Routine.
    Start Routine:
    Glodal Declaration
    DATA: it_dep   type standard table of /BI0/MDEPT,
          is_dep   type /BI0/MDEPT.
    LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>.
    if not SOURCE_PACKAGE[] is initial.
    SELECT * FROM /BI0/MDEPT INTO TABLE it_dep for all entries in
    SOURCE_PACKAGE
    WHERE depLOYEE    = SOURCE_PACKAGE-dep      AND
          OBJVERS     = 'A'                     AND
          DATETO     GE SY-DATUM.
    ENDIF.
    ENDLOOP.
    FIELD ROUTINE
    Clear:is_dep.
        Read table it_dep into is_dep with key
        depLOYEE = SOURCE_FIELDS-deployee binary search.
        if sy-subrc = 0.
          RESULT = is_dep-USERNAME.
        endif.
    Now for another field 'Manager' name.......
    My requirment
    Start Routine:
    (Sub Detp is an attribute to Dept and Sub Dept is referenced on dept)
    First it should copy all the Sub depts for the corresponding depts in the source field to a Temperoray table (TEMP1)
    For all sub depts in TEMP1 table it should copy manager names from dept master data table to a Temp2 table
    In start routine i need to first read temp1 and result from temp1 should be passed to temp2 and the result from tem2 can be passed to result field
    Please update

    Hi,
    i am providin you a sample code please modify it (field name and tables name's as per your requirement).
    Please write the code in transformation rule of field Emp_TDate.
    Map field Emp_SDATE  to the target field for Emp_TDATE .
        SELECT * FROM /BIC/AEMPPED00
                        WHERE Emp_SDATE NE ' '.
    if sy-subrc is initial.
    result = source_field-Emp_SDATE.
    else.
    result = ' '.
    endif.
    Please replace the emp_SDATE field with the source field name.
    But still i have some question...
    1. On what basis u decide the latest record ??
    Can u please explain scenarion bit mroe clearly.
    Thanks
    Dipika
    Edited by: Dipika Tyagi on Jun 24, 2008 8:47 AM

  • Abap logic in Transformation End Routine not working correctly

    Hi,
    I wrote a piece of code but during testing I found out that it doesn't meet my requirement.
    Requirement
    I want to extract Standard_Cost for all sales items that meets the conditon. but at the moment only the first sales item in the DSO is showing.
    I would like the following lines to display in the cube as well since the PLITEM is different.
    201021     PI31     REDBACK     999999A     78,850
    201021     PI31     FLXAAA     999999A     3154,000
    DSO Table
    CALWEEK     PLPLANT     PLITEM     SALESITEM     STRDCOST
    201020     IN06     FLXAAA     557868B     6308,000
    201021     FI24     FLXAAA     557868B     6308,000
    201021     FI24     FLXAAA     999999B     0,000
    201021     PI31     REDBACK     999999A     78,850
    201021     PI31     FLXAAA     999999A     3154,000
    InfoCube
    SALESITEM  PLPLANT       SALESDOC       STRDCOST
    999999A     PI31     1100000911         78,850
    Abap Logic
    Data ld_calweek(6) TYPE n.
    Getting the current week based on the system date.
    CALL FUNCTION 'DATE_GET_WEEK'
            EXPORTING
              date         = sy-datum
            IMPORTING
              week         = ld_calweek
            EXCEPTIONS
              date_invalid = 1
              OTHERS       = 2.
    Data rp TYPE tys_TG_1.
    LOOP AT RESULT_PACKAGE INTO rp.
    SELECT SINGLE STRDCOST FROM /N/ABC_EFG00 INTO
    rp-S_STRDCOST
    WHERE SALESITEM = rp-S_ITEMID  AND CALWEEK =
    ld_calweek AND PLPLANT EQ rp-S_SOURCE.
    MODIFY RESULT_PACKAGE FROM rp.
    Clear rp.
    ENDLOOP.
    How do I resolve this
    thanks

    Hi Vaidya
    Select single will always select the first entry from the source which matched your where condition.
    therefore you are not getting all the required data.
    WHERE SALESITEM = rp-S_ITEMID AND CALWEEK =
    ld_calweek AND PLPLANT EQ rp-S_SOURCE.
    according to your logic
    it will pick only one record e.g
    201021 PI31 REDBACK 999999A 78,850
    201021 PI31 FLXAAA 999999A 3154,000
    item id = 999999A
    plplant = PI31
    in this case it will pick only the first record due to select single will fetch only one record (whichever it gets first and which meets your where condition)
    You need to change your code logic and need to include more fileds which differentiates one record from another who have same valued as in your present where condition.
    Thanks
    Navneet

  • Abap logic in Transformation end routine bringing 0 records

    Hi,
    I wrote this logic but is not populating the figure that I need. I am trying to get a Key figure /
    field-symbols: <fs_rp> LIKE LINE OF RESULT_PACKAGE.
    Types : Begin of s_itab,
    S_ITEMID TYPE /N/ADSO_ASPC00-/N42/S_ITEMID,
    STRDCOST TYPE /N/ADSO_ASPC00-/N42/S_STRDCOST,
    End of s_itab.
    Data : it_itab type table of s_itab,
    wa_itab type s_itab.
    LOOP AT RESULT_PACKAGE ASSIGNING <fs_rp>.
    Read table it_itab INTO wa_itab with key S_ITEMID =
    <fs_rp>-/N42/S_ITEMID.
    Clear wa_itab.
    if sy-subrc ne 0.
    SELECT /N/S_STRDCOST /N/S_ITEMID FROM /N/ADSO_ASPC00 INTO
    CORRESPONDING FIELDS OF wa_itab
    FOR ALL ENTRIES IN RESULT_PACKAGE
           WHERE /N/S_ITEMID EQ RESULT_PACKAGE-/N/S_ITEMID.
    ENDSELECT.
    <fs_rp>-/N/S_STRDCOST = wa_itab-STRDCOST.
    ENDIF.
    ENDLOOP.

    1. the name of the fields in the internal table it_itab and in table /n/adso_dsc00 are not the same, so you're move-corresponding is not working.
    2. you need to select in table it_itab not in workarea wa_itab.
    Data rp TYPE tys_TG_1.
    field-symbols: <fs_rp> LIKE LINE OF RESULT_PACKAGE.
    Types : Begin of s_itab,
    /N/S_ITEMID TYPE /N/ADSO_DSOC00-/N/S_ITEMID,
    /N/S_STRDCOST TYPE N/ADSO_DSOC00-/N/S_STRDCOST,
    End of s_itab.
    Data : it_itab type table of s_itab,
    wa_itab type s_itab.
    SELECT /N/S_STRDCOST /N/S_ITEMID FROM N/ADSO_DSOC00 INTO
    INTO table it_itab
    FOR ALL ENTRIES IN RESULT_PACKAGE
    WHERE /N/S_ITEMID EQ RESULT_PACKAGE-/N/S_ITEMID.
    ENDSELECT.
    LOOP AT RESULT_PACKAGE ASSIGNING <fs_rp>.
    Read table it_itab INTO wa_itab with key /N/S_ITEMID =
    <fs_rp>-/N/S_ITEMID.
    if sy-subrc ne 0.
    <fs_rp>-/N/S_STRDCOST = wa_itab-STRDCOST.
    ENDIF.
    ENDLOOP.

  • Start/Field Routine in Transformations (ABAP)

    Hi Experts
    Please update me on how to proceed and ABAP Code required.
    DSOFULL->CUBE
    DSO Active Table: /BIC/AEMPPED00
    Data In DSO
    Emp_ID--Emp_SDATE--Emp_TDate
    1-----01.01.2008
    1---01.01.2008--01.06.2008
    1-----01.01.2008
    Data Expected in CUBE
    Emp_ID--Emp_SDATEEmp_TDate-----Ter_Date
    1---01.01.2008--
    01.06.2008
    1---01.01.200801.06.2008---01.06.2008
    1---01.01.2008--
    I need a start routine or field routine that
    Will loading data from DSO to CUBE the code should look for employee latest record and if it find Emp_TDatevalue then it should populate both recordsTer_date in cube with  Emp_TDate
    Please advise

    Hi,
    i am providin you a sample code please modify it (field name and tables name's as per your requirement).
    Please write the code in transformation rule of field Emp_TDate.
    Map field Emp_SDATE  to the target field for Emp_TDATE .
        SELECT * FROM /BIC/AEMPPED00
                        WHERE Emp_SDATE NE ' '.
    if sy-subrc is initial.
    result = source_field-Emp_SDATE.
    else.
    result = ' '.
    endif.
    Please replace the emp_SDATE field with the source field name.
    But still i have some question...
    1. On what basis u decide the latest record ??
    Can u please explain scenarion bit mroe clearly.
    Thanks
    Dipika
    Edited by: Dipika Tyagi on Jun 24, 2008 8:47 AM

  • ABAP code for BI 7.0 transformations start routine

    Hi all,
    I am trying to update data from DSO1 (Source1: transaction data) to Infocube(TARGET)
    In the transformations Start routine, I have to read DSO2(Source2: Master data) for some fields.
    DSO1 has CUSTOMER as part of key
    DSO2 has CUSTOMER (key) and other fields....FIELD1, FILED2, FIELD3
    Infocube to be updated with FIELDS1,2 & 3 WHILE READING DSO2.
    WHERE DSO1 CUSTOMER matches with DSO2 CUSTOMER.
    Also, data NOT TO BE UPLOADED into Infocube if FIELD1 in DSO2= NULL
    Please give me the abap code for the above logic.
    Appreciate any help in this regard.
    Thanks.

    This is a doc from this site:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6090a621-c170-2910-c1ab-d9203321ee19
    Ravi Thothadri

  • Convert ABAP code in start routine/update rule to transform. start routine

    Dear BW ABAPers,
    I have created a custom purchasing info cube (YCP_PURC1) based on 0CP_PURC1 standard cube. I would like to convert this new data flow to BI7 (from 3.x), and convert the standard update rule to transformation. I would need to rewrite the below start routine from the standard update rule to a start routine ABAP code in the newly created  transformation / start routine. My ABAP knowledge is limited. Will you please help?
    *this is the start routine from the update rule. As a side note, the data source is 2LIS_02_SCL.
    LOOP AT SOURCE_PACKAGE.
        IF (     SOURCE_PACKAGE-cppvlc  EQ 0
             AND SOURCE_PACKAGE-cppvoc  EQ 0
             AND SOURCE_PACKAGE-cpquaou EQ 0 ).
          DELETE SOURCE_PACKAGE.
          CONTINUE.
        ENDIF.
    no_scl is initial ( e.g. for good receipts, billing)
    value has to be set depending on storno
        IF SOURCE_PACKAGE-no_scl IS INITIAL.
          IF SOURCE_PACKAGE-storno = 'X'.
            SOURCE_PACKAGE-no_scl = -1.
          ELSE.
            SOURCE_PACKAGE-no_scl = 1.
          ENDIF.
          MODIFY SOURCE_PACKAGE.
        ENDIF.
      ENDLOOP.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    Many thanks and look forward to your kind feedback.
    Kind regards,
    Csaba

    Dear All, Durgesh,
    thanks to you all for your valuable input. Mainly the ABAP part was more interesting for me.
    Durgesh, thanks for your input, it was useful. I just had to change the info objects to data source fields and add the lines before the loop:
    DATA: I_PACKAGE TYPE TYT_SC_1.
        FIELD-SYMBOLS <i_package> TYPE tys_sc_1.
        I_PACKAGE[] = SOURCE_PACKAGE[].
        LOOP AT SOURCE_PACKAGE assigning <i_package>.
          IF ( <i_package>-BWGEO EQ 0
          AND <i_package>-BWGEOO EQ 0
          AND <i_package>-BWMNG EQ 0 ).
            DELETE SOURCE_PACKAGE index sy-tabix.
            CONTINUE.
          ENDIF.
    no_scl is initial ( e.g. for good receipts, billing)
    value has to be set depending on storno
          IF <i_package>-NOSCL IS INITIAL.
            IF <i_package>-ROCANCEL = 'X'.
              <i_package>-NOSCL = -1.
            ELSE.
              <i_package>-NOSCL = 1.
            ENDIF.
          ENDIF.
        ENDLOOP.
    Points have been assigned accordingly.
    Thanks,
    Csaba

  • ABAP (Routine) Error in BW Transformations

    Hi Experts,
    As i am new(Learner) to BW Please advise me on how can i achieve this and update me with Releavent Start Routine and Field Routine....please
    My Requirment is
    Employee is Compounded on Location.
    On Weekly or Monthly basis (dependending on Employee Payroll run) Employee will be assigned with the Wage Type and Amount for that Wage Type and Payroll Date (When the payroll was run)
    Data Currently i have/Data comming from Source System
    Loc_ID--Emp_IDWage_IDPayroll_Date-Amount
    -1--99900108.08.2008-----100.00
    -1--99908808.08.2008-----560.00
    -1--99934508.08.2008-----437.00
    -1--99900108.07.2008-----654.00
    -1--99908808.07.2008-----389.00
    -1--99934508.07.2008-----893.00
    -1--99926408.06.2008-----600.00
    -1--99934508.08.2008-----365.00
    (Employee may have Different Wage_ID and Amount for each payroll)
    My requirment is to include a new key figure 'Previous_Amount' which will be populated previous Wage_ID Amount.
    Loc_ID--Emp_IDWage_IDPayroll_Date-Amount---Previous_Amount
    -1--99900108.08.2008---100.00-----654.00
    -1--99908808.08.2008---560.00--
    389.00
    -1--99934508.08.2008---437.00--
    893.00
    -1--99900108.07.2008---654.00--
    0
    -1--99908808.07.2008---389.00--
    0
    -1--99934508.07.2008---893.00--
    365.00
    -1--99926408.06.2008-----600.00
    -1--99934508.08.2008-----365.00
    As i am a starter in BW i am struggling to write start routine in transformations (DSO-->CUBE) to transfer the data in DSO Active Table to a internal table and a field routine to update Previous_Amount field by sorting the internal table data and to pick employee's latest record less than the current payroll for that particular wage_id and populate that amout to Previous_Amount field.
    Please make necessary corrections to the start routine by fixing where i went wrong and update me with the required field routine (which will read data from internal table used in start routine.
    With the help of Vamsi i can able to write this code,But still the Previous Price is filled with 0
    Please correct me where it went wrong
    Start Routine
    Global declaration
    Types :
    Begin of ITABtype,
    ORG               TYPE /BIC/OIZORG,
    CYEMPNO           TYPE /BIC/OIZCYEMPNO,
    HED_ID           TYPE /BIC/OIZHED_ID,
    RHED_ID           TYPE /BIC/OIZRHED_ID,
    CHNG_DTE          TYPE /BIC/OIZCHNG_DTE,
    HED_AMT           TYPE /BIC/OIZHED_AMT,
    HED_PAMT          TYPE /BIC/OIZHED_PAMT,
    End of ITABtype.
    Data : ITAB type standard table of ITABtype
    with key
    ORG
    CYEMPNO
    HED_ID
    RHED_ID
    CHNG_DTE
    HED_AMT
    HED_PAMT,
    wa_itab like line of itab.
    Data : ITAB1 type standard table of ITABtype
    with key
    ORG
    CYEMPNO
    HED_ID
    RHED_ID
    CHNG_DTE
    HED_AMT
    HED_PAMT,
    wa_itab1 like line of itab1.
    *Create an internal table with all the field types with u want to have
    *in the output */
    Data : wa_SOURCE_PACKAGE type tys_SC_1.
    Data : tmp(2) type n value 1.
    \ The above loop is to get all the values into the internal table*/
    Loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE.
    Move wa_SOURCE_PACKAGE-/BIC/ZORG to wa_itab-ORG.
    Move wa_SOURCE_PACKAGE-/BIC/ZCYEMPNO to wa_itab-CYEMPNO.
    Move wa_SOURCE_PACKAGE-/BIC/ZHED_ID to wa_itab-HED_ID.
    Move wa_SOURCE_PACKAGE-/BIC/ZHED_ID/BIC/ZRHED_ID to wa_itab-RHED_ID.
    Move wa_SOURCE_PACKAGE-/BIC/ZCHNG_DTE to wa_itab-CHNG_DTE.
    Move wa_SOURCE_PACKAGE-/BIC/ZHED_AMT to wa_itab-HED_AMT.
    *Move wa_SOURCE_PACKAGE-/BIC/ZHED_PAMT to wa_itab-HED_PAMT.
    Append wa_itab to itab.
    Endloop.
    Sort itab by
    ORG       Ascending
    CYEMPNO   Ascending
    HED_ID    Ascending
    RHED_ID   Ascending
    CHNG_DTE  Descending.
    Sort SOURCE_PACKAGE by
    /BIC/ZORG                   Ascending
    /BIC/ZCYEMPNO               Ascending
    /BIC/ZHED_ID                Ascending
    /BIC/ZHED_ID/BIC/ZRHED_ID   Ascending
    /BIC/ZCHNG_DTE              Descending.
    Loop at itab into wa_itab.
    tmp = '1' .
    Loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE from tmp.
    If wa_itab-ORG = wa_SOURCE_PACKAGE-/BIC/ZORG.
       wa_itab-CYEMPNO  = wa_SOURCE_PACKAGE-/BIC/ZCYEMPNO.
       wa_itab-HED_ID   = wa_SOURCE_PACKAGE-/BIC/ZHED_ID.
       wa_itab-RHED_ID  = wa_SOURCE_PACKAGE-/BIC/ZHED_ID/BIC/ZRHED_ID.
    wa_itab-CHNG_DTE = wa_SOURCE_PACKAGE-/BIC/ZCHNG_DTE.
       wa_itab-HED_PAMT = wa_SOURCE_PACKAGE-/BIC/ZHED_AMT.
      wa_itab-CHNG_DTE gt wa_SOURCE_PACKAGE-/BIC/ZCHNG_DTE.
    tmp = tmp + 1.
    Exit.
    Endif.
    Endloop.
    Modify itab from wa_itab.
    Endloop.
    itab1[] = itab[].
    Sort itab1 by
    ORG       Ascending
    CYEMPNO   Ascending
    HED_ID    Ascending
    RHED_ID   Ascending
    CHNG_DTE  Descending.
    Delete adjacent duplicates from itab1 comparing
    ORG
    CYEMPNO
    HED_ID
    RHED_ID
    CHNG_DTE.
    Loop at itab1 into wa_itab1.
    wa_itab-HED_PAMT = '0'.
    Modify itab1 from wa_itab1.
    Endloop.
    Loop at itab into wa_itab.
    Loop at itab1 into wa_itab1.
    If wa_itab1-ORG = wa_itab-ORG.
       wa_itab1-CYEMPNO = wa_itab-CYEMPNO.
       wa_itab1-HED_ID  = wa_itab-HED_ID.
       wa_itab1-RHED_ID = wa_itab-RHED_ID.
       wa_itab1-CHNG_DTE = wa_itab-CHNG_DTE.
       wa_itab1-HED_PAMT = wa_itab-HED_PAMT.
    Exit.
    Endif.
    Endloop.
    Modify itab from wa_itab.
    Endloop.
    Field Routine
    Read table ITAB into wa_itab
    with key
    ORG       = SOURCE_FIELDS-/BIC/ZORG
    CYEMPNO   = SOURCE_FIELDS-/BIC/ZCYEMPNO
    HED_ID    = SOURCE_FIELDS-/BIC/ZHED_ID
    RHED_ID   = SOURCE_FIELDS-/BIC/ZHED_ID/BIC/ZRHED_ID
    CHNG_DTE  = SOURCE_FIELDS-/BIC/ZCHNG_DTE.
    if sy-subrc = 0.
    RESULT = wa_itab-HED_PAMT.
    endif.
    Please update me where it was wrong
    Thanks in advance

    Hi again,
    i don't have a BW system available now so the code is more as a how to and needs corrections but i hope you will figure out the logic.
    declare an internal table and working area similar with the ods object.
    data itab type table of ods_type.
    data wa_itab type ods_type.
    declare a working area for the source package.
    data wa_source type type_source_package.
    data l_tabix like sy-tabix.
    select all active entries from ods .
    if you figure out a performance issue here move this select into the loop and use where clauses or use for all entries in source_package
    select * from ods_object into table itab .
    sort source_package by payroll_date descending.
    loop at source_package into wa_source.
    l_tabix = sy-tabix.
    read table itab into wa_itab with key Loc_ID = wa_source_package-loc_id
                                          Emp_ID = wa_source_package-emp_id
                                          wage_id = wa_source_package-Wage_ID.
    wa_source-previous_amount = wa_itab-amount.
    modify source_package from wa_source index l_tabix.
    endloop.
    This code should be in the start routine of the ods update.
    Hope this helps
    Kostas

  • HOw to write/Develop this Start & Field Routine

    Hi Experts,
    As i am new(Learner) to BW Please advise me on how can i achieve this and update me with Releavent Start Routine and Field Routine....please
    My Requirment is
    Employee is Compounded on Location.
    On Weekly or Monthly basis (dependending on Employee Payroll run)  Employee will be assigned with the Wage Type and Amount for that Wage Type and Payroll Date (When the payroll was run)
    Data Currently i have/Data comming from Source System
    Loc_ID--Emp_IDWage_IDPayroll_Date-Amount
    -1--99900108.08.2008-----100.00
    -1--99908808.08.2008-----560.00
    -1--99934508.08.2008-----437.00
    -1--99900108.07.2008-----654.00
    -1--99908808.07.2008-----389.00
    -1--99934508.07.2008-----893.00
    -1--99926408.06.2008-----600.00
    -1--99934508.08.2008-----365.00
    (Employee may have Different Wage_ID and Amount for each payroll)
    My requirment is to include a new key figure 'Previous_Amount' which will be populated previous Wage_ID Amount.
    Loc_ID--Emp_IDWage_IDPayroll_Date-Amount---Previous_Amount
    -1--99900108.08.2008---100.00-----654.00
    -1--99908808.08.2008---560.00--
    389.00
    -1--99934508.08.2008---437.00--
    893.00
    -1--99900108.07.2008---654.00--
    0
    -1--99908808.07.2008---389.00--
    0
    -1--99934508.07.2008---893.00--
    365.00
    -1--99926408.06.2008-----600.00
    -1--99934508.08.2008-----365.00
    As i am a starter in BW i am struggling to write start routine in transformations (DSO-->CUBE) to transfer the data in DSO Active Table to a internal table and a field routine to update Previous_Amount field by sorting the internal table data and to pick employee's latest record less than the current payroll  for that particular wage_id and populate that amout to Previous_Amount field.
    Please make necessary corrections to the start routine by fixing where i went wrong and update me with the required field routine (which will read data from internal table used in start routine.
    Start Routine
    Data: ITAB_DSOP type table of /BIC/AZDFREW200,
          WA_DSOP type /BIC/AZDFREX200.
    Data: WA_PACKAGE like line of SOURCE_PACKAGE.
    Data: L_TABIX type SY-TABIX.
    If not SOURCE_PACKAGE[] is initial.
    Sort SOURCE_PACKAGE by
    /BIC/ZLOC                          ascending
    /BIC/ZEMP_ID                      ascending
    /BIC/ZPAY_DATE                     ascending
    /BIC/ZWGE_ID                       ascending.
    clear ITAB_DSOP[].
    Select  from /BIC/AZDFREW200 into table ITAB_DSOP
    for all entries in SOURCE_PACKAGE
        Where  /BIC/ZLOC      = SOURCE_PACKAGE-/BIC/ZLOC.
               /BIC/ZEMP_ID  = SOURCE_PACKAGE-/BIC/ZEMP_ID.
               /BIC/ZWGE_ID   = SOURCE_PACKAGE-/BIC/ZWGE_ID.
               /BIC/ZPAY_DATE < SOURCE_PACKAGE-/BIC/ZPAY_DATE.
    If sy-subrc = 0.
    Sort ITAB_DSOP by
    /BIC/ZLOC                          ascending
    /BIC/ZEMP_ID                      ascending
    /BIC/ZPAY_DATE                     descending
    /BIC/ZWGE_ID                       ascending.
    if sy-subrc = 0.
    loop at SOURCE_PACKAGE into wa_package.
    l_tabix = sy-tabix.
    read table ITAB_DSOP into wa_DSOP with key
    /BIC/ZLOC = wa_package-/BIC/ZLOC
    /BIC/ZEMP_ID = wa_package-/BIC/ZEMP_ID
    /BIC/ZWGE_ID  = wa_package-/BIC/ZWGE_ID
    binary search.
    if sy-subrc = 0.
    Please update me with Start Routine and Field Routine required  to achieve my requirment
    Thanks in advance

    hii
        I created small example as ur case, for that I will explain my logic which i used and i will give the code make the necessary mofications and use in ur case
    1) First bring all the input that exist in source_package into a temporary table which we create as that of the output structue.
    2) Sort both input i.e source_package and temporary table by wage id and date ascending
    3) Next compare both of them and get the value of previous price into the temporary table from the source_package..
    4)write a routine at the field level to populate the previous_price by mappign both wage id and payroll date
    5) Between 3 step and 4 step i used one more temporary table to get the values of previous price 0
    GLOBAl PART
      types : begin of itabtype,
               job_no type /bic/oirt_jobno,
               wage_id type /bic/oirt_wgid1,
               date type  /bic/oizfrm_dt,
               prc  type  /bic/oirt_prc,
               previous_price type /bic/oirt_prc1,
            end of itabtype.
    data : itab type standard table of itabtype
                           with key wage_id date,
                wa_itab like line of itab.
    data : itab1 type standard table of itabtype
                           with key wage_id date,
                wa_itab1 like line of itab1.
    \* Create an internal table with all the field types with u want to have in the output */
    LOCAL PART
      data : wa_SOURCE_PACKAGE type tys_SC_1.
      data : tmp(2) type n value 1.
       loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE.
             move wa_SOURCE_PACKAGE-/bic/rt_jobno to wa_itab-job_no.
             move wa_SOURCE_PACKAGE-/bic/rt_wgid1 to wa_itab-wage_id.
             move wa_SOURCE_PACKAGE-/bic/zfrm_dt to wa_itab-date.
             move wa_SOURCE_PACKAGE-/bic/rt_prc to wa_itab-prc.
             append wa_itab to itab.
        endloop.
      \* The above loop is to get all the values into the internal table*/
        sort itab by wage_id ascending date descending.
        sort SOURCE_PACKAGE by /bic/rt_wgid1 ascending /bic/zfrm_dt
        descending.
        loop at itab into wa_itab.
                tmp = '1' .
                 loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE from tmp.
                      if  wa_itab-date gt  wa_SOURCE_PACKAGE-/bic/zfrm_dt
                      and  wa_itab-wage_id = wa_SOURCE_PACKAGE-/bic/rt_wgid1
                          wa_itab-previous_price =
                          wa_SOURCE_PACKAGE-/bic/rt_prc.
                          tmp = tmp + 1.
                          exit.
                       endif.
                   endloop.
         modify  itab from wa_itab.
        endloop.
        itab1[] = itab[].
        sort  itab1 by wage_id ascending date ascending.
        delete adjacent duplicates from itab1 comparing wage_id.
        loop at itab1 into wa_itab1.
           wa_itab-previous_price = '0'.
           modify itab1 from wa_itab1.
        endloop.
        loop at itab into wa_itab.
              loop at itab1 into wa_itab1.
                     if wa_itab1-date = wa_itab-date and wa_itab1-wage_id = wa_itab-wage_id.
                             wa_itab-previous_price = wa_itab1-previous_price.
                             exit.
                      endif.
                endloop.
           modify itab from wa_itab.
          endloop.
    This looks big but logic is small....
    get back to me if any queries u have
    regards
    vamsi

  • Routine (ABAP Code)  in Transformation error

    Hi Experts
    Please correct the ABAP CODE written as Field routine in Transformations
    Requirment
    If  ZB_AMT = '0.00'
    then result should be '0.00'
    If  ZB_AMT <> '0.00' and
    SOURCE_FIELDS-/BIC/ZB_TPE1 = 'AMOUNT'
    the result should be
    CONCATENATE '$' SOURCE_FIELDS-/BIC/ZB_AMT INTO RESULT.
    If  ZB_AMT <> '0.00' and
    SOURCE_FIELDS-/BIC/ZB_TPE1 = 'PERCENTAGE'
    the result should be
    CONCATENATE  SOURCE_FIELDS-/BIC/ZB_AMT  '%' INTO RESULT.
    The code below is not working as it should please update me where i went wrong
    Source Fields
    SOURCE_FIELDS-/BIC/ZB_AMT (CHAR)
    SOURCE_FIELDS-/BIC/ZB_TPE1 (CHAR)
    CODE
    IF SOURCE_FIELDS-/BIC/ZB_AMT = '0.00'.
          RESULT = '0.00'.
        ELSE.
          IF SOURCE_FIELDS-/BIC/ZB_TPE1 = 'AMOUNT' AND
             SOURCE_FIELDS-/BIC/ZB_AMT <> '0.00'.
            CONCATENATE '$' SOURCE_FIELDS-/BIC/ZBON_AMT INTO RESULT.
            IF SOURCE_FIELDS-/BIC/ZB_TPE1 = 'PERCENTAGE' AND
               SOURCE_FIELDS-/BIC/ZB_AMT <> '0.00'.
              CONCATENATE SOURCE_FIELDS-/BIC/ZB_AMT '%' INTO RESULT.
            ENDIF.
          ENDIF.
        ENDIF.

    Your logic will not work, if your first check on amount is 0.00 fails, the other checks fail as well. I am not sure of the requirement but..try this..
    IF SOURCE_FIELDS-/BIC/ZB_TPE1 = 'AMOUNT' AND SOURCE_FIELDS-/BIC/ZB_AMT = '0.00'.
    CONCATENATE '$' SOURCE_FIELDS-/BIC/ZBON_AMT INTO RESULT.
    ELSEIF SOURCE_FIELDS-/BIC/ZB_TPE1 = 'PERCENTAGE' AND SOURCE_FIELDS-/BIC/ZB_AMT = '0.00'.
    CONCATENATE SOURCE_FIELDS-/BIC/ZB_AMT '%' INTO RESULT.
    ELSEIF SOURCE_FIELDS-/BIC/ZB_AMT = '0.00'.
      RESULT = '0.00'.
    ELSE.
    Do nothing or throw any message
    ENDIF.

  • Logic in Transformations to delete record

    Hi,
    How to write(syntax) a routine in Start routine of transformation
    I am extraction data from ECC to DSO in BW
    My requirment is in Transformations start routine i need to check each record if source package on 2 fields XYZ and PQR....need to update the record only if both the fields are NOT BLANK
    How to achieve this
    Thanks

    Hi
    There is a small correction in your syntax
    DELETE DATA_PACKAGE WHERE XYX IS INTIIAL
                                                OR PQR IS INITIAL.
    This will delete the records if any one of the field is blank
    There is one more option that you can handle in the field routine for skipping the record
    Just take the first field routine in your transformation, it may be any field say FCG
    Make the two fields XXX and PQR as the source by inserting them
    First map the source anf destination fiel d of the field in which the routine is created
    RESULT = SOURCE_FIELDS-FCG
    IF soure_fields-XXX IS INITIAL
    OR source_fields-PQR IS INITIAL.
    RAISE EXCEPTION TYPE CX_RSROUT_SKIP_RECORD
    ENDIF.
    By doing this the record will be skipped and it will not be updated to the target DSO.
    Prathish

  • (ABAP) Code in Transformation--Modification

    Hi Experts,
    As i am new(Learner) to BW Please advise me on how can i achieve this and update me with Releavent Start Routine and Field Routine....please
    My Requirment is
    Employee is Compounded on Location.
    On Weekly or Monthly basis (dependending on Employee Payroll run) Employee will be assigned with the Wage Type and Amount for that Wage Type and Payroll Date (When the payroll was run)
    Data Currently i have/Data comming from Source System
    Loc_ID--Emp_IDWage_IDPayroll_Date-Amount
    -1--99900108.08.2008-----100.00
    -1--99908808.08.2008-----560.00
    -1--99934508.08.2008-----437.00
    -1--99900108.07.2008-----654.00
    -1--99908808.07.2008-----389.00
    -1--99934508.07.2008-----893.00
    -1--99926408.06.2008-----600.00
    -1--99934508.08.2008-----365.00
    (Employee may have Different Wage_ID and Amount for each payroll)
    My requirment is to include a new key figure 'Previous_Amount' which will be populated previous Wage_ID Amount.
    Loc_ID--Emp_IDWage_IDPayroll_Date-Amount---Previous_Amount
    -1--99900108.08.2008---100.00-----654.00
    -1--99908808.08.2008---560.00--
    389.00
    -1--99934508.08.2008---437.00--
    893.00
    -1--99900108.07.2008---654.00--
    0
    -1--99908808.07.2008---389.00--
    0
    -1--99934508.07.2008---893.00--
    365.00
    -1--99926408.06.2008-----600.00
    -1--99934508.08.2008-----365.00
    As i am a starter in BW i am struggling to write start routine in transformations (DSO-->CUBE) to transfer the data in DSO Active Table to a internal table and a field routine to update Previous_Amount field by sorting the internal table data and to pick employee's latest record less than the current payroll for that particular wage_id and populate that amout to Previous_Amount field.
    Please make necessary corrections to the start routine by fixing where i went wrong and update me with the required field routine (which will read data from internal table used in start routine.
    With the help of Vamsi i can able to write this code,But still the Previous Price is filled with 0
    Please correct me where it went wrong
    Start Routine
    Global declaration
    Types :
    Begin of ITABtype,
    ORG               TYPE /BIC/OIZORG,
    CYEMPNO           TYPE /BIC/OIZCYEMPNO,
    HED_ID           TYPE /BIC/OIZHED_ID,
    RHED_ID           TYPE /BIC/OIZRHED_ID,
    CHNG_DTE          TYPE /BIC/OIZCHNG_DTE,
    HED_AMT           TYPE /BIC/OIZHED_AMT,
    HED_PAMT          TYPE /BIC/OIZHED_PAMT,
    End of ITABtype.
    Data : ITAB type standard table of ITABtype
    with key
    ORG
    CYEMPNO
    HED_ID
    RHED_ID
    CHNG_DTE
    HED_AMT
    HED_PAMT,
    wa_itab like line of itab.
    Data : ITAB1 type standard table of ITABtype
    with key
    ORG
    CYEMPNO
    HED_ID
    RHED_ID
    CHNG_DTE
    HED_AMT
    HED_PAMT,
    wa_itab1 like line of itab1.
    *Create an internal table with all the field types with u want to have
    *in the output */
    Data : wa_SOURCE_PACKAGE type tys_SC_1.
    Data : tmp(2) type n value 1.
    \ The above loop is to get all the values into the internal table*/
    Loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE.
    Move wa_SOURCE_PACKAGE-/BIC/ZORG to wa_itab-ORG.
    Move wa_SOURCE_PACKAGE-/BIC/ZCYEMPNO to wa_itab-CYEMPNO.
    Move wa_SOURCE_PACKAGE-/BIC/ZHED_ID to wa_itab-HED_ID.
    Move wa_SOURCE_PACKAGE-/BIC/ZHED_ID/BIC/ZRHED_ID to wa_itab-RHED_ID.
    Move wa_SOURCE_PACKAGE-/BIC/ZCHNG_DTE to wa_itab-CHNG_DTE.
    Move wa_SOURCE_PACKAGE-/BIC/ZHED_AMT to wa_itab-HED_AMT.
    *Move wa_SOURCE_PACKAGE-/BIC/ZHED_PAMT to wa_itab-HED_PAMT.
    Append wa_itab to itab.
    Endloop.
    Sort itab by
    ORG       Ascending
    CYEMPNO   Ascending
    HED_ID    Ascending
    RHED_ID   Ascending
    CHNG_DTE  Descending.
    Sort SOURCE_PACKAGE by
    /BIC/ZORG                   Ascending
    /BIC/ZCYEMPNO               Ascending
    /BIC/ZHED_ID                Ascending
    /BIC/ZHED_ID/BIC/ZRHED_ID   Ascending
    /BIC/ZCHNG_DTE              Descending.
    Loop at itab into wa_itab.
    tmp = '1' .
    Loop at SOURCE_PACKAGE into wa_SOURCE_PACKAGE from tmp.
    If wa_itab-ORG = wa_SOURCE_PACKAGE-/BIC/ZORG.
       wa_itab-CYEMPNO  = wa_SOURCE_PACKAGE-/BIC/ZCYEMPNO.
       wa_itab-HED_ID   = wa_SOURCE_PACKAGE-/BIC/ZHED_ID.
       wa_itab-RHED_ID  = wa_SOURCE_PACKAGE-/BIC/ZHED_ID/BIC/ZRHED_ID.
    wa_itab-CHNG_DTE = wa_SOURCE_PACKAGE-/BIC/ZCHNG_DTE.
       wa_itab-HED_PAMT = wa_SOURCE_PACKAGE-/BIC/ZHED_AMT.
      wa_itab-CHNG_DTE gt wa_SOURCE_PACKAGE-/BIC/ZCHNG_DTE.
    tmp = tmp + 1.
    Exit.
    Endif.
    Endloop.
    Modify itab from wa_itab.
    Endloop.
    itab1[] = itab[].
    Sort itab1 by
    ORG       Ascending
    CYEMPNO   Ascending
    HED_ID    Ascending
    RHED_ID   Ascending
    CHNG_DTE  Descending.
    Delete adjacent duplicates from itab1 comparing
    ORG
    CYEMPNO
    HED_ID
    RHED_ID
    CHNG_DTE.
    Loop at itab1 into wa_itab1.
    wa_itab-HED_PAMT = '0'.
    Modify itab1 from wa_itab1.
    Endloop.
    Loop at itab into wa_itab.
    Loop at itab1 into wa_itab1.
    If wa_itab1-ORG = wa_itab-ORG.
       wa_itab1-CYEMPNO = wa_itab-CYEMPNO.
       wa_itab1-HED_ID  = wa_itab-HED_ID.
       wa_itab1-RHED_ID = wa_itab-RHED_ID.
       wa_itab1-CHNG_DTE = wa_itab-CHNG_DTE.
       wa_itab1-HED_PAMT = wa_itab-HED_PAMT.
    Exit.
    Endif.
    Endloop.
    Modify itab from wa_itab.
    Endloop.
    Field Routine
    Read table ITAB into wa_itab
    with key
    ORG       = SOURCE_FIELDS-/BIC/ZORG
    CYEMPNO   = SOURCE_FIELDS-/BIC/ZCYEMPNO
    HED_ID    = SOURCE_FIELDS-/BIC/ZHED_ID
    RHED_ID   = SOURCE_FIELDS-/BIC/ZHED_ID/BIC/ZRHED_ID
    CHNG_DTE  = SOURCE_FIELDS-/BIC/ZCHNG_DTE.
    if sy-subrc = 0.
    RESULT = wa_itab-HED_PAMT.
    endif.
    Please update me where it was wrong
    Thanks in advance

    hi
    First loop fetches value from source_package into itab like thiss
    ITAB
    Hed_id    chng_date           Hed_Amt         Hed_Pmat
       001       08.08.2008            100                         NO VALUE YET
       001       08.07.2008            654                         NO VALUE YET                     
       088      08.08.2008             560                         NO VALUE YET
       088      08.07.2008              389                        NO VALUE YET
    Source_package
    Hed_id    chng_date           Hed_Amt        
       001       08.08.2008            100                        
       001       08.07.2008            654                                                     
       088      08.08.2008             560 
       088      08.07.2008              389
    That loop compares the itab and source_package by nrigning one record after another into wa_itab and wa_source_packageu2026.
    Wa_itab-chng_date > wa_odurce_package-chng_date and wa_itab-hed-id  = wa_source_package-hed_id
          1)       08.08.2007          >  08.08.2008               101    =101     false
           It will loop for second iteration in source_package outer loop it is at first record only.
         2)      08.08.2007        >   08.07.2008                  101   = 101    true
                   So wa_itab-zhed_pamt = wa_source_package-price ( right we has to get that value only )
                              Wa_itab-zhed_pamt = 654 (wa_source_package-amt).
                   So exit that loop and modify the itab
              So ur itab first record becomes
                    001       08.08.2008            100                654
    3) and it continues in the inner loop and finds no record with the sameu2026.
    So after this entire looping
    ITAB
    Hed_id    chng_date           Hed_Amt         Hed_Pmat
       001       08.08.2008            100                         654
       001       08.07.2008            654                         NO VALUE YET                     
       088      08.08.2008             560                         389
       088      08.07.2008              389                        NO VALUE YET
    Next itab1 = itab  so
    ITAB1
    Hed_id    chng_date           Hed_Amt         Hed_Pmat
       001       08.08.2008            100                         654
       001       08.07.2008            654                         NO VALUE YET                     
       088      08.08.2008             560                         389
       088      08.07.2008              389                        NO VALUE YET
    For the  001  08.07.2008 we has to get previous amount 0 for that
    Sort and delte adjacent steps after iot becomes like this
    ITAB1
    Hed_id    chng_date           Hed_Amt         Hed_Pmat
    001       08.07.2008            654                         NO VALUE YET     
    088      08.07.2008              389                        NO VALUE YET
    Next loop modify and add zero to previous amount  to these values
    ITAB1
    Hed_id    chng_date           Hed_Amt         Hed_Pmat
    001       08.07.2008            654                         0
    088      08.07.2008              389                        0
    Next loop we will modify these values to the internal table
    Hed_id    chng_date           Hed_Amt         Hed_Pmat
       001       08.08.2008            100                         654
       001       08.07.2008            654                         0                     
       088      08.08.2008             560                         389
       088      08.07.2008              389                        0
    Next using field routine suppose incoming record has hed_id 101 and change_date  08.08.2008             then the previous value corresponding to it is read from the itab
    U try to do debugging and know those more ......
    Regards
    vamsi

Maybe you are looking for