Skip to Content
Author's profile photo Richard Bailey

LSMW migration of SEPA Mandates


This is another blog to share my experiences on using LSMW for data migration. In a recent project there was a requirement to migrate SEPA mandates from an existing legacy system. This was achieved using two LSMW programs, in preference to creating and processing ABAP programs.

For some background on SEPA mandates I recommend that you read this document which includes useful information on the transactions and BAPIs that were used in LSMW.

I am assuming that you are already familiar with LSMW. If you are a beginner then there are plenty of other SCN posts that will help you.

Basic functional requirements

Since the mandates already existed in a legacy system an external mandate reference was used.

It is assumed that more than one mandate is allowed per customer (for example if the customer bank account changes).

When a mandate is added the collection authorization indicator should be flagged on the relevant bank account.

A customer may have more than one bank account.

It must be possible to distinguish between mandate first use and recurring.

Approach overview

Before migrating mandates, the customers including their bank account details are created.

The creation of the mandates is based on recordings of FSEPA_M1. If a customer has more than one bank account, then a pop-up appears. Therefore two recordings of FSEPA_M1 are required.

If the mandate is successfully created then the collection authorization indicator is updated using a recording of XD02.

The above 3 recordings are processed in a single LSMW program.

In a second step a dummy usage record is created for mandates that have already been used. This is achieved by using a dummy LSMW recording and a direct update using a BAPI function. This is explained below under “Details of add usage record”.

In both LSMWs various function modules are used.

Details of initial mandate creation

Most of the fields in a mandate are filled by default from the customer master and from the company code which is the vendor, so very little real input is needed.

In our project the following was sufficient:

Please note that you need to specify the BIC (SWIFT) code for the FSEPA_M1 recordings to work correctly.

As stated earlier, three recordings were used:

In the BEGIN_OF_TRANSACTION block we do the following:

1. Check that the customer already exists. In our example the legacy customer number was encoded in the mandate id.

2. Check if the mandate already exists:

* Customer exists, now check if the mandate already exists

* It is assumed that more than 1 mandate is allowed

h_sel_criteria-snd_type = ‘BUS3007’.

    h_sel_criteria-snd_id = h_kunnr.

    h_sel_criteria-anwnd = ‘F’.



        I_SEL_CRITERIA     = h_sel_criteria


        ET_MANDATES        = h_mandates

        E_MESSAGE          = h_emessage

        ET_MANDATES_FAILED = h_mandatesfail.

    if not h_mandates is initial.

      loop at h_mandates into wa_mandates.

        if wa_mandates-mndid = infile-mndid.

          write: /001 ‘Legacy Number:’,h_altkn,’SAP Customer:’,

                h_kunnr, ‘mandate already in SAP:’, wa_mandates-mndid.

g_skip_transaction = yes.




3. Check how many bank accounts the customer has. If there is more than 1 bank account then a pop-up appears in FSEPA_M1 so a separate recording will be used. You need to set a flag and then test this at the beginning of each FSEPA_M1 recording.

4. Determine which bank account in the customer master needs to be updated. If there is more than one, then the bank accounts in the table on the “payment transactions” tab are sorted by country, bank key, and bank account. Of course your input will be the IBAN!

* check which customer bank a/c matches the IBAN, if any

* load the bank accounts into an internal table and then search it

  refresh it_cbanks.


  into table it_cbanks

  from knbk where kunnr eq h_kunnr.

  if g_skip_transaction ne yes.

    if it_cbanks[] is initial.

      write: /001 ‘Customer:’,h_altkn,’SAP Customer:’,h_kunnr,

         ‘Mandate:’,infile-mndid, ‘Customer has no SAP bank accounts.’.

      g_skip_transaction = yes.

    else. “Locate the bank account to update

      w_found = ”.

      w_index = 0.

      LOOP AT it_cbanks INTO wa_cbanks.

        select single iban from tiban into h_iban

                where BANKS = wa_cbanks-BANKS

                 and  BANKL = wa_cbanks-BANKL

                 and  BANKN = wa_cbanks-BANKN

                 and  BKONT = wa_cbanks-BKONT.

        if sy-subrc eq 0 and h_iban = infile-SND_IBAN.

          w_index = sy-tabix.

          w_found = ‘X’.



      if w_found ne ‘X’.

        write: /001 ‘Customer:’,h_altkn,’SAP Customer:’,h_kunnr,


              ‘IBAN not available for this Customer in SAP.’.






The value of w_index determined in the code above is then used in the conversion rules of the XD02 recording for each collection authorization field in the recording. The screen shot just shows the first two:

Details of add usage record

After all of the mandates have been created a second LSMW is used to add a dummy usage record when the LASTUSEDATE in the input file is not empty. The same input file is used.

There isn’t a SAP transaction to add a dummy usage record so we need add it using a function module. We can process this through LSMW using a little trick.

