Skip to content

Instantly share code, notes, and snippets.

View js1972's full-sized avatar

Jason Scott js1972

  • Perth, Australia
View GitHub Profile
@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 / 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 / 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 / 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");
/**
* 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 / 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.
@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 / 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 / abap_brf_plus.abap
Created August 18, 2014 02:35
ABAP program to execute a BRF+ Function. In production code SAP recommends using program fdt_template_function_process to generate the required ABAP code. This gist is for testing...
report y_brfplus_function_test.
data: lo_admin_data type ref to if_fdt_admin_data,
lo_function type ref to if_fdt_function,
lo_context type ref to if_fdt_context,
lo_result type ref to if_fdt_result,
"lx_fdt type ref to cx_fdt,
result type abap_bool,
event_code type string.
@js1972
js1972 / msg_attachment_udf.java
Created August 25, 2014 05:12
Example PI UDF showing how to add an attachment to a message. In this case its sent to the MAIL adapter so is a text file attachment to the email. UDF function imports: public void setAttachment(String[] OrgFormatName, String[] StreetName, String[] HouseId, String[] Email, String[] RegionName, String[] CityName, String[] CountryName, String[] St…
/* This UDF reads all contents and creates an output along with an attachment to SAP PI message, which has data in CSV foramt as expected by DB Schenker.
Please note that DB Schenker expect some of the fields as empty and hence only commas are added in the payload. For future enhancements if further fields are required to be added, pass them as input to UDF and update the
content field to use that input
*/
AbstractTrace trace = container.getTrace();
String firstRow = "Organization Name,,Contact Name,Email Address,Phone Number,Handling Office,Trucker,US Principal Party of Interest / ISF Importer,Factory,Consignee/Destination/ISF Ship To,Freight Forwarder,Third Party,Equipment Stuffing Location,Secondary Name/3rd Party Description,Address (Line 1),Address (Line 2),Address (Line 3),Email Address,State,City,Country (ISO Country Code),Postal Code,Phone,Fax,Internal Customer Account #,Importer of Record Number,Type (EIN, SSN, Foreign),Consignee #,Type (EIN, SSN, Foreign),Vendor Name,Vendor Code,Contact Name";
St