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: 

Populating custom table from VBAK

Former Member
0 Kudos

I have a custom table ZTABLE (KUNNR, VBELN, ERDAT, ERZET, FLAG). I need to populate it with values from VBAK for all vbak-lifsk = 'Z7'

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

Hi Megan,

You may need to work with functional folks on output determination and find the appropriate one. You can use requirement (procedure) to call your program.

Anyhow ... please close the thread if your problem solved and reward points for all helpful answers

Regards,

Ferry Lianto

16 REPLIES 16

Former Member
0 Kudos

hi

try this:

  • first define ur internal table. flag has to be populated according to your requirement before inserting in to database table. or u can modify it after the required processes.

select kunnr vbeln erdat erzet

into corresponding fields of table itab

where lifsk = 'Z7'.

if sy-subrc = 0.

insert ztable from table itab.

endif.

**reward if helpful

regards,

madhu

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please try this.


TABLES: VBAK, ZTABLE.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.

DATA: BEGIN OF ITAB OCCURS 0,
        KUNNR LIKE VBAK-KUNNR,
        VBELN LIKE VBAK-VBLEN,
        ERDAT LIKE VBAK-ERDAT
        ERZET LIKE VBAK-ERZET
        FLAG LIKE ZTABLE-FLAG.
DATA: END OF ITAB.

DATA: WA_ITAB LIKE ITAB.

SELECT KUNNR VBELN ERDAT ERZET
INTO TABLE ITAB
FROM VBAK
WHERE VBELN IN S_VEBLN
     AND LIFSK = '27'.

LOOP AT ITAB INTO WA_ITAB.
   WA_ITAB-FLAG = 'X'.
   MODIFY ZTABLE FROM WA_ITAB.
ENDLOOP.

Regards,

Ferry Lianto

Former Member
0 Kudos

I am using my ZTABLE as a storage area itself so why do I need an itab

I was hoping for some syntax like

update ztable

set kunnr = vbak-kunnr,

vbeln = vbak-vbeln .. ..

where vbak-lifsk = 'z7'

but that doesnt work

ferry_lianto
Active Contributor
0 Kudos

Hi,

If you do not use internal table ITAB, how are you gonna collect the data from table VBAK and update ZTABLE?

Regards,

Ferry Lianto

Former Member
0 Kudos

update ztable.

set kunnr = vbak-kunnr,

vbeln = vbak-vbeln,

erdat = vbak-erdat,

erzet = vbak-erzet,

flag = space.

where vbak-lifsk = 'Z7'.

what is wrong with this code?

ferry_lianto
Active Contributor
0 Kudos

Hi,

Nothing wrong with your code if you have a single record that need to be update to ZTABLE.

But if you need to collect all information from VBAK and update the collected data to ZTABLE then you need to use internal table to store collected information.

If you don't want to use ITAB, perhaps you can try this.


DATA: WA_ITAB LIKE ITAB.

SELECT KUNNR VBELN ERDAT ERZET 
INTO (WA_ITAB-KUNNR, WA_ITAB-VBELN, WA_ITAB-ERDAT,WA_ITAB-ERZET)
FROM VBAK
WHERE VBELN IN S_VEBLN
  AND LIFSK = '27'.

UPDATE ZTABLE FROM WA_ITAB.

ENDSELECT.

Regards,

Ferry Lianto

Former Member
0 Kudos

yeah i do need to collect all information and not just one record

Should I just go ahead and use this then. Why are you using Select-Options

TABLES: VBAK, ZTABLE.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.

DATA: BEGIN OF ITAB OCCURS 0,

KUNNR LIKE VBAK-KUNNR,

VBELN LIKE VBAK-VBLEN,

ERDAT LIKE VBAK-ERDAT

ERZET LIKE VBAK-ERZET

FLAG LIKE ZTABLE-FLAG.

DATA: END OF ITAB.

DATA: WA_ITAB LIKE ITAB.

SELECT KUNNR VBELN ERDAT ERZET

INTO TABLE ITAB

FROM VBAK

WHERE VBELN IN S_VEBLN

AND LIFSK = '27'.

LOOP AT ITAB INTO WA_ITAB.

WA_ITAB-FLAG = 'X'.

MODIFY ZTABLE FROM WA_ITAB.

ENDLOOP.

ferry_lianto
Active Contributor
0 Kudos

Hi Megan,

Why are you using Select-Options?

Just for testing purposes. In case you want to test with couple documents before you do mass update.

Regards,

Ferry Lianto

Former Member
0 Kudos

SELECT KUNNR, VBELN, ERDAT, ERZET

INTO TABLE ITAB

FROM VBAK

WHERE VBELN IN S_VEBLN

AND LIFSK = 'Z7'.

What is wrong with this code

It says Comma without preceding colon (after Select ?)

0 Kudos

hi megan,

u should not use comma in between the field name in the select statement.

u have to use like this.

SELECT KUNNR VBELN ERDAT ERZET

INTO TABLE ITAB

FROM VBAK

WHERE VBELN IN S_VEBLN

AND LIFSK = 'Z7'.

Regards...

Arun.

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please remove coma in this line.

SELECT KUNNR, VBELN, ERDAT, ERZET

It should be ...

SELECT KUNNR VBELN ERDAT ERZET

Regards,

Ferry Lianto

Former Member
0 Kudos

SELECT KUNNR VBELN ERDAT ERZET

INTO TABLE ITAB

FROM VBAK

WHERE VBELN IN S_VEBLN

AND LIFSK = 'Z7'.

Error: The IN operator with "S_VEBLN" is followed neither by an internal table

nor by a value list.

ferry_lianto
Active Contributor
0 Kudos

Hi,

You had typo error.

S_VEBLN

it should be ...

S_VBELN

Please cut and paste above my codes ...

Regards,

Ferry Lianto

Former Member
0 Kudos

Thank you Ferry!! My brain is dead today

I shall be awarding points to you all once I get this working in a few mins

Former Member
0 Kudos

Hi Ferry

Your code works fine. The functional dude wants to now include the delivery block condition in the output determination which will call a transaction that will call this program, so I will have to remove the condition. More on that later. But for now, thank you!

Btw, do you know how output determination would work in this case. Basically whenever delivery block gets activated it will trigger a transaction which should populate my custom table from VBAK. I have still to understand how my program fits into this scheme.

ferry_lianto
Active Contributor
0 Kudos

Hi Megan,

You may need to work with functional folks on output determination and find the appropriate one. You can use requirement (procedure) to call your program.

Anyhow ... please close the thread if your problem solved and reward points for all helpful answers

Regards,

Ferry Lianto