Group Details Private

administrators

Member List

  • SAP BDC录屏
    FUNCTION zoms_va01.
    *"----------------------------------------------------------------------
    *"*"本地接口:
    *"  IMPORTING
    *"     VALUE(I_OMS_POHEAD) TYPE  ZOMS_004 OPTIONAL
    *"  TABLES
    *"      I_OMS_POITEM STRUCTURE  ZOMS_005 OPTIONAL
    *"      I_OMS_MESSAGE STRUCTURE  ZOMS_006 OPTIONAL
    *"----------------------------------------------------------------------
      DATA:lv_tdname LIKE stxh-tdname.
      DATA:lv_kunnr TYPE vbak-kunnr,
           lv_kunag TYPE vbak-kunnr,
           lv_kbetr TYPE char16,
           lv_vbeln TYPE vbak-vbeln.
      CLEAR:lv_kunnr,lv_kunag,lv_kbetr.
      REFRESH:i_oms_message.
      DATA:lv_i TYPE i.
    
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = i_oms_pohead-kunnr
        IMPORTING
          output = lv_kunnr.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = i_oms_pohead-kunag
        IMPORTING
          output = lv_kunag.
    
      REFRESH:i_bdc.
    * header
      PERFORM bdc_dynpro      USING 'SAPMV45A' '0101'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'VBAK-AUART'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'VBAK-AUART'
                                    i_oms_pohead-auart.
      PERFORM bdc_field       USING 'VBAK-VKORG'
                                    i_oms_pohead-vkorg.
      PERFORM bdc_field       USING 'VBAK-VTWEG'
                                    i_oms_pohead-vtweg.
      PERFORM bdc_field       USING 'VBAK-SPART'
                                    i_oms_pohead-spart.
      PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'VBKD-BSTKD'
                                    i_oms_pohead-bstkd.
      PERFORM bdc_field       USING 'VBKD-BSTDK'
                                    i_oms_pohead-bstdk.
      PERFORM bdc_field       USING 'KUAGV-KUNNR'
                                    lv_kunnr.
      PERFORM bdc_field       USING 'KUWEV-KUNNR'
                                    lv_kunag.
      CLEAR:lv_i.
    
    
      LOOP AT i_oms_poitem.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
          EXPORTING
            input        = i_oms_poitem-matnr
          IMPORTING
            output       = i_oms_poitem-matnr
          EXCEPTIONS
            length_error = 1
            OTHERS       = 2.
        IF lv_i = 0.
          PERFORM bdc_field       USING 'RV45A-MABNR(01)'
                                        i_oms_poitem-matnr.
          PERFORM bdc_field       USING 'VBAP-ZMENG(01)'
                                        '1'.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=ITEM'.
          PERFORM bdc_field       USING 'VBKD-FKDAT'
                                          sy-datum.
          PERFORM bdc_field       USING 'VBKD-PRSDT'
                                          sy-datum.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'VBAP-POSNR(01)'.
    
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=T\09'.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '/00'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'VBAP-POSEX'.
          PERFORM bdc_field       USING 'VBAP-POSEX'
                                        i_oms_poitem-posex.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=T\05'.
    
          PERFORM bdc_dynpro      USING 'SAPMV45A' '5003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '/00'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'KOMV-KBETR(06)'.
          PERFORM bdc_field       USING 'KOMV-KSCHL(06)'
                                        'PR01'.
          lv_kbetr = i_oms_poitem-netpr.
          PERFORM bdc_field       USING 'KOMV-KBETR(06)'
                                        lv_kbetr.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '5003'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'KOMV-KSCHL(07)'.
        ENDIF.
        IF lv_i NE 0.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '/EBACK'.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=POAN'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'RV45A-MABNR(03)'.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '/00'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'VBAP-ZMENG(02)'.
          PERFORM bdc_field       USING 'RV45A-MABNR(02)'
                                        i_oms_poitem-matnr.
          PERFORM bdc_field       USING 'VBAP-ZMENG(02)'
                                         '1'.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4001'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=ITEM'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'VBAP-POSNR(02)'.
    
          PERFORM bdc_dynpro      USING 'SAPMV45A' '5003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=T\09'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'KOMV-KSCHL(06)'.
          PERFORM bdc_dynpro      USING 'SAPMV45A' '4003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=T\05'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'VBAP-POSEX'.
          PERFORM bdc_field       USING 'VBAP-POSEX'
                                        i_oms_poitem-posex.
    
          PERFORM bdc_dynpro      USING 'SAPMV45A' '5003'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '/EBACK'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'KOMV-KBETR(06)'.
          PERFORM bdc_field       USING 'KOMV-KSCHL(06)'
                                         'PR01'.
          lv_kbetr = i_oms_poitem-netpr.
          PERFORM bdc_field       USING 'KOMV-KBETR(06)'
                                        lv_kbetr.
        ENDIF.
        lv_i = lv_i + 1.
      ENDLOOP.
    
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=SICH'.
    
      lst_params-dismode = 'P'.
      lst_params-updmode = 'S'.
      lst_params-defsize = 'X'.
    
      REFRESH:i_mess.
      CALL TRANSACTION 'VA01' USING i_bdc OPTIONS FROM lst_params MESSAGES
               INTO i_mess.
      READ TABLE i_mess INTO i_mess
        WITH KEY msgid = 'V1'
                 msgnr = '311'.
      IF sy-subrc NE 0.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        i_oms_message-ztype = 'E'.
        i_oms_message-message = '销售订单创建异常!'.
        i_oms_message-bstkd = i_oms_pohead-bstkd.
        APPEND i_oms_message.
        CLEAR:i_oms_message.
        LOOP AT i_mess WHERE msgtyp = 'E'.
          SELECT SINGLE text INTO i_oms_message-message FROM t100
            WHERE sprsl = sy-langu
              AND arbgb = i_mess-msgid
              AND msgnr = i_mess-msgnr.
          i_oms_message-ztype = 'E'.
          i_oms_message-bstkd = i_oms_pohead-bstkd.
          APPEND i_oms_message.
          CLEAR:i_oms_message.
        ENDLOOP.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
        CLEAR:lv_vbeln.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            input  = i_mess-msgv2
          IMPORTING
            output = lv_vbeln.
        lv_tdname = lv_vbeln.
    
        PERFORM create_text USING '0001' '1' lv_tdname 'VBBK' CHANGING i_oms_pohead-ztext.
    
        i_oms_message-ztype = 'S'.
        i_oms_message-message = '销售订单创建成功!'.
        i_oms_message-bstkd = i_oms_pohead-bstkd.
        i_oms_message-vbeln = i_mess-msgv2.
        APPEND i_oms_message.
        CLEAR:i_oms_message.
      ENDIF.
    ENDFUNCTION.
    
    posted in 代码库
  • BP 业务伙伴维护BAPI

    前情提要

    仅列出常用的BAPI,大家可以到具体的函数组中发现更多用法;角色可以创建的时候直接维护,或者单独维护;找不到BAPI的,比如公司代码,使用API来维护。

    BAPI清单

    创建BP
    BAPI_BUPA_CREATE_FROM_DATA 创建BP, 包括中心数据、地址等
    BAPI_BUPA_FS_CREATE_FROM_DATA2 功能同上,多一个角色分配功能
    ————————————————————————————————————
    角色维护
    BAPI_BUPA_ROLES_GET_2 获取分配的Role(按日期)
    BAPI_BUPA_ROLE_ADD_2 添加Role
    BAPI_BUPA_ROLE_CHANGE 修改已存在的Role属性
    BAPI_BUPA_ROLE_EXIST_CHECK_2 校验Role是否存在
    BAPI_BUPA_ROLE_REMOVE 删除已分配的Role
    ————————————————————————————————————
    中心数据维护
    BAPI_BUPA_CENTRAL_GETDETAIL 获取中心数据
    BAPI_BUPA_CENTRAL_CHANGE 修改中心数据
    ————————————————————————————————————
    地址信息维护
    BAPI_BUPA_ADDRESSES_GET 获取所有地址信息
    BAPI_BUPA_ADDRESS_ADD 添加地址信息
    BAPI_BUPA_ADDRESS_CHANGE 修改已存在的地址信息
    BAPI_BUPA_ADDRESS_GETDETAIL 获取某个地址的详细信息
    BAPI_BUPA_ADDRESS_GET_NUMBERS 获取地址对应的address number
    BAPI_BUPA_ADDRESS_REMOVE 删除地址信息
    ————————————————————————————————————
    银行信息维护
    BAPI_BUPA_BANKDETAILS_GET 获取所有的银行信息
    BAPI_BUPA_BANKDETAIL_ADD 添加银行信息
    BAPI_BUPA_BANKDETAIL_CHANGE 修改银行信息
    BAPI_BUPA_BANKDETAIL_GETDETAIL 获取单个银行的详细信息
    BAPI_BUPA_BANKDETAIL_NUMBERS 获取银行ID
    BAPI_BUPA_BANKDETAIL_REMOVE 删除银行信息
    ————————————————————————————————————
    Identification Number(标识号/证件号码)
    BAPI_IDENTIFICATIONDETAILS_GET 获取所有标识号
    BAPI_IDENTIFICATION_GET_DETAIL 获取单个标识号的详细信息
    BAPI_IDENTIFICATION_ADD 新增标识号
    BAPI_IDENTIFICATION_CHANGE 修改标识号
    BAPI_IDENTIFICATION_REMOVE 删除标识号
    ————————————————————————————————————
    API
    CMD_EI_API_EXTRACT 读取BP客户信息
    VMD_EI_API_EXTRACT 读取BP供应商信息
    VMD_EI_API 维护BP供应商
    CMD_EI_API 维护BP客户
    ————————————————————————————————————
    增强
    PARTNER_UPDATE BP创建或修改
    ADDRESS_UPDATE BP地址(通信)数据维护
    ————————————————————————————————————
    API示例代码(维护公司代码)
    维护客户

    form maintain_cust_company  using  u_bp_basic type zsmdg_bp_input_basic_req
                                      u_bp_comp_tab type zmdg_bp_input_company_req_t
                                changing c_return_table type bapiret2_tab.
      "获取BP关联的客户编码,默认1对1
      select single partner,
             b~partner_guid,
             customer
        from but000 as b
        inner join cvi_cust_link as c
        on c~partner_guid eq b~partner_guid
        where partner eq @u_bp_basic-bp_header
        into @data(ls_bp_cust).
    
      data:ls_master_data type cmds_ei_main,
           ls_customer    type cmds_ei_extern,
           ls_central     type cmds_ei_cmd_central,
           ls_company     type cmds_ei_company,
           lt_company     type cmds_ei_company_t,
           ls_message     type cvis_message.
    
      clear ls_master_data.
      clear ls_customer.
    
      loop at u_bp_comp_tab into data(ls_bp_comp).
        ls_company-task = 'M'.
        ls_company-data_key-bukrs = ls_bp_comp-company.
        ls_company-data-akont = '1122010000'.
        ls_company-data-loevm = ls_bp_comp-loevm_b.
    
        ls_company-datax-akont = abap_true.
        ls_company-datax-loevm = abap_true.
    
        append ls_company to lt_company.
      endloop.
    
      ls_central-data-ktokd = 'DEBI'.
      ls_central-datax-ktokd = abap_true.
    
      ls_customer = value #(
        header = value #(
                        object_instance = value #( kunnr = ls_bp_cust-customer )
                        object_task = 'M' )
       central_data = value #(
                        central = ls_central
                        address = value #( postal = value #( data = value #(
                                                            name = u_bp_basic-zzbpnm
                                                            city = u_bp_basic-zzcity
                                                            country = u_bp_basic-ref_posta
                                                            langu = '1'
                                                                        )
                        datax = value #(
                                                           name = abap_true
                                                           city = abap_true
                                                           country = abap_true
                                                           langu = abap_true
                                                                        )
                                                                  )
                                                )
                             )
      company_data = value #(  company = lt_company current_state = abap_true )
      ).
      append ls_customer to ls_master_data-customers.
    
      cmd_ei_api=>initialize( ).
      cmd_ei_api=>lock( iv_kunnr = ls_bp_cust-customer ).
      cmd_ei_api=>maintain(
      exporting
        is_master_data = ls_master_data
      importing
        es_error = ls_message
       ).
      cmd_ei_api=>unlock( iv_kunnr = ls_bp_cust-customer ).
    
      read table ls_message-messages transporting no fields with key type = 'E'.
      if sy-subrc ne 0.
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait = abap_true.
      else.
        call function 'BAPI_TRANSACTION_ROLLBACK'.
      endif.
    
      append lines of ls_message-messages to c_return_table.
    endform.
    

    维护供应商

    form maintain_ven_company  using   u_bp_basic type zsmdg_bp_input_basic_req
                                      u_bp_comp_tab type zmdg_bp_input_company_req_t
                                changing c_return_table type bapiret2_tab.
      "获取BP关联的供应商编码,默认1对1
      select single partner,
                    b~partner_guid,
                    vendor
      from but000 as b
      inner join cvi_vend_link as v
      on v~partner_guid eq b~partner_guid
      where partner eq @u_bp_basic-bp_header
      into @data(ls_bp_vend).
    
      data:ls_master_data type vmds_ei_main,
           ls_vendor      type vmds_ei_extern,
           ls_company     type vmds_ei_company,
           lt_company     type vmds_ei_company_t,
           ls_central     type vmds_ei_vmd_central,
           ls_message     type cvis_message.
    
      clear ls_master_data.
      clear ls_vendor.
    
      loop at u_bp_comp_tab into data(ls_bp_comp).
        ls_company-task = 'M'.
        ls_company-data_key-bukrs = ls_bp_comp-company.
        ls_company-data-akont = '2202020000'.
        ls_company-data-loevm = ls_bp_comp-loevm_b.
    
        ls_company-datax-akont = abap_true.
        ls_company-datax-loevm = abap_true.
        append ls_company to lt_company.
      endloop.
    
      ls_central-data-ktokk = 'KRED'.
      ls_central-datax-ktokk = abap_true.
    
      ls_vendor = value #(
      header = value #(
      object_instance = value #( lifnr = ls_bp_vend-vendor )
      object_task = 'M' )
      central_data = value #(
                              central = ls_central
                              address = value #( postal = value #( data = value #(
                                                                  name = u_bp_basic-zzbpnm
                                                                  city = u_bp_basic-zzcity
                                                                  country = u_bp_basic-ref_posta
                                                                  langu = '1'
                                                                                  )
                                                                  datax = value #(
                                                                  name = abap_true
                                                                  city = abap_true
                                                                  country = abap_true
                                                                  langu = abap_true
                                                                                  )
                                                                   )
                                                )
                                    )
      company_data = value #(  company = lt_company  current_state = abap_true )
      ).
      append ls_vendor to ls_master_data-vendors.
    
      vmd_ei_api=>initialize( ).
      vmd_ei_api=>lock( iv_lifnr = ls_bp_vend-vendor ).
      vmd_ei_api=>maintain(
      exporting
        is_master_data = ls_master_data
      importing
        es_error = ls_message
        ).
      vmd_ei_api=>unlock( iv_lifnr = ls_bp_vend-vendor ).
    
      read table ls_message-messages transporting no fields with key type = 'E'.
      if sy-subrc ne 0.
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait = abap_true.
      else.
        call function 'BAPI_TRANSACTION_ROLLBACK'.
      endif.
    
      append lines of ls_message-messages to c_return_table.
    endform.
    
    posted in BAPI
  • SAP标准搜索帮助增强

    RFC DD_SHLP_SINGLE_STEP
    c82dce2f-0ab5-4b90-9e9a-8799aa006109-image.png

    PERFORM f4proz_step_select
           
          TABLES shlp_tab
                  record_tab
           
          CHANGING shlp_curr
                    callcontrol ocxinterface cursor.
    
    *增加公司代码搜索帮助权限控制
    
