Application Development 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: 

Creating Goods Receipt using BAPI_GOODSMVT_CREATE?

Former Member
0 Kudos

Hi all,

I need to create Goods Receipt(MIGO) with Purchase Order known using standard BAPI_GOODSMVT_CREATE.

Please provide me the necessary procedure and coding to create Goods Receipt?

Thanks,

Vamshi.

Edited by: VAMSHI KRISHNA on Jul 7, 2008 12:19 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

&----


*& Report ZMIGO

*&

&----


*&

*&

&----


REPORT ZMIGO no standard page heading line-size 200.

include zmigo_data_declaration.

data:p_infile LIKE rlgrap-filename,

p_srfile LIKE rlgrap-filename,

p_errfl LIKE rlgrap-filename,

p_logfl LIKE rlgrap-filename.

***********selection screen

selection-screen begin of block b1 with frame title text-001.

*PARAMETERs : p_infile LIKE rlgrap-filename.

*parameters: p_srfile LIKE rlgrap-filename.

*PARAMETERs : p_errfl LIKE rlgrap-filename.

*PARAMETERs : p_logfl LIKE rlgrap-filename.

selection-screen end of block b1.

*at selection-screen on value-request for p_infile.

*

** getting the file name for uploading the PO data.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_infile.

*

*at selection-screen on value-request for p_srfile.

*

** getting the file name for uploading the Serial No.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_srfile.

*at selection-screen on value-request for p_errfl.

*

** getting the file name for downloading Error File.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_errfl.

*

*at selection-screen on value-request for p_logfl.

*

** getting the file name for downloading Log File.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_logfl.

**********start of selection

start-of-selection.

Perform upload_data.

Perform call_bapi_create_migo.

PERFORM download_error_file.

END-OF-SELECTION.

PERFORM write_record_log.

&----


*& Form upload_data

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM upload_data .

***********To fill input data

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p_infile

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_input

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear it_input.

********To Fill Serial Number

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p_infile

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_serial

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear it_serial.

delete it_serial where SERIALNO eq ' '.

ENDFORM. " upload_data

&----


*& Form call_bapi_create_migo

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM call_bapi_create_migo .

data: t_input like it_input.

loop at it_input.

t_input = it_input.

perform fill_header_level_table using t_input.

PERFORM fill_item_level_tables.

perform call_bapi_for_create_migo using t_input.

endloop.

ENDFORM. " call_bapi_create_migo

&----


*& Form fill_header_level_table

&----


* text

----


* -->P_T_INPUT text

----


FORM fill_header_level_table USING P_INPUT STRUCTURE it_input.

clear s1_header.

s1_header-PSTNG_DATE = p_input-PSTNG_DATE.

s1_header-DOC_DATE = p_input-DOC_DATE.

s1_header-REF_DOC_NO = p_input-REF_DOC_NO.

* append it_header.

* clear it_header.

clear s_code.

s_code-GM_CODE = p_input-GM_CODE.

* append it_code.

* clear it_code.

ENDFORM. " fill_header_level_table

&----


*& Form fill_item_level_tables

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM fill_item_level_tables .

it_item-PO_NUMBER = it_input-ebeln.

it_item-PO_ITEM = it_input-ebelp.

it_item-MOVE_TYPE = it_input-MOVE_TYPE.

if it_input-GM_CODE eq '01'.

it_item-MVT_IND = 'B'.

elseif it_input-GM_CODE eq '02'.

it_item-MVT_IND = 'F'.

endif.

it_item-ENTRY_QNT = it_input-menge.

it_item-ENTRY_UOM = it_input-ENTRY_UOM_ISO.

it_item-ENTRY_UOM_ISO = it_input-ENTRY_UOM_ISO.

it_item-STGE_LOC = it_input-stloc.

it_item-BATCH = it_input-batch.

append it_item.

clear it_item.

ENDFORM. " fill_item_level_tables

&----


*& Form call_bapi_for_create_migo

&----


* text

----


* -->P_T_INPUT text

----


FORM call_bapi_for_create_migo USING P_INPUT STRUCTURE it_input.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = s1_header

GOODSMVT_CODE = s_code

IMPORTING

