S4HCKS43 – Generating a check digit on your invoice

A check digit to secure BPay payments

It may sometimes be necessary to add information to a document that is made up of other pieces of information (concatenate fields, truncate fields, transform fields, etc…) – that is, information that does not readily exist in your system (like a customer number for example), but can be generated or deduced.

In this snippet we look at how you can add some custom logic in your SAP S/4HANA Cloud system to generate a check digit to a BPay CRN (Customer Reference Number). That is, we want to offer our customer the BPay payment method and for that we have to add to the invoice a CRN number, that will be made of the billing document number appended by a check digit that we will generate on the fly in S/4.

The custom logic to generate the check digit

You will below find the custom logic that I used to generate this check digit (Disclaimer : my code is probably dirty – but it works). I am not checking the length of the billing document number – I have made the assumption that the billing number will always be 8 digits long.

I have also added a screenshot that shows how my custom ‘CheckDigit’ field was defined (Numerical – 1 digit).

* Logic to determine a check digit for a BPay 8 digit CRN number

DATA:
Counter       TYPE i,
lv_billdigit  TYPE i,
lv_total      TYPE i,
lv_billingdoc TYPE string,
lv_chardigit  TYPE string.

Counter = 0.
lv_billingdoc = billingdoc-billingdocument.
SHIFT lv_billingdoc LEFT DELETING LEADING '0'.

While Counter < 8.

   IF ( Counter MOD 2 = 0 ).
      lv_billdigit = lv_billingdoc+Counter(1) * 1 .
   ELSE.
      lv_billdigit = lv_billingdoc+Counter(1) * 2 .
   ENDIF.


   IF ( lv_billdigit > 9 ).
      lv_chardigit = lv_billdigit.
      lv_billdigit = ( lv_chardigit+0(1) ) + ( lv_chardigit+1(1) ).
   ENDIF.


   lv_total = lv_total + lv_billdigit.
   Counter = Counter + 1.
ENDWHILE.


IF ( lv_total MOD 10 = 0 ).
   billingdoc_extension_out-yy1_checkdigit_bdh = 0.
ELSE.
    billingdoc_extension_out-yy1_checkdigit_bdh = 10 - ( lv_total MOD 10 ).
ENDIF.

Video: Generate a - BPay - check digit on your invoices

BPay check tool for Excel

In case you are interested to have it, I am also adding the Excel file that I used to double check the check digit generation. The CRN numbers in the file and check digits were generated on the BPay generator web page. You can download the excel by clicking the icon below.


S4HCKS41 - Execute Capacity Levelling in SAP S/4HANA Cloud

In this snippet we show you how to level your production capacity, to avoid bottleneck situations or if you want to plan your manufacturing operations on the basis of cadence setting work centers.

Importantly, make sure you check out the following links:


S4HCKS40 - Create MRP Areas from Excel by leveraging API's

In this snippet we re-visit a previously released snippet : S4HCKS23 Mass Processing Product Master changes in SAP S/4HANA Cloud, but this time leveraging an API that is called from the comfort of MS Excel.

The underlying objective of this snippet, is to show how easy it is to leverage our API’s from third party applications, not just in Read mode, but also in Create/Update Modes. In this snippet we show you how you can supplement your Product Masters with MRP Areas, but this coud apply to any other of the available API’s.

As indicated in the recording, I am providing the excel used in the recording, for you to try out and get some inspiration from. As a disclaimer : You can use it at your own risk – I take no responsibility for you using it. I encourage to first try it in your Q system, with a small dataset. I also remind you not to pass this file to others with either data and / or login credentials !

Some of the important links covered in the recording are:

I must also give credit to Philip Hoffmann, who’s blog provided the file that I have also used to kick start this project. Phillip’s blog also covers how to create a communication user.

I encourage you to read the ‘Read Me First’ tab to get some valuable information, but if you want to just dive right in after you have created your communication user, then you just need to maintain the data you want to upload (MRP_RECORDS tab) and the login credentials as shown below (in the EXEC_DATA tab)

You can download my MRP Areas Excel API file below, by clicking the Excel File icon.