Application Development and Automation 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: 
Read only

How to use INSERT in EXEC SQL ...... ENDEXEC ?

Former Member
0 Likes
4,326

Hi,

The following code;

*************************************************

DATA: BEGIN OF str_insert,

a(3) TYPE c,

b(3) TYPE c,

END OF str_insert.

EXEC SQL.

SET CONNECTION DEFAULT

ENDEXEC.

str_insert-a = 'a'.

str_insert-b = 'b'.

EXEC SQL.

INSERT INTO ZSAP VALUES :str_insert

ENDEXEC.

****************************************************

The Structure of the ZSAP table (There is no data in ZSAP);

A CHAR 3 (Primary Key)

B CHAR 3

I cannot instert a record to this table it throughs the following error;

Runtime Errors DBIF_DSQL2_SQL_ERROR

Exceptn CX_SY_NATIVE_SQL_ERROR

How could use a structure to insert values into ZSAP?

Thanks,

Kishan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,638

Hi ,

Follow this example for referance.

DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,

error_text TYPE string.

TRY.

EXEC SQL.

INSERT INTO scarr

(MANDT, CARRID, CARRNAME, CURRCODE, URL)

VALUES ('000', 'FF', 'Funny Flyers', 'EUR',

'http://www.ff.com');

INSERT INTO scarr

(MANDT, CARRID, CARRNAME, CURRCODE, URL)

VALUES ('000', 'EF', 'Easy Flyers', 'EUR',

'http://www.ef.com');

ENDEXEC.

CATCH cx_sy_native_sql_error INTO exc_ref.

error_text = exc_ref->get_text( ).

MESSAGE error_text TYPE 'I'.

ENDTRY.

Regards,

Ravi

4 REPLIES 4
Read only

Former Member
0 Likes
1,638

Hi All,

The Database is MS SQL 2005

Thanks,

Kishan

Read only

Former Member
0 Likes
1,639

Hi ,

Follow this example for referance.

DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,

error_text TYPE string.

TRY.

EXEC SQL.

INSERT INTO scarr

(MANDT, CARRID, CARRNAME, CURRCODE, URL)

VALUES ('000', 'FF', 'Funny Flyers', 'EUR',

'http://www.ff.com');

INSERT INTO scarr

(MANDT, CARRID, CARRNAME, CURRCODE, URL)

VALUES ('000', 'EF', 'Easy Flyers', 'EUR',

'http://www.ef.com');

ENDEXEC.

CATCH cx_sy_native_sql_error INTO exc_ref.

error_text = exc_ref->get_text( ).

MESSAGE error_text TYPE 'I'.

ENDTRY.

Regards,

Ravi

Read only

0 Likes
1,638

Hi Ravi,

How do I use a Work Area? for INSERT.

Thanks,

Kishan

Read only

0 Likes
1,638

Hello..

loop at T_PC.

loop at T_PCD .

at new NUMREFERENCIA.

exec sql.

INSERT INTO tblPolizaContableR3

(LibroMayor, PeriodoContable, Prefijo, NumReferencia,

Fecha, FuenteDiario, ComentarioPoliza, Moneda,

TipoCambio, RefExternaID1, RefExternaID2, RefExterna1,

RefExterna2, DescRefExterna)

VALUES (:T_PC-LIBROMAYOR, :T_PC-PERIODOCONTABLE,

:T_PC-PREFIJO, :T_PC-NUMREFERENCIA, :T_PC-FECHA,

:T_PC-FUENTEDIARIO, :T_PC-COMENTARIOPLIZA, :T_PC-MONEDA,

:T_PC-TIPOCAMBIO, :T_PC-REFEXTARNAID1, :T_PC-REFEXTERNAID2,

:T_PC-REFEXTERNA1, :T_PC-REFEXTERNA2, :T_PC-DESCREFEXTERNA)

endexec.

endat.

exec sql.

INSERT INTO tblPolizaContableDetR3

(LibroMayor, PeriodoContable, Prefijo, NumReferencia,

Partida, Cuenta, CuentaIMSA, CCostoIMSA,

Cargo, Abono, ComentarioPartida)

VALUES (:T_PCD-LIBROMAYOR, :T_PCD-PERIODOCONTABLE,

:T_PCD-PREFIJO, :T_PCD-NUMREFERENCIA, :T_PCD-PARTIDA,

:T_PCD-CUENTA, :T_PCD-CUENTAIMSA, :T_PCD-CCOSTOIMSA,

:T_PCD-CARGO, :T_PCD-ABONO, :T_PCD-COMENPARTIDA)

endexec.

endloop.

Hope this help you.

Regards, Gustavo Estrada