A code refacting using string template

简介: A code refacting using string template

Created by Jerry Wang, last modified on Jun 23, 2016

The original code before refact:

There are some fields in DDIC structure CRMT_SMS_STATUS_KEY which could be used for deletion.

Currently three fields are supported: sms_uuid, phone_number and resend_times.

Current implementation is to evaluate all possible status of the three fields, whether they are intial or not.

In theory support you have n fields to support for deletion case the combination would be . If we still follow the current design, the code could not be sustainable: more and more IF … ELSEIF has to be added.

image.png


A better solution could be using string template instead. A draft code looks like below:

image.png

The advantage is, if more fields are to be supported, you could simply add the code marked with bold, without having to code complex IF… ELSEIF statement. However, since now we use dynamical SQL statement instead, make sure to avoid the potential SQL injection by escaping all input fields of CRMT_SMS_STATUS_KEY via method cl_abap_dyn_prg=>escape_quotes.


相关文章
For input string: "null"
java.lang.NumberFormatException: For input string: "null"   在开发中你是否遇到过这样的问题,不管请求到的值是什么都能进入不为null或”“的判断中,如下例:      Stringtemp=req.
3817 0
|
4月前
|
存储 算法 C++
【C++】:string用法详解
【C++】:string用法详解
82 0
|
5月前
|
编译器
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
91 1
|
8月前
|
C++
2023-2-19-什么是string_view
2023-2-19-什么是string_view
64 0
|
9月前
|
C语言 C++
C++ string 基本用法
C++ string 基本用法
|
9月前
|
Java
【报错】String cannot be resolved to a type解决方案
【报错】String cannot be resolved to a type解决方案
212 1
|
10月前
|
C语言 C++
C++中string的用法
⭐一、string的简介 string的中文译为字符串,是C++在C语言中的char字符类型上的延伸。C++中封装有许多关于string的函数可以方便我们完成一些关于字符串的操作。而且string的空间大小是动态变化的,可以减小不必要空间的浪费。
163 0
String.search()
String.search()
70 0
|
Go
go语言map[string]string 转map[string]interface{}
go语言map[string]string 转map[string]interface{}
595 0
|
索引
string.find
string.find
106 0