Overview
ABAP Code can be added in a Mapping Project and will be included in an LSMW Project File.
MDA Workbench is certainly not the place to write ABAP code. However, if ABAP code is added to an LSMW project then the ABAP can be incorporated into the Mapping Project so that LSMW projects can be subsequently created automatically, including the incorporated ABAP code.
Moreover, MDA Workbench makes it easy to implement small bits of ABAP common functionality without writing ABAP Code, or makes it easier to implement ABAP Code though the use of Keyword Substitution.
- ABAP Code can be maintained in the IDoc Reference with the following Validity Areas:
- __GLOBAL_DATA__
- __BEGIN_OF_PROCESSING__
- __BEGIN_OF_TRANSACTION__
- __BEGIN_OF_RECORD__ for each Segment
- __END_OF_RECORD__ for each Segment
- __END_OF_TRANSACTION__
- __END_OF_PROCESSING__
- __FORM_ROUTINES__
- ABAP Code at field level can be used with an Active field (not just LSMW Active) and with LSMW Rule: Transfer.
- There are times when full manual intervention (i.e. ABAP Code) is required for a field, but you want that field to be included in a Staging Table so that the value is available for ABAP processing.
- When using LSMW Rule: ABAP Code then the option for LSMW Not Initial is not relevant.
- If this were not the case, then ABAP Code could not be used to set default values for a mapped Segment-Field (e.g. ABAP Code with logic that says ... if a value is not provided in the Load-Ready file then use value X).
-
Keyword Substitution works for ABAP Code maintained in LSMW Value or in the IDoc Reference.
- @FIELD is replaced with the SEGMENT-FIELD name of the field in which the ABAP is written. @FIELD refers to the field in the IDoc.
- @DATE is replaced with the system date (SYST-DATUM)
- @TIME is replaced with the system time (SYST-UZEIT)
- @LANGU is replaced with the user's logon language (SYST-LANGU)
- @LANGUAGE is replaced with the user's logon language (SYST-LANGU)
- @USER is replaced with the SAP User ID of the user (SYST-UNAME)
- @NAME is replaced with the SAP User ID of the user (SYST-UNAME)
- @INDEX is replaced with a numeric counter value that is increased for each segment (SYST-TABIX)
- @COUNTER is replaced with a numeric counter value that is increased for each segment (SYST-TABIX)
- Some IDocs (e.g. ASSORTMENT) require a sequential counter field to be populated.
- For such a field, populate its LSMW Value with: @FIELD = @COUNTER.
- [[SEGMENT-FIELD]] (i.e. segment field name in the mapping project, including the double square brackets) is replaced with SOURCE_STRUCTURE-FIELD of the Load-Ready file and considers renamed fields. It refers to the value from the Source Structure (i.e. the value from the Load-Ready file).
- This is valuable because the ABAP Code can be maintained and not updated even as segments move from one Source Structure to another (i.e. as the Merge indicator of Segments are changed).
- LSMW Rule: Move With LSMW Value If Initial
- In an update scenario, some IDoc (especially DEBMAS for Customer and CREMAS for Vendor) have fields that should be supplied a value of a slash character ( / ) if the Load-Ready file for that field does not contain a value.
- This is not the same as using a Constant value. When using a Constant value, the Constant value is always supplied to the IDoc. With this new LSMW Rule: Move With LSMW Value If Initial, the LSMW Value is only supplied to the IDoc field if the Load-Ready file for that field is empty.
- Against all Best Practices (Transformation belongs in the Staging Database, not in LSMW!) this LSMW Rule could be used to provide default values for any mapped Segment-Field when a value is not supplied by the Load-Ready file.
- Keyword Substitution works in the LSMW Value when using this LSMW Rule.
- e.g. to supply the system date as a default value, maintain @DATE as the LSMW Value.