QRFC的几个demo程序

关于QRFC我也没细研究,有兴趣的可以看看几个标准demo程序:


RSTRFCT0

RSTRFCT1

RSTRFCQ4


report rstrfct0 NO STANDARD PAGE HEADING.

 

TYPE-POOLS:

  abap.

 

TYPES number_type TYPE LENGTH 5.

 

PARAMETERSqname   TYPE trfcqout-qname default 'BASIS_TEST_Q1',

            rfcdest TYPE rfcdes-rfcdest default 'TRAN_TEST',

            ncall   TYPE number_type default '00001',

            nluw    TYPE number_type default '00001',

            nosend  TYPE abap_bool default abap_false,

            separate TYPE abap_bool default abap_false,

            updtask  TYPE abap_bool default abap_false.

 

PARAMETERSdisplay  TYPE abap_bool default abap_true no-DISPLAY.

 

TYPEStcpicLineTab TYPE STANDARD TABLE OF abaptext.

 

TYPESBEGIN OF displayLine,

        dest TYPE rfcdest,

        tid  TYPE arfctid,

        xcall TYPE i       the x.luw

       END OF displayLine.

 

TYPESdisplayLineTab TYPE STANDARD TABLE OF displayLine.

 

*----------------------------------------------------------------------*

      CLASS lcl_main DEFINITION

*----------------------------------------------------------------------*

