首页 > 其他分享 >利用APIFOX对ABAP函数进行调用

利用APIFOX对ABAP函数进行调用

时间:2023-06-02 15:55:30浏览次数:46  
标签:调用 LIKE lt lv ABAP ls TABLE APIFOX type

1.安装APIFOX,当然也可以使用在线版,无需下载

官网地址:https://apifox.com/

 

2.新建项目

 3.为项目起一个名称,为相关开发测试人员授权

 

4.在根目录新增子目录

 

5.编辑开发/测试/生产环境的地址信息以及默认全局变量

 

6.将SAP提供的ABAPAPI地址配置进APIFOX,有关ABAP提供的服务地址,请参考文章:

1.ABAP 功能模块的 JSON 适配器

2.RESTFUL方式 

 

 

7.与前一篇文章有所不同的是,本次在ABAP类中增加了更新模块,如图,请见代码:

 8.在APIFOX新建好服务URL后,可以在根目录设置用户密码,这样后面子节点就可以继承根目录的用户配置

 

9.新建调用接口[本例是SAP函数:BAPI_ACC_DOCUMENT_POST]

9.1在BODY页签,现在json格式,输入测试的报文

{
    "documentheader": {
        "obj_type": "",
        "obj_key": "",
        "obj_sys": "",
        "bus_act": "",
        "username": "CHENHUI",
        "header_txt": "抬头文本",
        "comp_code": "1710",
        "doc_date": "2023-06-02",
        "pstng_date": "2023-06-02",
        "trans_date": "0000-00-00",
        "fisc_year": 2023,
        "fis_period": 6,
        "doc_type": "SA",
        "ref_doc_no": "参照字段",
        "ac_doc_no": "",
        "obj_key_r": "",
        "reason_rev": "",
        "compo_acc": "",
        "ref_doc_no_long": "",
        "acc_principle": "",
        "neg_postng": "",
        "obj_key_inv": "",
        "bill_category": "",
        "vatdate": "0000-00-00",
        "invoice_rec_date": "0000-00-00",
        "ecs_env": "",
        "partial_rev": "",
        "doc_status": ""
    },
    "customercpd": {
        "name": "",
        "name_2": "",
        "name_3": "",
        "name_4": "",
        "postl_code": "",
        "city": "",
        "country": "",
        "country_iso": "",
        "street": "",
        "po_box": "",
        "pobx_pcd": "",
        "pobk_curac": "",
        "bank_acct": "",
        "bank_no": "",
        "bank_ctry": "",
        "bank_ctry_iso": "",
        "tax_no_1": "",
        "tax_no_2": "",
        "tax": "",
        "equal_tax": "",
        "region": "",
        "ctrl_key": "",
        "instr_key": "",
        "dme_ind": "",
        "langu_iso": "",
        "iban": "",
        "swift_code": "",
        "tax_no_3": "",
        "tax_no_4": "",
        "title": "",
        "tax_no_5": ""
    },
    "contractheader": {
        "doc_no": "",
        "doc_type_ca": "",
        "res_key": "",
        "fikey": "",
        "payment_form_ref": ""
    },
    "accountgl": [
        {
            "itemno_acc": 1,
            "gl_account": "0012121000",
            "item_text": "",
            "stat_con": "",
            "log_proc": "",
            "ac_doc_no": "",
            "ref_key_1": "",
            "ref_key_2": "",
            "ref_key_3": "",
            "acct_key": "",
            "acct_type": "",
            "doc_type": "",
            "comp_code": "",
            "bus_area": "",
            "func_area": "",
            "plant": "",
            "fis_period": 0,
            "fisc_year": 0,
            "pstng_date": "0000-00-00",
            "value_date": "2023-06-02",
            "fm_area": "",
            "customer": "",
            "cshdis_ind": "",
            "vendor_no": "",
            "alloc_nmbr": "",
            "tax_code": "",
            "taxjurcode": "",
            "ext_object_id": "",
            "bus_scenario": "",
            "costobject": "",
            "costcenter": "",
            "acttype": "",
            "profit_ctr": "",
            "part_prctr": "",
            "network": "",
            "wbs_element": "",
            "orderid": "",
            "order_itno": 0,
            "routing_no": 0,
            "activity": "",
            "cond_type": "",
            "cond_count": 0,
            "cond_st_no": 0,
            "fund": "",
            "funds_ctr": "",
            "cmmt_item": "",
            "co_busproc": "",
            "asset_no": "",
            "sub_number": "",
            "bill_type": "",
            "sales_ord": "",
            "s_ord_item": 0,
            "distr_chan": "",
            "division": "",
            "salesorg": "",
            "sales_grp": "",
            "sales_off": "",
            "sold_to": "",
            "de_cre_ind": "",
            "p_el_prctr": "",
            "xmfrw": "",
            "quantity": 0,
            "base_uom": "",
            "base_uom_iso": "",
            "inv_qty": 0,
            "inv_qty_su": 0,
            "sales_unit": "",
            "sales_unit_iso": "",
            "po_pr_qnt": 0,
            "po_pr_uom": "",
            "po_pr_uom_iso": "",
            "entry_qnt": 0,
            "entry_uom": "",
            "entry_uom_iso": "",
            "volume": 0,
            "volumeunit": "",
            "volumeunit_iso": "",
            "gross_wt": 0,
            "net_weight": 0,
            "unit_of_wt": "",
            "unit_of_wt_iso": "",
            "item_cat": "",
            "material": "",
            "matl_type": "",
            "mvt_ind": "",
            "reval_ind": "",
            "orig_group": "",
            "orig_mat": "",
            "serial_no": 0,
            "part_acct": "",
            "tr_part_ba": "",
            "trade_id": "",
            "val_area": "",
            "val_type": "",
            "asval_date": "0000-00-00",
            "po_number": "",
            "po_item": 0,
            "itm_number": 0,
            "cond_category": "",
            "func_area_long": "",
            "cmmt_item_long": "",
            "grant_nbr": "",
            "cs_trans_t": "",
            "measure": "",
            "segment": "",
            "partner_segment": "",
            "res_doc": "",
            "res_item": 0,
            "billing_period_start_date": "0000-00-00",
            "billing_period_end_date": "0000-00-00",
            "ppa_ex_ind": "",
            "fastpay": "",
            "partner_grant_nbr": "",
            "budget_period": "",
            "partner_budget_period": "",
            "partner_fund": "",
            "itemno_tax": 0,
            "payment_type": "",
            "expense_type": "",
            "program_profile": "",
            "material_long": "",
            "housebankid": "",
            "housebankacctid": "",
            "person_no": 0,
            "acrobj_type": "",
            "acrobj_id": "",
            "acrsubobj_id": "",
            "acritem_type": "",
            "valobjtype": "",
            "valobj_id": "",
            "valsubobj_id": ""
        },
        {
            "itemno_acc": 2,
            "gl_account": "0012401100",
            "item_text": "",
            "stat_con": "",
            "log_proc": "",
            "ac_doc_no": "",
            "ref_key_1": "",
            "ref_key_2": "",
            "ref_key_3": "",
            "acct_key": "",
            "acct_type": "",
            "doc_type": "",
            "comp_code": "",
            "bus_area": "",
            "func_area": "",
            "plant": "",
            "fis_period": 0,
            "fisc_year": 0,
            "pstng_date": "0000-00-00",
            "value_date": "2023-06-02",
            "fm_area": "",
            "customer": "",
            "cshdis_ind": "",
            "vendor_no": "",
            "alloc_nmbr": "",
            "tax_code": "",
            "taxjurcode": "",
            "ext_object_id": "",
            "bus_scenario": "",
            "costobject": "",
            "costcenter": "",
            "acttype": "",
            "profit_ctr": "",
            "part_prctr": "",
            "network": "",
            "wbs_element": "",
            "orderid": "",
            "order_itno": 0,
            "routing_no": 0,
            "activity": "",
            "cond_type": "",
            "cond_count": 0,
            "cond_st_no": 0,
            "fund": "",
            "funds_ctr": "",
            "cmmt_item": "",
            "co_busproc": "",
            "asset_no": "",
            "sub_number": "",
            "bill_type": "",
            "sales_ord": "",
            "s_ord_item": 0,
            "distr_chan": "",
            "division": "",
            "salesorg": "",
            "sales_grp": "",
            "sales_off": "",
            "sold_to": "",
            "de_cre_ind": "",
            "p_el_prctr": "",
            "xmfrw": "",
            "quantity": 0,
            "base_uom": "",
            "base_uom_iso": "",
            "inv_qty": 0,
            "inv_qty_su": 0,
            "sales_unit": "",
            "sales_unit_iso": "",
            "po_pr_qnt": 0,
            "po_pr_uom": "",
            "po_pr_uom_iso": "",
            "entry_qnt": 0,
            "entry_uom": "",
            "entry_uom_iso": "",
            "volume": 0,
            "volumeunit": "",
            "volumeunit_iso": "",
            "gross_wt": 0,
            "net_weight": 0,
            "unit_of_wt": "",
            "unit_of_wt_iso": "",
            "item_cat": "",
            "material": "",
            "matl_type": "",
            "mvt_ind": "",
            "reval_ind": "",
            "orig_group": "",
            "orig_mat": "",
            "serial_no": 0,
            "part_acct": "",
            "tr_part_ba": "",
            "trade_id": "",
            "val_area": "",
            "val_type": "",
            "asval_date": "0000-00-00",
            "po_number": "",
            "po_item": 0,
            "itm_number": 0,
            "cond_category": "",
            "func_area_long": "",
            "cmmt_item_long": "",
            "grant_nbr": "",
            "cs_trans_t": "",
            "measure": "",
            "segment": "",
            "partner_segment": "",
            "res_doc": "",
            "res_item": 0,
            "billing_period_start_date": "0000-00-00",
            "billing_period_end_date": "0000-00-00",
            "ppa_ex_ind": "",
            "fastpay": "",
            "partner_grant_nbr": "",
            "budget_period": "",
            "partner_budget_period": "",
            "partner_fund": "",
            "itemno_tax": 0,
            "payment_type": "",
            "expense_type": "",
            "program_profile": "",
            "material_long": "",
            "housebankid": "",
            "housebankacctid": "",
            "person_no": 0,
            "acrobj_type": "",
            "acrobj_id": "",
            "acrsubobj_id": "",
            "acritem_type": "",
            "valobjtype": "",
            "valobj_id": "",
            "valsubobj_id": ""
        }
    ],
    "accountreceivable": [],
    "accountpayable": [],
    "accounttax": [],
    "currencyamount": [
        {
            "itemno_acc": 1,
            "curr_type": "00",
            "currency": "CNY",
            "currency_iso": "",
            "amt_doccur": 100.0000,
            "exch_rate": 0,
            "exch_rate_v": 0,
            "amt_base": 0,
            "disc_base": 0,
            "disc_amt": 0,
            "tax_amt": 0,
            "amt_doccur_long": 0,
            "amt_base_long": 0,
            "disc_base_long": 0,
            "disc_amt_long": 0,
            "tax_amt_long": 0
        },
        {
            "itemno_acc": 2,
            "curr_type": "00",
            "currency": "CNY",
            "currency_iso": "",
            "amt_doccur": -100.0000,
            "exch_rate": 0,
            "exch_rate_v": 0,
            "amt_base": 0,
            "disc_base": 0,
            "disc_amt": 0,
            "tax_amt": 0,
            "amt_doccur_long": 0,
            "amt_base_long": 0,
            "disc_base_long": 0,
            "disc_amt_long": 0,
            "tax_amt_long": 0
        }
    ],
    "criteria": [],
    "valuefield": [],
    "extension1": [],
    "return": [],
    "paymentcard": [],
    "contractitem": [],
    "extension2": [
        {
            "structure": "ZSENBSEG",
            "valuepart1": "000000000140      字段一       字段二       字段三       字段四       字段五",
            "valuepart2": "",
            "valuepart3": "",
            "valuepart4": ""
        },
        {
            "structure": "ZSENBSEG",
            "valuepart1": "000000000250      字段一       字段二       字段三       字段四       字段五",
            "valuepart2": "",
            "valuepart3": "",
            "valuepart4": ""
        }
    ],
    "realestate": [],
    "accountwt": []
}
View Code

