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

相关文章

mysqld_multi在Linux服务器上运行多个MySQL实例

《mysqld_multi在Linux服务器上运行多个MySQL实例》在Linux系统上使用mysqld_multi来启动和管理多个MySQL实例是一种常见的做法,这种方式允许你在同一台机器上运行多个... 目录1. 安装mysql2. 配置文件示例配置文件3. 创建数据目录4. 启动和管理实例启动所有实例

Spring IOC的三种实现方式详解

《SpringIOC的三种实现方式详解》:本文主要介绍SpringIOC的三种实现方式,在Spring框架中,IOC通过依赖注入来实现,而依赖注入主要有三种实现方式,构造器注入、Setter注入... 目录1. 构造器注入(Cons编程tructor Injection)2. Setter注入(Setter

Java function函数式接口的使用方法与实例

《Javafunction函数式接口的使用方法与实例》:本文主要介绍Javafunction函数式接口的使用方法与实例,函数式接口如一支未完成的诗篇,用Lambda表达式作韵脚,将代码的机械美感... 目录引言-当代码遇见诗性一、函数式接口的生物学解构1.1 函数式接口的基因密码1.2 六大核心接口的形态学

Spring IOC控制反转的实现解析

《SpringIOC控制反转的实现解析》:本文主要介绍SpringIOC控制反转的实现,IOC是Spring的核心思想之一,它通过将对象的创建、依赖注入和生命周期管理交给容器来实现解耦,使开发者... 目录1. IOC的基本概念1.1 什么是IOC1.2 IOC与DI的关系2. IOC的设计目标3. IOC

Spring Boot统一异常拦截实践指南(最新推荐)

《SpringBoot统一异常拦截实践指南(最新推荐)》本文介绍了SpringBoot中统一异常处理的重要性及实现方案,包括使用`@ControllerAdvice`和`@ExceptionHand... 目录Spring Boot统一异常拦截实践指南一、为什么需要统一异常处理二、核心实现方案1. 基础组件

java中的HashSet与 == 和 equals的区别示例解析

《java中的HashSet与==和equals的区别示例解析》HashSet是Java中基于哈希表实现的集合类,特点包括:元素唯一、无序和可包含null,本文给大家介绍java中的HashSe... 目录什么是HashSetHashSet 的主要特点是HashSet 的常用方法hasSet存储为啥是无序的

IDEA运行spring项目时,控制台未出现的解决方案

《IDEA运行spring项目时,控制台未出现的解决方案》文章总结了在使用IDEA运行代码时,控制台未出现的问题和解决方案,问题可能是由于点击图标或重启IDEA后控制台仍未显示,解决方案提供了解决方法... 目录问题分析解决方案总结问题js使用IDEA,点击运行按钮,运行结束,但控制台未出现http://

解决Spring运行时报错:Consider defining a bean of type ‘xxx.xxx.xxx.Xxx‘ in your configuration

《解决Spring运行时报错:Considerdefiningabeanoftype‘xxx.xxx.xxx.Xxx‘inyourconfiguration》该文章主要讲述了在使用S... 目录问题分析解决方案总结问题Description:Parameter 0 of constructor in x

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

JSON字符串转成java的Map对象详细步骤

《JSON字符串转成java的Map对象详细步骤》:本文主要介绍如何将JSON字符串转换为Java对象的步骤,包括定义Element类、使用Jackson库解析JSON和添加依赖,文中通过代码介绍... 目录步骤 1: 定义 Element 类步骤 2: 使用 Jackson 库解析 jsON步骤 3: 添