首页 > 其他分享 >ABAP中常用的功能函数

ABAP中常用的功能函数

时间:2022-10-19 09:12:18浏览次数:74  
标签:FUNCTION LV 常用 函数 DATA lv ABAP CALL TYPE

 

1.负号前置:#

DATA lv_data(6) TYPE c VALUE '12345-'.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
  CHANGINGc
    value         = lv_data .  "-12345"

2.读取长文本:#

# 方式一
"定义长文本参数"
DATA: LV_ID       TYPE  THEAD-TDID,          "id"
      LV_LANGUAGE TYPE  THEAD-TDSPRAS,       "language"
      LV_NAME     TYPE  THEAD-TDNAME,        "name"
      LV_OBJECT   TYPE  THEAD-TDOBJECT,      "object"
      LT_LINES    TYPE  TLINE TABLE OF WITH HEADER LINE,  "长文本内容返回结果"
      LV_MSG      TYPE  STRING.

"设置参数值"
LV_ID       = ''.
LV_LANGUAGE = SY-LANGU.
LV_NAME     = ''.
LV_OBJECT   = ''.

"调用读取长文本函数:READ_TEXT"
CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    id                            = LV_ID
    language                      = LV_LANGUAGE
    NAME                          = LV_NAME
    OBJECT                        = LV_OBJECT
*   ARCHIVE_HANDLE                = 0
*   LOCAL_CAT                     = ' '
* IMPORTING
*   HEADER                        =
*   OLD_LINE_COUNTER              =
  TABLES
    lines                         = LT_LINES
 EXCEPTIONS
   ID                            = 1
   LANGUAGE                      = 2
   NAME                          = 3
   NOT_FOUND                     = 4
   OBJECT                        = 5
   REFERENCE_CHECK               = 6
   WRONG_ACCESS_TO_ARCHIVE       = 7
   OTHERS                        = 8.

"调整长文本格式"
IF sy-subrc = 0.
  LOOP AT LT_LINES.
      CONCATENATE LV_MSG LT_LINES-TDLINE ';' INTO LV_MSG SEPARATED BY SPACE.
  ENDLOOP.
ENDIF.
    
# 方式二
DATA:lv_str  TYPE STRING.
"读取长文本---通过id
CALL METHOD cl_eso_extraction_tools=>extract_long_text_by_id
  EXPORTING
    iv_langu        = sy-langu "语言
    iv_text_id      = 'F01'   "文本标识
    iv_name         =  '4500000151' "文本名
    iv_object       =  'EKKO'      "文本对象
  IMPORTING
    ev_search_terms = lv_str.
WRITE :lv_str.

3.添加前导零#

DATA lv_data TYPE aufk-aufnr.
lv_data = '10000001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = lv_data    "10000001"
  IMPORTING
    output = lv_data.   "000010000001'
	
# 在7.4以后的新版本可使用 lv_data = |{ lv_data = ALPHA = IN }|.添加前导零

4.去除前导零#

DATA lv_data TYPE aufk-aufnr.
lv_data = '000010000001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input  = lv_data    "000010000001"
  IMPORTING
    output = lv_data.   "10000001'
	
# 在7.4以后的新版本可使用 lv_data = |{ lv_data = ALPHA = OUT }|.去除前导零

5.显示加载进度百分比效果#

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
 EXPORTING
   PERCENTAGE       = 65                    '显示进度百分比'
   TEXT             = '数据处理中。。。' .    '显示文本'

6.根据结构生成ALV展示数据字段目录:#

DATA gt_fieldcat TYPE lvc_t_fieldcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
 EXPORTING
*   I_BUFFER_ACTIVE              =
   I_STRUCTURE_NAME             = 'ZSTRUCTURE'  "结构名称"
   I_CLIENT_NEVER_DISPLAY       = 'X'
*   I_BYPASSING_BUFFER           =
*   I_INTERNAL_TABNAME           =
  CHANGING
    CT_FIELDCAT                  = gt_fieldcat. "ALV字段目录内表"

7.通用表锁-加锁&解锁#

# 加锁
DATA lv_tabname TYPE rstable-tabname.
DATA lv_msg     TYPE bapimessage.
CALL FUNCTION 'ENQUEUE_E_TABLE'
 EXPORTING
   MODE_RSTABLE         = 'E'
   TABNAME              = lv_tabname
 EXCEPTIONS
   FOREIGN_LOCK         = 1
   SYSTEM_FAILURE       = 2
   OTHERS               = 3.

IF sy-subrc <> 0.
  CONCATENATE '用户' sy-uname '当前正在操作该表!' INTO lv_msg.
  MESSAGE lv_msg TYPE 'E'.
ENDIF.

# 解锁
DATA lv_tabname TYPE rstable-tabname.
CALL FUNCTION 'DEQUEUE_E_TABLE'
  EXPORTING
    mode_rstable = 'E'
    tabname      = lv_tabname.

8.UUID32位生成器#

DATA lv_id TYPE  sysuuid_c.
CALL FUNCTION 'ICF_CREATE_GUID'
  IMPORTING
    id = lv_id.    "C0A802DF9AA1606BF06B2B7E00000000"

9.动态设置ALV报表标题#

DATA gv_title TYPE sytitle.
CALL FUNCTION 'RECA_GUI_SET_TITLEBAR'
    EXPORTING
     id_text1      =  gv_title.   "一般只需要一个参数,如果长度不够,则用下面的额参数进行拼接"
*     id_text2      =  gv_title
*     id_text3      =  gv_title
*     id_text4      =  gv_title.

