Code sample for using change document function modules

Can someone send me some sample code for using function modules CHANGEDOCUMENT_READ_HEADER and CHANGEDOCUMENT_READ_POSITIONS?  I'm specifically looking for changes that occured to the standard price field in the material master (MBEW-STPRS) and I need to pull the most recent price change for a given material.  I'm not sure how to write the code efficiently since I don't have a date to pass (again, since we're looking for the most recent change.)
Thanks!

hi check this..
CHANGEDOCUMENT_READ_HEADERS
Example:
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
objectclass = 'EINKBELEG'
objectid = l_objectid
username = space
TABLES
i_cdhdr = lt_cdhdr.
LOOP AT lt_cdhdr WHERE udate IN s_aedat.
CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING
changenumber = lt_cdhdr-changenr
TABLES
editpos = lt_editpos.
LOOP AT lt_editpos WHERE fname = 'LOEKZ'
AND f_new = 'L'.
p_desc = text-r01. " Cancel Contract
ENDLOOP.
ENDLOOP.
CHANGEDOCUMENT_READ_POSITIONS
Example:
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
objectclass = 'EINKBELEG'
objectid = l_objectid
username = space
TABLES
i_cdhdr = lt_cdhdr.
LOOP AT lt_cdhdr WHERE udate IN s_aedat.
CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING
changenumber = lt_cdhdr-changenr
TABLES
editpos = lt_editpos.
LOOP AT lt_editpos WHERE fname = 'LOEKZ'
AND f_new = 'L'.
p_desc = text-r01. " Cancel Contract
ENDLOOP.
ENDLOOP.
Check this link.
http://www.sap-img.com/mm001.htm
<REMOVED BY MODERATOR>
venkat.
Edited by: Alvaro Tejada Galindo on Mar 18, 2008 4:05 PM

