Application Development and Automation 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: 
Read only

ABAP Function Module for BW

Former Member
0 Likes
453

I have crreated a function module that does a lot of data manipulation and creates 6 tables, I then loop at each of these tables into 1 table. My problem is that it has to go to BW. Having seen a few BW modules I see they have to use open cursor and fetch statements. Is it possible to use open cursor and fetch in a loop? if not is it possible to use these commands on internal tables? Below is the table I need recognized by a data source. Any help would be appreciated it is quite urgent.

TYPES: BEGIN OF ST_OUT,

VTGTYPNR LIKE /MSG/RVTG-VTGTYPNR,

YEAR(1) TYPE N,

BRCHNR LIKE /MSG/RD_ABR_BU-BRCHNR,

QTR(2) TYPE N,

EARNPREM LIKE /MSG/RD_ABR_BU-OW_BETR,

PAIDLOSS LIKE /MSG/RD_ABR_BU-OW_BETR,

OSLR LIKE /MSG/RD_ABR_BU-OW_BETR,

INCUR LIKE /MSG/RD_ABR_BU-OW_BETR,

END OF ST_OUT.

DATA: T_OUT TYPE ST_OUT OCCURS 0,

LOOP AT T_YR_1 INTO WA_T_YR.

MOVE WA_T_YR-VTGTYPNR TO WA_T_OUT-VTGTYPNR.

MOVE '6' TO WA_T_OUT-YEAR.

MOVE WA_T_YR-BRCHNR TO WA_T_OUT-BRCHNR.

MOVE WA_T_YR-QTR TO WA_T_OUT-QTR.

MOVE WA_T_YR-EARNPREM TO WA_T_OUT-EARNPREM.

MOVE WA_T_YR-PAIDLOSS TO WA_T_OUT-PAIDLOSS.

MOVE WA_T_YR-OSLR TO WA_T_OUT-OSLR.

MOVE WA_T_YR-INCUR TO WA_T_OUT-INCUR.

APPEND WA_T_OUT TO T_OUT.

ENDLOOP.

LOOP AT T_YR_2 INTO WA_T_YR.

MOVE WA_T_YR-VTGTYPNR TO WA_T_OUT-VTGTYPNR.

MOVE '5' TO WA_T_OUT-YEAR.

MOVE WA_T_YR-BRCHNR TO WA_T_OUT-BRCHNR.

MOVE WA_T_YR-QTR TO WA_T_OUT-QTR.

MOVE WA_T_YR-EARNPREM TO WA_T_OUT-EARNPREM.

MOVE WA_T_YR-PAIDLOSS TO WA_T_OUT-PAIDLOSS.

MOVE WA_T_YR-OSLR TO WA_T_OUT-OSLR.

MOVE WA_T_YR-INCUR TO WA_T_OUT-INCUR.

APPEND WA_T_OUT TO T_OUT.

ENDLOOP.

LOOP AT T_YR_3 INTO WA_T_YR.

MOVE WA_T_YR-VTGTYPNR TO WA_T_OUT-VTGTYPNR.

MOVE '4' TO WA_T_OUT-YEAR.

MOVE WA_T_YR-BRCHNR TO WA_T_OUT-BRCHNR.

MOVE WA_T_YR-QTR TO WA_T_OUT-QTR.

MOVE WA_T_YR-EARNPREM TO WA_T_OUT-EARNPREM.

MOVE WA_T_YR-PAIDLOSS TO WA_T_OUT-PAIDLOSS.

MOVE WA_T_YR-OSLR TO WA_T_OUT-OSLR.

MOVE WA_T_YR-INCUR TO WA_T_OUT-INCUR.

APPEND WA_T_OUT TO T_OUT.

ENDLOOP.

LOOP AT T_YR_4 INTO WA_T_YR.

MOVE WA_T_YR-VTGTYPNR TO WA_T_OUT-VTGTYPNR.

MOVE '3' TO WA_T_OUT-YEAR.

MOVE WA_T_YR-BRCHNR TO WA_T_OUT-BRCHNR.

MOVE WA_T_YR-QTR TO WA_T_OUT-QTR.

