智遥工作流中调用SAP基础数据

     话说公司选用智遥工作流,就是看中智遥的扩展灵活,与SAP系统交互方便。
 
     SAP系统是公司花了血本上的,公司的运作都是以SAP为基础的。要想开发出实用的工作流,难免要从SAP取数据。尤其是一些公司基本信息,很多流程都要用到,比如:工厂资料,客户资料,供应商资料,物料信息等等。
 
     通常我们要调用其他系统的数据时,直接连接他们的数据库,然后直接调用里面的数据就好了,但是SAP不允许这样直接连接他的数据库,只能通过写程序来调用SAP中的RFC程序。
 
     如果每调用一个基础数据就写一个对应的RFC,个人感觉太麻烦了,太费力了(没办法,我懒人就是这样想的);于是就想写一个通用的RFC,通过传递不同的参数,来获取到想要的基础数据。
如图: 
 
RFC代码如下: 
  1 FUNCTION ZGET_KEY_TEXT_LIST.
  2   DATA:BEGIN OF T_ZLIST OCCURS 0.
  3           INCLUDE STRUCTURE ZLIST.
  4   DATA:END OF T_ZLIST.
  5 
  6   DATA:BEGIN OF T_TEMP OCCURS 0.
  7           INCLUDE STRUCTURE ZLIST.
  8   DATA:END OF T_TEMP.
  9 
 10   T_TEMP[] = ZLIST[].
 11   IF KEY1 <> SPACE OR KEY2 <> SPACE OR KEY3 <> SPACE.
 12     CLEAR:T_TEMP.
 13     T_TEMP-KEY1 = KEY1.
 14     T_TEMP-KEY2 = KEY2.
 15     T_TEMP-KEY3 = KEY3.
 16     APPEND T_TEMP.
 17   ENDIF.
 18 
 19   IF KEY2 IS INITIAL .
 20     SORT T_TEMP BY KEY1 .
 21     DELETE ADJACENT DUPLICATES FROM T_TEMP COMPARING KEY1.
 22   ELSEIF KEY3 IS INITIAL .
 23     SORT T_TEMP BY KEY1 KEY2 .
 24     DELETE ADJACENT DUPLICATES FROM T_TEMP COMPARING KEY1 KEY2 .
 25   ELSE.
 26     SORT T_TEMP BY KEY1 KEY2 KEY3.
 27     DELETE ADJACENT DUPLICATES FROM T_TEMP COMPARING KEY1 KEY2 KEY3.
 28   ENDIF.
 29 
 30 * GET ALL OR SINGLE OR LIST IN TABLE
 31   REFRESH:T_ZLIST.
 32 
 33   IF TABLE_NAME = 'T024'."PUR.GROUP
 34     SELECT EKNAM EKGRP INTO TABLE T_ZLIST
 35       FROM T024.
 36   ELSEIF TABLE_NAME = 'TCURT'."CURRENCY
 37     SELECT LTEXT WAERS INTO TABLE T_ZLIST
 38       FROM TCURT
 39       WHERE SPRAS = 'E' .
 40   ELSEIF TABLE_NAME = 'T005T'."COUNTRY
 41     SELECT LANDX50 LAND1 INTO TABLE T_ZLIST
 42       FROM T005T
 43       WHERE SPRAS = 'E' .
 44   ELSEIF TABLE_NAME = 'BNKA'."BANK KEY
 45     SELECT BANKA BANKS BANKL INTO TABLE T_ZLIST
 46       FROM BNKA .
 47   ELSEIF TABLE_NAME = 'TINCT'."INCO TERM
 48     SELECT BEZEI INCO1 INTO TABLE T_ZLIST
 49       FROM TINCT
 50       WHERE SPRAS = 'E' .
 51   ELSEIF TABLE_NAME = 'T052U'."Payment term
 52     SELECT T052U~TEXT1 T052U~ZTERM
 53       INTO TABLE T_ZLIST
 54       FROM T052 INNER JOIN T052U ON T052~ZTERM = T052U~ZTERM
 55                                 AND T052~ZTAGG = T052U~ZTAGG
 56       WHERE T052~KOART IN ('K' , SPACE)
 57         AND T052U~SPRAS = 'E' .
 58 *ZBC 20130319 added begin
 59   ELSEIF TABLE_NAME = 'T015W'."Instruction keys
 60     SELECT DTZUS DTAWS BANKS ZLSCH INTO TABLE T_ZLIST
 61       FROM T015W .
 62   ELSEIF TABLE_NAME = 'T042Z'."Payment Methods
 63     SELECT TEXT1 ZLSCH LAND1 INTO TABLE T_ZLIST
 64       FROM T042Z .
 65   ELSEIF TABLE_NAME = 'ZVEN2'."Vendor Group
 66     SELECT VCNAME VCCODE INTO TABLE T_ZLIST
 67       FROM ZVEN2 .
 68 *ZBC 20130319 added end.
 69 
 70 *ZBC 20130408 added begin
 71   ELSEIF TABLE_NAME = 'ZCOM'."Company for Vendor creation workflow
 72     SELECT BUKRS INTO TABLE T_ZLIST
 73       FROM ZCOM .
 74   ELSEIF TABLE_NAME = 'ZPORG'."Pur.Org for Vendor creation workflow
 75     SELECT EKORG INTO TABLE T_ZLIST
 76       FROM ZPORG .
 77 *ZBC 20130408 added end.
 78 
 79 * 如果有新的Table,请加在这里即可。
 80   ELSE.
 81     RAISE TABLE_NAME_NOT_EXIST.
 82     EXIT.
 83   ENDIF.
 84 
 85   IF SY-SUBRC <> 0 .
 86     RAISE NO_DATA_FOUND.
 87   ENDIF.
 88 
 89   REFRESH:ZLIST.
 90   CLEAR:TEXT.
 91 
 92   IF T_TEMP[] IS INITIAL.
 93     LOOP AT T_ZLIST.
 94       APPEND T_ZLIST TO ZLIST.
 95       IF KEY1 = T_ZLIST-KEY1 AND KEY2 = T_ZLIST-KEY2 AND
 96          KEY3 = T_ZLIST-KEY3.
 97         TEXT = T_ZLIST-TEXT.
 98       ENDIF.
 99     ENDLOOP.
