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: 

problem in FM

Former Member
0 Kudos

Hi,

I have created a Function Module, and from the function module i am calling a report program thru "SUBMIT" command.

now in the 'submit' command i add the addition 'exporting list to memory and return'.

after that i read the contents of the list using FM

'list_from_memory'.

now i enter the name of the internal table which i declared in FM. But this is giving me run time error.

for detaild view i post the code down below:-

submit zrpt_mm_045 with s_werks-low = s_werks

with s_mtart-low = s_mtart_low

with s_mtart-high = s_mtart_high

with s_matnr-low = s_matnr_low

with s_matnr-high = s_matnr_high

with s_budat-low = s_budat_low

with s_budat-high = s_budat_high

with s_lgort-low = s_lgort

with rb1 = rb1

with rb2 = rb2

with rb3 = rb3

EXPORTING LIST TO MEMORY AND RETURN.

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = itmatgrp1 ---> from FM

  • EXCEPTIONS

  • NOT_FOUND = 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.

endfunction.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

write the code this way:

<b>submit zrpt_mm_045 EXPORTING LIST TO MEMORY</b>

with s_werks-low = s_werks

with s_mtart-low = s_mtart_low

with s_mtart-high = s_mtart_high

with s_matnr-low = s_matnr_low

with s_matnr-high = s_matnr_high

with s_budat-low = s_budat_low

with s_budat-high = s_budat_high

with s_lgort-low = s_lgort

with rb1 = rb1

with rb2 = rb2

<b>with rb3 = rb3

AND RETURN.</b>

A sample code:

submit prog name

exporting list to memory

with SO_BNAME-LOW = w_upload-bname

and return.

if sy-subrc = 0.

refresh: i_listobject, i_listkey.

  • TO READ THE ABOVE LIST FROM MEMORY

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = i_LISTOBJECT

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

endif.

where:

*Internal table to hold list output

DATA: BEGIN OF i_LISTOBJECT OCCURS 0.

INCLUDE STRUCTURE ABAPLIST.

DATA: END OF i_LISTOBJECT.

Regards,

Anjali

Message was edited by: Anjali Devi

6 REPLIES 6

Former Member
0 Kudos

Hi,

write the code this way:

<b>submit zrpt_mm_045 EXPORTING LIST TO MEMORY</b>

with s_werks-low = s_werks

with s_mtart-low = s_mtart_low

with s_mtart-high = s_mtart_high

with s_matnr-low = s_matnr_low

with s_matnr-high = s_matnr_high

with s_budat-low = s_budat_low

with s_budat-high = s_budat_high

with s_lgort-low = s_lgort

with rb1 = rb1

with rb2 = rb2

<b>with rb3 = rb3

AND RETURN.</b>

A sample code:

submit prog name

exporting list to memory

with SO_BNAME-LOW = w_upload-bname

and return.

if sy-subrc = 0.

refresh: i_listobject, i_listkey.

  • TO READ THE ABOVE LIST FROM MEMORY

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = i_LISTOBJECT

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

endif.

where:

*Internal table to hold list output

DATA: BEGIN OF i_LISTOBJECT OCCURS 0.

INCLUDE STRUCTURE ABAPLIST.

DATA: END OF i_LISTOBJECT.

Regards,

Anjali

Message was edited by: Anjali Devi

andreas_mann3
Active Contributor
0 Kudos

Hi,

you've to define

listobject = itmatgrp1 ---> from FM

like structure ABAPLIST (look in fm LIST_FROM_MEMORY)

regards Andreas

Former Member
0 Kudos

Thank you guys

but the problem is:

i declare an internal table like structure abaplist in the source code of the FM, right.

Now i want to transform the output to the internal table of different line type which i declared it in the TABLES option of FM.

how should i do it.

The reason behind this is i want to use the output in EP.

So the output should be in FM itself.

Deepak

0 Kudos

Hi Deepak,

