*Estrutura para armazenar a tabela e o campo Standard |
TYPES: BEGIN OF ty_tab_inf, |
tab TYPE dd02l-tabname, |
field TYPE dd03t-fieldname, |
END OF ty_tab_inf, |
*Estrutura com os campos do relatório |
BEGIN OF ty_teste, |
matnr TYPE mara-matnr, |
belnr TYPE bseg-belnr, |
END OF ty_teste. |
|
DATA: lt_tab_inf TYPE TABLE OF ty_tab_inf, |
ls_tab_inf TYPE ty_tab_inf, |
lt_teste TYPE TABLE OF ty_teste, |
ls_teste TYPE ty_teste, |
lt_fldcat TYPE TABLE OF lvc_t_fcat. |
*Adicionamos a tabela e campo de referência Standard, |
*para montar o FieldCat conforme os campos do relatório |
ls_tab_inf-tab = 'MARA'. ls_tab_inf-field = 'MATNR'. |
APPEND ls_tab_inf TO lt_tab_inf. |
ls_tab_inf-tab = 'BSEG'. ls_tab_inf-field = 'BELNR'. |
APPEND ls_tab_inf TO lt_tab_inf. |
|
PERFORM zf_get_fieldcat USING 'LT_TESTE' |
lt_tab_inf |
CHANGING lt_fldcat. |
*A informação de todos os campos existentes na LT_TESTE |
*estarão contidas na tabela LT_FLDCAT e poderão ser passados |
*como parâmetro na hora de montar o ALV Grid. |
|
*&----------------------------------------------------------* |
*& Form zf_get_fieldcat |
*&----------------------------------------------------------* |
* -->P_TABNAME text |
* -->PT_TAB_INF text |
* -->PT_FIELDCAT text |
*&----------------------------------------------------------* |
FORM zf_get_fieldcat USING p_tabname TYPE lvc_tname |
pt_tab_inf TYPE ANY TABLE |
CHANGING pt_fieldcat TYPE lvc_t_fcat. |
FIELD-SYMBOLS: <fs_slin> TYPE ANY, |
<fs_tab> TYPE ANY, |
<fs_field> TYPE ANY. |
DATA: ls_fldcat TYPE lvc_s_fcat, |
lv_subrc TYPE sy-subrc. |
|
ls_fldcat-row_pos = 1. |
LOOP AT <fs_ttab> ASSIGNING <fs_slin>. |
|
ls_fldcat-col_pos = sy-tabix. |
ASSIGN( '<FS_SLIN>-TAB') TO <fs_tab>. |
ASSIGN( '<FS_SLIN>-FIELD') TO <fs_field>. |
IF <fs_tab> IS NOT ASSIGNED OR <fs_field> IS NOT ASSIGNED. |
lv_subrc = 4. EXIT. |
ENDIF. |
CALL FUNCTION 'DDIF_FIELDINFO_GET' |
EXPORTING |
tabname = <fs_tab> |
fieldname = <fs_field> |
langu = sy-langu |
TABLES |
dfies_tab = lt_dfies. |
|
IF sy-subrc IS INITIAL. |
READ TABLE lt_dfies INTO ls_dfies INDEX 1. |
MOVE-CORRESPONDING ls_dfies TO ls_fldcat. |
ls_fldcat-tabname = p_tabname. |
APPEND ls_fldcat TO pt_fieldcat. |
ENDIF. |
ENDLOOP. |
sy-subrc = lv_subrc. |
ENDFORM."zf_get_fieldcat |
|
Nenhum comentário:
Postar um comentário