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

Get ALV_OUTPUT table from Custom program

Former Member
0 Likes
1,340

I have a sap program that display the table in ALV_OUTPUT. I want to create custom program to call the sap program and get the resulting ALV_OUTPUT table back into my custom program without modifying the sap program. Any help will be greatly appreciated.

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,192

Does it present to the user as a ALV Grid or a classical ALV list. If a list, then you might be able to SUBMIT the report and EXPORT LIST TO MEMEORY. Then retrieve the LIST_FROM_MEMORY.

If it is a ALV grid, then I'm afraid you are out of luck.

Regards,

Rich Heilman

Read only

0 Likes
1,192

I'm trying to get the ALV_OUTPUT into an internal table first then use custom code to add it to another internal table, then download it to excel.

Read only

0 Likes
1,192

Here is a sample program illistrating how to pull a list. This submits the program behind transaction MMBE and brings the list back, then displays the internal table. Enter any valid material number and execute.



report zrich_0002.


data: begin of listout occurs 0,
      line(1024) type c,
      end of listout.

parameters: p_matnr type mara-matnr.

ranges: r_matnr for mara-matnr.

start-of-selection.

  r_matnr-sign   = 'I'.
  r_matnr-option = 'EQ'.
  r_matnr-low  = p_matnr.
  append r_matnr.

* Submit the report and export list to memory
  submit RMMMBEST exporting list to memory

              with ms_matnr-low in r_matnr
              and return.

* Get list from memory and convert to ascii
  perform retrieve_list_from_memory tables listout.

  loop at listout.
    write:/ listout.
  endloop.

************************************************************************
* RETRIEVE_LIST_FROM_MEMORY
************************************************************************
form retrieve_list_from_memory tables reportlines.

  data: list like abaplist occurs 0 with header line.
  data: txtlines(1024) type c occurs 0 with header line.

  clear list.  refresh list.
  clear reportlines. refresh reportlines.

  call function 'LIST_FROM_MEMORY'
       tables
            listobject = list
       exceptions
            not_found  = 1
            others     = 2.

  check sy-subrc = 0.

  call function 'LIST_TO_ASCI'
       tables
            listobject         = list
            listasci           = txtlines
       exceptions
            empty_list         = 1
            list_index_invalid = 2
            others             = 3.

  check sy-subrc = 0.

  reportlines[] = txtlines[].

  call function 'LIST_FREE_MEMORY'.

endform.

Regards,

Rich HEilman

Read only

0 Likes
1,192

What Rich was asking is, does the SAP standard report displays an ALV grid or or an ALV list output? If the standard SAP program is displaying the output in a grid, then it is not possible to export it to memory and then read it. But if it is displaying it in ALV list format, then you can.

Remember, by exporting list to memory, you are exporting a formatted output, not the internal table. Your import will give you only data in a long string. You will have write some parsing code to read it into an internal table with fields.

Srinivas

Read only

0 Likes
1,192

It's alv list. and thanks for all the help. I'll try it out.

Read only

0 Likes
1,192

I just looked at the program in my system. It uses the REUSE_ALV_GRID_DISPLAY function module to display the data. In dialog mode it is an ALV grid. But when ran in background it write to the spool as a list.

I don't know if it will work or not, give a try and let us know.

Regards,

Rich Heilman

Read only

0 Likes
1,192

I just tried it with one of our custom programs, it doesn't work.

Regards,

Rich Heilman

Read only

0 Likes
1,192

It didn't work. The sap program still shows on the screen and the alv_output table didn't get copy over to the custom program. Do you have any other suggestions? Anything that help will be great.

Read only

0 Likes
1,192

The only other thing would be to copy the program into a "Z" program, then comment out the call to the ALV and just pass the ALV_OUTPUT to a memory id. The import it in your other program. Or you could comment out the call to ALV and just write it out with basic WRITE statements, then you would be able to use the EXPORT LIST TO MEMORY code.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,192

here is the code to call the sap program

SUBMIT rhpe_expired_quali

WITH pchplvar = pchplvar

WITH pchotype = pchotype

WITH pchobjid IN pchobjid

WITH pchbegda = se_begd

WITH pchendda = se_endd

WITH h_qual = h_qual

WITH h_events = h_events

AND RETURN.