Application Development 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: 

problem with using Append statement

Former Member
0 Kudos

i am trying to use Append in my following code but it says T_AZFIG isn't defined as a table.

DATA: ...

TYPES: BEGIN OF TY_AZFIG,

DOC_NUM TYPE /BIC/AZFIG_O5100-AC_DOC_NO,

ITEM_NUM TYPE /BIC/AZFIG_O5100-ITEM_NUM,

FISCVARNT TYPE /BIC/AZFIG_O5100-FISCVARNT,

FISCYEAR TYPE /BIC/AZFIG_O5100-FISCYEAR,

COMP_CODE TYPE /BIC/AZFIG_O5100-COMP_CODE,

PROFIT_CTR TYPE /BIC/AZFIG_O5100-PROFIT_CTR,

CO_AREA TYPE /BIC/AZFIG_O5100-CO_AREA,

END OF TY_AZFIG.

DATA: T_AZFIG TYPE TABLE OF TY_AZFIG,

LN_AZFIG LIKE LINE OF T_AZFIG.

LOOP AT DATA_PACKAGE.

SELECT AC_DOC_NO

ITEM_NUM

FISCVARNT

FISCYEAR

COMP_CODE

PROFIT_CTR

CO_AREA

INTO TABLE T_AZFIG

FROM /BIC/AZFIG_O5100

WHERE

AC_DOC_NO = DATA_PACKAGE-AC_DOC_NO AND

ITEM_NUM = DATA_PACKAGE-ITEM_NUM AND

FISCVARNT = DATA_PACKAGE-FISCVARNT AND

FISCYEAR = DATA_PACKAGE-FISCYEAR AND

COMP_CODE = DATA_PACKAGE-COMP_CODE.

APPEND T_AZFIG.

ENDLOOP.

6 REPLIES 6

suresh_datti
Active Contributor
0 Kudos

You don't need to append when using the INTO Table option.

Just comment that statement & you will be fine.

~Suresh

Since your code is inside a loop, you will have only the most recent record when you come out of the loop. In order to append line by line, you will have to use the code suggested by CJ below

Message was edited by:

Suresh Datti

0 Kudos

well I treid that and some fields were not being properly populated. They were empty

0 Kudos

have you tried my logic

LOOP AT DATA_PACKAGE.

SELECT AC_DOC_NO

ITEM_NUM

FISCVARNT

FISCYEAR

COMP_CODE

PROFIT_CTR

CO_AREA

INTO <b>corresponding fields of LN_AZFIG</b>

FROM /BIC/AZFIG_O5100

WHERE

AC_DOC_NO = DATA_PACKAGE-AC_DOC_NO AND

ITEM_NUM = DATA_PACKAGE-ITEM_NUM AND

FISCVARNT = DATA_PACKAGE-FISCVARNT AND

FISCYEAR = DATA_PACKAGE-FISCYEAR AND

COMP_CODE = DATA_PACKAGE-COMP_CODE.

<b>APPEND LN_AZFIG to T_AZFIG.

clear LN_AZFIG.</b>

ENDLOOP.

Former Member
0 Kudos
LOOP AT DATA_PACKAGE.

SELECT AC_DOC_NO
ITEM_NUM
FISCVARNT
FISCYEAR
COMP_CODE
PROFIT_CTR
CO_AREA
INTO corresponding fields of LN_AZFIG
FROM /BIC/AZFIG_O5100
WHERE
AC_DOC_NO = DATA_PACKAGE-AC_DOC_NO AND
ITEM_NUM = DATA_PACKAGE-ITEM_NUM AND
FISCVARNT = DATA_PACKAGE-FISCVARNT AND
FISCYEAR = DATA_PACKAGE-FISCYEAR AND
COMP_CODE = DATA_PACKAGE-COMP_CODE.
APPEND LN_AZFIG to T_AZFIG.
clear LN_AZFIG.
ENDLOOP.

Former Member
0 Kudos

Mick,

Your logic is doing a double APPEND (kinda).

You have a SELECT INTO TABLE T_AZFIG and then an append into that same internal table after the SELECT.

I would suggest removing the APPEND first.

Former Member
0 Kudos

your problem and why you get a sytax error is:

your table t_azfig has no header line. Actually thats good programming style, BUT if you have no header line the syntax for tha append statement has to change.

It would be in your case:

ln_azfig-doc_num = '???'.

...

append ln_azfig to t_azfig.

You could as well go to your data definition and make it like this:

DATA: T_AZFIG TYPE TABLE OF TY_AZFIG with header line.

tho i wouldnt recommend that since header lines are obsolete and just not a good programming style since it confuses programmers not beeing a 100% into the ABAP syntax.

additionally the other dudes are right, you are doing a select into right before the append. so you are trying to ghet 2 times the same record into the database.

Since the Database table has a primary key which has to be unique per definition, this wont work.

Message was edited by:

Florian Kemmer