CLASS lcl_main DEFINITION FINAL .

 

  PUBLIC SECTION.

 

    CLASS-METHODSrun.

 

    METHODSconstructor

              IMPORTING i_qname TYPE trfcqout-qname

                        i_dest  TYPE rfcdes-rfcdest

                        i_ncall TYPE number_type

                        i_nluw  TYPE number_type

                        i_nosend TYPE abap_bool

                        i_separate TYPE abap_bool

                        i_updtask TYPE abap_bool

                        i_display TYPE abap_bool,

 

             create_luws_on_commit.

 

  PRIVATE SECTION.

 

    DATAl_qname TYPE trfcqout-qname,

          l_dest  TYPE rfcdes-rfcdest,

          l_ncall TYPE number_type,

          l_nluw  TYPE number_type,

          l_nosend TYPE abap_bool,

          l_separate TYPE abap_bool,

          l_updtask TYPE abap_bool,

          l_display TYPE abap_bool.

 

    DATAlt_result TYPE TABLE OF displayLine .

 

    METHODSfill_tcpic_table

              IMPORTING i_len type I

                        i_qname type trfcqout-qname

              CHANGING  it_tcpic type tcpicLineTab,

 

              get_tid

                IMPORTING i_dest TYPE rfcdest

                RETURNING VALUE(e_tidTYPE arfctid,

 

              append_to_result_tab

                IMPORTING x_call type sy-index,

 

              display_result

                IMPORTING x_luw TYPE sy-index

                          i_subrc TYPE abap_bool

                          i_display type abap_bool.

ENDCLASS.

 

*----------------------------------------------------------------------*

      CLASS lcl_main IMPLEMENTATION

*----------------------------------------------------------------------*

CLASS lcl_main IMPLEMENTATION.

 

 

 **********************************************************************

  METHOD     run

  Created    07.11.2007 13:14:07

 *********************************************************************

  METHOD run .

 

    DATAl_appl TYPE REF TO lcl_main.

 

    CREATE OBJECT l_appl

      EXPORTING i_qname qname

                i_dest  rfcdest

                i_ncall ncall

                i_nluw  nluw

                i_nosend nosend

                i_separate separate

                i_updtask updtask

                i_display display.

 

    l_appl->create_luws_on_commit).

 

  ENDMETHOD"run

 

 **********************************************************************

  METHOD     constructor

  Created    07.11.2007 15:38:04

 *********************************************************************

  METHOD constructor .

 

  initial the destination

    me->l_qname    i_qname.

    me->l_dest     i_dest.

    me->l_ncall    i_ncall.

    me->l_nluw     i_nluw.

    me->l_nosend   i_nosend.

    me->l_separate i_separate.

    me->l_updtask  i_updtask.

    me->l_display i_display.

 

  ENDMETHOD"constructor

 

 

 **********************************************************************

  METHOD     fill_tcpic_table

  Created    07.11.2007 15:38:31

 the method is used to initial the table which will be used in the function call

 *********************************************************************

  METHOD fill_tcpic_table .

 

    DATAlinenr type number_type,

          etext TYPE abaptext value          Line No.:           '"#EC NOTEXT

 

    if i_len 0.

      RETURN.

    endif.

 

    etext i_qname.

    etext 40(32'12345678901234567890123456789012'.

 

    do i_len TIMES.

 

      linenr linenr   1.

      etext 20(6linenr.

      APPEND etext to it_tcpic.

 

    enddo.

 

  ENDMETHOD"fill_tcpic_table

 

 

**********************************************************************

  METHOD     create_luws_commit1

  Created    07.11.2007 15:32:18

  Call TRFC_QUEUE_INITIALIZE is neccessary because working with

  "Mischbetrieb" (QRFC and TRFC in one LUW) and the call is TRFC-call

 *********************************************************************

  METHOD create_luws_on_commit .

 

    DATAl_len    TYPE VALUE 1.

 

    DATAlt_tcpic TYPE tcpicLineTab.

 

    DATAr_subrc TYPE abap_bool.

 

    r_subrc abap_true.

 

    fill_tcpic_tableEXPORTING i_len    l_len

                                i_qname  me->l_qname

                      CHANGING  it_tcpic lt_tcpic ).

 

    DO me->l_nluw  TIMES.

 

    Update task and qRFC in commit work

      if me->l_updtask abap_true.

 

        CALL FUNCTION 'STFC_CALL_QRFC' IN UPDATE TASK

          EXPORTING

            QNAME         me->l_qname

            DEST          me->l_dest

            NCALL         1

            NOSEND        me->l_nosend

            QMESS         space .

 

      endif.

 

      DO me->l_ncall  TIMES.

 

      Set Queue Name for the next qRFC-call

        CALL FUNCTION 'TRFC_SET_QUEUE_NAME'

          EXPORTING

            QNAME                    me->l_qname

            NOSEND                   me->l_nosend

         EXCEPTIONS

           INVALID_QUEUE_NAME       1

           OTHERS                   .

 

        if sy-subrc <> 0.

          r_subrc abap_false.

          exit.

        endif.

 

      The call has the same TID like the TID of the previous call.

        if me->l_separate abap_false.

 

          CALL FUNCTION 'STFC_WRITE_TO_TCPIC'

            in BACKGROUND TASK

            DESTINATION me->l_dest

            TABLES

              TCPICDAT            lt_tcpic.

 

        else.

        The call will be assigned with new TID

          CALL FUNCTION 'STFC_WRITE_TO_TCPIC'

            in BACKGROUND TASK

            AS SEPARATE UNIT

            DESTINATION me->l_dest

            TABLES

              TCPICDAT            lt_tcpic.

 

        endif.

 

      append the created QRFC luw in the result table

        append_to_result_tabx_call sy-index ).

 

      ENDDO.

 

      COMMIT WORK.

 

      display_resultx_luw sy-index

                      i_subrc r_subrc

                      i_display me->l_display ).

 

 

    ENDDO.

 

  ENDMETHOD"create_luws_commit1

 

 

 **********************************************************************

  METHOD     get_tid

  Created    07.11.2007 15:07:31

  get the TID of the created LUW

 *********************************************************************

  METHOD get_tid .

 

    CALL FUNCTION 'ID_OF_BACKGROUNDTASK'

     EXPORTING

       DEST          i_dest

     IMPORTING

       TID           e_tid .

 

  ENDMETHOD"get_tid

 

 

 **********************************************************************

  METHOD     display_result

  Created    07.11.2007 15:37:49

 *********************************************************************

  METHOD display_result .

 

    FIELD-SYMBOLS  TYPE displayLine.

 

    if i_display abap_true.

 

      if i_subrc abap_false.

        WRITE'Error while calling of TRFC_SET_QUEUE_NAME'  "#EC NOTEXT

        RETURN.

      endif.

 

      write'LUW-No. :'x_luw"#EC NOTEXT

      write'No. of Calls :'me->l_ncall Queue Name:'me->l_qname"#EC NOTEXT

      skip 1.

 

      WRITEat /3(32'Destination' 36(24)'TID'66 'x.call'  "#EC NOTEXT

      WRITE'-----------------------------------------------------------------------------'.

      LOOP AT me->lt_result ASSIGNING  .

 

        if  IS ASSIGNED.

          WRITEAT /3(32-dest36(24-tid66 -xcall.

        endif.

 

      ENDLOOP.

      refresh me->lt_result.

      SKIP 2.

 

    else.

 

      SORT lt_result BY tid xcall.

    export the result table, thus the unittest can retrieve it and compare it with the database result

      EXPORT

        ex_tab me->lt_result

        to MEMORY ID '%_RSTRFCT0'.

 

    endif.

 

  ENDMETHOD"display_result

 

 

 **********************************************************************

  METHOD     append_to_result_tab

  Created    07.11.2007 15:03:25

 *********************************************************************

  METHOD append_to_result_tab .

 

    datal_result TYPE displayLine.

 

    l_result-dest me->l_dest.

    l_result-tid  get_tidi_dest me->l_dest ).

    l_result-xcall x_call.

    APPEND l_result to lt_result.

 

  ENDMETHOD"append_to_result_tab

 

 

ENDCLASS.

 

 

**************************************************************

this class is used for unittest

**************************************************************

CLASS lcl_unittest DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION MEDIUM FINAL.

 

  PRIVATE SECTION.

 

    CONSTANTSqname TYPE trfcqout-qname VALUE 'RSTRFCT0'.

 

    DATAdest TYPE rfcdes-rfcdest VALUE 'RSTRFCT0'.

 

    METHODSdo_unittest1 FOR TESTING,

 

             get_luws_in_db CHANGING ct_result_db TYPE displayLineTab.

 

ENDCLASS.

 

*----------------------------------------------------------------------*

      CLASS lcl_unittest IMPLEMENTATION

*----------------------------------------------------------------------*

CLASS lcl_unittest IMPLEMENTATION            "lcl_unittest DEFINITION

 

  method do_unittest1.

 

    DATAdb_tab TYPE displayLineTab,

          rep_tab TYPE displayLineTab.

 

  delete old queue

    CALL FUNCTION 'TRFC_QOUT_DELETE_QUEUE'

      EXPORTING

        QNAME                 qname

        DEST                  dest .

 

    SUBMIT RSTRFCT0 with qname qname

                    WITH rfcdest dest

                    WITH nosend 'X'

                    WITH display abap_false

                    AND RETURN.

 

 

  import the result table from the memory.

    IMPORT

      ex_tab rep_tab[]

      FROM MEMORY ID '%_RSTRFCT0'.

 

    if sy-subrc 0.

      FREE MEMORY ID '%_RSTRFCT0'.

    endif.

 

  get the LUWs from the QRFC tables

    get_luws_in_dbCHANGING ct_result_db db_tab ).

 

    cl_aunit_assert=>assert_equals(

        exp rep_tab

        act db_tab ).

 

  delete the created queue

    CALL FUNCTION 'TRFC_QOUT_DELETE_QUEUE'

      EXPORTING

        QNAME                 qname

        DEST                  dest .

 

  endmethod                                    "do_unittest1

 

 **********************************************************************

  METHOD     get_luws_in_db

  Created    08.11.2007 15:51:16

 *********************************************************************

  METHOD get_luws_in_db  .

 

    DATAlt_states TYPE STANDARD TABLE OF arfcsstate,

          l_tid TYPE arfctid,

          l_result TYPE displayLine.

 

    FIELD-SYMBOLS TYPE arfcsstate.

 

    SELECT FROM arfcsstate

      APPENDING TABLE lt_states

      WHERE arfcdest me->dest

      AND   arfcreturn 'O'.

 

    LOOP at lt_states ASSIGNING .

 

      l_result-dest -arfcdest.

      l_tid-arfcipid -arfcipid.

      l_tid-arfcpid -arfcpid.

      l_tid-arfctime -arfctime.

      l_tid-arfctidcnt -arfctidcnt.

      l_result-tid l_tid.

      l_result-xcall -arfcluwcnt.

 

      APPEND l_result to ct_result_db.

 

    ENDLOOP.

 

    SORT ct_result_db BY dest xcall.

 

  ENDMETHOD"get_luws_in_db

 

ENDCLASS                   "lcl_unittest IMPLEMENTATION

 

START-OF-SELECTION.

 

  lcl_main=>run).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值