0

I have the below code which does what I want it to do, however I want to add additional code so that any blank record for fields exit_prnt_layout and exit_web_layout in table hrp5021 is filled in with text STANDARD. I know how to extract data from tables but I'm struggling to understand how to add this functionality. I am very new to abap and help is appreciated.

TABLES: hrp5021.

DATA: hrp5021_wa TYPE hrp5021.

PARAMETERS: objid LIKE hrp5021-objid.

 END-OF-SELECTION.
 SELECT SINGLE * FROM hrp5021 INTO hrp5021_wa
               WHERE plvar = '01'
               AND   otype = 'VA'
               AND   objid   = objid
               AND   istat   = '4'
               AND   exit_prnt_layout = 'STANDARD'.
 IF sy-subrc = 0.
         hrp5021_wa-exit_prnt_layout = 'SMARTFORM'.
  UPDATE hrp5021 FROM hrp5021_wa.
         WRITE:/ 'VA', objid, 'was changed to Smartform'.
ELSE.
         WRITE:/ 'No entry for conversion found'.
ENDIF. 
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
user2916178
  • 15
  • 1
  • 2
  • 5

2 Answers2

3

DISCLAIMER

It is almost never a good idea to update an SAP standard table directly. If you are new to SAP you can remove the "almost" from that statement.

So while I will answer your question I would strongly suggest that you try to find a SAP-approved way to update the necessary fields using BDC, BAPI or a released function module.

The following code will update all entries where exit_prnt_layout is blank:

update hrp5021 set exit_prnt_layout = 'STANDARD'
  where exit_prnt_layout = space.

write:/ sy-dbcnt ' entries updated'.

And the same for exit_web_layout:

update hrp5021 set exit_web_layout = 'STANDARD'
  where exit_web_layout = space.

write:/ sy-dbcnt ' entries updated'.
Jagger
  • 10,350
  • 9
  • 51
  • 93
Esti
  • 3,677
  • 8
  • 35
  • 57
  • @ Esti I totally agree with you in terms of shouldnt be updating sap TABLES directly and i do realize that its not a good idea but thats what was required. Thanks for your response I had applied a similar approach to yours which has worked. But your code would do exactly what i wanted to do as well. **UPDATE hrp5021 SET exit_prnt_layout = 'STANDARD' exit_web_layout = 'STANDARD' WHERE exit_prnt_layout = ' ' OR exit_web_layout = ' '.** – user2916178 Nov 15 '13 at 12:30
0

Please add a "commit work", after a succesfull update so the pending transactions in Your actual LUW get physically committed to the db on the dbms.

icbytes
  • 1,831
  • 1
  • 17
  • 27
  • 1
    Seems like overkill, at most I would commit every 100 updates. – tomdemuyt Nov 14 '13 at 20:24
  • I said via luw. One should know his transactional dependencies. – icbytes Nov 14 '13 at 20:29
  • 2
    As the op said: the code above "works", assuming he means that the existing update from 'STANDARD' to 'SMARTFORM' is successfully executed. There is an implicit database commit at the end of the program. Also see http://help.sap.com/saphelp_nw04s/helpdata/en/41/7af4bca79e11d1950f0000e82de14a/content.htm for more info on LUW's and implicit commits/rollbacks. – Esti Nov 15 '13 at 01:23
  • Ok ok. One up for the link. – icbytes Nov 15 '13 at 08:03