Question on Interactive Reports(Not ALV just normal Reports)

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
YukiKaze

Question on Interactive Reports(Not ALV just normal Reports)

Post by YukiKaze » Tue Aug 09, 2005 9:45 am

Hi all.

Now i am in case of an interactive report.
The output screen are as follows:

Code: Select all

Button-UP  Button-DOWN (two buttons defined at PF-STATUS '100')

-----------------------------
Title1  | Title2   | Title3 |...
-----------------------------
aaa     |  bbb    |   ccc   |...
ddd        eee        fff     
ggg        hhh        iii
..................
...............
----------------------------
Below codes for above screen.

Code: Select all

...
Write: 'Title1','Title2','Title3'.
LOOP AT ITAB.
Write:/ ITAB-MATNR, ITAB-MAKTX, ITAB-NUMBER.
ENDLOOP.
...
Now the requirements needs me:

When i Click 'Title1' and then click an button called 'UP'.Then Sort ITAB by MATNR ascendly.
When i Click 'Title2' and then click an button called 'UP'.Then Sort ITAB by maktx ascendly.
When i Click 'Title3' and then click an button called 'UP'.Then Sort ITAB by number ascendly.


And vice versa:

When i Click 'Title1' and then click an button called 'DOWN'.Then Sort ITAB by MATNR descendly.
When i Click 'Title2' and then click an button called 'DOWN'.Then Sort ITAB by maktx descendly.
When i Click 'Title3' and then click an button called 'DOWN'.Then Sort ITAB by number descendly.



And the full programm write like this:
--------------START------------------------

Code: Select all

REPORT  ZT8 NO STANDARD PAGE HEADING LINE-COUNT 20(1).
TABLES: LQUA.

DATA: BEGIN OF ST_MAIN,
        MATNR LIKE LQUA-MATNR,
        VERME LIKE LQUA-VERME,
      END OF ST_MAIN.
DATA: I_MAIN LIKE ST_MAIN OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

  SET PF-STATUS '100'.

  SELECT MATNR VERME INTO CORRESPONDING FIELDS OF TABLE I_MAIN
  FROM LQUA
  WHERE CHARG EQ 'B1'.

AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'UP'.
      "How to code? when 'Title1',Then Sort ITAB by MATNR ascendly.
      "How to code? when 'Title2',Then Sort ITAB by VERME ascendly.
   

    WHEN 'DOWN'.

     "How to code? when 'Title1',Then Sort ITAB by MATNR DEScendly.
      "How to code? when 'Title2',Then Sort ITAB by VERME DEScendly.

  ENDCASE.


END-OF-SELECTION.

  PERFORM TITLE_OUTPUT.
  PERFORM DATA_OUTPUT.


FORM TITLE_OUTPUT.
  WRITE:/5 'TITLE1',
         20 'TITLE2'.
ENDFORM.                    " TITLE_OUTPUT

FORM DATA_OUTPUT.
  LOOP AT I_MAIN.
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME.
  ENDLOOP.  
ENDFORM.                    " DATA_OUTPUT
----------END---------------------------------
Actually i dont know how does the program know which Title i had clicked???

Anyone knows how to achieve that requirement?

Thanks very much!!

Yukikaze.

ocvantol
Posts: 929
Joined: Tue Oct 22, 2002 3:19 am
Location: The Hague

Post by ocvantol » Tue Aug 09, 2005 9:53 am

Look at the help on GET CURSOR, GET CURSOR FIELD f VALUE g. I guess you'd have to write the titles using variables.
Oscar.

Yukikaze

Post by Yukikaze » Tue Aug 09, 2005 9:57 am

Hi,ocvantol.

u mean i'd better define some string variables, such as:

String1 type string value 'Title1'.
...
etc.

??

Yukikaze.

Guest

Post by Guest » Tue Aug 09, 2005 10:30 am

This piece of code may help you to understand the effect of statement 'GET CURSOR FIELD' using variables.

Code: Select all

 
 DATA: cursorfield(20).
 DATA: var1 TYPE c VALUE 'A'.
 DATA: var2 TYPE c VALUE 'B'.
 FIELD-SYMBOLS <f>.
 WRITE: var1, var2.

 AT LINE-SELECTION.

   GET CURSOR FIELD cursorfield.
   ASSIGN (cursorfield) TO <f>.
   WRITE: / 'you have picked', cursorfield,  ' with value',  <f>. 
Well, so you can write your own code with transfer of knowledge.

Yukikaze

Post by Yukikaze » Tue Aug 09, 2005 9:53 pm

