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: 

How to pass input value (table field) while updating the Table

Former Member
0 Kudos

Hello,

I had a requirement to update selective Fields for a Table.  I am developing a generic program where Table and fields are input from FORM.

If i directly update the field to table  as below , i never get any error.

                  UPDATE MARC

                  SET    bstmi  = gs_file-bstmi

                  WHERE  matnr  = gs_file-matnr          "Material No

                  AND    werks  = gs_file-werks .             "Plant

But if write code as below , i am getting error,   i have to update on selective fields which selected in the form (User will input the field name)

                  UPDATE MARC

                  SET   &field1& = gs_file-bstmi

                  WHERE  matnr  = gs_file-matnr          "Material No

                  AND    werks  = gs_file-werks .             "Plant

Can anyone suggest how to fix this issue, 

Requirement : need to pass the field name to update command [SET   fieldname =     ] .

Thanks,

BR,

Murali

1 ACCEPTED SOLUTION

former_member195402
Active Contributor
0 Kudos

Hi Murali,

please check the ABAP keyword documentation for

UPDATE dbtab - set_expression

The option (expr_syntax) should solve your issue.

Regards,

Klaus

3 REPLIES 3

former_member195402
Active Contributor
0 Kudos

Hi Murali,

please check the ABAP keyword documentation for

UPDATE dbtab - set_expression

The option (expr_syntax) should solve your issue.

Regards,

Klaus

0 Kudos
  • Consider an example scenario where user will be having two parameters statement,

        one for entering field and other for entering value.

         Parameters: Field type C length 30,

                            Value type C length 30.

       Data: set_expr type string.

        set_expr = field && ` =  value`.

        So write your Update statement like ,


Update MARC SET (set_expr)

WHERE  matnr  = gs_file-matnr           "Material No

                  AND    werks  = gs_file-werks .             "Plant

Regards,

Philip.

raymond_giuseppi
Active Contributor
0 Kudos

As Klaus wrote, you could press F1 on UPDATE statement to read documentation on  SET ( expr_syntax ).

But never update a standard table in production with OPEN-SQL statement (here use BAPI BAPI_MATERIAL_SAVEDATA), you won’t get the change document, losing change traceability and lose some database consistency checks, are you working on a sandbox ?

Regards,

Raymond