首页 > 其他分享 >abap write report

abap write report

时间:2023-03-15 18:36:20浏览次数:31  
标签:SELECTION END &-------------------------------------------------------------

主程序

*&---------------------------------------------------------------------*
*& Report  ZBC_RE_01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBC_RE_01 MESSAGE-ID ZBC
                 NO STANDARD PAGE HEADING
                 LINE-SIZE 90
                 LINE-COUNT 20.

INCLUDE ZBC_RE_01TOP.
INCLUDE ZBC_RE_01FROM.
*&---------------------------------------------------------------------*
*& INITIALIZATION EVENT
*&---------------------------------------------------------------------*
INITIALIZATION.
    GV_NAME = 'checking'.
    GV_BUTTON = 'DOWNLOAD'.
    button1 = 'tab1'.
    button2 = 'tab2'.
    mytab-prog = SY-REPID.
    mytab-dynnr = 100.
    mytab-activetab = 'TAB1'.

*&---------------------------------------------------------------------*
*& EVENT SELECTION SCREEN EVENT.
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT . "screen PBO
  PERFORM modify_screen.


AT SELECTION-SCREEN . " SCREEN PAI
*  PERFORM selection_screen_pai.
  CASE SY-DYNNR .
    WHEN 1000.
      PERFORM selection_screen_pai.
        case sy-ucomm.
          when 'push1'.
            mytab-dynnr = 100.
            mytab-activetab = 'button1'.
           when 'push2'.
            mytab-dynnr = 200.
            mytab-activetab = 'button2'.
        ENDCASE.
    WHEN 100.
      MESSAGE S888(sapapdemos) WITH text-040 sy-dynnr.
    WHEN 200.
      MESSAGE S888(sapapdemos) WITH text-040 sy-dynnr.
   ENDCASE.
*&---------------------------------------------------------------------*
*& EVent start of selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM get_data.
*&---------------------------------------------------------------------*
*& Event end of selection
*&---------------------------------------------------------------------*
END-OF-SELECTION.
  GT_STATUS  ='DOWNLOAD'.
  APPEND GT_STATUS.
  SET PF-STATUS 'STATUS' EXCLUDING GT_STATUS .
  SET TITLEBAR 'TUTLE' with 'SUDENT'.
IF GT_TOTAL IS NOT INITIAL.
  PERFORM disaplay_data.
ELSE.
  MESSAGE S001(ZBC) WITH 'student' DISPLAY LIKE 'E'.
ENDIF.
*&---------------------------------------------------------------------*
*& EVent TOP OF PAGE
*&---------------------------------------------------------------------*
TOP-OF-PAGE .
  PERFORM top_of_page.
*&---------------------------------------------------------------------*
*& EVENT LINE-SELECTION
*&---------------------------------------------------------------------*
AT LINE-SELECTION.
  PERFORM line_select.
*&---------------------------------------------------------------------*
*& EVENT USER COMMAND
*&---------------------------------------------------------------------*
AT USER-COMMAND .
  PERFORM user_command .
*&---------------------------------------------------------------------*
*& TOP OF PAGE OF LINE SELECTION
*&---------------------------------------------------------------------*
 TOP-OF-PAGE DURING LINE-SELECTION .
  PERFORM top_of_page_line_selection.
ZBC_RE_01TOP
*&---------------------------------------------------------------------*
*&  Include           ZBC_RE_01TOP
*&---------------------------------------------------------------------*
TABLES: ZSTU,
        ZSCHOOL.
TYPES: BEGIN of GTY_TOTAL,
  ZCODE TYPE ZSTU-ZCODE,
  ZNAME TYPE ZSTU-ZNAME,
  SEX  TYPE ZSTU-SEX,
  ZSCHOOL TYPE ZSTU-ZSCHOOL,
  ZSNAME TYPE ZSCHOOL_HQ_03-ZSNAME,
  END OF GTY_TOTAL.

DATA GT_TOTAL TYPE TABLE OF GTY_TOTAL.
DATA GS_TOTAL TYPE GTY_TOTAL.

DATA GT_SCHOOL TYPE TABLE OF ZSCHOOL_HQ_03.
DATA GS_SCHOOL TYPE ZSCHOOL_HQ_03.
DATA WA_SCHOOL TYPE ZSCHOOL_HQ_03.

DATA GT_STU TYPE TABLE OF ZSTU .
DATA GS_STU TYPE ZSTU .

DATA GV_BUTTON TYPE C.

DATA GT_STATUS LIKE TABLE OF SY-UCOMM WITH HEADER LINE.

