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

Getting Data from Structure and Store Data into Table using Function Module

Former Member
0 Likes
1,368

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.

13 REPLIES 13
Read only

Former Member
0 Likes
1,351

does anyone here know why is this so? thanks alot...

Read only

0 Likes
1,351

Give the FM code so that we can troubleshoot your problem....

Read only

0 Likes
1,351

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.

Read only

0 Likes
1,351

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.


Read only

0 Likes
1,351

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...

Read only

0 Likes
1,351

Hi Fluffy,

You need to use the LOOP Statement to insert the data into the database table.

Thanks,

Chidanand

Read only

0 Likes
1,351

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.

Read only

0 Likes
1,351

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.

Read only

0 Likes
1,351

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.

Read only

0 Likes
1,351

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

Read only

0 Likes
1,351

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...

Read only

0 Likes
1,351

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. 

Read only

0 Likes
1,351

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?