Anonymous wrote:This piece of code may help you to understand the effect of statement 'GET CURSOR FIELD' using variables.

Code: Select all

 
 DATA: cursorfield(20).
 DATA: var1 TYPE c VALUE 'A'.
 DATA: var2 TYPE c VALUE 'B'.
 FIELD-SYMBOLS <f>.
 WRITE: var1, var2.

 AT LINE-SELECTION.

   GET CURSOR FIELD cursorfield.
   ASSIGN (cursorfield) TO <f>.
   WRITE: / 'you have picked', cursorfield,  ' with value',  <f>. 
Well, so you can write your own code with transfer of knowledge.
Thank u very much!!
i had modified my code as belows, and sort itab very well, But there is a new problem...when there r many pages of the report, the TOP-OF-PAGE
only display on the 1st page, missed at other pages. ....

How to stay the TOP-OF-PAGE still at its place?? Thanks very much.

Code: Select all

REPORT  ZT8 NO STANDARD PAGE HEADING LINE-COUNT 20(1). 
TABLES: LQUA. 

DATA: BEGIN OF ST_MAIN, 
        MATNR LIKE LQUA-MATNR, 
        VERME LIKE LQUA-VERME, 
      END OF ST_MAIN. 
DATA: I_MAIN LIKE ST_MAIN OCCURS 0 WITH HEADER LINE.

TOP-OF-PAGE.
  WRITE:'DDDD',  / 'DDD'.
  PERFORM TITLE_OUTPUT.
end-of-page.
  write:'FFFFFOOOOTTTER'.


AT LINE-SELECTION.
  GET CURSOR FIELD cursorfield.
  ASSIGN (cursorfield) TO <f>. 

START-OF-SELECTION. 

  SET PF-STATUS '100'. 

  SELECT MATNR VERME INTO CORRESPONDING FIELDS OF TABLE I_MAIN 
  FROM LQUA 
  WHERE CHARG EQ 'B1'. 

AT USER-COMMAND. 
  CASE SY-UCOMM. 
    WHEN 'UP'. 
      "How to code? when 'Title1',Then Sort ITAB by MATNR ascendly. 
      "How to code? when 'Title2',Then Sort ITAB by VERME ascendly. 
      GET CURSOR FIELD cursorfield.
     ASSIGN (cursorfield) TO <f>.
      IF <f> EQ 'TITLE2'.
        sort I_MAIN by VERME ASCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.
      ELSEIF <f> EQ 'TITLE1'.
        sort I_MAIN by matnr ASCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.
      ENDIF.   

    WHEN 'DOWN'. 

     "How to code? when 'Title1',Then Sort ITAB by MATNR DEScendly. 
    GET CURSOR FIELD cursorfield.
     ASSIGN (cursorfield) TO <f>.
      IF <f> EQ 'TITLE2'.
        sort I_MAIN by VERME DESCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.
      ELSEIF <f> EQ 'TITLE1'.
        sort I_MAIN by matnr DESCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.
      ENDIF.

  ENDCASE. 


END-OF-SELECTION. 

  PERFORM TITLE_OUTPUT. 
  PERFORM DATA_OUTPUT. 
  
FORM TOP_OF_PAGE.
  WRITE:'DDDD',  / 'DDD'.
  PERFORM TITLE_OUTPUT.
ENDFORM.                    " TOP-OF-PAGE


FORM TITLE_OUTPUT. 
  WRITE:/5 'TITLE1', 
         20 'TITLE2'. 
ENDFORM.                    " TITLE_OUTPUT 

FORM DATA_OUTPUT. 
  LOOP AT I_MAIN. 
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME. 
  ENDLOOP.  
   LOOP AT I_MAIN. 
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME. 
  ENDLOOP. 
   LOOP AT I_MAIN. 
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME. 
  ENDLOOP. 
   LOOP AT I_MAIN. 
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME. 
  ENDLOOP. 
   LOOP AT I_MAIN. 
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME. 
  ENDLOOP. 
ENDFORM.                    " DATA_OUTPUT

Yukikaze

Post by Yukikaze » Tue Aug 09, 2005 11:43 pm

The question for now is:

When i resort and rewrite the ITAB to the screen, the TOP-OF-PAGE lost .

there r many pages outputed to the screen, any1 knows why this would happen and how to solve it??

Thanks very much!!

Yuki. :shock: :shock:

Yukikaze

Post by Yukikaze » Wed Aug 10, 2005 12:15 am

I added below statements:

Code: Select all

TOP-OF-PAGE DURING LINE-SELECTION.
TOP-OF-PAGE still lost.

How to, how to?? :shock: :x :(

Yukikaze

Post by Yukikaze » Wed Aug 10, 2005 12:39 am

Below is the full code.(if u want to copy it for a try, should define an PF-status 100 and defined 2 buttons called 'AESC' and 'DESC'. )

Code: Select all

REPORT  ZATEST8     NO STANDARD PAGE HEADING LINE-COUNT 20(1).
TABLES: LQUA,MAKT,MCHA,MARM.

DATA: WS_LINES LIKE SY-LINNO.
DATA: cursorfield(20).
FIELD-SYMBOLS <f>.
DATA: var1(20) VALUE 'TITLE1'.
DATA: var2(20) VALUE 'TITLE2'.


DATA: BEGIN OF ST_MAIN,
        MATNR LIKE LQUA-MATNR,
        VERME LIKE LQUA-VERME,
      END OF ST_MAIN.
DATA: I_MAIN LIKE ST_MAIN OCCURS 0 WITH HEADER LINE.

TOP-OF-PAGE.
  WRITE:'DDDD',  / 'DDD'.
  PERFORM TITLE_OUTPUT.


TOP-OF-PAGE DURING LINE-SELECTION.

end-of-page.
  write:'FFFFFOOOOTTTER'.

AT LINE-SELECTION.
  GET CURSOR FIELD cursorfield.
  ASSIGN (cursorfield) TO <f>.
  

START-OF-SELECTION.

  SET PF-STATUS '100'.
  
  SELECT MATNR VERME INTO CORRESPONDING FIELDS OF TABLE I_MAIN
  FROM LQUA
  WHERE VERME >= 0.

AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'AESC'. "button for sort up
     GET CURSOR FIELD cursorfield.
     ASSIGN (cursorfield) TO <f>.
      IF <f> EQ 'TITLE2'.
*      WRITE: 'EEE'.
        sort I_MAIN by VERME ASCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.
      ELSEIF <f> EQ 'TITLE1'.
        sort I_MAIN by matnr ASCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.


      ENDIF.
*  sy-lsind = sy-lsind - 1.
    WHEN 'DESC'. "button for sort down
      GET CURSOR FIELD cursorfield.
     ASSIGN (cursorfield) TO <f>.
      IF <f> EQ 'TITLE2'.
*      WRITE: 'EEE'.
        sort I_MAIN by VERME DESCENDING.
        PERFORM TOP_OF_PAGE.
        PERFORM DATA_OUTPUT.
        PERFORM BLANK_FOOTER.
     ENDIF.

  ENDCASE.



END-OF-SELECTION.







  PERFORM DATA_OUTPUT.
  PERFORM BLANK_FOOTER.


*---------------------------------------------------------------------*
*       FORM TITLE_OUTPUT                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM TITLE_OUTPUT.
  WRITE:/5 VAR1,
         20 VAR2.
ENDFORM.                    " TITLE_OUTPUT

*---------------------------------------------------------------------*
*       FORM DATA_OUTPUT                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM DATA_OUTPUT.
  LOOP AT I_MAIN.
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME,
          / .

  ENDLOOP.
  LOOP AT I_MAIN.
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME,
          / .

  ENDLOOP.
  LOOP AT I_MAIN.
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME,
          / .

  ENDLOOP.
  LOOP AT I_MAIN.
    WRITE:/5 I_MAIN-MATNR,I_MAIN-VERME,
          / .

  ENDLOOP.
ENDFORM.                    " DATA_OUTPUT

*---------------------------------------------------------------------*
*       FORM BLANK_FOOTER                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM BLANK_FOOTER.
  ws_lines = sy-linct - sy-linno - 1. "REPORT LINE-COUNT(#)
  skip ws_lines.
ENDFORM.                    " BLANK_FOOTER
*&---------------------------------------------------------------------*
*&      Form  TOP-OF-PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
  WRITE:'DDDD',  / 'DDD'.
  PERFORM TITLE_OUTPUT.
ENDFORM.                    " TOP-OF-PAGE

:shock: :shock:

hognoxious
Posts: 1398
Joined: Thu Dec 04, 2003 8:16 am
Location: Stuck in a pagoda with Tricia Toyoda

Learn the ABAP event model

Post by hognoxious » Wed Aug 10, 2005 9:01 am

It looks like you have a form called top_of_page that's called once, and not from the top-of-page event. Do you think SAP magically guesses that, as the name is similar, that's when it should perform it?
First he pinches my sig, Now he's cribbing my posts too!

Post Reply