cancel
Showing results for 
Search instead for 
Did you mean: 

SAPScript: How to write form with TWO internal table?

Former Member
0 Kudos

Dears,

I have met a problem, when i am write form, I want to output two internal table in my code.

The output fields should like

AMOUNT                MARKT            FEE DESCRIP
10                    notebook          discount
                                        unsold
                                        sold
20                    keyboard          discount
                                        unsold
                                        sold

Fields AMOUNT MARKT are in I_TAB_1 , Field FEE DESCRIP are in I_TAB_2.

I_TAB_1, I_TAB_2 have the same fields VBELN, POSNR.

i know I should write form in the loop at I_TAB_1, but how to deal with I_TAB_2?

Thanks a lot.

Sincerely,

Julie

Edited by: Julie Lv on Jun 14, 2009 5:33 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

U can do this in 2 ways...

1.Make a final Internal table with all the required fields which are printing and then print.

2.LOOP the 1st Internal table and READ the 2nd Internal table with VBELN & POSNR, then Print.

Eg:

1st Method:

data : begin of it_final occurs 0,

vbeln TYPE vbeln,

posnr,

AMOUNT,

MARKT,

FEE DESCRIP,

end of it_final.

LOOP AT I_TAB_1.

read table I_TAB_2 with key vbeln = I_TAB_1-vbeln posnr = I_TAB_1-posnr.

IF sy-subrc EQ 0.

it_final-vbeln = I_TAB_1-vbeln.

it_final-posnr = I_TAB_1-posnr.

it_final-amount = I_TAB_1-amount.

it_final-markt = I_TAB_1-markt.

it_final-fee_descrip = I_TAB_2-fee_descrip.

ENDIF.

endloop.

Now, LOOP the final internal & print the rqd fields.

LOOP AT it_final.

call function 'WRITE_FORM'

element = 'FINAL'.

ENDLOOP.

2nd Method:

LOOP AT I_TAB_1.

READ TABLE I_TAB_2 with key vbeln = I_TAB_1-vbeln posnr = I_TAB_1-posnr.

call funtion 'WRITE_FORM'

element = 'FINAL'.

endfunction.

ENDLOOP.

In Script:

/E FINAL

P1 &I_TAB_1-amount&,,&I_TAB_1-markt&,,&I_TAB_2-fee_descrip&

Hope its clear.

Rgds,

Pavan

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Since VBELN and POSNR fields are common in both itab 1 and itab 2 internal table, you can collect both ITAB1 and ITAB2 records into Final internal table.

Then loop only on the final internal table. This will solve your problem..

Regards,

Prashant