**screen
*PARAMETERS P_CODE like GS_STU-ZCODE OBLIGATORY.
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-T01 .
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (10) TEXT-T06 for FIELD S_ZCODE.
SELECTION-SCREEN POSITION 30.
SELECT-OPTIONS S_ZCODE FOR GS_STU-ZCODE NO-EXTENSION
                                        NO INTERVALS .
SELECTION-SCREEN POSITION 50.
SELECTION-SCREEN COMMENT (20) GV_NAME.
SELECTION-SCREEN END OF LINE.

SELECT-OPTIONS S_ZNAME FOR GS_STU-ZNAME .
SELECT-OPTIONS S_ZSCH FOR GS_SCHOOL-ZSCHOOL .
SELECTION-SCREEN END OF BLOCK BK1 .


PARAMETERS SEX_CHK AS CHECKBOX USER-COMMAND SEHI.
SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME TITLE TEXT-T02 .
SELECTION-SCREEN BEGIN OF LINE .
PARAMETERS  R_MALE RADIOBUTTON GROUP GP1 MODIF ID SEX .
SELECTION-SCREEN COMMENT (10) TEXT-T03 FOR FIELD R_MALE .
PARAMETERS  R_FEMALE RADIOBUTTON GROUP GP1 MODIF ID SEX .
SELECTION-SCREEN POSITION 15 .
SELECTION-SCREEN COMMENT (10) TEXT-T04 FOR FIELD R_FEMALE .
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN END OF BLOCK BK2 .

SELECTION-SCREEN SKIP 3.
SELECTION-SCREEN ULINE.
PARAMETERS P_CHECK AS CHECKBOX .
SELECTION-SCREEN BEGIN OF BLOCK BK3 WITH FRAME TITLE TEXT-T05.
PARAMETERS P_SALES RADIOBUTTON GROUP GP2 MODIF ID DEP .
PARAMETERS P_EDU RADIOBUTTON GROUP GP2 MODIF ID DEP .
PARAMETERS P_ACC RADIOBUTTON GROUP GP2 MODIF ID DEP .
PARAMETERS P_HR RADIOBUTTON GROUP GP2 MODIF ID DEP .
SELECTION-SCREEN END OF BLOCK BK3.

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P1(10) TYPE C,
            P2(10) TYPE C,
            P3(10) TYPE C.
SELECTION-SCREEN END OF BLOCK B1 .
SELECTION-SCREEN END OF SCREEN 100.

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS: Q1(10) TYPE C,
            Q2(10) TYPE C,
            Q3(10) TYPE C.
SELECTION-SCREEN END OF BLOCK B2 .
SELECTION-SCREEN END OF SCREEN 200.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 10 LINES,
                  TAB (20) button1 USER-COMMAND push1,
                  TAB (20) button2 USER-COMMAND push2,
                  END OF BLOCK mytab.
ZBC_RE_01FROM
*&---------------------------------------------------------------------*
*&  Include           ZBC_RE_01FROM
*&---------------------------------------------------------------------*



*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .
  RANGES R_SEX FOR GS_STU-SEX .

  CLEAR: R_SEX, R_SEX[] .
  IF SEX_CHK = 'X' .
      IF R_MALE = 'X' .
        R_SEX-SIGN = 'I' .
        R_SEX-OPTION = 'EQ' .
        R_SEX-LOW    = 'M' .
        APPEND R_SEX .
      ELSE .
        R_SEX-SIGN = 'I' .
        R_SEX-OPTION = 'EQ' .
        R_SEX-LOW    = 'F' .
        APPEND R_SEX .
       ENDIF.
    ENDIF.


*&      inner join
*    SELECT A~ZCODE A~ZNAME A~SEX A~ZSCHOOL B~ZSNAME
*    FROM ZSTU AS A INNER JOIN ZSCHOOL_HQ_03 AS B
*      ON A~ZSCHOOL = B~ZSCHOOL
*    INTO CORRESPONDING FIELDS OF TABLE GT_TOTAL
*    WHERE A~ZSCHOOL IN S_ZSCH
*        AND A~ZCODE IN S_ZCODE
*        AND A~ZNAME IN S_ZNAME.

*&     left outer join
*  SELECT A~ZCODE A~ZNAME A~SEX A~ZSCHOOL B~ZSNAME
*    FROM ZSTU AS A LEFT OUTER JOIN ZSCHOOL_HQ_03 AS B
*      ON A~ZSCHOOL = B~ZSCHOOL
*    INTO CORRESPONDING FIELDS OF TABLE GT_TOTAL
*    WHERE A~ZSCHOOL IN S_ZSCH
*        AND A~ZCODE IN S_ZCODE
*        AND A~ZNAME IN S_ZNAME.

