Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_GOODSMVT_CREATE vs CALL TRANSACTION

Former Member
0 Likes
743

Hi people! I've tried to use the BAPI_GOODSMVT_CREATE for plant transfer in transaction MB1B, but when i run it in test mode the return table tells me that it's impossible to make the movement 313. It's that true? or is it that i've done something wrong? Has any of you done this in BAPI or it has to be made by call transaction?

Hi people! I've tried to use the BAPI_GOODSMVT_CREATE for plant transfer in transaction MB1B, but when i run it in test mode the return table tells me that it's impossible to make the movement 313. It's that true? or is it that i've done something wrong? Has any of you done this in BAPI or it has to be made by call transaction?

2 REPLIES 2
Read only

Former Member
0 Likes
564

I think movement type 313 is an automatically generated movement type and thats why it is not allowing you to create it using BAPI.

Read only

Former Member
0 Likes
564
*&---------------------------------------------------------------------*
*& Report  ZSRM_MB1A                                        *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZSRM_MB1A_GM                     .

TYPES: BEGIN OF X_FF,
        MTSNR TYPE RM07M-MTSNR,
        WERKS TYPE RM07M-WERKS,
        LGORT TYPE RM07M-LGORT,
        LIFNR TYPE MSEGK-LIFNR,
        WEMPF TYPE MSEGK-WEMPF,
        MATNR TYPE MSEG-MATNR,
        ERFMG TYPE CHAR10,
        AUFNR TYPE COBL-AUFNR,
       END OF X_FF.
DATA:IT_FF TYPE X_FF OCCURS 0 WITH HEADER LINE.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME OBLIGATORY
                            DEFAULT 'C:DATA1.TXT'.
DATA:LV_MSG(255),
     V_FILE TYPE STRING.

* Table for goods movement item data
DATA: BEGIN OF it_gds_item OCCURS 0.
        INCLUDE STRUCTURE bapi2017_gm_item_create.
DATA: END OF it_gds_item.

* Table for returns data from BAPI
DATA: BEGIN OF it_return OCCURS 0.
        INCLUDE STRUCTURE bapiret2.
DATA: END OF it_return.
* Structure for holding goods movement header
DATA:    x_gds_hdr LIKE bapi2017_gm_head_01,
* Structure for holding goods movement header returned from BAPI
    x_gds_hdr_ret LIKE  bapi2017_gm_head_ret,
* Work area for bapi return
    wa_return LIKE bapiret2,
    v_code    LIKE bapi2017_gm_code.

V_FILE = P_FILE.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                      = V_FILE
*      FILENAME                      = 'C:DATA1.TXT'
      FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = 'X'
*       HEADER_LENGTH                 = 0
*       READ_BY_LINE                  = 'X'
*       DAT_MODE                      = ' '
*       CODEPAGE                      = ' '
*       IGNORE_CERR                   = ABAP_TRUE
*       REPLACEMENT                   = '#'
*       CHECK_BOM                     = ' '
*     IMPORTING
*       FILELENGTH                    =
*       HEADER                        =
    TABLES
      DATA_TAB                      = IT_FF
   EXCEPTIONS
     FILE_OPEN_ERROR               = 1
     FILE_READ_ERROR               = 2
     NO_BATCH                      = 3
     GUI_REFUSE_FILETRANSFER       = 4
     INVALID_TYPE                  = 5
     NO_AUTHORITY                  = 6
     UNKNOWN_ERROR                 = 7
     BAD_DATA_FORMAT               = 8
     HEADER_NOT_ALLOWED            = 9
     SEPARATOR_NOT_ALLOWED         = 10
     HEADER_TOO_LONG               = 11
     UNKNOWN_DP_ERROR              = 12
     ACCESS_DENIED                 = 13
     DP_OUT_OF_MEMORY              = 14
     DISK_FULL                     = 15
     DP_TIMEOUT                    = 16
     OTHERS                        = 17.

  IF SY-SUBRC <> 0.
    EXIT.
  ENDIF.

  PERFORM goods_movement_261.

*&---------------------------------------------------------------------*
*&      Form  goods_movement_261
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM goods_movement_261 .
  DATA: lx_return TYPE bapiret2.
loop at it_ff.
  REFRESH it_gds_item.
  CLEAR: x_gds_hdr, it_gds_item.

  v_code = '03'.

  x_gds_hdr-pstng_date   = sy-datum.
  x_gds_hdr-doc_date     = sy-datum.

  x_gds_hdr-ref_doc_no   =  it_ff-mtsnr.
  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = it_ff-lifnr
   IMPORTING
     OUTPUT        =  it_ff-lifnr.
            .
  it_gds_item-vendor       = it_ff-lifnr.

  it_gds_item-move_type    = '261'.
  it_gds_item-spec_stock   = 'K'.
  it_gds_item-material     = it_ff-matnr.
  it_gds_item-plant        = it_ff-werks.
  it_gds_item-stge_loc     = it_ff-lgort.


  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = it_ff-AUFNR
   IMPORTING
     OUTPUT        =  it_ff-AUFNR.
  it_gds_item-orderid   =    it_ff-aufnr.
  it_gds_item-entry_qnt    = it_ff-erfmg.
  it_gds_item-gr_rcpt     =  it_ff-WEMPF.


*  x_gds_hdr-ref_doc_no   =  '20051103_1'.
*  it_gds_item-vendor       = '0000501007'.
*  it_gds_item-move_type    = '261'.
*  it_gds_item-spec_stock   = 'K'.
*  it_gds_item-material     = 'MRO108635'.
*  it_gds_item-plant        = '6000'.
*  it_gds_item-stge_loc     = '6020'.
*  it_gds_item-orderid   = '000020605359'.
*  it_gds_item-entry_qnt    = 1.
*  it_gds_item-gr_rcpt     = sy-uname.
*
  APPEND it_gds_item.
  CLEAR x_gds_hdr_ret.

call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header             = X_GDS_HDR
    goodsmvt_code               = V_CODE
*   TESTRUN                     = ' '
 IMPORTING
   GOODSMVT_HEADRET            = x_gds_hdr_ret
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
  tables
    goodsmvt_item               = it_gds_item
*   GOODSMVT_SERIALNUMBER       =
    return                      = IT_RETURN
          .

call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
          .

  IF NOT x_gds_hdr_ret-mat_doc IS INITIAL.
    WRITE:  /'For Movement type 261:',  x_gds_hdr_ret-mat_doc.
  ELSE.
    READ TABLE it_return INTO  lx_return INDEX 1.
    WRITE:  /'Movement 261 Failed as:', lx_return-message.
  ENDIF.
  REFRESH IT_RETURN.

endloop.
ENDFORM.                    " goods_movement_261