Mostrar mensagens com a etiqueta field-symbols. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta field-symbols. Mostrar todas as mensagens

sexta-feira, 9 de abril de 2010

How to write any table (example)

*&---------------------------------------------------------------------*
*& Report ZSL_EX_6
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zsl_ex_6.

*&--------------------------------------------------------------------*
*& Form write_table
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->P_TABLE text
*---------------------------------------------------------------------*
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


TYPES: BEGIN OF my_line_type,
name TYPE string,
birth_date TYPE d,
salary TYPE p DECIMALS 2,
END OF my_line_type,

my_table_type TYPE HASHED TABLE OF my_line_type
WITH UNIQUE KEY name birth_date.

DATA: my_wa TYPE my_line_type,
my_table TYPE my_table_type.

*&--------------------------------------------------------------------*
START-OF-SELECTION.
*&--------------------------------------------------------------------*
my_wa-name = 'Peter Smith'.
my_wa-birth_date = '19640303'.
my_wa-salary = '20000.00'.
INSERT my_wa INTO TABLE my_table.

my_wa-name = 'April May June'.
my_wa-birth_date = '19660401'.
my_wa-salary = '1000000.00'.
INSERT my_wa INTO TABLE my_table.

my_wa-name = 'Maria albertina'.
my_wa-birth_date = '19640601'.
my_wa-salary = '1.00'.
INSERT my_wa INTO TABLE my_table.

PERFORM write_table USING my_table.

quinta-feira, 4 de março de 2010

How to Access or change variables that are not passed in user exit

Many times we are faced with scenarios that require some SAP standard parameters to be changed or accessed. However, these parameters are not always available in user-exit's interface. This is peculiar to versions earlier than ECC where enhancement spot concept was not available.

In these cases, the parameter can be accessed and the value can be changed using the concept of pointers in ABAP. Here we assume that the parameter is declared either in the parent program, or in some other extrnal program (which has been triggered before user-exit call), but the parameter is not passed to the available user-exit.

The idea is to get the reference of the memory area of the required parameter and then assign a local pointer to access this memory area. Following example demonstrates this method:


data: wv_table(50) type c.

field-symbols: ‹wf_table› type any ,
‹wf_reference› type table.
DATA: wo_ref TYPE REF TO DATA.
wv_table = '(SAPLFPAYM_DE)DTADDEZ[]'.
ASSIGN (wv_table) TO ‹wf_table›.
GET REFERENCE OF ‹wf_table› INTO wo_ref.
ASSIGN wo_ref-›* TO ‹wf_reference›.
IF sy-subrc IS INITIAL.
loop at DTADDEZ.
* Manipulate the value of standard parameter here
* Then update to pass back the value
modify from dtaddez.
endloop.
endif.