Creating Custom Post-processing of the Output Payment File

Objective

After completing this lesson, you will be able to add Developer Extensibility of Outgoing Format Mappings

Developer Extensibility of Outgoing Format Mappings

To proceed, we will leverage the Developer Extensibility features available in SAP S/4HANA Cloud Public Edition. For detailed insights on Developer Extensibility, kindly refer to our Help Portal.

SAP S/4HANA Cloud Public Edition provides the enhancement spot ES_DMEEX. You can utilize the BAdI definition "DMEE_OUTPUT_POSTPROCESSING" to develop custom post-processing for the output payment file.

Common business scenarios include creating an envelope that encapsulates the file, computing a hash from the file content, or meeting unique requirements that the standard Map Format Data for Payment functionality doesn't cover.

To create a new BAdi Enhancement Spot, follow these steps:

  1. Open Eclipse with ADT plugin.
  2. File ⇒ New ⇒ ABAP Cloud Project.
  3. Provide ABAP Service Instance URL of your SAP S/4HANA Cloud Public Edition development tenant.
  4. Click Open Logon Page in Browser and proceed with the login as user with authorization for Developer Extensibility.
  5. Click Next and then Finish.

After setting up the project, search for ES_DMEEX in the hierarchy. Navigate to "Released Objects", then "USE_IN_CLOUD_DEVELOPMENT", followed by "Enhancements", and "Enhancements Spots". Here, you will find ES_DMEEX.

Right-click on the enhancement spot and select New BAdI Enhancement Implementation.

In the following dialog box, fill in the necessary details as indicated in the provided screenshot.

Click Next and choose your transport request. This will create a new BAdI Enhancement Implementation.

Click Add BAdI Implementation. In the following dialog, select the BAdI Definition "DMEE_OUTPUT_POSTPROCESSING", enter an appropriate name, and then click Add.

Click on the Implementing Class link. Choose your package and fill in the other attributes as shown. Then click Next and select your transport request.

Once the implementing class is successfully created, you will be automatically redirected to the code editor.

Copy and paste the following code into the modify_output method.

The code performs these actions:

  1. Converts the output table into a string.
  2. Calculates a hash.
  3. Creates an envelope.
  4. Converts the modified string back into an output table.
Code Snippet
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
DATA hash TYPE string. DATA(file_string) = cl_dmee_output_file=>to_string( output_mode = output_mode output_file_lines = output_file_lines string = string xml_document = xml_document ). " 2) Hash Generation TRY. cl_abap_message_digest=>calculate_hash_for_char( EXPORTING if_algorithm = 'SHA256' if_data = file_string IMPORTING ef_hashstring = hash ). TEST-SEAM hash_generation. END-TEST-SEAM. CATCH cx_abap_message_digest INTO DATA(cx). MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(dummy). APPEND CORRESPONDING #( sy ) TO log. ENDTRY. " removing byte order mark cl_dmee_output_file=>remove_bom( CHANGING file_string = file_string ). " removing XML header from file_string DATA(xml_header) = cl_dmee_output_file=>get_xml_header( file_string ). cl_dmee_output_file=>remove_xml_header( CHANGING file_string = file_string ). " 3) Adjusting of the XML file_string = xml_header && " add the removed header to the beginning of the file '<Envelope>' && '<Hash>' && hash && '</Hash>' && '<Payload>' && file_string && '</Payload>' && '</Envelope>'. " 4) Prepare the table content of the file cl_dmee_output_file=>to_file( EXPORTING file_string = file_string CHANGING output_file_lines = output_file_lines ).

To set up a filter for the BAdI implementation, return to the previous tab in Eclipse and click Add Filter Combination.

Enter PAYM as TREE_TYPE and /DEMO_PAYMENT_FORMAT as TREE_ID

Note

TREE_ID refers to the name of the format mapping in 'Map Format Data for Payments', not the payment format in 'Create Payment Medium Formats'.

Click Activate.

Log in to track your progress & complete quizzes