测试的报文是由ABAP测试生成而来:

*&---------------------------------------------------------------------*
*& Report Z3426008A
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z3426008a.
DATA:ls_header TYPE bapiache09,
     lv_key    TYPE bapiache09-obj_key,
     lv_msg    TYPE string,
     ls_struct TYPE zsenbseg,
     lv_posnr  TYPE i.
DATA:lt_gl TYPE bapiacgl09 OCCURS 0 WITH HEADER LINE,
     lt_cr TYPE bapiaccr09 OCCURS 0 WITH HEADER LINE,
     lt_ex TYPE bapiparex OCCURS 0 WITH HEADER LINE,
     lt_rt TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

*参考会计凭证 100000006 F011 2021
ls_header-header_txt = '抬头文本'.
ls_header-comp_code = '1710'.
ls_header-doc_type = 'SA'.
*ls_header-obj_type = 'BKPF'.
ls_header-username = sy-uname.
ls_header-doc_date = sy-datum.
ls_header-pstng_date = sy-datum.
ls_header-fisc_year = sy-datum+0(4).
ls_header-fis_period = sy-datum+4(2).
ls_header-ref_doc_no = '参照字段'.

lv_posnr = lv_posnr + 1.
lt_gl-itemno_acc = lv_posnr.
lt_gl-gl_account = '0012121000'.
lt_gl-value_date = sy-datum.
APPEND lt_gl.

