You are on page 1of 17

*&---------------------------------------------------------------------* *& Report ZFTP_CONNECT *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZFTP_CONNECT.

TABLES: CTU_PARAMS, " Param strng for runtime of CALL TRANSACTION USING LIKP, LIPS, MARA, MARC, VBUP. TYPES : BEGIN OF text, line(500) TYPE c, END OF text. DATA : bindata TYPE TABLE OF blob WITH HEADER LINE, chardata type table of text with header line, result TYPE TABLE OF text WITH HEADER LINE, d_contentt TYPE TABLE OF text WITH HEADER LINE, d_content TYPE TABLE OF text WITH HEADER LINE, s_contentt TYPE TABLE OF text WITH HEADER LINE, t s_content TYPE TABLE OF text WITH HEADER LINE. t DATA : BEGIN OF st_lips, vbeln LIKE lips-vbeln, vgbel LIKE lips-vgbel, " customer(360) TYPE c, " traid(30) TYPE c, " inco1(30) TYPE c, " posnr(06) TYPE c, " matnr(18) TYPE c, item_revision(03) TYPE c, kodat(18) TYPE c, bolnr LIKE likp-bolnr, " pikmg(13) TYPE c, canc_quantity(13) TYPE c, " brgew(13) TYPE c, freight_cost(13) TYPE c, " carton_number(10) TYPE c, " asn_id(20) TYPE c, END OF st_lips. DATA : wa_lips LIKE st_lips, it_lips LIKE st_lips OCCURS 10 WITH HEADER LINE, it_lips1 LIKE st_lips OCCURS 10 WITH HEADER LINE, it_lips2 LIKE st_lips OCCURS 10 WITH HEADER LINE. DATA : BEGIN OF st_sernr, vbeln(10) TYPE c, posnr(06) TYPE c, matnr(18) TYPE c,

" Delivery content " Delivery content " Serial number conten " Serial number conten

Sales Order Customer Ship Method Code Freight Term Code Line Number

Tracking Number Cancelled_Quantity Freight Cost Carton Number

"

Line Number

pikmg(10) TYPE c, kodat(18) TYPE c, sernr(18) TYPE c, extra1(1) TYPE c, extra2(1) TYPE c, extra3(1) TYPE c, extra4(1) TYPE c, extra5(1) TYPE c, END OF st_sernr. DATA : wa_sernr LIKE st_sernr, it_sernr LIKE st_sernr OCCURS 10 WITH HEADER LINE. DATA : key TYPE i VALUE 26101957, handle TYPE i, slen TYPE i, docid LIKE sysuuid-c, " file name cmd(120) TYPE C, count TYPE i VALUE '1', lines TYPE i VALUE '1000', error(1) TYPE c, ftpdir LIKE ifibl_aux_fields-allgunix, gv_app_ser LIKE ifibl_aux_fields-allgunix, gv_app_arc LIKE ifibl_aux_fields-allgunix, ftpfiles type table of text with header line, fname like rlgrap-filename, part1(200) type c, downld_file type string, filename(2000) TYPE c. DATA : user(30) TYPE c VALUE 'infinite', pwd(30) TYPE c VALUE 'ftpadmin', host(60) TYPE c VALUE 'ftp://10.99.1.47/', dest LIKE rfcdes-rfcdest VALUE 'SAPFTP'. TYPES: BEGIN OF ty_file, dirname(100) TYPE name(255) TYPE type(10) TYPE len(8) TYPE owner(8) TYPE mtime(6) TYPE fmode(9) TYPE useable(1) TYPE subrc(4) TYPE errno(3) TYPE errmsg(40) TYPE mod_date TYPE mod_time(8) TYPE seen(1) TYPE changed(1) TYPE END OF ty_file. DATA: file TYPE ty_file. c, c, c, p, c, p, c, c, c, c, c, d, c, c, c, " name of directory. (possibly truncated.) " name of entry. (possibly truncated.) " type of entry. " length in bytes. " owner of the entry. " last modification date, seconds since 1970 " like "rwx-r-x--x": protection mode.

" hh:mm:ss

TYPES: BEGIN OF dirlist, filename(175) type c, filetype(10) type c, END OF dirlist. DATA : ls_dir TYPE dirlist. DATA : BEGIN OF DIR_TABLE OCCURS 10,

