Sapass

 Simplify SAP R/3 development with Excel VBA/VB RFC  
Home> UserExit>FTXW0001



Index

FTXW0001

DART: Customer extensions
Filling customer defined fields Overview

If activated, this function exit is called for every record that is being exported to a data extract. The exit can be used to fill additional fields that are not part of the source table and to convert numeric fields to a character representation.

Adding fields

Every export structure is delivered with an empty customer include. For example, the FI document header structure TXW_FI_HD has customer include CI_FI_HD. To add fields, display the structure in the Data Dictionary and double-click the ".INCLUDE CI_FI_HD" entry. You are prompted to create table/structure CI_FI_HD. Click the "Structure" button and enter the desired fields. If you simply need additional fields from the corresponding BKPF source table, you must use the same field names as in BKPF. If the source field is numeric, the target field in the structure must have the same name, but must be of character type with a sufficient length. Activate the structure. You can ignore warnings that field names are not within the customer range.

If the fields you added are character fields and have the same name as in the source table, you are done. The added fields will be filled automatically, and no additional coding is required (technically, the export structure is filled with a MOVE-CORRESPONDING command).

You only need to create a function exit for fields that are not in the source table, and for numeric fields. Numeric fields need to be converted to a character representation. Numeric fields have one of the following data types:

Data type Description Example

CURR Currency value BSEG-DMBTR

QUAN Quantity value BSEG-ERFMG

DEC Decimal value BSEG-BLNPZ

FLTP Floating point value

INT1, INT2, INT4 Integer value

The data type is defined in the domain of a field (Data Dictionary). To convert numeric values to character representation, you can use subroutines that are delivered with the software; examples can be found in the SAP template for the function exit (see below).

Creating the function exit

Extension FTXW0001 consists of a function exit to fill fields of export structures. The extraction utility reads the source tables, moves each record to the corresponding export structure, calls the function exit, and then exports the record via the export structure to the data extract file.

Follow the instructions in the help documentation of this transaction (CMOD) to create the function exit and copy in a program template (SAP source code example).

Function exit interface

The function exit receives the name of the current export structure (parameter EXPORT_STRUCTURE) and the record that is to be exported (parameter EXPORT_RECORD).

The export record contains the field values from the source tables. The function exit can modify the record. The export record is passed by reference, so all changes made in the function exit are automatically known in the calling extraction utility.

Example: For the source table BSEG only those fields are filled that are also in the export structure TXW_FI_POS. You can access the BSEG work area directly in the function exit. The function exit must declare the required source tables with a TABLES statement.

The archive retrieval tables include the corresponding export structures by reference. This implies that customer added fields are automatically included in the archive retrieval tables. When the extraction utility reads from the archive retrieval tables, the resulting data records are moved to the work area of the corresponding source table. Example: Data records from the retrieval table TXW_S_BSEG are moved to the BSEG work area.

Example coding

The following example coding has been adapted from the SAP template. The following subroutines to convert numeric fields to character format are delivered with the software:

WRITE_CURRENCY convert currency values

WRITE_QUANTITY convert quantity values

WRITE_DECIMAL_VALUE convert decimal values

The conversion of currency and quantity values is based on the currency and quantity unit, respectively. The value plus the unit is passed to the conversion subroutine. The unit is often stored together with the value in the source table, but it can also be stored in master data. The coding below gives an example how a currency unit is read from master data in an efficient way (subroutine GET_CUNIT_ANEP_SAFAB; the coding for this subroutine must be in a separate include program ZXTXWZZZ).


*----------------------------------------------------------------------*
* INCLUDE ZXTXWU01 *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Example coding for function module EXIT_SAPLTXW2_001: *
* Fill customer fields in SAP structures *
*----------------------------------------------------------------------*

** Function exit interface:
** import: EXPORT_STRUCTURE - name of export structure
** changing: EXPORT_RECORD - data record
** in: all standard fields are filled and those customer
** fields that have the same name as a source table field
** out: in addition, customer fields are filled


* Table declarations (only list tables where fields are needed below).
* - Note that table work areas are global; the source table work areas
* are always filled from the calling program and can be used in
* this exit function.
* (declare here or, better, in global data; see CMOD help)

TABLES: BKPF, "source table for TXW_FI_HD
BSEG, "source table for TXW_HD_POS
ANEP. "source table for TXW_AS_POS