lt_cr-itemno_acc = lv_posnr.             " 会计凭证行项目编号
lt_cr-curr_type  = '00'.          " 货币和评估视图
lt_cr-currency   = 'CNY'.         " 货币码
lt_cr-amt_doccur = '100'.
APPEND lt_cr.

ls_struct-posnr = lv_posnr.
ls_struct-bschl = '40'.
ls_struct-rstgr = ''.
ls_struct-zzfield1 = '字段一'.
ls_struct-zzfield2 = '字段二'.
ls_struct-zzfield3 = '字段三'.
ls_struct-zzfield4 = '字段四'.
ls_struct-zzfield5 = '字段五'.
lt_ex-structure = 'ZSENBSEG'.
lt_ex-valuepart1 = ls_struct.
APPEND lt_ex.

lv_posnr = lv_posnr + 1.
lt_gl-itemno_acc = lv_posnr.
lt_gl-gl_account = '0012401100'.
lt_gl-value_date = sy-datum.
APPEND lt_gl.

lt_cr-itemno_acc = lv_posnr.      " 会计凭证行项目编号
lt_cr-curr_type  = '00'.          " 货币和评估视图
lt_cr-currency   = 'CNY'.         " 货币码
lt_cr-amt_doccur = '-100'.
APPEND lt_cr.

