>안녕하세요.
>
>alv에서 필드명은 가운데정렬하고 밑에 나오는 데이터는 오른쪽정렬로 하려면 어떻게 해야하나요/?? ㅠㅠ
>
>따로따로 정렬하려면.. 어떻게 해야하는지 모르겠네요..
>
>도움 부탁드립니다.
>
>
>
테스트 프로그램 소스입니다.
TYPE-POOLS CNDP.
************************************************************************
* DATA Def.
************************************************************************
DATA GCL_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA GCL_EVENT TYPE REF TO ZSDCL_EVENT_RECEIVER.
DATA GS_LAYO TYPE LVC_S_LAYO.
DATA DREF TYPE REF TO DATA.
DATA G_OKCODE TYPE SYUCOMM.
DATA GT_FCAT TYPE LVC_T_FCAT.
DATA GT_SORT TYPE LVC_T_SORT.
DATA G_NO_DATA . "" 'X' 데이터 없음
DATA : BEGIN OF GS_DATA,
FIELD TYPE C LENGTH 10,
FLD_2 TYPE C LENGTH 10,
GGGG LIKE FAGLFLEXT-HSL01,
COLOR TYPE LVC_T_SCOL,
STYLE TYPE LVC_T_STYL,
END OF GS_DATA,
GT_DATA LIKE TABLE OF GS_DATA.
FIELD-SYMBOLS : <FS_DATA> TYPE ANY TABLE.
************************************************************************
* AT SELECTION-SCREEN
************************************************************************
AT SELECTION-SCREEN.
INITIALIZATION.
************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
DO 15 TIMES.
CLEAR GS_DATA.
GS_DATA-FLD_2 = 'AAA'.
GS_DATA-GGGG = '8300'.
* PERFORM SET_COLOR USING SY-INDEX CHANGING GS_DATA-COLOR.
PERFORM SET_STYLE USING SY-INDEX CHANGING GS_DATA-STYLE.
GS_DATA-FIELD = SY-INDEX.
APPEND GS_DATA TO GT_DATA.
ENDDO.
CALL SCREEN 100.
************************************************************************
************************************************************************
* SUBROUTINE POOLS
************************************************************************
************************************************************************
*&---------------------------------------------------------------------*
*& Form CHECK_TABLE_DATA
*&---------------------------------------------------------------------*
*& 테이블에 데이터가 있는지 확인
*&---------------------------------------------------------------------*
FORM CHECK_TABLE_DATA USING US_TABNM.
DATA LDREF TYPE REF TO DATA.
FIELD-SYMBOLS <LFS_STRUC>.
CLEAR G_NO_DATA.
CHECK US_TABNM IS NOT INITIAL.
CREATE DATA LDREF TYPE (US_TABNM).
ASSIGN LDREF->* TO <LFS_STRUC>.
CHECK <LFS_STRUC> IS ASSIGNED.
SELECT SINGLE * INTO <LFS_STRUC>
FROM (US_TABNM).
IF SY-SUBRC IS NOT INITIAL.
G_NO_DATA = 'X'.
MESSAGE S398(00) WITH 'No data : Table - ' US_TABNM.
ENDIF.
ENDFORM. " CHECK_TABLE_DATA
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'M100'.
SET TITLEBAR 'T100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
MODULE EXIT INPUT.
LEAVE TO SCREEN 0.
ENDMODULE. " EXIT INPUT
*&---------------------------------------------------------------------*
*& Module SET_ALV OUTPUT
*&---------------------------------------------------------------------*
MODULE SET_ALV OUTPUT.
IF GCL_GRID IS NOT BOUND.
* Create alv
CREATE OBJECT GCL_GRID
EXPORTING
I_PARENT = CL_GUI_CONTAINER=>DEFAULT_SCREEN
I_APPL_EVENTS = 'X'.
GS_LAYO-BOX_FNAME = 'A'.
GS_LAYO-CTAB_FNAME = 'COLOR'.
GS_LAYO-STYLEFNAME = 'STYLE'.
* Event-set
CREATE OBJECT GCL_EVENT
EXPORTING
I_PROGRAM = SY-CPROG.
SET HANDLER GCL_EVENT->Z_HALV_DATA_CHANGED FOR GCL_GRID.
CALL METHOD GCL_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
DATA LS_FCAT TYPE LVC_S_FCAT.
LS_FCAT-FIELDNAME = 'FLD_2'.
LS_FCAT-INTTYPE = 'C'.
LS_FCAT-INTLEN = 10.
APPEND LS_FCAT TO GT_FCAT.
LS_FCAT-FIELDNAME = 'FIELD'.
LS_FCAT-INTTYPE = 'I'.
APPEND LS_FCAT TO GT_FCAT.
LS_FCAT-FIELDNAME = 'GGGG'.
LS_FCAT-REF_FIELD = 'HSL01'.
LS_FCAT-EDIT = 'X'.
LS_FCAT-REF_TABLE = 'FAGLFLEXT'.
LS_FCAT-DO_SUM = 'X'.
APPEND LS_FCAT TO GT_FCAT.
* Display-ALV
CALL METHOD GCL_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYO
CHANGING
IT_OUTTAB = GT_DATA
IT_FIELDCATALOG = GT_FCAT
IT_SORT = GT_SORT.
ELSE.
CALL METHOD GCL_GRID->REFRESH_TABLE_DISPLAY.
ENDIF.
ENDMODULE. " SET_ALV OUTPUT
*&---------------------------------------------------------------------*
*& Form CHECK_VALID_TABLE
*&---------------------------------------------------------------------*
FORM CHECK_VALID_TABLE USING US_TABNM TYPE ANY.
DATA LS_DD02L TYPE DD02L.
SELECT SINGLE * INTO LS_DD02L
FROM DD02L
WHERE TABNAME = US_TABNM
AND AS4LOCAL = 'A'. "" 활성상태의 테이블
IF SY-SUBRC IS NOT INITIAL.
MESSAGE S398(00) WITH '활성테이블'
US_TABNM
'이 없습니다'.
STOP.
ENDIF.
ENDFORM. " CHECK_VALID_TABLE
*&---------------------------------------------------------------------*
*& Form Z_HALV_DATA_CHANGED
*&---------------------------------------------------------------------*
FORM Z_HALV_DATA_CHANGED CHANGING SENDER TYPE REF TO CL_GUI_ALV_GRID
ER_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL
E_ONF4
E_ONF4_BEFORE
E_ONF4_AFTER
E_UCOMM.
DATA LV_TMP TYPE STRING.
DATA LV_TYPE .
FIELD-SYMBOLS : <LFS_CELLS> TYPE LVC_S_MODI,
<LFS_DATA> TYPE ANY,
<LFS_FIELD> TYPE ANY.
LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS ASSIGNING <LFS_CELLS>.
READ TABLE GT_DATA ASSIGNING <LFS_DATA> INDEX <LFS_CELLS>-ROW_ID.
CHECK SY-SUBRC IS INITIAL.
ASSIGN COMPONENT <LFS_CELLS>-FIELDNAME OF STRUCTURE <LFS_DATA> TO <LFS_FIELD>.
CHECK SY-SUBRC IS INITIAL.
LV_TMP = <LFS_CELLS>-VALUE.
DESCRIBE FIELD <LFS_FIELD> TYPE LV_TYPE.
CASE LV_TYPE.
WHEN 'N' OR 'I' OR 'P' OR 'F'.
TRANSLATE LV_TMP USING ', '.
CONDENSE LV_TMP NO-GAPS.
WHEN OTHERS.
ENDCASE.
<LFS_FIELD> = LV_TMP.
ENDLOOP.
ENDFORM. "Z_HALV_DATA_CHANGED
*&---------------------------------------------------------------------*
*& Form SET_COLOR
*&---------------------------------------------------------------------*
FORM SET_COLOR USING US_INDEX TYPE ANY
CHANGING CT_COLOR TYPE LVC_T_SCOL.
DATA LS_COLOR TYPE LVC_S_SCOL.
DATA LV_COL TYPE I.
LV_COL = US_INDEX MOD 7.
CHECK LV_COL = 6.
LS_COLOR-FNAME = 'FLD_2'.
LS_COLOR-COLOR-COL = LV_COL.
LS_COLOR-COLOR-INT = 0.
LS_COLOR-COLOR-INV = 0.
INSERT LS_COLOR INTO TABLE CT_COLOR.
ENDFORM. " SET_COLOR
*&---------------------------------------------------------------------*
*& Module USER_COMMAND INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND INPUT.
FIELD-SYMBOLS : <LFS_DATA> TYPE TABLE,
<LFS_STRUC> TYPE ANY,
<LFS_FIELD> TYPE ANY.
CASE G_OKCODE.
WHEN OTHERS.
ENDCASE.
CLEAR G_OKCODE.
ENDMODULE. " USER_COMMAND INPUT
*&---------------------------------------------------------------------*
*& Form SET_STYLE
*&---------------------------------------------------------------------*
FORM SET_STYLE USING VALUE(US_INDEX) TYPE ANY
CHANGING CT_STYLE TYPE LVC_T_STYL.
DATA LS_STYLE TYPE LVC_S_STYL.
DATA LV_MOD TYPE I.
US_INDEX = US_INDEX - 1.
LV_MOD = US_INDEX MOD 3.
LS_STYLE-FIELDNAME = 'FLD_2'.
CASE LV_MOD.
WHEN 0.
WHEN 1.
LS_STYLE-STYLE = 4096.
WHEN 2.
LS_STYLE-STYLE = 6144.
ENDCASE.
INSERT LS_STYLE INTO TABLE CT_STYLE.
ENDFORM. " SET_STYLE