GOODSMVT_HEADRET = it_GOODSMVT_HEADER

MATERIALDOCUMENT = it_mat_docu

MATDOCUMENTYEAR = it_mat_docu_yr

TABLES

GOODSMVT_ITEM = it_item

GOODSMVT_SERIALNUMBER = it_serial

RETURN = it_return.

v_err = 'N'.

FORMAT COLOR 6.

LOOP AT it_return WHERE type = 'E'.

CLEAR it_log.

CONCATENATE 'Ref:' it_input-ebeln '-ERR-' it_return-message

INTO it_log-txt.

APPEND it_log.

PERFORM create_error_file USING it_input.

+v_error_rec = v_error_rec + 1.+

v_err = 'Y'.

EXIT.

endloop.

IF v_err = 'N'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

+v_success_rec = v_success_rec + 1.+

ENDIF.

ENDFORM. " call_bapi_for_create_migo

&----


*& Form create_error_file

&----


* text

----


* -->P_T_INPUT text

----


FORM create_error_file USING P_t_INPUT STRUCTURE it_input.

LOOP AT it_input WHERE ebeln = p_t_input-ebeln.

it_error = it_input.

APPEND it_error.

ENDLOOP.

ENDFORM. " create_error_file

&----


*& Form download_error_file

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM download_error_file .

CALL FUNCTION 'DOWNLOAD'

EXPORTING

filename = p_errfl

filetype = 'DAT'

TABLES

data_tab = it_error

EXCEPTIONS

invalid_filesize = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

customer_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

filename = p_logfl

filetype = 'DAT'

TABLES

data_tab = it_log

EXCEPTIONS

invalid_filesize = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

customer_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " download_error_file

&----


*& Form write_record_log

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM write_record_log .

WRITE:/ 'Number of Material Document in Error :',

v_error_rec LEFT-JUSTIFIED.

WRITE:/ 'Number of Material Document created through BAPI:',

v_success_rec LEFT-JUSTIFIED.

ENDFORM. " write_record_log

Include Program.....

&----


*& Include ZMIGO_DATA_DECLARATION

&----


********data declaration

DATA : it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

data: it_item like BAPI2017_GM_ITEM_CREATE occurs 0 with header line.

data: it_serial like BAPI2017_GM_SERIALNUMBER occurs 0 with header line.

data: it_mat_docu like BAPI2017_GM_HEAD_RET-MAT_DOC occurs 0 with header line.

data: it_mat_docu_yr like BAPI2017_GM_HEAD_RET-DOC_YEAR occurs 0 with header line.

data: it_GOODSMVT_HEADer like BAPI2017_GM_HEAD_RET occurs 0 with header line.

data: it_header like BAPI2017_GM_HEAD_01 occurs 0 with header line.

data: s1_header like BAPI2017_GM_HEAD_01.

data: it_code like BAPI2017_GM_CODE occurs 0 with header line.

data: s_code like BAPI2017_GM_CODE.

data: begin of s_podetail,

ebeln like ekpo-ebeln,

ebelp like ekpo-ebelp,

move_type(3),

menge like ekpo-menge,

ENTRY_UOM_ISO(3),

stloc(4),

batch(10),

end of s_podetail.

data: begin of s_header,

PSTNG_DATE(8),

DOC_DATE(8),

REF_DOC_NO(16),

end of s_header.

data: begin of it_input occurs 0.

INCLUDE STRUCTURE s_header.

INCLUDE STRUCTURE s_code.

INCLUDE STRUCTURE s_podetail.

data: end of it_input.

data: v_err,v_error_rec TYPE i,v_success_rec TYPE i.

DATA : it_error LIKE it_input OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_log OCCURS 0,

txt(255),

END OF it_log.

Reward if useful.....

Thanks,

Durai.V

Edited by: Durai V on Jul 7, 2008 6:28 AM

5 REPLIES 5

Former Member
0 Kudos

Hi,

&----


*& Report ZMIGO

*&

&----


*&

*&

&----


REPORT ZMIGO no standard page heading line-size 200.

include zmigo_data_declaration.

data:p_infile LIKE rlgrap-filename,

p_srfile LIKE rlgrap-filename,

