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: 

Set defaul values on a select

Former Member
0 Kudos
694

Hi all

I need do  a sql select where some of the results columns are default values, for example in Oracle i write

SELECT COLUMN1

                "IT IS A DEFAULT VALUE "

   FROM SOME_TABLE

and my resultsets are

| COLUMN1 | IT IS A DEFAULT VALUE |

| value 1        | IT IS A DEFAULT VALUE |

| value 2        | IT IS A DEFAULT VALUE |

How can i do the same thinks in ABAP?

Thanks

1 ACCEPTED SOLUTION

aferngas
Active Participant
0 Kudos
543

Hi Luis,

OpenSQL syntax of ABAP doesn't allow your issue (except if you use EXEC SQL statement but it's not a good practice). You should do on the application layer. Select your data filling a table and then fill the initial values (you can't distinguish between null and blanks values).

This code it will get better performance with this operation (Depending of size of your internal table you'll need an additional secondary index to boost the process of the MODIFY statement).

SELECT field1 field2 field3

  FROM table

  INTO TABLE lt_table.

wa_table-field1 = 'Default'.

MODIFY lt_table FROM wa_table TRANSPORTING field1 WHERE field1 IS INITIAL.

wa_table-field2 = 'Default2'.

MODIFY lt_table FROM wa_table TRANSPORTING field2 WHERE field2 IS INITIAL.

...

Regards,

Alex

4 REPLIES 4

former_member215344
Contributor
0 Kudos
543

Hi Luis,

You can use a SELECT... ENDSELECT to fill a work area like mentioned below:

wa_data-column1 = 'DEFAULT1'.

wa_data-column2 = 'DEFAULT2'.

SELECT single column2 column3 from SOME_TABLE

into corresponding fields of wa_data

WHERE condition.

APPEND wa_data to it_data.

ENDSELECT.

Thanks,

Ajay Bose

rodolformoraes
Explorer
0 Kudos
543

Hi Luis,

Refer to the code below:

EXEC SQL.
  SELECT columnA, 'X'
    INTO :lv_columnA, :lv_default
    FROM table_name
   WHERE columnA = value1.
ENDEXEC.

You will probably need a perform to return this as a internal table, like this:

EXEC SQL PERFORMING fill_internal_table.

SELECT columnA, 'X'

    INTO :gs_internal_table-columnA, :gs_internal_table-default

    FROM table_name

   WHERE columnA = value1.

ENDEXEC.

FORM fill_internal_table .

  APPEND gs_internal_table TO gt_internal_table.

ENDFORM.

Regards,

Rodolfo

aferngas
Active Participant
0 Kudos
544

Hi Luis,

OpenSQL syntax of ABAP doesn't allow your issue (except if you use EXEC SQL statement but it's not a good practice). You should do on the application layer. Select your data filling a table and then fill the initial values (you can't distinguish between null and blanks values).

This code it will get better performance with this operation (Depending of size of your internal table you'll need an additional secondary index to boost the process of the MODIFY statement).

SELECT field1 field2 field3

  FROM table

  INTO TABLE lt_table.

wa_table-field1 = 'Default'.

MODIFY lt_table FROM wa_table TRANSPORTING field1 WHERE field1 IS INITIAL.

wa_table-field2 = 'Default2'.

MODIFY lt_table FROM wa_table TRANSPORTING field2 WHERE field2 IS INITIAL.

...

Regards,

Alex

Former Member
0 Kudos
543

Hi all

Thansk a lot for your help.

Following your opinion I could correct my mistake

Alex, your opinion appear to be the correct one, in fact i follow it.

Again thanks to all