Quantcast
Channel: SCN : Blog List - All Communities
Viewing all articles
Browse latest Browse all 2548

Is is possible to enter data in custom fields while creating transaction using Function modules?

$
0
0

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.

01.jpg

 

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:

  1. Many business objects with functioin modules in order to create Interest rate instrument transaction.
  2. No business objects in order to fill our User-exit tab's fields.
  3. 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.
  4. 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 moduleDescription
BAPI_FTR_IRATE_DEALCREATECompletely Create an Interest Rate Instrument
BAPI_FTR_FTD_DEALCREATECreate a Fixed Term Deposit Completely
BAPI_FTR_SECURITY_DEALCREATECompletely Create a Security Transaction
BAPI_FTR_FXT_DEALCREATECompletely Create a Forex Transaction
BAPI_FTR_FST_DEALCREATECompletely Create a Forward Security
BAPI_FTR_COMS_COND_DEALCREATECompletely Create a Commodity Swap
BAPI_FTR_COMS_DEALCREATECompletely Create a Commodity Swap
BAPI_FTR_CTYFWD_DEALCREATECompletely Create a Forex Transaction
BAPI_FTR_FLP_DEALCREATECompletely Create a Forward Loan
BAPI_FTR_REPO_DEALCREATECompletely Create a Repo
BAPI_FTR_TRES_DEALCREATECompletely 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:

  1. badi FTR_CUSTOMER_EXTENT in order to create user-exit tabs and fields. Article
  2. 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)
  3. badi FTR_CUSTOMER_EXTENT, methods:
    1. EVT_BAPI_SET_CUSTOM1 - set new parameters at user-exit tab 1
    2. EVT_BAPI_SET_CUSTOM2 - set new parameters at user-exit tab 2
    3. EVT_BAPI_GET_CUSTOM1 - read parameters from user-exit tab 1 in BAPI_FTR_*_DEALGET function module
    4. EVT_BAPI_GET_CUSTOM2 - read parameters from user-exit tab 2 in BAPI_FTR_*_DEALGET function module
  4. 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.

02.jpg

 

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:

  1. Use only single function module in order to create transaction.
  2. Can use TESRUN flag in order to test all structures and its data
  3. 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.


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>