Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

!!Urgent!! help needed for CDHDR FM

Former Member
0 Kudos

hello everyone,

I need to read the changes done for material. When I'm testing the function module through se37, it runs fine. Also, I am able to go and see the changes done by me in the contents of cdhdr. Following is my code, can someone tell me what I'm missing here:

*********************************************************

data: ins_data type string,

upd_data type string.

parameters:

p_b_date like CDHDR-UDATE obligatory, "Begin Date

p_e_date like CDHDR-UDATE obligatory, "End Date

p_b_time like CDHDR-UTIME obligatory, "Begin Time

p_e_time like CDHDR-UTIME obligatory. "End Time

data: begin of i_pt_cdhdr occurs 0.

include structure cdhdr.

data: end of i_pt_cdhdr.

CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

EXPORTING

DATE_OF_CHANGE = p_b_date

OBJECTCLASS = 'MATERIAL'

TIME_OF_CHANGE = p_b_time

USERNAME = SY-UNAME

DATE_UNTIL = p_e_date

TIME_UNTIL = p_e_time

TABLES

I_CDHDR = i_pt_cdhdr

EXCEPTIONS

NO_POSITION_FOUND = 1

WRONG_ACCESS_TO_ARCHIVE = 2

TIME_ZONE_CONVERSION_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

open dataset v_data1 for output

in text mode encoding default.

loop at i_pt_cdhdr.

if i_pt_cdhdr-change_ind = 'I'.

At First.

concatenate 'Material' 'Inserted' into ins_data separated by ' '.

concatenate 'Object ID' 'Document Change Number' 'Username' 'Creation Date' 'Time changed' 'Transaction' 'Change indicator' 'Language'

into ins_data separated by ' '.

transfer ins_data to v_data1.

Endat.

*Load data for inserted material

concatenate i_pt_cdhdr-objectid i_pt_cdhdr-changenr i_pt_cdhdr-username i_pt_cdhdr-udate i_pt_cdhdr-utime i_pt_cdhdr-tcode i_pt_cdhdr-change_ind i_pt_cdhdr-langu

into ins_data separated by ' '.

transfer ins_data to v_data1.

*Message if no material inserted

else.

concatenate 'No material' 'inserted.' into ins_data.

transfer ins_data to v_data1.

*Check for Update indicator

if i_pt_cdhdr-change_ind = 'U'.

*Load headings first

At First.

concatenate 'Material' 'Updated' into ins_data separated by ' '.

concatenate 'Object ID' 'Document Change Number' 'Username' 'Creation Date' 'Time changed' 'Transaction' 'Change indicator' 'Language'

into upd_data separated by ','.

transfer upd_data to v_data1.

Endat.

*Load data for inserted material

concatenate i_pt_cdhdr-objectid i_pt_cdhdr-changenr i_pt_cdhdr-username i_pt_cdhdr-udate i_pt_cdhdr-utime i_pt_cdhdr-tcode i_pt_cdhdr-change_ind i_pt_cdhdr-langu

into upd_data separated by ','.

transfer upd_data to v_data1.

*Message if no material updated

else.

concatenate 'No material' 'updated.' into upd_data.

transfer upd_data to v_data1.

endif.

endif.

endloop.

*Close file on Application Server

close dataset v_data1.

*********************************************************

In short, I need to read changes for material Inserted or Updated and load it to the Application Server. In the function module, i_pt_cdhdr is not getting populated. SY-SUBRC is 1.

Please let me know how to resolve this.

Many Thanks.

Regards,

Fred.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Don't give the SY-UNAME to the function module. You want to capture all the changes/inserts, not just the person who is running your program.

13 REPLIES 13

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You function module actually works quite well in my system. Are you sure that you are not getting anything back from the FM? Are you sure that the dates/times are correct and that they will pick something up?



report zrich_0001.


parameters:
p_b_date like cdhdr-udate obligatory default '20060101', "Begin Date
p_e_date like cdhdr-udate obligatory default '20060406', "End Date
p_b_time like cdhdr-utime obligatory default '000001', "Begin Time
p_e_time like cdhdr-utime obligatory default '235959'. "End Time

data: begin of i_pt_cdhdr occurs 0.
        include structure cdhdr.
data: end of i_pt_cdhdr.