filename(175) type c, filetype(10) type c, END OF DIR_TABLE. DATA: DATA: DATA: DATA: DATA: BDCDATA XLIKP XLIPS XVBUP XMARC LIKE LIKE LIKE LIKE LIKE BDCDATA LIKP LIPS VBUP MARC OCCURS OCCURS OCCURS OCCURS OCCURS 10 10 10 10 10 WITH WITH WITH WITH WITH HEADER HEADER HEADER HEADER HEADER LINE. LINE. LINE. LINE. LINE.

DATA: BEGIN OF REPTAB OCCURS 10, VBELN LIKE LIKP-VBELN, POSNR LIKE LIPS-POSNR, MATNR LIKE LIPS-MATNR, PIKMG LIKE LIPSD-PIKMG, SERNR LIKE OBJK-SERNR, MSG(80) TYPE C, RCD_OK(1) TYPE C, END OF REPTAB. DATA: REPTABS LIKE REPTAB OCCURS 10 WITH HEADER LINE. DATA: ERRTAB LIKE REPTAB OCCURS 10 WITH HEADER LINE. DATA: NVBELN(10) NPOSNR(6) NMATNR(18) NSERNR(18) R_DATUM(10) R_UZEIT(10) R_DATIME(20) E_PRINT_LINE(132) W_PRINT_LINE(132) W_RPT(1) W_MSG(80) W_TABIX ELINES ZLINES TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE LIKE LIKE LIKE N, N, N, N, C, C, C, C, C, C VALUE '1', C, SY-TABIX, SY-TABIX, SY-TABIX.

*----------------------- START OF SELECTION -------------------------* START-OF-SELECTION. PERFORM initial_setup. PERFORM ftp_conn. PERFORM check_for_files. if d_content[] is not initial. PERFORM modify_data. IF it_lips[] IS initial. MESSAGE I899(V1) WITH 'No delivery items found'. PERFORM move_to_archive. ELSE. PERFORM validate_data. IF it_lips2[] IS NOT initial. PERFORM bapi_post. ENDIF. PERFORM move_to_archive. PERFORM report_updates. ENDIF. ELSE. MESSAGE I899(V1) WITH 'No delivery files found'. ENDIF.

END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form INITIAL_SETUP *&---------------------------------------------------------------------* form INITIAL_SETUP. WRITE SY-DATUM TO R_DATUM. WRITE SY-UZEIT TO R_UZEIT USING EDIT MASK '__:__:__'. CONCATENATE R_DATUM R_UZEIT INTO R_DATIME SEPARATED BY SPACE. * Get the server filename (reference RSWATCH0, tcode AL11) select single dirname into FTPDIR FROM user_dir WHERE aliass = 'Z_New'. IF SY-SUBRC GT 0. MESSAGE E899(V1) WITH 'Trilliant FTP directory not found'. ENDIF. * Parameters for CALL CLEAR CTU_PARAMS. CTU_PARAMS-DISMODE CTU_PARAMS-UPDMODE CTU_PARAMS-CATTMODE CTU_PARAMS-DEFSIZE CTU_PARAMS-RACOMMIT CTU_PARAMS-NOBINPT CTU_PARAMS-NOBIEND endform. *&---------------------------------------------------------------------* *& Form FTP_CONN *&---------------------------------------------------------------------* form FTP_CONN . slen = STRLEN( pwd ). CALL FUNCTION 'HTTP_SCRAMBLE' EXPORTING SOURCE = pwd sourcelen = slen key = key IMPORTING DESTINATION = pwd. CALL FUNCTION 'FTP_CONNECT' EXPORTING user = user password = pwd host = host rfc_destination = dest IMPORTING handle = handle EXCEPTIONS not_connected = 1 OTHERS = 2. if sy-subrc = 0. CLEAR cmd. TRANSACTION options = = = = = = = 'N'. 'S'. ' '. ' '. 'X'. 'X'. 'X'. " " " " " " MODE action (A,E,N) UPDATE action CATT mode Use default window size Do not end trans at COMMIT WORK Batch input mode set to inactive

Host contains the path where the file is stored on the FTP serve CONCATENATE 'cd' 'Incoming' INTO cmd SEPARATED BY space. PERFORM ftp_command USING cmd. Directory of the files cmd = 'dir TRILLIANT*'. PERFORM ftp_command USING cmd. loop at result. move-corresponding result to ftpfiles. append ftpfiles. endloop. loop at ftpfiles. clear: part1, fname, cmd. split ftpfiles-line at 'TRILLIANT' into part1 fname. if fname cs '.txt'. concatenate 'TRILLIANT' fname into fname. condense fname. error = 0. Get files in internal table one by one in directory on remote server concatenate 'get' fname into cmd separated by ' '. refresh result. call function 'FTP_COMMAND' exporting handle = handle command = cmd tables data = result exceptions tcpip_error = 1 command_error = 2 data_error = 3. if sy-subrc ne 0. error = 1. continue. endif.

