FORM create_dynamic .
PERFORM create_dynamic_fieldcat TABLES gt_fieldcat2.
PERFORM create_dynamic_table TABLES gt_fieldcat2.
PERFORM create_dynamic_data.
PERFORM set_dynamic_color.
ENDFORM. " create_dynamic_table
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
FORM create_dynamic_fieldcat TABLES pt_fieldcat TYPE lvc_t_fcat.
DEFINE $_set_fieldcat.
clear : pt_fieldcat.
pt_fieldcat-fieldname = &1.
pt_fieldcat-ref_table = &2.
pt_fieldcat-ref_field = &3.
if &4 is not initial.
pt_fieldcat-coltext = &4.
endif.
append pt_fieldcat.
END-OF-DEFINITION.
DATA : lv_coltext LIKE pt_fieldcat-coltext.
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.
$_set_fieldcat : 'LIFNR' 'LFA1' 'LIFNR' ' ',
'NAME1' 'LFA1' 'NAME1' ' ',
'MATNR' 'MARA' 'MATNR' ' ',
'MAKTX' 'MAKT' 'MAKTX' ' '.
LOOP AT gt_bedat.
CONCATENATE 'Quantity(' gt_bedat-bedat ')' INTO lv_coltext.
$_set_fieldcat : gt_bedat-menge 'EKPO' 'MENGE' lv_coltext.
CONCATENATE 'Unit(' gt_bedat-bedat ')' INTO lv_coltext.
$_set_fieldcat : gt_bedat-meins 'EKPO' 'MEINS' lv_coltext.
CONCATENATE 'Total(' gt_bedat-bedat ')' INTO lv_coltext.
$_set_fieldcat : gt_bedat-netwr 'EKPO' 'NETWR' lv_coltext.
CONCATENATE 'Curr.(' gt_bedat-bedat ')' INTO lv_coltext.
$_set_fieldcat : gt_bedat-waers 'EKKO' 'WAERS' lv_coltext.
ENDLOOP.
ENDFORM. " create_dynamic_fieldcat
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
FORM create_dynamic_table TABLES pt_fieldcat.
DATA : lt_celltab TYPE lvc_t_scol.
DATA : lo_table TYPE REF TO cl_abap_tabledescr,
lo_line TYPE REF TO cl_abap_structdescr.
DATA :
gdo_handle TYPE REF TO data,
go_sdescr TYPE REF TO cl_abap_structdescr,
go_sdescr_new TYPE REF TO cl_abap_structdescr,
go_tdescr TYPE REF TO cl_abap_tabledescr,
gs_comp TYPE abap_componentdescr,
gt_components TYPE abap_component_tab.
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>.
*----- Celltab 추가.
lo_table ?= cl_abap_typedescr=>describe_by_data( <table> ).
lo_line ?= lo_table->get_table_line_type( ).
gt_comps[] = lo_line->get_components( ).
CLEAR gt_comps.
gt_comps-type ?= cl_abap_typedescr=>describe_by_data( lt_celltab ).
gt_comps-name = 'CELLTAB'.
APPEND gt_comps.
go_sdescr = cl_abap_structdescr=>create(
p_components = gt_comps[]
p_strict = cl_abap_structdescr=>false
).
go_tdescr = cl_abap_tabledescr=>create( go_sdescr ).
CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
ASSIGN gdo_handle->* TO <table>.
*-----
CREATE DATA gs_wa LIKE LINE OF <table>.
ASSIGN gs_wa->* TO <wa>.
ENDFORM. " create_dynamic_table
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
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 set_dynamic_color .
DATA : ls_cols TYPE LINE OF lvc_t_scol.
FIELD-SYMBOLS : <lv_field> TYPE ANY,
<lt_cols> TYPE lvc_t_scol.
CHECK <table> IS NOT INITIAL.
LOOP AT <table> ASSIGNING <wa>.
ASSIGN COMPONENT 'CELLTAB' OF STRUCTURE <wa>
TO <lt_cols>.
LOOP AT gt_comps.
CASE gt_comps-name.
WHEN 'LIFNR'.
WHEN 'NAME1'.
WHEN 'MATNR'.
WHEN 'MAKTX'.
WHEN OTHERS.
ASSIGN COMPONENT gt_comps-name OF STRUCTURE <wa>
TO <lv_field>.
IF <lv_field> IS ASSIGNED
AND <lv_field> IS NOT INITIAL.
ls_cols-fname = gt_comps-name.
ls_cols-color-col = gc_color+1(1).
ls_cols-color-int = gc_color+2(1).
ls_cols-color-inv = gc_color+3(1).
APPEND ls_cols TO <lt_cols>.
CLEAR ls_cols.
ENDIF.
ENDCASE.
ENDLOOP.
ENDLOOP.
ENDFORM. " set_dynamic_color
'Abap' 카테고리의 다른 글
C01 (0) | 2021.06.01 |
---|---|
ALV 1 (0) | 2021.06.01 |
[ABAP] Dynamic Table (0) | 2013.11.27 |
[Abap-TabStrip] Screen Tab strip (0) | 2013.09.24 |
[Abap-Excel] 엑셀에 데이터 넘기기 2 (매크로) - 엑셀부분 (0) | 2013.09.16 |