ls_struct-posnr = lv_posnr.
ls_struct-bschl = '50'.
ls_struct-rstgr = ''.
ls_struct-zzfield1 = '字段一'.
ls_struct-zzfield2 = '字段二'.
ls_struct-zzfield3 = '字段三'.
ls_struct-zzfield4 = '字段四'.
ls_struct-zzfield5 = '字段五'.
lt_ex-structure = 'ZSENBSEG'.
lt_ex-valuepart1 = ls_struct.
APPEND lt_ex.

DATA:BEGIN OF ls_request,
       documentheader    LIKE bapiache09,
       customercpd       LIKE bapiacpa09,
       contractheader    LIKE bapiaccahd,
       accountgl         LIKE TABLE OF bapiacgl09,
       accountreceivable LIKE TABLE OF bapiacar09,
       accountpayable    LIKE TABLE OF bapiacap09,
       accounttax        LIKE TABLE OF bapiactx09,
       currencyamount    LIKE TABLE OF bapiaccr09,
       criteria          LIKE TABLE OF bapiackec9,
       valuefield        LIKE TABLE OF bapiackev9,
       extension1        LIKE TABLE OF bapiacextc,
       return            LIKE TABLE OF bapiret2,
       paymentcard       LIKE TABLE OF bapiacpc09,
       contractitem      LIKE TABLE OF bapiaccait,
       extension2        LIKE TABLE OF bapiparex,
       realestate        LIKE TABLE OF bapiacre09,
       accountwt         LIKE TABLE OF bapiacwt09,
     END OF ls_request.