if error eq 0. write to SAP refresh chardata. CALL FUNCTION 'FTP_SERVER_TO_R3' exporting handle = handle fname = fname character_mode = 'X' importing blob_length = slen tables text = chardata. concatenate ftpdir '\' fname into downld_file. open dataset downld_file for output in text mode encoding default WITH SMART LINEFEED. loop at chardata. transfer chardata to downld_file . endloop. close dataset downld_file. endif. endif. endloop.

CALL FUNCTION 'FTP_DISCONNECT' EXPORTING handle = handle. CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING destination = dest EXCEPTIONS destination_not_open = 1 OTHERS = 2. IF sy-subrc EQ 0. ENDIF. ELSE. WRITE : / 'COULD NOT CONNECT TO THE SERVER'. ENDIF. endform. " FTP_CONN

*&---------------------------------------------------------------------* *& Form FTP_COMMAND *&---------------------------------------------------------------------* form FTP_COMMAND using cmd. REFRESH result. call function 'SAPGUI_PROGRESS_INDICATOR' exporting text = cmd. CALL FUNCTION 'FTP_COMMAND' EXPORTING HANDLE = handle command = cmd tables data = result[] EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3 OTHERS = 4. IF sy-subrc <> 0. ENDIF. endform. " FTP_COMMAND

*---------------------------------------------------------------------* * form CHECK_FOR_FILES * *---------------------------------------------------------------------* form CHECK_FOR_FILES. DATA : dir_name TYPE salfile-longname. DATA : path TYPE eseftappl. DATA: filenm TYPE rsmrgstr-name. dir_name = ftpdir. filenm = '*'. path = dir_name. CONDENSE path NO-GAPS. CALL 'C_DIR_READ_START' ID 'DIR'

FIELD path

ID 'FILE' FIELD filenm ID 'ERRNO' FIELD file-errno ID 'ERRMSG' FIELD file-errmsg. IF sy-subrc <> 0. RAISE access_error. ENDIF. DO. CLEAR file. CALL 'C_DIR_READ_NEXT' ID 'TYPE' FIELD file-type ID 'NAME' FIELD file-name ID 'LEN' FIELD file-len ID 'OWNER' FIELD file-owner ID 'MTIME' FIELD file-mtime ID 'MODE' FIELD file-fmode ID 'ERRNO' FIELD file-errno ID 'ERRMSG' FIELD file-errmsg. file-dirname = path. MOVE sy-subrc TO file-subrc. CASE sy-subrc. WHEN 0. CLEAR: file-errno, file-errmsg. CASE file-type(1). WHEN 'F'. " normal file. WHEN 'f'. " normal file. WHEN OTHERS. " directory, device, fifo, socket,... ENDCASE. WHEN 1. EXIT. ENDCASE. TRANSLATE file-type(1) TO UPPER CASE. ls_dir-filename = file-name. ls_dir-filetype = file-type(1). APPEND ls_dir TO dir_table. ENDDO. CALL 'C_DIR_READ_FINISH' ID 'ERRNO' FIELD file-errno ID 'ERRMSG' FIELD file-errmsg. * Shipment file REFRESH d_content. CLEAR d_content. LOOP AT DIR_TABLE WHERE FILENAME(14) EQ 'TRILLIANT_SHIP'. REFRESH d_contentt. CLEAR d_contentt. CONCATENATE ftpdir '\' dir_table-filename INTO gv_app_ser. OPEN DATASET gv_app_ser FOR INPUT IN TEXT MODE ENCODING DEFAULT WITH SMART LINEFEED. IF sy-subrc = 0. READ DATASET gv_app_ser INTO d_contentt. WHILE sy-subrc EQ 0. APPEND d_contentt. READ DATASET gv_app_ser INTO d_contentt. ENDWHILE. ENDIF. CLOSE DATASET gv_app_ser. * first and last lines in this file are BOF/EOF flags DESCRIBE TABLE d_contentt LINES lines.

DELETE d_contentt INDEX lines. DELETE d_contentt INDEX 1. APPEND LINES OF d_contentt TO d_content. ENDLOOP. * Serial number file REFRESH s_content. CLEAR s_content. LOOP AT DIR_TABLE WHERE FILENAME(16) EQ 'TRILLIANT_SERIAL'. REFRESH s_contentt. CLEAR s_contentt. CONCATENATE ftpdir '\' dir_table-filename INTO gv_app_ser. OPEN DATASET gv_app_ser FOR INPUT IN TEXT MODE ENCODING DEFAULT WITH SMART LINEFEED. IF sy-subrc = 0. READ DATASET gv_app_ser INTO s_contentt. WHILE sy-subrc EQ 0. APPEND s_contentt. READ DATASET gv_app_ser INTO s_contentt. ENDWHILE. ENDIF. CLOSE DATASET gv_app_ser. * this file doesn't have BOF/EOF flags * DESCRIBE TABLE s_contentt LINES lines. * DELETE s_contentt INDEX lines. * DELETE s_contentt INDEX 1. APPEND LINES OF s_contentt TO s_content. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form MODIFY_DATA *&---------------------------------------------------------------------* FORM modify_data . DATA : l_lfimg(13) TYPE c, l_idx TYPE sy-tabix. CONSTANTS : tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab. REFRESH it_lips. LOOP AT d_content. CLEAR: wa_lips. SPLIT d_content AT tab INTO wa_lips-vbeln wa_lips-vgbel wa_lips-customer wa_lips-traid wa_lips-inco1 wa_lips-posnr wa_lips-matnr wa_lips-item_revision wa_lips-kodat wa_lips-bolnr wa_lips-pikmg wa_lips-canc_quantity wa_lips-brgew wa_lips-freight_cost wa_lips-carton_number wa_lips-asn_id. nvbeln = wa_lips-vbeln. wa_lips-vbeln = nvbeln.

nposnr = wa_lips-posnr. wa_lips-posnr = nposnr. if wa_lips-matnr co '0123456789 '. nmatnr = wa_lips-matnr. wa_lips-matnr = nmatnr. else. translate wa_lips-matnr to upper case. shift wa_lips-matnr left deleting leading space. endif. APPEND wa_lips TO it_lips. ENDLOOP. SORT it_lips BY vbeln posnr. * File of unique delivery/item numbers APPEND LINES OF it_lips TO it_lips1 . DELETE ADJACENT DUPLICATES FROM it_lips1 COMPARING vbeln posnr. LOOP AT it_lips1. l_idx = sy-tabix. CLEAR : it_lips1-pikmg. LOOP AT it_lips WHERE vbeln EQ it_lips1-vbeln AND posnr EQ it_lips1-posnr. ADD it_lips-pikmg TO it_lips1-pikmg. ENDLOOP. MODIFY it_lips1 INDEX l_idx. ENDLOOP. * file of unique delivery numbers it_lips2[] = it_lips1[]. DELETE ADJACENT DUPLICATES FROM it_lips2 COMPARING vbeln. * Serial numbers REFRESH it_sernr. LOOP AT s_content. CLEAR: wa_sernr. SPLIT s_content AT tab INTO wa_sernr-vbeln wa_sernr-posnr wa_sernr-matnr wa_sernr-pikmg wa_sernr-kodat wa_sernr-sernr wa_sernr-extra1 wa_sernr-extra2 wa_sernr-extra3 wa_sernr-extra4 wa_sernr-extra5. if wa_sernr-sernr eq space. else. nvbeln = wa_sernr-vbeln. wa_sernr-vbeln = nvbeln. nposnr = wa_sernr-posnr. wa_sernr-posnr = nposnr. if wa_sernr-matnr co '0123456789 '. nmatnr = wa_sernr-matnr. wa_sernr-matnr = nmatnr. else. translate wa_sernr-matnr to upper case. shift wa_sernr-matnr left deleting leading space. endif.

if wa_sernr-sernr co '0123456789 '. nsernr = wa_sernr-sernr. wa_sernr-sernr = nsernr. else. translate wa_sernr-sernr to upper case. shift wa_sernr-sernr left deleting leading space. endif. APPEND wa_sernr TO it_sernr. endif. ENDLOOP. SORT it_sernr BY vbeln posnr. ENDFORM. " MODIFY_DATA

*&---------------------------------------------------------------------* *& Form VALIDATE_DATA *&---------------------------------------------------------------------* form VALIDATE_DATA. REFRESH: REFRESH: REFRESH: REFRESH: xlikp. xlips. xvbup. xmarc. CLEAR: CLEAR: CLEAR: CLEAR: xlikp. xlips. xvbup. xmarc.

SELECT * FROM likp INTO TABLE xlikp FOR ALL ENTRIES IN it_lips2 WHERE vbeln EQ it_lips2-vbeln. SELECT * FROM lips INTO TABLE xlips FOR ALL ENTRIES IN it_lips1 WHERE vbeln EQ it_lips1-vbeln. SELECT * FROM vbup INTO TABLE xvbup FOR ALL ENTRIES IN it_lips1 WHERE vbeln EQ it_lips1-vbeln. IF NOT xlips[] IS initial. SELECT * FROM marc INTO TABLE xmarc FOR ALL ENTRIES IN xlips WHERE matnr EQ xlips-matnr AND werks EQ xlips-werks. ENDIF. * delivery header LOOP AT it_lips2. READ TABLE xlikp WITH KEY vbeln = it_lips2-vbeln. IF sy-subrc GT 0. LOOP AT it_lips1 WHERE vbeln EQ it_lips2-vbeln. CLEAR errtab. errtab-vbeln = it_lips1-vbeln. errtab-posnr = it_lips1-posnr. errtab-matnr = it_lips1-matnr. errtab-pikmg = it_lips1-pikmg. errtab-msg = 'Invalid Delivery'. LOOP AT it_sernr WHERE vbeln EQ it_lips1-vbeln AND posnr EQ it_lips1-posnr. errtab-sernr = it_sernr-sernr. APPEND errtab. CLEAR errtab-sernr. ENDLOOP. IF sy-subrc GT 0. APPEND errtab. ENDIF. ENDLOOP. ENDIF. ENDLOOP. LOOP AT errtab. DELETE it_lips2 WHERE vbeln EQ errtab-vbeln.

DELETE it_lips1 WHERE vbeln EQ errtab-vbeln. DELETE it_sernr WHERE vbeln EQ errtab-vbeln. ENDLOOP. * delivery items LOOP AT it_lips1. READ TABLE xlips WITH KEY vbeln = it_lips1-vbeln posnr = it_lips1-posnr. IF sy-subrc EQ 0. READ TABLE xvbup WITH KEY vbeln = it_lips1-vbeln posnr = it_lips1-posnr. IF xvbup-kosta EQ 'B' or xvbup-kosta EQ 'C'. CLEAR errtab. errtab-vbeln = it_lips1-vbeln. errtab-posnr = it_lips1-posnr. errtab-matnr = it_lips1-matnr. errtab-pikmg = it_lips1-pikmg. errtab-msg = 'Delivery Item has already been picked'. errtab-rcd_ok = 'A'. LOOP AT it_sernr WHERE vbeln EQ it_lips1-vbeln AND posnr EQ it_lips1-posnr. errtab-sernr = it_sernr-sernr. APPEND errtab. CLEAR errtab-sernr. ENDLOOP. IF sy-subrc GT 0. APPEND errtab. ENDIF. ENDIF. ELSE. CLEAR errtab. errtab-vbeln = it_lips1-vbeln. errtab-posnr = it_lips1-posnr. errtab-matnr = it_lips1-matnr. errtab-pikmg = it_lips1-pikmg. errtab-msg = 'Invalid Delivery Item'. LOOP AT it_sernr WHERE vbeln EQ it_lips1-vbeln AND posnr EQ it_lips1-posnr. errtab-sernr = it_sernr-sernr. APPEND errtab. CLEAR errtab-sernr. ENDLOOP. IF sy-subrc GT 0. APPEND errtab. ENDIF. ENDIF. ENDLOOP. LOOP AT errtab. DELETE it_lips2 WHERE vbeln EQ errtab-vbeln. DELETE it_lips1 WHERE vbeln EQ errtab-vbeln. DELETE it_sernr WHERE vbeln EQ errtab-vbeln. ENDLOOP. * serialization LOOP AT it_sernr. clear xlips. READ TABLE xlips WITH KEY vbeln posnr clear xmarc. READ TABLE xmarc WITH KEY matnr werks IF xmarc-sernp EQ space.

= it_sernr-vbeln = it_sernr-posnr. = xlips-matnr = xlips-werks.

CLEAR errtab. errtab-vbeln = it_sernr-vbeln. errtab-posnr = it_sernr-posnr. errtab-matnr = it_sernr-matnr. errtab-pikmg = it_sernr-pikmg. errtab-msg = 'Material is not set up for serialization'. errtab-sernr = it_sernr-sernr. APPEND errtab. ENDIF. ENDLOOP. LOOP AT errtab. DELETE it_lips2 WHERE vbeln EQ errtab-vbeln. DELETE it_lips1 WHERE vbeln EQ errtab-vbeln. DELETE it_sernr WHERE vbeln EQ errtab-vbeln. ENDLOOP. * materials LOOP AT it_lips1. CLEAR xmarc. READ TABLE xmarc WITH KEY matnr = it_lips1-matnr. IF sy-subrc GT 0. CLEAR errtab. errtab-vbeln = it_lips1-vbeln. errtab-posnr = it_lips1-posnr. errtab-matnr = it_lips1-matnr. errtab-pikmg = it_lips1-pikmg. errtab-msg = 'Invalid Material'. LOOP AT it_sernr WHERE vbeln EQ it_lips1-vbeln AND posnr EQ it_lips1-posnr. errtab-sernr = it_sernr-sernr. APPEND errtab. CLEAR errtab-sernr. ENDLOOP. IF sy-subrc GT 0. APPEND errtab. ENDIF. ENDIF. ENDLOOP. LOOP AT errtab. DELETE it_lips2 WHERE vbeln EQ errtab-vbeln. DELETE it_lips1 WHERE vbeln EQ errtab-vbeln. DELETE it_sernr WHERE vbeln EQ errtab-vbeln. ENDLOOP. DELETE errtab WHERE rcd_ok EQ 'A'. " already processed, not really an error

* Remove BOM parent items - they cannot be picked LOOP AT it_lips1. w_tabix = sy-tabix. READ TABLE xlips WITH KEY vbeln = it_lips1-vbeln uepos = it_lips1-posnr. IF sy-subrc eq 0. DELETE it_lips1 INDEX w_tabix. ENDIF. ENDLOOP. ENDFORM. " VALIDATE_DATA

*&---------------------------------------------------------------------* *& Form BAPI_POST *&---------------------------------------------------------------------*

form BAPI_POST . DATA: LS_VBKOK_WA LT_VBPOK LT_PROT LS_PROT TYPE LIKE TYPE LIKE VBKOK, VBPOK OCCURS 0 WITH HEADER LINE, TABLE OF PROTT, PROTT.

data: lt_serno type SHP_SERNR_UPDATE_T , ls_serno type SHP_SERNR_UPDATE_S. LOOP at it_lips2. " unique deliveries

REFRESH: reptabs. REFRESH: lt_serno. REFRESH: lt_prot. REFRESH: lt_vbpok. CLEAR: ls_vbkok_wa, ls_serno, lt_serno, lt_prot, lt_vbpok, reptabs. ls_vbkok_wa-wabuc = ''. ls_vbkok_wa-vbeln_vl = it_lips2-vbeln. LOOP AT it_lips1 where vbeln EQ it_lips2-vbeln. very lt_vbpok-vbeln_vl = it_lips1-vbeln. lt_vbpok-posnr_vl = it_lips1-posnr. lt_vbpok-vbeln = it_lips1-vbeln. lt_vbpok-posnn = it_lips1-posnr. if it_lips1-pikmg cs ','. " remove commas replace all occurrences of ',' in it_lips1-pikmg with ' '. condense it_lips1-pikmg no-gaps. shift it_lips1-pikmg left deleting leading space. endif. lt_vbpok-matnr = it_lips1-matnr. lt_vbpok-lianp = 'X'. " change delivery qty clear xlips. READ TABLE xlips WITH KEY vbeln = it_lips1-vbeln posnr = it_lips1-posnr. lt_vbpok-lfimg = xlips-lfimg. lt_vbpok-pikmg = it_lips1-pikmg. APPEND lt_vbpok. reptabs-vbeln = it_lips1-vbeln. reptabs-posnr = it_lips1-posnr. reptabs-pikmg = lt_vbpok-pikmg. reptabs-matnr = it_lips1-matnr. LOOP AT it_sernr WHERE vbeln eq it_lips1-vbeln " serial numbers per item AND posnr eq it_lips1-posnr. ls_serno-rfbel = it_sernr-vbeln. ls_serno-rfpos = it_sernr-posnr. ls_serno-sernr = it_sernr-sernr. APPEND ls_serno TO lt_serno. reptabs-sernr = it_sernr-sernr. APPEND reptabs. CLEAR reptabs-sernr. ENDLOOP. IF SY-SUBRC GT 0. APPEND reptabs. CLEAR reptabs. ENDIF. ENDLOOP. CALL FUNCTION 'WS_DELIVERY_UPDATE' " unique items / deli

EXPORTING vbkok_wa = synchron = commit = delivery = update_picking = if_error_messages_send_0 = nicht_sperren = it_sernr_update = TABLES vbpok_tab = prot = IF SY-SUBRC EQ 0. LOOP AT lt_prot INTO ls_prot

ls_vbkok_wa 'X' 'X' ls_vbkok_wa-vbeln_vl 'X' '' space lt_serno lt_vbpok lt_prot. WHERE msgty EQ 'E' OR msgty EQ 'A'.

ENDLOOP. IF SY-SUBRC EQ 0. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING MSGID = ls_prot-msgid MSGNR = ls_prot-msgno MSGV1 = ls_prot-msgv1 MSGV2 = ls_prot-msgv2 MSGV3 = ls_prot-msgv3 MSGV4 = ls_prot-msgv4 IMPORTING MESSAGE_TEXT_OUTPUT = w_msg. REPTABS-MSG = W_MSG. MODIFY REPTABS TRANSPORTING MSG WHERE MSG EQ SPACE. APPEND LINES OF REPTABS TO ERRTAB. ELSE. CALL FUNCTION 'DEQUEUE_ALL'. PERFORM PGI_DELIVERY. ENDIF. ELSE. REPTABS-MSG = 'Unable to update delivery'. MODIFY REPTABS TRANSPORTING MSG WHERE MSG EQ SPACE. APPEND LINES OF REPTABS TO ERRTAB. ENDIF. ENDLOOP. endform. " BAPI_POST

*---------------------------------------------------------------------* * FORM PGI_DELIVERY * *---------------------------------------------------------------------* FORM PGI_DELIVERY. REFRESH BDCDATA. CLEAR * First screen PERFORM ZA_BDC_NEWSCREEN PERFORM ZB_BDC_DATA PERFORM ZB_BDC_DATA * Post Goods Issue PERFORM ZA_BDC_NEWSCREEN PERFORM ZB_BDC_DATA BDCDATA. USING 'SAPMV50A' USING 'LIKP-VBELN' USING 'BDC_OKCODE' USING 'SAPMV50A' USING 'BDC_OKCODE' '4004'. IT_LIPS2-VBELN. '/00'. '1000'. '=WABU_T'.

CALL TRANSACTION 'VL02N' USING BDCDATA OPTIONS FROM CTU_PARAMS. IF SY-SUBRC EQ 0.

COMMIT WORK AND WAIT. REPTABS-MSG = 'Delivery updated; PGI completed'. MODIFY REPTABS TRANSPORTING MSG WHERE MSG EQ SPACE. APPEND LINES OF REPTABS TO REPTAB. ELSE. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING MSGID = SY-MSGID MSGNR = SY-MSGNO MSGV1 = SY-MSGV1 MSGV2 = SY-MSGV2 MSGV3 = SY-MSGV3 MSGV4 = SY-MSGV4 IMPORTING MESSAGE_TEXT_OUTPUT = W_MSG. REPTABS-MSG = W_MSG. MODIFY REPTABS TRANSPORTING MSG WHERE MSG EQ SPACE. APPEND LINES OF REPTABS TO ERRTAB. ENDIF. ENDFORM. *---------------------------------------------------------------------* * FORM ZA_BDC_NEWSCREEN * *---------------------------------------------------------------------* FORM ZA_BDC_NEWSCREEN USING SCRNAM SCRNO. BDCDATA-PROGRAM BDCDATA-DYNPRO BDCDATA-DYNBEGIN APPEND BDCDATA. ENDFORM. *---------------------------------------------------------------------* * FORM ZB_BDC_DATA * *---------------------------------------------------------------------* FORM ZB_BDC_DATA USING FNAM FVAL. BDCDATA-FNAM = FNAM. BDCDATA-FVAL = FVAL. APPEND BDCDATA. CLEAR BDCDATA. ENDFORM. *---------------------------------------------------------------------* * FORM MOVE_TO_ARCHIVE * *---------------------------------------------------------------------* form MOVE_TO_ARCHIVE. DATA: parcom(250), parcom_loc LIKE parcom, p_ifile LIKE rlgrap-filename, p_ofile LIKE rlgrap-filename, w_line(10) TYPE c. DATA: BEGIN OF tabl OCCURS 0, line(200), END OF tabl. * Shipment file = SCRNAM. = SCRNO. = 'X'. CLEAR BDCDATA.

LOOP AT DIR_TABLE WHERE FILENAME(14) EQ 'TRILLIANT_SHIP'. REFRESH tabl. CLEAR: gv_app_ser, gv_app_arc, parcom, parcom_loc. CONCATENATE ftpdir '\' dir_table-filename INTO gv_app_ser. CONCATENATE ftpdir '\archive\' dir_table-filename INTO gv_app_arc. CONCATENATE 'move' gv_app_ser gv_app_arc INTO parcom SEPARATED BY space. parcom_loc = parcom. CALL 'SYSTEM' ID 'COMMAND' FIELD parcom_loc ID 'TAB' FIELD tabl-*sys*. DESCRIBE TABLE tabl LINES zlines. ENDLOOP. * Serial number file LOOP AT DIR_TABLE WHERE FILENAME(16) EQ 'TRILLIANT_SERIAL'. REFRESH tabl. CLEAR: gv_app_ser, gv_app_arc, parcom, parcom_loc. CONCATENATE ftpdir '\' dir_table-filename INTO gv_app_ser. CONCATENATE ftpdir '\archive\' dir_table-filename INTO gv_app_arc. CONCATENATE 'move' gv_app_ser gv_app_arc INTO parcom SEPARATED BY space. parcom_loc = parcom. REFRESH tabl. CALL 'SYSTEM' ID 'COMMAND' FIELD parcom_loc ID 'TAB' FIELD tabl-*sys*. DESCRIBE TABLE tabl LINES zlines. ENDLOOP. ENDFORM. *---------------------------------------------------------------------* * FORM REPORT_UPDATES * *---------------------------------------------------------------------* form REPORT_UPDATES. DESCRIBE TABLE REPTAB LINES ZLINES. IF ZLINES GT 0. W_RPT = '1'. SY-PAGNO = 0. NEW-PAGE. LOOP AT REPTAB. FORMAT COLOR COL_NORMAL INTENSIFIED OFF. WRITE: /1 REPTAB-VBELN, REPTAB-POSNR, REPTAB-MATNR, (10) REPTAB-PIKMG, REPTAB-SERNR, (60) REPTAB-MSG, 132 ' '. ENDLOOP. SKIP 2. FORMAT COLOR COL_HEADING INTENSIFIED OFF. WRITE: /1 'Number of delivery/items updated:', ZLINES. ENDIF. DESCRIBE TABLE ERRTAB LINES ELINES. IF ELINES GT 0. W_RPT = '2'. SY-PAGNO = 0. NEW-PAGE.

LOOP AT ERRTAB. FORMAT COLOR COL_NORMAL INTENSIFIED OFF. WRITE: /1 ERRTAB-VBELN, ERRTAB-POSNR, ERRTAB-MATNR, (10) ERRTAB-PIKMG, ERRTAB-SERNR, (60) ERRTAB-MSG, 132 ' '. ENDLOOP. SKIP 2. FORMAT COLOR COL_HEADING INTENSIFIED OFF. WRITE: /1 'Number of records in error:', ELINES. ENDIF. SKIP 2. FORMAT COLOR COL_HEADING INTENSIFIED OFF. E_PRINT_LINE = '********* END OF REPORT *********'. PERFORM JUST_ROUTINE(RSBTCHH0) USING E_PRINT_LINE SY-LINSZ. WRITE: / E_PRINT_LINE. ENDFORM. *---------------------------------------------------------------------* * FORM ZTOP_OF_PAGE * *---------------------------------------------------------------------* FORM ZTOP-OF-PAGE. FORMAT COLOR COL_HEADING INTENSIFIED ON. W_PRINT_LINE = SY-TITLE. PERFORM JUST_ROUTINE(RSBTCHH0) USING W_PRINT_LINE SY-LINSZ. WRITE R_DATIME TO W_PRINT_LINE+0(20). WRITE 'Page' TO W_PRINT_LINE+122(4). WRITE SY-PAGNO TO W_PRINT_LINE+126(6). WRITE: / W_PRINT_LINE. SKIP 1. FORMAT COLOR COL_HEADING INTENSIFIED OFF. WRITE: /1 'Delivery', 12 'Item', 19 'Material', 39 'Pick Qty', 49 'Serial No', 68 'Message', 132 ' '. ULINE: /(132). ENDFORM. *-------------------------- Top of Page -----------------------------* TOP-OF-PAGE. PERFORM ZTOP-OF-PAGE. TOP-OF-PAGE DURING LINE-SELECTION. PERFORM ZTOP-OF-PAGE. ************************************************************************ * END OF PROGRAM * ************************************************************************