Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Introduction

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'.

    CALL FUNCTION 'SEPA_MANDATES_API_GET'

      EXPORTING

        I_SEL_CRITERIA     = h_sel_criteria

      IMPORTING

        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.

        endif.

      endloop.

    endif.

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.

  select KUNNR BANKS BANKL BANKN BKONT

  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'.

        endif.

      ENDLOOP.

      if w_found ne 'X'.

        write: /001 'Customer:',h_altkn,'SAP Customer:',h_kunnr,

              'IBAN:',infile-snd_iban,

              'IBAN not available for this Customer in SAP.'.

        skip_transaction.

      endif.

    endif.

  endif.

        endif.

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.

* __GLOBAL_DATA__

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'.

start-of-selection.

* __BEGIN_OF_TRANSACTION__

if infile-status = 'R'. "status revoked

skip_transaction.

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

  1. else.

tables: SEPA_MANDATE.

data: p_usage type SEPA_MANDATE_USE,

h_sel_criteria like SEPA_GET_CRITERIA_MANDATE,

h_mandates type SEPA_TAB_DATA_MANDATE_DATA,

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)

            infile-usedate+2(2)

            infile-usedate+0(2)

            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'.

  CALL FUNCTION 'SEPA_MANDATES_API_GET'

    EXPORTING

      I_SEL_CRITERIA     = h_sel_criteria

    IMPORTING

      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'.

  else.

    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

      p_usage-USE_DOCID.

      if p_test <> 'X'.

        call function 'SEPA_MANDATE_ADD_USAGE'

          EXPORTING

            i_usage = p_usage.

        commit work.

      else.

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

        p_usage-USE_DOCID.

      endif.

    endif.

  endif.

endif.

Conclusion

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

5 Comments
Labels in this area