Application Development 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: 

Convert to ALV output

0 Kudos

Hi All,

Can anyone help me convert the following code to ALV instead of Write command for its output?

REPORT Z_TEST2. "NO STANDARD PAGE HEADING.
PARAMETERS p_sys TYPE tmssysnam DEFAULT sy-sysid NO-DISPLAY.

SELECTION-SCREEN BEGIN OF BLOCK time WITH FRAME TITLE text-001 NO INTERVALS.
  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 1(25) text-002 FOR FIELD strtdate.
  PARAMETERS strtdate LIKE sy-datum OBLIGATORY DEFAULT sy-datum.
  PARAMETERS strttime LIKE sy-uzeit DEFAULT '000000'.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 1(25) text-003 FOR FIELD enddate.
  PARAMETERS enddate  LIKE sy-datum DEFAULT sy-datum.
  PARAMETERS endtime  LIKE sy-uzeit DEFAULT '240000'.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK time.

DATA: it_tmslog TYPE tmstpalogs.

CALL FUNCTION 'TMS_TM_GET_HISTORY'
 EXPORTING
   IV_SYSTEM               = p_sys
   IV_ALLCLI               = 'X'
   IV_IMPORTS              = 'X'
   IV_MONITOR              = 'X'
 IMPORTING
   ET_TMSTPALOG            = it_tmslog
 CHANGING
   CV_START_DATE           = strtdate
   CV_START_TIME           = strttime
   CV_END_DATE             = enddate
   CV_END_TIME             = endtime
          .

IF SY-SUBRC = 0.
  IF it_tmslog[] IS NOT INITIAL.
    LOOP AT it_tmslog ASSIGNING FIELD-SYMBOL(<fs_tmslog>).
      MOVE: <fs_tmslog>-trtime(8) TO enddate,
            <fs_tmslog>-trtime+4(6) TO endtime.
      WRITE: / enddate(8), endtime(6),<fs_tmslog>-trkorr(20),<fs_tmslog>-truser(12),<fs_tmslog>-as4text(60),<fs_tmslog>-retcode(4).
    ENDLOOP.
  ELSE.
    WRITE: 'No import logs found.'.
  ENDIF.
ENDIF.
1 ACCEPTED SOLUTION

DoanManhQuynh
Active Contributor

after call the function module, dont write just call alv:

CL_SALV_TABLE=>factory(
  IMPORTING
    r_salv_table   = DATA(lr_alv)
  CHANGING
    t_table        = it_tmslog
).
*  CATCH cx_salv_msg.    "
lr_alv->display( ).
10 REPLIES 10

DominikTylczyn
Active Contributor

Hi, that should not be that difficult:

  1. Create internal table with the fields to display in ALV list.
  2. Change your WRITE statement to the internal table population.
  3. Display the internal table with REUSE_ALV_LIST_DISPLAY function.

HTH

Dominik Tylczyński

0 Kudos

Hi Dominic,

Thank u for your reply.

Should i call the function within the Loop statement?

Regards,

Jandi

Outside of the loop.

Inside of the loop you collect the data. After the loop you display the data. Also follow Matthew's advice to use CL_SALV_TABLE instead of REUSE_ALV_LIST_DISPLAY.

matt
Active Contributor
0 Kudos

Don't use REUSE_ALV_LIST_DISPLAY. Use CL_SALV_TABLE. More modern and powerful.

DominikTylczyn
Active Contributor

You are right Matthew. These are just my old habits.

DoanManhQuynh
Active Contributor

after call the function module, dont write just call alv:

CL_SALV_TABLE=>factory(
  IMPORTING
    r_salv_table   = DATA(lr_alv)
  CHANGING
    t_table        = it_tmslog
).
*  CATCH cx_salv_msg.    "
lr_alv->display( ).

0 Kudos

Hi,

Is there a way to display specific columns only?

I wanted to display columns that are displayed the same in stms-import history.

Also, i want to write the Date details on top of the table but write command is not helping to display said details.

REPORT Z_TEST2 NO STANDARD PAGE HEADING.
PARAMETERS p_sys TYPE tmssysnam DEFAULT sy-sysid NO-DISPLAY.

SELECTION-SCREEN BEGIN OF BLOCK time WITH FRAME TITLE text-001 NO INTERVALS.
 SELECTION-SCREEN BEGIN OF LINE.
 SELECTION-SCREEN COMMENT 1(25) text-002 FOR FIELD strtdate.
 PARAMETERS strtdate LIKE sy-datum OBLIGATORY DEFAULT sy-datum.
 PARAMETERS strttime LIKE sy-uzeit DEFAULT '000000'.
 SELECTION-SCREEN END OF LINE.
 SELECTION-SCREEN BEGIN OF LINE.
 SELECTION-SCREEN COMMENT 1(25) text-003 FOR FIELD enddate.
 PARAMETERS enddate  LIKE sy-datum DEFAULT sy-datum.
 PARAMETERS endtime  LIKE sy-uzeit DEFAULT '240000'.
 SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK time.

DATA: it_tmslog  TYPE tmstpalogs.
DATA: lr_alv  TYPE REF TO cl_salv_table.

CALL FUNCTION 'TMS_TM_GET_HISTORY'
 EXPORTING
IV_SYSTEM  = p_sys
IV_ALLCLI  = 'X'
IV_IMPORTS  = 'X'
IV_MONITOR  = 'X'
 IMPORTING
ET_TMSTPALOG  = it_tmslog
 CHANGING
CV_START_DATE  = strtdate
CV_START_TIME  = strttime
CV_END_DATE  = enddate
CV_END_TIME  = endtime.

IF SY-SUBRC = 0.
 WRITE: / sy-datum,sy-uzeit.
 WRITE: / 'Time Interval: ',strtdate,strttime,' to',enddate,endtime.
 IF it_tmslog[] IS NOT INITIAL.
 LOOP AT it_tmslog ASSIGNING FIELD-SYMBOL(<fs_tmslog>).
 MOVE: <fs_tmslog>-trtime(8) TO enddate,
<fs_tmslog>-trtime+4(6) TO endtime.
 ENDLOOP.

 CALL METHOD CL_SALV_TABLE=>FACTORY
 IMPORTING
R_SALV_TABLE  = lr_alv
 CHANGING
T_TABLE  = it_tmslog.
lr_alv->display( ).

 ELSE.
 WRITE:/,/ 'No import logs found.'.
 ENDIF.
ENDIF.<br>

Jandi Nayanug

*) specific column:

- short version: create a table structure with your specific columns, move data and display.

- long version: hide all columns you dont want from alv:

lr_alv->get_columns( )->get_column( columnname = 'your column' )->set_technical( value = IF_SALV_C_BOOL_SAP=>TRUE ).

*) alv header: there is method: set_top_of_list in that class, you can search google for it.

matt
Active Contributor
0 Kudos

There are many many blogs and answered questions concerning how to do all kinds of things with CL_SALV_TABLE. Why not take the time to search for them?

0 Kudos

Thanks a lot for all your response. I now have done modifying the output accordingly.