Mam metodę w ABAP:

METHOD testuj.
    DATA: ls_head      TYPE bapisdhd1,
          ls_headx     TYPE bapisdhd1x,
          lt_items     TYPE TABLE OF bapisditm,
          lt_itemsx    TYPE TABLE OF bapisditmx,
          lt_partners  TYPE TABLE OF bapiparnr,
          lt_sched     TYPE TABLE OF bapischdl,
          lt_schedx    TYPE TABLE OF bapischdlx,
          lt_cfgs_ref  TYPE TABLE OF bapicucfg,
          lt_cfgs_inst TYPE TABLE OF bapicuins,
          lt_cfgs_val  TYPE TABLE OF bapicuval,
          lt_return    TYPE TABLE OF bapiret2,
          lv_salesdoc  TYPE bapivbeln-vbeln,
          lt_cfgs_part_of TYPE TABLE OF BAPICUPRT.

    " 1. Nagłówek zwrotu ZBAR
    CLEAR ls_head.
    ls_head-doc_type   = 'ZBAR'.
    ls_head-sales_org  = 'HR01'.
    ls_head-distr_chan = 'EX'.
    ls_head-division   = '01'.
    ls_head-req_date_h = sy-datum + 14.
    ls_head-ord_reason = 'REK'."'901'.
    ls_head-po_method = 'E'.
    ls_head-ship_cond  = 'NT'.
    ls_head-purch_no_c = '25-05365'.

    CLEAR ls_headx.
    ls_headx-doc_type   = 'X'.
    ls_headx-sales_org  = 'X'.
    ls_headx-distr_chan = 'X'.
    ls_headx-division   = 'X'.
    ls_headx-req_date_h = 'X'.
    ls_headx-ord_reason = 'X'.
    ls_headx-po_method = 'X'.
    ls_headx-ship_cond = 'X'.
    ls_headx-purch_no_c = 'X'.

    " 2. Partnerzy (AG – Sold-to Party)
    DATA(ls_partner) = VALUE bapiparnr(
      partn_role = 'AG'
      partn_numb = '0000230205' ).
    APPEND ls_partner TO lt_partners.

    ls_partner-partn_role = 'WE'.            " Ship-to
    ls_partner-partn_numb = '0000230205'.
    ls_partner-unload_pt  = 'z001'.
    APPEND ls_partner TO lt_partners.

    " 3. Pozycja zwrotu
    DATA: ls_item  TYPE bapisditm,
          ls_itemx TYPE bapisditmx.

    CLEAR: ls_item, ls_itemx.
    ls_item-itm_number = '000010'.
    ls_item-material   = 'ZK_ZESP'.
    ls_item-item_categ    = 'ZZRE'.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = ls_item-material
      IMPORTING
        output = ls_item-material.

    ls_item-target_qty = '10'.
*    ls_item-target_qu = 'St.'.


    ls_itemx-itm_number    = '000010'.
    ls_itemx-material      = 'X'.
    ls_itemx-target_qty    = 'X'.
*    ls_itemx-target_qu  = 'X'.
    ls_itemx-item_categ = 'X'.

    APPEND ls_item  TO lt_items.
    APPEND ls_itemx TO lt_itemsx.

    " 4. Harmonogram dostaw (ilość i termin odbioru zwrotu)
    DATA: ls_sched  TYPE bapischdl,
          ls_schedx TYPE bapischdlx.

    CLEAR: ls_sched, ls_schedx.
    ls_sched-itm_number  = '000010'.
    ls_sched-sched_line  = '0001'.
    ls_sched-req_qty     = '10'.
    ls_sched-req_date    = sy-datum + 14.

    ls_schedx-itm_number  = '000010'.
    ls_schedx-sched_line  = '0001'.
    ls_schedx-req_qty     = 'X'.
    ls_schedx-req_date    = 'X'.

    APPEND ls_sched  TO lt_sched.
    APPEND ls_schedx TO lt_schedx.

    " 5. Konfiguracja wariantu – cecha VC_SZEROKOSC = 500
    DATA: ls_cfg_ref  TYPE bapicucfg,
          ls_cfg_inst TYPE bapicuins,
          ls_cfg_val  TYPE bapicuval,
          ls_cfg_part_of TYPE BAPICUPRT.

    ls_cfg_ref = VALUE #( config_id = '000001'
                          root_id   = '00000001'