DATA:BEGIN OF ls_response,
       obj_type          LIKE  bapiache09-obj_type,
       obj_key           LIKE  bapiache09-obj_key,
       obj_sys           LIKE  bapiache09-obj_sys,
       accountgl         LIKE TABLE OF bapiacgl09,
       accountreceivable LIKE TABLE OF bapiacar09,
       accountpayable    LIKE TABLE OF bapiacap09,
       accounttax        LIKE TABLE OF bapiactx09,
       currencyamount    LIKE TABLE OF bapiaccr09,
       criteria          LIKE TABLE OF bapiackec9,
       valuefield        LIKE TABLE OF bapiackev9,
       extension1        LIKE TABLE OF bapiacextc,
       return            LIKE TABLE OF bapiret2,
       paymentcard       LIKE TABLE OF bapiacpc09,
       contractitem      LIKE TABLE OF bapiaccait,
       extension2        LIKE TABLE OF bapiparex,
       realestate        LIKE TABLE OF bapiacre09,
       accountwt         LIKE TABLE OF bapiacwt09,
     END OF ls_response.

ls_request-documentheader   = ls_header.
ls_request-accountgl[]      = lt_gl[].
ls_request-currencyamount[] = lt_cr[].
ls_request-extension2[]     = lt_ex[].

DATA:lv_fname    TYPE string,
     lv_request  TYPE string,
     lv_response TYPE string.

lv_fname = `BAPI_ACC_DOCUMENT_POST`.
lv_request  = /ui2/cl_json=>serialize( data = ls_request compress = abap_false pretty_name = 'L' ).
PERFORM frm_call_function USING lv_fname lv_request CHANGING lv_response.
/ui2/cl_json=>deserialize( EXPORTING json = lv_response pretty_name = 'X' CHANGING data = ls_response ).

FORM frm_call_function USING iv_fname TYPE string
                             iv_request TYPE string
                    CHANGING ov_response TYPE string.
  DATA:lv_url      TYPE string,
       lv_hostname TYPE string,
       lv_port     TYPE string.

  CALL FUNCTION 'TH_GET_VIRT_HOST_DATA'
    EXPORTING
      protocol = 0
      virt_idx = 0
    IMPORTING
      hostname = lv_hostname
      port     = lv_port.

  lv_url = 'http://' && lv_hostname && ':' && lv_port && '/abapapi/' && iv_fname.
  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = lv_url
    IMPORTING
      client             = DATA(lo_http_client)
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

  lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
  lo_http_client->authenticate( EXPORTING username = CONV string( 'HTTP_USER' ) password = CONV string( '123qazQAZ' ) ).
  "lo_http_client->request->set_content_type( content_type = 'application/json; charset=utf-8' ).
  lo_http_client->request->set_method( if_http_request=>co_request_method_post ).
  lo_http_client->request->set_header_field( name = if_http_header_fields=>content_type value = 'application/json; charset=utf-8' ).
  lo_http_client->request->set_cdata( data   = iv_request offset = 0 length = strlen( iv_request ) ).
  lo_http_client->send(  EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 ).
  lo_http_client->receive( EXCEPTIONS http_communication_failure = 1 http_invalid_state  = 2 http_processing_failed = 3 ).
  lo_http_client->get_last_error( IMPORTING message = DATA(lv_message) code = DATA(lv_code) ).
  ov_response = lo_http_client->response->get_cdata( ).
  lo_http_client->close( ).
ENDFORM.
View Code

9.2在header页签输入参数:Commit,值为X,目的是提交数据

 

9.3,在左上角切换环境进行发送测试,如有COOKie干扰测试,可以删除COOKie,点击发送并保存

 

10已经成功生成会计凭证

 11.进到SAP系统,使用事务码FB03查看该会计凭证

 

12.同理也可以调用其他SAP提供的函数或者自开发的函数

13.点击左下角的“文档模式”,切换编辑模式,将测试的报文进行修改,按项目要求生成对方能够理解的接口定义书

 14.点击修改文档页签,点击“JSON/XML智能识别、快捷导入”按钮,将测试报文粘贴后,会自动转成测试的结构对象,按转义将项目要求的字段和字段描述加上,用不上的字段可以保留或者剔除

 

