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

Select column with default value

Former Member
0 Likes
5,954

Hi,

I can write query like this i SQL.

SELECT VBELN, '1' AS Flag FROM VBAK WHERE.......

How can i do this in ABAP?

8 REPLIES 8
Read only

adam_krawczyk1
Contributor
0 Likes
2,004

Hi Sathya,

I doubt if there is a syntax that allows to put default value in column from select statement.

Anyhow you can get same results by few ABAP commands, like example below:

DATA ls_vbak type vbak.

DATA lt_vbak type table of vbak.

ls_vbak-vbtyp = '1'.  " Constant defined

SELECT VBELN FROM VBAK INTO TABLE lt_vbak WHERE ...

MODIFY lt_vbak from ls_vbak transporting vbtyp WHERE vbtyp IS INITIAL.

Regards,

Adam

Read only

Former Member
0 Likes
2,004

Hi Satya,

You can write in abap as follows:

SELECT VBELN

     from vbak

into table t_vbak

where vbeln eq '1'.

Regards,

Vineesh.

Read only

jascha_meiswinkel
Product and Topic Expert
Product and Topic Expert
0 Likes
2,004

Hi Sathya,

this is not possible by only using the SELECT statement. This is what you can do:

1) Use the approach mentioned by Adam

2) Define a loop after you executed the SELECT which may look like this:

FIELD-SYMBOL <f_s_yourTable> TYPE <yourTable>.

LOOP AT <yourTable> ASSIGNING <f_s_yourTable>.

     <f_s_yourTable>-yourStaticField = '1'.

ENDLOOP.

This is very fast and therefore should not lead to any performance issues. This is also discussed here: http://scn.sap.com/thread/3229304

BR, Jascha

Read only

Former Member
0 Likes
2,004

Hi Sathya,

You can write the query like that when the case occured as your internal table or work area structure field  is different and your dictionary table field is differnt but with the same data type.

please find the delow example code.

TYPES : BEGIN OF TY_MARA,

              MAT  TYPE MATNR,

             END OF TY_MARA.

DATA : WA_MARA TYPE TY_MARA.

SELECT SINGLE MAT AS MATNR

              FROM MARA

              INTO WA_MARA

             WHERE ...................

Thanks

Mani 

Read only

0 Likes
2,004

Dear Satya,

Do you want to fetch from VBAK where VBELN = 1?

OR
After fectching you want change the value of VBELN to 1?
If yes to 2nd question then you can follow   or .

Hope it helps you.

Please let me know in case of any issues.

Thanks & Regards,

Vignesh Yeram

Read only

Former Member
0 Likes
2,004

Hi Sathya,

I think you are new in SAP ABAP (i think so ) its a basic question any way please refer the below link it explain's how to use the SELECT statement in abap.

http://help.sap.com/erp2005_ehp_04/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm

Please search in scn before posting (Otherwise Moderator will lock the Discussion ).

Regards

Mahesh .

Read only

guilherme_frisoni
Contributor
0 Likes
2,004

Hi Sathya,

you can do this with ABAP Open SQL.

But you can use the following solution:

Keep FLAG column in our IT_VBAK as the last column.

Do your selection normally, without using this flag.

Right after select, update your IT_VBAK.

wa_vbak-flag = '1'.

modify it_vbak from wa_vbak transporting flg

  where flag is initial.

Regards,

Frisoni

Read only

Former Member
0 Likes
2,004

This message was moderated.