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

相关文章

Java数组初始化的五种方式

《Java数组初始化的五种方式》数组是Java中最基础且常用的数据结构之一,其初始化方式多样且各具特点,本文详细讲解Java数组初始化的五种方式,分析其适用场景、优劣势对比及注意事项,帮助避免常见陷阱... 目录1. 静态初始化:简洁但固定代码示例核心特点适用场景注意事项2. 动态初始化:灵活但需手动管理代

Java使用SLF4J记录不同级别日志的示例详解

《Java使用SLF4J记录不同级别日志的示例详解》SLF4J是一个简单的日志门面,它允许在运行时选择不同的日志实现,这篇文章主要为大家详细介绍了如何使用SLF4J记录不同级别日志,感兴趣的可以了解下... 目录一、SLF4J简介二、添加依赖三、配置Logback四、记录不同级别的日志五、总结一、SLF4J

将Java项目提交到云服务器的流程步骤

《将Java项目提交到云服务器的流程步骤》所谓将项目提交到云服务器即将你的项目打成一个jar包然后提交到云服务器即可,因此我们需要准备服务器环境为:Linux+JDK+MariDB(MySQL)+Gi... 目录1. 安装 jdk1.1 查看 jdk 版本1.2 下载 jdk2. 安装 mariadb(my

SpringBoot中配置Redis连接池的完整指南

《SpringBoot中配置Redis连接池的完整指南》这篇文章主要为大家详细介绍了SpringBoot中配置Redis连接池的完整指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以... 目录一、添加依赖二、配置 Redis 连接池三、测试 Redis 操作四、完整示例代码(一)pom.

Java 正则表达式URL 匹配与源码全解析

《Java正则表达式URL匹配与源码全解析》在Web应用开发中,我们经常需要对URL进行格式验证,今天我们结合Java的Pattern和Matcher类,深入理解正则表达式在实际应用中... 目录1.正则表达式分解:2. 添加域名匹配 (2)3. 添加路径和查询参数匹配 (3) 4. 最终优化版本5.设计思

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

Java字符串操作技巧之语法、示例与应用场景分析

《Java字符串操作技巧之语法、示例与应用场景分析》在Java算法题和日常开发中,字符串处理是必备的核心技能,本文全面梳理Java中字符串的常用操作语法,结合代码示例、应用场景和避坑指南,可快速掌握字... 目录引言1. 基础操作1.1 创建字符串1.2 获取长度1.3 访问字符2. 字符串处理2.1 子字

Java Optional的使用技巧与最佳实践

《JavaOptional的使用技巧与最佳实践》在Java中,Optional是用于优雅处理null的容器类,其核心目标是显式提醒开发者处理空值场景,避免NullPointerExce... 目录一、Optional 的核心用途二、使用技巧与最佳实践三、常见误区与反模式四、替代方案与扩展五、总结在 Java

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

基于Java实现回调监听工具类

《基于Java实现回调监听工具类》这篇文章主要为大家详细介绍了如何基于Java实现一个回调监听工具类,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录监听接口类 Listenable实际用法打印结果首先,会用到 函数式接口 Consumer, 通过这个可以解耦回调方法,下面先写一个