Abap/4 控制ALV树(1)

*&---------------------------------------------------------------------*
*& Report  Z_CPT9_5                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&        ALV树        *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  Z_CPT9_5                                                    .
DATA:OK_CODE TYPE SY-UCOMM,
     SAVE_OK TYPE SY-UCOMM.

DATA:GB_FIELDCAT TYPE LVC_T_FCAT.
DATA:GB_SORTFLD TYPE LVC_T_SORT.
DATA WA_SPFLI TYPE TABLE OF SPFLI.

SELECT * FROM SPFLI INTO TABLE WA_SPFLI.

DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'CONTAINER1',
     ALV_GRID TYPE REF TO CL_GUI_ALV_TREE_SIMPLE,
     WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

CALL SCREEN 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
IF WA_CUSTOM_CONTAINER IS INITIAL.
    DATA LS_LIST_COMM TYPE SLIS_T_LISTHEADER.
    DATA LS_ALIST_COMM TYPE SLIS_LISTHEADER.
    LS_ALIST_COMM-TYP = 'H'.
    LS_ALIST_COMM-INFO = 'My ALV TREE Testing'.
    APPEND LS_ALIST_COMM TO LS_LIST_COMM.

    PERFORM BLDCAT.
    PERFORM BLDSORTFLD.


    "创建容器
    CREATE OBJECT WA_CUSTOM_CONTAINER
        EXPORTING
            CONTAINER_NAME = WA_CONTAINER.
    "创建ALV表格
    CREATE OBJECT ALV_GRID
        EXPORTING I_PARENT = WA_CUSTOM_CONTAINER.
    "绑定数据
    CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
            IT_LIST_COMMENTARY = LS_LIST_COMM
            I_STRUCTURE_NAME = 'SPFLI'
        CHANGING
            IT_SORT = GB_SORTFLD
            IT_FIELDCATALOG = GB_FIELDCAT
            IT_OUTTAB = WA_SPFLI.
    "展开树
    CALL METHOD ALV_GRID->EXPAND_TREE
        EXPORTING
            I_LEVEL = 1.

ENDIF.


ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.

ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Module  CANCEL  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE CANCEL INPUT.
    LEAVE PROGRAM.
ENDMODULE.                 " CANCEL  INPUT


FORM BLDCAT.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
            I_STRUCTURE_NAME = 'SPFLI'
        CHANGING
            CT_FIELDCAT = GB_FIELDCAT.
    DATA LS_FLDCAT TYPE LVC_S_FCAT.
    LOOP AT GB_FIELDCAT INTO LS_FLDCAT.
        CASE LS_FLDCAT-FIELDNAME.
            WHEN 'COUNTRYFR' OR 'CITYFROM'
                             OR 'COUNTRYTO'
                             OR 'CITYTO'
                             OR 'DISTANCE'.
                 LS_FLDCAT-OUTPUTLEN = 15.
             WHEN OTHERS.
                 LS_FLDCAT-NO_OUT = 'X'.
        ENDCASE.
    IF LS_FLDCAT-FIELDNAME = 'DISTANCE'.
        LS_FLDCAT-DO_SUM ='X'.
    ENDIF.
    MODIFY GB_FIELDCAT FROM LS_FLDCAT.
    ENDLOOP.
ENDFORM.

FORM BLDSORTFLD.
    DATA LS_SORTFLD TYPE LVC_S_SORT.
    LS_SORTFLD-SPOS = 1.
    LS_SORTFLD-FIELDNAME = 'COUNTRYFR'.
    LS_SORTFLD-UP = 'X'.
    LS_SORTFLD-SUBTOT = 'X'.
    APPEND LS_SORTFLD TO GB_SORTFLD.

    LS_SORTFLD-SPOS = 2.
    LS_SORTFLD-FIELDNAME = 'CARRID'.
    LS_SORTFLD-UP = 'X'.
    LS_SORTFLD-SUBTOT = 'X'.
    APPEND LS_SORTFLD TO GB_SORTFLD.

    LS_SORTFLD-SPOS = 3.
    LS_SORTFLD-FIELDNAME = 'CONNID'.
    LS_SORTFLD-UP = 'X'.
    LS_SORTFLD-SUBTOT = 'X'.
    APPEND LS_SORTFLD TO GB_SORTFLD.

ENDFORM.

你可能感兴趣的:(Module,command,tree,input,distance,structure)