Is is possible to enter data in custom fields while creating transaction using Function modules?
Sometimes we need to create Financial Transaction automatically using such instruments as business objects (tr. SWO1) and function modules (tr. SE37), etc.
For example, business object BUS5550 “Interest Rate Instrument” has method to create transaction.
But we also need to use other business objects to create other parameters in our transaction.
- BUS5102 “Conditions”
- BUS5103 “Payment details”
- BUS5101 “Additional flows”
- etc.
So we have:
- Many business objects with functioin modules in order to create Interest rate instrument transaction.
- No business objects in order to fill our User-exit tab’s fields.
- If we use all mentioned business objects in our program, we are not able to use “TESTRUN” flag, because it works for BUS5550 “Interest Rate Instrument”, but for other business objects it requires already created transaction. But we need to test our function modules and structures with data before transaction creation.
- It’s not possible to start mirror transaction creation.
What to do?
The answer is to use standalone function modules like BAPI_FTR_*_DEALCREATE
Function module | Description |
---|---|
BAPI_FTR_IRATE_DEALCREATE | Completely Create an Interest Rate Instrument |
BAPI_FTR_FTD_DEALCREATE | Create a Fixed Term Deposit Completely |
BAPI_FTR_SECURITY_DEALCREATE | Completely Create a Security Transaction |
BAPI_FTR_FXT_DEALCREATE | Completely Create a Forex Transaction |
BAPI_FTR_FST_DEALCREATE | Completely Create a Forward Security |
BAPI_FTR_COMS_COND_DEALCREATE | Completely Create a Commodity Swap |
BAPI_FTR_COMS_DEALCREATE | Completely Create a Commodity Swap |
BAPI_FTR_CTYFWD_DEALCREATE | Completely Create a Forex Transaction |
BAPI_FTR_FLP_DEALCREATE | Completely Create a Forward Loan |
BAPI_FTR_REPO_DEALCREATE | Completely Create a Repo |
BAPI_FTR_TRES_DEALCREATE | Completely Create a Total Return Swap |
It’s a pity we don’t have any function modules for: Cash flow transaction, Facility, Commercial paper and some other produc types.
The structure of funcion module is:
function BAPI_FTR_IRATE_DEALCREATE.
IMPORTING
* "Structure tab paramters"
VALUE(INTERESTRATEINSTRUMENT) TYPE BAPI_FTR_CREATE_IRATE
* "What parameters we are entering at Structure tab"
VALUE(INTERESTRATEINSTRUMENTX) TYPE BAPI_FTR_CREATE_IRATEX
* "Administration tab paramters"
VALUE(GENERALCONTRACTDATA) TYPE BAPI_FTR_CREATE
* "Indicators what parameters we are entering at Administration tab"
VALUE(GENERALCONTRACTDATAX) TYPE BAPI_FTR_CREATEX
* "Indicator whether we are entering Conditions"
VALUE(CONDITION_COMPLETE_INDICATOR) TYPE BAPI2042-COMPLETE_INDICATOR DEFAULT SPACE
* "Indicator whether we are entering Payment details"
VALUE(PAYDET_COMPLETE_INDICATOR) TYPE BAPI2042-COMPLETE_INDICATOR DEFAULT SPACE
* "Indicator whether we are entering Additional flows"
VALUE(ADDFLOW_COMPLETE_INDICATOR) TYPE BAPI2042-COMPLETE_INDICATOR DEFAULT SPACE
* "Indicator whether we are entering Main flows (Other changes in capital structure button)"
VALUE(MAINFLOW_COMPLETE_INDICATOR) TYPE BAPI2042-COMPLETE_INDICATOR DEFAULT SPACE
* "Indicator for test run"
VALUE(TESTRUN) TYPE BAPI2042-TESTRUN DEFAULT SPACE
* "Indicator to start mirror transaction creation"
VALUE(MIRRORING) TYPE BOOLEAN_FLG DEFAULT SPACE
EXPORTING
* "After transaction creation we have company code"
VALUE(COMPANYCODE) TYPE BAPI2042-COMPANY_CODE
* "and transaction number"
VALUE(FINANCIALTRANSACTION) TYPE BAPI2042-TRANSACTION
TABLES
* "Condition paramters"
CONDITION STRUCTURE BAPI_FTR_CONDITION
* "What parameters we use in codition structure"
CONDITIONX STRUCTURE BAPI_FTR_CONDITIONX
* "Condition's formula parameters"
FORMULAVARIABLE STRUCTURE BAPI_FTR_CONDITION_FORMULA
* "Condition's single dates paramters"
SINGLEDATE STRUCTURE BAPI_FTR_CONDITION_SINGLEDAT
* "Payment details parameters"
PAYMENTDETAIL STRUCTURE BAPI_FTR_PAYDET
* "What parameters we use in payment details structure"
PAYMENTDETAILX STRUCTURE BAPI_FTR_PAYDETX
* "Additional flows parameters"
ADDFLOW STRUCTURE BAPI_FTR_FLOW
* "What parameters we use in main flow structure"
ADDFLOWX STRUCTURE BAPI_FTR_FLOWX
* "Main flows parameters"
MAINFLOW STRUCTURE BAPI_FTR_MAINFLOW
* "What parameters we use in main flow structure"
MAINFLOWX STRUCTURE BAPI_FTR_MAINFLOWX
* "User-exit tab's field parameters"
EXTENSIONIN STRUCTURE BAPIPAREX OPTIONAL
* "List of errors if we have them"
RETURN STRUCTURE BAPIRET2 OPTIONAL
How to fill all structures in function module it is material for other articles and right now let’s understand how to set/read User-exit tab’s field.
What we need is:
- badi FTR_CUSTOMER_EXTENT in order to create user-exit tabs and fields. Article
- function module ZSET_CUSTOM1 created in ZTRM_CUSTOM_TABS function group – a copy from FTR_CUSTOM_BADI_SAMPLE function group (tr. SE38 -> SAPLFTR_CUSTOM_BADI_SAMPLE)
- badi FTR_CUSTOMER_EXTENT, methods:
- EVT_BAPI_SET_CUSTOM1 – set new parameters at user-exit tab 1
- EVT_BAPI_SET_CUSTOM2 – set new parameters at user-exit tab 2
- EVT_BAPI_GET_CUSTOM1 – read parameters from user-exit tab 1 in BAPI_FTR_*_DEALGET function module
- EVT_BAPI_GET_CUSTOM2 – read parameters from user-exit tab 2 in BAPI_FTR_*_DEALGET function module
- Fill EXTENSIONIN structure for BAPI_FTR_IRATE_DEALCREATE function module in our program.
1. Reffer this article to create user-exit tab and fields in your transaction. Basic step is to copy function group FTR_CUSTOM_BADI_SAMPLE (SAPLFTR_CUSTOM_BADI_SAMPLE) into your own function group ZTRM_CUSTOM_TABS (SAPLZTRM_CUSTOM_TABS), for example.
Here we’ll have structure G_TAB_FHA_APPENDS which will have our append data.
Append (append ZTRM_CUSTOM_FIELDS in my exaple) usually is made to VTBFHA table.
2. Let’s create function module ZSET_CUSTOM1 in our ZTRM_CUSTOM_TABSfunction group.
FUNCTION ZSET_CUSTOM1.
*"----------------------------------------------------------------------
*"*"Локальный интерфейс:
*" EXPORTING
*" REFERENCE(PI_RETURN) TYPE BAPIRET2_TAB
*" TABLES
*" PT_EXTENSIONIN TYPE BAPIPAREXTAB
*"----------------------------------------------------------------------
DATA: LEN TYPE C LENGTH 3,
ZTAB LIKE LINE OF G_TAB_FHA_APPENDS.
* "getting data from append structure (user-exit tab 1)"
CALL METHOD G_PROXY_CUST_DATA->GET_CUST_DATA
IMPORTING
PE_TAB_FHA_APPENDS = G_TAB_FHA_APPENDS
EXCEPTIONS
OTHERS = 4.
* "Read data from EXT structures from function module BAPI_FTR_IRATE_DEALCREAT into append structure G_TAB_FHA_APPENDS"
IF SY-SUBRC = 0.
READ TABLE PT_EXTENSIONIN INDEX 1.
LEN = STRLEN( PT_EXTENSIONIN-VALUEPART1 ).
READ TABLE G_TAB_FHA_APPENDS INDEX 1 INTO ZTAB.
ZTAB-CONTENT(LEN) = PT_EXTENSIONIN-VALUEPART1(LEN).
MODIFY G_TAB_FHA_APPENDS FROM ZTAB INDEX 1.
ENDIF.
* "Saving data from EXT structure into transaction"
CALL METHOD G_PROXY_CUST_DATA->SET_CUST_DATA
EXPORTING
PI_TAB_FHA_APPENDS = G_TAB_FHA_APPENDS
EXCEPTIONS
INVALID_DATA = 1
INVALID_CALL = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
ENDFUNCTION.
3. In your implementation of FTR_CUSTOMER_EXTENT for method EVT_BAPI_SET_CUSTOM1 enter ZSET_CUSTOM1 function module.
METHOD IF_EX_FTR_CUSTOMER_EXTENT~EVT_BAPI_SET_CUSTOM1.
CALL FUNCTION 'ZSET_CUSTOM1'
IMPORTING
PI_RETURN = PE_RETURN
TABLES
PT_EXTENSIONIN = PI_EXTENSIONIN.
ENDMETHOD.
4. Fill EXTENSIONIN structure in function module BAPI_FTR_IRATE_DEALCREATE.
* "Define EXTENSIONIN structure which have BAPIPAREX type"
DATA: ZEXT TYPE STANDARD TABLE OF BAPIPAREX WITH HEADER LINE.
...
ZEXT-STRUCTURE = 'ZTRM_CUSTOM_FIELDS'.
* "Flat structure without any delimeters. Fields order just like in append structure"
CONCATENATE LT_FILE-ZZAUFNR LT_FILE-ZZGSBER LT_FILE-ZZBUKRS LT_FILE-ZZRFHA INTO ZEXT-VALUEPART1 RESPECTING BLANKS.
ZEXT-VALUEPART2 = '"'.
ZEXT-VALUEPART3 = ''".
ZEXT-VALUEPART4 = ''".
APPEND ZEXT.
...
CALL FUNCTION 'BAPI_FTR_IRATE_DEALCREATE'
EXPORTING
INTERESTRATEINSTRUMENT = ZINTERESTRATE
INTERESTRATEINSTRUMENTX = ZINTERESTRATEX
GENERALCONTRACTDATA = ZGENERAL
GENERALCONTRACTDATAX = ZGENERALX
CONDITION_COMPLETE_INDICATOR = P_COND
PAYDET_COMPLETE_INDICATOR = P_PAY
ADDFLOW_COMPLETE_INDICATOR = P_ADD
MAINFLOW_COMPLETE_INDICATOR = P_MAIN
TESTRUN = P_TEST
MIRRORING = ' '
IMPORTING
COMPANYCODE = BUKR
FINANCIALTRANSACTION = TRAN
TABLES
CONDITION = ZCOND
CONDITIONX = ZCONDX
FORMULAVARIABLE = ZFORMULA
SINGLEDATE = ZSINGLE
PAYMENTDETAIL = ZPAYDET
PAYMENTDETAILX = ZPAYDETX
ADDFLOW = ZADD
ADDFLOWX = ZADDX
MAINFLOW = ZMAIN
MAINFLOWX = ZMAINX
EXTENSIONIN = ZEXT "EXTENSIONIN structure"
RETURN = ZERR.
So, using function modules BAPI_FTR_*_DEALCREATE we:
- Use only single function module in order to create transaction.
- Can use TESRUN flag in order to test all structures and its data
- Can work with user-exit tab’s data
P.S. In attachment you can find file EXAMPLE.txt with example of programm which uploads data from files into SAP and creates Interest rate instrument. This is a demo and it has some bugs (read Known bugs), but never the less it is working quite good.
Read Prerequisites part in file.
Hi Grigoriy Babitskiy ,
Thanks for your post, it is quite useful, where can we find the file example you mean in your PS?
Regards,
Fernando
Hello Former Member,
It is not possible to upload file attachments in new blogs.
Check this link https://drive.google.com/file/d/0B6CvOxs6tAv7cmVBTk93Tnpqclk/view?usp=sharing
Thanks a lot for your response Grigoriy, do appreciate it
You are welcom!
I am just trying to find a single set of data to generate a variable interest operation generated same as we do in FTR_EDIT but I am stuck witht the parameters needed, do you need to pass all the internal tables? I did not think so, I thought cash flows, conditions etc were filled in return when BAPI was executed......
For BAPI_FTR_IRATE_DEALCREATE. i can use only 2 structures:
1. INTERESTRATEINSTRUMENT
2. GENERALCONTRACTDATA
That's all.
In order to find out what you need - you can create transaction, fill minimum fields and get transaction's parameters with FM BAPI_FTR_IRATE_DEALGET.
The you can check structures:
1. RETURNIRATE
2. RETURNGENERALCONTRACTDATA
Thanks much again
Hi Grigoriy,
Have you passed bcd packed numbers in your extensions? I am now stuck with this, the extensionin bapi parameter comes with char but when it tranforms to packed numer it turns into crappy numbers, so they are not charged fine in the VTBFHA table.....
Regards,
Fernando
Hi Grigoriy,
Great post, It made my customization much easier.
I am facing with a problem.....
The methods 'get/set_cust_data' are only triggered for events different to 'APPLICATION_START', but in FM 'set_custom1' I always have the event (A_EVENT) 'APPLICATION_START', so I always get the exception and I can't update the customized fields.
A_EVENT is a protected attribute for G_PROXY_CUST_DATA.
Did you face the same problem? How did you solve it?