call function 'CHANGEDOCUMENT_READ_HEADERS'
     exporting
          date_of_change             = p_b_date
          objectclass                = 'MATERIAL'
          time_of_change             = p_b_time
          username                   = sy-uname
          date_until                 = p_e_date
          time_until                 = p_e_time
     tables
          i_cdhdr                    = i_pt_cdhdr
     exceptions
          no_position_found          = 1
          wrong_access_to_archive    = 2
          time_zone_conversion_error = 3
          others                     = 4.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.


check sy-subrc  = 0.


loop at i_pt_cdhdr.


write:/
i_pt_cdhdr-OBJECTCLAS,
i_pt_cdhdr-OBJECTID,
i_pt_cdhdr-CHANGENR,
i_pt_cdhdr-USERNAME,
i_pt_cdhdr-UDATE,
i_pt_cdhdr-UTIME,
i_pt_cdhdr-TCODE.


endloop.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

Thanks for the quick reply.

I think I figured out why its behaving like this, but i'll need some help from you on this.

I can't default the dates because i'm reading them as variants from TVARV table. In this table i'm putting date as 20060406, and when i read the variant into my program, it comes as 04/06/2006. Date and time will be changed every time.

But here's the problem, while debugging the program, i see that date is passed as 20060406, the exact value as from TVARV table, and when i tried testing the function module by putting in value for date as 20060406, it says this is an incorrect value.

I think this is the reason that my change pointer table is not getting populated, because the format for date/time passed into it is wrong. On the other hand, if I put that format into TVARV table, then when i call the variant, its format seems to be odd. For example, in TVARV i put 2006/04/06 and in my program it gives /0/4//2006.

Regards,

Fred.

0 Kudos

Right, the internal format will always be 20060406, this is coming correctly, this is the value that should be being passed to the function module. Now in "Test" mode of the function module, it provides you an interface, here you will want to enter the data in the MM/DD/YYYY format, if you debug this, you will see that the interface will convert it to YYYYMMDD. Please test my program above and make sure that all is well.

Regards,

Rich Heilman

0 Kudos

Hi Fred,

Your TVARV varaible value should be stored as 20060406 as you mentioned. That is the correct way. The same value will not work in SE37 because there you need to input it in the external format. Everything is ok, just remove the SY-UNAME as I mentioned before and it should work.

Srinivas

Former Member
0 Kudos

Don't give the SY-UNAME to the function module. You want to capture all the changes/inserts, not just the person who is running your program.

0 Kudos

Yes, this is for testing purposes. I have done changes as well, and I want to see whether they are reflected or not. I see them in the contents of cdhdr through se16 but the function module is not working.

0 Kudos

> Yes, this is for testing purposes. I have done

> changes as well, and I want to see whether they are

> reflected or not. I see them in the contents of cdhdr

> through se16 but the function module is not working.

That is strange. Your code works for me. Let us take the variant part of it out of the picture. Try inputting the dates and times manually and see if it works.

0 Kudos

I just copied and pasted Rich's code, and it works fine.

So why is my code reacting different? The only different part is that I am not defaulting values for dates and time, they are just being read from TVARV table. The values of dates and times are changed in TVARV so that only deltas are read.

0 Kudos

Just before calling the function module , put a break point, now run it, check the values that you are passsing, are then coming correctly?

YYYYMMDD

HHMMSS

Regards,

Rich Heilman

0 Kudos

We use the same logic for reading deltas and it always worked. How are you updating TVARV in the program and are you referring to the TVARV variable in your variant? Do you have TVARV variables defined for FROM DATE and TIME? I hope you are defaulting the TO DATE and TIME to current date and time.

0 Kudos

The values are correct:

begin date: 20060101

begin time: 093753

end date: 20060406

end time: 100324

I did not fix anything, and now the table is being populated.

This seems very odd..I had been debugging it before also, and nothing seemed to pop up..and now its running ok.

Thank you so much all of you.

Regards,

Fred.

ferry_lianto
Active Contributor
0 Kudos

Hi Fred,

Please try to use this FM <b>CONVERT_DATE_TO_INTERN_FORMAT or CONVERT_DATE_TO_INTERNAL </b> to convert date format.

Hope this will help.

Regards,

Ferry Lianto

0 Kudos

Ferry, there is no need to convert the date here.

Regards,

Rich Heilman