1、加上前导零与去除前导零函数
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = L_IN
IMPORTING
output = L_OUT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = L_IN
IMPORTING
output = L_OUT.
2、人员岗位组织数据获取函数
*获取岗位所在组织从最底层到最高层
REFRESH :lt_objec1,lt_struc1.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'S'
act_objid = ls_objec-objid
act_wegid = 'S_UP'
act_begda = ls_objec-endda
act_endda = ls_objec-endda
* act_tdepth = 0
authority_check = ''
TABLES
result_objec = lt_objec1
result_struc = lt_struc1
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
*获取此组织下的所有子组织
REFRESH :lt_objec,lt_struc.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'O'
act_objid = gv_orgeh
act_wegid = 'O-O_DOWN'
act_begda = '18000101'
act_endda = i_endda
* act_tdepth = 0
authority_check = ''
TABLES
result_objec = lt_objec
result_struc = lt_struc
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
*获取此组织下的所有岗位
REFRESH :lt_objec,lt_struc.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'O'
act_objid = gv_orgeh
act_wegid = 'O-O-S'
act_begda = '18000101'
act_endda = i_endda
* act_tdepth = 0
authority_check = ''
TABLES
result_tab = result_tab 【评估路径】
result_objec = lt_objec
result_struc = lt_struc
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
"获取当前组织架构版本
CALL FUNCTION 'RH_GET_ACTIVE_WF_PLVAR'
EXPORTING
ask_plvar_dialog = ' '
IMPORTING
act_plvar = lv_plvar
EXCEPTIONS
no_active_plvar = 01.
3、价格循环比较逻辑代码示例
DATA:first_time TYPE abap_bool.
"相同主键的第一行价格与后续同一主键进行比较
LOOP AT lt_data2 INTO ls_data2.
first_time = abap_true.
LOOP AT lt_data INTO ls_data WHERE pernr = ls_data2-pernr .
IF first_time = abap_true.
lv_betrg5 = ls_data-zbznx.
first_time = abap_false.
ELSE .
IF lv_betrg5 <> 0.
zbl = ( ls_data-zbznx - lv_betrg5 ) / lv_betrg5 * 100.
ELSE.
zbl = 0.
ENDIF.
IF zbl LT 0.
ls_data-znewtxret = zbl.
CONDENSE ls_data-znewtxret NO-GAPS.
REPLACE '-' WITH '%' INTO ls_data-znewtxret.
CONCATENATE '-' ls_data-znewtxret INTO ls_data-znewtxret.
ELSEIF zbl EQ 0.
ls_data-znewtxret = '0%'.
CONDENSE ls_data-znewtxret NO-GAPS.
ELSEIF zbl GT 0.
ls_data-znewtxret = zbl.
CONDENSE ls_data-znewtxret NO-GAPS.
CONCATENATE ls_data-znewtxret '%' INTO ls_data-znewtxret.
ENDIF.
lv_betrg5 = ls_data-zbznx.
ENDIF.
MODIFY lt_data FROM ls_data.
ENDLOOP.
CLEAR: lv_betrg5,ls_data.
ENDLOOP.
4、双重LOOP循环优化逻辑
SORT: IT_VBAK BY VBELN,
IT_VBAP BY VBELN.
LOOP AT IT_VBAK INTO WA_VBAK.
**--Read到对应的TABIX
READ TABLE IT_VBAP TRANSPORTING NO FIELDS WITH KEY VBELN = WA_VBAK-VBELN BINARY SEARCH.
IF sy-subrc = 0.
LV_TABIX = SY-TABIX.
**然后根据TABIX来循环
LOOP AT IT_VBAP FROM LV_TABIX INTO WA_VBAP.
IF WA_VBAP-VBELN <> WA_VBAK-VBELN.
EXIT.
ENDIF.
这里需要操作的代码块。
ENDLOOP.
endif.
ENDLOOP.
5、ABAP中Collect的用法
"对总表进行排序
SORT GT_DATA BY KUNNR.
REFRESH GT_DATAHJ.
LOOP AT GT_DATA INTO GS_DATA.
CLEAR GS_DATAHJ.
GS_DATAHJ-KUNNR = GS_DATA-KUNNR.
GS_DATAHJ-DZZJE = GS_DATA-DZZJE.
COLLECT GS_DATAHJ INTO GT_DATAHJ.
CLEAR GS_DATA.
ENDLOOP.
6、调用函数进入维护视图页面
call function 'VIEW_MAINTENANCE_CALL'
exporting
action = 'U'
view_name = iv_name “表名或视图名
exceptions
foreign_lock = 2
no_tvdir_entry = 8.
7、点击按钮打开链接
data lv_url TYPE string.
lv_url = 'http://192.100.99.176:8080/ProjectWeb/Page/BusinessStart/BusinessStart.aspx?bonum=' && ls_adminh-object_id && '&botype=' && ls_adminh-process_type.
CONCATENATE 'javascript:window.open( "' lv_url '" );' INTO lv_url.
CLEAR ls_button.
READ TABLE gt_button INTO ls_button WITH KEY text = '发起业务启动流程'.
ls_button-type = cl_thtmlb_util=>gc_icon_edit.
ls_button-text = '发起业务启动流程'. "#EC NOTEXT
ls_button-on_client_click = lv_url. "这是重点,跟普通的按钮不一样ON_CLIENT_CLICK
ls_button-enabled = abap_true.
APPEND ls_button TO gt_button.
8、更新保存数据
COMMIT WORK 异步更新,该语句执行后不会等待所有更新函数都执行完后才继续执行后面的代码
COMMIT WORK AND WAIT 同步更新,该语句执行后会等待所有更新函数都执行完后才继续执行后面的代码,执行结果可以通过sy-subrc来判断事务提交是否成功
1、 CALL FUNCTION 'DB_COMMIT'.
2、
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
非本地方式会将更新结果记录到数据表中,可以通过SM13查看更新情况,异步快速
9、CEIL向上取整应用与类型相关
10、报错信息几种代码格式:
DATA: lv_msg_service TYPE REF TO cl_bsp_wd_message_service.
lv_msg_service = me->view_manager->get_message_service( ).
CALL METHOD lv_msg_service->add_message
EXPORTING
iv_msg_type = 'E'
iv_msg_id = 'ZLES_WF'
iv_msg_number = '034'.
MESSAGE e034(zles_wf) INTO lv_messtxt. "便于通过消息号反查到该位置,无其他作用
RETURN.
DATA:lv_message TYPE string,
lv_flag_1242 TYPE char1,
ls_bapiret2 TYPE bapiret2,
lt_bapiret2 TYPE bapiret2_t.
DEFINE def_set_message.
rv_error = abap_true.
CLEAR:ls_bapiret2.
ls_bapiret2-type = sy-msgty.
ls_bapiret2-id = sy-msgid.
ls_bapiret2-number = sy-msgno.
ls_bapiret2-message_v1 = sy-msgv1.
ls_bapiret2-message_v2 = sy-msgv2.
ls_bapiret2-message_v3 = sy-msgv3.
ls_bapiret2-message_v4 = sy-msgv4.
APPEND ls_bapiret2 TO rt_bapiret2.
RETURN.
END-OF-DEFINITION.
11、报表查询逻辑dump检查具体报错信息方法
DATA: lr_sy_dynamic_osql_syntax TYPE REF TO cx_sy_dynamic_osql_syntax.
TRY.
********代码逻辑
CATCH cx_root INTO lr_sy_dynamic_osql_syntax.
lr_sy_dynamic_osql_syntax->get_text( ).
ENDTRY.
12、SELECT简便写法
13、只取一条
SELECT *
INTO TABLE @lt_wb_1239 UP TO 1 ROWS
FROM zles_wb_1239
WHERE bizid = @ls_wb_1238-bizid
AND userid = @ls_wb_1238-userid
ORDER BY created_date DESCENDING,
created_time DESCENDING.
14、链接编辑::
DATA: lr_adminh TYPE REF TO cl_crm_bol_entity.
IF zbt126h IS BOUND.
"add by yes at 20181026 begin
"优先调用super->do_init_context,首次获取zbt126h,首次进入无法获取p,默认为链接.
lr_adminh ?= zbt126h->ztyped_context->btadminh->collection_wrapper->get_current( ).
CASE iv_property.
WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
IF lr_adminh->is_changeable( ) = abap_true.
rv_value = cl_bsp_dlc_view_descriptor=>field_type_input.
ELSE.
rv_value = cl_bsp_dlc_view_descriptor=>field_type_link.
ENDIF.
"WHEN IF_BSP_WD_MODEL_SETTER_GETTER=>...
"...
ENDCASE.
ELSE.
CASE iv_property.
WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
rv_value = cl_bsp_dlc_view_descriptor=>field_type_link. “获取链接
"WHEN IF_BSP_WD_MODEL_SETTER_GETTER=>...
"...
ENDCASE.
ENDIF.
15、排除查询SQL方法:
16、DB01—SQL编辑器查询书写格式
select a.object_id,a.ZZAPPLYSTATU,a.wi_text,A.ZZAPPLYSTATU_TXT,b.TXT30
from zvles_wi_obj as a
join zles001 as b on b.OBJECT_ID = a.OBJECT_ID
where a.WI_TEXT like '%等待%'
and a.wi_stat = 'READY'
and a.ZZAPPLYSTATU = '02'
and a.wi_cd = '20180202'
and a.process_type IN ( 'ZQ01' ,'ZQ02','ZQ03')