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

lists

Former Member
0 Likes
669

hi!

i have a program which runs on internal table and create list.

i have to update this list and when clicking on SAVE i have to read the list ( few lines ) and the update my table.

I dont know how to read the list line.

i used AT USER-COMMAND

CASE 'SAVE'.

but i dont know how to continue from there,

if someone have sample code it will be very helpul

regards

yifat

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
638

Hi Yifat.

you can use READ LINE to read the list.

check the sample code...

REPORT  ZTEST_ALV_GRAY                          .
type-pools: slis.

data: begin of itab occurs 0,
       vbeln like vbak-vbeln,
       posnr like vbap-posnr,
       check(1),
       process(1),
      end of itab.

data: it_fieldcat type slis_t_fieldcat_alv,
      x_fieldcat type slis_fieldcat_alv,
      x_events type slis_alv_event,
      it_events type SLIS_T_EVENT.
 x_events-NAME = SLIS_EV_END_OF_LIST.
  x_events-FORM = 'END_OF_LIST'.
  APPEND x_events  TO iT_EVENTS.
  CLEAR x_events .



select vbeln
       posnr
       into table itab
       up to 100 rows
       from vbap.

x_fieldcat-fieldname = 'CHECK'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-checkbox = 'X'.
x_fieldcat-input = 'X'.
x_fieldcat-edit = 'X'.
x_fieldcat-col_pos = 1.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM             = sy-repid
   I_CALLBACK_PF_STATUS_SET       = 'STATUS'
   I_CALLBACK_USER_COMMAND        = 'USER_COMMAND'
    IT_FIELDCAT                    = IT_FIELDCAT
     it_events                = it_events
  TABLES
    T_OUTTAB                       = ITAB
 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.

*----------------------------------------------------------------------*
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
*- Pf status
  SET PF-STATUS 'STATUS'.
ENDFORM.                 " STATUS
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                               RS_SELFIELD TYPE SLIS_SELFIELD.

  case r_ucomm.
    when 'BACK' or 'CANC' or 'EXIT'.
      leave to screen 0.
    when '&IC1'.
    ITAB-PROCESS = 'X'.
    "do what ever here....
    modify itab index rs_selfield-tabindex transporting PROCESS.
  endcase.
  rs_selfield-refresh = 'X'.
ENDFORM.                    "USER_COMMAND
FORM END_OF_LIST.
data: l_vbeln like vbak-vbeln,
      l_posnr like vbap-posnr,
      l_index type sy-tabix.

DO 106 TIMES.  "Here check your itab count and do that many times
    CLEAR: L_VBELN, L_POSNR.
    READ LINE SY-INDEX INDEX SY-LSIND
         FIELD VALUE ITAB-VBELN INTO L_VBELN
                     ITAB-POSNR INTO L_POSNR .
"3lines are reserved for alv headings , so i am reading it form 4th line
"so 4th line is equal to 1st line of itab
    IF SY-SUBRC = 0 AND SY-INDEX GE 4.
       l_index = sy-index - 3.
      READ TABLE ITAB INDEX l_index.
      IF SY-SUBRC = 0 AND ITAB-PROCESS = 'X'.
*-Modifying current list
        MODIFY LINE SY-INDEX INDEX SY-LSIND
                   FIELD FORMAT ITAB-CHECK INPUT OFF.
      ENDIF.
    ENDIF.
  ENDDO.
ENDFORM.

Regards

Vijay

5 REPLIES 5
Read only

shishupalreddy
Active Contributor
0 Likes
638

hai ,

Try to have a check box for every row in the list .

and use

READ LINE statement to read the selected lines (selected check boxes) into an internal table .

and then when u click on save capture the ucomm of save and write

modify < databasetable > from <internaltable>.

regards,

Read only

Former Member
0 Likes
638

See the demo program: demo_list_read_line to get some idea of reading the lines from the list.

Regards,

ravi

Read only

Former Member
0 Likes
638

Hi,

