Application Development and Automation 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: 
Read only

MSEG question

Former Member
0 Likes
2,517

Hello,

I am working on a program that will read the records in the MSEG table and generate postings based on the value of the MSEG record. this process will be run at intervals (most likely daily). I am trying to figure out how to mark the MSEG records that have been processed so that when my program runs again, I do not pick up these records. I am not sure if there is a field in the MSEG table that is not being used in SAP that I could use or if I can add a field to the MSEG table. I was thinking of using the date as a driver but if for some reason the program does not run at the scheduled time and runs a day later, I could be in trouble in that I would not pick up all the records that have to be processed.

Thanks in advance for the help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,087

You have to go to MKPF and use the fields CPUDT and CPUTM (Create date and time) and use a date and time parameter in your selection screen for last run date and last run time. Your logic will be to pick up all those material documents that are created since the last run date and time. You will have to create two custom variant variables in TVARV for these two parameters, store the value of current run date and current run time in those TVARV variables once the processing is completed and read them before you start next time (INITIALIZATION event). Make sure that you store the current date and time are stored in variables captured right after the select statement because that is the last time you selected the documents not the end of your program execution.

Hello,

I am working on a program that will read the records in the MSEG table and generate postings based on the value of the MSEG record. this process will be run at intervals (most likely daily). I am trying to figure out how to mark the MSEG records that have been processed so that when my program runs again, I do not pick up these records. I am not sure if there is a field in the MSEG table that is not being used in SAP that I could use or if I can add a field to the MSEG table. I was thinking of using the date as a driver but if for some reason the program does not run at the scheduled time and runs a day later, I could be in trouble in that I would not pick up all the records that have to be processed.

Thanks in advance for the help.

9 REPLIES 9
Read only

Former Member
0 Likes
2,087

Hi,

I had the same scenario and i Implemented this..

1) Create a custom table with material document and year..

2) In the BADI MB_DOCUMENT_BADI method MB_DOCUMENT_UPDATE..You can also use the exit EXIT_SAPLMBMB_001..Both are called in the same function module.

Populate the records in the custom table...The material document and year will be available in this BADI.

3) Then in the program select all the records from that custom table...Once it is successfully processed delete the records from the custom table..

Thanks,

Naren

Read only

0 Likes
2,087

Naren,

I will look at the BADI but I am not sure if I am missing something in your response . when you state

<i>"Populate the records in the custom table...The material document and year will be available in this BADI.

3) Then in the program select all the records from that custom table...Once it is successfully processed delete the records from the custom table..</i>

"

I populate the records from the MSEG table into the custom table. I use the records in the custom table in my program. I delete the records from the custom table when my process is complete. My question is, what prevents these same records from being populated in the custom table when the next running of the program occurs?

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,087

First I would not suggest using any of the standard fields within the MSEG structure. It doesn't appear that there is any APPEND structure or INCLUDE structure which can be used to add your field. This is usually how it would be extended. So, another option is to use a user exit within the material document creation which will write you a record out to a custom database, then you can do whatever you want as far as setting a flag or whatever.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,087

After reading the reocrds...update the MSEG table field....try to use not used field of MSEG table and update with X value, which will indicate you that record has been read before.

I hope this will help you.

Regards,

Amey

Read only

Former Member
0 Likes
2,088

You have to go to MKPF and use the fields CPUDT and CPUTM (Create date and time) and use a date and time parameter in your selection screen for last run date and last run time. Your logic will be to pick up all those material documents that are created since the last run date and time. You will have to create two custom variant variables in TVARV for these two parameters, store the value of current run date and current run time in those TVARV variables once the processing is completed and read them before you start next time (INITIALIZATION event). Make sure that you store the current date and time are stored in variables captured right after the select statement because that is the last time you selected the documents not the end of your program execution.

Read only

0 Likes
2,087

Srinivas,

This sounds like a good idea but I have one question. we plan on running this on off-hours when no-one is on the the system, probably at night but, do I have to worry about the possibility of after the select of the MKPF data and before the update of the date time variables, a new document is created? do I have to do something like lock the MKPF table, do the select, update the variables, unlock the table? if I lock the MKPF and someone tries to create the document, will they blow up?. is it a good idea to lock the MKPF table for the period of selecting and updating the variables?

Read only

0 Likes
2,087

No, I would not suggest locking. The chance of a document getting created right after your select is very remote. What I will do is to capture the date and time right after your select statement and update that to the TVARV variable. That way you will be as close as possible to include all the documents.

Just to be on the safe side, you can also add document number and year as part of your selection screen. By adding them, you will have the flexibility of retrieving any documents that you might have missed. But make sure that when someone enters a document number, you select only that document and not apply the date criteria. Also, you don't want to update TVARV during such adhoc runs. If you take care of these scenarios, I think you will not miss any document and even if you miss, you can always send it as an adhoc run.

Read only

Former Member
0 Likes
2,087

Hi,

Okay..Once the material document is posted..It will generate a number along with the year..Let's say 123 and year 2006..

You put that information in that table..

In the program you will select all the records from the custom table..

In the program you process that record ...If it is successful ...you will delete that record from the custom table...Let's say 123 and 2006 record is deleted from the table..

Then the next time the program runs the record 123 and 2006 is no longer available in the table...It won't process that record again...

And every time a new material document is created...A new number will be generated in the standard sap program...

Thanks,

Naren

Read only

Former Member
0 Likes
2,087

Sorry for the delay is responding. I have some more questions and depending on the answer I can then make a decision on which way to go. the BADI idea sounds pretty good but I am a little nervous about changing the code that affects the online processing. everytime a material document is created, it will call this badi and update the custom table based on my selection parameters. if something goes wrong with this process, the online processing is affected, possibly evens stops. That is why I am leaning towards the TVARV process.

1) am I worrying to much about the online processing?

2) I am thinking that the performance using the badi will be better that using the TVARV method but not enough to make the changes to the badi code