100   ELSE.
101     LOOP AT T_ZLIST.
102       READ TABLE T_TEMP WITH KEY KEY1 = T_ZLIST-KEY1
103                                  KEY2 = T_ZLIST-KEY2
104                                  KEY3 = T_ZLIST-KEY3 BINARY SEARCH.
105       IF SY-SUBRC <> 0 .
106         CONTINUE.
107       ENDIF.
108 
109       APPEND T_ZLIST TO ZLIST.
110       IF KEY1 = T_ZLIST-KEY1 AND KEY2 = T_ZLIST-KEY2 AND
111          KEY3 = T_ZLIST-KEY3.
112         TEXT = T_ZLIST-TEXT.
113       ENDIF.
114     ENDLOOP.
115   ENDIF.
116 
117 ENDFUNCTION.

智遥工作流中调用RFC代码:

//获取SAP中所有的采购组织信息
          SapRFCHelper SAPH = new SapRFCHelper();
          string k1 = "";
          string k2 = "";
          string k3 = "";
          string table_name = "T024";
          string[] param = { 
                                "KEY1|"+k1,
                                "KEY2|"+k2,
                                "KEY3|"+k3,
                                "TABLE_NAME|"+table_name                            
                            };
          DataTable dt_result = SAPH.GetRfcOutTable("Sapconn", param, "ZGET_KEY_TEXT_LIST", "ZLIST");
//Sapconn 是系统设置好的链接参数
//ZGET_KEY_TEXT_LIST 就是刚才的RFC名称
//ZLIST 就是返回的结果表名称

注:之前在网上搜过用C#调用SAP RFC的代码,一大坨,看了头痛。智遥工作流调用RFC还是挺简单的。

有些日子没写博客了,加油~~~~~

 

 
posted @ 2013-06-26 10:22  程序思考者  阅读(691)  评论(0编辑  收藏  举报