Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

alv list viewer

Former Member
0 Likes
1,961

how the at line selection event on alv list can be performed.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,937

Hi suganya,

1. There are some parameters

in the FM which are passed,

and a new FORM has to be written.

2. Just copy paste this code in new program.

3. It will display list of company.

On double-clicking on the alv,

it will again display the clicked company code.

Important code has been marked.

4.

REPORT abc.

TYPE-POOLS : slis.

*----


Data

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE t001.

DATA : END OF itab.

DATA : alvfc TYPE slis_t_fieldcat_alv.

*----


Select Data

SELECT * FROM t001 INTO TABLE itab.

*------- Field Catalogue

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'ITAB'

i_inclname = sy-repid

CHANGING

ct_fieldcat = alvfc

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

*----


Display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

it_fieldcat = alvfc

i_callback_program = sy-repid "<-------Important

i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2.

*----


  • CALL BACK FORM

*----


FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE

slis_selfield.

READ TABLE itab INDEX whatrow-tabindex.

WRITE itab-bukrs.

ENDFORM. "ITAB_user_command

regards,

amit m.

18 REPLIES 18
Read only

Former Member
0 Likes
1,937
AT LINE SELECTION in ALV is used in interactive reporting

AT LINE-SELECTION.

If SY-LSIND = 0. " basic list

ENDIF.

<b>If SY-LSIND = 1. " 1st interactive list</b>
  
CLEAR I_LIKP_LIPS.
REFRESH I_LIKP_LIPS.

SELECT LIKP~VBELN LIKP~LFART LIKP~LFDAT LIPS~POSNR LIPS~LFIMG LIPS~VGBEL
LIPS~VGPOS INTO TABLE I_LIKP_LIPS FROM LIKP INNER JOIN LIPS ON
LIKP~VBELN = LIPS~VBELN WHERE
LIPS~VGBEL = I_VBAK_VBAP-VBELN AND
LIPS~VGPOS = I_VBAK_VBAP-POSNR.

LOOP AT I_LIKP_LIPS.

WRITE: / I_LIKP_LIPS-VBELN, I_LIKP_LIPS-POSNR.

HIDE I_LIKP_LIPS.


ENDLOOP.

<b>ENDIF.</b>
<b>If SY-LSIND = 2. " 2nd interactive list

ENDIF.</b>  and so on ...

Message was edited by: Sekhar

Read only

Former Member
0 Likes
1,938

Hi suganya,

1. There are some parameters

in the FM which are passed,

and a new FORM has to be written.

2. Just copy paste this code in new program.

3. It will display list of company.

On double-clicking on the alv,

it will again display the clicked company code.

Important code has been marked.

4.

REPORT abc.

TYPE-POOLS : slis.

*----


Data

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE t001.

DATA : END OF itab.

DATA : alvfc TYPE slis_t_fieldcat_alv.

*----


Select Data

SELECT * FROM t001 INTO TABLE itab.

*------- Field Catalogue

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'ITAB'

i_inclname = sy-repid

CHANGING

ct_fieldcat = alvfc

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

*----


Display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

it_fieldcat = alvfc

i_callback_program = sy-repid "<-------Important

i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2.

*----


  • CALL BACK FORM

*----


FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE

slis_selfield.

READ TABLE itab INDEX whatrow-tabindex.

WRITE itab-bukrs.

ENDFORM. "ITAB_user_command

regards,

amit m.

Read only

Former Member
0 Likes
1,937

Hi again,

1. When using alv,

AT LINE SELECTION

concept does not come into picture.

(it can still be used)

2. However, for such, thing,

ALV architecture already provided

a facility for this using

CALL_BACK concept.

3. Whenever a line is double clicked on alv,

our FORM is called by the system.

The form is provided some

basic input like

a) user command which invoked the code

b) selected row information ie. (index of the row, field name which is clicked, etc)

4. This inputs can be read

and we can detect which row has been clicked,

for further logic and action.

5. Refer my previous reply !

regards,

amit m.

Read only

0 Likes
1,937

hi,

