Skip to Content
0

call function '/AFS/BAPI_GOODSMVT_CREATE' starting new task

May 18, 2017 at 06:13 AM

63

avatar image

Hi Friends

I have problem when i try to call function '/AFS/BAPI_GOODSMVT_CREATE' do 551.

My code as follow

form get_goodsmvt_item .
  data: wa_header        like bapi2017_gm_head_01,
        wa_item          like /afs/bapi2017_gm_item_create,
        lt_item          like /afs/bapi2017_gm_item_create occurs 0,
        it_return_commit like  bapiret2 occurs 0 with header line.


  data: lv_no(5)      type c,
        lv_all(5)     type c,
        lv_msg(70)    type c,
        open_task_num type i
        .
*   RFC Serve Group name         Start--*
* g_classname = 'parallel_generators'
  call 'C_SAPGPARAM'                                      "#EC CI_CCALL
    id 'NAME'  field 'rdisp/myname'
    id 'VALUE' field gv_applserver.


  select single classname
    from rzllitab
    into gv_classname   "Server Group Name
    where applserver = gv_applserver
      and grouptype = 'S'.   
*  RFC Serve Group name         End--*
  clear: lv_all, open_task_num.
  lv_all = lines( it_matnr ).


  sort: it_matnr by bktxt matnr,
        it_record by matnr.


  loop at it_matnr.
    
    lv_no = sy-tabix.


    condense: lv_no, lv_all.


    concatenate 'Doing 551:' lv_no '/' lv_all into lv_msg separated by ''.


    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        text = lv_msg.
    "taskname = 'Task' + sy-tabix
    gv_taskname = lv_no.
    condense gv_taskname.
    concatenate 'Task' gv_taskname into gv_taskname.
    "get header
    clear wa_header.
    wa_header-doc_date        = it_matnr-bldat.
    wa_header-pstng_date      = it_matnr-budat.
    wa_header-header_txt      = it_matnr-bktxt.
    wa_header-ver_gr_gi_slip  = '3'.
    wa_header-ver_gr_gi_slipx = 'X'.


    clear lt_item.
    loop at it_record where matnr = it_matnr-matnr
                        and bldat = it_matnr-bldat
                        and budat = it_matnr-budat
                        and bktxt = it_matnr-bktxt
                         .


      if it_record-message ne ' OK.'.
        move-corresponding it_record to it_err2.
        append it_err2.
        clear it_err2.


      else.
        "keep taskname and message
        move-corresponding it_record to it_err3.
        it_err3-taskname = gv_taskname.
        append it_err3.
        clear it_err3.
        "get item
        wa_item-material  = it_record-matnr.
        wa_item-move_type = it_record-bwart.
        wa_item-plant     = it_record-werks.
        wa_item-stge_loc  = it_record-lgort.


        if  it_record-j_4kscat <> space
          and it_record-j_4kscat is not initial .


          wa_item-stock_cat = it_record-j_4kscat.
        endif.


        wa_item-entry_qnt   = it_record-menge.
        wa_item-vendrbatch  = it_record-charg_v.
        wa_item-move_reas   = 1.


        if it_record-meins = 'PC'.
          wa_item-entry_uom = 'ST'.
        else.
          wa_item-entry_uom = it_record-meins.
        endif.


        wa_item-batch       = it_record-charg.
        wa_item-grid_value  = it_record-j_3asize_id.
        wa_item-costcenter  = it_record-kostl.
        append wa_item to lt_item.


      endif.
    endloop.


    if lines( lt_item ) > 0.
      call function '/AFS/BAPI_GOODSMVT_CREATE'
        starting new task gv_taskname
*        destination in group gv_applserver
        performing frm_return on end of task
        exporting
          goodsmvt_header       = wa_header
          goodsmvt_code         = '03'
        tables
          afs_goodsmvt_item     = lt_item
        exceptions
          communication_failure = 1 message lv_msg
          system_failure        = 2 message lv_msg
          resource_failure      = 3.


      if sy-subrc = 0.


        snd_jobs = snd_jobs + 1.


      endif.


      open_task_num = open_task_num + 1.   


      if open_task_num = 5.    "5 = RZ12 Max. requests in queue


        wait until rcv_jobs >= snd_jobs.


        if gv_success = 'X'.
          call function 'BAPI_TRANSACTION_COMMIT'
            exporting
              wait   = 'X'
            importing
              return = it_return_commit.


          wait up to 1 seconds.
        endif.


        clear:open_task_num,rcv_jobs,snd_jobs,gv_success.
        clear: it_err3, it_err3[].


      else.


        if lv_no = lv_all.
          wait until rcv_jobs >= snd_jobs.


          call function 'BAPI_TRANSACTION_COMMIT'
            exporting
              wait   = 'X'
            importing
              return = it_return_commit.


        wait up to 1 seconds.


          clear:open_task_num,rcv_jobs,snd_jobs, gv_success.
          clear: it_err3, it_err3[].
        endif.
      endif.
    endif.


  endloop.
endform.


form frm_return using gv_taskname.
  data: lv_msg(255)   type c.


  rcv_jobs = rcv_jobs + 1.  ""Receiving data


  receive results from function '/afs/BAPI_GOODSMVT_CREATE'
          importing
            materialdocument  = gv_mdoc
            matdocumentyear   = gv_year
          tables
            return            = it_return.




  read table it_return with key type = 'E'.
  if sy-subrc eq 0.


    lv_msg = it_return-message.
  else.


    concatenate gv_mdoc ' is posted.' into lv_msg.
    gv_success = 'X'.
  endif.


  loop at it_err3 where taskname = gv_taskname.
    move-corresponding it_err3 to it_err.
    it_err-message = lv_msg.
    append it_err  .
    clear it_err.
  endloop.
endform.

I can get material code from receive results from function '/afs/BAPI_GOODSMVT_CREATE' , but call function 'BAPI_TRANSACTION_COMMIT' can not update the material code to database.

I need your help.

Thanks very much.

br

Vega

10 |10000 characters needed characters left characters exceeded

Please post coding questions with the ABAP Development tag.

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jürgen L
May 18, 2017 at 06:37 AM
0

Not sure what you want to say with this sentence "I can get material code from receive results"

Wouldn't you expect to get the material document number instead of the material number?

Have you already check SM13 for posting failures?

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I can get a new material document number after receiveresultsfromfunction'/afs/BAPI_GOODSMVT_CREATE', and I sure I had been check SM13 and ST22, no error log or fail log.

I only want to konw why the new material document number no insert into the table:MSEG after callfunction'BAPI_TRANSACTION_COMMIT'.

0