‎2008 Mar 29 9:40 AM
‎2008 Mar 29 11:15 AM
Hi,
Gothrough the following links. I hope it will give clear idea about internal table and Functional module.
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
https://www.sdn.sap.com/irj/sdn/advancedsearch?query=table%20and%20structure&cat=sdn_all
Example Code:
TABLES:MARA.
DATA:ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
ITAB-MATNR = '123ABCDA'. .
ITAB-MBRSH = 'C'.
ITAB-MTART = 'FERT' .
ITAB-MEINS = 'KG' .
APPEND ITAB.
ITAB-MATNR = '123ABCDB'. .
ITAB-MBRSH = 'C'.
ITAB-MTART = 'FERT' .
ITAB-MEINS = 'KG' .
APPEND ITAB.
LOOP AT ITAB.
INSERT MARA FROM ITAB.
MODIFY MARA .
ENDLOOP.
Regards,
Harish
‎2008 Mar 29 8:04 PM
hai
dongare,
if u want to use internal table in function module, u must follow these steps.
1. Create a table type and corresponding line type using SE11 to make it as a global.
2. Populate the internal table by using appropriate selection criteria.
3. Create a Function module and in Tables option in the interface of fm,
Specify the parameter name (The name of internal table passing from report program) and
Associated Type( Line type Created in SE11)
4. Perform the required Operations on the table.
5. Call the Function module from main program.
If it useful , reward ponts.
Thank you
G.V.K.Prasad
‎2008 Mar 30 12:08 PM
display the functional module .
check the data type of the import/export field.
all you need to match the data type of internal table you are passing(export or import) in the function module or badi or bapi.
In FM, 'tables' part are passed as internal table , rest are either as fields or as structures.
Reward points if helpful.
Rgs,
Ashok
‎2008 Mar 31 7:51 AM
Hi,
here are example function modules where u can understand how to declare internal tables.
Check this sample program for creating delivery from a sales order.
Give the sales order as input..
internal table is generally declared as type of a structure.
in the following code t_vbap is a structure and t_request is an internal table of this bapideliciousrequest table type
t_created is also an internal table of table type bapideliciouscreateditems
PARAMETERS: p_vbeln LIKE vbak-vbeln.
DATA: BEGIN OF t_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
matnr LIKE vbap-matnr,
werks LIKE vbap-werks,
END OF t_vbap.
DATA: t_request TYPE STANDARD TABLE OF bapideliciousrequest
WITH HEADER LINE.
DATA: t_created TYPE STANDARD TABLE OF bapideliciouscreateditems
WITH HEADER LINE.
DATA: t_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
SELECT vbeln posnr kwmeng matnr werks
INTO TABLE t_vbap
FROM vbap
WHERE vbeln = p_vbeln.
LOOP AT t_vbap.
t_request-document_numb = t_vbap-vbeln.
t_request-document_item = t_vbap-posnr.
t_request-quantity_sales_uom = t_vbap-kwmeng.
t_request-id = 1.
t_request-document_type = 'A'.
t_request-delivery_date = sy-datum.
t_request-material = t_vbap-matnr.
t_request-plant = t_vbap-werks.
t_request-date = sy-datum.
t_request-goods_issue_date = sy-datum.
t_request-goods_issue_time = sy-uzeit.
APPEND t_request.
ENDLOOP.
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = t_request
createditems = t_created
return = t_return
.
READ TABLE t_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE e208(00) WITH 'Delivery creation error'.
ENDIF.
COMMIT WORK.
READ TABLE t_created INDEX 1.
WRITE: / 'Delivery - ', t_created-document_numb.
This another example.
REPORT z_yaktest3 NO STANDARD PAGE HEADING MESSAGE-ID zi455.
*----
Internal table declaration *
----
DATA: gt_headerdata TYPE STANDARD TABLE OF bapi_incinv_create_header
INITIAL SIZE 0,
gt_itemdata TYPE STANDARD TABLE OF bapi_incinv_create_item
INITIAL SIZE 0,
gt_accountingdata TYPE STANDARD TABLE OF bapi_incinv_create_account
INITIAL SIZE 0,
gt_return TYPE STANDARD TABLE OF bapiret2
INITIAL SIZE 0.
DATA: gs_headerdata LIKE bapi_incinv_create_header.
DATA: gs_itemdata LIKE bapi_incinv_create_item.
DATA: gs_accountingdata TYPE bapi_incinv_create_account.
DATA: gs_return TYPE bapiret2.
DATA: l_date TYPE sy-datum.
l_date = sy-datum - 15.
Error flag *
DATA: l_errflag(1) TYPE c.
*----
Build Invoice header
*----
Document Type (Invoice)
gs_headerdata-invoice_ind = 'X'.
gs_headerdata-doc_type = 51.
Document Date
gs_headerdata-doc_date = l_date.
Posting Date
gs_headerdata-pstng_date = l_date.
Reference Document No
gs_headerdata-ref_doc_no = 323348.
gs_headerdata-gross_amount = 31.
Currency
gs_headerdata-currency = 'USD'.
Company Code
gs_headerdata-comp_code = 'D3'.
Baseline Date
gs_headerdata-bline_date = l_date.
*
**Tax Indicator
*gs_headerdata-calc_tax_ind = 'X'.
*----
Build order item(s) - Only 1 is used in this example
*----
Document Item
gs_itemdata-invoice_doc_item = 000001.
Purchase Order Number
gs_itemdata-po_number = 3700000011.
Purchase Order Item
gs_itemdata-po_item = 00010.
Quantity
gs_itemdata-quantity = 31.
gs_itemdata-po_unit = 'Z00'.
Item Amount
gs_itemdata-item_amount = 31.
gs_itemdata-tax_code = 'O0'.
gs_itemdata-taxjurcode = '0100000000'.
APPEND gs_itemdata TO gt_itemdata.
Document Item
*gs_itemdata-invoice_doc_item = '00002'.
*
Purchase Order Number
*gs_itemdata-po_number = '4700000158'.
*
Purchase Order Item
*gs_itemdata-po_item ='00020' .
*
Quantity
*gs_itemdata-quantity = '5'.
*gs_itemdata-po_unit = 'Z00'.
*
Item Amount
*gs_itemdata-item_amount = '5'.
*gs_itemdata-tax_code = 'O0'.
*gs_itemdata-taxjurcode = '0100000000'.
*
*APPEND gs_itemdata TO gt_itemdata.
*
Accounting Data
***gs_accountingdata-costcenter = 'DUMMY CCTR'.
*gs_accountingdata-invoice_doc_item = '00001'.
*gs_accountingdata-xunpl = 'X'.
*gs_accountingdata-tax_code = 'O0'.
*gs_accountingdata-taxjurcode = '0100000000'.
*gs_accountingdata-ITEM_AMOUNT = 100.
*gs_accountingdata-gl_account = '0003805101'.
*
*APPEND gs_accountingdata TO gt_accountingdata.
*CLEAR :gs_accountingdata.
*Call the BAPI to Create the Return Order
data: gv_INVOICE type BAPI_INCINV_FLD-INV_DOC_NO,
gv_YEAR type BAPI_INCINV_FLD-FISC_YEAR.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = gs_headerdata
IMPORTING
INVOICEDOCNUMBER = gv_INVOICE
FISCALYEAR = gv_YEAR
TABLES
return = gt_return
itemdata = gt_itemdata.
accountingdata = gt_accountingdata.
PERFORM error.
*----
Check and write Return table
*----
FORM error.
LEAVE TO LIST-PROCESSING.
CLEAR l_errflag.
LOOP AT gt_return INTO gs_return.
WRITE: / gs_return-type, gs_return-message(200).
IF gs_return-type = 'E'.
l_errflag = 'X'.
ENDIF.
ENDLOOP.
PERFORM commit.
ENDFORM. " ERROR INPUT
*----
No errors - Commit
*----
FORM commit.
these sample codes may help u.
Thanks®ards,
Sravani.