Initially i had a selection-screen,when i click a pushbutton in that screen a report is displayed.whether the code u sended can be used for this application.

Read only

0 Likes
1,937

Hi again,

1. If the report which is displayed

is a alv

then we can use this code.

2. Just check the source code of the program.

it must be having the fm

REUSE_ALV_LIST_DISPLAY

regards,

amit m.

Read only

0 Likes
1,937

The source code contains 'REUSE_ALV_LIST_DISPLAY' but when i use the I_CALLBACK_user-command the pushbutton fuction is not working.ie the report is not displayed.

Read only

0 Likes
1,937

Is ur pushbutton defined in ur Pf status as vijay given and activated

Read only

0 Likes
1,937

I defined my push button using USER_COMMAND only.

Read only

0 Likes
1,937

How did you define can you tell us,

you need to declare it , by double click on the pfstatus you mentioned.

set pf-status '<b>ABC</b>' need to click on ABC and create it and set the FCODE,and then activate it.

in user_command

you need to check the sy-ucomm.

case sy-ucomm.

when '<b>BUTTONCODE</b>'.

handle it here...

Regards

vijay

Read only

0 Likes
1,937

i defined by

CASE sy-ucomm.

when' '

perform....

like this only i defined.

Read only

0 Likes
1,937

Hi ,

pls clarify on these

1.Have u defined ur pushbutton in selection screen??if so is it in application toolbar or in ur selection screen block

or

first u will get ur selection screen , then ALV will be displayed , in that ALV u had defined a push button in application toolbar , on click that u want another ALV

Read only

0 Likes
1,937

first i will get my selection screen in that a pushbutton is there if i click on that ALV will be displayed .

Read only

0 Likes
1,937

Hi Sugnaya,

you need do like this..

at user-command.

when 'BUTTON'.

write the code for alv

display alv here....

Regards

vijay

Read only

0 Likes
1,937

hi vijay,

i had written code like this and also the report is displayed.after the report display if i dubleclick on the field in the report i want to get the details of that field.

this is what i needed exactly.

pls help me.

Read only

0 Likes
1,937

Hi Suganya,

it can be done.

please confirm this...

in selection screen if you click on a button it will display the report.

now you want to double click on alv report is it correct.

alv built in functionality is there .you don't need to do much for that.

FORM POPUP USING P_EXTAB TYPE SLIS_T_EXTAB.
*- Pf status
  SET PF-STATUS '<b>STATUS</b>'.
ENDFORM. 

double click on status , give the Fucntion codes for BACK, CANCEL, EXIT and also FOR CHOOSE give THE FUCNTION CODE AS <b>PICK</b>.

then you activate it , and come back to your report activate it, now test it by clicking a line. it will display the details in popup.

Regards

vijay

Read only

0 Likes
1,937

hi vijay,

FORM POPUP USING P_EXTAB TYPE SLIS_T_EXTAB.

*- Pf status

SET PF-STATUS 'STATUS'.

ENDFORM.

can u explain this in detail.

Read only

0 Likes
1,937

this is for alv buttons. and your own buttons. but double click on cell you need to set it, and also you need to give Function code for<b> CHOOSE</b> it will enable double click....

you need to give <b>PICK</b>(for CHOOSE to enable double click).........

regards

vijay

Read only

Former Member
0 Likes
1,937

Hi Suganya,

your question is realted to ALV list, so it is obvious that what ever Amit provided works well. but in interactive alv sy-lsind will never work.

so you need to use pf-status and at user-command.

check this example...

REPORT  ZTEST_ALV_INT                            .

TYPE-POOLS:SLIS.
DATA :   IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
          IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.


DATA: BEGIN OF ITAB OCCURS 0,
       VBELN LIKE VBAK-VBELN,
       POSNR LIKE VBAP-POSNR,
       END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0,
       VBELN LIKE LIKP-VBELN,
       POSNR LIKE LIPS-POSNR,
       VGBEL LIKE LIPS-VGBEL,
       VGPOS LIKE LIPS-VGPOS,
       END OF ITAB1.

