avatar
Untitled

Guest 571 9th Apr, 2024

ABAP 4.43 KB
                                           
                         FUNCTION ZF4PU_FM_MASS_PRINT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_UNAME) TYPE  UNAME
*"     VALUE(IV_LIFNR) TYPE  LIFNR
*"     VALUE(IT_EBELN) TYPE  MMPURUI_EBELN_TABLE_TTY
*"  EXPORTING
*"     VALUE(ET_OK) TYPE  MMPURUI_EBELN_TABLE_TTY
*"     VALUE(ET_ERROR) TYPE  MMPURUI_EBELN_TABLE_TTY
*"  EXCEPTIONS
*"      TCODE_INVALID
*"      AUTHORITY_CHECK_FAILED
*"      NO_ELEMENTS_PROVIDED
*"      NO_EKORG_FOUND
*"      UNAME_DOES_NOT_EXIST
*"      BDC_ERROR
*"----------------------------------------------------------------------
  DATA ls_username_check_return TYPE bapiret2.
  DATA lv_rcode TYPE sy-subrc.
  DATA lt_nast           TYPE TABLE OF nast.
  DATA lt_nast_to_update TYPE TABLE OF nast.
  DATA lt_vnast          TYPE TABLE OF vnast.
  DATA ls_vnast          TYPE vnast.
  DATA lt_objkey TYPE TABLE OF na_objkey.

  LOOP AT it_ebeln INTO DATA(lv_ebeln) WHERE table_line IS NOT INITIAL.
    INSERT CONV na_objkey( lv_ebeln ) INTO TABLE lt_objkey.
  ENDLOOP.
  """"""""""""""""""""""""""

  SELECT * FROM nast FOR ALL ENTRIES IN @lt_objkey
          WHERE kappl =  'EV'
            AND objky =  @lt_objkey-table_line
            AND kschl = 'NEU'
            AND vstat = 0
            AND nacha = 1
            AND usnam = @iv_uname
          INTO TABLE @lt_nast.

  LOOP AT lt_nast INTO DATA(ls_nast).

    INSERT ls_nast INTO TABLE lt_nast_to_update.
    MOVE-CORRESPONDING ls_nast TO ls_vnast.
    ls_vnast-updat = 'D'.
    APPEND ls_vnast TO lt_vnast.

    CALL FUNCTION 'RV_MESSAGE_UPDATE'
      TABLES
        msg_xnast = lt_vnast
        msg_ynast = lt_nast_to_update.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.    " Use of Command `COMMIT AND WAIT`
  ENDLOOP.
  """"""""""""""""""""""""""""""""""""""""""""
  IF it_ebeln IS INITIAL.
    RAISE no_elements_provided.
  ENDIF.

  SELECT ebeln, ekorg, spras FROM ekko FOR ALL ENTRIES IN @it_ebeln
    WHERE ebeln = @it_ebeln-table_line INTO TABLE @DATA(lt_ekko).
  IF sy-subrc <> 0.
    RAISE no_ekorg_found.
  ENDIF.

  SELECT SINGLE adrnr FROM lfa1 INTO @DATA(lv_adrnr) WHERE lifnr = @iv_lifnr.

  LOOP AT it_ebeln INTO DATA(ls_ebeln_input).
    TRY.
        DATA(lv_ebeln_input) = VALUE #( lt_ekko[ ebeln = ls_ebeln_input ] ).
      CATCH cx_root INTO DATA(lo_cx).
        INSERT ls_ebeln_input INTO TABLE et_error.
    ENDTRY.
  ENDLOOP.

  LOOP AT lt_ekko INTO DATA(ls_ekko).
    AUTHORITY-CHECK OBJECT 'M_BEST_EKO'
      ID 'ACTVT' FIELD '03'
      ID 'EKORG' FIELD ls_ekko-spras.
    IF sy-subrc <> 0.
      RAISE authority_check_failed.
    ENDIF.
  ENDLOOP.

  CALL FUNCTION 'BAPI_USER_EXISTENCE_CHECK'
    EXPORTING
      username = iv_uname
    IMPORTING
      return   = ls_username_check_return.
  IF ls_username_check_return-id = 01 AND ls_username_check_return-number = 124.
    RAISE uname_does_not_exist.
  ENDIF.

  LOOP AT lt_ekko INTO DATA(ls_ebeln).
    CLEAR ls_nast.
    ls_nast-kappl = 'EV'.
    ls_nast-objky = ls_ebeln-ebeln.
    ls_nast-kschl = 'NEU'.
    ls_nast-spras = ls_ebeln-spras.
    ls_nast-parnr = iv_lifnr.
    ls_nast-parvw = 'LF'.
    ls_nast-nacha = '1'.
    ls_nast-adrnr = lv_adrnr.
    ls_nast-usnam = iv_uname.
    ls_nast-ldest = 'ZPDF'.
    ls_nast-dimme = abap_true.
    ls_nast-tdreceiver = iv_uname.
    ls_nast-objtype = 'BUS2013'.
    ls_nast-vstat = '1'.
    ls_nast-vsztp = '4'.
    ls_nast-erdat = sy-datum.
    ls_nast-eruhr = sy-timlo.
    ls_nast-tdid = 'BEWG'.
    ls_nast-tdspras = ls_ebeln-spras.

    CALL FUNCTION 'WFMC_MESSAGE_SINGLE'
      EXPORTING
        pi_nast  = ls_nast
      IMPORTING
        pe_rcode = lv_rcode.

    IF lv_rcode <> 0.
      INSERT ls_ebeln-ebeln INTO TABLE et_error.
    ELSE.
      INSERT ls_ebeln-ebeln INTO TABLE et_ok.
    ENDIF.
  ENDLOOP.
ENDFUNCTION.
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
Ta strona używa plików cookie w celu usprawnienia i ułatwienia dostępu do serwisu oraz prowadzenia danych statystycznych. Dalsze korzystanie z tej witryny oznacza akceptację tego stanu rzeczy.
Wykorzystywanie plików Cookie
Jak wyłączyć cookies?
ROZUMIEM