cancel
Showing results for 
Search instead for 
Did you mean: 

BW Extract function module

Former Member
0 Kudos

I have a problem - I am trying to create a generic extract function module. The problem is that the template RSAX_BIW_GET_DATA_SIMPLE uses one database select. However for my purpose I need to select from various tables in order to build up my internal table.

It is for PO Service orders so I have to read headers then detailed lines then other tables to get account assignments etc. How do I transfer this to E_T_Data using the required logic for the fetch and open curser etc.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi andrew catchpole,

I hope ,To transfer your required data to E_T_Data using the required logic for the fetch and open curser etc, First of all, You have to populate the data from 'detailed lines' to cursor.

Then in the User exit, by the procedure of enhancement, you have to populate the required extra information like account assignments and data from header.

I am suggesting this procedure, because:

It is difficult to capture all the your required data in a single statement at the time of opening the cursor .So my advice is take main stream of data into consideration at the time of opening cursor.And then findout the values for remaining fields at the time of user exit execution(Enhancement).

With rgds,

Anil Kuamr Sharma .P

Former Member
0 Kudos

Yes this is an option where you have x number of lines and then just wish to add details to those lines, but in my case I need to add extra lines. PO Header, line items, then service line items.

Former Member
0 Kudos

Hi,

I am not able imagine your situation. Why do you want to comibne the records from Header,Item and Schedule Line level tables ?

I hope, you well known about the problem with this.i.e We get blank values for Key figures.

What will be the Key figure for the Datatarget , which gets data from this Data source?

Anyhow the outer join may help you to get the all records from these 3 tables.

With rgds,

Anil Kumar Sharma .P

Former Member
0 Kudos

OK I have written an ABAP report which gets the information I need. This is crude code that I know I can tidy up with joins but I just wanted to make sure I could get the information and that it was correct first.

The code is below. I have two scenarios one for full load and one for delta (which will be the same process but reading the po's that have changed from a bespoke table populated from a user exit EXIT_SAPLRSAP_001

from 2LIS_02_SCL.)

Anyway here it is:-

            • FULL LOAD ************************************

IF FLAG = 'F'.

  • EKKO FIRST READ

SELECT * FROM EKKO

WHERE EBELN IN PO

AND AEDAT IN DDATE

AND BUKRS = 'OPCS'

AND BSTYP = 'F'

AND LOEKZ NE 'X'.

MOVE-CORRESPONDING EKKO TO I_TAB.

APPEND I_TAB.

ENDSELECT.

  • EKPO SECOND READ POULATING i_tab2

LOOP AT I_TAB.

SELECT * FROM EKPO

WHERE EBELN = I_TAB-EBELN

AND PSTYP = '9'

AND EREKZ NE 'X'

AND ELIKZ NE 'X'

AND LOEKZ NE 'X'.

I_TAB2-WAERS = I_TAB-WAERS.

MOVE-CORRESPONDING EKPO TO I_TAB2.

APPEND I_TAB2.

ENDSELECT.

ENDLOOP.

SORT I_TAB2 BY EBELN EBELP.

CLEAR W_PACKNO.

  • POPULATE ITAB_ESLL FINAL TABLE

LOOP AT I_TAB2.

SELECT SINGLE SUB_PACKNO INTO W_PACKNO FROM ESLL

WHERE PACKNO = I_TAB2-PACKNO.

IF SY-SUBRC = 0.

SELECT * FROM ESLL

WHERE PACKNO = W_PACKNO.

ITAB_ESLL-ERDAT = I_TAB2-AEDAT.

ITAB_ESLL-WAERS = I_TAB2-WAERS.

MOVE-CORRESPONDING ESLL TO ITAB_ESLL.

ITAB_ESLL-EBELN = I_TAB2-EBELN.

ITAB_ESLL-EBELP = I_TAB2-EBELP.

  • account assignment

CLEAR W_ZEKKN.

SELECT SINGLE ZEKKN FROM ESKL INTO W_ZEKKN

WHERE PACKNO = W_PACKNO

AND INTROW = ESLL-INTROW.

IF SY-SUBRC = 0.

CLEAR EKKN.

SELECT SINGLE * FROM EKKN

WHERE EBELN = ITAB_ESLL-EBELN

AND EBELP =

ITAB_ESLL-EBELP AND ZEKKN = W_ZEKKN.

ITAB_ESLL-PS_PSP_PNR = EKKN-PS_PSP_PNR.

ITAB_ESLL-SAKTO = EKKN-SAKTO.

ITAB_ESLL-KOSTL = EKKN-KOSTL.

