domingo, 13 de fevereiro de 2011

Céu da Boca: Morangos em leite creme

Céu da Boca: Morangos em leite creme: "Para 6 taças Leite creme 250ml de leite meio gordo 100g de açúcar 1 colher de sopa de farinha T55 3 gemas casca de limão Chantilly 20..."

Gosto particularmente das nodoas no livro.tipico :P

quinta-feira, 29 de julho de 2010

How to add text to radio buttons

SELECT-OPTIONS: data FOR zsl_cp_header-pstng_date.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(11) FOR FIELD r1.
PARAMETERS: r1 RADIOBUTTON GROUP rad1 DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(11) FOR FIELD r2.
PARAMETERS: r2 RADIOBUTTON GROUP rad1.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN:END OF BLOCK block01.

quinta-feira, 6 de maio de 2010

How to Download/upload files to server

*&---------------------------------------------------------------------*
*& Report Z_FORMA_UPLOAD_TRANSFER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT z_forma_upload_transfer.


DATA: p_file_aux TYPE string.

TYPES: BEGIN OF s_file,
* bldat(8),
* budat(8),
* bwartwa(3),
* werks_d(4),
* lgort_d(4),
* matnr(18),
* erfmg(10),
kunnr(16),
name1(35),

END OF s_file.

DATA: BEGIN OF st_file,
* bldat(8),
* budat(8),
* bwartwa(3),
* werks_d(4),
* lgort_d(4),
* matnr(18),
* erfmg(10),
kunnr(16),
name1(35),
END OF st_file.



DATA: t_file TYPE s_file OCCURS 0,
wa_file TYPE s_file.


PARAMETERS: p_file LIKE rlgrap-filename,
p_fserv LIKE rlgrap-filename DEFAULT '.\teste_upload.txt'.


PARAMETERS: p_up RADIOBUTTON GROUP rad1,
p_dow RADIOBUTTON GROUP rad1.

*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*&---------------------------------------------------------------------*

PERFORM f4_filename.


*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*

IF p_up = 'X'.
PERFORM upload_file.
PERFORM transfer_to_server TABLES t_file.
ELSEIF p_dow = 'X'.
PERFORM download_from_server TABLES t_file.
perform escreve_ficheiro.
ENDIF.




*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*




*&---------------------------------------------------------------------*
*& Form f4_filename
*&---------------------------------------------------------------------*
FORM f4_filename .


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

ENDFORM. " f4_filename
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_FILE text
* -->P_P_FILE text
*----------------------------------------------------------------------*
FORM upload_file.

p_file_aux = p_file.

CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = p_file_aux
filetype = 'ASC'
has_field_separator = 'X'
CHANGING
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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
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. " upload_file

*&---------------------------------------------------------------------*
*& Form transfer_to_server
*&---------------------------------------------------------------------*
FORM transfer_to_server TABLES p_t_file STRUCTURE st_file.

* DELETE t_file INDEX 1.

OPEN DATASET p_fserv FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT t_file INTO wa_file.
TRANSFER wa_file TO p_fserv.
ENDLOOP.


CLOSE DATASET p_fserv.

ENDFORM. " transfer_to_server
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FROM_sERVER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_FILE text
*----------------------------------------------------------------------*
FORM download_from_server TABLES p_t_file STRUCTURE st_file.


OPEN DATASET p_fserv FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.
READ DATASET p_fserv INTO wa_file.
IF sy-subrc = 0.
APPEND wa_file TO t_file.
ELSE.
EXIT.
ENDIF.
ENDDO.

CLOSE DATASET p_fserv.

ENDFORM. " DOWNLOAD_FROM_sERVER

*&---------------------------------------------------------------------*
*& Form escreve_ficheiro
*&---------------------------------------------------------------------*
form escreve_ficheiro .

loop at t_file into wa_file.
write:/ wa_file.
endloop.

endform. " escreve_ficheiro

quarta-feira, 28 de abril de 2010

How to create an F4 for a file

Data: l_file LIKE rlgrap-filename.

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

another similar way:

DATA: return_code TYPE i,
files LIKE file_table OCCURS 0.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
WINDOW_TITLE = 'Title'
* DEFAULT_EXTENSION =
* DEFAULT_FILENAME =
* FILE_FILTER =
* WITH_ENCODING =
* INITIAL_DIRECTORY =
* MULTISELECTION =
CHANGING
file_table = files
rc = return_code
* USER_ACTION =
* FILE_ENCODING =
* EXCEPTIONS
* FILE_OPEN_DIALOG_FAILED = 1
* CNTL_ERROR = 2
* ERROR_NO_GUI = 3
* NOT_SUPPORTED_BY_GUI = 4
* others = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

segunda-feira, 26 de abril de 2010

How to dynamicaly select and print a table (example)

PROGRAM test.

PARAMETER:
table TYPE c LENGTH 30 DEFAULT 'SPFLI',
where TYPE c LENGTH 70 DEFAULT 'carrid = ''AA'''.

DATA:
data_ref TYPE REF TO data.

FIELD-SYMBOLS:
‹tab› TYPE ANY TABLE.


*&--------------------------------------------------------------------*
*& Form write_table
*&--------------------------------------------------------------------*
FORM write_table USING p_table TYPE ANY TABLE.

FIELD-SYMBOLS: ‹line› TYPE data,
‹field› TYPE data.

WRITE:/ '{'.
LOOP AT p_table ASSIGNING ‹line›.
WRITE /4 '('.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE ‹line› TO ‹field›.
IF sy-subrc ‹› 0.
EXIT.
ENDIF.
WRITE /8 ‹field›.
ENDDO. "loop a componente
WRITE /4 ')'.
ENDLOOP. "loop a tabela
WRITE / '}'.
ENDFORM. "write_table

START-OF-SELECTION.
CREATE DATA data_ref TYPE TABLE OF (table).
ASSIGN data_ref->* TO ‹tab›.
SELECT * FROM (table) INTO TABLE ‹tab› WHERE (where).
PERFORM write_table USING ‹tab›.

How to declare a variable dynamicaly

DATA r_elemdescr TYPE REF TO cl_abap_elemdescr.

r_elemdescr ?= cl_abap_elemdescr=>describe_by_name( 'DATA_ELEMENT_HERE' ).

DATA r_field TYPE REF TO data.
FIELD-SYMBOLS ‹field› TYPE ANY.

CREATE DATA r_field TYPE HANDLE r_elemdescr.
ASSIGN r_field->* TO ‹field›.
‹field› = .....

"now ‹field› is your dynamic field value

How to force ALV to process PAI

To force an ALV to go to PAI we can call the method CL_GUI_CFW=>SET_NEW_OK_CODE