10.不同物料单位数量比例转换#

DATA:
     i_matnr  LIKE  mara-matnr,
     i_in_me  LIKE  mara-meins,
      i_out_me LIKE  mara-meins,
     i_menge  LIKE  ekpo-menge,
     e_menge  LIKE  ekpo-menge.
     CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
       EXPORTING
         i_matnr              = i_matnr        "物料"
         i_in_me              = i_in_me        "基本单位"
         i_out_me             = i_out_me       "待转换单位"
         i_menge              = i_menge		"待转换数量"
       IMPORTING
         e_menge              = e_menge        "转换后数量"
       EXCEPTIONS
         error_in_application = 1
         error                = 2
         OTHERS               = 3.

11.数字四舍五入转换#

  CALL FUNCTION 'ROUND'
    EXPORTING
      decimals      = 2       " 保留多少位小数
      input         = lr_dat
      sign          = '+'     " + 向上取舍 - 向下取舍 (负数也一样)
    IMPORTING
      output        = lr_dat    " 输出返回结果
    EXCEPTIONS
      input_invalid = 1
      overflow      = 2
      type_invalid  = 3
      OTHERS        = 4.

12.BAPI返回消息转换#

  DATA lv_msg TYPE string.
  LOOP AT lt_bapiret2 INTO DATA(ls_return) WHERE type CO 'AEX' .
    CALL FUNCTION 'MESSAGE_TEXT_BUILD'
      EXPORTING
        msgid               = ls_return-id
        msgnr               = ls_return-number
        msgv1               = ls_return-message_v1
        msgv2               = ls_return-message_v2
        msgv3               = ls_return-message_v3
        msgv4               = ls_return-message_v4
      IMPORTING
        message_text_output = lv_msg.
    CONCATENATE message lv_msg INTO message SEPARATED BY ';'.
  ENDLOOP.

13.调用表维护视图#

  CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
  EXPORTING
    action                       = 'U'      "操作模式:S-显示;U-更新;T-传输"
    view_name                    = 'ZMMT001'  "视图/表名"
  EXCEPTIONS
    client_reference             = 1
    foreign_lock                 = 2
    invalid_action               = 3
    no_clientindependent_auth    = 4
    no_database_function         = 5
    no_editor_function           = 6
    no_show_auth                 = 7
    no_tvdir_entry               = 8
    no_upd_auth                  = 9
    only_show_allowed            = 10
    system_failure               = 11
    unknown_field_in_dba_sellist = 12
    view_not_found               = 13
    maintenance_prohibited       = 14
    OTHERS                       = 15.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

14.重置系统运行时间#

LOOP AT itab .
    lv_time = SY-TABIX MOD 10000.
    IF lv_time EQ 0.
      CALL FUNCTION 'TH_REDISPATCH'.
    ENDIF.
     ......
ENDLOOP.

作者:ITiger

出处:https://www.cnblogs.com/zyhcs/p/15533231.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

转载请注明出处!

标签:FUNCTION,LV,常用,函数,DATA,lv,ABAP,CALL,TYPE
From: https://www.cnblogs.com/zt11402/p/16804975.html

相关文章

  • python当中map,reduce和filter函数用法和区别
    在python当中,关于map,reduce和filter函数用法。map:对任何可迭代序列中的每一个元素应用对应的函数。python3中返回的是迭代器。reduce:将序列中所有的元素进行合并运算......
  • MySQL函数
    1.字符串函数1.length():计算字符串长度函数,返回字符串字节长度,一个汉字占三个字节语法:select length('length长度')  -----122.concat():拼接字符串......
  • Anaconda常用命令
    如何创建、激活、退出虚拟环境创建虚拟环境condacreate-nnev_name(环境名称)python=3.7(对应版本号)激活虚拟环境condaactivateenv_name(环境名称)退出虚拟环境......
  • 03-Go的执行原理及Go的常用命令
    go的源码文件分为三类:命令源码文件,库源码文件,测试源码文件命令源码文件:后缀.go的文件,一个目录下,只能有一个main的入口,否则build或install会报错。库源码文件:普通的源码......
  • 工作笔记之 SELECT 语句在 SAP ABAP 中的用法总结(上)
    日常开发过程中,最常用的语句可能就是查询语句了。那么如果从数据库表中查询数据呢?答:​​selectfrom​​语句。SELECT的三个部分在OPENSQL中,​​SELECT​​语句可以查......
  • clamp()函数
    clamp函数clamp:钳子的意思返回范围内的一个数值。可以使用clamp函数将不断增加、减小或随机变化的数值限制在一系列的值中。floatclamp(floatminnumber,floatma......
  • linux常用命令
    1、常用命令命令对应英文作用lslist查看当前目录下的内容pwdprintworkdirectory查看当前所在目录cd[目录名]changedirectory切换目录touch......
  • Linux类常用命令
    1.浏览目录类命令1.1pwd命令pwd命令用于显示用户当前所处的目录。[root@localhost~]#pwd/root1.2cd命令cd命令用来在不同的目录之间切换[root@localhost~]#c......
  • 常用的数组方法有哪些?
    concat()方法用于合并两个或多个数组。此方法不会更改现有数组,而是返回一个新数组。find()方法返回数组中满足提供的测试函数的第一个元素的值。否则返回undefined。f......
  • 函数
    实验目的python支持自定义函数,通过将一段有规律的、重复的代码定义为函数,来达到一次编写,多次调用的目的,使用函数可以提高代码的重复利用率。实验过程实例01输出每日一......