Skip to content

Instantly share code, notes, and snippets.

@js1972
js1972 / testing.sc
Created August 16, 2014 08:22
Monoid implementation for Double. From ScalaZ 7.1 Double and Float are no longer supported as they don't totally fulfill the Monoid laws.
package com.example
import scalaz._
import Scalaz._
object testing {
1 |+| 1 //> res0: Int = 2
@js1972
js1972 / email_image_chart.abap
Created August 15, 2014 03:31
ABAP program to send email with images and charts. Not written by me, but I've tested it and it works - clean up before use (I've only added comments to clear things up)!!! This abap shows how to create a multi-part email to display inline images as well as attachments. It also shows how to generate a chart in abap (IGS) and get its image, as we…
report y_test_email_with_chart.
type-pools: abap .
tables: sflight .
constants: image_name_01 type string value 'Sailing.jpg' .
constants: image_name_02 type string value 'chart_01.jpg' .
constants: c_series_01 type string value 'series_01' .
@js1972
js1972 / partner_address.abap
Created August 7, 2014 04:49
Get SAP document partner addresses. Function SD_PARTNER_READ can be used to read the partner addresses for sales documents such as deliveries. The benefit of using this function is that it correctly gets the correct data when the user has overwritten the default partner address.
method get_address_as_gdt.
data addresses type standard table of sadrvb with empty key.
data partners type standard table of vbpavb with empty key.
data(country) = value land1_gp( ).
data(state) = value regio( ).
clear: r_result, addresses, partners.
r_result-internal_id-content = me->ship_to_party.
/**
* A monad to abstract dependencies in the code, see https://coderwall.com/p/kh_z5g
*/
object Reader {
/**
* an implicit to convert a function A => B in a Reader[A, B]
*/
implicit def reader[C, R](block: C => R): Reader[C, R] = Reader(block)
@js1972
js1972 / pi_java_udf_asma.java
Created July 29, 2014 02:52
How to set a Dynamic Configuration attribute (asma) in a mapping UDF function. This sample sets two attributes. The second one is for dynamically setting the soap-action attribute on the receiver SOAP adapter. [For the receiver SOAP channel - in the Advanced tab: set Use Adapter-specific Message Properties as well as Transport Binding. Also spec…
@LibraryMethod(title="", description="", category="User-Defined", type=ExecutionType.SINGLE_VALUE)
public String setASMA (
@Argument(title="setASMA") String s,
Container container) throws StreamTransformationException{
DynamicConfiguration dc = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey dck = DynamicConfigurationKey.create("urn_asma_test", "Z_ASMA");
dc.put(dck, "ASMA ASMA ASMA Oi Oi Oi");
@js1972
js1972 / odata_service.abap
Created July 21, 2014 04:48
Sample OData service for a basic User model. Shows how to provide filtering and sorting and also a Function Import. This uses the ODC (OData Channel) method for implementing an OData service which is the recommended approach by SAP. This sample shows two method redefinition's to get the entity by key value and to get an entity set by searching.
class zcl_zusers_dpc_ext definition
public
inheriting from zcl_zusers_dpc
create public .
public section.
methods /iwbep/if_mgw_appl_srv_runtime~execute_action redefinition.
protected section.
methods userset_get_entity redefinition.
@js1972
js1972 / read_table.abap
Created July 11, 2014 02:29
Reading data from an internal table in ABAP 7.40. We can now read table rows using array syntax. The only think to note is that an exception is thrown if the record is not found. You can even directly access fields after the array operator.
try.
data(forwarding_agent_details) = me->partners_tab[ parvw = c_forwarding_agent_partner ].
r_result-content = forwarding_agent_details-lifnr.
catch cx_sy_itab_line_not_found.
"Do nothing if not found
endtry.
@js1972
js1972 / abap_value_constructor.abap
Created July 4, 2014 03:03
Creating values based on structures and internal tables with ABAP 7.40. This example shows how to create a structure and provide values in-line and also how to create a new internal table, providing the row in-line. Note each new row is just separated by a set of parenthesis. You can also build the individual field values all in the one data(ret…
data(ret) = value BAPIRET2(
type = 'E'
id = 'ZM_ILO'
number = '017'
message_v1 = delivery
message_v2 = shipping_data_exc->get_text( )
).
data(rettab) = value bapirettab( ( ret ) ).
@js1972
js1972 / abap_type_conversion.abap
Created July 4, 2014 02:55
Using the new ABAP 7.40 constructor operation CONV for converting data-types on the fly. In this example we need to pass the name to the get_as_string method. i_delivery is type vbeln_vl yet a string is expected. CONV # takes car of the conversion in-line.
method payment_terms_text.
data(text) = new lcl_text_reader( )->get_as_string(
id = '0002'
name = conv #( i_delivery )
object = 'VBBK'
).
data proxy_text_collection type zxi_text_collection_text_tab.
data proxy_text_line like line of proxy_text_collection.
@js1972
js1972 / data_and_new_operators.abap
Created July 4, 2014 02:19
Using the new DATA() operator to declare a new variable in-line and the new NEW() operator for instantiating an object. These are available from ABAP 7.40. In this example we are creating a new string object, then de-referencing when we need to use it in the method call. We are also creating a new lcl_text_reader object and immediately calling t…
data(delivery_value) = new string( delivery ).
data(text) = new lcl_text_reader( )->get_as_string(
id = '0002'
name = delivery_value->*
object = 'VBBK'
).