cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

"Executing a Batch Input Session --> Error: 'LEAVE TO TRANSACTION' is not allowed in Batch Input."

alexgiedt
Explorer
0 Kudos
177

Hello everyone,

I have the following problem: I created a recording of my report using the SHDB transaction. Based on this, I created a report that, simply put, saves the corresponding records when changes are made (e.g., the description is changed), clicks the back button, and processes the next record that was entered in the selection screen.

Now, the report works quite well, but when the first record is processed and it moves to the next record by clicking the back button, I receive the error: "Error: 'LEAVE TO TRANSACTION' is not allowed in Batch Input." I have tried many things, but nothing has brought the desired success. My goal is to be able to run the report, which creates a batch input session, in the background. Unfortunately, this is currently failing.

Here is the code of my report:

REPORT z_autosave.

TABLES: /opl09/anl_sts, /opl09/fa_vorrat.

CONSTANTS: lc_transaction TYPE tstc-tcode VALUE '/OPL09/INVENTUR'.

DATA: BEGIN OF bdcdata OCCURS 1000.
        INCLUDE STRUCTURE bdcdata.
DATA: END OF bdcdata.
DATA: ls_bdcdata TYPE bdcdata.

SELECT-OPTIONS: s_melnr FOR /opl09/fa_vorrat-melnr,
                s_satza FOR /opl09/fa_vorrat-satza,
                s_datum FOR /opl09/fa_vorrat-datum,
                s_bukrs FOR /opl09/fa_vorrat-bukrs OBLIGATORY,
                s_anln1 FOR /opl09/fa_vorrat-anln1,
                s_anln2 FOR /opl09/fa_vorrat-anln2,
                s_icon FOR /opl09/fa_vorrat-icon OBLIGATORY DEFAULT '@09@',   "@08@ = green, @09@ = yellow, @0A@ = red
                s_frgsts FOR /opl09/anl_sts-frg_sts OBLIGATORY DEFAULT 'NRE'. "NRE = not relevant (for workflow)

PARAMETERS: p_group TYPE apqi-groupid DEFAULT 'OPAL_AUTO'.




START-OF-SELECTION.

  AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
    ID 'BUKRS' DUMMY "FIELD p_bukrs    <----- TO BE CHANGED LATER
    ID 'ACTVT' FIELD '01'.
  IF sy-subrc NE 0.
    MESSAGE e112(fg). "WITH p_bukrs.    <----- TO BE CHANGED LATER
  ENDIF.

  SELECT v~melnr, v~anln1, v~anln2 FROM /opl09/fa_vorrat AS v JOIN /opl09/anl_sts AS s
    ON v~melnr = s~melnr
    AND s~frg_step IS INITIAL
    AND s~frg_def IS INITIAL

    WHERE v~melnr IN @s_melnr
    AND v~satza IN @s_satza
    AND v~datum IN @s_datum
    AND v~bukrs IN @s_bukrs
    AND v~anln1 IN @s_anln1
    AND v~anln2 IN @s_anln2
    AND v~icon IN @s_icon
    AND s~frg_sts IN @s_frgsts

    INTO TABLE @DATA(lt_items).

  DATA: lv_count TYPE i VALUE 0.


** Öffnen der Arbeitsmappe
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      client = sy-mandt
      group  = p_group
      user   = sy-uname
      keep   = 'X'.

  LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<fs_item>).

    " Zähler erhöhen
    lv_count = lv_count + 1.

    "Choose Process work list on main screen
    PERFORM bdc_dynpro USING '/OPL09/FA_INVENTUR' '1000'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                     '=ARBVO'.

    " fill selection screen for process work list
    PERFORM bdc_dynpro USING '/OPL09/FA_ANLAGEN_ARBVOR' '1000'.
    PERFORM bdc_field       USING 'S_MELNR-LOW'
                                     <fs_item>-melnr.      " Registration number
    PERFORM bdc_field       USING 'BDC_OKCODE' '=ONLI'.

    " click on save
    PERFORM bdc_dynpro USING '/OPL09/FA_ANLAGEN_ARBVOR' '0100'.
*    PERFORM bdc_field  USING 'S_ANLN1' <fs_item>-anln1.
*    PERFORM bdc_field  USING 'S_ANLN2' <fs_item>-anln2.
    PERFORM bdc_field       USING 'BDC_OKCODE' '=SAVE'.

    " confirm popup
    PERFORM bdc_dynpro USING 'SAPLSPO1' '0500'.
    PERFORM bdc_field       USING 'BDC_OKCODE' '=YES'.
    PERFORM bdc_field       USING 'BDC_SUBSCR'
                                     'SAPLSPO1                                0501SUBSCREEN'.

*    " Additional pop-up confirmations can be added here
*    " Example for another pop-up
*    PERFORM bdc_dynpro USING 'SAPLSPO1' '0500'.
*    PERFORM bdc_field       USING 'BDC_OKCODE' '=YES'.

*    PERFORM bdc_dynpro USING '/OPL09/FA_ANLAGEN_ARBVOR' '0100'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                     '=/EBACK'.







    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        tcode     = lc_transaction
      TABLES
        dynprotab = bdcdata.

    CLEAR bdcdata[].

  ENDLOOP.



** Schließen der Arbeitsmappe
  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.
  IF sy-subrc <> 0.
    MESSAGE 'closing batch input session failed' TYPE 'E'.
  ENDIF.

  CLEAR bdcdata[].

  " Ausgabe der Anzahl der verarbeiteten Datensätze
  WRITE: / 'Number of processed records:', lv_count.
  WRITE: / 'Batch input session successfully created.'.


*--------------------------------------------------------------------*
*                              FORMS                                 *
*                              -----                                 *
*--------------------------------------------------------------------*
*&--------------------------------------------------------------------*
*& Form BDC_DYNPRO                                                    *
*&--------------------------------------------------------------------*
*& Hilfsroutine zum Anlegen der Dynprobefehle                         *
*&--------------------------------------------------------------------*
*&  -->  program = Programmanme des Dynpro                            *
*&  -->  dynpro  = Dynpronummer                                       *
*&--------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.

  CLEAR ls_bdcdata.
  ls_bdcdata-program  = program.
  ls_bdcdata-dynpro   = dynpro.
  ls_bdcdata-dynbegin = 'X'.
  APPEND ls_bdcdata TO bdcdata.

ENDFORM.                    "bdc_dynpro
*&--------------------------------------------------------------------*
*& Form BDC_FIELD                                                     *
*&--------------------------------------------------------------------*
*& Hilfsroutine zum Anlegen der Dynprobefehle                         *
*&--------------------------------------------------------------------*
*&  -->  fnam = Feldname                                              *
*&  -->  fval = Feldwert                                              *
*&--------------------------------------------------------------------*
FORM bdc_field USING fnam fval.

  CLEAR ls_bdcdata.
  ls_bdcdata-fnam     = fnam.
  ls_bdcdata-fval     = fval.
  APPEND ls_bdcdata TO bdcdata.

ENDFORM.       

Here is the recording of my report.

alexgiedt_0-1724738550707.png

I would really appreciate your help, as I am getting a bit frustrated.

Best regards,
Alex

 

Accepted Solutions (0)

Answers (0)