15.如果网络涉及到代理和证书,点击右上角设置按钮,可以配置代理和证书

 

 

标签:调用,LIKE,lt,lv,ABAP,ls,TABLE,APIFOX,type
From: https://www.cnblogs.com/1187163927ch/p/17452014.html

相关文章

  • Jmeter:Beanshell调用java代码的三种方式
    阅读文本大概需要3分钟。0x01:BeanShell控制界面介绍每次调用前重置bsh.Interpreter:可以选择True和False。如果此选项为True,则将为每个取样器重新创建解释器。传递给BeanShell的参数(=>StringParametersandString[]bsh.args):传递给BeanShell脚本的参数,参数存在以下变量中。Param......
  • 《深度剖析CPython解释器》16. Python函数机制的深度解析(第三部分): 闭包的底层实现
    https://www.cnblogs.com/traditional/p/13580694.html楔子上一篇我们看了函数是如何调用的,这一次我们看一下函数中局部变量的访问、以及闭包相关的知识。函数中局部变量的访问我们说过函数的参数和函数内部定义的变量都属于局部变量,所以它也一样是通过静态的方式进行访问。......
  • Windows 下 JNA 调用动态链接库 dll
    1.创建动态链接库项目创建jnaTest项目下一步中填写项目名称和存储的目录;然后直接创建即可创建结果2.定义头文件#pragmaonce#ifndefJNA_TEST_H#defineJNA_TEST_H#ifdef__cplusplusextern"C"{#endif__declspec(dllexport)intadd(inta,intb);__declspec......
  • ingress 调用istio ingress 控制器
    清理环境[root@k8s-master01httpbin]#  kubectldelete-fhttpbin-gateway1.yaml-nistiogateway.networking.istio.io"httpbin-gateway"deletedvirtualservice.networking.istio.io"httpbin"deleted[root@k8s-master01httpbin]#[root@k8s-master......
  • VB运行库+FlashPlayer国际去广告版安装脚本(支持静默安装封装部署时调用)
    前言:此脚本可静默安装VB运行库和flash国际版三合一程序,flash是去广告最新版,已测试不会有乱七八糟的弹窗广告,绿色无毒!!制作脚本的目的主要是为了离线封装系统时方便在部署阶段调用安装支持库。个人认为,离线封装系统是最绿色的,避免了二次封装破坏系统的稳定性,而且第三方封装工具都......
  • API接口调用的优势以及获取方式
     API接口调用的优势:简化了系统集成:API接口提供了一种方便、快捷的方式,允许不同的系统之间进行通信和集成,降低了系统集成的难度和复杂度。提供了标准化的接口:API接口通常采用标准化的协议和数据格式,方便不同系统之间进行交换和共享信息。提高了数据安全性:API接口可以......
  • 有赞 调用 api 接口(有赞开放平台)
    ps:先注册有赞账号有赞https://www.youzan.com/有赞开放平台http://open.youzan.com/有赞开发者后台http://open.youzan.com/developer/app/index接入说明:http://open.youzan.com/docAPI文档:http://open.youzan.com/api***********************************************......
  • 【Python】【Flask】前端调用后端方法
    后端代码:@app.route("/test",methods=['POST','GET'])deftest():return"我是测试的"前端代码:1、使用<a>标签<ahref="{{url_for('test')}}">我是测试</a>这个是最简单的,点击一下,就自动跳转了。2、使用<button>......
  • QA|外部调用类方法总报错missing 1 required positional argument:'self'|UI自动化
    外部调用类方法总报错missing1requiredpositionalargument:'self' 原因:实例化这个类实例化错了,少了括号()解决:改成如下就可以了 参考学习:调用类方法时报错:missing1requiredpositionalargument:'self'-hehehe_wy7-博客园(cnblogs.com) ......
  • ES transport client底层是netty实现,netty本质上是异步方式,但是netty自身可以使用sync
    EStransportclient底层是netty实现,netty本质上是异步方式,但是netty自身可以使用sync或者await(future超时机制)来实现类似同步调用!因此,EStransportclient可以同步调用也可以异步(不过底层的socket必然是异步实现)。发送端例子对于javaclient的数据发送(这里以bulk为例),写过的人都知......