* work areas
DATA: WA_TXW_FI_HD LIKE TXW_FI_HD, "FI document header
WA_TXW_FI_POS LIKE TXW_FI_POS, "FI document position
WA_TXW_AS_POS LIKE TXW_AS_POS. "AM Asset document position

DATA: CURRENCY_UNIT LIKE TCURC-WAERS.


CASE EXPORT_STRUCTURE.

* add WHEN block for each structure where customer specific fields
* need to filled (to use FORM routines, see CMOD help)

WHEN 'TXW_FI_HD'. "FI document header
WA_TXW_FI_HD = EXPORT_RECORD. "copy record to local structure
* convert a decimal value to string:
BKPF-KURSF = WA_TXW_FI_HD-KURSF.
PERFORM WRITE_DECIMAL_VALUE
USING BKPF-KURSF "decimal value
WA_TXW_FI_HD-KURSF. "value converted to character
EXPORT_RECORD = WA_TXW_FI_HD. "copy structure back to record

WHEN 'TXW_FI_POS'. "FI document positon
WA_TXW_FI_POS = EXPORT_RECORD. "copy record to local structure
* convert quantity value to string:
BSEG-ERFMG = WA_TXW_FI_POS-ERFMG.
PERFORM WRITE_QUANTITY
USING BSEG-ERFMG "quantity amount
BSEG-ERFME "quantity unit
WA_TXW_FI_POS-ERFMG. "value converted to character
EXPORT_RECORD = WA_TXW_FI_POS. "copy structure back to record

WHEN 'TXW_AS_POS'. "AM Asset document position
WA_TXW_AS_POS = EXPORT_RECORD.
* get currency unit from master data
PERFORM GET_CUNIT_ANEP_SAFAB
USING WA_TXW_AS_POS-BUKRS
WA_TXW_AS_POS-AFABE
CHANGING CURRENCY_UNIT.
* convert currency value to string:
ANEP-SAFAB = WA_TXW_AS_POS-SAFAB.
PERFORM WRITE_CURRENCY
USING ANEP-SAFAB "currency value
CURRENCY_UNIT "currency unit
WA_TXW_AS_POS-SAFAB. "value converted to character
EXPORT_RECORD = WA_TXW_AS_POS. "copy structure back to record


ENDCASE.

....

*----------------------------------------------------------------------*
* INCLUDE ZXTXWZZZ *
*----------------------------------------------------------------------*

* DART: form routines for user exits
*&---------------------------------------------------------------------*
*& Form GET_CUNIT_ANEP_SAFAB
*&---------------------------------------------------------------------*
* get currency unit for ANEP-SAFAB *
*----------------------------------------------------------------------*
* --> P_BUKRS company code
* --> P_AFABE depreciation area
* <-- P_CUNIT currency unit
*----------------------------------------------------------------------*
FORM GET_CUNIT_ANEP_SAFAB
USING P_BUKRS LIKE TXW_AS_POS-BUKRS
P_AFABE LIKE TXW_AS_POS-AFABE
CHANGING P_CUNIT LIKE TCURC-WAERS.

TABLES: T093B.

* buffer table
STATICS: BEGIN OF BUF_T093B OCCURS 0,
BUKRS LIKE T093B-BUKRS,
AFABE LIKE T093B-AFABE,
WAERS LIKE T093B-WAERS,
END OF BUF_T093B.

* first check if information is in global table work area
IF T093B-BUKRS = P_BUKRS AND
T093B-AFABE = P_AFABE.
P_CUNIT = T093B-WAERS.
ELSE.
* read information from buffer
READ TABLE BUF_T093B BINARY SEARCH
WITH KEY BUKRS = P_BUKRS
AFABE = P_AFABE.
IF SY-SUBRC <> 0. "not found in buffer table
* insert to buffer table (sorted)
BUF_T093B-BUKRS = P_BUKRS.
BUF_T093B-AFABE = P_AFABE.
SELECT SINGLE WAERS FROM T093B INTO BUF_T093B-WAERS
WHERE BUKRS = P_BUKRS
AND AFABE = P_AFABE.
INSERT BUF_T093B INDEX SY-TABIX.

Function/Program:
  • EXIT_SAPLTXW2_001: Fill customer fields in SAP structures

02-Oct-2005