I don't think you can directly get the information into an internal table of your choice. The functon Module LIST_FROM_MEMORY expects you to give an internal table of a particular structure. You can later on transfer the contents of the internal table to another internal table with a structure that you want.

Hope that helps...

Regards,

Anand Mandalika.

0 Kudos

Once you have the data back from memory in your internal table, you need to pick apart the data and send it back thru your TABLES interface.

Data coming back from memory must be in table I_LISTOBJECT and be structured like ABAPLIST. Otherwise the function module will not work.




DATA: BEGIN OF i_LISTOBJECT OCCURS 0.
INCLUDE STRUCTURE ABAPLIST.
DATA: END OF i_LISTOBJECT.

CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = i_LISTOBJECT
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
endif.


Next you next to pick apart the data. Here is where it gets tricky and dangerous. We do this kind of thing when bringing data from reports to the portal. It keeps all the report code in one place but also you must be careful when changing the report program. Here's how we do it.

In this example, listout is the table I got back from memory. xzepphlsm is the internal table which is passing thru the interface. Notice that each line of the report is being broken up into the output structure.




  loop at listout.
    check sy-tabix > 8.
    clear xzepphlsm.


    perform convert_date_internal using listout-line+0(10)
                                        xzepphlsm-datum .

    perform convert_list_number_to_integar
                    changing listout-line+20(10).
    xzepphlsm-nopak = listout-line+20(10).

    perform convert_list_number_to_integar
                    changing listout-line+40(10).
    xzepphlsm-nopik = listout-line+40(10).

    perform convert_list_number_to_integar
                    changing listout-line+60(10).
    xzepphlsm-inpip = listout-line+60(10).

    append xzepphlsm.

  endloop.

Regards,

Rich Heilman

0 Kudos

Hi Deepak,

Even my requirement was the same. I dint paste that code as i was not sure whether u needed it.

Anyways, here it goes:

DATA: BEGIN OF I_LISTKEY OCCURS 0,

ZEILE(256) TYPE C.

DATA: END OF I_LISTKEY.

DATA : i_DUMMY_OUTPUT1 type standard table of DUMMY_OUTPUT1,

w_DUMMY_OUTPUT1 LIKE LINE OF I_DUMMY_OUTPUT1.

where:

TYPES : BEGIN OF DUMMY_OUTPUT1,

ur internal table fields.

END OF DUMMY_OUTPUT1.

Now:

<b>*To Convert the list into an internal table</b>

CALL FUNCTION 'LIST_TO_ASCI'

TABLES

LISTASCI = I_LISTKEY

LISTOBJECT = i_LISTOBJECT

EXCEPTIONS

EMPTY_LIST = 1

LIST_INDEX_INVALID = 2

OTHERS = 3.

CLEAR I_DUMMY_OUTPUT1. REFRESH I_DUMMY_OUTPUT1.

delete i_listkey from 1 to 3.

DESCRIBE TABLE I_LISTKEY LINES LV_LIN.

delete i_listkey index lv_lin.

LOOP AT I_LISTKEY.

SPLIT I_LISTKEY-ZEILE AT '|'

INTO W_DUMMY_OUTPUT1-field1

W_DUMMY_OUTPUT1-field2.

CONDENSE W_DUMMY_OUTPUT1-field1 NO-GAPS.

CONDENSE W_DUMMY_OUTPUT1-field2 NO-GAPS.

  • append w_dummy_output to i_dummy_output.

MOVE w_dummy_output_field1 TO

w_ur_warea_of_table -field1.

MOVE w_dummy_foutput_field2 TO

w_ur_warea_of_table-field2.

APPEND lw_ur_warea_of_table TO li_ur_itab_of_table .

ENDLOOP.

CALL FUNCTION 'LIST_FREE_MEMORY'

TABLES

LISTOBJECT = i_LISTOBJECT.

CLEAR I_DUMMY_OUTPUT1.

REFRESH I_DUMMY_OUTPUT1.

Once u go into debugg mode u wil understand why we are using the split and condense.

Hope this is how u want it.

Regards,

Anjali.