We create a dummy recording. I made a recording of XD03 (display customer) and saved it as DUMMY. Since I won’t actually be using the recording, it doesn’t matter which transaction I use. In the “field mapping and conversion rules” the ABAP code is inserted to perform a direct update of the SAP table.

This means that when the LSMW program is used, you should only process up to the convert step.

It is also important that you carefully test your LSMW! In this case standard function modules are used so the danger of corrupting the SAP database is very low.

Below I have included the complete code used in our project. Please note the value of USE_DOCID where 0668 is a company code value.


data: h_mndid type sepa_mndid.

selection-screen: begin of block 1 with frame title title1.

selection-screen: begin of line, comment 1(31) para1, position 33.

PARAMETERS: p_year(4) type c OBLIGATORY default ‘2014’.

selection-screen: end of line.

selection-screen: begin of line, comment 1(31) para2, position 33.

PARAMETERS: p_test as checkbox.

selection-screen: end of line.

selection-screen: end of block 1.

at selection-screen output.

  title1 = ‘User processing parameters’.

  para1 = ‘Ref year for dummy usage document’.

  para2 = ‘Data validation only’.



if infile-status = ‘R’. “status revoked


   write: /001 ‘Mandate:’,infile-sepa_mndid,’Revoked mandate skipped’.

  1. else.


data: p_usage type SEPA_MANDATE_USE,

h_sel_criteria like SEPA_GET_CRITERIA_MANDATE,


wa_mandates LIKE LINE OF h_mandates,

h_emessage like BAPIRET1,

h_mandatesfail type SEPA_TAB_MANDATE_KEY_EXTERNAL,

h_usedate(8) type c.

if not infile-usedate is initial. “input is YYYY-MM-DD

  replace all occurrences of regex ‘[^0-9]’ in infile-usedate with ”.

concatenate infile-usedate+4(4)



            into infile-usedate.

*write: /001 ‘last used date:’,infile-usedate.

  h_usedate = infile-usedate.

* Get the GUID of the mandate

  h_sel_criteria-snd_type = ‘BUS3007’.

  h_sel_criteria-mndid = h_mndid.

  h_sel_criteria-anwnd = ‘F’.



      I_SEL_CRITERIA     = h_sel_criteria


      ET_MANDATES        = h_mandates

      E_MESSAGE          = h_emessage

      ET_MANDATES_FAILED = h_mandatesfail.

  if h_mandates is initial.

    write: /001 ‘Mandate:’,h_mndid,

          ‘not migrated to SAP’.


    read table h_mandates into wa_mandates index 1.

    p_usage-MANDT = ‘360’.

    p_usage-MGUID = wa_mandates-mguid.

    p_usage-USE_DATE = h_usedate.

    p_usage-USE_DOCTYPE = ‘BKPF’.

    concatenate ‘0668 9999999999 ‘ p_year into


      if p_test <> ‘X’.

        call function ‘SEPA_MANDATE_ADD_USAGE’


            i_usage = p_usage.

        commit work.


        write: /001 h_mndid,p_usage-MGUID,h_usedate,







With a few recordings and some standard function modules, it is possible to migrate SEPA mandates (including usage information) with LSMW.

This blog also gives an example of how to use a dummy recording and direct update in LSMW

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      The document number 9999999999 in the 'mandate use' is off course a dummy document number. You can freely choose it. Just take care that it is a non-existing document number in FI, so that a wrong drilldown is not possible. The number 9999999999 is the same number logic - for a dummy number - that is used in the migration of purchase orders which had already partial goods receipts and/or partial invoice receipts.



      Author's profile photo Former Member
      Former Member


      how can I use multiple records in one LSMW?

      What do you mean with BEGIN_OF_TRANSACTION block?



      Author's profile photo R. Bailey
      R. Bailey
      Blog Post Author

      Hi Sebastian,

      I guess you are relatively new to LSMW and, as explained in the intro, my blog post assumes you already know this sort of thing.

      I assume that you mean how to use multiple recordings and you can find that described in many places. For example:


      I also found a SCN blog post that describes the basics of LSMW including the process steps like BEGIN_OF_TRANSACTION

      If you need further info then I suggest your try using Google or the SCN search function!

      Author's profile photo Former Member
      Former Member

      Hi, Thanks four your explanations. Very helpful!

      One more question: Could you explain step 3 (If there is more than 1 bank account then a pop-up appears...) a bit further?

      When I create the recording there is no pop-up, it only shows up when I run the batch input....How can I create the recording so that I cover the pop-up? I have tried it with a customer with multiple bank accounts and IBANS...


      Author's profile photo R. Bailey
      R. Bailey
      Blog Post Author

      Sebastian, Difficult to say what your problem is. Maybe your system is customized differently. I just had a quick look in the system where I did the work and don't get the pop-up either any more! There can be differences between how batch input and the real transaction work but normally if you are getting the pop-up for a customer in batch input then you should get the pop-up when you try to create a mandate for the same customer directly. If you can't work out what is happening in your system then I suggest you ask a colleague on your project for help.