SAP4TECH

SAP and ABAP Free Tutorials
Menu
  • SAP Technical
    • ABAP Code Snippets
    • ABAP WebDynPro
    • SAP GW
    • SAP IDOC (ALE)
    • SAP PI (XI)
    • SAP Screen Personas
    • SAP Workflow
  • SAP Functional
    • SAP FI
    • SAP FSCM
    • SAP HR
    • SAP SD & SAP MM
    • SAP PM
    • SAP PP
    • SAP PS
    • SAP QM
    • SAP VIM
    • SAP WM
  • SAP Fiori
  • SAP HANA
  • SAP BW
  • SAP CRM
  • SAP SRM
  • SAP4TECH
    • About Us
    • Contact Us
    • Terms & Conditions
    • Privacy and Cookie Policy

SAP4TECH » Add Leading Zero ABAP – Zeros Padding in SAP

ABAP Tutorials

Add Leading Zero ABAP – Zeros Padding in SAP

December 18, 2015 John

Add Leading Zero ABAP is a common requirement in the daily task of ABAP developer.

How to handle leading and padding zeros for SAP Data and variables in SAP using ABAP with common case of SAP Material Number

Check also Conversion ABAP: between Binary, String, XString and Table

Table of Contents

  • Add Leading Zero ABAP
  • SAP Material Add Leading Zeros ABAP
  • Add Leading Zeros in ABAP
    • ABAP Unpack Statement
    • ABAP Default Casting Or Write
    • Other Zeros Padding Alternative in ABAP

Add Leading Zero ABAP

In order to add zeros in ABAP, in general use the standard function CONVERSION_EXIT_ALPHA_INPUT.

This function will add the leading zeros until filling the length with the output. It will check the Data Type and domain in order to calculate how many zeros will be added.

Add Leading Zero ABAP - Zeros Padding in SAP

SAP Material Add Leading Zeros ABAP

For Material, I recommend using another function:CONVERSION_EXIT_MATN1_INPUT

In one project I have been working on, in some systems, SAP Material Numbers are stored in SAP Material Master data with leading zeros and for some others systems, the SAP Material Number is handled without leading zeros in SAP.

ABAP
1
2
3
4
5
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    INPUT  = WA_MATNR
  IMPORTING
    OUTPUT = WA_MATNR.

In the opposite, to remove the Zeros in SAP Material Number use rather CONVERSION_EXIT_MATN1_OUTPUT.

These both Conversion routines are set in MATNR domain.

Check also the Main Important SAP Material Master Tables (Data & Customizing).

Add Leading Zeros in ABAP

There are some other ways to add the zeros in ABAP Variable.

ABAP Unpack Statement

ABAP Statement Unpack is the easiest way to deal with zeros padding in ABAP.

It can be a serious alternative for the conversion_exit_alpha_input.

ABAP
1
2
3
4
DATA : input(16),
output(6) TYPE c VALUE '123456'.
unpack output to input.
write /: v1 , v2

Read also SAP Alternative Unit of Measure for Material.

ABAP Default Casting Or Write

ABAP can handle formatting SAP variables when copying variables. It will add the leading zeros for example if you copy a string variable containing a number to an integer.

The Integer variable will have the needed zeros.

ABAP
1
2
3
4
5
Data: Lv_Char(10) type c value '12345'.
Data: lv_num(10) type n.
 
lv_num = lv_char.
" lv_num = '0000012345'

Other Zeros Padding Alternative in ABAP

The ABAP WRITE statement has multiple functionalities within the formatting tools.

  • To Add zeros: WRITE lv_variable USING EDIT MASK ‘==ALPHA’.
  • To Remove zeros: WRITE lv_variable no NO-ZERO.

For more complete ABAP Tutorials check the following book Mastering SAP ABAP: A complete guide to developing fast, durable, and maintainable ABAP programs in SAP

Prev Article
Next Article

Related Articles

SAP EDI
EDI in SAP: this post is an overview of SAP …

EDI in SAP ( Electronic Data Interchange )

domino 163522 1280 e1442441105680
Update Contacts of Customer: One of recurrent business requirement in …

The 3 ways to Mass Update Contacts of Customer in SAP

Search on SAP4TECH

The Most Populars

  • The Most Important SAP ISU Tables
    The Most Important SAP ISU Tables
  • SAP Users Tables
    SAP Users Tables (for Personal, Logon, and Address Data)
  • List of SAP Purchase Order Tables in SAP MM SAP PO Tables
    SAP Purchase Order Tables: Main PO tables in SAP MM – SAP PO Tables
  • Full list of SAP Movement Types
    SAP Good Movement Types – Full list of SAP Movement Types
  • The Main SAP GL Account Tcodes SAP GL Account Tables
    The Main SAP G/L Account Tcodes & SAP GL Account Tables
  • SAP BOM Tables
    SAP BOM Tables for BOM Header, Items and components and Category

Related Posts

  • JSON and ABAP
    List of The most important JSON ABAP Classes in SAP
  • Calculate Due Date1 e1452811957210
    Calculate Due Date in ABAP (BAPI DETERMINE_DUE_DATE)
  • handle PopUp in ABAP
    ABAP PopUp: Types and Samples codes
  • binary 1332816 1920 e1492679732848
    How to Trigger IDOC immediately when SAP PO is created or updated ?
  • List of WorkItems for a User
    How to retrieve List of WorkItems for a user ?

SAP4TECH

SAP and ABAP Free Tutorials

Trending Posts

  • The Most Important SAP ISU Tables
  • SAP Users Tables (for Personal, Logon, and Address Data)
  • SAP Purchase Order Tables: Main PO tables in SAP MM – SAP PO Tables
  • SAP Good Movement Types – Full list of SAP Movement Types
  • The Main SAP G/L Account Tcodes & SAP GL Account Tables
  • SAP BOM Tables for BOM Header, Items and components and Category

The Most Recents

  • The Most Important SAP ISU Tables
  • SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd Lecture
  • The Main SAP Dunning Transaction Codes
  • SAP Accounts Payable Tcodes & Accounts Receivable Tcodes ( SAP AP Tcodes & SAP AR Tcodes)
  • The Most Important SAP Payment Terms Tables (ZTERM, Text…)

Search

SAP Tutorials by Topics

  • SAP Tables
  • SAP Tcodes
  • SAP BAPI
  • ABAP Snippets
  • Top SAP Courses
  • Top SAP Books
Copyright © 2021 SAP4TECH

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
This website uses cookies to improve your experience. We'll assume you accept this policy as long as you are using this websiteAcceptView Policy