p_errfl LIKE rlgrap-filename,

p_logfl LIKE rlgrap-filename.

***********selection screen

selection-screen begin of block b1 with frame title text-001.

*PARAMETERs : p_infile LIKE rlgrap-filename.

*parameters: p_srfile LIKE rlgrap-filename.

*PARAMETERs : p_errfl LIKE rlgrap-filename.

*PARAMETERs : p_logfl LIKE rlgrap-filename.

selection-screen end of block b1.

*at selection-screen on value-request for p_infile.

*

** getting the file name for uploading the PO data.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_infile.

*

*at selection-screen on value-request for p_srfile.

*

** getting the file name for uploading the Serial No.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_srfile.

*at selection-screen on value-request for p_errfl.

*

** getting the file name for downloading Error File.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_errfl.

*

*at selection-screen on value-request for p_logfl.

*

** getting the file name for downloading Log File.

*

* call function 'F4_FILENAME'

* EXPORTING

* program_name = syst-cprog

* dynpro_number = syst-dynnr

* IMPORTING

* file_name = p_logfl.

**********start of selection

start-of-selection.

Perform upload_data.

Perform call_bapi_create_migo.

PERFORM download_error_file.

END-OF-SELECTION.

PERFORM write_record_log.

&----


*& Form upload_data

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM upload_data .

***********To fill input data

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p_infile

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_input

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear it_input.

********To Fill Serial Number

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p_infile

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_serial

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear it_serial.

delete it_serial where SERIALNO eq ' '.

ENDFORM. " upload_data

&----


*& Form call_bapi_create_migo

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM call_bapi_create_migo .

data: t_input like it_input.

loop at it_input.

t_input = it_input.

perform fill_header_level_table using t_input.

PERFORM fill_item_level_tables.

perform call_bapi_for_create_migo using t_input.

endloop.

ENDFORM. " call_bapi_create_migo

&----


*& Form fill_header_level_table

&----


* text

----


* -->P_T_INPUT text

----


FORM fill_header_level_table USING P_INPUT STRUCTURE it_input.

clear s1_header.

s1_header-PSTNG_DATE = p_input-PSTNG_DATE.

s1_header-DOC_DATE = p_input-DOC_DATE.

s1_header-REF_DOC_NO = p_input-REF_DOC_NO.

* append it_header.

* clear it_header.

clear s_code.

s_code-GM_CODE = p_input-GM_CODE.

* append it_code.

* clear it_code.

ENDFORM. " fill_header_level_table

&----


*& Form fill_item_level_tables

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM fill_item_level_tables .

it_item-PO_NUMBER = it_input-ebeln.

it_item-PO_ITEM = it_input-ebelp.

it_item-MOVE_TYPE = it_input-MOVE_TYPE.

if it_input-GM_CODE eq '01'.

it_item-MVT_IND = 'B'.

elseif it_input-GM_CODE eq '02'.

it_item-MVT_IND = 'F'.

endif.

it_item-ENTRY_QNT = it_input-menge.

it_item-ENTRY_UOM = it_input-ENTRY_UOM_ISO.

it_item-ENTRY_UOM_ISO = it_input-ENTRY_UOM_ISO.

it_item-STGE_LOC = it_input-stloc.

it_item-BATCH = it_input-batch.

append it_item.

clear it_item.

ENDFORM. " fill_item_level_tables

&----


*& Form call_bapi_for_create_migo

&----


* text

----


* -->P_T_INPUT text

----


FORM call_bapi_for_create_migo USING P_INPUT STRUCTURE it_input.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = s1_header

GOODSMVT_CODE = s_code

IMPORTING

GOODSMVT_HEADRET = it_GOODSMVT_HEADER

MATERIALDOCUMENT = it_mat_docu

MATDOCUMENTYEAR = it_mat_docu_yr

TABLES

GOODSMVT_ITEM = it_item

GOODSMVT_SERIALNUMBER = it_serial

RETURN = it_return.

v_err = 'N'.

FORMAT COLOR 6.

LOOP AT it_return WHERE type = 'E'.

CLEAR it_log.

CONCATENATE 'Ref:' it_input-ebeln '-ERR-' it_return-message

INTO it_log-txt.

