Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

A Simple Assembler & DB2 program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
balimanja

New User


Joined: 14 Aug 2007
Posts: 38
Location: Bangalore

PostPosted: Mon Nov 14, 2011 9:12 pm    Post subject: A Simple Assembler & DB2 program
Reply with quote

Hello everyone,

I have been practicing writing some simple assembler programs that have DB2 queries in them. These are very basic programs. It can be used as a skeletal structure to add on more advanced conditions.

Hope somebody finds it useful.

Code:

000100 PROG0010 CSECT
000200          YREGS
000300          STM   R14,R12,12(R13)
000400          LR    R12,R15
000500          USING PROG0010,R12
000600 *
000700          L     R6,PROGSIZ    <- Memory space needed by the program
000800          A     R6,SQLDSIZ    <- SQL DSECT size
000900          GETMAIN R,LV=(6)
001000 *
001100          LR    R10,R1
001200          LR    R2,R10
001300          LR    R3,R6
001400          SR    R4,R4
001500          SR    R5,R5
001600          MVCL  R2,R4    <- Clearing out the obtained space
001700 *
001800          OPEN  (TESTOUT,OUTPUT)
001900 *
002000          ST    R13,4(R10)
002100          ST    R10,8(R13)
002200          LR    R13,R10
002300          USING PROGAREA,R13
002400 *
002500          LR    R9,R13
002600          A     R9,PROGSIZ
002700          USING SQLDSECT,R9
002800          ST    R6,GETLENTH
002900          B     LOOP1
003000 FD100    DC    A(100)
003100 *
003200 LOOP1    EXEC SQL DECLARE C1 CURSOR FOR                                X
003300                   SELECT * FROM IDCR43.CUSTOMER
003400 *
003500          EXEC SQL OPEN C1
003600 *
003700 FTCHLOOP EQU *
003800          DS    0H
003900          EXEC SQL FETCH C1 INTO                                        X
004000                   :CUST_NO, :F_NAME, :L_NAME,                          X
004100                   :A_DDR,   :C_ITY,  :S_TATE,                          X
004200                   :ZIP_CODE
004300          DS    0H
004400          CLC   SQLCODE,FD100
004500          BE    SQLEND
004600 *
004700          PUT   TESTOUT,DCL_VAR
004800          B     FTCHLOOP
004900 *
005000 SQLEND   DS    0H
005100          EXEC SQL CLOSE C1
005200          CLOSE (TESTOUT)
005300          L     R0,GETLENTH
005400          LR    R1,R13
005500          L     R13,4(R13)
005600          FREEMAIN R,LV=(0),A=(1)
005700          LM    R14,R12,12(R13)
005800          SR    R15,R15
005900          BR    R14
006000          EJECT
006100          LTORG
006200 PROGAREA DSECT
006300 SAVE     DS    18F
006400 GETLENTH DS    F
006500 DCL_VAR  DS    0CL109
006600 CUST_NO  DS    CL6
006700 F_NAME   DS    CL15
006800 L_NAME   DS    CL15
006900 A_DDR    DS    CL40
007000 C_ITY    DS    CL25
007100 S_TATE   DS    CL2
007200 ZIP_CODE DS    CL6
007300          EXEC SQL INCLUDE SQLCA
007400          CNOP  0,4
007500          DS    0D
007600 PROGSIZE EQU   *-PROGAREA
007700 PROG0010 CSECT
007800 PROGSIZ  DC    A(PROGSIZE)
007900 TESTOUT  DCB DSORG=PS,MACRF=PM,LRECL=109,BLKSIZE=1090,DDNAME=TESTOUT,  X
008000                RECFM=FB
008100          END


I have put this program here since I tried many times over the internet to find a simple program to make myself understand how to integrate both Assembler and DB2, but always found advanced programs.

Just a humble contribution to a great forum that has helped all throughout my software development career so far.

Thank you everyone... icon_smile.gif
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Nov 14, 2011 9:45 pm    Post subject: Reply to: A Simple Assembler & DB2 program
Reply with quote

Hello,

Thank you for posting your sample program icon_smile.gif

d
Back to top
View user's profile Send private message
Mohamed Tharwat

New User


Joined: 01 Jul 2014
Posts: 6
Location: Egypt

PostPosted: Wed Jul 09, 2014 4:52 am    Post subject:
Reply with quote

Hi;
I am a new member in this forum and also a beginner in assembly coding, after running the above code with HLASMCLG job it terminated by Return code 12, further more there are any of sql or exec commands can be recognized in compiler step, is there any help to overcome that.
Thanks in advance.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1717
Location: UK

PostPosted: Thu Jul 10, 2014 12:43 am    Post subject: Reply to: A Simple Assembler & DB2 program
Reply with quote

Not sure what you are saying but have you processed the code through the SQL precompiler for Assembler before running it through the assembler itself? The SQL statements have to be converted to assembler first so that the assembler can understand them.
Back to top
View user's profile Send private message
Mohamed Tharwat

New User


Joined: 01 Jul 2014
Posts: 6
Location: Egypt

PostPosted: Thu Jul 10, 2014 4:54 am    Post subject:
Reply with quote

Thanks Nic for your reply and sorry for not to be clarified,
I copied the above code on mainframe after chaning some code as the following :
Code:

//ASSEM     JOB (xyz),'xyz',CLASS=A,                     
//          MSGCLASS=X,REGION=4096K,NOTIFY=&SYSUID                 
//*                                                               
//JOBLIB  DD DSN=XYZ.LIB.LOADLIB,DISP=SHR                       
//JCLLIB  JCLLIB ORDER=(XYZ.LIB.PROC,ASM.SASMSAM1)           
//*                                                               
//IDCAMS    EXEC PGM=IDCAMS                                       
//SYSPRINT  DD SYSOUT=*                                           
//SYSIN     DD *                                                   
  DELETE    ESSNBE.ASSEM3                                         
//*                                                               
//TRYIT    EXEC PROC=HLASMCLG                                     
//*                                                               
//SYSIN DD *                                                       
PROG0010 CSECT                                                     
         YREGS                                                     
         STM   R14,R12,12(R13)                                     
         LR    R12,R15                                             
         USING PROG0010,R12                                       
*                                                                 
         L     R6,PROGSIZ    <- MEMORY SPACE NEEDED BY THE PROGRAM
         A     R6,SQLDSIZ    <- SQL DSECT SIZE                     
         GETMAIN R,LV=(6)                                         
*                                                                 
         LR    R10,R1                                             
         LR    R2,R10                                             
         LR    R3,R6                                               
         SR    R4,R4                                               
         SR    R5,R5                                               
         MVCL  R2,R4    <- CLEARING OUT THE OBTAINED SPACE         
*                                                                 
         OPEN  (TESTOUT,OUTPUT)                                   
*                                                                 
         ST    R13,4(R10)                                         
         ST    R10,8(R13)                                         
         LR    R13,R10                                             
         USING PROGAREA,R13                                       
         LR    R9,R13                                                   
         A     R9,PROGSIZ                                               
         USING SQLDSECT,R9                                             
         ST    R6,GETLENTH                                             
         B     LOOP1                                                   
FD100    DC    A(100)                                                   
*                                                                       
LOOP1    EXEC SQL DECLARE C1 CURSOR FOR                                X
                  SELECT * FROM XYZ.TGEN008                         
                  FETCH FIRST 2 ROW ONLY                               
         EXEC SQL OPEN C1                                               
*                                                                       
         FTCHLOOP EQU *                                                 
         DS    0H                                                       
         EXEC SQL FETCH C1 INTO                                        X
                   :A_DDR                                               
         DS    0H                                                       
         CLC   SQLCODE,FD100                                           
         BE    SQLEND                                                   
*                                                                       
         PUT   TESTOUT,DCL_VAR                                         
         B     FTCHLOOP                                                 
*                                                                       
SQLEND   DS    0H                                                       
         EXEC SQL CLOSE C1                                             
         CLOSE (TESTOUT)                                               
         L     R0,GETLENTH                                             
         LR    R1,R13                                                   
         L     R13,4(R13)                                               
         FREEMAIN R,LV=(0),A=(1)                                       
         LM    R14,R12,12(R13)                                         
         SR    R15,R15                                                 
         BR    R14                                                     
         EJECT                                                         
         LTORG                                                         
PROGAREA DSECT                                                         
SAVE     DS    18F                                                     
SAVE     DS    18F                                                     
GETLENTH DS    F                                                       
DCL_VAR  DS    0CL40                                                   
A_DDR    DS    CL40                                                     
         EXEC SQL INCLUDE SQLCA                                         
         CNOP  0,4                                                     
         DS    0D                                                       
PROGSIZE EQU   *-PROGAREA                                               
PROG0010 CSECT                                                         
PROGSIZ  DC    A(PROGSIZE)                                             
TESTOUT  DCB DSORG=PS,MACRF=PM,LRECL=40,BLKSIZE=1090,DDNAME=TESTOUT,  X
             RECFM=FB                                                   
         END                                                           
