Hi experts,
I am working in SAP Netweaver PI (Process Integration). I am facing an issue while writing a function module in ECC.
The function module updates a database table in ECC system (not PI system).
TABLE:

FUNCTION MODULE:
Import parameters of function module:
IF_NAME TYPE CHAR_02 (Character of length 2)
SENDER_DATE TYPE CHAR_08 (Character of length 8)
Export parameter:
V_OUTPUT TYPE INT
CODE:
FUNCTION ZFILE_COUNTER.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IF_NAME) TYPE CHAR_02
*" VALUE(SENDER_DATE) TYPE CHAR0008
*" EXPORTING
*" VALUE(V_OUTPUT) TYPE INT1
*"----------------------------------------------------------------------
TABLES zfile_counter.
TYPES: BEGIN OF ty_zfile_counter,
mandt TYPE zfile_counter-mandt,
if_name TYPE zfile_counter-if_name,
cntr_value TYPE zfile_counter-cntr_value,
curr_date TYPE zfile_counter-curr_date,
END OF ty_zfile_counter.
DATA: wa_zfile_counter TYPE ty_zfile_counter.
CLEAR: wa_zfile_counter.
SELECT SINGLE mandt if_name cntr_value curr_date
FROM zfile_counter
INTO wa_zfile_counter
WHERE if_name = if_name.
IF sy-subrc = 0.
IF sender_date <> wa_zfile_counter-curr_date.
wa_zfile_counter-cntr_value = '0'.
wa_zfile_counter-curr_date = sender_date.
UPDATE ZFILE_COUNTER from wa_zfile_counter.
COMMIT WORK.
ELSE.
v_output = wa_zfile_counter-cntr_value + 1.
UPDATE zfile_counter SET cntr_value = v_output
WHERE if_name = if_name.
IF sy-subrc = 0.
commit WORK.
endif.
ENDIF.
ENDIF.
ENDFUNCTION.
*********************************************************************************************************
PI will call the above function module whenever it receives a message from system, say system-A.
The import parameters of FM, will be sent from PI, when the function module is called in PI using RFC lookup feature.
IF_NAME is always a constant = "PI" (There is only going to be one record in the DB)
SENDER_DATE is the current date (i.e) date when PI calls the function module. This is sent as an 8 char number (eg: "20121026" for 26-Oct-2012)
So, the SENDER_DATE is just considered as a character string here and not as data-type: date.
AIM OF FN.MODULE:
The aim of the function module is to return a counter value, incremented by 1 each time the fn. module is called, which will be used in PI to maintain count of files coming in, during a single day. BUT, when a message comes on the next day, the counter value should be reset to 0 and start again.
LOGIC:
PI sends the current date when the first file comes into PI. This will be updated in field "CURR_DATE" of table in the ECC system by the function module. When next message comes into PI, again the fn. module is called and PI sends current date. This is checked with the value already there in CURR_DATE. If, there is a match, (it means the second file was also received on same date), the counter value is increased by 1 and returned. Like this the process continues. So, during any given time of the day, the total number of files received by PI will be stored in the table.
HOWEVER
When a message comes to PI on the next day, the date sent by PI for the function call (SENDER_DATE) will not be equal to CURR_DATE of the DB table. (Because, CURR_DATE will have previous day's date) So, the counter value will be reset to "0" and the field CURR_DATE of the table will be updated with the value of SENDER_DATE.
ISSUE:
I filled the table like this before first execution of function module: (random values to prevent the first SELECT query from failing)
(CURR_DATE = 25-Oct-2012)
When I called the function module from PI, the first time, the table got updated as below:
(SENDER_DATE = 20121026) **refer to PI trace below**
The counter value was correctly reset to "0" (since CURR_DATE does not match with SENDER_DATE), but the date string did not get updated in CURR_DATE.
When the second file came in to PI and function module was called second time, the table was updated like this:
So, obviously, there is some issue with CURR_DATE field but I cant find it. The data types are all the same.
The value passed by PI is STRING, the type of the import parameter, SENDER_DATE is CHAR and the type of the field CURR_DATE of DB table is also CHAR.
EXTRACT FROM PI TRACE:

PI also seems to be sending the correct value while calling the RFC. Any suggestions to remedy this are most welcome !!
thanks & regards,
Manoj