ABAP--一个极好的调用外部java程序的Search Help Exit的实例(RFC好例子)

2024-01-10 07:20

本文主要是介绍ABAP--一个极好的调用外部java程序的Search Help Exit的实例(RFC好例子),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

 

Connecting to an external source via Java Connector
(By Bob Billings)
Overview... 1
1st. The Collective Search Help. 2
2nd. The Elementary Search Help. 3
3rd. The View that supports the Elementary Search Help. 3
4th. The SM59 transaction defining the RFC destination connection.4
5th. ABAP. 4
6th. JAVA.. 6
Overview
In the process of SAP Order Entry (VA01) it became necessary to provide a “fuzzy” search help from an external source using the Java Connector for a material lookup. I.e. SAP does not store all the possible search options to return a material number. Additional searchable fields related to a material are maintained in an external system and we want to search on these fields.
The way this was accomplished was through an Elementary search help that used the search help exit to connect via a remote function call to the Java Connector. The Elementary search help was then added to a Collective search help via the Included search help list and connected using the parameter assignment button. 
Three code snippets follow:
  • The function call which accepts the request and processes the results,
  •    
  • the remote function which is merely a conduit to and from the remote destination, and
  •    
  • a part of the Java code that accepts input from SAP and returns an internal table of results.
1st. The Collective Search Help
2nd. The Elementary Search Help
3rd. The View that supports the Elementary Search Help
4th. The SM59 transaction defining the RFC destination connection.
 
5th. ABAP
The global data top include for the actual exit contains the following:
type-pools shlp.
type-pools f4typ. "Brücke zu alten F4-Bausteinen
tables: ddshdefsh. "Tabelle der Default-Suchhilfen
data %shlpname like dd30v-shlpname.   
constants: par%domname like ddshfprop-fieldname value 'DOMNAME',
par%value like ddshfprop-fieldname value 'VALUE',
par%text like ddshfprop-fieldname value 'TEXT',
par%_low like ddshfprop-fieldname value'_LOW',
par%_high like ddshfprop-fieldname value'_HIGH',
par%_text like ddshfprop-fieldname value'_TEXT',
par%rollname like ddshfprop-fieldname value 'ROLLNAME',
par%tabname like ddshfprop-fieldname value 'TABNAME'.
Search help exit definition:
FUNCTION Z_F4_ZMAT_EXIT.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*"      SHLP_TAB TYPE SHLP_DESCR_TAB_T
*"      RECORD_TAB STRUCTURE SEAHLPRES
*" CHANGING
*"     VALUE(SHLP) TYPE SHLP_DESCR_T
*"     VALUE(CALLCONTROL) LIKE DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*"----------------------------------------------------------------------
data: matnr like mara-matnr,
maktx like makt-maktx,
desc like makt-maktx,
recs_to_return like lfa1-bbsnr,
recs_returned like lfa1-bbsnr,
is_selopt    like DDSHSELOPT,
is_shlp_tab like line of shlp_tab,
is_interface like line of shlp_tab-interface.
data: begin of it_return occurs 0.
include structure ZPM_RETURN.
data: end of it_return.
data: begin of is_disp,
filler type char005,
matnr like mara-matnr,
maktx like makt-maktx,
end   of is_disp.
data: is_return like line of it_return.
*************************************************************
Case callcontrol-step.
*************************************************************
when 'SELONE' or 'PRESEL1' or 'PRESEL' or 'DISP'.
exit.
when 'SELECT'.
clear: is_disp.
refresh: record_tab.
** Find the search item & number of lines to return
read table shlp_tab index 1 into is_shlp_tab.
read table is_shlp_tab-interface index 1 into is_interface.
if not is_interface-value is initial.
maktx = is_interface-value.
else.
read table shlp-selopt index 1 into is_selopt.
maktx = is_selopt-low.
endif.
recs_to_return = callcontrol-maxrecords.
** call dummy FM that is remotely enabled. The Java listener
** is looking for destination SAP_JAVA
CALL FUNCTION 'Z_RFC_TO_PM'
DESTINATION 'SAP_JAVA'
EXPORTING
MAKTG             = maktx
max_lines         = recs_to_return
IMPORTING
COUNT             = recs_returned
TABLES
RESULT_TAB        = it_return.
if recs_returned > 0.
** put the return table into search help display table
loop at it_return into is_return.
is_disp-matnr = is_return-matnr.
is_disp-maktx = is_return-maktx.
append is_disp to record_tab.
endloop.
else.
is_disp-matnr = '*************'.
is_disp-maktx = 'Nothing returned'.
append is_disp to record_tab.
endif.
callcontrol-step = 'DISP'.
exit.
when others.
exit.
endcase.
ENDFUNCTION.
** Remotely enabled function module
FUNCTION Z_RFC_TO_PM.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*"     VALUE(MAKTG) LIKE MAKT-MAKTG
*"     VALUE(MAX_LINES) LIKE LFA1-BBSNR
*" EXPORTING
*"     VALUE(COUNT) LIKE LFA1-BBSNR
*" TABLES
*"      RESULT_TAB STRUCTURE ZPM_RETURN
*"----------------------------------------------------------------------
ENDFUNCTION.


