Online Tutorials & Training Materials | STechies.com
Register Login

Program to upload picking quantity and do Post Goods Issue through vl02 transaction

|| 0

Program to upload picking quantity and do Post Goods Issue through vl02 transaction
Stechies

Program : ZSDD_DELIV_PICK
Title : Upload picking.
Developed By : Sujitha.D - Orchid
Functional Spec. By : Velayathum - Spectra
Module : SD
Start-Date : 14.11.2011
Description : To upload picking quantity and do Post Goods Issue
through vl02 transaction
Service Request No : IT/SAP/1647
Transport Request No: ORDK936364

REPORT zsdd_deliv_pick.

"Data declaration

TYPES:BEGIN OF ty_deliv,
vbeln TYPE vbeln_vl, " Delivery
Comb_field is combination of input values Actual Goods Mvt Dt and Item No
comb_field(8), " Actual Goods Mvt Date & Item No
pkimg TYPE pkimg, " Picking Quantity
END OF ty_deliv.

DATA: it_deliv TYPE ty_deliv OCCURS 0 WITH HEADER LINE .

DATA : BEGIN OF deliv_head OCCURS 0,
vbeln LIKE likp-vbeln,
wadat_ist LIKE likp-wadat_ist,
END OF deliv_head.

DATA :BEGIN OF deliv_item OCCURS 0,
vbeln LIKE likp-vbeln,
posnr LIKE lips-posnr,
pikmg TYPE pikmg, " Picking Qty
END OF deliv_item.

DATA :it_vbpok TYPE STANDARD TABLE OF vbpok,
it_vbkok TYPE STANDARD TABLE OF vbkok,
it_return TYPE STANDARD TABLE OF prott,
wa_return TYPE prott,
wa_vbpok TYPE vbpok,
wa_vbkok TYPE vbkok.

DATA: sytabix TYPE sy-tabix.

DATA: file1 TYPE string,
line TYPE i,
message_text_output TYPE natxt,
l_msg(250) TYPE c.

"End of data declaration

"Selection screen declaration

PARAMETER :p_file LIKE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'p_file'
IMPORTING
file_name = p_file.

START-OF-SELECTION.

* Uploading Input File
PERFORM f_upload_file.
Populating Header and Item Data
PERFORM f_it_deliv.
Updating BAPI
PERFORM f_deliv_head.

& Form F_UPLOAD_FILE

text

--> p1 text
<-- p2 text

FORM f_upload_file .

file1 = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING
filename = file1
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_deliv
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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " F_UPLOAD_FILE

& Form F_IT_DELIV

text

--> p1 text
<-- p2 text

FORM f_it_deliv .

LOOP AT it_deliv .
sytabix = sy-tabix.
AT NEW vbeln.
READ TABLE it_deliv INDEX sytabix.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING
input = it_deliv-vbeln
IMPORTING
output = it_deliv-vbeln.
deliv_head-vbeln = it_deliv-vbeln.
deliv_head-wadat_ist = it_deliv-comb_field. " Actual Goods Mvt Date
APPEND deliv_head.
CONTINUE.
ENDAT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING
input = it_deliv-vbeln
IMPORTING
output = it_deliv-vbeln.

deliv_item-vbeln = it_deliv-vbeln. " Delivery No
deliv_item-posnr = it_deliv-comb_field. " Line Item No
deliv_item-pikmg = it_deliv-pkimg. " Picking Quantity
APPEND deliv_item.
ENDLOOP.

ENDFORM. " F_IT_DELIV

& Form F_DELIV_HEAD

text

--> p1 text
<-- p2 text

FORM f_deliv_head .

LOOP AT deliv_head.
REFRESH it_vbpok.

* Header Data
wa_vbkok-vbeln_vl = deliv_head-vbeln.
wa_vbkok-vbtyp_vl = 'J'.
wa_vbkok-vbeln = deliv_head-vbeln.
wa_vbkok-wabuc = 'X'.
wa_vbkok-wadat_ist = deliv_head-wadat_ist.

LOOP AT deliv_item WHERE vbeln = deliv_head-vbeln.
Item Data
wa_vbpok-vbeln_vl = deliv_item-vbeln.
wa_vbpok-posnr_vl = deliv_item-posnr.
wa_vbpok-vbeln = deliv_item-vbeln.
wa_vbpok-posnn = deliv_item-posnr.
wa_vbpok-pikmg = deliv_item-pikmg.
APPEND wa_vbpok TO it_vbpok.
CLEAR: wa_vbpok.
ENDLOOP.

CALL FUNCTION 'WS_DELIVERY_UPDATE_2'

EXPORTING
vbkok_wa = wa_vbkok " Header Data
synchron = 'X'
commit = 'X'
delivery = deliv_head-vbeln
update_picking = 'X'
if_database_update_1 = '1'
TABLES
vbpok_tab = it_vbpok[] " Item Data
prot = it_return. " Message Return Table

CLEAR: deliv_head,wa_vbkok.
ENDLOOP.

* IF NOT it_return[] IS INITIAL.
READ TABLE it_return INTO wa_return WITH KEY msgty = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
LOOP AT it_return INTO wa_return.

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING
msgid = wa_return-msgid
msgnr = wa_return-msgno
msgv1 = wa_return-msgv1
msgv2 = wa_return-msgv2
msgv3 = wa_return-msgv3
msgv4 = wa_return-msgv4
IMPORTING
message_text_output = message_text_output.
* WRITE : / message_text_output.
ENDLOOP.
ENDIF.
ENDIF.

* To Commit BAPI
IF it_return[] IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.

ENDLOOP.
* WRITE : / deliv_head-vbeln, 'saved'. "'Delivery successfully updated'.
LOOP AT deliv_head.
READ TABLE it_return INTO wa_return WITH KEY vbeln = deliv_head-vbeln.
IF sy-subrc = 0.

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING
msgid = wa_return-msgid
msgnr = wa_return-msgno
msgv1 = wa_return-msgv1
msgv2 = wa_return-msgv2
msgv3 = wa_return-msgv3
msgv4 = wa_return-msgv4
IMPORTING
message_text_output = message_text_output.
WRITE : / message_text_output.
ELSE.
WRITE :/ deliv_head-vbeln, 'Delivery successfully updated'.
ENDIF.
ENDLOOP.

ENDFORM. " F_DELIV_HEAD