使用SAP C4C自定义BO实现自定义的Number Range
In On-Premise world customer could use transaction code SNRO to create and maintain their custom number range object and consume via function module NUMBER_GET_NEXT.
In C4C it is not possible to use this backend approach for partner. In this blog a simple approach is introduced which fulfill the custom number range by leveraging custom Business object developed via Cloud studio.
Here below is what I have achieved: (1) Every time a new Custom transaction BO is created, the new ID is automatically populated by the Number Range Business Object. This behavior is exactly the same as the one in On-Premise world.
In C4C it is not possible to use this backend approach for partner. In this blog a simple approach is introduced which fulfill the custom number range by leveraging custom Business object developed via Cloud studio.
Here below is what I have achieved: (1) Every time a new Custom transaction BO is created, the new ID is automatically populated by the Number Range Business Object. This behavior is exactly the same as the one in On-Premise world.
(2) The current number interval is stored via an instance of Number Range object, which means even if you log off and log on system again, the current number range interval is loaded from backend persistence, instead of starting from scratch.
Detail implementation of this solution
(1) Create a Custom BO in Cloud Studio and paste the following source code:
import AP.Common.GDT as apCommonGDT;
businessobject NumberRange {
// Used to distinguish between different number ranges.
[AlternativeKey] element Topic:ID;
// Constant prefix of the generated number.
element Prefix : LANGUAGEINDEPENDENT_EXTENDED_Text;
element PrefixSeparatedByBlank : Indicator;
// The (formatted) number itself.
element Number : LANGUAGEINDEPENDENT_EXTENDED_Text;
// If true, a blank will be placed between the formatted number and the suffix.
element SuffixSeparatedByBlank : Indicator;
element Suffix : LANGUAGEINDEPENDENT_EXTENDED_Text;
// Latest generated number (Prefix + Number + Suffix).
element PresentValue : LANGUAGEINDEPENDENT_EXTENDED_Text;
// Counter for the number generation itself.
element Counter : IntegerValue;
// Minimum and maximum values of the counter.
element MinValue : IntegerValue;
element MaxValue : IntegerValue;
// true as long as we haven't reached the maximum value of the counter.
element Ready : Indicator;
action GenerateNextNumber;
action InitializeInstance;
}
(2) Implement action InitializeInstance. Here I hard code the max number as 999999999.
import ABSL;
if(!this.Topic.IsInitial()){
this.Prefix = this.Topic;
this.Suffix = "";
this.PrefixSeparatedByBlank = false;
this.SuffixSeparatedByBlank = false;
this.MaxValue = 999999999;
this.MinValue = 1;
this.Ready = true;
}
(3) Implement action GenerateNextNumber. The logic is a simplified version of the good old function module NUMBER_GET_NEXT.
import ABSL;
var lv_sFormat = "";
var lv_sAux;
if (this.Ready) {
if(!this.MinValue.IsInitial()){
if(!this.MaxValue.IsInitial()){
if(this.MinValue < this.MaxValue){
// Initialize the counter in case the object is new.
if (this.Number.Length() == 0) {
this.Counter = this.MinValue - 1;
}
this.Counter = this.Counter + 1;
this.Number = this.Counter.ToString();
// Put the new value together.
if (this.Prefix.Length() > 0) {
if (this.PrefixSeparatedByBlank) {
lv_sAux = this.Prefix + " ";
}
else {
lv_sAux = this.Prefix;
}
}
else {
lv_sAux = "";
}
lv_sAux = lv_sAux + this.Number;
if (this.Suffix.Length() > 0)
{
if (this.SuffixSeparatedByBlank) {
lv_sAux = lv_sAux + " ";
}
this.PresentValue = lv_sAux + this.Suffix;
}
else {
this.PresentValue = lv_sAux;
}
if (this.Counter == this.MaxValue) {
this.Ready = false;
}
}
}
}
}
(4) In your transaction custom BO, consume the function exposed by Number Range BO in AfterModify.absl.
Here I hard code the number range prefix as “JerryBO”. You can for sure even use different prefix based on for example different transaction type of your custom BO.
import ABSL;
var lv_my_topic: NumberRange.Topic;
var lo_number_range;
if (this.AgreementID.IsInitial()) {
lv_my_topic = "JerryBO";
lo_number_range = NumberRange.Retrieve(lv_my_topic);
if(!lo_number_range.IsSet()) {
lo_number_range = NumberRange.Create();
lo_number_range.Topic = lv_my_topic;
lo_number_range.InitializeInstance();
}
if(lo_number_range.Ready==true) {
lo_number_range.GenerateNextNumber();
this.AgreementID = lo_number_range.PresentValue;
return;
}
}
- 大牛教你使用7种卷积神经网络进行物体检测!
- Enterprise Library深入解析与灵活应用(3):倘若将Unity、PIAB、Exception Handling引入MVP模式.. .. ..
- 别对我说谎!你的小九九我都知道
- Spring集成RabbitMQ-使用RabbitMQ更方便
- Nodejs学习笔记(三)--- 模块
- 使用JClouds在Java中获取和发布云服务器
- Silverlight单元测试框架
- Enterprise Library深入解析与灵活应用(2): 通过SqlDependency实现Cache和Database的同步
- 让你感觉不真实的13个伟大科学成就和发现
- 分析Silverlight跨域调用
- Spring集成RabbiMQ-Spring AMQP新特性
- Nodejs学习笔记(二)--- 事件模块
- 巧用FireFox来调试Silverlight
- Nodejs学习笔记(一)--- 简介及安装Node.js开发环境
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 走进STL - 哈希表,散装称重么
- 第八届蓝桥杯省赛javaB组题目解析
- 拥抱STL - 类/结构体元素查询与排序
- 【tensorflow2.0】处理图片数据-cifar2分类
- 操作系统实验多线程编程中的读者优先和写者优先
- 【python】使用csv库以字典格式读写csv文件
- 基于TypeScript封装Axios笔记(八)
- springmvc之HttpMessageConverter<T>
- django-模板之静态文件加载(十四)
- springmvc之使用JstlView
- django-模板之include标签(十五)
- 【pytorch】改造mobilenet_v2进行multi-class classification(多标签分类)
- 走进STL - heap,小树芽
- 走进STL - 序列式容器(常用篇)
- springmvc之RequestMapping中的请求方式