ITAB_ESLL-KOKRS = EKKN-KOKRS.

I_TAB2-SAKTO = EKKN-SAKTO.

I_TAB2-KOSTL = EKKN-KOSTL.

I_TAB2-KOKRS = EKKN-KOKRS.

ENDIF.

MODIFY I_TAB2.

APPEND ITAB_ESLL.

ENDSELECT.

ENDIF.

ENDLOOP.

******************************

  • NOW READ EKBE

LOOP AT I_TAB2.

SELECT * FROM EKBE

WHERE EBELN = I_TAB2-EBELN

AND EBELP = I_TAB2-EBELP

AND ( BEWTP = 'E' OR BEWTP = 'R' OR BEWTP = 'Q' ).

IF SY-SUBRC = 0.

MOVE-CORRESPONDING EKBE TO ITAB_EKBE.

APPEND ITAB_EKBE.

ENDIF.

ENDSELECT.

ENDLOOP.

  • get rid of duplicate lines in ekbe

SORT ITAB_EKBE BY EBELN EBELP BELNR.

DATA: FIRST(1) TYPE C.

FIRST = 'x'.

DATA: D_BELNR LIKE EKBE-BELNR.

LOOP AT ITAB_EKBE.

IF FIRST = 'x'.

D_BELNR = ITAB_EKBE-BELNR.

FIRST = ''.

ELSE.

IF ITAB_EKBE-BELNR = D_BELNR.

DELETE ITAB_EKBE.

ELSE.

D_BELNR = ITAB_EKBE-BELNR.

ENDIF.

ENDIF.

ENDLOOP.

LOOP AT ITAB_EKBE.

CLEAR W_PACKNO1.

SELECT SINGLE * FROM ESSR

WHERE LBLNI = ITAB_EKBE-LFBNR.

W_PACKNO1 = ESSR-PACKNO.

CLEAR W_PACKNO.

IF SY-SUBRC = 0.

SELECT SINGLE SUB_PACKNO FROM ESLL INTO W_PACKNO

WHERE PACKNO = W_PACKNO1.

  • get service line items from esll

SELECT * FROM ESLL

WHERE PACKNO = W_PACKNO.

IF SY-SUBRC = 0.

  • ACCOUNT ASSIGNMENT INSERVICE PACKAGE

*

CLEAR W_ZEKKN.

SELECT SINGLE ZEKKN FROM ESKL INTO W_ZEKKN

WHERE PACKNO = W_PACKNO

AND INTROW = ESLL-INTROW.

IF SY-SUBRC = 0.

CLEAR EKKN.

SELECT SINGLE * FROM EKKN

WHERE EBELN = ITAB_EKBE-EBELN

AND EBELP =

ITAB_EKBE-EBELP AND ZEKKN = W_ZEKKN.

IF SY-SUBRC = 0.

CLEAR ITAB_ESLL.

MOVE-CORRESPONDING ESLL TO ITAB_ESLL.

ITAB_ESLL-EBELN = ITAB_EKBE-EBELN.

ITAB_ESLL-EBELP = ITAB_EKBE-EBELP.

ITAB_ESLL-ZEKKN = W_ZEKKN.

ITAB_ESLL-VGABE = ITAB_EKBE-VGABE.

ITAB_ESLL-BELNR = ITAB_EKBE-BELNR.

ITAB_ESLL-BEWTP = ITAB_EKBE-BEWTP.

ITAB_ESLL-SAKTO = EKKN-SAKTO.

ITAB_ESLL-KOSTL = EKKN-KOSTL.

ITAB_ESLL-KOKRS = EKKN-KOKRS.

ITAB_ESLL-PS_PSP_PNR = EKKN-PS_PSP_PNR.

ENDIF.

ENDIF.

  • CHECK IF CREDIT OR DEBIT AND ADJUST

IF ITAB_EKBE-SHKZG = 'H'.

ESLL-MENGE = ESLL-MENGE * -1.

ESLL-NETWR = ESLL-NETWR * -1.

ENDIF.

ITAB_ESLL-MENGE = ESLL-MENGE.

ITAB_ESLL-NETWR = ESLL-NETWR.

ITAB_ESLL-ERDAT = ESSR-ERDAT.

ITAB_ESLL-WAERS = ESSR-WAERS.

ITAB_ESLL-LOEKZ = ESSR-LOEKZ.

ITAB_ESLL-KZABN = ESSR-KZABN.

ITAB_ESLL-FRGKL = ESSR-FRGKL.

ITAB_ESLL-BUZEI = ITAB_EKBE-BUZEI.

ITAB_ESLL-GJAHR = ITAB_EKBE-GJAHR.

