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

Problem in merging two tables

Former Member
0 Likes
901

Hello Friends,

Can some one please help me with my code merging two tables in to one.

My table one looks like this

Table 1:

it_vbreve

604000036 10 808000618 20090228 54000.00

604000036 20 808000618 20090228 33750.00

Table 2 :

it_bsis2

300101 20090227 604000036 27250

300302 20090227 604000036 1545

300304 20090227 604000036 1236

Expected output.

it_final

604000036 10 808000618 20090228 54000.00 300101 27250

604000036 20 808000618 20090228 33750.00 300302 1545

300304 1236

My code .

LOOP AT it_vbreve.

LOOP AT IT_BSIS2 WHERE AUFNR = IT_vbreve-VBELN.

IF SY-SUBRC = 0.

IT_final-VBELN = IT_vbreve-VBELN. " SO Number

IT_final-posnr = IT_vbreve-POSNR. " Item number

IT_final-vbeln_n = IT_vbreve-VBELN_N. " Delviery Number

IT_final-budat = IT_vbreve-BUDAT. " Posting Period

IT_final-wrbtr = IT_vbreve-WRBTR. " Accrued Income

IT_final-matnr = IT_vbreve-MATNR. " Material Number

IT_final-vkorg = IT_vbreve-VKORG. " Sales Organisation

IT_final-vkbur = IT_vbreve-VKBUR. " Sales Office

IT_final-kunnr = IT_vbreve-KUNNR. " Customer Number

IT_final-name1 = IT_vbreve-NAME1. " Customer Name

IT_final-bezei = IT_vbreve-BEZEI. " Sales Office description

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

ENDIF.

ENDLOOP.

ENDLOOP.

Can some one please correct me ..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
872

Try using this:

LOOP AT it_vbreve.

READ TABLE IT_BSIS2 WITH KET AUFNR = IT_vbreve-VBELN.

IF SY-SUBRC = 0.

IT_final-VBELN = IT_vbreve-VBELN. " SO Number

IT_final-posnr = IT_vbreve-POSNR. " Item number

IT_final-vbeln_n = IT_vbreve-VBELN_N. " Delviery Number

IT_final-budat = IT_vbreve-BUDAT. " Posting Period

IT_final-wrbtr = IT_vbreve-WRBTR. " Accrued Income

IT_final-matnr = IT_vbreve-MATNR. " Material Number

IT_final-vkorg = IT_vbreve-VKORG. " Sales Organisation

IT_final-vkbur = IT_vbreve-VKBUR. " Sales Office

IT_final-kunnr = IT_vbreve-KUNNR. " Customer Number

IT_final-name1 = IT_vbreve-NAME1. " Customer Name

IT_final-bezei = IT_vbreve-BEZEI. " Sales Office description

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

DELETE IT_BSIS2.

ENDIF.

ENDLOOP.

IF NOT IT_BSIS2 IS INITIAL.

LOOP AT IT_BSIS2.

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

CLEAR it_final.

ENDLOOP.

ENDIF.

Hope this helps you..

Edited by: Srinivas Kalluri on Apr 3, 2009 8:51 AM

Hello Friends,

Can some one please help me with my code merging two tables in to one.

My table one looks like this

Table 1:

it_vbreve

604000036 10 808000618 20090228 54000.00

604000036 20 808000618 20090228 33750.00

Table 2 :

it_bsis2

300101 20090227 604000036 27250

300302 20090227 604000036 1545

300304 20090227 604000036 1236

Expected output.

it_final

604000036 10 808000618 20090228 54000.00 300101 27250

604000036 20 808000618 20090228 33750.00 300302 1545

300304 1236

My code .

LOOP AT it_vbreve.

LOOP AT IT_BSIS2 WHERE AUFNR = IT_vbreve-VBELN.

IF SY-SUBRC = 0.

IT_final-VBELN = IT_vbreve-VBELN. " SO Number

IT_final-posnr = IT_vbreve-POSNR. " Item number

IT_final-vbeln_n = IT_vbreve-VBELN_N. " Delviery Number

IT_final-budat = IT_vbreve-BUDAT. " Posting Period

IT_final-wrbtr = IT_vbreve-WRBTR. " Accrued Income

IT_final-matnr = IT_vbreve-MATNR. " Material Number