IF SHLP-SHLPNAME = 'H_T001'.
  
    data:lv_str type char10.
  
    LOOP AT RECORD_TAB ASSIGNING FIELD-SYMBOL(<fs_h_t001>).
    
    lv_str = <fs_h_t001>-string+0(7).
    
    CONDENSE lv_str NO-GAPS.
   
     AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
                    
                       吧ID 'BUKRS'   FIELD lv_str.
    
    IF sy-subrc ne 0.
      
      delete RECORD_TAB.
    
    ENDIF.
  
    ENDLOOP.
ENDIF.
    
    posted in 增强
  • RE: div / mod 的用法区别

    下面是一段关于CEIL 和 FLOOR 的代码
    DATA:a TYPE mseg-menge,
    b TYPE mseg-menge,
    c TYPE mseg-menge.

    a = '1.36'.
    b = '1.34'.

    c = a / b.

    c = CEIL( a / b ).
    WRITE:/,c.
    "输出 2.000

    c = FLOOR( a / b ).
    WRITE:/,c.
    "输出 1.000

    posted in Development For Sap
  • ABAP报表开发模板
    REPORT zfytypcfg.
    *&---------------------------------------------------------------------*
    *& Responsibility
    *&---------------------------------------------------------------------*
    * Program Name:ZFI_RPT_079
    * Date written: 2017/2/27
    * Author's name:醉逍遥
    * Last update:2017/2/27
    * Program title:费控-大类-细类-审批规则明细表
    * Version:1.0
    *&---------------------------------------------------------------------*
    * Description: (Incl. Related Function Area and System)
    *&---------------------------------------------------------------------*
    *
    
    *&---------------------------------------------------------------------*
    * CHANGING History
    *&---------------------------------------------------------------------*
    *     Date   |   Programmer   |   Corr. #   |   Description
    *            |                |             |
    *            |                |             |
    *&---------------------------------------------------------------------*
    TABLES:ztprocess.
    TYPE-POOLS:slis,icon.
    *&---------------------------------------------------------------------*
    *& DATA
    *&---------------------------------------------------------------------*
    TYPES:BEGIN OF ty_xstd,
            fytyp TYPE ztfytyp-fytyp,
          END OF ty_xstd.
    DATA:gt_xstd TYPE TABLE OF ty_xstd,
         gs_xstd TYPE ty_xstd.
    
    *&--------------------------ALV----------------------------------------*
    DATA: gt_fieldcat TYPE TABLE OF lvc_s_fcat , "字段清单内表
          gs_fieldcat LIKE  lvc_s_fcat , "字段工作区
          gs_layout   TYPE  lvc_s_layo.
    *&---------------------------------------------------------------------*
    *SELECT-OPTIONS
    *&---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
    PARAMETERS: p_a1 RADIOBUTTON GROUP g1 USER-COMMAND uc DEFAULT 'X',
                p_a2 RADIOBUTTON GROUP g1,
                p_a3 RADIOBUTTON GROUP g1,
                p_a4 RADIOBUTTON GROUP g1,
                p_a5 RADIOBUTTON GROUP g1.
    SELECTION-SCREEN END OF BLOCK b1.
    
    *&---------------------------------------------------------------------*
    *INITIALIZATION
    *&---------------------------------------------------------------------*
    INITIALIZATION.
    
    *&---------------------------------------------------------------------*
    *AT SELECTION-SCREEN OUTPUT
    *&---------------------------------------------------------------------*
    AT SELECTION-SCREEN OUTPUT.
    
    *&---------------------------------------------------------------------*
    *SQL
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.
    *Check
      PERFORM frm_check_selection.
    * 取数据
      PERFORM frm_select_data.
    * 循环处理
      PERFORM frm_process_data.
    
    END-OF-SELECTION.
    
    * ALV显示
      PERFORM frm_output_alv.
    *&---------------------------------------------------------------------*
    *&      Form  FRM_CHECK_SELECTION
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_check_selection .
    
    ENDFORM.
    *&---------------------------------------------------------------------*
    *&      Form  FRM_SELECT_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_select_data .
    
    ENDFORM.
    *&---------------------------------------------------------------------*
    *&      Form  FRM_PROCESS_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_process_data .
    
    ENDFORM.
    *&---------------------------------------------------------------------*
    *&      Form  FRM_OUTPUT_ALV
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_output_alv .
    
      PERFORM get_field USING:'ZCIRCNO' '保监牌照编码',
                              'ZCIRCNOT' '保监牌照名称',
                              'ZXSTD' '销售团队',
                              'ZXSTD_TXT50' '销售团队描述',
                              'KOSTL' '成本中心',
                              'LTEXT' '成本中心描述',
                              'TYDATE' '停用日期'.
      PERFORM alv_out TABLES gt_xstd .
    
    ENDFORM.
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_OUTPUT_ALV
    *&---------------------------------------------------------------------*
    FORM alv_out TABLES pitab .
    
      gs_layout-cwidth_opt = 'X'..     " 自动调整列
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_callback_program          = sy-repid
          i_callback_pf_status_set    = 'FRM_SET_STATUS'
          i_callback_user_command     = 'FRM_SET_COMMAND'
          i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
          is_layout_lvc               = gs_layout
          it_fieldcat_lvc             = gt_fieldcat[]
          i_default                   = 'X'
          i_save                      = 'A'
          i_html_height_top           = 16
        TABLES
          t_outtab                    = pitab
        EXCEPTIONS
          program_error               = 1
          OTHERS                      = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
    ENDFORM. " alv_out
    FORM get_field USING p1 p2 .
      gs_fieldcat-fieldname = p1 .
      gs_fieldcat-scrtext_l = p2 .
      APPEND gs_fieldcat TO gt_fieldcat.
    ENDFORM. " get_field
    *&---------------------------------------------------------------------*
    *&      FRM_SET_STATUS
    *&---------------------------------------------------------------------*
    *       自定义状态栏
    *----------------------------------------------------------------------*
    FORM frm_set_status CHANGING excluding .
      SET PF-STATUS 'STANDARD'.
    ENDFORM.                    "FRM_SET_STATUS
    *&---------------------------------------------------------------------*
    *&      Form  FRM_SET_COMMAND
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_UCOMM    text
    *      -->ps_selfield text
    *----------------------------------------------------------------------*
    FORM frm_set_command CHANGING pv_ucomm TYPE sy-ucomm
                               ps_selfield TYPE slis_selfield.
    
      DATA: lc_grid TYPE REF TO cl_gui_alv_grid.
      DATA: lv_index TYPE i.
    
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = lc_grid.
      CALL METHOD lc_grid->check_changed_data.
      ps_selfield-refresh = 'X'.  "自动刷新
      CASE pv_ucomm.
        WHEN '&IC1'."双击事件
    *      IF  ps_selfield-fieldname = 'BELNR'. "判断是否选中
    *        READ TABLE gt_yj INTO gs_yj INDEX ps_selfield-tabindex. "取出当前鼠标
    *        IF sy-subrc EQ 0.
    *          SET PARAMETER ID: 'BUK' FIELD gs_yj-bukrs,
    *                            'GJR' FIELD gs_yj-gjahr,
    *                            'BLN' FIELD gs_yj-belnr.
    *          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
    *
    *        ENDIF.
    *      ENDIF.
    
      ENDCASE.
      "  CALL METHOD lc_grid->REFRESH_TABLE_DISPLAY.
      ps_selfield-col_stable = 'X'.
      ps_selfield-row_stable = 'X'.
    
    ENDFORM.                    "FRM_SET_COMMAND
    *&---------------------------------------------------------------------*
    *&      Form  html_top_of_page
    *&---------------------------------------------------------------------*
    FORM html_top_of_page USING document TYPE REF TO cl_dd_document.
    
      DATA: text TYPE sdydo_text_element.
      DATA: m_p      TYPE i,
            m_buffer TYPE string.
    
      text = '团财保费记账明细'.
    
      CONCATENATE  '<HTML><CENTER><H1>' text '</H1></CENTER></HTML>' INTO m_buffer.  " 居中  <H1>设置字体格式
      CALL METHOD document->html_insert
        EXPORTING
          contents = m_buffer
        CHANGING
          position = m_p.
    
      text = '保监牌照名称:'.
      CALL METHOD document->add_text
        EXPORTING
          text         = text
          sap_emphasis = 'Strong'.
    
      CALL METHOD document->add_text
        EXPORTING
          text      = text
          sap_style = 'Key'.
    
      CALL METHOD document->new_line.
    
      text = '查询截至期间:'.
      CALL METHOD document->add_text
        EXPORTING
          text         = text
          sap_emphasis = 'Strong'.
    
      CALL METHOD document->add_text
        EXPORTING
          text      = text
          sap_style = 'Key'.
    
      CALL METHOD document->add_gap
        EXPORTING
          width = 2.
    
    ENDFORM.                    "HTML_TOP_OF_PAGE 
    
    posted in 代码库
  • 三种替换字符串中首字母的三种方法

    "替换字符串中的某一个字符

    DATA:lv_char TYPE c VALUE ‘C01’ LENGTH 10.

    lv_char+0(1) = ‘B’.

    WRITE:lv_char.

    OVERLAY lv_char WITH ‘B’ ONLY lv_char.

    WRITE: / lv_char.

    REPLACE FIRST OCCURRENCE OF ‘C’ IN LV_CHAR WITH ‘B’.

    WRITE: / lv_char.

    此三种方法均能将C01转变成B01.

    此处的类型是char如果是字符串则不能用第一种方法

    要用replace来实现

    DATA:lv_str TYPE string VALUE ‘D01’.

    REPLACE SECTION OFFSET 0 LENGTH 1 OF LV_STR WITH ‘B’.

    WRITE:/ lv_str.

    posted in Development For Sap
  • abap 删除字符串末尾*

    写法一:

    DATA: STR(20),STR2(20),N.

    STR = ‘ abcade‘.

    WRITE STR.

    IF SUBSTRING( VAL = STR OFF = STRLEN( STR ) – 1 LEN = 1 ) = ‘‘.

    STR = SUBSTRING( VAL = STR LEN = STRLEN( STR ) – 1 ) .

    ENDIF.

    WRITE / STR.

    写法二:

    DATA v_res TYPE string.

    v_res = shift_right( val = str places = 0 ).

    WRITE : v_res.

    v_res = shift_right( val = str sub = |*| ).

    posted in Development For Sap
  • SAP保存操作记录CDHDR和CDPOS表
    1. 使用sap的标准函数CHANGEDOCUMENT_READ_HEADERS 和CHANGEDOCUMENT_READ_POSITIONS
    
    CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS' "Change document: Read change document items
    EXPORTING
    *   archive_handle = 0          " sy-tabix      Handle on Open Archive Files
        changenumber =              " cdpos-changenr  Change document number
    *   tablekey = SPACE            " cdpos-tabkey  Object class table key
    *   tablename = SPACE           " cdpos-tabname  Object class table name
    *   tablekey254 = SPACE         " cdpos_uid-tabkey  Table Key for CDPOS in Character 254
    *   keyguid = SPACE             " cdpos_uid-keyguid  UUID in Character Format
    *   keyguid_str = SPACE         " cdpos_str-keyguid  UUID in Character Format
    IMPORTING
        header =                    " cdhdr   Change document header (structure CDHDR)
       et_cdred_str =              " cdred_str_tab  Additional Change Document - Table for STRINGs
    * TABLES
    *   editpos =                  " cdshw     Table with edited change document items
    EDITPOS_WITH_HEADER =               "CDRED  更改文档,显示结构
    EXCEPTIONS
    NO_POSITION_FOUND = 1       "               No item foun
    WRONG_ACCESS_TO_ARCHIVE = 2  "              incorrect access to archive
    
    

    2)使用select语
    句直接从表中读取。

    直接使用SELECT语句读取数据的示例:

    *提取信用额度字段修改的抬头信息       
    select cdhdr~changenr cdhdr~udate cdhdr~utime        
    into corresponding fields of table p_cdhdr         
    from cdhdr         
    where cdhdr~objectclas = 'KLIM' and           
    cdhdr~objectid = wa_customerinfo-kunnr.       
    if sy-subrc = 0. 
    *提取信用额度字段修改的字段值         
    select cdpos~changenr cdpos~value_old cdpos~value_new           
    into corresponding fields of table p_cdpos           
    from cdpos             
    for all entries in p_cdhdr           
    where cdpos~objectclas = 'KLIM' and             
    cdpos~objectid = wa_customerinfo-kunnr and             
    cdpos~changenr = p_cdhdr-changenr and             
    cdpos~tabname = 'KNKK' and             
    cdpos~fname = 'KLIMK'.         
    if sy-subrc = 0.        
    endif. 
    endif.
    
    

    可以在CHANGEDOCUMENT_READ_HEADERS 中设置中断获得对象类型。

    提取有变动的 Acc. changes

    SELECT SINGLE tabkey value_new  INTO (cdpos-tabkey,ikoinh)
          FROM cdpos
          WHERE   objectclas = 'KRED'
            AND objectid = itab-lifnr
            AND changenr = itab-changenr
            AND tabname = 'LFBK'
            AND fname = 'KOINH'.
    
    

    提取有变动的vendor最新日期

       SELECT MAX( udate ) INTO itab-cndate FROM cdhdr
          WHERE objectclas = 'KRED' AND objectid = itab-lifnr.
    
    

    抓取所有有变动的程序

    report ztest001.
    TYPE-POOLS slis.
    DATA : cdhdr TYPE cdhdr.
    SELECT-OPTIONS :
       s_objcls FOR cdhdr-objectclas OBLIGATORY,
       s_objtid FOR cdhdr-objectid,
       s_chngnr FOR cdhdr-changenr,
       s_usrnam FOR cdhdr-username DEFAULT sy-uname,
       s_udate  FOR cdhdr-udate    DEFAULT sy-datum,
       s_time   FOR cdhdr-utime,
       s_tcode  FOR cdhdr-tcode,
       s_plncnr FOR cdhdr-planchngnr,
       s_chngno FOR cdhdr-act_chngno,
       s_wsplnd FOR cdhdr-was_plannd,
       s_chngid FOR cdhdr-change_ind.
    
    SELECTION-SCREEN SKIP.
    PARAMETERS p_max TYPE numc3 OBLIGATORY DEFAULT '200'.
    
    *---------------------------------------------------------------------*
    TYPES :
      BEGIN OF ty_s_cdhdr.
            INCLUDE STRUCTURE cdhdr.
    TYPES : checkbox,
      END OF ty_s_cdhdr,
    
      BEGIN OF ty_s_cdpos.
            INCLUDE STRUCTURE cdpos.
    TYPES : checkbox,
      END OF ty_s_cdpos.
    
    *---------------------------------------------------------------------*
    DATA :
    * Layout for ALV
       gs_layout TYPE slis_layout_alv,
    * Change document header
       t_cdhdr TYPE TABLE OF ty_s_cdhdr.
    
    *---------------------------------------------------------------------*
    START-OF-SELECTION.
    
    * Read Change document header
      SELECT * INTO TABLE t_cdhdr
                 UP TO p_max ROWS
               FROM cdhdr
              WHERE objectclas IN s_objcls
                and objectid   in s_objtid
                and changenr   in s_chngnr
                AND username   IN s_usrnam
                AND udate      IN s_udate
                AND utime      IN s_time
                AND tcode      IN s_tcode
                AND planchngnr IN s_plncnr
                AND act_chngno IN s_chngno
                AND was_plannd IN s_wsplnd
                AND change_ind IN s_chngid.
    
       gs_layout-zebra = 'X'.
       gs_layout-colwidth_optimize = 'X'.
       gs_layout-box_fieldname = 'CHECKBOX'.
    
    * Display ALV
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                 i_callback_program       = sy-cprog
                 i_callback_user_command = 'USER_COMMAND'
                 i_structure_name         = 'CDHDR'
                 is_layout                = gs_layout
           TABLES
                 t_outtab                 = t_cdhdr.
    
    *---------------------------------------------------------------------*
    *        FORM USER_COMMAND                                              *
    *---------------------------------------------------------------------*
    FORM user_command USING u_ucomm     TYPE syucomm
                             us_selfield TYPE slis_selfield.     "#EC CALLED
    
    * Macro definition
      DEFINE m_sort.
        add 1 to ls_sort-spos.
         ls_sort-fieldname = &1.
         ls_sort-up = 'X'.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
    
      DATA :
         ls_cdhdr TYPE ty_s_cdhdr,
         ls_sort  TYPE slis_sortinfo_alv,
         lt_sort  TYPE slis_t_sortinfo_alv,
    *    Change document items
         lt_cdpos TYPE TABLE OF ty_s_cdpos.
    
      CASE u_ucomm.
        WHEN '&IC1'.
          PERFORM check_marked USING us_selfield.
    
    *      Read Change document items
          LOOP AT t_cdhdr INTO ls_cdhdr WHERE checkbox = 'X'.
            SELECT * APPENDING TABLE lt_cdpos
                     FROM cdpos
                    WHERE objectclas = ls_cdhdr-objectclas
                      AND objectid    = ls_cdhdr-objectid
                      AND changenr    = ls_cdhdr-changenr.
          ENDLOOP.
    
           m_sort 'CHANGENR'.
    
    *      Display ALV
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
               EXPORTING
                     i_structure_name = 'CDPOS'
                     is_layout         = gs_layout
                     it_sort           = lt_sort
               TABLES
                     t_outtab          = lt_cdpos.
    
      ENDCASE.
    
    ENDFORM.                               " USER_COMMAND
    *--------------------------------------------------------------------FORM check_marked USING us_selfield TYPE slis_selfield.
    
      FIELD-SYMBOLS :
          TYPE ty_s_cdhdr.
    
      READ TABLE t_cdhdr TRANSPORTING NO FIELDS WITH KEY checkbox = 'X'.
      IF NOT sy-subrc IS INITIAL AND
         NOT us_selfield-tabindex IS INITIAL.
        READ TABLE t_cdhdr INDEX us_selfield-tabindex ASSIGNING .
         -checkbox = 'X'.
      ENDIF.
    
    ENDFORM.
    
    
    posted in Development For Sap
  • OOALV cl_salv_table
    *&---------------------------------------------------------------------*
    *& Report ZTEST1
    *&---------------------------------------------------------------------*
    *&
    *&---------------------------------------------------------------------*
    REPORT ztest1.
    TABLES:spfli.
    
    
    
    ***"可编辑
    ****----------------------------------------------------------------------*
    ****  Define the Local class inheriting from the CL_SALV_MODEL_LIST
    ****  to get an access of the model, controller and adapter which inturn
    ****  provides the Grid Object
    ****----------------------------------------------------------------------*
    ***CLASS lcl_salv_model DEFINITION INHERITING FROM cl_salv_model_list.
    ***
    ***  PUBLIC SECTION.
    ***    DATA: o_control TYPE REF TO cl_salv_controller_model,
    ***          o_adapter TYPE REF TO cl_salv_adapter.
    ***
    ***    METHODS:
    ***      grabe_model
    ***        IMPORTING
    ***          io_model TYPE REF TO cl_salv_model,
    ***
    ***      grabe_controller,
    ***
    ***      grabe_adapter.
    ***
    ***
    ***  PRIVATE SECTION.
    ***    DATA: lo_model TYPE REF TO cl_salv_model.
    ***
    ***ENDCLASS.                    "LCL_SALV_MODEL DEFINITION
    ****----------------------------------------------------------------------*
    **** LCL_SALV_MODEL implementation
    ****----------------------------------------------------------------------*
    ***CLASS lcl_salv_model IMPLEMENTATION.
    ***
    ***  METHOD grabe_model.
    ***
    ****   save the model
    ***    lo_model = io_model.
    ***
    ***  ENDMETHOD.                    "grabe_model
    ***
    ***  METHOD grabe_controller.
    ***
    ****   save the controller
    ***    o_control = lo_model->r_controller.
    ***
    ***  ENDMETHOD.                    "grabe_controller
    ***
    ***  METHOD grabe_adapter.
    ***
    ****   save the adapter from controller
    ***    o_adapter ?= lo_model->r_controller->r_adapter.
    ***
    ***  ENDMETHOD.                    "grabe_adapter
    ***
    ***ENDCLASS.                    "LCL_SALV_MODEL IMPLEMENTATION
    
    
    CLASS l_cl_handle_events DEFINITION.
      PUBLIC SECTION.
        METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table"新加按钮
          IMPORTING e_salv_function.
        METHODS: on_after_func FOR EVENT after_salv_function OF cl_salv_events_table"标准按钮操作后
          IMPORTING e_salv_function.
        METHODS: on_double_click FOR EVENT double_click OF cl_salv_events_table"双击
          IMPORTING
              row "事件触发所在的行号
              column."事件触发所在的列名
    ENDCLASS.
    
    CLASS l_cl_handle_events IMPLEMENTATION.
      METHOD on_user_command.
        PERFORM handle_user_command USING e_salv_function.
      ENDMETHOD.
      METHOD on_after_func.
        PERFORM handle_after_func USING e_salv_function.
      ENDMETHOD.
      METHOD on_double_click.
        PERFORM dbclick_user_command USING row column.
      ENDMETHOD.
    ENDCLASS.
    
    DATA: gt_itab LIKE TABLE OF spfli WITH HEADER LINE.
    DATA: gt_table     TYPE REF TO cl_salv_table,
          gr_function  TYPE REF TO cl_salv_functions_list,
          gr_display   TYPE REF TO cl_salv_display_settings,
          gr_layout    TYPE REF TO cl_salv_layout,
          gs_program   TYPE salv_s_layout_key, "该结构包含了布局变式所属程序名
          gr_columns   TYPE REF TO cl_salv_columns_table,
          gr_column    TYPE REF TO cl_salv_column,
          gr_selection TYPE REF TO cl_salv_selections,
          lr_events    TYPE REF TO cl_salv_events_table.
    ***"可编辑
    ***DATA: o_salv_model TYPE REF TO lcl_salv_model.
    
    PARAMETERS : l_connid LIKE spfli-connid.
    
    
    START-OF-SELECTION.
    
      IF l_connid = space.
        SELECT
          * FROM spfli
          INTO CORRESPONDING FIELDS OF TABLE gt_itab.
      ELSE.
        SELECT
          * FROM spfli
          INTO CORRESPONDING FIELDS OF TABLE gt_itab
          WHERE connid = l_connid.
      ENDIF.
    
    
      "全屏ALV
      cl_salv_table=>factory( IMPORTING r_salv_table = gt_table
                              CHANGING t_table = gt_itab[] ).
    
      gr_function = gt_table->get_functions( )."使用所有按钮function
      gr_function->set_all( 'X' ).
    
      "
    *  gt_table->set_screen_status(
    *                              EXPORTING
    *                                report = sy-repid
    *                                pfstatus = 'STANDARD'  "GUI状态,添加了ZTEST按钮
    *                                set_functions = gt_table->c_functions_all )."显示所有通用的预设按钮
      "set_functions = gt_table->c_functions_default )."显示基本默认选择性的预设按钮
      "set_functions = gt_table->c_functions_none )."所有预设按钮都将不会显示
    
      gr_display = gt_table->get_display_settings( ).
      gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
      gr_display->set_list_header('Header Test').
    
      gr_layout = gt_table->get_layout( ).
      gs_program-report = sy-repid.
      gr_layout->set_key( gs_program )."设置布局保存为变式时,这些变式应属性此Key(本程序名)
      gr_layout->set_save_restriction( cl_salv_layout=>restrict_none )."允许保存布局为变式
    
    
      "=====获取事件对象
      DATA: lr_event TYPE REF TO cl_salv_events_table.
      lr_event = gt_table->get_event( ).
    
    *  lr_event->RAISE_AFTER_SALV_FUNCTION( '&OAD' ).
    
      "=====事件注册
      DATA: lr_handle_event TYPE REF TO l_cl_handle_events.
      CREATE OBJECT lr_handle_event.
      SET HANDLER lr_handle_event->on_user_command FOR lr_event."新按钮
      SET HANDLER lr_handle_event->on_double_click FOR lr_event."标准按钮操作后
      SET HANDLER lr_handle_event->on_after_func FOR lr_event."双击
    
    *  gr_function->add_function(
    *                    name = 'PRING'
    *                    TEXT = '打印'
    *                    TOOLTIP = 'haha'
    *                    POSITION = if_salv_c_function_position=>right_of_salv_functions )."只适用与可控模式
    *  gt_table->set_screen_popup(   "以弹出框显示SALV  可控模式(利用控制器的模式)的SALV是不能以弹出框来显示的
    *    start_column = 1
    *    end_column = 500
    *    start_line = 1
    *    end_line = 50 ).
      gr_columns = gt_table->get_columns( )."字段标签
      gr_columns->set_optimize( 'X' ).
      gr_column ?= gr_columns->get_column( 'CONNID' ).
      gr_column->set_long_text( '列名222').
    
    
    
      "SALV行列选择模式
      gr_selection = gt_table->get_selections( ).
      gr_selection->set_selection_mode( if_salv_c_selection_mode=>row_column )."可以以行、列的方式进行选择
    
    ***"可编辑
    ****...Get Model Object ...............................................
    ***    DATA: lo_alv_mod TYPE REF TO cl_salv_model.
    ***
    ****   Narrow casting
    ***    lo_alv_mod ?= gt_table.
    ***
    ****   object for the local inherited class from the CL_SALV_MODEL_LIST
    ***    CREATE OBJECT o_salv_model.
    ***
    ****   grabe model to use it later
    ***    CALL METHOD o_salv_model->grabe_model
    ***      EXPORTING
    ***        io_model = lo_alv_mod.
    
      gt_table->display( ).
    *&---------------------------------------------------------------------*
    *&      Form  HANDLE_USER_COMMAND
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_E_SALV_FUNCTION  text
    *----------------------------------------------------------------------*
    FORM handle_user_command  USING    p_e_salv_function.
    
      CASE p_e_salv_function.
        WHEN 'ZTEST'.
          MESSAGE '按钮测试i' TYPE 'I'.
      ENDCASE.
    
      gt_table->refresh( ).
    ENDFORM.                    " HANDLE_USER_COMMAND
    *&---------------------------------------------------------------------*
    *&      Form  HANDLE_AFTER_FUNC
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_E_SALV_FUNCTION  text
    *----------------------------------------------------------------------*
    FORM handle_after_func  USING    p_e_salv_function.
      CASE p_e_salv_function.
        WHEN '&OAD'.
          MESSAGE '按钮测试i' TYPE 'I'.
      ENDCASE.
    ENDFORM.                    " HANDLE_AFTER_FUNC
    *&---------------------------------------------------------------------*
    *&      Form  DBCLICK_USER_COMMAND
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_E_SALV_FUNCTION  text
    *----------------------------------------------------------------------*
    FORM dbclick_user_command  USING p_row TYPE i
                                     p_column TYPE lvc_fname.
      DATA: l_row  TYPE char10,
            p_text TYPE string.
      WRITE p_row TO l_row LEFT-JUSTIFIED.
    
      CONCATENATE l_row '行,' '列名:'  p_column p_text INTO p_text SEPARATED BY space.
      MESSAGE p_text TYPE 'I'.
    
    
    
    
    ***  "可编辑
    ***  DATA: lo_grid TYPE REF TO cl_gui_alv_grid,
    ***        lo_full_adap TYPE REF TO cl_salv_fullscreen_adapter.
    ***
    ***  DATA: ls_layout TYPE lvc_s_layo.
    ***
    **** Contorller
    ****  CALL METHOD lo_report->
    ***  o_salv_model->grabe_controller( ).
    ***
    **** Adapter
    ****  CALL METHOD lo_report->
    ***  o_salv_model->grabe_adapter( ).
    ***
    **** Fullscreen Adapter (Down Casting)
    ***  lo_full_adap ?= o_salv_model->o_adapter.
    ***
    **** Get the Grid
    ***  lo_grid = lo_full_adap->get_grid( ).
    ***
    **** Got the Grid .. ?
    ***  IF lo_grid IS BOUND.
    ***
    ****   Editable ALV
    ***    ls_layout-edit = 'X'.
    ***
    ****   Set the front layout of ALV
    ***    CALL METHOD lo_grid->set_frontend_layout
    ***      EXPORTING
    ***        is_layout = ls_layout.
    ***
    ****   refresh the table
    ***    CALL METHOD lo_grid->refresh_table_display.
    ***
    ***  ENDIF.
    
    ENDFORM.                    " DBCLICK_USER_COMMAND
    
    posted in Development For Sap
  • SE11 自定义锁

    一、创建锁事务码:SE11 锁名称:EZTAR_T001

    二、程序锁应用

    1、加锁

    CALL FUNCTION 'ENQUEUE_EZTAR_T001'
        EXPORTING
          mode_ztar_t001 = 'E'
          mandt          = sy-mandt
          bukrs          = p_bukrs
          gjahr          = p_gjahr
          monat          = p_monat
          zar_type       = p_rtype
    *     X_BUKRS        = ' '
    *     X_GJAHR        = ' '
    *     X_MONAT        = ' '
    *     X_ZAR_TYPE     = ' '
    *     _SCOPE         = '2'
    *     _WAIT          = ' '
    *     _COLLECT       = ' '
        EXCEPTIONS
          foreign_lock   = 1
          system_failure = 2
          OTHERS         = 3.
    

    2、获取被锁定用户

      IF sy-subrc <> 0.
        CALL FUNCTION 'ENQUE_READ2'
          EXPORTING
            gclient = sy-mandt
            gname   = 'ZTAR_T001'
    *       GARG    = ' '
            guname  = '*'
    *       OPCODE2 = 1
    *       IMPORTING
    *       NUMBER  =
    *       SUBRC   =
          TABLES
            enq     = lt_enq.
        LOOP AT lt_enq ASSIGNING FIELD-SYMBOL().
          lv_uname = -guname.
        ENDLOOP.
        lv_str = '当前操作数据已被' && lv_uname && '锁定!'.
        MESSAGE lv_str TYPE 'S' DISPLAY LIKE 'E'.
        LEAVE LIST-PROCESSING.
    

    3、解锁

      CALL FUNCTION 'DEQUEUE_EZTAR_T001'
        EXPORTING
          mode_ztar_t001 = 'E'
          mandt          = sy-mandt
          bukrs          = p_bukrs
          gjahr          = p_gjahr
          monat          = p_monat
          zar_type       = p_rtype
    *     X_BUKRS        = ' '
    *     X_GJAHR        = ' '
    *     X_MONAT        = ' '
    *     X_ZAR_TYPE     = ' '
    *     _SCOPE         = '3'
    *     _SYNCHRON      = ' '
    *     _COLLECT       = ' '
        .
    
    posted in Development For Sap