ITAB_ESLL-EBELN = ITAB_EKBE-EBELN.

ITAB_ESLL-EBELP = ITAB_EKBE-EBELP.

APPEND ITAB_ESLL.

ENDIF.

ENDSELECT.

ENDIF.

ENDLOOP.

  • report print out

WRITE:/5 'doc',

20 'PO Line',

30 'date created',

45 'Currency',

55 'deletion Ind',

70 'ACCEPT IND',

85 'Rel Ind',

95 'Line No',

115 'Service',

135 'Quantity',

155 'UOM',

175 'Net Value',

195 'Mat Grp',

215 'G/L Acc',

230 'Cost Centre',

245 'Cont Area',

255 'Acc Ass line',

275 'Trans/Event Type',

295 'Posting Year',

315 'Mat Doc No',

335 'Mat Doc Line no',

355 'bewtp',

375 'WBS'.

SORT ITAB_ESLL BY EBELN EBELP SRVPOS EXTROW.

LOOP AT ITAB_ESLL.

WRITE:/5 ITAB_ESLL-EBELN,

20 ITAB_ESLL-EBELP,

30 ITAB_ESLL-ERDAT,

45 ITAB_ESLL-WAERS,

55 ITAB_ESLL-LOEKZ,

70 ITAB_ESLL-KZABN,

85 ITAB_ESLL-FRGKL,

95 ITAB_ESLL-EXTROW,

115 ITAB_ESLL-SRVPOS,

135 ITAB_ESLL-MENGE,

155 ITAB_ESLL-MEINS,

175 ITAB_ESLL-NETWR,

195 ITAB_ESLL-MATKL,

215 ITAB_ESLL-SAKTO,

230 ITAB_ESLL-KOSTL,

245 ITAB_ESLL-KOKRS,

255 ITAB_ESLL-ZEKKN,

275 ITAB_ESLL-VGABE,

295 ITAB_ESLL-GJAHR,

315 ITAB_ESLL-BELNR,

335 ITAB_ESLL-BUZEI,

355 ITAB_ESLL-BEWTP,

375 ITAB_ESLL-PS_PSP_PNR.

ENDLOOP.

                                                    • DELTA LOAD ****************

ELSE.

IF FLAG = 'D'.

WRITE: /'Test DELTA Part'.

  • SELECT * FROM ZBWSERVICEPOS

  • WHERE DATE_UPDATED IN DDATE.

  • MOVE-CORRESPONDING ZBWSERVICEPOS TO I_TAB-DELTA.

  • APPEND I_TAB-DELTA.

  • ENDSELECT.

*

*LOOP AT I_TAB-DELTA.

  • WRITE:/ I_TAB-DELTA-DATE_UPDATED,

  • I_TAB-DELTA-EBELN, I_TAB-DELTA-EBELP.

*ENDLOOP.

ELSE.

MESSAGE I100.

ENDIF.

ENDIF.

Former Member
0 Kudos

Hi,

It is possible with generic extraction .Here the main table is ESLL . First of all you will get data from this table in FM . Then you will get the remaining information from other tables like EKKN,ESKL,account assignment..in custoemr exit.

  • EKKO FIRST READ

SELECT * FROM EKKO

into corresponding fields of table I_TAB

WHERE EBELN IN PO

AND AEDAT IN DDATE

AND BUKRS = 'OPCS'

AND BSTYP = 'F'

AND LOEKZ NE 'X'.

  • EKPO SECOND READ POULATING i_tab2

SELECT * FROM EKPO

into corresponding fields of table I_TAB2

for all entries in I_TAB

WHERE EBELN = I_TAB-EBELN

AND PSTYP = '9'

AND EREKZ NE 'X'

AND ELIKZ NE 'X'

AND LOEKZ NE 'X'

and ITAB_ESLL-ERDAT = AEDAT

and ITAB_ESLL-WAERS = WAERS.

OPEN CURSOR WITH HOLD S_CURSOR FOR

SELECT * FROM ESLL

for all entries of itab2

where EBELN = itab2-ebeln.

Account assignment and data from EKBE can be findout on the user exit.

It is juast a rough code to show that it is possible with generic extractor.

With rgds,

Anil Kumar Sharma .P

Former Member
0 Kudos

Thanks. I will have a play

Message was edited by: andrew catchpole

Former Member
0 Kudos

Hi thanks the info was good. The only problem I have is that the select for all in itab does not pick up all records. I have proved this by changing the code to a loop again that works. It seems that if on the ESLL read it is picking the same pack number that has already been read (which I will have) it ignores it.

Answers (0)