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: 

Dynamic operations

former_member583013
Active Contributor
0 Kudos

Hi:

I just this sample code to make dynamic updates:


REPORT  Z_DUMMY_ATG NO STANDARD PAGE HEADING.

DATA: STRING_1 TYPE STRING,
      STRING_2 TYPE STRING.

STRING_1 = 'NAME = ''Alvaro'' LAST_NAME = ''Tejada'''.
STRING_2 = 'SEQUENCE = 1'.

UPDATE ZDUMMY_TABLE
SET (STRING_1)
WHERE (STRING_2).

IF SY-SUBRC EQ 0.
WRITE:/ 'Ok!'.
ELSE.
WRITE:/ 'Error!'.
ENDIF.

It works fine on my SAP 5....But in my MiniSap 4.6D it doesn't work....Any way i can achieve this? I want to make it a reusable as possible.

Greetings,

Blag.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Alvaro,

The first think to do is to find out what ABAP´S version you are using, because if it is before release 6.10 you will not be able to do dynamic select, update...

On your code it seems to be correct, but as I say you can do it if you have an old ABAP release. But you can try with the following example:

Lo primero que hay que hacer es encontrar qué versión de ABAP esta usando, ya que antes la version 6.10 no se pueden hacer updates, selects...dinámicos, si esta intentándolo hacer en una versión anterior no podrá hacerlo, y al parecer según veo su código esa es la manera correcta de hacerlo dinámicamente pero tiene que ver la versión, sin embargo el siguiente es un ejemplo:

PARAMETERS: table TYPE c LENGTH 30,

column TYPE c LENGTH 30,

old_curr TYPE sycurr.

DATA: set_expr TYPE string,

condition TYPE string.

CONCATENATE column ` = 'EUR'`

INTO set_expr.

CONCATENATE column ` = old_curr`

INTO condition.

TRY.

UPDATE (table)

SET (set_expr)

WHERE (condition).

CATCH cx_sy_dynamic_osql_error.

MESSAGE `Error in update!` TYPE 'I'.

ENDTRY.

Hope this helps!!!Dont forget to reward

Gabriel P

7 REPLIES 7

Former Member
0 Kudos

pls check this...

the table ZDUMMY_TABLE has an entry with sequence=1 in the Minisap system ?

Thanks,

Renjith

0 Kudos

Hehehe...Of course it has that entry...What i was trying to say is that it doesn't compile on MiniSap....It got an error telling me something like this...


After (STRING_1) you should use = or , or =,....

So i just can run it...But on SAP 5 i have succefully update the table.

Greetings,

Blag.

Former Member
0 Kudos

Hi Alvaro,

This what i found on that subject:

Alternative 2

... (dbtab_syntax)

Effect:

Instead of static specification, a bracketed data object dbtab_syntax can be specified, which must contain the name of the database table or the view when the statement is executed. A character-type data object can be specified for the data object dbtab_syntax. The syntax in dbtab_syntax, as in the AAP Editor, is not case-sensitive.

Note:

Before release 6.10, it was only possible to specify a flat character-type data object for dbtab_syntax, which had to contain the name of the database table or the view in capital letters.

I think you can do it as it is explained above.

Check abap doc.

Hope this helps!!

Gabriel!!!

0 Kudos

Hi Gabriel:

Can you please give me some example? My english it not actually pretty good. And also...The help on that topic it's not very usefull.

Greetings,

Blag.

Message was edited by: Alvaro Tejada Galindo

Former Member
0 Kudos

Alvaro,

The first think to do is to find out what ABAP´S version you are using, because if it is before release 6.10 you will not be able to do dynamic select, update...

On your code it seems to be correct, but as I say you can do it if you have an old ABAP release. But you can try with the following example:

Lo primero que hay que hacer es encontrar qué versión de ABAP esta usando, ya que antes la version 6.10 no se pueden hacer updates, selects...dinámicos, si esta intentándolo hacer en una versión anterior no podrá hacerlo, y al parecer según veo su código esa es la manera correcta de hacerlo dinámicamente pero tiene que ver la versión, sin embargo el siguiente es un ejemplo:

PARAMETERS: table TYPE c LENGTH 30,

column TYPE c LENGTH 30,

old_curr TYPE sycurr.

DATA: set_expr TYPE string,

condition TYPE string.

CONCATENATE column ` = 'EUR'`

INTO set_expr.

CONCATENATE column ` = old_curr`

INTO condition.

TRY.

UPDATE (table)

SET (set_expr)

WHERE (condition).

CATCH cx_sy_dynamic_osql_error.

MESSAGE `Error in update!` TYPE 'I'.

ENDTRY.

Hope this helps!!!Dont forget to reward

Gabriel P

0 Kudos

Now i get...hehehe...Sometimes i'm a little bit silly. Anyway, you right...it doesn't work on my MiniSap 4.6D...and it may never work...That's a shame...Anyway...it must continue working on my SAP 5.

Thanx a lot Gabriel, full points awarded.

Greetings,

Blag.

Former Member
0 Kudos

Hello Alvaro,

according to "ABAP Reference" by Horst Keller, dynamic expressions in the UPDATE statement are available for Release 610 and higher, but not in your 46D system.

On a 46D system you have to write your program like this:

REPORT Z_DUMMY_ATG NO STANDARD PAGE HEADING.

UPDATE ZDUMMY_TABLE

SET NAME = 'Alvaro' LAST_NAME = 'Tejada'

WHERE SEQUENCE = 1.

IF SY-SUBRC EQ 0.

WRITE:/ 'Ok!'.

ELSE.

WRITE:/ 'Error!'.

ENDIF.

Regards,

Michael