‎2010 Aug 16 10:47 AM
Hello People,
I found few threads on this topic already, I tried solving with the help of those clues but in vain.
I want to create a function module which accepts a date range like in ACC_T_RA_DATE, and output a list of materials.
The list of materials correspond to the purchase orders that were created in the given date range.
Please kindly observe, I am not using a program to pass any value - I will be using only the function module throughout the process.
Please advice me on this.
Thanks in advance,
Disha.
‎2010 Aug 16 11:16 AM
‎2010 Aug 16 11:09 AM
Hi what is there so difficult in it ?
ACC_T_RA_DATE is a table type.
Declare a import parameter in your fm refereing to ACC_T_RA_DATE.
In you program
data:i_tab type ACC_T_RA_DATE,
la_date type ACC_S_RA_DATE.
la_date-sign = 'I'.
la_date-option = 'BT' "or EQ,LE etc.
la_date-low = '__/__/____'/
la_date-high = '__/__/____/.
append la_date to i_tab.
Now just pass i_tab to your importng parameter of the fm.
‎2010 Aug 16 11:39 AM
Hello Keshav,
Thanks for the quick reply. As I have already mentioned in my post, I am not using any program to export values into Function module. The entire thing should happen with the function module.
Disha.
‎2010 Aug 16 11:16 AM
‎2010 Aug 16 11:53 AM
Hi Anya,
Thanks for the reply, I did the same thing.
One import variable of type ACC_T_RA_DATE. And an other table which accepts the materials into it (of type ekpo) for output. I did an inner join on ekko and ekpo and in the where condition I have aedat from the date range.
I wonder if I am missing out something.
Disha.
‎2010 Aug 16 11:58 AM
What is your exact requirement, FM should look like
FUNCTION z_mm_xxx.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(RANGE_DATE) TYPE ACC_T_RA_DATE
*" EXPORTING
*" REFERENCE(MATERIAL_LIST) TYPE /SAPXCQM/EKPO_TAB
*" EXCEPTIONS
*" INVALID_DATE_RANGE
*" NO_PURCHASE_ORDER
*" NO_ITEM_FOUND
*"----------------------------------------------------------------------
DATA: lv_ebeln LIKE ekko-ebeln, "#EC NEEDED
lv_datum LIKE syst-datum.
FIELD-SYMBOLS <fs> TYPE acc_s_ra_date.
* Init
REFRESH material_list.
* Check date range
LOOP AT range_date ASSIGNING <fs>.
lv_datum = <fs>-low.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = lv_datum
EXCEPTIONS
plausibility_check_failed = 1.
IF sy-subrc NE 0.
RAISE invalid_date_range.
ENDIF.
IF <fs>-option EQ 'BT'
OR <fs>-option EQ 'NB'.
IF <fs>-high LT <fs>-low. "#EC PORTABLE
RAISE invalid_date_range.
ENDIF.
lv_datum = <fs>-high.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = lv_datum
EXCEPTIONS
plausibility_check_failed = 1.
IF sy-subrc NE 0.
RAISE invalid_date_range.
ENDIF.
ENDIF.
ENDLOOP.
* Check existence of PO
SELECT SINGLE ebeln INTO lv_ebeln
FROM ekko
WHERE aedat IN range_date.
IF sy-subrc NE 0.
RAISE no_purchase_order.
ENDIF.
* Read item
SELECT * INTO CORRESPONDING FIELDS OF TABLE material_list
FROM ekpo
JOIN ekko ON ekko~ebeln EQ ekpo~ebeln
WHERE ekko~aedat IN range_date.
IF sy-subrc NE 0.
RAISE no_item_found.
ENDIF.
ENDFUNCTION.Regards,
Raymond
‎2010 Aug 16 12:59 PM
Hi Disha,
You can try with two import parameters instead one like start_date and end_date. In the select statement you can use between.
Hope this works.
Thanks,
Venkat
‎2010 Aug 16 1:01 PM
I don't understand your problem.
Simply create to import parameters i.e. a from and to date, plus the output table for your materials.
‎2010 Aug 16 2:01 PM
Hi Dishaa,
I think as per your requirement.. I have the same thinking that you create a fm with two import parameters which contains dates, i.e. From and To. and one export parameter as table from which you can get the list of materials you want from the table.
Regards,
Kunal.
‎2010 Aug 17 3:15 PM
Hey everybody,
Thanks for the post and the clues. It works.
I created a structure type zlinetype for my output table. And yup, its all fine - I dont understand why I faced a problem earlier.
FUNCTION ZMAT2.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(START) TYPE EKKO-AEDAT
*" REFERENCE(END) TYPE EKKO-AEDAT
*" TABLES
*" T_MAT STRUCTURE ZLINETYPE
*"----
SELECT P~MATNR
K~AEDAT
INTO TABLE T_MAT
FROM EKPO AS P
INNER JOIN
EKKO AS K
ON PEBELN = KEBELN
WHERE
K~AEDAT GT START
AND
K~AEDAT LT END.
LOOP AT T_MAT.
WRITE : / T_MAT-MATNR,
/ T_MAT-AEDAT.
ENDLOOP.
ENDFUNCTION.
I have an other doubt. Is there way a way I can get an input help for my date range.
Thanks,
Disha.
‎2010 Aug 17 6:34 PM
WHY would you need input help on an FM parameter? Are you trying to use a function module as a report tool? Makes no sense...we call function modules from inside other programs!
If you need help on a date field, why not create a report with a selection screen and declare your input range with the appropriate DDIC reference?
‎2010 Aug 17 6:45 PM
Makes sense. Was just wondering why can we not ? Anyways Thanks people for your valuable suggestions.