最近没事,把笔记上的东西慢慢移到CSDN上,持续完善中~
1:/nsxi_monitor查看接口日志
2:内表数据拼接
2.1、给内表加一个空行并修改他的值
APPEND INITIAL LINE TO GT_ALV ASSIGNING FIELD-SYMBOL(<FS>) .
2.2、将内表数据拼接在一行
CONCATENATE LINES OF GT_ZMTZBZ INTO LV_ZBZ SEPARATED BY '/'.在这里插入代码片
2.3、将内表部分字段数据拼接在一行
CONCATENATE LV_Z1 LV_Z2 INTO LV_ZBZ SEPARATED BY '/'.入代码片
2.4、两个内表数据拼接
APPEND LINE OF GT_TAB1 TO GT_TAB2 .
3、Group By分组
3.1:常规分组
LOOP AT gt_alv3 INTO gs_alv3 GROUP BY ( matnr = gs_alv3-matnrkostl = gs_alv3-kostlsize = GROUP SIZE )ASSIGNING FIELD-SYMBOL(<lt_out>) .LOOP AT GROUP <lt_out> ASSIGNING FIELD-SYMBOL(<fs_out>) .ENDLOOP .ENDLOOP .
3.2:动态Group分组
可以用到SWITCH/COND关键字实现
DATA : lv_type TYPE c VALUE 'B'.ASSIGN lt_ekpo TO FIELD-SYMBOL(<dy_table>) .IF <dy_table> IS ASSIGNED .LOOP AT <dy_table> ASSIGNING FIELD-SYMBOL(<fs_ekko>)GROUP BY SWITCH string( lv_type WHEN 'A' THEN <fs_ekko>-matnrWHEN 'B' THEN <fs_ekko>-matkl )* GROUP BY COND string( WHEN lv_type = 'A' THEN <fs_ekko>-matnr* WHEN lv_type = 'B' THEN <fs_ekko>-matkl )ASSIGNING FIELD-SYMBOL(<ft_group>) .LOOP AT GROUP <ft_group> ASSIGNING FIELD-SYMBOL(<fs_group>) .ENDLOOP .ENDLOOP .ENDIF .
缺点:此语法只能通过一个维度来进行分组,如果要通过多个维度分组的话还是建议用常规的方法
4、查看表中的数据条目数
DESCRIBE TABLE LT_MARC LINES LV_TABIX .
5、增删改查
UPDATA [TABLE] SET A = 1 .
6、获取字符串长度
lv_len = cl_abap_list_utilities=>dynamic_output_length( lv_str ).
7、转换例程
gt_tab-akont = |{ gt_tab-akont ALPHA = IN }|.
8、给字符串去空格
CONDENSE <字符串> NO-GAPS.
9、在选择屏幕上添加文本
1:SELECTION-SCREEN COMMENT 01(78) TEXT-001 .
TEXT-001为需要显示的文本,双击创建即可
10、输出简易版ALV
cl_demo_output=>display( lt_table ).
11、红绿灯
函数组:icon
12、submit调用程序
正常调用:
cl_salv_bs_runtime_info=>set(display = abap_true"abap_false(这个参数很SB,后面的ALV输出不了)metadata = abap_falsedata = abap_true ).
"获取数据
SUBMIT rm07docsWITH budat BETWEEN lv_firday AND lv_lastdayWITH bwart IN lr_bwartWITH rflat_l = 'X'WITH database = 'X'EXPORTING LIST TO MEMORYAND RETURN.IF sy-subrc = 0 .TRY.cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_alv_data ) .ASSIGN lr_alv_data->* TO <lt_alv_data> .CLEAR :lr_alv_data .CATCH cx_salv_bs_sc_runtime_info.MESSAGE '查询结果为空!' TYPE 'E'.ENDTRY.ENDIF .
后台调用:
cl_salv_bs_runtime_info=>set(display = abap_truemetadata = abap_falsedata = abap_true ).CALL FUNCTION 'JOB_OPEN'EXPORTINGjobname = nameIMPORTINGjobcount = numberEXCEPTIONScant_create_job = 1invalid_job_data = 2jobname_missing = 3OTHERS = 4.IF sy-subrc = 0.SUBMIT ukm_rfdkli20WITH sdchd = 'X'WITH testlauf = ''WITH pkunnr IN r_kunnrWITH pkkber IN r_kkberTO SAP-SPOOLSPOOL PARAMETERS print_parametersWITHOUT SPOOL DYNPROVIA JOB name NUMBER numberAND RETURN.IF sy-subrc = 0.CALL FUNCTION 'JOB_CLOSE'EXPORTINGjobcount = numberjobname = namestrtimmed = 'X'EXCEPTIONScant_start_immediate = 1invalid_startdate = 2jobname_missing = 3job_close_failed = 4job_nosteps = 5job_notex = 6lock_failed = 7OTHERS = 8.IF sy-subrc = 0.ENDIF.ENDIF .ENDIF.
13、创建UUID
TRY.lo_uuid = cl_uuid_factory=>create_system_uuid( ).lv_uuid_x16 = lo_uuid->create_uuid_x16( ).lo_uuid->convert_uuid_x16(EXPORTINGuuid = lv_uuid_x16IMPORTINGuuid_c26 = lv_uuid_c26 ).CATCH cx_uuid_error.ENDTRY.
14、查找关键字在那个程序中出现过
执行程序:RS_ABAP_SOURCE_SCAN
15、动态调用函数模块
DATA: lt_param TYPE abap_func_parmbind_tab,ls_param TYPE abap_func_parmbind,lt_excep TYPE abap_func_excpbind_tab,ls_excep TYPE abap_func_excpbind,DEFINE fill_func_parm.IF &3 IS NOT INITIAL.ls_param-name = &1.ls_param-kind = &2.GET REFERENCE OF &3 INTO ls_param-value.INSERT ls_param INTO TABLE lt_param.CLEAR ls_param.ENDIF.END-OF-DEFINITION.fill_func_parm:gs_config-parm1 abap_func_exporting lv_key,gs_config-parm2 abap_func_exporting lf_log->key2,gs_config-parm3 abap_func_exporting lf_log->key3,gs_config-parm4 abap_func_exporting lf_log->key4,gs_config-parm5 abap_func_exporting lf_log->key5.CALL FUNCTION gs_config-zprogramPARAMETER-TABLElt_paramEXCEPTION-TABLElt_excep.
16、读表不存工作区
READ TABLE XVBUV[] WITH KEY TBNAM = 'VBAP' FDNAM = 'NETWR' FEHGR = 'Y1' TRANSPORTING NO FIELDS .
17、复制表部分数据到新表
APPEND LINES OF 【Tab1】 FROM 1 TO 10 TO 【Tab2】 .
18、CONCATENATE拼接字符串
RESPECTING BLANKS:左对齐
CONCATENATE `bearer` ' ' lv_base64 INTO token RESPECTING BLANKS.
19、ABAP 字符串处理
"字符串替换
REPLACE ALL OCCURRENCES OF 'A' IN lv_string WITH 'B'. (将lv_string 中所有A 换为B )
REPLACE ALL OCCURRENCES OF 'ABC' IN lv_string WITH space. (将lv_string 中 所有 ABC 换为 空 )"字符串拼接
CONCATENATE t1 t2 INTO result. "直接拼接
CONCATENATE t1 t2 INTO result SEPARATED BY space. "用空格将字符串连接"字符串拆分
SPLIT text AT space INTO str1 str2. "根据空格将字符串拆分到str1 和str2中 "字符转换
TRANSLATE text TO UPPER CASE. "转大写
TRANSLATE text TO LOWER CASE. "转小写"取字符长度
len = strlen( text ). "字符串长度"字符串截取
subtext = text+0(5). "取左边5個字符('ABCDE')
subtext = text+3(5). "从第四個字串起取5个字符('DEFGH)
text+0(1) = 'Z'. "將第一个字符转为Z"查找字符位置
SEARCH text FOR '='. "查找=在text中的位置
IF sy-subrc = 0.DATA(l_index) = sy-fdpos. "sy-fdpos的位置
ENDIF .
注意:sy-fdpos是从第0位开始的"正则判断字符串
FIND FIRST OCCURRENCE OF REGEX '[^0-9]' IN wa_data-lfdat.“判断wa_data-lfdat中是否包含不是0-9的数字
IF sy-subrc = 0.
Endif."字符串去空格
CONDENSE:重新整合分配字符串
CONDENSE C <NO-GAPS> "字符串大小写转换
TRANSLATE
TRANSLATE c TO UPPER CASE. "转大写
TRANSLATE c TO LOWER CASE. "转小写
TRANSLATE c USING c1. "用C1替换C "字符移动
"SHIFT:字符串整体或者字串进行转移.
"如果SHIFT 操作的对象是 C类型, 则所有字节都会向前移动一位,最后一位用空格代替;
"如果SHIFT操作的对象是String类型,则所有字符都会向前移动一位,最后一位删除;
SHIFT c <LEFT/RIGHT/CIRCULAR>.
SHIFT c BY n PLACES.
SHIFT c UP TO c1.