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

get string from variable within program

former_member212148
Participant
0 Likes
914

Hi Experts,

I want to get string stored in a variable within program

scenerio

data: v_cmd(200) type c.

V_CMD = 'INSERT INTO AFRU1 (AUFNR,BUDAT,ERSDA,LMNGA,SMENG) VALUES (:<DYN_WA>-AUFNR,:<DYN_WA>-BUDAT,:    

                                                                                                     <DYN_WA>-ERSDA,:<DYN_WA>-LMNGA,:<DYN_WA>-SMENG).'.

Now i want to print this value

INSERT INTO AFRU1 (AUFNR,BUDAT,ERSDA,LMNGA,SMENG) VALUES (:<DYN_WA>-AUFNR,:<DYN_WA>-BUDAT,:

                                                                                                     <DYN_WA>-ERSDA,:<DYN_WA>-LMNGA,:<DYN_WA>-SMENG).

purpose.

Execute Native SQL statement.

EXC SQL.

* If i pass here V_CMD.

* I get error.

* so i want to write text in bold.

ENDEXEC.

Please give me solution on urgent basis.

Support is appreciated.

Moderator message: What is urgent for you is not urgent for other members. Please read the forum RoE before posting.

Message was edited by: Suhas Saha

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
873

Hello Ranjit,

AFAIK native SQL construct does not support dynamic tokens. Alternatively you'll have to use ADBC classes to achieve your requirement.

BR,

Suhas

7 REPLIES 7
Read only

Former Member
0 Likes
873

(V_CMD) - this syntax will bring you the value of the string stored inside the variable.

So write your insert statement directly and if you get error

then write statement

Message v_cmd type e.

Hope this helps.

Read only

0 Likes
873

Hello Siddharth,

Syntax comes in V_CMD after concatenate and loop operation.

So I cant pass the insert statement directly within

EXEC SQL

...

..

ENDEXEC.

My code is :

DATA: CONNECTION LIKE DBCON-CON_NAME VALUE 'HEROPAY'.
   DATA : V_CMD(200) TYPE C,
          V_CMD1(200) TYPE C,
          V_CNT(10) TYPE C,
          V_RCNT(10) TYPE C,
          V_EXCCMD(200) TYPE C.

   EXEC SQL.
     CONNECT TO :CONNECTION
   ENDEXEC.
   IF SY-SUBRC = 0.
     EXEC SQL.
       SET CONNECTION :CONNECTION
     ENDEXEC.
     V_RCNT = 1.

     LOOP AT <DYN_TABLE> INTO <DYN_WA>.
       V_CMD = 'INSERT INTO AFRU1 ('.
       V_CMD1 = ' VALUES ('.
       V_CNT = 1.
       LOOP AT IDETAILS INTO XDETAILS.
         IF V_CNT <> 1.
           CONCATENATE V_CMD ',' INTO V_CMD.
           CONCATENATE V_CMD1 ',' INTO V_CMD1.
         ENDIF.
         CONCATENATE V_CMD XDETAILS-NAME INTO V_CMD.
         CONCATENATE V_CMD1  ':<DYN_WA>-' XDETAILS-NAME INTO V_CMD1.
         V_CNT = V_CNT + 1.
       ENDLOOP.
       V_RCNT = V_RCNT + 1.
       CONCATENATE V_CMD ')' V_CMD1 ')' INTO V_CMD." SEPARATED BY SPACE.

       EXEC SQL.

       ENDEXEC.
     ENDLOOP.

       EXEC SQL.
         COMMIT
       ENDEXEC.

       EXEC SQL.
         SET CONNECTION DEFAULT
       ENDEXEC.

       EXEC SQL.
         DISCONNECT :CONNECTION
       ENDEXEC.

     ENDIF.

Read only

Former Member
0 Likes
873

Hi Ranjit,

To Print the text in bold you can use format intensified

FORMAT INTENSIFIED ON.

WRITE <FIELD>.

FORMAT INTENSIFIED OFF.

Read only

0 Likes
873

Hello Chandresh,

I have to put insert statement stored in variable within

EXEC SQL.

........

ENDEXEC.

I have not to print this string.

Thanks for your reply.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
874

Hello Ranjit,

AFAIK native SQL construct does not support dynamic tokens. Alternatively you'll have to use ADBC classes to achieve your requirement.

BR,

Suhas

Read only

0 Likes
873

Hello Suhas,

Could you please explain ADBC class in details, If possible.

As I have posted code above.

Your support is appreciated.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
873

Hello Ranjit,

Please search for the relevant content on SCN. The usage of ADBC is highly documented in the forums.

BR,

Suhas