아래 소스중에 매크로 내용이 있는데 어떻게 연결이 되어 있나요?
'VKORG' 'VBAK'. 이 두개가 fieldname과 ref_tabname인가요?
ls_fieldcat-col_pos은 어디와 연결이 되는지 이해도 않가고..
아래소스를 보시고 자세한 답변부탁합니다.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TABLES : vbak. " Sales Document: Header Data
TYPE-POOLS: slis. " ALV Global types
SELECT-OPTIONS :
s_vkorg FOR vbak-vkorg, " Sales organization
s_kunnr FOR vbak-kunnr, " Sold-to party
s_vbeln FOR vbak-vbeln. " Sales document
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
DATA:
* Data displayed in the first list
BEGIN OF gt_vbak OCCURS 0,
vkorg LIKE vbak-vkorg, " Sales organization
kunnr LIKE vbak-kunnr, " Sold-to party
vbeln LIKE vbak-vbeln, " Sales document
netwr LIKE vbak-netwr, " Net Value of the Sales Order
END OF gt_vbak,
* Data displayed in the popup list
BEGIN OF gt_vbap OCCURS 0,
posnr LIKE vbap-posnr, " Sales document item
matnr LIKE vbap-matnr, " Material number
arktx LIKE vbap-arktx, " Short text for sales order item
kwmeng LIKE vbap-kwmeng, " Order quantity
netwr LIKE vbap-netwr, " Net value of the order item
END OF gt_vbap.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'Maximum of records to read'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data_vbak.
PERFORM f_display_data_vbak.
*---------------------------------------------------------------------*
* Form f_read_data_vbak
*---------------------------------------------------------------------*
FORM f_read_data_vbak.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
FROM vbak
UP TO p_max ROWS
WHERE kunnr IN s_kunnr
AND vbeln IN s_vbeln
AND vkorg IN s_vkorg.
ENDFORM. " F_READ_DATA_VBAK
*---------------------------------------------------------------------*
* Form f_display_data_vbak
*---------------------------------------------------------------------*
FORM f_display_data_vbak.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
* Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
* Display the first list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA_VBAK
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm LIKE sy-ucomm
us_selfield TYPE slis_selfield. "#EC CALLED
CASE u_ucomm.
WHEN '&IC1'.
READ TABLE gt_vbak INDEX us_selfield-tabindex.
CHECK sy-subrc EQ 0.
PERFORM f_read_data_vbap. " Read data from VBAP
PERFORM f_display_data_vbap.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form f_read_data_vbap
*---------------------------------------------------------------------*
FORM f_read_data_vbap.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbap
FROM vbap
WHERE vbeln = gt_vbak-vbeln.
ENDFORM. " F_READ_DATA_VBAP
*---------------------------------------------------------------------*
* Form f_display_data_vbap
*---------------------------------------------------------------------*
FORM f_display_data_vbap.
DATA:
ls_private TYPE slis_data_caller_exit,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
* Build the field catalog
m_fieldcat 'POSNR' 'VBAP'.
m_fieldcat 'MATNR' 'VBAP'.
m_fieldcat 'ARKTX' 'VBAP'.
m_fieldcat 'KWMENG' 'VBAP'.
m_fieldcat 'NETWR' 'VBAP'.
ls_private-columnopt = 'X'. " Optimize width
* Display items in a POPUP
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_selection = ' '
i_tabname = 'GT_VBAP'
it_fieldcat = lt_fieldcat
is_private = ls_private
TABLES
t_outtab = gt_vbap.
ENDFORM. " F_DISPLAY_DATA_VBAP
**************** END OF PROGRAM Z_ALV_GRID_AND_POPUP ******************
m_fieldcat 'POSNR' 'VBAP'. 이 구문을 통해 해당 매크로를
수행하게 되는데 두개의 파라미터를 넘겨주죠
&1 에 첫번째, &2 에 두번째 파라미터값을 넘겨 줍니다.
결국 필드카탈로그 생성을 매크로 작업을 통해 중복적인
부분을 매크로로 만든 것입니다.
위의 소스에서 매크로를 사용하지 않는다면
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = 'POSNR'.
ls_fieldcat-ref_tabname = 'VBAP'.
append ls_fieldcat to lt_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-ref_tabname = 'VBAP'.
append ls_fieldcat to lt_fieldcat.
이런식으로 동일한 코드를 계속 사용을 해서 추가를 하겠죠.
차이점을 아시겠죠.. 왜 매크로를 사용했는지...
add 1 to ls_fieldcat-col_pos. 이 구문을 통해 칼럼 순서를 1씩증가를 하죠
위의 소스를 참고하면 alv 출력시 칼럼 순서가 아래와 같겠죠.
POSNR MATNR ARKTX KWMENG NETWR