2014-07-02

Stripping table name prefixes from SAP DirectLink fieldnames

So if you are using ACL DirectLink to do a full table extraction out of SAP, it will create an ACL Table whose fieldnames are prefixed with %TABLENAME%_, so for example BUKRS from BSAK ends up as BSAK_BUKRS. When you are using DirectLink as an ETL shim to export a flatfile extraction, you sometimes want the native field names instead, without prefixes (Careful: if you have specified a server side join in DirectLink, it will use the tablename prefix to distinguish between the same fieldname in two different tables from the resulting join, for example: BKPF_BUKRS, BSAK_BUKRS. Of course, server side joins are to be avoided when doing this type of dump anyway). From the ACL project, extract the table definition:
BSAK_MANDT     UNICODE     1   6   AS "Accounting: Secondary Index for Vendors (Cleared Items);Client"  
BSAK_BUKRS     UNICODE     7   8   AS "Accounting: Secondary Index for Vendors (Cleared Items);Company Code"  
BSAK_LIFNR     UNICODE    15  20   AS "Accounting: Secondary Index for Vendors (Cleared Items);Account Number of Vendor or Creditor"  
BSAK_UMSKS     UNICODE    35   2   AS "Accounting: Secondary Index for Vendors (Cleared Items);Special G/L Transaction Type"  
BSAK_UMSKZ     UNICODE    37   2   AS "Accounting: Secondary Index for Vendors (Cleared Items);Special G/L Indicator"  
BSAK_AUGDT     DATETIME   39  16   PICTURE "YYYYMMDD" AS "Accounting: Secondary Index for Vendors (Cleared Items);Clearing Date"  
BSAK_AUGBL     UNICODE    55  20   AS "Accounting: Secondary Index for Vendors (Cleared Items);Document Number of the Clearing Document"  
...
etc
$ awk '{print $1}' bsak_all.txt | while read line; do echo "DELETE FIELD " $(echo $line | sed 's/[^_]*_\(.*\)/\1/') " OK" && echo "DEFINE FIELD " $(echo $line | sed 's/[^_]*_\(.*\)/\1/') " COMPUTED " $line && echo; done

non-greedy matching in sed

If you want to match a prefix in a string and stop at the n'th occurence of a delimiter in that string then you need non-greedy matching. This is how you would do it if the regex engine you are using doesn't support it natively, do it by negative character class.

Example: given a URI http://service.domain.tld/path1/path2/path3 and you only want service.domain.tld by splitting on /, then:

$ echo "http://service.domain.tld/path1/path2/path3" | sed 's@http://\([^/]*\).*@\1@'
service.domain.tld
Now what happens if you need the suffix after the delimiter? Just change the capturing parens:
$ echo "foo_bar_baz" | sed 's/[^_]*_\(.*\)/\1/'
bar_baz

Courtesy of: http://stackoverflow.com/questions/1103149/non-greedy-regex-matching-in-sed

Find which SAP roles provide access to what T-Codes

A lot of times, your SAP superuser wants you to request the specific role (or a template user) for which to provision a new account or role assignment you requested. Best way to determine that role is to search roles which fulfill the TCODEs you require access to. To do this, make sure you can login with a user with a role that has access to SUIM.

SUIM -> Roles -> By Authorization Values

Set Authorization Object 1 to S_TCODE

Click Entry value

Specify the TCodes you want to look up roles for. Pay attention to the AND and OR boxes for multiple TCode criteria.