*&     mutli table select
    SELECT ZCODE ZNAME SEX ZSCHOOL
      FROM ZSTU
      INTO CORRESPONDING FIELDS OF TABLE GT_STU
      WHERE ZCODE IN S_ZCODE
        AND ZNAME IN S_ZNAME
        AND ZSCHOOL IN S_ZSCH
        AND SEX in R_SEX .

    IF GT_STU IS NOT INITIAL.
      SELECT ZSCHOOL ZSNAME
        FROM ZSCHOOL_HQ_03
        INTO CORRESPONDING FIELDS OF TABLE GT_SCHOOL
        FOR ALL ENTRIES IN GT_STU
        WHERE ZSCHOOL = GT_STU-ZSCHOOL .
       SORT GT_SCHOOL BY ZSCHOOL .
    ENDIF .

     LOOP AT GT_STU INTO GS_STU.
       CLEAR GS_TOTAL .
       MOVE-CORRESPONDING GS_STU to GS_TOTAL.
       READ TABLE GT_SCHOOL INTO GS_SCHOOL
                            WITH KEY ZSCHOOL = GS_TOTAL-ZSCHOOL
                            BINARY SEARCH.
       IF SY-SUBRC = 0 .
         GS_TOTAL-ZSNAME = GS_SCHOOL-ZSNAME .
*       ELSE . "read failuer
*         GS_TOTAL-ZSNAME = '' .
*         CONTINUE .     "stop loop anc continure next
       ENDIF .
       APPEND GS_TOTAL TO GT_TOTAL.
      ENDLOOP .

*  IF R_FEMALE = 'X' .
*    SELECT ZCODE ZNAME SEX ZSCHOOL WEIGH ZUNIT
*        FROM ZSTU
*        INTO CORRESPONDING FIELDS OF TABLE GT_STU
*        WHERE ZCODE IN S_ZCODE
*        AND   ZNAME IN S_ZNAME
*        AND   SEX ='F'.
*  ELSE.
*    SELECT ZCODE ZNAME SEX ZSCHOOL WEIGH ZUNIT
*        FROM ZSTU
*        INTO CORRESPONDING FIELDS OF TABLE GT_STU
*        WHERE ZCODE IN S_ZCODE
*        AND   ZNAME IN S_ZNAME
*        AND   SEX ='M'.
*  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISAPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM disaplay_data .

*  WRITE:  / 'result:'.

  WRITE: /1(71) SY-ULINE.
  LOOP AT GT_TOTAL INTO GS_TOTAL.
    WRITE : /1 SY-VLINE NO-GAP,(10) GS_TOTAL-ZCODE NO-GAP LEFT-JUSTIFIED,
               SY-VLINE NO-GAP,(20) GS_TOTAL-ZNAME NO-GAP LEFT-JUSTIFIED,
               SY-VLINE NO-GAP,(5)  GS_TOTAL-SEX NO-GAP LEFT-JUSTIFIED,
               SY-VLINE NO-GAP,(10) GS_TOTAL-ZSCHOOL NO-GAP LEFT-JUSTIFIED ,
               SY-VLINE NO-GAP,(20) GS_TOTAL-ZSNAME NO-GAP LEFT-JUSTIFIED ,
               SY-VLINE.
  WRITE: /1(71) SY-ULINE.
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  MODIFY_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM modify_screen .
  LOOP AT SCREEN.
    IF P_CHECK = 'X' .
        " DISPLAY
    ELSE.
      " Hide
      IF SCREEN-GROUP1 = 'DEP'.
         SCREEN-INVISIBLE = 1 . "1 True 0 False
         MODIFY SCREEN.
      ENDIF.
    ENDIF.

    IF SEX_CHK = 'X' .
        " DISPLAY
    ELSE.
      " Hide
      IF SCREEN-GROUP1 = 'SEX'.
         SCREEN-INVISIBLE = 1 . "1 True 0 False
         MODIFY SCREEN.
      ENDIF.
    ENDIF.
   ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SELECTION_SCREEN_PAI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM selection_screen_pai .
  clear GS_STU.
  if S_ZCODE IS NOT INITIAL.
      select SINGLE *
        FROM ZSTU
        INTO CORRESPONDING FIELDS OF GS_STU
        WHERE ZCODE IN S_ZCODE.
      IF SY-SUBRC = 0.
        GV_NAME = 'exist'.
        MESSAGE S000 WITH GS_STU-ZNAME 'exist'.
      ELSE.
        GV_NAME = 'not exist'.
        MESSAGE S000 WITH GS_STU-ZNAME 'not exist' DISPLAY LIKE 'E'.
      ENDIF.
   ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM top_of_page .
  FORMAT COLOR 3 ON.
  WRITE: /1(71) 'student basic information ' CENTERED.
  FORMAT COLOR 3 OFF.
  WRITE: /1(71) SY-ULINE.
  FORMAT COLOR 6 INVERSE ON .
  WRITE: /1 SY-VLINE NO-GAP,(10) 'STUDENCODE' NO-GAP CENTERED,
                SY-VLINE NO-GAP,(20) 'STUDENTNAME' NO-GAP CENTERED,
                SY-VLINE NO-GAP,(5) 'SEX' NO-GAP CENTERED,
                SY-VLINE NO-GAP,(10) 'SCHOOLCODE' NO-GAP CENTERED,
                SY-VLINE NO-GAP,(20) 'SCHOOLNAME' NO-GAP CENTERED,
                SY-VLINE.
  WRITE: /1(71) SY-ULINE.
  FORMAT COLOR 6 INVERSE OFF .
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  LINE_SELECT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM line_select .
DATA: GV_FIELD(30),
      GV_VALUE(30).