APPEND it_log.

PERFORM create_error_file USING it_input.

+v_error_rec = v_error_rec + 1.+

v_err = 'Y'.

EXIT.

endloop.

IF v_err = 'N'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

+v_success_rec = v_success_rec + 1.+

ENDIF.

ENDFORM. " call_bapi_for_create_migo

&----


*& Form create_error_file

&----


* text

----


* -->P_T_INPUT text

----


FORM create_error_file USING P_t_INPUT STRUCTURE it_input.

LOOP AT it_input WHERE ebeln = p_t_input-ebeln.

it_error = it_input.

APPEND it_error.

ENDLOOP.

ENDFORM. " create_error_file

&----


*& Form download_error_file

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM download_error_file .

CALL FUNCTION 'DOWNLOAD'

EXPORTING

filename = p_errfl

filetype = 'DAT'

TABLES

data_tab = it_error

EXCEPTIONS

invalid_filesize = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

customer_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

filename = p_logfl

filetype = 'DAT'

TABLES

data_tab = it_log

EXCEPTIONS

invalid_filesize = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

customer_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " download_error_file

&----


*& Form write_record_log

&----


* text

----


* --> p1 text

* <-- p2 text

----


FORM write_record_log .

WRITE:/ 'Number of Material Document in Error :',

v_error_rec LEFT-JUSTIFIED.

WRITE:/ 'Number of Material Document created through BAPI:',

v_success_rec LEFT-JUSTIFIED.

ENDFORM. " write_record_log

Include Program.....

&----


*& Include ZMIGO_DATA_DECLARATION

&----


********data declaration

DATA : it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

data: it_item like BAPI2017_GM_ITEM_CREATE occurs 0 with header line.

data: it_serial like BAPI2017_GM_SERIALNUMBER occurs 0 with header line.

data: it_mat_docu like BAPI2017_GM_HEAD_RET-MAT_DOC occurs 0 with header line.

data: it_mat_docu_yr like BAPI2017_GM_HEAD_RET-DOC_YEAR occurs 0 with header line.

data: it_GOODSMVT_HEADer like BAPI2017_GM_HEAD_RET occurs 0 with header line.

data: it_header like BAPI2017_GM_HEAD_01 occurs 0 with header line.

data: s1_header like BAPI2017_GM_HEAD_01.

data: it_code like BAPI2017_GM_CODE occurs 0 with header line.

data: s_code like BAPI2017_GM_CODE.

data: begin of s_podetail,

ebeln like ekpo-ebeln,

ebelp like ekpo-ebelp,

move_type(3),

menge like ekpo-menge,

ENTRY_UOM_ISO(3),

stloc(4),

batch(10),

end of s_podetail.

data: begin of s_header,

PSTNG_DATE(8),

DOC_DATE(8),

REF_DOC_NO(16),

end of s_header.

data: begin of it_input occurs 0.

INCLUDE STRUCTURE s_header.

INCLUDE STRUCTURE s_code.

INCLUDE STRUCTURE s_podetail.

data: end of it_input.

data: v_err,v_error_rec TYPE i,v_success_rec TYPE i.

DATA : it_error LIKE it_input OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_log OCCURS 0,

txt(255),

END OF it_log.

Reward if useful.....

Thanks,

Durai.V

Edited by: Durai V on Jul 7, 2008 6:28 AM

0 Kudos

Hi Durai,

Thanks for the quick reply and it is very helpful.

But i had a small doubt.

The reference document no in the header structure, is mandatory to fill

if yes, with which document no it has to fill?

Thanks,

Vamshi.

0 Kudos

Hi,

Not mandatory.

Reward if useful....

Thanks,

Durai.V

0 Kudos

Hi durai,

Thanks and as my problem solved i am closing th thread.

Thanks,

Vamshi.

0 Kudos

Hi Durai,

According to ur program u get the data's from external system. In our company we are scanning the incoming goods and do the migo through Bapi_goodsmvt_create.we are getting the following data from scanning.

(PO number, Qty. )

So we should do migo for the incoming PO number. Here i encountered one problem, while the qty allocation i should give preference for delivery date in schedule line. Through this bapi how can achieve the my requirement.