cancel
Showing results for 
Search instead for 
Did you mean: 

Creating internal table in ABAP program.

miske
Participant

Hello everyone,
I need some help with creating an internal table. HOW CAN I CREATE INTERNAL TABLE IN MY CODE that I want to populate with data from 2 different tables:

1st column should be TAXCODE (mwsk1 field from VBRP table) and

2nd should contain the TAX (in percentage) for that taxcode. But VBRP does not contain that value. This is the code that Im using to get the tax %.

SELECT kbetr INTO l_procenatPDV10<br>      FROM konp JOIN a003 ON konp~mwsk1 EQ a003~mwskz<br>                JOIN vbrp ON a003~aland EQ vbrp~land1_ana AND a003~mwskz EQ vbrp~mwsk1<br>      WHERE vbrp~vbeln = p_vbeln.<br>    ENDSELECT.<br><br>    l_procenatPDV = l_procenatPDV10 / 10.

(p_vbeln - the document number that I insert at the start of the program)

Since the TAX AMOUNT in KONP is times 10 for some reason (ex. for 20% its 200) I have to divide it by 10.

3rd should contain TAXVALUE (Tax Amount - MWSBP from VBRP table)

4th shoud contain NET VALUE (netwr - from VBRP table)

Example:

I am creating this internal table so I can SUM all of the values with the same tax%. Since I dont have filed with tax% in VBRP I have to get it like this from KONP table. Then I want to create this new table, populate that table like I showded you above, group them by TAX% and SUM the values.

This is probably a simple problem but I am fairly new at abap. I would love it if someone could help me fast.
Thanks in advance.

FredericGirod
Active Contributor

I don't find the question

miske
Participant
0 Kudos

Dear Frederic,
the question is how can I create this internal table? Can someone give me a code sample?
Best regards,
Dame.

FredericGirod
Active Contributor
0 Kudos

if you have an inner join with VBEP why didn't you get the MWSK1 ?

Accepted Solutions (1)

Accepted Solutions (1)

filipn
Active Participant

Hi,

Small hint: I would use GROUP BY and SUM function directly in the SELECT statement.

Regards,

Filip

miske
Participant
0 Kudos

Dear Nespor,

thanks for replying to my question again. Appreciate that. Will consider this hint of yours. Can you read my comment on the answer above that YASIN wrote so I don't repeat myself. Do you have any hints on how to solve the error that I'm getting?
"IT_TAXCODE is not declared as a table, projection view, or database view in ABAP dictionary or does not exist in an active version"
But I did declared it: DATA: it_taxcode TYPE STANDARD TABLE OF ty_taxcode WITH HEADER LINE.
I guess this is some basic problem again but then again I am new in this.

Regards,

Dolla.

filipn
Active Participant

Try adding SUM directly to the SQL statement:

SELECT vbrp-mwsk1, SUM(vbrp-netwr), vbrp-mwsbp FROM vbrp INTO TABLE @it_taxcode GROUP BY vbrp-mwsk1, vbrp-mwsbp

Answers (1)

Answers (1)

Yasin
Active Participant

Hi

TYPES : BEGIN OF tty_i_final,
vbeln TYPE vbrp-vbeln,
fkdat TYPE vbrk-fkdat,
WSBP TYPE VBRP-MWSBP ,
END OF tty_i_final.

DATA : i_final TYPE STANDARD TABLE OF tty_i_final WITH HEADER LINE.

i_final is internal table but you need to declare all fields used by your SQL query.

MWSBP TYPE VBRP-MWSBP is the Tax amount

Kindly reward if was helpful to you.

miske
Participant
0 Kudos

Dear Yasin,

this was usefull, but my problem was mainly how to populate that table. How to get the data from 2 other tables into that one.
I managed to do that. But now I got to the next problem. I tried now to use SELECT statement FROM that it_table that I declared and populated with wanted data but I get the error "IT_TAXCODE is not declared as a table, projection view, or database view in ABAP dictionary or does not exist in an active version"

Here is my full code:

How can I overcome this error? 🙂

P.S. This is just a testing program, I will modify last select statement after I manage to make it work at all.

Best regards,

Dolla.

FredericGirod
Active Contributor
0 Kudos

your system could not do a SELECT on internal table, this is not supported.

You have to do a collect or a manual sum

Yasin
Active Participant
0 Kudos

Hi Dame

Better if you can post your code as code not pic so we can test better on our system.

your internal table definition is not correct you need to mention table-field see my code
vbeln TYPE vbrp-vbeln not TYPE vbeln

You have changed the default field names like you are using netval instead of NETWR.

the bellow query is working fine you can adjust as per your requirements


TYPES : BEGIN OF tty_i_final,
MWSBP TYPE VBRP-MWSBP ,
NETWR TYPE VBRP-NETWR,
END OF tty_i_final.

DATA : i_final TYPE STANDARD TABLE OF tty_i_final WITH HEADER LINE.

SELECT VBRP~MWSBP VBRP~NETWR
INTO CORRESPONDING FIELDS OF TABLE i_final
FROM vbrp.

For getting data from different tables to one you can use JOIN SQL statement or APPEND to your internal table instead of MODFIY

base on your scenario

Please reward if was helpful to you.

Thanks

miske
Participant

I solved my problem inside of a loop.

LOOP AT it_taxcode.

CLEAR it_taxcode1.

CASE it_taxcode-taxcode.
WHEN 'G1'.
it_taxcode1 = '10'.
it_taxcode-taxperc = it_taxcode1.
WHEN 'H1' OR 'H2' OR 'I1' OR 'I3' OR 'J1'.
it_taxcode1 = '20'.
it_taxcode-taxperc = it_taxcode1.
WHEN 'IA' OR 'IB' OR 'F1'.
it_taxcode1 = '0'.
it_taxcode-taxperc = it_taxcode1.
ENDCASE.

MODIFY it_taxcode.

if it_taxcode-taxperc = '10'.
l_netval10 = l_netval10 + it_taxcode-netval.
elseif it_taxcode-taxperc = '20'.
l_netval20 = l_netval20 + it_taxcode-netval.
else. l_netval0 = l_netval0 + it_taxcode-netval.
endif.


ENDLOOP.

This probably isn't the best solution but it works for now. Thanks for your contribution.

Best regards.