First of all generate the primary list in your START-OF-SELECTION event.

The system variable sy-linno will contain one line more than the total no: of lines in the list. So take this value into a variable l_lines after subtracting one from sy-linno. This variable now represents the total no: of lines in your list.

Now you can handle the user command as follows:

AT USER-COMMAND.

CASE sy-ucomm.

WHEN 'SAVE'.

DO l_lines.

READ LINE sy-index FIELD VALUE <this will contain the differentiaing value>

<compare the value here & make the changes.

ENDO.

ENDCASE.

Hope this helps.

Regards,

Chetan.

PS: Reward points if this is helpful.

Message was edited by:

Chetan H. Dubey

Read only

Clemenss
Active Contributor
0 Likes
638

Yifat,

create the list as internal table.

Display using ALV. For the newcomer, FM REUSE_ALV_GRID_DISPLAY is recommended.

See sample report BCAlv

Regards,

Clemens

Read only

Former Member
0 Likes
639

Hi Yifat.

you can use READ LINE to read the list.

check the sample code...

REPORT  ZTEST_ALV_GRAY                          .
type-pools: slis.

data: begin of itab occurs 0,
       vbeln like vbak-vbeln,
       posnr like vbap-posnr,
       check(1),
       process(1),
      end of itab.

data: it_fieldcat type slis_t_fieldcat_alv,
      x_fieldcat type slis_fieldcat_alv,
      x_events type slis_alv_event,
      it_events type SLIS_T_EVENT.
 x_events-NAME = SLIS_EV_END_OF_LIST.
  x_events-FORM = 'END_OF_LIST'.
  APPEND x_events  TO iT_EVENTS.
  CLEAR x_events .



select vbeln
       posnr
       into table itab
       up to 100 rows
       from vbap.

x_fieldcat-fieldname = 'CHECK'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-checkbox = 'X'.
x_fieldcat-input = 'X'.
x_fieldcat-edit = 'X'.
x_fieldcat-col_pos = 1.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM             = sy-repid
   I_CALLBACK_PF_STATUS_SET       = 'STATUS'
   I_CALLBACK_USER_COMMAND        = 'USER_COMMAND'
    IT_FIELDCAT                    = IT_FIELDCAT
     it_events                = it_events
  TABLES
    T_OUTTAB                       = ITAB
 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.

*----------------------------------------------------------------------*
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
*- Pf status
  SET PF-STATUS 'STATUS'.
ENDFORM.                 " STATUS
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                               RS_SELFIELD TYPE SLIS_SELFIELD.

  case r_ucomm.
    when 'BACK' or 'CANC' or 'EXIT'.
      leave to screen 0.
    when '&IC1'.
    ITAB-PROCESS = 'X'.
    "do what ever here....
    modify itab index rs_selfield-tabindex transporting PROCESS.
  endcase.
  rs_selfield-refresh = 'X'.
ENDFORM.                    "USER_COMMAND
FORM END_OF_LIST.
data: l_vbeln like vbak-vbeln,
      l_posnr like vbap-posnr,
      l_index type sy-tabix.

DO 106 TIMES.  "Here check your itab count and do that many times
    CLEAR: L_VBELN, L_POSNR.
    READ LINE SY-INDEX INDEX SY-LSIND
         FIELD VALUE ITAB-VBELN INTO L_VBELN
                     ITAB-POSNR INTO L_POSNR .
"3lines are reserved for alv headings , so i am reading it form 4th line
"so 4th line is equal to 1st line of itab
    IF SY-SUBRC = 0 AND SY-INDEX GE 4.
       l_index = sy-index - 3.
      READ TABLE ITAB INDEX l_index.
      IF SY-SUBRC = 0 AND ITAB-PROCESS = 'X'.
*-Modifying current list
        MODIFY LINE SY-INDEX INDEX SY-LSIND
                   FIELD FORMAT ITAB-CHECK INPUT OFF.
      ENDIF.
    ENDIF.
  ENDDO.
ENDFORM.

Regards

Vijay