//TESTOUT   DD DSN=ESSNBE.ASSEM3,SPACE=(TRK,(1,1),RLSE),               
//          DISP=(NEW,CATLG,DELETE)


After running it i got the following SAMPLE OF ERRORS in SYSPRINT :
** ASMA044E Unwdefined symbol - SQLDSIZ
** ASMA057E Undefined operation code - EXEC
** ASMA044E Undefined symbol - SQLDSECT

If the above is wrong, So what's your advice and how i can correct that.
Thanks again.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1717
Location: UK

PostPosted: Thu Jul 10, 2014 11:49 pm    Post subject: Reply to: A Simple Assembler & DB2 program
Reply with quote

The EXEC SQL code is not assembler language. You have to put your program through the DB2 pre-processor so that it can substitute the SQL code with the relevant assembler code. This modified code is then passed into the assembler.
Back to top
View user's profile Send private message
Mohamed Tharwat

New User


Joined: 01 Jul 2014
Posts: 6
Location: Egypt

PostPosted: Fri Jul 11, 2014 2:47 am    Post subject:
Reply with quote

Is there any suggestion to substitute EXEC SQL by DB2 pre-processor code with example.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Jul 11, 2014 10:14 pm    Post subject: Reply to: A Simple Assembler & DB2 program
Reply with quote

Quote:
Is there any suggestion to substitute EXEC SQL by DB2 pre-processor code with example.
???

the proper suggestion was already given,
a source/program containing EXEC SQL commands should be processed by

1) the appropriate DB2 preprocessor
2) the COBOL integrated preprocessor

FULL STOP
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Jul 11, 2014 10:14 pm    Post subject: Reply to: A Simple Assembler & DB2 program
Reply with quote

deleted, duplicate of the previous post, ( hit back on the browser )
Back to top
View user's profile Send private message
Mohamed Tharwat

New User


Joined: 01 Jul 2014
Posts: 6
Location: Egypt

PostPosted: Sat Jul 12, 2014 7:46 am    Post subject:
Reply with quote

Hi enrico;
At first I want to know why violence in your response, I do not care science in front of respect.
Question marks ??? and Full Stop indicate that you didn't respect others.
I still have questions, but I will not ask or post anything in PL/I & ASSEMBLER again.

Thanks enrico.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sat Jul 12, 2014 9:53 am    Post subject:
Reply with quote

Mohamed Tharwat, your question
Quote:
Is there any suggestion to substitute EXEC SQL by DB2 pre-processor code with example.
indicates that you do not belong on this forum, which is for PROFESSIONAL programmers. There is a Beginner's and Students Forum which would better suit your apparent skill level.

I say this because a professional programmer knows that the purpose of the DB2 preprocessor is to substitute EXEC SQL statements with syntactically valid code in the program language. In other words, you asked about replacing the DB2 preprocessor with a DB2 preprocessor. And no, there is nothing to replace the DB2 preprocessor -- you must use one to convert the EXEC SQL statements.
Back to top
View user's profile Send private message
Mohamed Tharwat

New User


Joined: 01 Jul 2014
Posts: 6
Location: Egypt

PostPosted: Sat Jul 12, 2014 4:59 pm    Post subject:
Reply with quote

Hi Robert ,
The first thing i said in my first post that
Quote:
"I am a new member in this forum and also a beginner in assembly coding"
, that doesn't mean i am Beginner or Student.

I ask the admin of this forum to delete my account.
My apologize for all.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sat Jul 12, 2014 6:17 pm    Post subject:
Reply with quote

Quote:
that doesn't mean i am Beginner or Student.
No, the attitude you have expressed, and the unwillingness to read and accept good valid answers -- these are why I recommended you go to the Beginner's and Students forum. It is expected on this forum that you don't ask the same question repeatedly, as the answer is not going to change. And if you don't like the answer you got, it is expected that you not start personal attacks against the responder(s). These are reasons you do not belong on a forum dedicated to professional programmers.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts I can not compile my program PL1 V3.R... Miguel Fernandez PL/I & Assembler 13 Tue Dec 06, 2016 8:30 pm
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
No new posts A sample of exit program for exit XMN... lind sh CICS 2 Mon Oct 03, 2016 5:07 pm
No new posts Need points to tune IMS Checkpoint Pr... satish.ms10 IMS DB/DC 2 Fri Sep 30, 2016 4:12 pm
No new posts ISPF program to set SCRNAME prino TSO/ISPF 5 Fri Sep 30, 2016 2:18 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us