Here, I have given some ABAP Cloud syntax with an example. This will work in the SAP S/4HANA Cloud and BTP ABAP environment with RAP & CDS view.
Table of Contents
Get System Current Date, Month, Year
DATA(current_date) = cl_abap_context_info=>get_system_date( ).
DATA(current_year) = substring( val = current_date off = 0 len = 4 ). " This will give you 'YYYY'
DATA(current_month) = substring( val = current_date off = 4 len = 2 ). " This will give you 'MM'
Cast Statement in ABAP Cloud Syntax
Example 1: cast( CGST.AmountInTransactionCurrency as abap.dec(23, 2) ) as gstrate
Example 2: cast( (get_numeric_value(CGST.AmountInTransactionCurrency) * 100 ) as abap.dec(23, 2)) as gstrate
Case Statement in ABAP Cloud Syntax
Example 1: case when Client_Name = 'SAP' then '1100' else '2200' end as ClientCode
Example 2: case Client_Name when 'SAP' then '1100' else '2200' end as ClientCode
Multiplication in CDS View
cast( (get_numeric_value(CGST.AmountInTransactionCurrency) * 100 ) as abap.dec(23, 2)) as gstrate
Division Statement In CDS View
cast( cast( ( (get_numeric_value(CGST.AmountInTransactionCurrency) * 100 ) / get_numeric_value(ACI.AmountInTransactionCurrency) ) as abap.dec(23, 2))
as abap.curr(23, 2)) as gstrate
Comment on the logic
Shortcut: Ctrl & / for commenting out the logic
Bypass the Authorization using Privileged Access
Select * from yy1_validate_postingperiod with Privileged Access
into table @data(gt_postingperiod).
Note: "with Privileged Access" is used to give access to all users to use with any access.
Remove the negative sign from the amount fields in CDS View
abs(fields) or abs(IGST.AmountInTransactionCurrency) as igstamount.
Get Address data in ABAP Cloud Syntax
The following class, which contains the method for returning address data, can be used in Cloud BAdIs or Custom Logic. It can change the address using a standard call and method.
cl_address_format=>get_instance( )->printform_postal_addr(
EXPORTING
iv_address_number = address_number
iv_language_of_country_field = language
IMPORTING
ev_formatted_to_one_line = DATA(one_line)
et_formatted_all_lines = DATA(all_lines)
).
Substring in CDS View (Split 2 characters from a string)
Syntax: substring(ACI.IN_HSNOrSACCode, 1, 2)
Example: ACI.IN_HSNOrSACCode = 99152346, you want '99'.
Read More