2011 Sep 06 9:46 AM
Hi All,
My table has structue : Material --- Depo --- Start Date --- End Date
During Maintenance of table , there should not be Overlapping of dates for the Same Depo + Material.
For this , I am using event 05. But the problem is, it is copying the last entry read during the loop.
for eg :
first time i enter
1 - DDPL -- 1.1.2011 -- 31.12.2011
so it will create. now I enter second entry
2 -- DDPL -
1.1.2011 -- 31.12.2011.
but what I see in the table control is
1 - DDPL -- 1.1.2011 -- 31.12.2011
2 -- DDPL -
1.1.2011 -- 31.12.2011.
1 - DDPL -- 1.1.2011 -- 31.12.2011 -
Incorrect
So its appending the last entry read . Similarly For more new entries It is showing similar behaviour.
Below is code written for event 05.
DATA : lt_passage TYPE TABLE OF zTable,
wa_passage type zTable.
FIELD-SYMBOLS: <fs_prd> type any.
FIELD-SYMBOLS: <fs_depo> type any.
DATA: F_INDEX LIKE SY-TABIX. "Index to note the lines found
lOOP at total.
if <action> = NEUER_EINTRAG. " N--> New entry
READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDeX.
ENDIF.
IF F_INDEX <> 0.
ASSIGN COMPONENT 'MATERIAL' of STRUCTURE <vim_total_struc> to <fs_prd>.
ASSIGN COMPONENT 'DEPO' of STRUCTURE <vim_total_struc> to <fs_depo>.
if <fs_prd> = zTable-PRODUCT AND
<fs_depo> = zTable-WAREHOUSE.
*** code to compare Overlapping of Dates
endif.
ENdIF.
endif.
CLEAR : total,<vim_xtotal_key>,<vim_total_struc>.
ENDLOOP.
CLEAR : total,<vim_xtotal_key>,<vim_total_struc> .
Thanks
Jitendra
2011 Sep 06 9:52 AM
Hi,
I am not so clear with your question.
there should not be Overlapping of dates for the Same Depo + Material
I think this can be solved by adding one more key fields which makes the entry unique for a Materlal & Depo
Kesav
2011 Sep 06 9:52 AM
Hi,
I am not so clear with your question.
there should not be Overlapping of dates for the Same Depo + Material
I think this can be solved by adding one more key fields which makes the entry unique for a Materlal & Depo
Kesav
2011 Sep 06 10:36 AM
Hi Keshav,
Here keys are not a issue.
For the same Depo + Material Dats should not overlap.
eg.
Mateial -- Depo --- Star date -- Enddate
1 --- DDPL --- 01.01.2011 -
31.08.2011
1-- DDPL -
08.08.2011 -- 31.12.2011 -
> this is invalid entry becoz from 08.08.2011 to 31.08.2011 is already covered in
first entry,
Thanks
Jitendra
2011 Sep 06 10:46 AM
Hello Jitendra,
Mateial -- Depo --- Star date -- Enddate
1 --- DDPL --- 01.01.2011 -
31.08.2011
1-- DDPL -
08.08.2011 -- 31.12.2011 -
> this is invalid entry becoz from 08.08.2011 to 31.08.2011 is already covered in
In this case what should be SAP's response? Throw an error?
N.B.: In the event 05, the system internal tables TOTAL & EXTRACT are not updated. You can use the fields of the table directly e.g., ZTABLE-FIELDNAME.
Check this code snippet:
DATA: lt_zdelimit TYPE SORTED TABLE OF zdelimit
WITH NON-UNIQUE KEY matnr depo.
FIELD-SYMBOLS: <lwa_zdelimit> TYPE zdelimit.
* Fetch the recs from the table
SELECT * FROM zdelimit
INTO TABLE lt_zdelimit
WHERE matnr = zdelimit-matnr "Material Number
AND depo = zdelimit-depo. "Depo
IF sy-subrc = 0.
LOOP AT lt_zdelimit ASSIGNING <lwa_zdelimit>.
* Check if the i/p is overlapping with another period
IF <lwa_zdelimit>-start_dt LE zdelimit-end_dt AND
<lwa_zdelimit>-end_dt GE zdelimit-start_dt.
MESSAGE 'Overlapping periods. Correct your entry' TYPE 'E'.
ENDIF.
ENDLOOP.
ENDIF.
BR,
Suhas
Edited by: Suhas Saha on Sep 6, 2011 3:25 PM
Edited by: Suhas Saha on Sep 6, 2011 3:39 PM
2011 Sep 06 11:17 AM
Hi Suhas,
I am confused ..Suppose if the user enters 2 records without hitting an enter key and just hits the save button to save it...Will this code part execute correctly ?
I suppose that event 05 triggers with a enter key action...Is this correct ?
What about event 01..I think we should consider this event also.
Kesav
2011 Sep 06 11:32 AM
Hi Suhas,
Thanks For your Help.
Yes. it should throw an error.
I have checked , in event 05, system internal tables TOTAL & EXTRACT are updated .
If I use fields of table name directly, It will give me contents of the row currently being entered.
What I have to do is , I have to compare this entry with other entries entered(not saved) + Database entries.
Code given by you ,compares current entry with Database entries ( it should also consider other entries entered but not
SAVED).
Thanks
Jitendra
2011 Sep 06 11:42 AM
Hello Jitendra,
I have checked , in event 05, system internal tables TOTAL & EXTRACT are updated .
I've checked now & i don't find the new entries being updated in TOTAL. The table EXTRACT contains only the initial records. This does confirm to the SAP documentation on [Event 05|http://help.sap.com/saphelp_nw04s/helpdata/en/91/ca9f1aa9d111d1a5690000e82deaaa/content.htm].
What I have to do is , I have to compare this entry with other entries entered(not saved) + Database entries.
In this case you got to use the Event 01 & not 05!
BR,
Suhas
2011 Sep 06 12:39 PM
Hi Suhas,
Current entry will not update in TOTAL & EXTRACT, but entries entered previous than this entry, are updated in those tables.
For the current entry, I can directly use Table name and compare it with previous entries in table TOTAL & EXTRACT.
It a requiremnt that this checking should take place once use press enter So i have to use 05 only.
Thanks
Jitendra
2011 Sep 06 1:44 PM
Hello Jitendra,
Check this code snippet:
CLASS lcl_helper DEFINITION.
PUBLIC SECTION.
CLASS-METHODS check_db_data
RETURNING value(ex_err) TYPE flag.
ENDCLASS. "lcl_helper DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_helper IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_helper IMPLEMENTATION.
METHOD check_db_data.
DATA: lt_zdelimit TYPE SORTED TABLE OF zdelimit
WITH NON-UNIQUE KEY matnr depo.
FIELD-SYMBOLS: <lwa_zdelimit> TYPE zdelimit.
* Fetch the recs from the table
SELECT * FROM zdelimit
INTO TABLE lt_zdelimit
WHERE matnr = zdelimit-matnr "Material Number
AND depo = zdelimit-depo. "Depo
IF sy-subrc = 0.
LOOP AT lt_zdelimit ASSIGNING <lwa_zdelimit>.
* Check if the i/p is overlapping with another period
IF <lwa_zdelimit>-start_dt LE zdelimit-end_dt AND
<lwa_zdelimit>-end_dt GE zdelimit-start_dt.
ex_err = 'X'.
ENDIF.
ENDLOOP.
ENDIF.
ENDMETHOD. "check_db_data
ENDCLASS. "lcl_helper IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Form ZDELIMIT_EVT_05
*&---------------------------------------------------------------------*
* Event 05
*----------------------------------------------------------------------*
FORM zdelimit_evt_05.
STATICS: lv_run_flag TYPE flag.
DATA: lt_zdelimit TYPE SORTED TABLE OF zdelimit
WITH NON-UNIQUE KEY matnr depo.
FIELD-SYMBOLS: <matnr> TYPE matnr,
<depo> TYPE lgort_d,
<start_dt> TYPE d,
<end_dt> TYPE d.
BREAK-POINT.
IF lv_run_flag IS INITIAL.
lv_run_flag = 'X'. "Idea is to check for multiple "new" recs
* Step 1. Check existing DB recs
IF lcl_helper=>check_db_data( ) = 'X'.
MESSAGE 'Overlapping periods found in the table' TYPE 'E'.
ENDIF.
* Step 2. Check other "new" records
* TOTAL & EXTRACT tables are not updated in the first run, will check
* in subsequent runs
ELSE.
* Step 1. Check existing DB recs
IF lcl_helper=>check_db_data( ) = 'X'.
MESSAGE 'Overlapping periods found in the table' TYPE 'E'.
ENDIF.
* Step 2. Check other "new" records
LOOP AT total.
IF <action> = neuer_eintrag. " N--> New entry.
ASSIGN COMPONENT:
'MATNR' OF STRUCTURE <vim_total_struc> TO <matnr>,
'DEPO' OF STRUCTURE <vim_total_struc> TO <depo>.
CHECK <matnr> = zdelimit-matnr AND <depo> = zdelimit-depo.
ASSIGN COMPONENT:
'START_DT' OF STRUCTURE <vim_total_struc> TO <start_dt>,
'END_DT' OF STRUCTURE <vim_total_struc> TO <end_dt>.
* Check if the i/p is overlapping with another period
IF <start_dt> LE zdelimit-end_dt AND
<end_dt> GE zdelimit-start_dt.
MESSAGE 'Overlapping periods found in user input' TYPE 'E'.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "ZDELIMIT_EVT_05
BR,
Suhas
2011 Sep 07 7:26 AM
Hi Suhas,
Thanks a lot for your help.
but i have done some changes. I have removed <action> = neuer_eintrag condition and also we dont need to fetch data from
database as data exists in database will automatically filled in TOTAL table.
I am still confused between EXTRACT and TOTAL table as they have same data. what is difference between them ?
Thanks
Jitendra
2011 Sep 07 8:16 AM
Hello Jitendra,
TOTAL -> Contains all the data in the table - new, existing(unchanged), changed, deleted(you can check this in Event 01)
EXTRACT -> This is a subset of TOTAL & contains the data which is displayed. I've never checked this, but may be in 2-step maintenance you'll appreciate the difference between TOTAL & EXTRACT!
You can read the SAP documentation on these tables for further details.
also we dont need to fetch data from database as data exists in database will automatically filled in TOTAL table.
But then TOTAL contains all the records(as mentioned above), so in order to check the existence of the record i've to LOOP on TOTAL everytime.
LOOP'ing on TOTAL for every "new" record may give performance hiccups. So i thought it'll better to select data directly from the DB based on the material + depot combination!
BR,
Suhas
2011 Sep 06 10:18 AM
Hello Jitendra,
If you make the MaterialDepoStart Date as key fields, you cannot have overlapping periods
I'm sorry for this senseless answer
BR,
Suhas
Edited by: Suhas Saha on Sep 6, 2011 2:52 PM