Click here to load reader

***** Function(RFC) 작성 방법 *****

  • Upload
    thom

  • View
    439

  • Download
    1

Embed Size (px)

DESCRIPTION

***** Function(RFC) 작성 방법 *****. 1. Function Group 을 만든다. 2. 생성된 Function Group 에 Function Module 을 만든다. 3. Function Module 작성 3.1 Attributes 탭 작성. * Nomal Function Module 선택 : local 에서만 사용 가능 * Remote-Enabled Module 선택 : 다른 SAP 서버 / 이기종 서버와의 인터페이스 가능 (RFC). - PowerPoint PPT Presentation

Citation preview

  • ***** Function(RFC) *****1. Function Group .

  • 2. Function Group Function Module .

  • 3. Function Module 3.1 Attributes * Nomal Function Module : local * Remote-Enabled Module : SAP/ (RFC)

  • 3. Function Module 3.2 import - () . , .RFC . .

  • 3. Function Module 3.3 export - .

  • 3. Function Module 3.4 Tables - function module . - (PERFORM ).

  • 3. Function Module 3.5 Exceptions - () . - Raise ( .)

  • FUNCTION ZTEST_FUNCTION_MODULE_01.*"----------------------------------------------------------------------*"*"Local Interface:*" IMPORTING*" VALUE(INPUT1) TYPE I OPTIONAL*" VALUE(INPUT2) TYPE I OPTIONAL*" VALUE(STATUS) TYPE ZZSTATUS_KJL OPTIONAL*" VALUE(CARRID) TYPE ZFLIGHT_KJL-CARRID OPTIONAL*" EXPORTING*" REFERENCE(OUTPUT) TYPE P*" REFERENCE(OUTVALUE) TYPE CHAR10*" TABLES*" ITAB STRUCTURE ZFLIGHT_KJL OPTIONAL*" EXCEPTIONS*" NOTFOUND*" OTHERS*"----------------------------------------------------------------------

    OUTPUT = INPUT1 * INPUT2.

    IF STATUS = '1'. OUTVALUE = 'ING'. ELSEIF STATUS = '2'. OUTVALUE = 'COMP'. ENDIF.

    SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE CARRID = CARRID.

    IF SY-SUBRC 0. RAISE NOTFOUND. Exception ENDIF.

    ENDFUNCTION.3. Function Module 3.6 Source code : .

  • *&-----------------------------------------------------**&*& Report ZTEST_FUNCTION_MODULE_01*& *& < FUNCTION MODULE >*& - Function Module Pattern .*& - Function Module *& .*&*&-----------------------------------------------------*

    REPORT ztest_function_module_01.

    DATA: g_output TYPE p, g_outvalue(10) TYPE c.

    DATA: it_flight TYPE TABLE OF zflight_kjl, wa_flight TYPE zflight_kjl.

    PARAMETERS: p_input1 TYPE i, p_input2 TYPE i, p_status LIKE zflight_kjl-status, p_carrid LIKE zflight_kjl-carrid.

    START-OF-SELECTION.

    * Function call pattern . CALL FUNCTION 'ZTEST_FUNCTION_MODULE_01' EXPORTING input1 = p_input1 input2 = p_input2 status = p_status carrid = p_carrid IMPORTING output = g_output outvalue = g_outvalue TABLES itab = it_flight EXCEPTIONS notfound = 1 others = 2.

    IF sy-subrc = 1. MESSAGE i888(sabapdocu) WITH 'NOTHING'. ELSEIF sy-subrc = 2. MESSAGE i888(sabapdocu) WITH 'OTHERS ERROR!'. ENDIF.

    WRITE:/ p_input1, ' * ' , p_input2, ' = ', g_output, :/ 'STATUS : ', p_status, '(', g_outvalue, ')'.

    DESCRIBE TABLE it_flight LINES sy-tfill. SKIP.

    IF sy-tfill 0. LOOP AT it_flight INTO wa_flight. WRITE:/ wa_flight-carrid, 10 wa_flight-connid, 20 wa_flight-fldate, 30 wa_flight-price, 50 wa_flight-seatsmax, 60 wa_flight-seatsocc. ENDLOOP. ENDIF.

    * IF IT_FLIGHT[] IS INITIAL. * ENDIF.

    4. Program Function Module .************************************************************* SELECT ************************************************************** 1. DESCRIBE TABLE LINES * - sy-tfill * 0 IF . * 2. IF IT_FLIGHT[] IS INITIAL.* ENDIF.* - INITIAL .*************************************************************

  • : []rfc import optional passvalue .. [5] [2008-01-04 16:53] : IP: 58.103.***. | PL: 1143 :30 : 102 | : 7 :7 . . rfc importoptional passvalue . .. . . e-abap | IP: 211.181.***. | PL: 6861 | : 68 | : 1 [2008-01-07 09:48] 1. optional

    - import .

    , .

    2. pass value

    - import function module ,

    .

    , call by value

    .

    rfc pass value

    pass value .

    Web In Abap | IP: 210.94.***. | PL: 1339 | : 80 | : 2 [2008-01-07 14:24] ... 1 ??? ... rfc pass value . ? pass value ~ e-abap | IP: 211.181.***. | PL: 6861 | : 68 | : 1 [2008-01-07 14:29] . . | IP: 58.103.***. | PL: 1143 | : 30 | : 7 [2008-01-14 11:01] Web In Abap . | IP: 211.219.***. | PL: 379 | : 12 | : 7 [2008-02-09 15:11] .

  • : RFC . .[5][2007-04-16 13:40] :IP: 211.54.***.|PL: 385 :7 : 466|: 131 :7 RFC . RFC . . . RFC . . e-abap|IP: 211.181.***.|PL: 6861|: 68|: 1 [2007-04-16 13:44] RFC . SE37 REMETE-ENABLED MODULE . , R/3 EAI . e-abap|IP: 211.181.***.|PL: 6861|: 68|: 1 [2007-04-16 13:46] http://ecbase.dyndns.org/zb/bbs/zboard.php?id=onepaper&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=130. |IP: 211.54.***.|PL: 385|: 7|: 7 [2007-04-16 13:56] .... . .... ......... . sapDB .... ?...select ? . e-abap|IP: 211.181.***.|PL: 6861|: 68|: 1 [2007-04-16 14:00] . .r/3 eai . . e-abap|IP: 211.181.***.|PL: 6861|: 68|: 1 [2007-04-16 15:04] http://ecbase.dyndns.org/zb/bbs/zboard.php?id=onepaper&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=131~

  • Dynamic Internal Table Subramanian Venkateswaran Company: L&T Infotech Nov. 19, 2004 11:45 PM Permalink On searching the ABAP forums, I did find many queries (in fact, there were a few queries last week as well) to create a dynamic internal table. I have identified a couple of scenarios and methods by which we can create a dynamic internal table. Tools Required Knowledge on data references, field-symbols is an added advantage, as they are extensively used in all the approaches. Create a Dynamic Internal Table Scenario 1 ------------------------------------- Assuming, in an internal table, you have entries of field names, which should be present as columns of a dynamic internal table. For e.g. we have an internal table, LT_INTERNALTABLE. Entries in LT_INTERNALTABLE are: FIELDNAME MANDT CARRID CONNID FLDATE PRICE CURRENCY To be converted to MANDT CARRID CONNID FLDATE PRICE CURRENCY 100 LH 0400 28.02.1995 899 DEM 100 LH 0454 17.11.1995 1499 DEM Data Definition *** Tables DATA: LT_DATA type ref to DATA. DATA: LT_FIELDCATALOG type LVC_T_FCAT. *** Structure DATA: LS_FIELDCATALOG type LVC_S_FCAT. *** Data References DATA: NEW_LINE type ref to data. *** Field Symbols FIELD-SYMBOLS: type ref to DATA, type any table, , . Populating the internal table with fieldnames required for our dynamic internal table LS_FIELDCATALOG-FIELDNAME = 'MANDT'. append LS_FIELDCATALOG to LT_FIELDCATALOG. LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character append LS_FIELDCATALOG to LT_FIELDCATALOG. LS_FIELDCATALOG-FIELDNAME = 'CONNID'. LS_FIELDCATALOG-INTTYPE = 'N'. append LS_FIELDCATALOG to LT_FIELDCATALOG. LS_FIELDCATALOG-FIELDNAME = 'FLDATE'. LS_FIELDCATALOG-INTTYPE = 'D'. append LS_FIELDCATALOG to LT_FIELDCATALOG. LS_FIELDCATALOG-FIELDNAME = 'PRICE'. LS_FIELDCATALOG-INTTYPE = 'P'. append LS_FIELDCATALOG to LT_FIELDCATALOG. LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'. LS_FIELDCATALOG-INTTYPE = 'C'. append LS_FIELDCATALOG to LT_FIELDCATALOG. Assigning Field-Symbol to our dynamic internal table assign LT_DATA to . Calling the method CREATE_DYNAMIC_TABLE call method cl_alv_table_create=create_dynamic_table exporting it_fieldcatalog = LT_FIELDCATALOG importing ep_table = FS_DATA exceptions generate_subpool_dir_full = 1 others = 2 . if sy-subrc 0. endif. Internal Table is ready, now to put data in that table If you check the field-symbol, , it now refers to dynamic internal table that you wanted to create at start. Next steps are to put data inside. For this, we first assign the data contents of to a field-symbol . *** So now points to our dynamic internal table. assign ->* to . *** Next step is to create a work area for our dynamic internal table. create data NEW_LINE like line of . *** A field-symbol to access that work area assign NEW_LINE->*to . *** And to put the data in the internal table select MANDT CARRID CONNID FLDATE PRICE CURRENCY from SFLIGHT into corresponding fields of table . *** Access contents of internal table loop at assigning . assign component 1 of structure to . write: / . endloop. Scenario 2 In case you know the name of the DDIC structure, then it becomes all the more simple. data: lv_tablename type string value 'SFLIGHT'. data: lv_dref type ref to DATA. CREATE DATA lv_dref type table of (lv_tablename). FIELD-SYMBOLS: TYPE STANDARD TABLE. ASSIGN lv_dref->* TO . select * from sflight into table . WAS 6.40 Approach ---------------------------------------------- Thomas Jung shares with us the approach that can be used in WAS 6.40 , which is more elegant and it removes some of the issues associated with cl_alv_table_create. report yes_tjung_sflight_test. *** Data Declaration data: sflighttype type ref to cl_abap_structdescr, tabletype type ref to cl_abap_tabledescr, comp_tabtype cl_abap_structdescr=>component_table, new_comp_tab like comp_tab, linetype type ref to cl_abap_structdescr, dref type ref to data. *** Field Symbols field-symbols: like line of comp_tab. field-symbols: type any table. sflighttype ?= cl_abap_typedescr=>describe_by_name('SFLIGHT'). comp_tab = sflighttype->get_components( ). loop at comp_tab assigning . case -name. when 'CARRID' or 'CONNID' or 'FLDATE' or 'PRICE' or 'CURRENCY'. append to new_comp_tab. endcase. endloop. linetype = cl_abap_structdescr=>create( new_comp_tab ). tabletype = cl_abap_tabledescr=>create( p_line_type = linetype p_table_kind = cl_abap_tabledescr=>tablekind_std ). create data dref type handle tabletype. assign dref->* to . select * from sflight into corresponding fields of table . field-symbols: type any. field-symbols: type any. loop at assigning . write: /. loop at new_comp_tab assigning . assign component sy-tabix of structure to . write: . endloop. endloop. For more see the comments section of this weblog, you may also find the Dynamic Function Module Interface. Also check this section of the comments, where Thomas Jung shares some important information from developers perspective : https://weblogs.sdn.sap.com/cs/user/view/cs_msg/1599 Dynamic Function Module Parameter Creation ------------------------------------------------------ 2004-11-15 06:28:52 Thomas Jung [Reply] While we are on the subject of dynamic internal table creation; here is another method. I have used this in 620 to dynamically create data areas for making RFC calls to a 46C system. I read the data type from the function Interface and then use the CREATE DATA statement. Also included are the exceptions you will probably want to catch any bad casts. ****Dynamically read the interface of the function module we are going ****to call data: irfc type table of rfc_fint_p. field-symbols: like line of irfc. call function 'RFC_GET_FUNCTION_INTERFACE_P' destination me->rfcdest exporting funcname = me->rfcfunction tables params_p = irfc exceptions fu_not_found = 1 nametab_fault = 2 others = 3. if sy-subrc 0. me->message = 'Unable to read function interface'(e05). exit. endif. ****Read the datatype of the IDATA Exporting Parameter read table irfc assigning with key paramclass = 'E' "Exporting parameter = 'IDATA'. if sy-subrc ne 0. me->message = 'Specified RFC Exit does not have the correct interface'(e06). exit. endif. data_type = -tabname. ****We need a DataType if data_type is initial. me->message = 'Data Type of Value Help can not be blank'(e02). exit. endif. ****Create a Importing Parameter for the DataType Specified data: error1 type ref to cx_sy_create_data_error . try. create data me->idata type (data_type). catch cx_sy_create_data_error into error1. me->message = error1->get_text( ). exit. endtry. data: error2 type ref to cx_sy_assign_cast_illegal_cast. data: error3 type ref to cx_sy_assign_cast_unknown_type . try. field-symbols: type standard table. assign me->idata->* to . catch cx_sy_assign_cast_illegal_cast into error2. me->message = error2->get_text( ). exit. catch cx_sy_assign_cast_unknown_type into error3. me->message = error3->get_text( ). exit. endtry. Dynamic Internal Table in 640 --------------------------------------------------------------------- 2004-11-15 05:38:35 Thomas Jung [Reply] Since you mentioned that this can be done easier in 640, I thought I might share this 640 code sample. In 640 we have public classes and kernel support instead of dynamically generated code inside cl_alv_table_create. This give greater flexibility. report yes_tjung_sflight_test. data: sflighttype type ref to cl_abap_structdescr, tabletype type ref to cl_abap_tabledescr, comp_tab type cl_abap_structdescr=>component_table, new_comp_tab like comp_tab, linetype type ref to cl_abap_structdescr, dref type ref to data. field-symbols: like line of comp_tab. field-symbols: type any table. sflighttype ?= cl_abap_typedescr=>describe_by_name('SFLIGHT'). comp_tab = sflighttype->get_components( ). loop at comp_tab assigning . case -name. when 'CARRID' or 'CONNID' or 'FLDATE' or 'PRICE' or 'CURRENCY'. append to new_comp_tab. endcase. endloop. linetype = cl_abap_structdescr=>create( new_comp_tab ). tabletype = cl_abap_tabledescr=>create( p_line_type = linetype p_table_kind = cl_abap_tabledescr=>tablekind_std ). create data dref type handle tabletype. assign dref->* to . select * from sflight into corresponding fields of table . field-symbols: type any. field-symbols: type any. loop at assigning . write: /. loop at new_comp_tab assigning . assign component sy-tabix of structure to . write: . endloop. endloop.