*                      object    = 'SDI'
*                      object_id = '000010'
                          complete = 'T'
                          consistent = 'T'
                          posex = '000010'
*                          kbname  = 'PK_ZK_ZESP_PROTOTYP1'
                          KBPROFILE = 'PK_ZK_ZESP_PROTOTYP1'
                          CBASE_ID_TYPE = 'G'
                          CBASE_ID = '19A9DE65456F1EDFA1E000A8D3E9919E'
                            ).
    APPEND ls_cfg_ref TO lt_cfgs_ref.

    ls_cfg_inst = VALUE #( config_id   = '000001'
                           inst_id     = '00000001'
*                       object      = ls_item-material
*                       object_typ  = 'MARA'
                           class_type = '300'
                           obj_key = 'ZK_ZESP'
                           quantity   = 10
                           complete   = 'T'
                           consistent = 'T'
                           ).
    APPEND ls_cfg_inst TO lt_cfgs_inst.

    ls_cfg_val = VALUE #( config_id = '000001'
                          inst_id   = '00000001'
                          charc     = 'VC_FIG_L'
                          value     = '500'
                          valcode   = '2'
                          author    = '1' ).
    APPEND ls_cfg_val TO lt_cfgs_val.

    ls_cfg_val = VALUE #( config_id = '000001'
                          inst_id   = '00000001'
                          charc     = 'VC_FIG_H'
                          value     = '1000'
                          valcode   = '2'
                          author    = '1' ).
    APPEND ls_cfg_val TO lt_cfgs_val.

    ls_cfg_val = VALUE #( config_id = '000001'
                          inst_id   = '00000001'
                          charc     = 'VC_ZE_RODZ_BUT'
                          value     = 'FENZI'
                          valcode   = '2'
                          author    = '1' ).
    APPEND ls_cfg_val TO lt_cfgs_val.

    ls_cfg_val = VALUE #( config_id = '000001'
                          inst_id   = '00000001'
                          charc     = 'VC_ZE_USZCZ'
                          value     = 'DC993'
                          valcode   = '2'
                          author    = '1' ).
    APPEND ls_cfg_val TO lt_cfgs_val.

    ls_cfg_part_of = VALUE #( config_id = '000001'
                               parent_id = '000010'
                               inst_id = '00000001'
                               class_type = 'MARA'
                               obj_key = 'ZK_ZESP').
    APPEND ls_cfg_part_of TO lt_cfgs_part_of.

    " 6. Wywołanie BAPI
    CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
      EXPORTING
        return_header_in     = ls_head
        return_header_inx    = ls_headx
*       TESTRUN              = 'X'   " <- odkomentuj jeśli chcesz tylko testować
      IMPORTING
        salesdocument        = lv_salesdoc
      TABLES
        return               = lt_return
        return_partners      = lt_partners
        return_items_in      = lt_items
        return_items_inx     = lt_itemsx
        return_schedules_in  = lt_sched
        return_schedules_inx = lt_schedx
        return_cfgs_ref      = lt_cfgs_ref
        return_cfgs_inst     = lt_cfgs_inst
        return_cfgs_value    = lt_cfgs_val.

    " 7. Obsługa komunikatów i zatwierdzenie
    DATA(lv_error) = abap_false.

    SELECT SINGLE cuobj INTO @DATA(lv_cuobj)
    FROM vbap
    WHERE vbeln = @lv_salesdoc
      AND posnr = '000010'.

    LOOP AT lt_return INTO DATA(ls_ret).
      WRITE: / ls_ret-type, ls_ret-id, ls_ret-number, ls_ret-message.
      IF ls_ret-type = 'E' OR ls_ret-type = 'A'.
        lv_error = abap_true.
      ENDIF.
    ENDLOOP.

    IF lv_salesdoc IS NOT INITIAL AND lv_error = abap_false.
      COMMIT WORK AND WAIT.
      WRITE: / 'Dokument zwrotu utworzony pomyślnie:', lv_salesdoc.
    ELSE.
      ROLLBACK WORK.
      WRITE: / 'Błąd podczas tworzenia dokumentu zwrotu.'.
    ENDIF.

  ENDMETHOD.

Przeanalizuj jej poprawność, gdyż nie jest dodawana konfiguracja wariantów do pozycji zlecenia.