IT_final-vkorg = IT_vbreve-VKORG. " Sales Organisation

IT_final-vkbur = IT_vbreve-VKBUR. " Sales Office

IT_final-kunnr = IT_vbreve-KUNNR. " Customer Number

IT_final-name1 = IT_vbreve-NAME1. " Customer Name

IT_final-bezei = IT_vbreve-BEZEI. " Sales Office description

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

ENDIF.

ENDLOOP.

ENDLOOP.

Can some one please correct me ..

6 REPLIES 6
Read only

Former Member
0 Likes
873

Try using this:

LOOP AT it_vbreve.

READ TABLE IT_BSIS2 WITH KET AUFNR = IT_vbreve-VBELN.

IF SY-SUBRC = 0.

IT_final-VBELN = IT_vbreve-VBELN. " SO Number

IT_final-posnr = IT_vbreve-POSNR. " Item number

IT_final-vbeln_n = IT_vbreve-VBELN_N. " Delviery Number

IT_final-budat = IT_vbreve-BUDAT. " Posting Period

IT_final-wrbtr = IT_vbreve-WRBTR. " Accrued Income

IT_final-matnr = IT_vbreve-MATNR. " Material Number

IT_final-vkorg = IT_vbreve-VKORG. " Sales Organisation

IT_final-vkbur = IT_vbreve-VKBUR. " Sales Office

IT_final-kunnr = IT_vbreve-KUNNR. " Customer Number

IT_final-name1 = IT_vbreve-NAME1. " Customer Name

IT_final-bezei = IT_vbreve-BEZEI. " Sales Office description

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

DELETE IT_BSIS2.

ENDIF.

ENDLOOP.

IF NOT IT_BSIS2 IS INITIAL.

LOOP AT IT_BSIS2.

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

CLEAR it_final.

ENDLOOP.

ENDIF.

Hope this helps you..

Edited by: Srinivas Kalluri on Apr 3, 2009 8:51 AM

Read only

0 Likes
872

I am getting a ABAP runtime error.

for Delete bsis2.

Read only

0 Likes
872

DELETE TABLE it_bsis2.

or

DELETE it_bsis2 INDEX sy-tabix.

Edited by: Srinivas Kalluri on Apr 3, 2009 9:06 AM

Read only

0 Likes
872

Thanks ..

that has solved my prob.

Thank you for such quick reply..

Read only

0 Likes
872

Final Solution.

LOOP AT IT_vbreve.

READ TABLE IT_bsis2 WITH KEY aufnr = IT_vbreve-vbeln.

IF SY-SUBRC = 0.

IT_final-VBELN = IT_vbreve-VBELN. " SO Number

IT_final-posnr = IT_vbreve-POSNR. " Item number

IT_final-vbeln_n = IT_vbreve-VBELN_N. " Delviery Number

IT_final-budat = IT_vbreve-BUDAT. " Posting Period

IT_final-wrbtr = IT_vbreve-WRBTR. " Accrued Income

IT_final-matnr = IT_vbreve-MATNR. " Material Number

IT_final-vkorg = IT_vbreve-VKORG. " Sales Organisation

IT_final-vkbur = IT_vbreve-VKBUR. " Sales Office

IT_final-kunnr = IT_vbreve-KUNNR. " Customer Number

IT_final-name1 = IT_vbreve-NAME1. " Customer Name

IT_final-bezei = IT_vbreve-BEZEI. " Sales Office description

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

APPEND it_final.

DELETE TABLE it_bsis2.

ENDIF.

ENDLOOP.

IF NOT IT_BSIS2 IS INITIAL.

LOOP AT IT_BSIS2.

it_final-hkont = it_bsis2-hkont. " Expense Head

it_final-wrbtr1 = it_bsis2-wrbtr1. " Actual expense

IT_final-wrbtr = ' ' . " Accrued Income

IT_final-posnr = ' ' . " Item Number

IT_final-matnr = ' ' . " Material Number

APPEND it_final.

CLEAR it_final.

ENDLOOP.

ENDIF.

Read only

Former Member
0 Likes
872

Hello,

Use MODIFY IT_FINAL instead of APPEND IT_FINAL.

And try avoiding the use of loop inside a loop.

TRy using the READ statement inside the LOOP.

Hope that will solve your problem.

Edited by: Richa Wahi on Apr 3, 2009 8:52 AM