如何将xs javascript中的变量传递给ABAP函数

问题描述 投票:0回答:1

我已经完成了将ABAP传递给xs Javascript的任务。这将使用ODATA服务,其中带有body.data的POST请求将具有一个带有标头的对象和一个对象数组,我可以使用以下格式:

{
   "IvCompCode":"1710",
   "IvDocType":"NB",
   "IvPurchOrg":"1710",
   "IvPurGroup":"002",
   "IvVendor":"17386001",
   "ItemsSet":[
      {
         "Ebelp":"00010",
         "Matnr":"MZ-RM-M500-09",
         "Werks":"1710",
         "Lgort":"171S",
         "Menge":"5.000",
         "Netpr":"100.000"
      },
      {
         "Ebelp":"00020",
         "Matnr":"MZ-RM-M500-07",
         "Werks":"1710",
         "Lgort":"171S",
         "Menge":"4.000",
         "Netpr":"105.000"
      }
   ]
}

我可以在javascript函数中调用ABAP函数,但是,我不知道如何从ODATA服务传递变量,然后将其简单地放入ABAP函数中,同时将其保留在javascript函数中,以便可以用于另一种逻辑。这是我现在所拥有的:

<script language="JavaScript">
function callABAPMethod()
{
<%
  DATA: po_header          LIKE bapimepoheader,
        poheaderx          LIKE bapimepoheaderx,
        tab_poitem         TYPE STANDARD TABLE OF bapimepoitem,
        tab_poitemx        TYPE STANDARD TABLE OF bapimepoitemx,
        tab_poitem_struct  LIKE bapimepoitem,
        tab_poitemx_struct LIKE bapimepoitemx,
        ebelp_num(5)       TYPE n,
        ebelp_char(5)      TYPE c.


  po_header-comp_code = iv_comp_code.
  po_header-doc_type  = iv_doc_type.
  po_header-vendor = iv_vendor.
  po_header-purch_org = iv_purch_org.
  po_header-pur_group = iv_pur_group.


  poheaderx-comp_code = 'X'.
  poheaderx-doc_type = 'X'.
  poheaderx-vendor = 'X'.
  poheaderx-purch_org = 'X'.
  poheaderx-pur_group = 'X'.



  LOOP AT zpoitems INTO DATA(item).
    CLEAR: tab_poitem_struct, tab_poitemx_struct.

    tab_poitem_struct-po_item = item-ebelp.
    tab_poitem_struct-material = item-matnr.
    tab_poitem_struct-plant = item-werks.
    tab_poitem_struct-stge_loc = item-lgort.
    tab_poitem_struct-quantity = item-menge.
    tab_poitem_struct-net_price = item-netpr.


    tab_poitemx_struct-po_item = item-ebelp.
    tab_poitemx_struct-po_itemx = 'X'.
    tab_poitemx_struct-material = 'X'.
    tab_poitemx_struct-plant = 'X'.
    tab_poitemx_struct-stge_loc = 'X'.
    tab_poitemx_struct-quantity = 'X'.
    tab_poitemx_struct-net_price = 'X'.

    APPEND tab_poitem_struct TO tab_poitem.
    APPEND tab_poitemx_struct TO tab_poitemx.


  ENDLOOP.


  IF iv_update EQ 'X'.
    IF  iv_po_number IS NOT INITIAL.
      CALL FUNCTION 'BAPI_PO_CHANGE'
        EXPORTING
          purchaseorder = iv_po_number
          poheader      = po_header
          poheaderx     = poheaderx
        TABLES
          return        = return
          poitem        = tab_poitem
          poitemx       = tab_poitemx.

      IF sy-subrc = 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
      ENDIF.
    ENDIF.
  ELSE.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        poheader         = po_header
        poheaderx        = poheaderx
      IMPORTING
        exppurchaseorder = po_numer
      TABLES
        return           = et_return
        poitem           = tab_poitem
        poitemx          = tab_poitemx.

    IF sy-subrc = 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ENDIF.
  ENDIF.
%>
}


</script>
javascript sap abap hana
1个回答
-1
投票

您可以创建自定义oData服务,以将ABAP代码从js发送到后端。使用SEGW t代码创建自定义服务,并实现自己的ABAP代码以捕获请求。一些示例博客here

在后端,您可以在运行时在ABAP端创建动态程序,但通常未经系统管理员批准。代码扫描工具可能会捕获您的请求。这是有风险的,因为有人操纵您的代码并更改您的代码以无特权地访问系统。

检查GENERATE SUBROUTINE POOL语句以在运行时中运行动态ABAP代码。

© www.soinside.com 2019 - 2024. All rights reserved.