Include Top 선언.
FIELD-SYMBOLS : <table> TYPE STANDARD TABLE,
<wa>.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
data select.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
CREATE DYNAMIC TABLE
FORM create_dynamic .
PERFORM create_dynamic_fieldcat TABLES gt_fieldcat2.
PERFORM create_dynamic_table TABLES gt_fieldcat2.
PERFORM create_dynamic_data.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form create_dynamic_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_dynamic_fieldcat TABLES pt_fieldcat TYPE lvc_t_fcat.
CLEAR : pt_fieldcat[], gt_bedat[].
LOOP AT gt_data.
CLEAR gt_bedat.
gt_bedat-bedat = gt_data-bedat.
CONCATENATE gt_data-bedat '_MENGE' INTO gt_bedat-menge.
CONCATENATE gt_data-bedat '_MEINS' INTO gt_bedat-meins.
CONCATENATE gt_data-bedat '_NETWR' INTO gt_bedat-netwr.
CONCATENATE gt_data-bedat '_WAERS' INTO gt_bedat-waers.
APPEND gt_bedat.
ENDLOOP.
SORT gt_bedat.
DELETE ADJACENT DUPLICATES FROM gt_bedat.
CLEAR : pt_fieldcat.
pt_fieldcat-fieldname = 'LIFNR'.
pt_fieldcat-ref_table = 'LFA1'.
pt_fieldcat-ref_field = 'LIFNR'.
APPEND pt_fieldcat.
pt_fieldcat-fieldname = 'NAME1'.
pt_fieldcat-ref_table = 'LFA1'.
pt_fieldcat-ref_field = 'NAME1'.
APPEND pt_fieldcat.
pt_fieldcat-fieldname = 'MATNR'.
pt_fieldcat-ref_table = 'MARA'.
pt_fieldcat-ref_field = 'MATNR'.
APPEND pt_fieldcat.
pt_fieldcat-fieldname = 'MAKTX'.
pt_fieldcat-ref_table = 'MAKT'.
pt_fieldcat-ref_field = 'MAKTX'.
APPEND pt_fieldcat.
LOOP AT gt_bedat.
pt_fieldcat-fieldname = gt_bedat-menge.
pt_fieldcat-ref_table = 'EKPO'.
pt_fieldcat-ref_field = 'MENGE'.
CONCATENATE 'Quantity(' gt_bedat-bedat ')' INTO pt_fieldcat-coltext.
APPEND pt_fieldcat.
pt_fieldcat-fieldname = gt_bedat-meins.
pt_fieldcat-ref_table = 'EKPO'.
pt_fieldcat-ref_field = 'MEINS'.
CONCATENATE 'Unit(' gt_bedat-bedat ')' INTO pt_fieldcat-coltext.
APPEND pt_fieldcat.
pt_fieldcat-fieldname = gt_bedat-netwr.
pt_fieldcat-ref_table = 'EKPO'.
pt_fieldcat-ref_field = 'NETWR'.
CONCATENATE 'Total(' gt_bedat-bedat ')' INTO pt_fieldcat-coltext.
APPEND pt_fieldcat.
pt_fieldcat-fieldname = gt_bedat-waers.
pt_fieldcat-ref_table = 'EKKO'.
pt_fieldcat-ref_field = 'WAERS'.
CONCATENATE 'Curr.(' gt_bedat-bedat ')' INTO pt_fieldcat-coltext.
APPEND pt_fieldcat.
ENDLOOP.
ENDFORM. " create_dynamic_fieldcat
*&---------------------------------------------------------------------*
*& Form create_dynamic_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FIELDCAT2 text
*----------------------------------------------------------------------*
FORM create_dynamic_table TABLES pt_fieldcat.
CLEAR : gs_wa, gt_tab.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = pt_fieldcat[]
IMPORTING
ep_table = gt_tab.
UNASSIGN : <table>, <wa>.
ASSIGN gt_tab->* TO <table>.
CREATE DATA gs_wa LIKE LINE OF <table>.
ASSIGN gs_wa->* TO <wa>.
ENDFORM. " create_dynamic_table
*&---------------------------------------------------------------------*
*& Form create_dynamic_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_dynamic_data.
FIELD-SYMBOLS : <ls_data> LIKE gt_data.
REFRESH <table>.
SORT gt_data.
LOOP AT gt_data ASSIGNING <ls_data>.
AT NEW lifnr.
CLEAR <wa>.
ENDAT.
AT NEW matnr.
CLEAR <wa>.
ENDAT.
PERFORM assign_value USING 'LIFNR' <ls_data>-lifnr.
PERFORM assign_value USING 'NAME1' <ls_data>-name1.
PERFORM assign_value USING 'MATNR' <ls_data>-matnr.
PERFORM assign_value USING 'MAKTX' <ls_data>-maktx.
LOOP AT gt_bedat WHERE bedat EQ <ls_data>-bedat.
PERFORM assign_value USING gt_bedat-menge <ls_data>-menge.
PERFORM assign_value USING gt_bedat-meins <ls_data>-meins.
PERFORM assign_value USING gt_bedat-netwr <ls_data>-netwr.
PERFORM assign_value USING gt_bedat-waers <ls_data>-waers.
ENDLOOP.
AT END OF matnr.
APPEND <wa> TO <table>.
ENDAT.
AT END OF lifnr.
* APPEND <wa> TO <table>.
ENDAT.
ENDLOOP.
ENDFORM. " create_dynamic_data
*&---------------------------------------------------------------------*
*& Form assign_value
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<LS_DATA>_LIFNR text
* -->P_0756 text
*----------------------------------------------------------------------*
FORM assign_value USING p_field
p_value.
DATA : l_field(30).
FIELD-SYMBOLS <fs>.
CHECK p_value IS NOT INITIAL.
UNASSIGN <fs>.
CONCATENATE '<WA>-' p_field INTO l_field.
ASSIGN (l_field) TO <fs>.
IF <fs> IS ASSIGNED.
<fs> = p_value.
ELSE.
CLEAR <fs>.
ENDIF.
ENDFORM. " assign_vALUE
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
DISPLAY ALV.
CALL METHOD gr_alv2->set_table_for_first_display
EXPORTING
is_layout = gs_layout
it_toolbar_excluding = gt_toolbar[]
CHANGING
it_fieldcatalog = gt_fieldcat2[]
it_outtab = <table>.
'Abap' 카테고리의 다른 글
ALV 1 (0) | 2021.06.01 |
---|---|
[ABAP] Dynamic table - cell color (0) | 2013.11.29 |
[Abap-TabStrip] Screen Tab strip (0) | 2013.09.24 |
[Abap-Excel] 엑셀에 데이터 넘기기 2 (매크로) - 엑셀부분 (0) | 2013.09.16 |
[Abap-Excel] 엑셀에 데이터 넘기기 1 (매크로) - Abap 부분 (0) | 2013.09.16 |