[ABAP] string-Formatierungen mit String-Templates

* ab V7.31
* http://zevolving.com/2013/07/abap-string-templates-new-feature-in-abap-731/

* Hinweis: String-Templates funktionieren nur Programmen bei denen die Unicodeprüfung aktiv ist!
* Z.B. kommt es in Modulpool-Programmen zu Fehlern beim kompilieren des Codes und der Compiler moniert die '|'-Symbole

DATA: text TYPE string VALUE 'Text'.
DATA: atext TYPE string VALUE '012345'.
DATA: num TYPE p DECIMALS 3 VALUE '-123.45'.

* Case
WRITE: / |RAW:   { text CASE = RAW }|.   " Text
WRITE: / |LOWER: { text CASE = LOWER }|. " text
WRITE: / |UPPER: { text CASE = UPPER }|. " TEXT

* Align
WRITE: / |LEFT:   ->{ text WIDTH = 20 ALIGN = LEFT }<--|.   " >Text                <
WRITE: / |RIGHT:  ->{ text WIDTH = 20 ALIGN = RIGHT }<--|.  " >                Text<
WRITE: / |CENTER: ->{ text WIDTH = 20 ALIGN = CENTER }<--|. " >        Text        <

* Padding, Auffüllen mit definiertem Zeichen
WRITE: / |PAD: { text ALIGN = LEFT WIDTH = 20 PAD = '_' }|.   " Text________________
WRITE: / |PAD: { text ALIGN = RIGHT WIDTH = 20 PAD = '_' }|.  " ________________Text
WRITE: / |PAD: { text ALIGN = CENTER WIDTH = 20 PAD = '_' }|. " ________Text________

* führende Nullen hinzufügen, ersetzt FUBA 'CONVERSION_EXIT_ALPHA_INPUT'
WRITE: / |ALPHA: { atext WIDTH = 20 ALPHA = IN }|. " 00000000000000012345
* führende Nullen entfernen, ersetzt FUBA 'CONVERSION_EXIT_ALPHA_OUTPUT'
WRITE: / |ALPHA: { atext ALPHA = OUT }|.           " 12345

* Zahlen 1
WRITE: / |RAW:         { num NUMBER = RAW }|.         " -123.45
WRITE: / |USER:        { num NUMBER = USER }|.        " -123,45
WRITE: / |ENVIRONMENT: { num NUMBER = ENVIRONMENT }|. " -123,45

* Zahlen 2
WRITE: / |SCIENTIFIC:                   { num STYLE = SCIENTIFIC }|.                   " -1.2345E+02
WRITE: / |SCIENTIFIC_WITH_LEADING_ZERO: { num STYLE = SCIENTIFIC_WITH_LEADING_ZERO }|. " -0.12345E+03
WRITE: / |SCALE_PRESERVING_SCIENTIFIC:  { num STYLE = SCALE_PRESERVING_SCIENTIFIC }|.  " -1.2345E+0002
WRITE: / |ENGINEERING:                  { num STYLE = ENGINEERING }|.                  " -123.45E+00

* Datumsformat
WRITE: / |RAW:         { sy-datum DATE = RAW }|.         " 20160705
WRITE: / |ISO:         { sy-datum DATE = ISO }|.         " 2016-07-05
WRITE: / |USER:        { sy-datum DATE = USER }|.        " 05.07.2016
WRITE: / |ENVIRONMENT: { sy-datum DATE = ENVIRONMENT }|. " 05.07.2016

* Uhrzeitformat
WRITE: / |RAW:         { sy-uzeit TIME = RAW }|.         " 102336
WRITE: / |ISO:         { sy-uzeit TIME = ISO }|.         " 10:23:36
WRITE: / |USER:        { sy-uzeit TIME = USER }|.        " 10:23:36
WRITE: / |ENVIRONMENT: { sy-uzeit TIME = ENVIRONMENT }|. " 10:23:36

* Timestampformat
DATA: lv_tsl TYPE timestampl.
* Zeitstempel lang
GET TIME STAMP FIELD lv_tsl.
WRITE: / |SPACE:       { lv_tsl TIMESTAMP = SPACE }|.       " 2016-07-05 08:23:36.0908600
WRITE: / |ISO:         { lv_tsl TIMESTAMP = ISO }|.         " 2016-07-05T08:23:36,0908600
WRITE: / |USER:        { lv_tsl TIMESTAMP = USER }|.        " 05.07.2016 08:23:36,0908600
WRITE: / |ENVIRONMENT: { lv_tsl TIMESTAMP = ENVIRONMENT }|. " 05.07.2016 08:23:36,0908600

