ABAP Help Document(29):14 Data Interface and Comunication Interfaces


14.Data Interfaces and Conmunication Interfaces

          ABAP提供与其他系统交互的数据接口。

14.1Remote Function Call(RFC)

          ABAP提供的调用远程系统功能的接口。

语法:

1. CALL FUNCTION func DESTINATION dest parameter_list.

parameter_list:

[EXPORTING  p1 = a1 p2 = a2 ...]
[IMPORTING  p1 = a1 p2 = a2 ...]
[TABLES     t1 = itab1 t2 = itab2 ...]
[CHANGING   p1 = a1 p2 = a2 ...]
[EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
 [system_failure = ns [MESSAGE smess]]
[communication_failure = nc [MESSAGE cmess]]
[OTHERS = n_others]].

Synchronous RFC,同步RFC。

2. CALL FUNCTION func STARTING NEW TASK task

                [DESTINATION {dest|{IN GROUP {group|DEFAULT}}}]

                [{PERFORMING subr}|{CALLING meth} ON END OF TASK]

                parameter_list.

parameter_list:

[EXPORTING  p1 = a1 p2 = a2 ...]
[TABLES     t1 = itab1 t2 = itab2 ...]
[CHANGING   p1 = a1 p2 = a2 ...]
[EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
[system_failure = ns [MESSAGE smess]]
[communication_failure = nc [MESSAGE cmess]]
[resource_failure      = nr [MESSAGE rmess]]
[OTHERS = n_others]].

Asynchronous RFC,异步RFC。

异步调用的一下显示配置参数:

profile parameter:

rdisp/rfc_min_wait_dia_wp:Number of available dialog work processes: 1;

rdisp/rfc_max_own_used_wp:Percentage of user-specific dialog work processes: 75% ;

rdisp/rfc_max_queue: Percentage of waiting requests in dialog queue: 5%;

rdisp/rfc_max_login: Percentage of logons to the system: 90%;

rdisp/rfc_max_own_login: Percentage of own logons to system: 25%;

rdisp/rfc_max_comm_entries: Percentage of used communication entries: 90%;

语法:

RECEIVE RESULTS FROM FUNCTION func

                [KEEPING TASK]

                parameter_list.

parameter_list:

[IMPORTING  p1 = a1 p2 = a2 ...]
[TABLES     t1 = itab1 t2 = itab2 ...]
 [CHANGING   p1 = a1 p2 = a2 ...]
[EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
[system_failure = ns [MESSAGE smess]]
[communication_failure = nc [MESSAGE cmess]]
[OTHERS = n_others]].

通过RECEIVE获取异步function返回的结果。

语法:

WAIT UNTIL log_exp [UP TO sec SECONDS].

等待一段时间,执行之后语句。

3. CALL FUNCTION func IN BACKGROUND UNIT parameter_list.

Background RFC,后台RFC。

语法:CALL FUNCTION func IN BACKGROUND UNIT oref  parameter_list.

parameter_list:

EXPORTING  p1 = a1 p2 = a2 ... ]
[TABLES     t1 = itab1 t2 = itab2 ...]

oref为实现了接口IF_BGRFC_UNIT的类实例;

4. CALL FUNCTION func IN BACKGROUND TASK

                     [AS SEPARATE UNIT]

                     [DESTINATION dest]

                     parameter_list.

Transactional RFC ,推荐使用Background RFC。

          ABAP使用Tcode:SM59管理RFC Destination;

       RFC Function Exception: SYSTEM_FAILURE、COMMUNICATION_FAILURE、RESOURCE_FAILURE;

          RFC权限检查:profile parameter:auth/rfc_authority_check,配置为1,自动检查RFC权限;

       RFC Trust Relationships,使用Tcode:SMT1,配置受信任系统;

示例:DEMO_PARALLEL_RFC。

14.2 ABAP and XML

          Transformation Editor:使用Tcode:STRANS,编辑transformation程序。

1.ST

Simple Transformations(ST):描述ABAP数据到XML格式转换;

ST Command命令:

ST Command

Meaning

Callss a subtemplate

Assigns a value to data

Non-literal attribute

Call an ST program

Calls a static method or an instance method in ABAP Objects

Down casts reference variables

Initializes data

Conditional transformation

Condition for variables

Context for local data roots in subtemplates

Transformation to and from asXML

Creates objects in ABAP Objects

Conditional transformation for deserializations

Defines the transformation direction

Empty pattern

<... tt:extensible="..."...>

Extensibility of literal XML elements

Initial part of a structured type

Groups conditional transformations

Includes an ST program

<... tt:lax="..." ...>

Compares names of literal XML elements

Loops across internal tables

Defines a namespace

Component of a type

Declares parameters

Reads a variable from XML

Sets the current node

<... tt:ref="..."...>

Sets the current node for a literal XML element

Declares a data root

Defines the transformation direction

Conditional transformation for serializations

SkipsXML elements in deserializations

Defines a case distinction between conditional transformations.

Case distinctions for variables

Main template or subtemplates

Literal Text

Root element of an ST program

Type definition

Transforms elementary data objects and structures

<... tt:value-ref ="..." ...>

Short form of the transformation of elementary data objects

Declares a variable

Passes a value to ST programs, subtemplates, and ABAP methods

Passes data to ST programs and subtemplates

Writes a variable to XML

Namespaces:

1.http://www.sap.com/abapxml/types/dictionary describes the ABAP Dictionary.

2.http://www.sap.com/abapxml/types/type-pool/name describes the type group name.

3.http://www.sap.com/abapxml/types/class-pool/class describes the global class class.

4.http://www.sap.com/abapxml/types/defined/name describes the type that is defined in the current ST program using tt:type.

定义Root节点


定义Type节点

  [extensible=extensible_flag]>

ABAP数据类型:C, D, F, I, N, P, STRING, T, X or XSTRING;

定义数据

1.tt:root defines data roots for ABAP data interfaces.

2.tt:parameter defines parameters as formal parameters.

3.tt:variable defines variables as local data.

语法:

kind:in输入参数;out输出参数;in/out输入输出参数;

s-val,在串行化时有效;d-val,反串行化时有效;val,串行化反串行化都生效;

定义模板

 

定义引用

  ...  

14.3 ABAP and OLE

语法:

CREATE OBJECT ole class [NO FLUSH] [QUEUE-ONLY].

type group: OLE2;

权限检查Function: AUTHORITY_CHECK_OLE;

语法:

CALL METHOD OF ole meth [= rc]
               [EXPORTING p1 = f1 p2 = f2 ...]
               [NO FLUSH] [QUEUE-ONLY].

语法:

GET PROPERTY OF ole attr = dobj [NO FLUSH] [QUEUE-ONLY]   [EXPORTING p1 = f1 p2 = f2 ...].

语法:

SET PROPERTY OF ole attr = dobj [NO FLUSH]  [EXPORTING p1 = f1 p2 = f2 ...].

语法:

FREE OBJECT ole [NO FLUSH].

可以使用ole2方式生成excel。

14.4 UUIDS

       使用类CL_SYSTEM_UUID获取UUID。

示例:

FORM f_get_uuid.
  DATA:lo_system_uuid TYPE REF TO if_system_uuid.
  DATA:lv_uuid TYPE sysuuid_c32.
  "创建类对象
  lo_system_uuid = cl_uuid_factory=>create_system_uuid( ).
  TRY.
      lv_uuid = lo_system_uuid->create_uuid_c32( ).
      WRITE:/ lv_uuid.
  CATCH cx_uuid_error.
  ENDTRY.
ENDFORM.