Skip to Content

In SAP Cash Management, the Flow Builder plays a key role which in charge of build the source documents into the central storage of One Exposure (table FQM_FLOW). In Finance area, Flow Builder rely on the accounting documents (BKPF/BSEG entries), In MM area, Flow Builder rely on the purchase order/requisite documents (EKKO/EKPO/EKKN entries).

With respect to the volume of the legacy documents as well as the complexity of the document chain may occur, the Flow Builder had a ‘heavily’ initial loading.

Occasionally we received complains from the customer side saying the Flow Builder run out of memory with Initial Loads. We’d noticed that this scenario occurs in the customer who running SAP HANA with limited free memory, and it is the root cause.

Meanwhile, we think this issue can be avoid if the Initial Loading using smaller range of documents based on the fact that Flow Builder actually provides the functionality to build flow on Document level.

All in all, we think a small z-namespace report can make the work a little bit easier for both SAP and Customer.

Here comes the sample codes (please be aware that this report does not support background job run):

*&---------------------------------------------------------------------*
*& Report zac_flowbuilder_splitting
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zac_flowbuilder_splitting.

TABLES: fqm_flow.
TYPES: BEGIN OF ts_startdoc,
         bukrs TYPE bukrs,
         gjahr TYPE gjahr,
         belnr TYPE belnr_d,
       END OF ts_startdoc.
TYPES: ty_startdoc TYPE STANDARD TABLE OF ts_startdoc WITH DEFAULT KEY.
DATA: gt_startdoc TYPE ty_startdoc.
DATA: gv_lines LIKE sy-tfill.
DATA: gt_bseg_bukrs TYPE SORTED TABLE OF bukrs WITH UNIQUE KEY table_line.
DATA: gt_bseg_gjahr TYPE SORTED TABLE OF gjahr WITH UNIQUE KEY table_line.
"DATA: BEGIN OF ts_batch_statistics.
"DATA: batch type i.
"DATA: doc_amount type i.
"DATA: END OF TS_BATCH_STATISTICS.


SELECT-OPTIONS: so_bukrs FOR fqm_flow-company_code.
SELECT-OPTIONS: so_gjahr FOR fqm_flow-fi_fiscal_year.
PARAMETERS: p_pkgsz TYPE i DEFAULT 10000.
PARAMETERS: p_test TYPE xfeld DEFAULT space.

INITIALIZATION.
  IF sy-batch IS NOT INITIAL.
    MESSAGE E001(00) WITH 'Cannot run in background job mode!'.
  ENDIF.


START-OF-SELECTION.
  DATA lt_bukrs_fi TYPE TABLE OF rsparams.
  DATA lv_batch TYPE i.
"  DATA lt_statistics like table of ts_batch_statistics.
"  DATA ls_statistics LIKE LINE OF lt_statistics.

  CLEAR: lv_batch.
  SELECT COUNT( * ) INTO @DATA(lv_count)
    FROM BKPF
    WHERE bukrs in @so_bukrs
      AND gjahr IN @so_gjahr.

  WRITE: 'Total BKPF amount: ', lv_count.
  ULINE.

  WRITE: 5 'BATCH', 20 'Doc Amount'.
  ULINE.

  DATA l_c1 TYPE cursor.
  OPEN CURSOR @l_c1 FOR
    SELECT bukrs, gjahr, belnr
    FROM bkpf
    WHERE bukrs IN @so_bukrs
      AND gjahr IN @so_gjahr
    .
  IF sy-subrc NE 0.
    WRITE: 'Failed to open DB cursor.'.
    EXIT.
  ENDIF.

  WHILE NOT l_c1 IS INITIAL.
    ADD 1 TO lv_batch.

    IF NOT l_c1 IS INITIAL.
      FETCH NEXT CURSOR @l_c1 INTO TABLE @gt_startdoc PACKAGE SIZE @p_pkgsz.
      IF sy-subrc EQ 0.
*        CLEAR: ls_statistics.
*        ls_statistics-batch = lv_batch.
        DESCRIBE TABLE gt_startdoc LINES gv_lines.
*        APPEND ls_statistics TO lt_statistics.
        WRITE: / lv_batch UNDER 'BATCH',
                gv_lines UNDER 'Doc Amount'.

        REFRESH: gt_bseg_bukrs, gt_bseg_gjahr, lt_bukrs_fi.

        LOOP AT gt_startdoc ASSIGNING FIELD-SYMBOL(<fs_startdoc>).
          READ TABLE gt_bseg_bukrs TRANSPORTING NO FIELDS
            WITH KEY table_line = <fs_startdoc>-bukrs
            BINARY SEARCH.
          IF sy-subrc NE 0.
            INSERT <fs_startdoc>-bukrs INTO TABLE gt_bseg_bukrs.
          ENDIF.

          READ TABLE gt_bseg_gjahr TRANSPORTING NO FIELDS
            WITH KEY table_line = <fs_startdoc>-gjahr
            BINARY SEARCH.
          IF sy-subrc NE 0.
            INSERT <fs_startdoc>-gjahr INTO TABLE gt_bseg_gjahr.
          ENDIF.
        ENDLOOP.

        LOOP AT gt_bseg_bukrs ASSIGNING FIELD-SYMBOL(<fs_bseg_bukrs>).
          APPEND VALUE #(
                          selname = 'P_BUKRS'
                          kind    = 'P'
                          sign    = 'I'
                          option  = 'EQ'
                          low     = <fs_bseg_bukrs>
                        ) TO lt_bukrs_fi.
        ENDLOOP.

        LOOP AT gt_bseg_gjahr ASSIGNING FIELD-SYMBOL(<fs_bseg_gjahr>).
          APPEND VALUE #(
                          selname = 'P_GJAHR'
                          kind    = 'P'
                          sign    = 'I'
                          option  = 'EQ'
                          low     = <fs_bseg_gjahr>
                        ) TO lt_bukrs_fi.
        ENDLOOP.

        LOOP AT gt_startdoc ASSIGNING <fs_startdoc>.
          APPEND VALUE #(
                          selname = 'P_BELNR'
                          kind    = 'P'
                          sign    = 'I'
                          option  = 'EQ'
                          low     = <fs_startdoc>-belnr
                        ) TO lt_bukrs_fi.
        ENDLOOP.

        TRY.
            SUBMIT fclm_flow_builder
              WITH iv_runtp = 'M' "Mass Run
              WITH p_test   = p_test
              WITH p_showpt = abap_false
              WITH p_fi     = 'X'
              WITH p_mm     = ' '
              WITH SELECTION-TABLE lt_bukrs_fi
              AND RETURN.
          CATCH cx_root.
        ENDTRY.

      ELSE.
        CLOSE CURSOR @l_c1.
      ENDIF.
    ENDIF.
  ENDWHILE.

END-OF-SELECTION.
To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply