jueves, 23 de diciembre de 2010

Abap que crea script VBS

*Manda pulsaciones de teclas como si el usuario las invocara, llena la XD02

report zbatchxd02.
data begin of i_upload occurs 0.
data line(255).
data end of i_upload.

parameter p_name like rlgrap-filename.

data begin of i_outtab occurs 0.
data line(255).
data end of i_outtab.

data: begin of record,
customer(100),
name(100),
name2(100),
name3(100),
name4(100),
street(100),
street2(100),
housenumber(100),
house(100),
nosuppl(100),
district(100),
street3(100),
street4(100),
city(100),
region(100),
postalcode(100),
country(100),
telephone1(100),
taxcode1(100),
taxcode2(100),
zipcode(100),
end of record.


*$*$********************************************************************
*$*$ AT SELECTION-SCREEN
*$*$********************************************************************
at selection-screen.

* Para la seleccion del archivo a convertir
at selection-screen on value-request for p_name.
call function 'KD_GET_FILENAME_ON_F4'
exporting
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = ''
static = ''
mask = ''
changing
file_name = p_name
exceptions
mask_too_long = 1
others = 2.

*$*$********************************************************************
*$*$ START-OF-SELECTION
*$*$********************************************************************
start-of-selection.
perform leer_archivo.
perform procesa_datos.
perform baja_script.
*Perform BATCHINPUT.

*$*$********************************************************************
*$*$ FORMS
*$*$********************************************************************
*&---------------------------------------------------------------------*
*& Form LEER_ARCHIVO
*&---------------------------------------------------------------------*
form leer_archivo.

* Para cargar el archivo de entrada
refresh i_upload.
call function 'WS_UPLOAD'
exporting
filename = p_name
* Filetype = 'WK1'
tables
data_tab = i_upload
exceptions
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10.

endform. " LEER_ARCHIVO

*&---------------------------------------------------------------------*
*& Form PROCESA_DATOS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form procesa_datos.
clear: record.
data: c_tab type x value '09'.
loop at i_upload.
translate i_upload-line using '" '.
condense i_upload-line.
modify i_upload.
endloop.
i_outtab-line = 'set WshShell = WScript.CreateObject("WScript.Shell")'.
append i_outtab.

loop at i_upload.
split i_upload-line at c_tab into
record-customer
record-name
record-name2
record-name3
record-name4
record-street
record-street2
record-housenumber
record-nosuppl
record-district
record-street3
record-street4
record-city
record-region
record-postalcode
record-country
record-telephone1
record-taxcode1
record-taxcode2
record-zipcode.

condense: record-customer
,record-name
,record-name2
,record-name3
,record-name4
,record-street
,record-street2
,record-housenumber
,record-nosuppl
,record-district
,record-street3
,record-street4
,record-city
,record-region
,record-postalcode
,record-country
,record-telephone1
,record-taxcode1
,record-taxcode2
,record-zipcode.

i_outtab-line = 'WScript.Sleep 3500'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys
"{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{DEL}{
del}{del}"'.
append i_outtab.
*CUSTOMER
concatenate 'WshShell.SendKeys "' record-customer '"' into i_outtab-line
. append i_outtab.
*ENTER
i_outtab-line = 'WshShell.SendKeys "~"'.
append i_outtab.
i_outtab-line = 'WScript.Sleep 1500'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.




*NAME1
concatenate 'WshShell.SendKeys "' record-name '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*NAME2
concatenate 'WshShell.SendKeys "' record-name2 '"' into i_outtab-line.
append i_outtab.
*PREGUNTAMOS SI ES DE 2 RENGLONES
i_outtab-line = 'intAnswer = Msgbox("¿Es de 2 campos?", vbYesNo,
"Script")'.
append i_outtab.
i_outtab-line = 'If intAnswer = vbYes Then'.
append i_outtab.

i_outtab-line = 'WshShell.SendKeys "{TAB}{TAB}{TAB}"'.
append i_outtab.
i_outtab-line = 'Else'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}{DEL}{TAB}{TAB}{TAB}"'.
append i_outtab.
i_outtab-line = 'End If'.
append i_outtab.


*STREET
concatenate 'WshShell.SendKeys "' record-street '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*HOUSE NUMBER
concatenate 'WshShell.SendKeys "' record-housenumber '"' into
i_outtab-line. append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*POSTAL CODE
concatenate 'WshShell.SendKeys "' record-postalcode '"' into
i_outtab-line. append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*CITY
concatenate 'WshShell.SendKeys "' record-city '"' into
i_outtab-line. append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*DISTRICT
i_outtab-line = 'WshShell.SendKeys"{DEL}"'.append i_outtab.
concatenate 'WshShell.SendKeys "' record-district '"' into
i_outtab-line. append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*MANDA ESPACIO Y ESPERA
i_outtab-line = 'WshShell.SendKeys " "'.
append i_outtab.
i_outtab-line = 'WScript.Sleep 1500'.
append i_outtab.
*NAME3

concatenate 'WshShell.SendKeys "' record-name3 '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.

*NAME4
concatenate 'WshShell.SendKeys "' record-name4 '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}{TAB}"'.
append i_outtab.
*HOUSENOSUPPLY
concatenate 'WshShell.SendKeys "' record-nosuppl '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*STREET3
concatenate 'WshShell.SendKeys "' record-street3 '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*STREET4
concatenate 'WshShell.SendKeys "' record-street4 '"' into i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys
"{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}"'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys " "'.
append i_outtab.
i_outtab-line = 'WScript.Sleep 1500'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
*REGION
*concatenate 'WshShell.SendKeys "' record-region '"' into i_outtab-line.
* append i_outtab.
i_outtab-line = 'WshShell.SendKeys
"{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}"'.
append i_outtab.
*Telephone1
*concatenate 'WshShell.SendKeys "' record-telephone1 '"' into
*i_outtab-line.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{F8}"'.
append i_outtab.
i_outtab-line = 'WScript.Sleep 1500'.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}"'.
append i_outtab.

*Taxcode1
concatenate 'WshShell.SendKeys "' record-taxcode1 '"' into i_outtab-line
.
append i_outtab.
i_outtab-line = 'WshShell.SendKeys "{TAB}"'.
append i_outtab.

*Taxcode2
concatenate 'WshShell.SendKeys "' record-taxcode2 '"' into i_outtab-line
.
i_outtab-line = 'MsgBox "¿Grabar ahora?"'.
append i_outtab.
i_outtab-line = 'WScript.Sleep 2500'.

i_outtab-line = 'WshShell.SendKeys "^s"'.
append i_outtab.

clear i_outtab.
append i_outtab.

endloop.

endform. " PROCESA_DATOS

*&---------------------------------------------------------------------*
*& Form BAJA_SCRIPT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form baja_script.
concatenate p_name '.vbs' into p_name.
call function 'WS_DOWNLOAD'
exporting
* BIN_FILESIZE = ' '
* CODEPAGE = ' '
filename = p_name
* FILETYPE = 'DAT'
* filetype = 'WK1'
* MODE = ' '
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* COL_SELECT = ' '
* COL_SELECTMASK = ' '
* importing
* filelength =
tables
data_tab = i_outtab
* FIELDNAMES =
exceptions
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
others = 8.

if sy-subrc = 0.
skip.
write:/ 'Script bajado'.
endif.
endform. " BAJA_SCRIPT

No hay comentarios: