cancel
Showing results for 
Search instead for 
Did you mean: 

Call a Function

former_member184386
Active Participant
0 Kudos
71

Hi

I created a GUI-STATUS using se41 and added it in my abap report:

start-of-selection.

set pf-status 's001'.

I also added an icon in the GUI-STATUS to use for calling a function 'ALVG', now, where do I add the code that will execute this function, is it in SE41 or in the report itself? I also tried modifying screen 1000 but got an error message that this screen should not be modified.

Need some advice on this one, thanks!

Accepted Solutions (1)

Accepted Solutions (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You will need to put it directly in your program under the AT USER-COMMAND event.

start-of-selection.

...

AT USER-COMMAND.

case sy-ucomm.
when 'ALVG'.
* do something.

endcase.

REgards,

Rich Heilman

former_member184386
Active Participant
0 Kudos

tried this already, but the user has to click a button first before the report is shown. what i would like to do is to display the report first, then the user has an option to display it as an alv grid.

Former Member
0 Kudos

Hi Ricky

You can as well write the write statemants and get the report list.

The PF status set will reflect only on the report list that has come up for your write statements. and once you reach this screen you will get your icon too so if the user clicks here the control jumps to "at user-command" event so you can write your ALV code under this event.

I guess I have answers you correctly... let me know if I am wrong.

Regards

Santosh

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Ricky, this is working good for me.

button shows up on the list, user presess it and the AT USER COMMAND event is fire.



report zrich_0003.

parameters: p_check.

start-of-selection.

  set pf-status 'TEST'.
  do 100 times.

    write:/ sy-index.

  enddo.

at user-command.
  case sy-ucomm.
    when 'ALVG'.
* Do something.
      check sy-subrc  = 0.

  endcase.

Regards,

RIch Heilman

former_member188685
Active Contributor
0 Kudos

REPORT  ZTEST_REPORT_ALV.

type-pools: slis.
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
       LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA: BEGIN OF I_TAB OCCURS 0,
FIELD1 TYPE I,
FIELD2 TYPE I,
END OF I_TAB.
start-of-selection.
set pf-status 'AAA'.

I_TAB-FIELD1 = 19.
I_TAB-FIELD2 = 20.
APPEND I_TAB.
I_TAB-FIELD1 = 19.
I_TAB-FIELD2 = 20.
APPEND I_TAB.
I_TAB-FIELD1 = 19.
I_TAB-FIELD2 = 20.
APPEND I_TAB.
I_TAB-FIELD1 = 19.
I_TAB-FIELD2 = 20.
APPEND I_TAB.
I_TAB-FIELD1 = 19.
I_TAB-FIELD2 = 20.
APPEND I_TAB.

loop at I_TAB.

write:/ I_TAB-FIELD1,
       I_TAB-FIELD2.

endloop.
at user-command.
case sy-ucomm.
when 'ALVG'.
PERFORM INITIALIZE_FIELDCAT USING GT_FIELDCAT[].
PERFORM CALL_ALV  TABLES I_TAB[]
                 USING GT_FIELDCAT.
when 'BACk'.

endcase.
*&---------------------------------------------------------------------*
*& Form initialize_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FIELDCAT[] text
*----------------------------------------------------------------------*
FORM INITIALIZE_FIELDCAT USING L_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

 LS_FIELDCAT-FIELDNAME = 'FIELD1'.
  LS_FIELDCAT-KEY = 'X'.
  LS_FIELDCAT-COL_POS = 1.
  LS_FIELDCAT-SELTEXT_S = 'field1'.


  APPEND LS_FIELDCAT TO L_FIELDCAT.
  CLEAR LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME = 'FIELD2'.
  LS_FIELDCAT-KEY = ' '.
  LS_FIELDCAT-COL_POS = 2.
  LS_FIELDCAT-SELTEXT_S = 'field2'.

  APPEND LS_FIELDCAT TO L_FIELDCAT.
  CLEAR LS_FIELDCAT.
ENDFORM. " initialize_fieldcat

FORM CALL_ALV  TABLES   P_TAB
                USING    P_GT_FIELDCAT .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      IT_FIELDCAT              = P_GT_FIELDCAT
    TABLES
      T_OUTTAB                 = P_TAB[]
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " call_alv
former_member184386
Active Participant
0 Kudos

Hi Rich,

I would like to go back to the list after I viewed the ALV grid, how is this done?

Thanks,

Ricky

Former Member
0 Kudos

hi

Just a back click or 'F3' will get back to the normal list

Santosh

former_member184386
Active Participant
0 Kudos

not working, i even add sy-ucomm = 'BACK' LEAVE SCREEN.

former_member583013
Active Contributor
0 Kudos

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 100

Or SCREEN 1000....It depends on you Dynpro screen or if your working on a simple report.

Greetings,

Blag.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please see this example program. When the user clics on the button in the list, the alv grid is fired, then the user clicks back from the ALV grid, the list is again displayed.



report  zrich_0003.

data: imara type table of mara with header line.

start-of-selection.

  set pf-status 'TEST'.

  select * into table imara from mara up to 100 rows.

  perform write_list.


at user-command.
  case sy-ucomm.
    when 'ALVG'.

      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_structure_name = 'MARA'
           tables
                t_outtab         = imara.

  endcase.


*---------------------------------------------------------------------*
*       FORM write_list                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form write_list.

  loop at imara.
    write:/ imara-matnr.
  endloop.

endform.

Regards,

Rich Heilman

Answers (2)

Answers (2)

former_member188685
Active Contributor
0 Kudos

Hi Ricky,

why do you need a PF-status?

is there any special requirement?

start-of-selection.
set pf-status 'S001'.

at use-command.

case sy-ucomm.
when 'BACK'.
leave to screen 0.
when 'SAVE'.

when 'EXIT'.

when 'CANC'.

endcase.

Regards

vijay

Former Member
0 Kudos

Hi Ricky

You got to write the code for this function in your report program itself.

write this piece of code in "at usercommand " event.

under this event have a case endcase. condition where in you can check for 'ALVG' and here write the necessary code for the same.

Regards

Santosh