‎2008 Oct 24 12:53 PM
Hello...
we are created a function module to import 2 structures in the systems and want to read the data from the structure into a customized table when the fucntion module is called. However, whenever the function module is run, we only managed to have one data into the customized table whereas the actual results is that there will be a few records in this customized table.
‎2008 Oct 24 12:54 PM
‎2008 Oct 24 12:56 PM
Give the FM code so that we can troubleshoot your problem....
‎2008 Oct 24 1:15 PM
hello...the code is as below:
FUNCTION Z_MBB_WRITE_RES_MORT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_CKF_CONTRACT) TYPE /BA1/R2_STR_CALC_KF
*" REFERENCE(I_CKF_PROCESS) TYPE /BA1/R2_STR_CKF_PROCESS
*"----------------------------------------------------------------------
TABLES ZRESMORT.
DATA E_ZRESMORT TYPE STANDARD TABLE OF ZRESMORT WITH HEADER LINE.
SELECT * FROM ZRESMORT.
DELETE ZRESMORT.
ENDSELECT.
E_ZRESMORT-MORT_FT_ID = I_CKF_CONTRACT-COMMON-CONTRACT_ID_EXT.
E_ZRESMORT-MORT_KDATE = I_CKF_PROCESS-TECHNICAL-KEY_DATE.
E_ZRESMORT-MORT_TSTAMP = I_CKF_PROCESS-TECHNICAL-TIMESTAMP.
E_ZRESMORT-MORT_FLAG = 1.
E_ZRESMORT-MORT_BUPA = I_CKF_CONTRACT-BUPA-BUSINESS_PARTNER_ID.
E_ZRESMORT-MORT_PORTFO = I_CKF_CONTRACT-BUPA-PORTFOLIO_CAT.
E_ZRESMORT-MORT_FT_ID_DUM = I_CKF_CONTRACT-COMMON-CONTRACT_ID.
INSERT INTO ZRESMORT VALUES E_ZRESMORT.
IF SY-SUBRC EQ 0.
ENDIF.
ENDFUNCTION.
‎2008 Oct 24 1:58 PM
You are deleting all the values in your table first, then inserting one value from the import parameters, so at any point in time you will always have 1 value in the Z table
FUNCTION Z_MBB_WRITE_RES_MORT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_CKF_CONTRACT) TYPE /BA1/R2_STR_CALC_KF
*" REFERENCE(I_CKF_PROCESS) TYPE /BA1/R2_STR_CKF_PROCESS
*"----------------------------------------------------------------------
TABLES ZRESMORT.
DATA E_ZRESMORT TYPE STANDARD TABLE OF ZRESMORT WITH HEADER LINE.
SELECT * FROM ZRESMORT. <=====================
DELETE ZRESMORT. <================== It is deleting all the records in your Z table
ENDSELECT. <===============================
E_ZRESMORT-MORT_FT_ID = I_CKF_CONTRACT-COMMON-CONTRACT_ID_EXT.
E_ZRESMORT-MORT_KDATE = I_CKF_PROCESS-TECHNICAL-KEY_DATE.
E_ZRESMORT-MORT_TSTAMP = I_CKF_PROCESS-TECHNICAL-TIMESTAMP.
E_ZRESMORT-MORT_FLAG = 1.
E_ZRESMORT-MORT_BUPA = I_CKF_CONTRACT-BUPA-BUSINESS_PARTNER_ID.
E_ZRESMORT-MORT_PORTFO = I_CKF_CONTRACT-BUPA-PORTFOLIO_CAT.
E_ZRESMORT-MORT_FT_ID_DUM = I_CKF_CONTRACT-COMMON-CONTRACT_ID.
INSERT INTO ZRESMORT VALUES E_ZRESMORT.
IF SY-SUBRC EQ 0.
ENDIF.
ENDFUNCTION.
‎2008 Oct 25 4:31 PM
Hi Mxg,
So how can we modify the code so that the functiona module will add in more than one records into the table when the function module is being called??
thanksss...
‎2008 Oct 25 5:12 PM
Hi Fluffy,
You need to use the LOOP Statement to insert the data into the database table.
Thanks,
Chidanand
‎2008 Oct 25 5:17 PM
Hi,
It should be something like this...
TABLES ZRESMORT.
DATA E_ZRESMORT TYPE STANDARD TABLE OF ZRESMORT WITH HEADER LINE.
SELECT * FROM ZRESMORT. <=====================
DELETE ZRESMORT. <================== It is deleting all the records in your Z table
ENDSELECT. <===============================
Loop at I_CKF_CONTRACT. " Assuming this is the Main Table
Read table I_CKF_PROCESS with key ." Here you will read this table to get the corresponding records of Table I_CKF_CONTRACT
E_ZRESMORT-MORT_FT_ID = I_CKF_CONTRACT-COMMON-CONTRACT_ID_EXT.
E_ZRESMORT-MORT_KDATE = I_CKF_PROCESS-TECHNICAL-KEY_DATE.
E_ZRESMORT-MORT_TSTAMP = I_CKF_PROCESS-TECHNICAL-TIMESTAMP.
E_ZRESMORT-MORT_FLAG = 1.
E_ZRESMORT-MORT_BUPA = I_CKF_CONTRACT-BUPA-BUSINESS_PARTNER_ID.
E_ZRESMORT-MORT_PORTFO = I_CKF_CONTRACT-BUPA-PORTFOLIO_CAT.
E_ZRESMORT-MORT_FT_ID_DUM = I_CKF_CONTRACT-COMMON-CONTRACT_ID.
INSERT INTO ZRESMORT VALUES E_ZRESMORT.
IF SY-SUBRC EQ 0.
ENDIF.
endloop.
‎2008 Oct 25 5:43 PM
Cant say anything unless I know the complete picture of what you are trying to do. Fro now I can say that your FM is importing one value and you wan tot insert that value, while retaining the other value in there.
One way would be to put a where condition ib the code below to delete just the entries you want to get rid of not all
SELECT * FROM ZRESMORT.
DELETE ZRESMORT.
ENDSELECT.
‎2008 Oct 28 1:31 AM
hey...actually when the function module is being called, this functional module will delete all the data in the existing table "zresmort", load in the new sets of data.
Currently when the function module is being called, the existing data in the table cannot be deleted and insert another new sets of data.
‎2008 Oct 28 1:37 AM
Would you have all the records available when calling this FM? if yes, then instead of using structur ein import parameters use table types as the import and then use the rows to update the Z table for all the rows at the same time
‎2008 Oct 28 1:47 AM
the function module is to called the structure, there are no table for this to store the data, we get the data from the structure...
‎2008 Oct 28 1:57 AM
You need to think of logic on what you are trying here.
basically you want to call it several times in one process, and during that you would want to delete all previous entries.
One option would be to define a global variable V_flag , and set that during the 1st run, and check that flag in subsequent one before deleting the entries
if v_flag = space.
SELECT * FROM ZRESMORT.
DELETE ZRESMORT.
ENDSELECT.
v_flag = 'X'
endif.
‎2008 Oct 28 3:19 AM
Hi MxG..
thanks for your information. For the global variable that you mentioned in the previous post, what's the purpose of the global variable? thanksss...can elaborate more on this?