Esse programa eu fiz para gerar um arquivo com as estratégias de liberação criadas em DEV para serem importados em QA ou PRD.
REPORT zmmb0009 MESSAGE-ID zmm NO STANDARD PAGE HEADING LINE-COUNT 65
LINE-SIZE 255.
TYPE-POOLS: icon.
TABLES: t16fs.
TYPES: BEGIN OF tp_file,
tipo TYPE char1, "(N)num,(C)char,(X)Curr
objectkey TYPE bapi1003_key-object,
objecttable TYPE bapi1003_key-objecttable,
classnum TYPE bapi1003_key-classnum,
classtype TYPE bapi1003_key-classtype,
charact TYPE char30,
value_from TYPE char30,
value_to TYPE char30,
value_relation TYPE char1,
unit_from TYPE char3,
unit_to TYPE char3,
unit_from_iso TYPE char3,
unit_to_iso TYPE char3,
inherited TYPE char1,
instance TYPE numc3,
charact_descr TYPE char30,
value_char TYPE char30,
value_neutral TYPE char30,
currency_from TYPE char5,
currency_to TYPE char5,
currency_from_iso TYPE char30,
currency_to_iso TYPE char30,
END OF tp_file.
DATA: t_grpest TYPE TABLE OF t16fs WITH HEADER LINE,
t_file TYPE TABLE OF tp_file WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF BLOCK b11 WITH FRAME TITLE text-002.
PARAMETERS: pr_imp RADIOBUTTON GROUP g1 MODIF ID G1 USER-COMMAND USCOM,
pr_exp RADIOBUTTON GROUP g1 DEFAULT 'X' MODIF ID G1.
SELECTION-SCREEN END OF BLOCK b11.
PARAMETERS: p_frggr TYPE frggr OBLIGATORY DEFAULT 'G3',
p_clsnum TYPE bapi1003_key-classnum
DEFAULT 'LIBERACAO_PEDIDO' OBLIGATORY,
p_clstyp TYPE bapi1003_key-classtype
DEFAULT '032' OBLIGATORY.
SELECT-OPTIONS: s_frgsx FOR t16fs-frgsx.
SELECTION-SCREEN SKIP.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
******************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
******************************
PERFORM value_request_file.
******************************
START-OF-SELECTION.
******************************
PERFORM seleciona_dados.
PERFORM processa_dados.
PERFORM exportar_dados.
******************************
END-OF-SELECTION.
******************************
*&---------------------------------------------------------------------*
*& Form SELECIONA_DADOS
*&---------------------------------------------------------------------*
FORM seleciona_dados .
IF pr_exp = 'X'.
SELECT *
INTO TABLE t_grpest
FROM t16fs
WHERE frggr EQ p_frggr
AND frgsx IN s_frgsx.
IF sy-subrc <> 0.
MESSAGE i000 WITH text-mo1.
STOP.
ENDIF.
ELSE.
PERFORM importar_dados.
IF t_file[] IS INITIAL.
MESSAGE i000 WITH text-mo1.
STOP.
ENDIF.
ENDIF.
ENDFORM. " SELECIONA_DADOS
*&---------------------------------------------------------------------*
*& Form PROCESSA_DADOS
*&---------------------------------------------------------------------*
FORM processa_dados .
DATA: lt_num TYPE TABLE OF bapi1003_alloc_values_num,
lt_char TYPE TABLE OF bapi1003_alloc_values_char,
lt_curr TYPE TABLE OF bapi1003_alloc_values_curr,
lt_return TYPE TABLE OF bapiret2.
DATA: lt_head TYPE TABLE OF tp_file WITH HEADER LINE.
DATA: ls_bapi TYPE bapi1003_key,
ls_num TYPE bapi1003_alloc_values_num,
ls_char TYPE bapi1003_alloc_values_char,
ls_curr TYPE bapi1003_alloc_values_curr,
ls_return TYPE bapiret2.
IF pr_exp = 'X'.
LOOP AT t_grpest.
CLEAR ls_bapi.
CONCATENATE t_grpest-frggr t_grpest-frgsx INTO ls_bapi-object.
ls_bapi-objecttable = 'T16FS'.
ls_bapi-classnum = p_clsnum.
ls_bapi-classtype = p_clstyp.
REFRESH: lt_num, lt_char, lt_curr, lt_return.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = ls_bapi-object
objecttable = ls_bapi-objecttable
classnum = ls_bapi-classnum
classtype = ls_bapi-classtype
TABLES
allocvaluesnum = lt_num
allocvalueschar = lt_char
allocvaluescurr = lt_curr
return = lt_return.
READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: / icon_red_light AS ICON, text-002, ls_bapi-object.
PERFORM lista_erros TABLES lt_return.
ELSE.
WRITE: / icon_green_light AS ICON, text-002, ls_bapi-object.
LOOP AT lt_num INTO ls_num.
CLEAR t_file.
t_file-tipo = 'N'.
t_file-objectkey = ls_bapi-object.
t_file-objecttable = ls_bapi-objecttable.
t_file-classnum = ls_bapi-classnum.
t_file-classtype = ls_bapi-classtype.
t_file-charact = ls_num-charact.
t_file-value_from = ls_num-value_from.
t_file-value_to = ls_num-value_to.
t_file-value_relation = ls_num-value_relation.
t_file-unit_from = ls_num-unit_from.
t_file-unit_to = ls_num-unit_to.
t_file-unit_from_iso = ls_num-unit_from_iso.
t_file-unit_to_iso = ls_num-unit_to_iso.
t_file-inherited = ls_num-inherited.
t_file-instance = ls_num-instance.
t_file-charact_descr = ls_num-charact_descr.
APPEND t_file.
ENDLOOP.
LOOP AT lt_char INTO ls_char.
CLEAR t_file.
t_file-tipo = 'C'.
t_file-objectkey = ls_bapi-object.
t_file-objecttable = ls_bapi-objecttable.
t_file-classnum = ls_bapi-classnum.
t_file-classtype = ls_bapi-classtype.
t_file-charact = ls_char-charact.
t_file-value_char = ls_char-value_char.
t_file-inherited = ls_char-inherited.
t_file-instance = ls_char-instance.
t_file-value_neutral = ls_char-value_neutral.
t_file-charact_descr = ls_char-charact_descr.
APPEND t_file.
ENDLOOP.
LOOP AT lt_curr INTO ls_curr.
CLEAR t_file.
t_file-tipo = 'X'.
t_file-objectkey = ls_bapi-object.
t_file-objecttable = ls_bapi-objecttable.
t_file-classnum = ls_bapi-classnum.
t_file-classtype = ls_bapi-classtype.
t_file-charact = ls_curr-charact.
t_file-value_from = ls_curr-value_from.
t_file-value_to = ls_curr-value_to.
t_file-value_relation = ls_curr-value_relation.
t_file-currency_from = ls_curr-currency_from.
t_file-currency_to = ls_curr-currency_to.
t_file-currency_from_iso = ls_curr-currency_from_iso.
t_file-currency_to_iso = ls_curr-currency_to_iso.
t_file-inherited = ls_curr-inherited.
t_file-instance = ls_curr-instance.
t_file-charact_descr = ls_curr-charact_descr.
APPEND t_file.
ENDLOOP.
ENDIF.
ENDLOOP.
ELSE.
lt_head[] = t_file[].
SORT lt_head BY objectkey objecttable classnum classtype.
DELETE ADJACENT DUPLICATES FROM lt_head
COMPARING objectkey objecttable classnum classtype.
LOOP AT lt_head.
REFRESH: lt_num, lt_char, lt_curr, lt_return.
LOOP AT t_file WHERE objectkey EQ lt_head-objectkey
AND objecttable EQ lt_head-objecttable
AND classnum EQ lt_head-classnum
AND classtype EQ lt_head-classtype.
CASE t_file-tipo.
WHEN 'N'.
CLEAR ls_num.
ls_num-charact = t_file-charact.
ls_num-value_from = t_file-value_from.
ls_num-value_to = t_file-value_to.
ls_num-value_relation = t_file-value_relation.
ls_num-unit_from = t_file-unit_from.
ls_num-unit_to = t_file-unit_to.
ls_num-unit_from_iso = t_file-unit_from_iso.
ls_num-unit_to_iso = t_file-unit_to_iso.
ls_num-inherited = t_file-inherited.
ls_num-instance = t_file-instance.
ls_num-charact_descr = t_file-charact_descr.
APPEND ls_num TO lt_num.
WHEN 'C'.
CLEAR ls_char.
ls_char-charact = t_file-charact.
ls_char-value_char = t_file-value_char.
ls_char-inherited = t_file-inherited.
ls_char-instance = t_file-instance.
ls_char-value_neutral = t_file-value_neutral.
ls_char-charact_descr = t_file-charact_descr.
APPEND ls_char TO lt_char.
WHEN 'X'.
CLEAR ls_curr.
ls_curr-charact = t_file-charact.
ls_curr-value_from = t_file-value_from.
ls_curr-value_to = t_file-value_to.
ls_curr-value_relation = t_file-value_relation.
ls_curr-currency_from = t_file-currency_from.
ls_curr-currency_to = t_file-currency_to.
ls_curr-currency_from_iso = t_file-currency_from_iso.
ls_curr-currency_to_iso = t_file-currency_to_iso.
ls_curr-inherited = t_file-inherited.
ls_curr-instance = t_file-instance.
ls_curr-charact_descr = t_file-charact_descr.
APPEND ls_curr TO lt_curr.
ENDCASE.
ENDLOOP.
CALL FUNCTION 'BAPI_OBJCL_CREATE'
EXPORTING
objectkeynew = lt_head-objectkey
objecttablenew = lt_head-objecttable
classnumnew = lt_head-classnum
classtypenew = lt_head-classtype
TABLES
allocvaluesnum = lt_num
allocvalueschar = lt_char
allocvaluescurr = lt_curr
return = lt_return.
READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: / icon_red_light AS ICON, text-002, lt_head-objectkey.
PERFORM lista_erros TABLES lt_return.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
WRITE: / icon_green_light AS ICON, text-002, lt_head-objectkey.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " PROCESSA_DADOS
*&---------------------------------------------------------------------*
*& Form EXPORTAR_DADOS
*&---------------------------------------------------------------------*
FORM exportar_dados .
DATA: l_string TYPE string.
CHECK pr_exp = 'X'.
l_string = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_string
TABLES
data_tab = t_file
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
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. " EXPORTAR_DADOS
*&---------------------------------------------------------------------*
*& Form VALUE_REQUEST_FILE
*&---------------------------------------------------------------------*
FORM value_request_file.
DATA: l_string TYPE string.
IF pr_exp = 'X'.
CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
EXPORTING
window_title = 'Salvar'
initial_directory = 'C:/'
IMPORTING
fullpath = l_string.
ELSE.
CALL FUNCTION 'GUI_FILE_LOAD_DIALOG'
EXPORTING
window_title = 'Abrir'
initial_directory = 'C:/'
IMPORTING
fullpath = l_string.
ENDIF.
p_file = l_string.
ENDFORM. " VALUE_REQUEST_FILE
*&---------------------------------------------------------------------*
*& Form IMPORTAR_DADOS
*&---------------------------------------------------------------------*
FORM importar_dados .
DATA: l_string TYPE string.
REFRESH t_file.
l_string = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_string
TABLES
data_tab = t_file
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. " IMPORTAR_DADOS
*&---------------------------------------------------------------------*
*& Form LISTA_ERROS
*&---------------------------------------------------------------------*
FORM lista_erros TABLES ft_return STRUCTURE bapiret2.
LOOP AT ft_return.
CASE ft_return-type.
WHEN 'E'.
WRITE: /5 icon_message_error_small AS ICON.
WHEN 'W'.
WRITE: /5 icon_message_warning_small AS ICON.
WHEN OTHERS.
WRITE: /5 icon_message_information_small AS ICON.
ENDCASE.
WRITE: ft_return-message.
ENDLOOP.
ENDFORM. " LISTA_ERROS
Nenhum comentário:
Postar um comentário