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.
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.
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
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.
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.
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
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.
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.
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
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.
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
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.