GET CURSOR FIELD GV_FIELD
           VALUE GV_VALUE.
CHECK GV_FIELD = 'GS_TOTAL-ZSCHOOL' .

  CLEAR WA_SCHOOL.
  SELECT SINGLE *
    FROM ZSCHOOL_HQ_03
    INTO CORRESPONDING FIELDS OF WA_SCHOOL
    WHERE ZSCHOOL = GV_VALUE .

  IF SY-SUBRC = 0 .
    WRITE: / 'SCHOOL BASIC INFORMATION'.

    WRITE: /1(50) SY-ULINE.
    WRITE: /1 SY-VLINE NO-GAP,'SCHOOLCODE:    ' NO-GAP, SY-VLINE ,(30) WA_SCHOOL-ZSCHOOL CENTERED,SY-VLINE .
    WRITE: /1(50) SY-ULINE.
    WRITE: /1 SY-VLINE NO-GAP,'SCHOOLNAME:    ' NO-GAP, SY-VLINE ,(30) WA_SCHOOL-ZSNAME  CENTERED,SY-VLINE .
    WRITE: /1(50) SY-ULINE.
    WRITE: /1 SY-VLINE NO-GAP,'SCHOOLADDRESS: ' NO-GAP, SY-VLINE ,(30) WA_SCHOOL-ZADD    CENTERED,SY-VLINE .
    WRITE: /1(50) SY-ULINE.
  ELSE .
    MESSAGE I000 WITH 'this school info not exist'.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE_LINE_SELECTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM top_of_page_line_selection .
  CASE SY-UCOMM.
    WHEN 'SORTUP' OR 'SORTDOWN'.
      PERFORM top_of_page.
    when 'OTHERS'.
      WRITE :/ 'SCHOOL INFORMATION'.
  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM user_command .
  CASE SY-UCOMM .
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'SORTUP'.
      SY-LSIND = SY-LSIND - 1 .
      PERFORM sort_list
              USING 'UP'.
    WHEN 'SORTDOWN'.
      SY-LSIND = SY-LSIND - 1 .
      PERFORM sort_list
              USING 'DOWN'.
    WHEN 'DOWNLOAD' .
      MESSAGE S000 WITH 'download successfully!'.
    WHEN OTHERS.
  ENDCASE.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  SORT_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  P_FLAG char
*----------------------------------------------------------------------*

FORM sort_list USING P_FLAG.

  DATA: LV_FIELD(30) ,
       LV_FIELDNAME(30) .
  GET CURSOR FIELD LV_FIELD .
  SPLIT LV_FIELD AT '-' INTO LV_FIELD LV_FIELDNAME.
  CHECK  LV_FIELD = 'GS_TOTAL' .
  IF P_FLAG = 'UP'.
    SORT GT_TOTAL BY (LV_FIELDNAME) ASCENDING.
  ELSEIF P_FLAG = 'DOWN'.
    SORT GT_TOTAL BY (LV_FIELDNAME) DESCENDING.
  ENDIF.

  PERFORM disaplay_data.
ENDFORM.

GUI STATUS

 

标签:SELECTION,END,&-------------------------------------------------------------
From: https://www.cnblogs.com/tingxin/p/17219543.html

相关文章