INTERNAL - Authorized for Partners
Exercise 3 – Migrate Custom Code from S/4HANA
S/4HANA Cloud Developer Extensibility bootcamp
TABLE OF CONTENTS
INTRODUCTION ............................................................................................................................................... 3
Exercise scope ................................................................................................................................................. 3
Prerequisites .................................................................................................................................................... 3
STEP 1 – CREATE AND CHECK AND MODIFY DEVELOPMENT OBJECTS .............................................. 4
Step 1.1 – Create Custom ABAP Class ......................................................................................................... 4
Step 1.2 – Run ABAP Test Cockpit and modify your code ......................................................................... 8
Step 2 – Export Code to S/4HANA Cloud .................................................................................................... 12
2
INTRODUCTION
This Hands-On workshop will guide you to enhance existing custom code on SAP S/4HANA on premise to
be ready for SAP S/4HANA Cloud.
Custom Code which has been developed on SAP S/4HANA on premise shall be made cloud ready to
support a migration from on premise to an SAP S/4HANA Cloud solution.
With the Cloud Readiness-Check on SAP S/4HANA we have the possibility to check existing code and make
it ready to run also with SAP S/4HANA Cloud Developer Extensibility.
In this tutorial, wherever XXX appears, use a number (e.g. D01).
Exercise scope
In this exercise you will create a class with custom code, programmed in a classic style of SAP ECC
programming. Afterwards you will check the code with the respective ATC check and correct it using only
APIs which are available on S/4HANA Cloud.
Prerequisites
Make sure that you have a developer user in the S/4HANA and S/4HANA Cloud systems with necessary
authorizations.
You have installed SAP ABAP Development Tools (ADT), version 3.16 or later, and have created an ABAP
Cloud project for your SAP S/4HANA Cloud System in it.
Hints and Tips
Speed up the typing by making use of the Code Completion feature (shortcut: Ctrl+Space) or the prepared
Code Snippets mentioned in the next section. You can easily open an object with the shortcut Ctrl+Shift+A.
In this hands-on workshop, you will go through the following steps. You can open transactions in the on-
premise systems with ADT using shortcut Alt+F8
3
STEP 1 – CREATE AND CHECK AND MODIFY DEVELOPMENT OBJECTS
Step 1.1 – Create Custom ABAP Class
Description Screenshot
Login to the S/4HANA system S4H with the
provided username and password from your
cheat sheet.
To do this open Eclipse using the icon in the
Remote Desktop.
Create a new workspace and make sure
you use your user folder.
If the folder doesn’t already exist, create a
new one.
Example:
C:\Users\STUDENT<XXX>\eclipse-
workspace
where <XXX> is your ID (e.g. D01).
Open the ABAP Perspective by clicking the
“Open Perspective” icon on the top right and
then selecting “ABAP” and finally pressing
“Open”.
4
Click on Create new ABAP project.
You can do this from File >> New >> ABAP
Project.
Click on “new system connection”.
Select the option “Custom Application
Server” and provide the data as per your
cheat sheet.
Please provide system ID (S4H), Application
Server and Instance Number.
Disable the SNC communication since this
will be internal.
5
Specify your user and password from the
cheat sheet.
Navigate to Package
ZDEMO_MIGRATE_CODE and choose
“New” > “ABAP Package” to create your
own package
On the following dialog use
• Name:
ZDEMO_MIGRATE_CODE_XXX
• Description: S4HANA Code
Migration to Cloud XXX
Make sure the right super-package is
selected.
Click “Next”
On the following dialog click “Next”
6
Select the transport request you have been
assigned to or create a new transport
request if one does not exist already.
Click “Finish” to write changes on the
respective transport
Right-Click on the newly created Package
and select “New” > “ABAP Class”
On the following dialog use
• Name:
ZCL_MATERIAL_INFORMATION_
XXX
• Description: Material Information
Demo Class XXX
“Project” and “Package” should be already
filled in with values.
Click “Next”
7
Select the transport request you have been
assigned to and click “Finish”
When the source code editor opens paste CLASS zcl_material_information_XXX DEFINITION
the following code. PUBLIC
FINAL
This code is using APIs which are not
CREATE PUBLIC .
available on S/4HANA Public Cloud.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS get_material_art
IMPORTING
matnr TYPE matnr
RETURNING
VALUE(material_art) TYPE mtart.
ENDCLASS.
CLASS zcl_material_information_XXX IMPLEMENTATION.
METHOD get_material_art.
DATA material TYPE mara.
DATA production_date TYPE datn.
DATA bool_tmp TYPE boole_d.
production_date = sy-datum.
SELECT SINGLE mtart FROM mara INTO CORRESPONDING
FIELDS OF material WHERE matnr = matnr.
MOVE material-mtart TO material_art.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA material_info TYPE REF TO
zcl_material_information_000.
material_info = NEW zcl_material_information_000( ).
DATA(material_art) = material_info->get_material_art(
'RM34' ).
out->write( material_art ).
ENDMETHOD.
ENDCLASS.
Step 1.2 – Run ABAP Test Cockpit and modify your code
8
Description Screenshot
Select the newly created class and choose
“Run as” > “4 ABAP Test Cockpit With…”
from the context menu
Insert Check variant
“ABAP_CLOUD_READINESS”
Press “OK”
This ATC check variant tests for released
APIs and ABAP language version 5 (ABAP
for Cloud development)
The Tab “ATC Problems” shows syntax
errors for statements which are not
available for ABAP language version 5 and
the use of non-released APIs.
The SELECT and MOVE statements are
not compliant with ABAP language version
5.
The types “MARA” and “MTART” are not
released.
Check the ABAP for cloud development
documentation to make yourself familiar
with the syntax. The MOVE-Statement is
not allowed in ABAP for Cloud
development. Select the respective lines
and from the context menu choose
“Recommended Quick Fixes”.
9
To examine the Quick Fixes proposals click
“Next”
Click “Next” to confirm the transport
request and affected objects.
Review and agree to the Quick Fix
proposals (press “Finish” button)
Look up in the SAP Note 3088062 the
GitHub repository with information around
the successor API. The latest object
release information from the repository at
the time of training could be used. For
access to the MARA table (search for
MARA → Successor is I_PRODUCT)
10
Replace the occurrences of MARA with
I_PRODUCT and the corresponding data
elements:
• mtart → i_product-
producttype
• matnr → i_product-
producttype- product
The result code should look like this: CLASS zcl_material_information_xxx DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS get_material_art
IMPORTING
matnr TYPE i_product-
product
RETURNING
VALUE(material_art) TYPE i_product-
producttype.
ENDCLASS.
CLASS zcl_material_information_xxx
IMPLEMENTATION.
METHOD get_material_art.
DATA material TYPE i_product.
DATA production_date TYPE datn.
DATA bool_tmp TYPE boole_d.
production_date = sy-datum.
SELECT SINGLE FROM i_product FIELDS
producttype WHERE product = @matnr INTO
CORRESPONDING FIELDS OF @material .
material_art = material-producttype.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA material_info TYPE REF TO
zcl_material_information_xxx.
material_info = NEW
zcl_material_information_xxx( ).
DATA(material_art) = material_info-
>get_material_art( 'RM34' ).
out->write( material_art ).
ENDMETHOD.
ENDCLASS.
11
Run ATC with Check variant
ABAP_CLOUD_READINESS again.
The ATC run should finish with no findings.
Please find both initial and migrated
version
(ZCL_MATERIAL_INFORMATION_XXX_5)
of the source code in package
ZDEMO_MIGRATE_CODE_XXX
Step 2 – Optional: Export Code to S/4HANA Cloud
Step 2.1 – Export code from the on-premise system to an online git repository
You can now export your coding using abapGit. This might be useful to a) get to know abapGit and b) have
the example coding stored for later exploration.
Prerequisites:
- You have a git repository (e.g. on github.com) prepared and available. If not you can register a new
account from HERE. Make sure you have a personal access token with sufficient authorizations
created under developer settings of GitHub.
- You have abapGit installed on your S/4HANA on-premise System. This is already done for our
workshop.
- You have abapGit plugin integrated in your ABAP Development Tools installation. This is already
installed in our system.
Description Screenshot
Open Report ZABAPGIT_STANDALONE in
transaction SE38. Press Alt+F8 to run the
transaction
12
Description Screenshot
On the entry screen (Repository List) click
on “New Online”.
Before you push changes to your online
repository make sure to have at least one
file in your repository, e.g. a README.md
file.
Create a new Online Repository with the
data from your formerly created git
repository (e.g. on github.com, see
prerequisites) and the in step 1 created
package
• Git Repository URL: <your-
repository-url>
• Package:
“ZDEMO_MIGRATE_CODE_XXX”
• Display Name “Code Migration to
Cloud XXX”
Click “Create Online Repo”
Click “Stage”.
Click on “Add All and Commit”.
13
Description Screenshot
Input a comment such as “Migrated Code
to Cloud” as well as your username for the
git repository and your E-mail address and
press “Commit”.
You will be prompted with a credentials
popup. Enter your git repository server
credentials and click the Execute button.
Verify your code was committed by
checking the status message “Commit was
successful”.
14
Step 2.1 – Import code from git repository to S/4HANA Cloud
Description Screenshot
Create New package on your S/4HANA
Cloud system where you can import the
code from the git repository.
To achieve this choose New → ABAP
Package within the
ZDEMO_MIGRATE_CODE package
Create the new package with
• Name:
“ZDEMO_MIGRATE_CODE_XXX”
• Description: “Migrated Demo
Code XXX”
And click “Next”
On the following screen click “Next”
15
Description Screenshot
Select the transport request you have been
assigned to and click “Finish”
If needed:
Add abapGit-View to ADT
Choose Window → Show View → Other
Choose abapGit Staging and abapGit
Repositories
16
Description Screenshot
Add your Repository in view “abapGit
Repositories”.
Click the “+” sign on the abapGit
Repositories Tab and enter the link of your
repository in the dialog.
Enter valid authentication mechanism, e.g.
user & password or user & token
17
Description Screenshot
If you are prompted to use secure storage
make your choice to open the next screen.
Choose your package
(ZDEMO_MIGRATE_CODE_XXX) and
make sure to activate the “Pull after link”
check box.
Click “Next”
Click “Finish”
18
Description Screenshot
Select the newly created package and click
“Finish”
On the newly created package choose
“Refresh” from the context menu to show
the pulled code.
Now you should be able to locate the
imported code and see the linked
repository in the abapGit Repositories tab.
19
www.sap.com/contactsap
© 2022 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable
for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality
mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or platform directions and functionality are
all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation
to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are
cautioned not to place undue reliance on these forward-looking statements, and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other
countries. All other product and service names mentioned are the trademarks of their respective companies. See www.sap.com/trademark for additional trademark information and notices.