* ABAP Serialization XML (axXML)
WRITE: / |XML: { lv_tsl XSD = YES }|. " 20160705082336.09086

Informationen über das akt. verwendete .NET-Framework abfragen

using System;
using System.IO;
using Microsoft.Win32;

/// <summary>
/// freeware helper class for getting .NET framework info
/// (W) 2011 by admin of codezentrale.de
/// </summary>
public static class NETFrameworkInfo
{
    /// <summary>
    /// prints the root install path of the .NET-Frameworks on your system
    /// </summary>
    /// <returns>.NET root install path</returns>
    public static string NETRootPath
    {
        get
        {
            string rootpath = string.Empty;

            try
            {
                RegistryKey rKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");

                if (rKey != null)
                {
                    rootpath = rKey.GetValue("InstallRoot").ToString();
                }
            }
            catch (Exception e)
            {
                rootpath = e.Message;
            }

            return rootpath;
        }
    }
    /// <summary>
    /// prints currently used CLR version string
    /// hint: .NET 3.0 & 3.5 are using CLR v2.0!
    /// </summary>
    /// <returns>currently used CLR version</returns>
    public static string CurrentCLRVersion
    {
        get
        {
            return Environment.Version.ToString();
        }
    }
    /// <summary>
    /// prints the currently used .NET version home directory
    /// hint: .NET 3.0 & 3.5 are using CLR v2.0, so the homedir for the CLR-DLLs is v2.X !
    /// </summary>
    /// <returns>the currently used .NET version home directory</returns>
    public static string CurrentCLRVersionHome
    {
        get
        {
            string sRetVal = string.Empty;

            string sRootPath = NETRootPath;

            if (!string.IsNullOrEmpty(sRootPath))
            {
                sRetVal = Path.Combine(sRootPath, "v" + Environment.Version.Major.ToString() + "." + Environment.Version.Minor.ToString() + "." + Environment.Version.Build.ToString());

                if (!Directory.Exists(sRetVal))
                {
                    sRetVal = string.Empty;
                }
            }

            return sRetVal;
        }
    }
}

Windows Betriebssystemversion ermitteln

using System;

/// <summary>
/// freeware helper class for getting OS info
/// (W) 2011 by admin of codezentrale.de
/// </summary>
public static class OSVersion
{
    /// <summary>
    /// version string for current system
    /// </summary>
    public static string VersionString
    {
        get
        {
            string sRetVal = string.Empty;

            Version osver = Environment.OSVersion.Version;

            switch (Environment.OSVersion.Platform)
            {
                // Windows 95 wird von .NET nicht unterstützt
                // Windows 98, Windows 98SE, Windows Me
                case PlatformID.Win32Windows:
                    if (osver.Major == 4)
                    {
                        switch (osver.Minor)
                        {
                            case 10: sRetVal = "Windows 98"; break;
                            case 90: sRetVal = "Windows Me"; break;
                        }
                    }
                    break;
                case PlatformID.Win32NT:
                    // Windows NT 3.51 wird von .NET nicht unterstützt
                    // Windows NT 4.0
                    if (osver.Major == 4) sRetVal = "Windows NT 4.0";

                    // Windows 2000, XP, Server 2003
                    if (osver.Major == 5)
                    {
                        switch (osver.Minor)
                        {
                            case 0: sRetVal = "Windows 2000"; break;
                            case 1: sRetVal = "Windows XP"; break;
                            case 2: sRetVal = "Windows Server 2003"; break;
                        }
                    }
                    // Windows Vista, Windows Server 2008, Windows 7
                    if (osver.Major == 6)
                    {
                        switch (osver.Minor)
                        {
                            case 0: sRetVal = "Windows Vista / Windows Server 2008"; break;
                            case 1: sRetVal = "Windows 7 / Windows Server 2008 R2"; break;
                            case 2: sRetVal = "Windows 8 / Windows Server 2012"; break;
                        }
                    }
                    break;
            }

            if (sRetVal == string.Empty) sRetVal = "unbekannte oder von .NET nicht unterstützte Windows-Version";
            else sRetVal += " [" + Environment.OSVersion.VersionString + ", rev " + osver.Revision.ToString() + "]";

            return sRetVal;
        }
    }
}