MOVE WA_T_YR-EARNPREM TO WA_T_OUT-EARNPREM.

MOVE WA_T_YR-PAIDLOSS TO WA_T_OUT-PAIDLOSS.

MOVE WA_T_YR-OSLR TO WA_T_OUT-OSLR.

MOVE WA_T_YR-INCUR TO WA_T_OUT-INCUR.

APPEND WA_T_OUT TO T_OUT.

ENDLOOP.

LOOP AT T_YR_5 INTO WA_T_YR.

MOVE WA_T_YR-VTGTYPNR TO WA_T_OUT-VTGTYPNR.

MOVE '2' TO WA_T_OUT-YEAR.

MOVE WA_T_YR-BRCHNR TO WA_T_OUT-BRCHNR.

MOVE WA_T_YR-QTR TO WA_T_OUT-QTR.

MOVE WA_T_YR-EARNPREM TO WA_T_OUT-EARNPREM.

MOVE WA_T_YR-PAIDLOSS TO WA_T_OUT-PAIDLOSS.

MOVE WA_T_YR-OSLR TO WA_T_OUT-OSLR.

MOVE WA_T_YR-INCUR TO WA_T_OUT-INCUR.

APPEND WA_T_OUT TO T_OUT.

ENDLOOP.

LOOP AT T_YR_6 INTO WA_T_YR.

MOVE WA_T_YR-VTGTYPNR TO WA_T_OUT-VTGTYPNR.

MOVE '1' TO WA_T_OUT-YEAR.

MOVE WA_T_YR-BRCHNR TO WA_T_OUT-BRCHNR.

MOVE WA_T_YR-QTR TO WA_T_OUT-QTR.

MOVE WA_T_YR-EARNPREM TO WA_T_OUT-EARNPREM.

MOVE WA_T_YR-PAIDLOSS TO WA_T_OUT-PAIDLOSS.

MOVE WA_T_YR-OSLR TO WA_T_OUT-OSLR.

MOVE WA_T_YR-INCUR TO WA_T_OUT-INCUR.

APPEND WA_T_OUT TO T_OUT.

ENDLOOP.

2 REPLIES 2
Read only

Former Member
0 Likes
403

You cannot use open cursor with internal tables, it works with database tables only. Open cursor , fetch, close cursor statements are used to fetch data from database but in ur case if i am not mistaking, u r creating a final table form 6 diff. tables.So you cannot use Open cursor concept here.

OPEN CURSOR [WITH HOLD] dbcur FOR

SELECT result

FROM source

[[FOR ALL ENTRIES IN itab] WHERE sql_cond]

[GROUP BY group] [HAVING group_cond]

[ORDER BY sort_key].

Addition:

... WITH HOLD

Effect:

This statement opens a database cursor for the selection defined after FOR, and links a cursor variable dbcur with this database cursor. For dbcur, a declared variable with the specific predefined data type cursor must be entered. A database cursor dbcur that has already been opened cannot be opened again. A line of the resulting set is always assigned to an opened database cursor as a cursor position. After the OPEN CURSOR statement, the database cursor is positioned in front of the first line of the resulting set.

After FOR, the syntax of a SELECT statement can be entered, which contains all the additions of the normal SELECT statement, except for INTO and APPENDING. In the addition result, the addition SINGLE can also not be used after SELECT.

Only a limited number of database cursors can be open at the same time. An open database cursor can be closed using the statement CLOSE CURSOR . In addition, an open database cursor is closed for a database commit or a database rollback.

If a cursor variable dbcur of an open database cursor is assigned to another cursor variable, the latter is linked to the same database cursor at the same position. A cursor variable of an open database cursor can also be transferred to procedures that have been called externally, to enable the database cursor to be accessed from there.

Note

It is not recommended to assign cursor variables to each other, but rather to set them exclusively using the statements OPEN CURSOR and CLOSE CURSOR.

Regards,

Joy.

Read only

Former Member
0 Likes
403

Hi Geroge,

i am facing the same problem, can you please share your solution how you have used open cursor to loop through internal table to get the data in bw.

please help me on the same.