Similar Messages

  • Regarding a Change Document Function Module ----- VERY VERY Urgent

    I am using a Change Document Function module "CHANGEDOCUMENT_READ". It is taking a long time.
    I am using the parameters:
    Start date is the first date of the current month
    Enddate as last date of the current month
    Object class as 'MATERIAL'
    Table Name as 'MBEW'

    Hi ,
    When you want to read the change documents, please follow the below process.
    1. Read the change documents headers with function modules
    call function 'CHANGEDOCUMENT_READ_HEADERS'
           exporting
                date_of_change             = cdhdr-udate
                objectclass                = cdhdr-objectclas
                objectid                   = cdhdr-objectid
                time_of_change             = '000000'
                username                   = cdhdr-username
           tables
                i_cdhdr                    = gt_cdhdr
           exceptions
                no_position_found          = 1
                wrong_access_to_archive    = 2
                time_zone_conversion_error = 3
                others                     = 4.
    2. From above step you will get data of change documents very quickly into Itab (gt_cdhdr)
    3. Read the details on change documents with functiion module by using Itab in loop for each document.
      loop at gt_cdhdr.
        call function 'CHANGEDOCUMENT_READ_POSITIONS'
             exporting
                  changenumber            = gt_cdhdr-changenr
             importing
                  header                  = cdhdr
             tables
                  editpos                 = gt_cdshw
             exceptions
                  no_position_found       = 1
                  wrong_access_to_archive = 2
                  others                  = 3.
    Above is the best way to read the change documents.
    Rewards please if above info is useful.
    Thanks.

  • How to use Change doc Function Module?

    Fn mod:ZSUBTESTCHG_WRITE_DOCUMENT
    Import parameters               Value
    OBJECTID                        ZSUBTESTCHG
    TCODE                            SE37
    UTIME                             00:00:00
    UDATE                             09.03.2009
    USERNAME                        'TESTUSER'
    PLANNED_CHANGE_NUMBER
    OBJECT_CHANGE_INDICATOR            I
    PLANNED_OR_REAL_CHANGES         R
    NO_CHANGE_POINTERS
    UPD_ICDTXT_ZSUBTESTCHG               I
    N_ZSUBTEST                         2         TEST
    O_ZSUBTEST                         2         TEST
    UPD_ZSUBTEST                    I
    Tables                          Value
    ICDTXT_ZSUBTESTCHG                 0 Entries
    I have a ztable 'ZSUBTEST' with 2 fields DEPTID and DEPNAME and ticked "change document" for data element.
    I have created the above change doc write fn module. I am trying to insert a new reocrd into table.
    How to use ZSUBTESTCHG_WRITE_DOCUMENT so that even if i try to change an existing record in ztable the old and new values for a particulat ztable will be filled in CDPOS Table.
    Would appreciate if you can suggest me how to use in1) Update and 2) Insert scenarios.
    Thanks,
    Subba

    hi check this,
    Types Declaration***
    types: BEGIN OF X_audit,
    Field of ZAUDIT TABLE OR a custom created table------
           END OF X_audit.
    Data Declaration***
    Data: w_newvalues type X_audit,
          w_oldvalues type X_audit.
    DATA: BEGIN OF t_cdtxt OCCURS 0.
            INCLUDE STRUCTURE cdtxt.
    DATA: END OF t_cdtxt.
    DATA:  l_tcode type cdhdr-tcode ,
           l_time type cdhdr-utime,
           l_usnam type cdhdr-username,
           l_date type cdhdr-udate.
    **Constants****
    CONSTANTS : l_objectid TYPE cdhdr-objectid VALUE 'ZAUDIT_CD'.
    Initialization.
    Clear: l_tcode,l_time, l_usnam, l_date.
    Clear: w_newvalues, w_oldvalues.
    **Start-Of-Selection**
    Start-of-selection.
    *Populating w_oldvalues workarea with old values from the table
    Select single * from zaudit_t
                    Into w_oldvalues
                    Where belnr eq belnr_1
                    And  gjahr eq gjahr_1
                    And  bukrs eq bukrs_1. u201C where, belnr_1, gjahr_1, bukrs_1  are the fields on selection screen.
    here we are populating w_newvalues workarea with new values
    W_newvalues-f1 = w_oldvalues-f1
    f2 = u2018XXXXXXXu2019     -
    f3 = u2018YYYYYYYu2019
    f4 = u2018ZZZZZZZu2019
    l_tcode = sy-tcode.
    l_time = sy-uzeit.
    l_usnam = sy-uname.
    l_date = sy-datum.
    modify the table with new values***
    MODIFY zaudit_t FROM w_submit.
    IF sy-subrc EQ 0.
        MESSAGE 'Document Updated' TYPE 'S'.
    call function 'ZAUDIT_CD1_WRITE_DOCUMENT'
        exporting
          objectid                   = l_objectid
          tcode                      = l_tcode
          utime                      = l_time
          udate                      = l_date
          username                   = l_usnam
        PLANNED_CHANGE_NUMBER      = ' '
          object_change_indicator    = 'U'           u201CU-update, I-insert, D-delete
        PLANNED_OR_REAL_CHANGES    = ' '
        NO_CHANGE_POINTERS         = ' '
          upd_icdtxt_zaudit_cd       = 'U'
          n_zaudit_t                 = w_newvalues  u201Cpass the work area containing new values     
          o_zaudit_t                 = w_oldvalues  u201Cpass the work area containing old values
          upd_zaudit_t               = 'U'         u201C this parameter gives the values in the columns(new value, old value and changed field name) of table CDPOS.
        tables
          icdtxt_zaudit_cd           = t_cdtxt
    ELSE.
       MESSAGE 'Document Not Updated' TYPE 'S'.
    ENDIF. u201CIF sy-subrc EQ 0.

  • Code samples for using HTTPServices in Cairngorm framework

    Hello there,
    Does anyone have any samples for retrieving data through
    HTTPServices using the cairngorm framework model. All samples on
    the web, as far as I have searched, lead only to remote services
    mode of communication only.
    Any help here would be greatly appreciated.
    Thanks,
    Arun B
    [email protected]

    I wrote a sample code modifiying the Remote Object examples
    .. I got this working now . Please ignore this message, just incase
    anyone needs my sample just email me..

  • URI format for using XSL document function.

    Hi Tim,
    >>but I am not able to figure out where I should place the xml file. What are best practices for choosing a location for the xml file?
    You can place the xslt code and xml file in a single folder, zip it an import it into PI as an external definition. I think this should work
    Regards
    Suraj

    Thank you for your reply.    But my requirements are such that they need to be independent, and not be in the same imported archive (ie ZIP file).    In my case the XSLT code is a standard product that is the same across multiple installations,  but each installation may required some installation specific cross reference values that would be maintained in the XML file.    So I need them separated so if I make updates to my XSLT and distribute it, I do not wipe out the installation specific settings that have been made to the XML file.

  • How to get the "last changed by" for a set of function modules?

    How to get the "last changed by" for a set of function modules?
    is there any table to get it??

    See [this|Re: Date of creation of function module] I posted earlier.
    >TFDIR will give you the name of the function group program and the include number.
    >E.g. SAPLZFUNCGROUP Include 01.
    >From this you can construct the include name: LZFUNCGROUPU01.
    >You can look this up in TRDIR to find the creation date (CDAT) of the function module.
    In your case, you need unam and udat.
    matt

  • How to create the change document functionality for a dependent objects?

    May I please know how to create the change document functionality for a dependent objects?
    I have done it follow the same process as for business process objects. But when i try to test it in BOBT, there is no records under "FIELD_CHANGE_WITH_FILTER". It seems the change hasn't been recorded.
    If the way I did to create change document for dependent object is correct, please also kindly advise the possibilities for why there is no record during testing.
    thanks in advance.

    I also have some doubts about the business object.In this case,one abstract BO hase a subnode wihich is root extended.I added the change document for this node under the category "root_extended" and then tested the function in BOBT.I got some error message "can't find the root key".Shall i redefine the method /BOFU/IF_CDO_CREATION~IS_CDO_CREATION_ACTIVE so as to solve the problem?
    Thx.

  • Problem while generating Update progam for a Change Document Object

    Hi,
    I'm trying to deal with Change Document concept in a R/3 4.6C environment and to establish new Change Document object for my (Z)-table. I haven't using any namespace and created object with name ZTEST. Following the online documentation I came to the point, where I have to generate include program. I made all the nessesary inputs (using Z prefix) but faced
    "Function module name is reserved for SAP"
    Creating everything similarily using some of our registered namespaces (/somenamespace/) I succeed to generate the Update program and to integrate it in my Z-programs as well.
    My question is: is it possible to use Change Document Object-names without predefined namespace - being a regular customer developer, but not an SAP developer - means, if I am allowed to manage programs in the customer namespace (Z,Y, X) only. If yes, how to do this?
    Further (I decided not to open a new thread) - generated Update program uses
    CALL FUNCTION 'xxxxx' IN UPDATE TASK
    for creation of Change Numbers for generated Change Document Object. This CALL doesn't work when I implemented it in my Z-program, but when changed  (IN UPDATE TASK was commented) - everything goes well and the system creates records in CDHDR/CDPOS tables for my object class and table.
    Why is that? According to the documentation I shoud only fill appropriate variables for the Change Document Object (class, tr.code, etc.) and call generated FM, nothing is pointed out about any possible problems? Am I doing something wrong?
    Well, to be precise, I think I have to give a sample:
    1. I have a sample Z-table with few fields (their data elements are marked as Change-Document relevant).
    2. Using own z-progam I created a new record for this z-table. Also fill all the nessesary variables included in the interface of generated FM for Change Document Object (for example - FM-mane CD_CALL_my_object).
    3. I call the CDO FM.
    4. Check what is happening (directly in both tables CDHDR/CDPOS or using FM CHANGEDOCUMENT_READ).
    Further, I perfom the steps from 1 to 4 updating the created in previous loop record in my Z-table.
    In both cases if the FM 'CD_CALL_my_object' is called IN UPDATE TASK nothing happens, but in case of direct call (without addition IN UPDATE TASK) the system behaves as expected. Well, obliously I can change the generated code for our production needs, but it doesn't seems to be the correct decision - in case of next possible modification of the Change Document Object definition, respectively in need of re-generation of the code.
    Any hints are wellcome.
    Thanks in advance.
    Ivaylo Mutafchiev
    Edited by: Ivaylo Mutafchiev on Jan 24, 2008 10:24 AM

    "IN UPDATE TASK" resolved by myself. The one should explicitly call 'COMMIT WORK' from Z-program after CALL FUNCTION '...' IN UPDATE TASK in order to get changes in the CDHDR/CDPOS commited. The key in this issue for me was to check the documentation of CALL FUNCTION :-).
    Regards,
    Ivo

  • How to make use of SE37- Function Module & how to find out the table?

    Hi ,
    1.Could anyone help me what's this SE37-Function module is all about,How to make use of this?
    For Eg,If i want to delete a BOM permanently from the system then I have to use the Function module CM_DB_DEL_FROM_ROOT_BOM.
    But after giving the particular name what should i do?
    Please help me.
    2.How to find out the respective table for a particular field sya for T code-COGI, T code MFBF,where its values are getting populated.,Please help in this issue.
    Thanks in adavnce for spending some time
    Raj.S

    Hi Raj
    Function Modules
    Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.
    Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating  and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.
    Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
    The Function Builder  also has a release process for function modules. This ensures that incompatible changes cannot be made to any function modules that have already been released. This applies particularly to the interface. Programs that use a released function module will not cease to work if the function module is changed.
    Check this link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
    You can execute function module in SE37ie you can perform the activiites defined in the function module by executing it.
    By deleting BOM you mention the FM name in se37 and execute. In some function module it will ask input parameters as developed in the program , you have to give the input parameters and execute.

  • Regarding Workflow trigerring using change document

    Hi all,
    I am trying to trigger a workflow using change document object.
    I want that to trigger the workflow on the material master change through MM02.
    I have created  a business object ZBUS1001 and wanted that on change of material master
    the custom change document object should call the workflow
    I went through all the material avaialable over SDN ,but can not find a change object for change in material master through MM02  for std business object  BUS1001.
    Please tell me how to find one.
    Please reply if any one of you have some solution.

    Hi,
    Thanks for your reply.
    I am using an existing change object - MATERIAL_N of Business Object - BUS1001 and the event
    BASICMATERIALCHANGED.
    I have mentioned  the details in the tcode SWEC.
    And even in the workflow i have given the start of event  as the BUS1001 and event BASICMATERIALCHANGED.
    But workflow not called .
    Do we need to maintain an entry in SWED?
    If yes then in function module column what we need to mention.

  • Is it necessary to use the standard function modules always?

    Hi All,
       Suppose i can retrieve the BUSINEES PARTNER ID from the table BUT000 with the help of 'BP_GUID' field through a select query statement. 
    Now is it necessary to use a standard function module to retrieve the same data. what about the performance? which is the better solution. to implement our own code or to use the function module available.
    Please someone clarify me about this issue.
    Regards,
    Sharry.

    If you'd ask the question in general it's obvious that there is no good answer as it always would depend on the circumstance. However, as you've posted your question in the performance tuning forum, let's look at your question in this context first. I think it's fairly safe to say, that in almost 100% of the cases a standard function module will not be as fast as any well implemented and custom tailored code. If in doubt, just try reading the code of the function module you want to read; most likely you will find lots of unnecessary fluff in there, often they read data that you don't even need.
    And as far as buffering is concerned, that can also be an issue. E.g. let's say you do a massive read of distinct business partners and you only need the data once for each partner. Obviously buffering is silly in this case and it might even slow down your program, because the implemented buffering is not necessarily well implemented. I've come across a few cases, where the buffer tables where standard tables with no efficient read access (so no sorted table or hash table) and once tons of data were buffered, it actually took a moment to look up if the record already was buffered (just to find it wasn't there yet).
    Now most of the times this slowdown is not an issue as the lookup is still fast compared to the (usually) prevalent database accesses with their slower IO timing. But another factor to consider is memory consumption and why buffer data in memory (and waste it), if you can't use the buffer anyway? So when I do use standard function modules, I usually try to see what they retain in global memory, to better understand if I need to call some initialization/clearing/refresh function...
    Note also that often you need to process lots of data, but don't find a standard function module for "mass access", so you need to read your object one by one. Obviously that's another good candidate for implementing your own queries, where you can process the data in packages.
    So what might be the reason to use a standard function module? Well, often it's required because the logic is so complex that it would take you too much time to implement it (not to mention that we often simply don't know all the logic that's coded in there). Another advantage is that you might get independent of the data model. E.g. for IDoc interfaces SAP switched in some release the tables where the data is stored. So if you had coded your own queries to get IDoc data, they wouldn't have worked after this particular release upgrade. The standard function on the other hand, checks both the old and new tables, so by using it you would have been fine.
    The one major caveat I'd give though is to always check whether the function module is released or at least documented to some degree. I.e. if it's not released, SAP won't support it and does not guarantee that the interface or logic stays the same. In my experience lots of functions I do want to use are not released (or documented), but I will still use them because they seem to be the best alternative in certain scenarios.
    Cheers, harald

  • How to do data source ehancement by using "Extraction by function module"

    I have one customized datasource "ZSOURCE" in R/3, this datasource use Extraction by function module, namely one functiona
    module "ZBI_FM_EX"and Extract. struct "ZBI_EX".
    Now I want to add one field "ZNEW" from standard SAP table LIKP into extractor "ZBI_EX" and write coding in ZXRSAU01.
    Question, could I add new field "ZNEW" into Structure:"ZBI_EX"? Do I need to change anything in functional module "ZBI_FM_EX" itself?
    Many Thanks!
    rajatina.

    Hi Dear,
                  It is good to write the code in your function module i.e. ZBI_FM_EX. becuase writing the code in ZXRSAU01 include program will affect the loading performance. instead of looping the data two time (one in your FM and again in ZXRSAU01 ), you can get the same will only loop.
    Thanks
    Obaid
    Edited by: obaid shaikh on Jan 21, 2011 11:53 AM

  • Why do so many code samples here use Arrays?

    I've seen many code samples here use Arrays. Why? I much prefer to use ArrayLists, and Vectors if I need synchronization or HashSets if I require uniqueness. I don't understand why people are using Arrays when the Collection classes are so useful. You can change the underlying datastructure without changing any of the access code.

    I guess they are faster...
    public class Test1 {
         public static void main(String[] args) {
                Integer zero = new Integer(0);
                   long start = System.currentTimeMillis();
                   for (int j = 0; j < 1000; j++) {
                        Integer[] array = new Integer[10000];
                        for (int i = 0; i < 10000; i++) {
                             array[i] = zero;
                   long finish = System.currentTimeMillis();
                   System.out.println(finish - start);
                   start = System.currentTimeMillis();
                   for (int j = 0; j < 1000; j++) {
                        ArrayList arrayList = new ArrayList();
                        for (int i = 0; i < 10000; i++) {
                             arrayList.add(zero);
                   finish = System.currentTimeMillis();
                   System.out.println(finish - start);
    }~460 ms for array
    ~1600 for ArrayList
    Still, the benefit of the Collections interface and the better OO design of code that uses these classes is probably worth it in most cases, IMO.

  • To use SubRoutines and function modules and include

    Hellow Friends ,
    Can any body suggest me at waht situations we have to use SubRoutines and function modules and include in an abap report and also i need the standards in an abap program.

    Hi Rajesh,
    You use create subroutines within your programs for those block of codes which are used often within the scope of the development. Function modules are like global subroutines , hence any number programs which might want to use the functionality within the function module can do so.
    Creating includes is a good programming prctise, e.g. one for data declerations , one for subroutines, so that it makes the code more reader friendly and also helps in modularizing the program. Also once you put a subroutine in an include, you can use the same subroutine in other programs by referring to the include with the INCLUDE statement in your other programs.
    Hence basically they are used for :
    1. Reusability
    2. Modularization of code (make it more readable)
    Hope this is of some help.
    Regards,
    Aditya

  • How to find out the Area Menu for a Report/ Table/Function Module

    Hi,
    Is there any procedure to find out the <b>"AREA MEANU"</b> for a Report/Table/Function Module...
    Or is there any Transaction code / Report is available to find out all the report for a particular "AREA MENU".
    Thank you for your quick response...
    Regards,
    Thiru
    <b></b>

    Hi,
    Check these below threads:
    user log in & log out time SAO
    How to find user log-out time ?
    Regards,
    Nitin

Maybe you are looking for

  • How to sync an iPhone 4 with a New Computer?

    I have a broken Windows Vista laptop, an iPhone 4 with broken WIFI, and a new Windows 7 PC. I'd like to backup the data on my iPhone somewhere, but the wireless iCloud backups won't work because my phone has no WIFI, and the old laptop I used to use

  • Syncing Palm Tungsten E2 With MacBook Air

    Hello, I have owned a Palm Tungsten E2 since 2005.  I was able to install the Desktop software on windows XP and sync the device with my Windows XP laptop since 2005.  I recently purchased a MAcBook Air and installed the Desktop Software from the CD

  • Performance of Sql query

    Hi, Is Insert (or) Update which one is faster. can any one explain breifly?

  • Essbase Connection error: version 11.1.2

    HI all, I am facing an issue... I am not able to see the SQL data source in the EAS - when I click File>Open SQL. It gives error - There are No data sources defined, SQL data sources option will be disabled and that is the case. somwhere i read to mo

  • External video capture card

    Hi I am looking for an 'external video capture card' that will record a screen and sound from a PC or preferable a mac at 30fps and 1080p that I can then edit with I have a budget up to £150 but can go further if need be. This is for video game trail