Skip to Content
0
Former Member
Jan 26, 2009 at 05:10 PM

Dealing with Tables in a Function Module

26 Views

Hi ABAP Gurus,

I am doing development for BI transformations where I am dealing with run time tables with standard BI run time names such as Source_Package or Result_Package. I need to write a function module which will do identical processing on these tables but I am having troubling dealing with typing.

1. I need work areas (like wa_Source_Package) during loops

2. Derive/declare other tables (itabs) like these run time tables

3. Use these in structures like 'FOR ALL ENTRIES IN SOURCE_PACKAGE'

I can't seem to find any documentation on this in SDN or Help. Can someone help? I am listing the code below which I need to convert into a function module because it is being repeated at many places in the implementation.

Also, is there a way to know if a field belongs to an itab during run time?

----


  • Declare a work area for the result package

----


DATA: ST_RESULT_PACKAGE LIKE LINE OF RESULT_PACKAGE.

----


  • itab for holding PO's/Items which should be reversed because new

  • data for the associated program codes is being processed

----


DATA: TBL_PROGLINES TYPE SORTED TABLE OF /BIC/AZMM_O01000

WITH NON-UNIQUE KEY DOC_NUM DOC_ITEM.

DATA: ST_PROGLINES LIKE LINE OF TBL_PROGLINES.

----


  • itab for building new result package

----


DATA: TBL_NEW_PACKAGE LIKE RESULT_PACKAGE.

DATA: ST_NEW_PACKAGE LIKE LINE OF TBL_NEW_PACKAGE.

----


  • itab for holding pegging list

----


DATA: TBL_PEGLINES TYPE STANDARD TABLE OF /BIC/AZMM_O01200.

  • WITH NON-UNIQUE KEY DOC_NUM DOC_ITEM.

DATA: ST_PEGLINES LIKE LINE OF TBL_PEGLINES.

----


  • itab for holding items to control to compute other key figures

----


DATA: TBL_ITEMLINES TYPE SORTED TABLE OF /BIC/AZMM_O00100

WITH UNIQUE KEY DOC_NUM DOC_ITEM PROCESSKEY.

DATA: ST_ITEMLINES LIKE LINE OF TBL_ITEMLINES.

----


  • If a program code for the PO line being processed was found

----


DATA: F_FOUND(1) VALUE 'N'.

----


  • New record no. as there may be more or less records being send forward

----


DATA: CTR_RECORD TYPE RSARECORD VALUE 1.

----


  • Ratio of a program based upon Order Quantity

----


DATA: W_PROG_RATIO TYPE N VALUE 0.

DATA: I_RESULT_INDEX LIKE SY-TABIX.

*"----


*"End Declarations

*"

*"BEGIN EXTRACTING PROGRAM LINES FROM THE ENHANCED DSO ZMM_O010

  • NEED ALL THE FIELDS TO CREAT A REVERSAL RECORD

*"----


SELECT *

FROM /BIC/AZMM_O01000

INTO TABLE TBL_PROGLINES

FOR ALL ENTRIES IN RESULT_PACKAGE

WHERE DOC_NUM = RESULT_PACKAGE-DOC_NUM

AND DOC_ITEM = RESULT_PACKAGE-DOC_ITEM.

*"----


*"

*"GET PEGGING LINES.

  • NEED ALL THE FIELDS TO CREAT A NEW RECORD

*"----


SELECT *

FROM /BIC/AZMM_O01200

INTO TABLE TBL_PEGLINES

FOR ALL ENTRIES IN RESULT_PACKAGE

WHERE DOC_NUM = RESULT_PACKAGE-DOC_NUM

AND DOC_ITEM = RESULT_PACKAGE-DOC_ITEM.

SORT TBL_PEGLINES BY DOC_NUM DOC_ITEM /BIC/ZPOASQTY.

*"----


*"

*"GET ITEM LINES TO CONTROL LOOP TO COMPUTE OTHER KEY FIGURES

*"----


SELECT *

FROM /BIC/AZMM_O00100

INTO TABLE TBL_ITEMLINES

FOR ALL ENTRIES IN RESULT_PACKAGE

WHERE DOC_NUM = RESULT_PACKAGE-DOC_NUM

AND DOC_ITEM = RESULT_PACKAGE-DOC_ITEM

AND PROCESSKEY = RESULT_PACKAGE-PROCESSKEY.

*"----


*"End EXTRACTING PEG LINES FROM CONSOLIDATED PEGGING DSO

*"

*"BEGIN CONVERTING ITEM LINES TO MULTIPLE ITEM LINES

  • DEPENDING UPON THE PROGRAM ALLOCATION

*"----


LOOP AT RESULT_PACKAGE INTO ST_RESULT_PACKAGE.

LOOP AT TBL_PEGLINES INTO ST_PEGLINES

WHERE DOC_NUM = ST_RESULT_PACKAGE-DOC_NUM

AND DOC_ITEM = ST_RESULT_PACKAGE-DOC_ITEM.

F_FOUND = 'Y'.

ST_NEW_PACKAGE = ST_RESULT_PACKAGE.

MOVE-CORRESPONDING ST_PEGLINES TO ST_NEW_PACKAGE.

IF ST_RESULT_PACKAGE-ORDER_QUAN GT 0.

ST_NEW_PACKAGE-ORDER_QUAN = ST_PEGLINES-/BIC/ZPOASQTY.

ST_NEW_PACKAGE-NET_PO_VAL = ST_PEGLINES-/BIC/ZPOASQTY *

ST_RESULT_PACKAGE-NETPRICE.

SUBTRACT ST_PEGLINES-/BIC/ZPOASQTY FROM

ST_RESULT_PACKAGE-ORDER_QUAN.

ENDIF.

  • DONE! ADD RECORD TO THE NEW PACKAGE

ST_NEW_PACKAGE-RECORD = CTR_RECORD.

CTR_RECORD = CTR_RECORD + 1.

APPEND ST_NEW_PACKAGE TO TBL_NEW_PACKAGE.

ENDLOOP.

APPEND ST_NEW_PACKAGE TO TBL_NEW_PACKAGE.

ENDIF.

F_FOUND = 'N'.

ENDLOOP.

*"----


*"DELETE EXISTING RESULT PACKAGE AND

  • REPLACE IT WITH THE NEW ONE.

*"----


REFRESH RESULT_PACKAGE.

RESULT_PACKAGE[] = TBL_NEW_PACKAGE[].

REFRESH TBL_PROGLINES.

REFRESH TBL_PEGLINES.

REFRESH TBL_NEW_PACKAGE.