数据库增删改查Native SQL

发布时间:2023年12月19日

DBCO:检查数据库是否连接

在这里插入图片描述

代码:

查询:
DATA: gv_dbs TYPE char30 VALUE 'XXXXXXXX'.		"数据库连接名称
DATA:gt_ztclaim_2 TYPE TABLE OF ztclaim_2.
DATA:gs_ztclaim_2 TYPE ztclaim_2.

TRY.
    EXEC SQL.
      CONNECT TO  :GV_DBS
    ENDEXEC.

    EXEC SQL PERFORMING frm_build_ztclaim_2.
      SELECT *
       INTO :gs_ztclaim_2
        from  ztclaim_2
    ENDEXEC.
ENDTRY.

FORM frm_build_ztclaim_2.
  IF gs_ztclaim_2 IS NOT INITIAL.
    APPEND gs_ztclaim_2 TO gt_ztclaim_2.
  ENDIF.
ENDFORM.

删除:
LOOP AT LT_DATA INTO DATA(LS_DATA).
        READ TABLE gt_role INTO DATA(ls_role) WITH KEY personid_ext = ls_data-personid_ext
                                                         BINARY SEARCH.
         IF sy-subrc EQ 0.
            EXEC SQL.
              DELETE from HCM_PA_EMP_ROLE
                     WHERE PERSONID_EXT = :ls_data-personid_ext
            ENDEXEC.
          ENDIF.

ENDLOOP.
增加:
        EXEC SQL.
          INSERT INTO HCM_PA_EMP_ROLE
          (
          PERSONID_EXT,
          PERNR,
          ASSIGN_PART,
          JOB_INDICATOR,
          PLANS,
          ZJSBM,
          ZJSMS,
          APPROVER,
          APPROVER_PLANS )
       VALUES (
          :LS_DATA-PERSONID_EXT,
          :LS_DATA-PERNR:LV_PERNR_NULL,
          :LS_DATA-ASSIGN_PART,
          :LS_DATA-JOB_INDICATOR,
          :LS_DATA-PLANS:LV_PLANS_NULL,
          :LS_DATA-ZJSBM,
          :LS_DATA-ZJSMS,
          :LS_DATA-APPROVER,
          :LS_DATA-APPROVER_PLANS:LV_APPROVER_PLANS_NULL )
        ENDEXEC.
断开连接:
    EXEC SQL.
      ROLLBACK WORK.
      DISCONNECT :gv_dbs
    ENDEXEC.
文章来源:https://blog.csdn.net/weixin_49691117/article/details/135015202
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。