6th. JAVA
This is the method in server class that handles incoming RFC calls:
public void handleRequest(JCO.Function pFunction) throws java.lang.Exception
    {
        String className = resolveClassName(pFunction.getName());
if (className != null)
        {
            IMethod method = (IMethod) Class.forName(className).newInstance();
            method.execute(pFunction.getImportParameterList(),
                           pFunction.getExportParameterList(),
                           pFunction.getTableParameterList());
        } else
        {
            //Throw JCO.AbapException if we don't handle Function.
            throw new NotSupportedException();
        }
    }
And this one does the work:
public void execute(JCO.ParameterList pImportParameters,
                        JCO.ParameterList pExportParameters,
                        JCO.ParameterList pTableParameters) throws PMVSException
    {
        JCO.Table table = pTableParameters.getTable("RESULT_TAB");
        String searchString = pImportParameters.getString("MAKTG");
        int maxReturn = new Integer(pImportParameters.getString("MAX_LINES")).intValue();
try
        {
            ValuesCollection[] results = search(searchString, maxReturn);
if (results != null)
            {
                String count = "" + results.length;
                pExportParameters.setValue(count, "COUNT");
                for (int i = 0; i<results.length; i++)
                {
                    DisplayAttrValue[] vals;
                    String partnum;
                    String desc;
//Get part num
                    vals = results[i].get("A-ManufacturerPartNumber");
                    partnum = vals.length > 0 ? vals[0].getDisplayString() : "null";
//Get description
                    vals = results[i].get("A-Description");
                    desc = vals.length > 0 ? vals[0].getDisplayString() : "null";
if (partnum.length() > 18)
                    {
                        partnum = partnum.substring(0,18);
                    }
                    if (desc.length() > 40)
                    {
                        desc = desc.substring(0,40);
                    }
                    table.appendRow();
                    table.setValue(partnum, "MATNR");
                    table.setValue(desc, "MAKTX");
                }
                pTableParameters.setValue(table, "RESULT_TAB");
            } else
            {
                pExportParameters.setValue("0", "COUNT");
            }
        } catch (Exception exc)
        {
            exc.printStackTrace();
        }
    }
url: http://www.erpgenie.com/sapgenie/docs/search%20help%20to%20java.doc
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述

这篇关于ABAP--一个极好的调用外部java程序的Search Help Exit的实例(RFC好例子)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/589995

相关文章

Spring @Scheduled注解及工作原理

《Spring@Scheduled注解及工作原理》Spring的@Scheduled注解用于标记定时任务,无需额外库,需配置@EnableScheduling,设置fixedRate、fixedDe... 目录1.@Scheduled注解定义2.配置 @Scheduled2.1 开启定时任务支持2.2 创建

SpringBoot中使用Flux实现流式返回的方法小结

《SpringBoot中使用Flux实现流式返回的方法小结》文章介绍流式返回(StreamingResponse)在SpringBoot中通过Flux实现,优势包括提升用户体验、降低内存消耗、支持长连... 目录背景流式返回的核心概念与优势1. 提升用户体验2. 降低内存消耗3. 支持长连接与实时通信在Sp

Spring Boot 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

Mac系统下卸载JAVA和JDK的步骤

《Mac系统下卸载JAVA和JDK的步骤》JDK是Java语言的软件开发工具包,它提供了开发和运行Java应用程序所需的工具、库和资源,:本文主要介绍Mac系统下卸载JAVA和JDK的相关资料,需... 目录1. 卸载系统自带的 Java 版本检查当前 Java 版本通过命令卸载系统 Java2. 卸载自定

springboot下载接口限速功能实现

《springboot下载接口限速功能实现》通过Redis统计并发数动态调整每个用户带宽,核心逻辑为每秒读取并发送限定数据量,防止单用户占用过多资源,确保整体下载均衡且高效,本文给大家介绍spring... 目录 一、整体目标 二、涉及的主要类/方法✅ 三、核心流程图解(简化) 四、关键代码详解1️⃣ 设置

Java Spring ApplicationEvent 代码示例解析

《JavaSpringApplicationEvent代码示例解析》本文解析了Spring事件机制,涵盖核心概念(发布-订阅/观察者模式)、代码实现(事件定义、发布、监听)及高级应用(异步处理、... 目录一、Spring 事件机制核心概念1. 事件驱动架构模型2. 核心组件二、代码示例解析1. 事件定义

SpringMVC高效获取JavaBean对象指南

《SpringMVC高效获取JavaBean对象指南》SpringMVC通过数据绑定自动将请求参数映射到JavaBean,支持表单、URL及JSON数据,需用@ModelAttribute、@Requ... 目录Spring MVC 获取 JavaBean 对象指南核心机制:数据绑定实现步骤1. 定义 Ja

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再