DATA: IT_LIPS LIKE ITAB1 OCCURS 0 WITH HEADER LINE.
SELECT  VBELN
        POSNR
        up to 1000 rows
        FROM VBAP
        INTO TABLE ITAB.

IF SY-SUBRC = 0.
  SORT ITAB BY VBELN .
  SELECT VBELN
   POSNR
   VGBEL
   VGPOS
   INTO TABLE ITAB1
   FROM LIPS
   FOR ALL ENTRIES IN ITAB
   WHERE VGBEL = ITAB-VBELN
     AND    VGPOS = ITAB-POSNR.
ENDIF.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS  = 1.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS  = 1.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM       = SY-REPID
    I_CALLBACK_PF_STATUS_SET = 'POPUP'
    I_CALLBACK_USER_COMMAND  = 'HANDLE_USER_COMMAND'
    IT_FIELDCAT              = IT_FIELDCAT
  TABLES
    T_OUTTAB                 = ITAB
  EXCEPTIONS
    PROGRAM_ERROR            = 1
    OTHERS                   = 2.

IF SY-SUBRC  = 0.

ENDIF.

*&---------------------------------------------------------------------*
*&      Form  POPUP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_EXTAB    text
*----------------------------------------------------------------------*
FORM POPUP USING P_EXTAB TYPE SLIS_T_EXTAB.

*- Pf status
  SET PF-STATUS 'POPUP'.

ENDFORM.                 " POPUP

*&---------------------------------------------------------------------*
*&      Form  HANDLE_USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM HANDLE_USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                               RS_SELFIELD TYPE SLIS_SELFIELD.

  CASE R_UCOMM.

    WHEN '&IC1'.
      IF RS_SELFIELD-FIELDNAME = 'VBELN'.
        READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.
        LOOP AT ITAB1 WHERE VGBEL = ITAB-VBELN
                          AND VGPOS = ITAB-POSNR.

          MOVE-CORRESPONDING ITAB1 TO IT_LIPS.
          APPEND IT_LIPS.
        ENDLOOP.

        PERFORM INTERACTIVE_REPORT.
      ENDIF.

  ENDCASE.

ENDFORM.                    "HANDLE_USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  interactive_report
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM INTERACTIVE_REPORT .
  X_FIELDCAT-FIELDNAME = 'VBELN'.
  X_FIELDCAT-SELTEXT_L = 'VBELN'.
  X_FIELDCAT-TABNAME = 'IT_LIPS'.
  X_FIELDCAT-COL_POS  = 1.
  APPEND X_FIELDCAT TO IT_FIELDCAT1.
  CLEAR X_FIELDCAT.

  X_FIELDCAT-FIELDNAME = 'POSNR'.
  X_FIELDCAT-SELTEXT_L = 'ITEM'.
  X_FIELDCAT-TABNAME = 'IT_LIPS'.
  X_FIELDCAT-COL_POS  = 2.
  APPEND X_FIELDCAT TO IT_FIELDCAT1.
  CLEAR X_FIELDCAT.
  X_FIELDCAT-FIELDNAME = 'VGBEL'.
  X_FIELDCAT-SELTEXT_M = 'SO #'.
  X_FIELDCAT-TABNAME = 'IT_LIPS'.
  X_FIELDCAT-COL_POS  = 3.
  APPEND X_FIELDCAT TO IT_FIELDCAT1.
  CLEAR X_FIELDCAT.

  X_FIELDCAT-FIELDNAME = 'VGPOS'.
  X_FIELDCAT-SELTEXT_M = 'SO ITEM'.
  X_FIELDCAT-TABNAME = 'IT_LIPS'.
  X_FIELDCAT-COL_POS  = 4.
  APPEND X_FIELDCAT TO IT_FIELDCAT1.
  CLEAR X_FIELDCAT.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IT_FIELDCAT        = IT_FIELDCAT1
    TABLES
      T_OUTTAB           = IT_LIPS
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.

  IF SY-SUBRC  = 0.

  ENDIF.
ENDFORM.                    " interactive_report

Regards

vijay