external stored procedure db2 on cobol - stored-procedures
I would ask about calling external stored procedure on cobol z/os
This is my code , the stored procedure code
*----------------------------------------------------------------*
IDENTIFICATION DIVISION.
*----------------------------------------------------------------*
PROGRAM-ID. SPROC02.
AUTHOR. AESANJA.
DATE-WRITTEN. 19 OKT 2017.
DATE-COMPILED.
DATA DIVISION.
WORKING-STORAGE SECTION.
*************************************************************
*INCLUDE SQLCA ITU SQL COMMUNICATION AREA *
*SETIAP SELESAI MENJALANKAN SQL STATEMENT DAN SELESAI *
*NILAI AKAN BERUBAH *
*************************************************************
EXEC SQL
INCLUDE SQLCA
END-EXEC.
*************************************************************
*INCLUDE DCLGEN NYA YANG DIGUNAKAN UNTUK AKSES DATABASE *
*MEMUNGKIKAN PROGRAM MELIHAT STRUKTUR TABLE DARI DATABASE *
*************************************************************
EXEC SQL
INCLUDE DAAVACDC
END-EXEC.
************************************************************
01 SP-SQLCODE PIC 9(9).
01 SP-SQLSTATE PIC 9(9).
LINKAGE SECTION.
01 BRANCH PIC X(07).
01 ACCTNO PIC X(11).
01 AVAILABLE PIC X(01).
01 ADDTS PIC X(26).
01 ADDUSER PIC X(08).
01 ADDPROGRAM PIC X(08).
01 UPDTS PIC X(26).
01 UPDUSER PIC X(08).
01 UPDPROGRAM PIC X(08).
01 OUTCODE PIC S9(09) USAGE BINARY.
PROCEDURE DIVISION USING BRANCH ,
ACCTNO ,
AVAILABLE ,
ADDTS ,
ADDUSER ,
ADDPROGRAM,
UPDTS ,
UPDUSER ,
UPDPROGRAM,
OUTCODE.
MAIN-PROC.
EXEC SQL
SELECT *
INTO :BRANCH ,
:ACCTNO ,
:AVAILABLE ,
:ADDTS ,
:ADDUSER ,
:ADDPROGRAM,
:UPDTS ,
:UPDUSER ,
:UPDPROGRAM
FROM DAVACV0
WHERE AVAC_BRANCH = :BRANCH
AND AVAC_ACCT_NO = :ACCTNO
END-EXEC.
MOVE SQLCODE TO OUTCODE.
MAIN-PROC-RETURN.
GOBACK.
Then this is my JCL to precompile,compile,linked,and bind the stored procedure
//SPROCJCL JOB (999),CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),NOTIFY=&SYSUID, JOB09854
// REGION=4M
//JOBLIB DD DSN=DB2DEV.DSNUAT2.SDSNEXIT,DISP=SHR
// DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//*--------------------------------------------------------------------*
//STEP01 EXEC DSN2HCOB,MEM=TEMPNAME,USER='CISUSER',
// PARM.PC='HOST(IBMCOB),APOST,APOSTSQL,SOURCE,XREF',
// PARM.COB=('OBJECT,APOST,MAP,XREF,NONUM,OFF,FLAG(I,E),TRUNC(BIN)', X
// 'RENT,RES,LIB,NODYNAM'),
// PARM.LKED='RENT,REUS,LIST,XREF,LET,AMODE=31'
//*PLACE THE DCLGEN DSN
//PC.SYSLIB DD DSN=LCM.MNI.BCA.P.COPY,DISP=SHR
//*PLACE LOAD DBRMLIB
//PC.DBRMLIB DD DSN=IBS.BCA.DEV.DBRMLIB(SPROC02),DISP=SHR
//*PLACE THE SOURCE CODE OF STORED PROCEDURE
//PC.SYSIN DD DSN=AESANJA.LEARN.DB2(SPROC02),DISP=SHR
//*--------------------------------------------------------------------*
//*COPY BOOK OF THE DATA
//COB.SYSLIB DD DSN=LCM.MNI.BCA.P.COPY,DISP=SHR
//*--------------------------------------------------------------------*
//LKED.SYSLIB DD DSN=SYS1.CEE.SCEELKED,DISP=SHR
// DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//LKED.SYSLMOD DD DSN=AESANJA.LEARN.LOAD(SPROC02),DISP=SHR
//LKED.SYSIN DD *
INCLUDE SYSLIB(DSNALI)
MODE AMODE(31) RMODE(ANY)
//*--------------------------------------------------------------------*
//SQLBIND PROC
//BIND EXEC PGM=IKJEFT01,DYNAMNBR=20
//DBRMLIB DD DSN=IBS.BCA.DEV.DBRMLIB,DISP=SHR
//STEPLIB DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD DUMMY
//SYSTSIN DD DDNAME=SYSTSIN
// PEND
//STEP2 EXEC SQLBIND
//****************************************************************
//* UBAH XXXXXXXX MENJADI NAMA PROGRAM
//****************************************************************
//BIND.SYSTSIN DD *
DSN SYSTEM(DSN1)
BIND PACKAGE(DPB_COLLID) -
MEMBER(SPROC02) -
ACT(REP) ISO(UR) ENCODING(EBCDIC) -
OWNER(CISUSER)
END
DSN SYSTEM(DSN1)
BIND PLAN(SPROC02) -
OWNER(CISUSER) -
PKLIST(DPB_COLLID.SPROC02) -
RETAIN -
DYNAMICRULES(BIND) -
VALIDATE(BIND) -
ISOLATION(CS) -
ACQUIRE(USE) -
RELEASE(COMMIT) -
EXPLAIN(YES)
END
And then this my JCL for define the stored procedure in system table
//CREASTPR JOB ,,CLASS=A,MSGCLASS=X,MSGLEVEL=(1,1),TIME=1440, JOB15600
// NOTIFY=&SYSUID,REGION=4M
//**********************************************************************
//* CREATE STORED PROCEDURE *
//**********************************************************************
//JOBLIB DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
// DD DSN=AESANJA.LEARN.LOAD,DISP=SHR
//STEP1 EXEC PGM=IKJEFT01,DYNAMNBR=20
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DSN1)
RUN PROGRAM(DSNTIAD) PLAN(DSNTIAD) -
LIB('DSNBCA.RUNLIB.LOAD')
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
SET CURRENT SQLID='CISUSER';
CREATE PROCEDURE CISUSER.SP02KE02
(INOUT BRANCH DECIMAL(7) ,
INOUT ACCTNO DECIMAL(11),
OUT AVAILABLE CHAR(1) ,
OUT ADDTS TIMESTAMP ,
OUT ADDUSER CHAR(8) ,
OUT ADDPROGRAM CHAR(8) ,
OUT UPDTS TIMESTAMP ,
OUT UPDUSER CHAR(8) ,
OUT UPDPROGRAM CHAR(8) ,
OUT OUTCODE INTEGER )
LANGUAGE COBOL
DETERMINISTIC
READS SQL DATA
EXTERNAL NAME 'SPROC02'
COLLID DPB_COLLID
ASUTIME NO LIMIT
PARAMETER STYLE GENERAL
STAY RESIDENT NO
RUN OPTIONS 'MSGFILE(OUTFILE),RPTSTG(ON),RPTOPTS(ON)'
WLM ENVIRONMENT ENV1DB2
PROGRAM TYPE MAIN
SECURITY DB2
RESULT SETS 2
COMMIT ON RETURN YES;
after that,this is my main program code thaht will be call a stored procedure
*----------------------------------------------------------------*
IDENTIFICATION DIVISION.
*----------------------------------------------------------------*
PROGRAM-ID. COBA12.
AUTHOR. AESANJA.
DATE-WRITTEN. 19 OKT 2017.
DATE-COMPILED.
DATA DIVISION.
WORKING-STORAGE SECTION.
*************************************************************
*INCLUDE SQLCA ITU SQL COMMUNICATION AREA *
*SETIAP SELESAI MENJALANKAN SQL STATEMENT DAN SELESAI *
*NILAI AKAN BERUBAH *
*************************************************************
EXEC SQL
INCLUDE SQLCA
END-EXEC.
*************************************************************
*INCLUDE DCLGEN NYA YANG DIGUNAKAN UNTUK AKSES DATABASE *
*MEMUNGKIKAN PROGRAM MELIHAT STRUKTUR TABLE DARI DATABASE *
*************************************************************
EXEC SQL
INCLUDE DAAVACDC
END-EXEC.
77 SQLRETCODE PIC 9(9).
01 WS-SQL-STORAGE.
05 AVAC-BRANCH-NO PIC X(7).
05 SQL-STATEMENT.
49 SQL-STATEMENT-LEN PIC S9(4) COMP VALUE +320.
49 SQL-STATEMENT-TEXT PIC X(320).
01 BRANCH PIC X(07).
01 ACCTNO PIC X(11).
01 AVAILABLE PIC X(01).
01 ADDTS PIC X(26).
01 ADDUSER PIC X(08).
01 ADDPROGRAM PIC X(08).
01 UPDTS PIC X(26).
01 UPDUSER PIC X(08).
01 UPDPROGRAM PIC X(08).
01 OUTCODE PIC S9(9) USAGE COMP.
PROCEDURE DIVISION.
MAIN-PROC.
MOVE 1 TO BRANCH.
MOVE 3913 TO ACCTNO.
EXEC SQL CALL CISUSER.SP02KE04(:BRANCH ,
:ACCTNO ,
:AVAILABLE ,
:ADDTS ,
:ADDUSER ,
:ADDPROGRAM,
:UPDTS ,
:UPDUSER ,
:UPDPROGRAM,
:OUTCODE )
END-EXEC.
DISPLAY "SP-DA-AVAC-BRANCH " BRANCH.
DISPLAY "SP-DA-AVAC-ACCT-NO " ACCTNO.
DISPLAY "SP-DA-AVAC-AVAILABLE " AVAILABLE.
DISPLAY "SP-DA-AVAC-ADD-TS " ADDTS.
DISPLAY "SP-DA-AVAC-ADD-USER " ADDUSER.
DISPLAY "SP-DA-AVAC-ADD-PROGRAM " ADDPROGRAM.
DISPLAY "SP-DA-AVAC-UPD-TS " UPDTS.
DISPLAY "SP-DA-AVAC-UPD-USER " UPDUSER.
DISPLAY "OUT-CODE " OUTCODE.
STOP RUN.
After I precompile,compile,link my program using this
//EXECUTE JOB (123),CLASS=A,MSGCLASS=A,NOTIFY=&SYSUID,MSGLEVEL=(1,1)
//*
//* -------------------------------------------------------------------
//* --- Cobol Compile - Batch or CICS ---
//* -------------------------------------------------------------------
//*
//* ---------------------------------------------------------- *//
//* SCAN CODE FOR CICS, DB2 OR DLI ..... *//
//* ---------------------------------------------------------- *//
//*
//DB2SCAN EXEC PGM=IRXJCL,COND=(4,LT),
// PARM='PSSRCSCN COBA12'
//*
//SYSTSPRT DD SYSOUT=*
//SYSEXEC DD DISP=SHR,DSN=CCCLCM.V600.BCA.CLIST
//SYSTSIN DD SYSOUT=*
//CBLSRC DD DSN=AESANJA.LEARN.DB2(COBA12),DISP=SHR
//CBLSRCO DD DISP=(,PASS),DSN=&&SRCFULL,
// SPACE=(CYL,(10,10),RLSE),
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=0)
//DB2OPTS DD *
CBL SQL("HOST(IBMCOB),APOST,APOSTSQL")
CBL SQL("DATE(ISO),TIME(ISO),LEVEL(DB2CIS)")
/*
//FILEOT DD DISP=(,PASS),DSN=&&TMPLNK,
// SPACE=(TRK,(15,15)),UNIT=SYSDA,
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=3120)
//*
//* ---------------------------------------------------------- *//
//* COBOL COMPILE *//
//* *//
//* ---------------------------------------------------------- *//
//COMPILE EXEC PGM=IGYCRCTL,REGION=0M,
// PARM=('DATA(31)','FLAG(I,E)',APOST,MAP,LIST,
// 'SIZE(24000K)',NOADV)
//STEPLIB DD DSN=ECOB.V4R2M0.SIGYCOMP,DISP=SHR
// DD DSN=DB2DEV.DSNUAT2.SDSNEXIT,DISP=SHR
// DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
// DD DSN=CICSTS53.CICS.SDFHLOAD,DISP=SHR
// DD DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//SYSIN DD DATA
/*
// DD DSN=&&SRCFULL,DISP=(OLD,DELETE,DELETE)
//*
//SYSLIB DD DISP=SHR,DSN=LCM.DEFAULT.EMPTY.COPYLIB
// DD DISP=SHR,DSN=LCM.MNI.BCA.P.COPY
// DD DISP=SHR,DSN=LCM.DEFAULT.EMPTY.COPYLIB
// DD DISP=SHR,DSN=LCM.MNI.BCA.P.ONLCOPY
// DD DSN=WMQ.V701.TLIB.SCSQCOBC,DISP=SHR
// DD DISP=SHR,DSN=LCM.GGLM.GL312.P.COPY
// DD DISP=SHR,DSN=LCM.GGLM.P.COPY
// DD DISP=SHR,DSN=LCM.ATM.CMS.P.COPY
// DD DISP=SHR,DSN=LCM.ATM.L24.P.COPY
// DD DISP=SHR,DSN=ATMD.CARD.SOURCE
// DD DISP=SHR,DSN=ATMD.MNI.SOURCE
// DD DISP=SHR,DSN=EBSD.BCA.PROD.COPY
// DD DISP=SHR,DSN=EBSD.BCA.PROD.ONLCOPY
// DD DISP=SHR,DSN=IBS.UND.PROD.COPY
// DD DISP=SHR,DSN=LCM.KUX.P.COPY
// DD DISP=SHR,DSN=LCM.KUX.P.ONLCOPY
//* DD DISP=SHR,DSN=CARDD.LA10.COPYLIB.CX2091
//* REQUEST BY SGT 15 MAY 2015
// DD DISP=SHR,DSN=LCM.CARD.P.SCPYB
// DD DISP=SHR,DSN=LCM.CARD.P.SCPYC
//* STLH CUT OFF CRD 11 JUL '13
//* LHM MEN+KAN DD DISP=SHR,DSN=LCM.CARD.P.SCPYC 07 OCT 2013
//DBRMLIB DD DISP=SHR,DSN=IBS.BCA.DEV.DBRMLIB(COBA12)
//SYSLIN DD DISP=(,PASS),DSN=&&TMPOBJ,
// UNIT=3390,SPACE=(TRK,(25,25)),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=3120)
//SYSPRINT DD SYSOUT=*
//*
//SYSUT1 DD UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT2 DD UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT3 DD UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT4 DD UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT5 DD UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT6 DD UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT7 DD UNIT=3390,SPACE=(CYL,(15,5))
//*
//*-------------------------------------------------------------------*
//* LINKEDIT *
//*-------------------------------------------------------------------*
//LINK IF COMPILE.RC LE 4 THEN
//LINKEDIT EXEC PGM=HEWL,
// PARM=(LIST,XREF,LET,'AC=0','SIZE=(512K,100K)',
// 'AMODE(31)','RMODE(ANY)',CALL)
//SYSUT1 DD UNIT=3390,SPACE=(TRK,(15,5))
//SYSLMOD DD DSN=AESANJA.LEARN.LOAD(COBA12),DISP=SHR
//* SYSLIB DD DISP=(SHR,PASS),DSN=&&TMPOBJ
//SYSLIB DD DISP=SHR,DSN=AESANJA.LEARN.LOAD
// DD DSN=LCM.MNI.BCA.P.LOAD,DISP=SHR
// DD DSN=FISD.MILL30.LOAD,DISP=SHR
// DD DSN=FISD.MILL30.GL312.LOAD,DISP=SHR
// DD DSN=ATMD.BASE24.L24R512.PROD.CICSLOAD,DISP=SHR
//* DD DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
// DD DSN=IMS.OTX.SDFSRESL,DISP=SHR
// DD DISP=SHR,DSN=SYS1.CEE.SCEELKED
// DD DISP=SHR,DSN=DB2DEV.SDSNLOAD
// DD DISP=SHR,DSN=SYS1.LINKLIB
//CSQSTUB DD DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//CSQSTUB DD DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//TSTLIB DD DSN=AESANJA.LEARN.LOAD,DISP=SHR
//SYSPRINT DD SYSOUT=*
//OBJECT DD DISP=(SHR,PASS),DSN=&&TMPOBJ
//SYSLIN DD DISP=(SHR,PASS),DSN=&&TMPLNK
// DD *
/*
//LINK ENDIF
//*
//*
Finnaly I bind my program
//BIND JOB REGION=4M,NOTIFY=&SYSUID,MSGLEVEL=(1,1) JOB15655
//SQLBIND PROC
//BIND EXEC PGM=IKJEFT01,DYNAMNBR=20
//DBRMLIB DD DSN=IBS.BCA.DEV.DBRMLIB,DISP=SHR
//STEPLIB DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD DUMMY
//SYSTSIN DD DDNAME=SYSTSIN
// PEND
//STEP2 EXEC SQLBIND
//****************************************************************
//* UBAH XXXXXXXX MENJADI NAMA PROGRAM
//****************************************************************
//BIND.SYSTSIN DD *
DSN SYSTEM(DSN1)
BIND PACKAGE(DPB_COLLID) -
OWNER(CISUSER) -
MEMBER(COBA12) -
DYNAMICRULES(BIND) -
VALIDATE(BIND) -
ISOLATION(CS) -
RELEASE(COMMIT) -
EXPLAIN(YES)
END
DSN SYSTEM(DSN1)
BIND PLAN(COBA13) -
OWNER(CISUSER) -
PKLIST(DPB_COLLID.COBA12) -
RETAIN -
DYNAMICRULES(BIND) -
VALIDATE(BIND) -
ISOLATION(CS) -
ACQUIRE(USE) -
RELEASE(COMMIT) -
EXPLAIN(YES)
END
/*
And then i run my program
using this
//DB200001 JOB CLASS=A,MSGCLASS=A,NOTIFY=&SYSUID,MSGLEVEL=(1,1), JOB22858
// REGION=4M,TIME=1440
//*-----------------------------------------------------------
//CICCODE2 EXEC PGM=IKJEFT01
//STEPLIB DD DSN=AESANJA.LEARN.LOAD,DISP=SHR
// DD DSN=LCM.MNI.BCA.P.DB2LOAD,DISP=SHR
// DD DSN=LCM.MNI.BCA.P.LOAD,DISP=SHR
// DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=A
//SYSUDUMP DD SYSOUT=A
//SYSABOUT DD SYSOUT=*
//SYSDBOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSERROR DD SYSOUT=*
//SYSOUT DD SYSOUT=A
//SYSOUD DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DSN1) RETRY(0) TEST(0)
RUN PROGRAM(COBA12) PLAN(COBA12) -
LIB('AESANJA.LEARN.LOAD')
everything gone fine, i got the return code 4 for compiling and got 0 return code on the other job
and then the display from the coba12 program didnot display the other data that i want to get
********************************* TOP OF DATA *************************************************************************************
SP-DA-AVAC-BRANCH 1
SP-DA-AVAC-ACCT-NO 3913
SP-DA-AVAC-AVAILABLE
SP-DA-AVAC-ADD-TS
SP-DA-AVAC-ADD-USER
SP-DA-AVAC-ADD-PROGRAM
SP-DA-AVAC-UPD-TS
SP-DA-AVAC-UPD-USER
OUT-CODE 000000000
******************************** BOTTOM OF DATA ***********************************************************************************
Before this i try to display something onthe stored procedure code 'sproc02'
but it didnot appear on the spool sysout, is it my stored procedure not called
or i do the wrong jcl / flow
In other word it not returning any result
i would be very appreciate your answer, thank you :)
*----------------------------------------------------------------*
IDENTIFICATION DIVISION.
*----------------------------------------------------------------*
PROGRAM-ID. MAIN.
AUTHOR. DUMMY.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 BRANCH PIC X(07).
01 ACCTNO PIC X(11).
01 AVAILABLE PIC X(01).
01 ADDTS PIC X(26).
01 ADDUSER PIC X(08).
01 ADDPROGRAM PIC X(08).
01 UPDTS PIC X(26).
01 UPDUSER PIC X(08).
01 UPDPROGRAM PIC X(08).
01 OUTCODE PIC S9(09) USAGE BINARY.
PROCEDURE DIVISION.
MOVE 1 TO BRANCH.
MOVE 3913 TO ACCTNO.
CALL 'SPROC02' USING BRANCH ,
ACCTNO ,
AVAILABLE ,
ADDTS ,
ADDUSER ,
ADDPROGRAM,
UPDTS ,
UPDUSER ,
UPDPROGRAM,
OUTCODE.
EVALUATE OUTCODE
WHEN +0
CONTINUE
WHEN OTHER
DISPLAY 'ERROR CALL SPROC02 RC: ' OUTCODE
END-EVALUATE.
DISPLAY "SP-DA-AVAC-BRANCH " BRANCH.
DISPLAY "SP-DA-AVAC-ACCT-NO " ACCTNO.
DISPLAY "SP-DA-AVAC-AVAILABLE " AVAILABLE.
DISPLAY "SP-DA-AVAC-ADD-TS " ADDTS.
DISPLAY "SP-DA-AVAC-ADD-USER " ADDUSER.
DISPLAY "SP-DA-AVAC-ADD-PROGRAM " ADDPROGRAM.
DISPLAY "SP-DA-AVAC-UPD-TS " UPDTS.
DISPLAY "SP-DA-AVAC-UPD-USER " UPDUSER.
DISPLAY "OUT-CODE " OUTCODE.
STOP RUN.
Related
COBOL 6.3 JSON-GENERATE SUPPRESS is suppressing all table occurrences
I am working with the COBOL Enterprise 6.3 JSON-GENERATE, using the SUPPRESS phrase. I have the following COBOL data area: 05 contactInfo. 07 postalAddresses OCCURS 0 TO 10 DEPENDING ON WIMBCST-POSTAL-COUNT. 09 POSTAL-ID PIC X(40). 09 addressCategory PIC X(30). 09 startDate PIC X(10). 09 legalAddressStartDate PIC X(10). 09 endDate PIC X(10). 09 perpetualEndDate PIC X(10). 09 perpetualStartDate PIC X(10). 09 addressFormatName PIC X(10). 09 POSTAL-SEQ PIC 99. 09 postalAddressType PIC X(20). 09 addressLines OCCURS 10 TIMES. 11 addressLineType PIC X(20). 11 addressLineText PIC X(60). 09 locationLines OCCURS 10 TIMES. 11 locationType PIC X(20). 11 locationText PIC X(60). The data is initially LOW-VALUES. When the JSON is generated, if any occurrence of addressLines or locationLines is eligible for suppression, the entire table is suppressed as follows: { "postalAddresses": [ { "addressCategory": "Master", "addressFormatName": "US", "sequenceNumber": 1, "postalAddressType": "Unknown" } ] } Even though occurrence 1 of addressLines has data, and locationLines has 3 occurrences of data. I am really expecting this: { "postalAddresses": [ { "addressCategory": "Master", "addressFormatName": "US", "sequenceNumber": 1, "postalAddressType": "Unknown", "addressLines": [ { "addressLineType": "A", "addressLineText": "123 MAIN" } ], "locationLines": [ { "locationType": "City", "locationText": "TEST CITY" }, { "locationType": "State", "locationText": "CA" }, { "locationType": "Postal Code", "locationText": "99999" } ] } ] } Any tips/advice on how I can use the SUPPRESS phrase and get the addressLines and locationLines items generated?
this is a known problem that should be fixed by APAR PH40288
SwiftDate - string to date
I use the SwiftDate library but I can't transform my string to date. This code return null let date = "Tue, 19 Sep 2017 15:43:57 GMT".date(format: .custom("EEE, dd MMM yyyy HH:mm:ss zzz")) Would anyone know why?
This code works now : let region = Region(tz: TimeZoneName.gmt, cal: CalendarName.gregorian, loc: LocaleName.englishUnitedStates) let date = "Tue, 19 Sep 2017 15:43:57 GMT".date(format: .custom("EEE, dd MMM yyyy HH:mm:ss zzz"), fromRegion: region) Thank you for your help!
dateFromString returns nil for some values
I am getting nil for some values while using dateFromString in swift. I searched a lot but in vain. Following is my code: let strDate = self.sortedDict.valueForKey("TIME").objectAtIndex(indexPath.row).objectAtIndex(0) as? String print(strDate); let st_date = frmt.dateFromString(strDate!) let frmt1:NSDateFormatter = NSDateFormatter() frmt1.locale = NSLocale(localeIdentifier: localeStr) frmt1.dateFormat = "MMM, dd yyyy hh:mm a" if st_date != nil { print(st_date) } Output console: Optional("September, 20 2015 10:00:00") Optional(2015-09-20 10:00:00 +0000) Optional("October, 04 2015 10:00:00") Optional(2015-10-04 10:00:00 +0000) Optional("October, 04 2015 14:00:00") // nil Optional("October, 18 2015 15:00:00") // nil Optional("September, 20 2015 14:00:00") // nil Optional("September, 27 2015 10:00:00") Optional(2015-09-27 10:00:00 +0000) Optional("September, 27 2015 12:00:00") Optional(2015-09-27 00:00:00 +0000) Optional("September, 27 2015 14:00:00") Optional("October, 03 2015 14:00:00") //nil Optional("October, 03 2015 16:00:00") //nil The format is same for all date strings still I get nil for few values. Why so? Please help. Where am I getting wrong?
format should be HH for 24 hours even you are getting values only for 12 hours. frmt1.dateFormat = "MMM, dd yyyy HH:mm a"
Convert Hex to Byte array in Swift
I've a hardware which sends me a hex data and i need to convert it to byte array in swift. Here's example data; 01 01 02 0A 12 14 14 11 10 0D 0B 0A 09 09 08 08 08 07 06 06 06 06 06 06 05 05 06 05 05 04 04 04 04 03 03 03 04 03 03 02 03 02 03 02 02 03 02 02 02 01 02 01 01 01 01 01 Can you help me please?
If you got a bunch of hexes (UInt8), then you can create NSData like this: NSData(bytes: [0xFF, 0xD9] as [UInt8], length: 2)
use this method it gives Byte Array func getByte(data:NSData) -> Array<UInt8> { let count = data.length / sizeof(Int8) var array = [UInt8](count: count, repeatedValue: 0) data.getBytes(&array, length:count * sizeof(UInt32)) return array }
SNMP trap via Indy plus russian letters
I send snmp traps from borland c++ application using indy components, (thanks Remy Lebeau for working example Implementing SNMP SendTrap using Indy components) But I have problem with russian letters. void __fastcall TMainForm::QuickSendTrap() { String myEnterprise = _D("1.5.5.5.5.5.5.5"); String eventType = myEnterprise + _D(".1"); String eventDistance = myEnterprise + _D(".2"); String eventTitle1 = myEnterprise + _D(".3"); String eventTitle2 = myEnterprise + _D(".4"); String eventTitle3 = myEnterprise + _D(".5"); TStringList *names = new TStringList; names->Add(eventType); names->Add(eventDistance); names->Add(eventTitle1); names->Add(eventTitle2); names->Add(eventTitle3); TStringList *values = new TStringList; values->AddObject(_D("ftCritical"), (TObject*)ASN1_OCTSTR); values->AddObject(_D("2.357"), (TObject*)ASN1_OCTSTR); values->AddObject(_D("АБВГД"), (TObject*)ASN1_OCTSTR); values->AddObject(_D("абвгд"), (TObject*)ASN1_OCTSTR); values->AddObject(_D("ОПРСТ"), (TObject*)ASN1_OCTSTR); TIdSNMP *idSnmp = new TIdSNMP(NULL); idSnmp->QuickSendTrap(edHost->Text, myEnterprise, _D("public"), 162, 6, 1, names, values); delete idSnmp; delete names; delete values; } Instead of russian symbols Wireshark see "?" 0000 30 81 8b 02 01 00 04 06 70 75 62 6c 69 63 a4 7e 0.......public.~ 0010 06 07 2d 05 05 05 05 05 05 40 04 c0 a8 64 56 02 ..-......#...dV. 0020 01 06 02 01 01 43 01 00 30 64 30 16 06 08 2d 05 .....C..0d0...-. 0030 05 05 05 05 05 01 04 0a 66 74 43 72 69 74 69 63 ........ftCritic 0040 61 6c 30 11 06 08 2d 05 05 05 05 05 05 02 04 05 al0...-......... 0050 32 2e 33 35 37 30 11 06 08 2d 05 05 05 05 05 05 2.3570...-...... 0060 03 04 05 3f 3f 3f 3f 3f 30 11 06 08 2d 05 05 05 ...?????0...-... 0070 05 05 05 04 04 05 3f 3f 3f 3f 3f 30 11 06 08 2d ......?????0...- 0080 05 05 05 05 05 05 05 04 05 3f 3f 3f 3f 3f .........????? The question is how to encode russian string for snmp properly?
Unfortunately, TIdSNMP does not support non-ASCII data at this time. This is because: Indy's ASN.1 encode/decode functions have not been made encoding-aware yet so that strings can be converted to/from byte arrays using charsets. TSNMPInfo encodes PDU data to a String first and then encodes that String to bytes using Indy's 8bit encoding when sending. Thus, any Unicode codepoints greater than #255 will get converted to ?. The Russian characters you are trying to send all have Unicode codepoint values greater than #255. There is no option to specify a different encoding, even though ASN.1 octet strings can technically carry character data encoded in any 8bit charset as long as both parties agree to the charset used.
In order to send cyrillic symbols via Indy's Snmp component I implemented functions which "hide" message in different encoding inside UnicodeString that used by TIdSnmp. UnicodeString TMainForm::Windows1251ForSnmp(AnsiString str) { UnicodeString ustr = ""; for (int i = 0; i < str.Length(); i++) { unsigned char cc = *(str.c_str()+i); wchar_t buff = 0; memcpy((char*)&buff, &cc, 1); ustr = ustr + buff; } return ustr; } UnicodeString TMainForm::Utf8ForSnmp(UTF8String str) { UnicodeString ustr = ""; for (int i = 0; i < str.Length(); i++) { unsigned char cc = *(str.c_str()+i); wchar_t buff = 0; memcpy((char*)&buff, &cc, 1); ustr = ustr + buff; } return ustr; } UnicodeString TMainForm::Utf16ForSnmp(UnicodeString str) { UnicodeString ustr = ""; for (int i = 0; i < str.Length(); i++) { unsigned int cc = *(str.c_str()+i); byte a = cc / 256; byte b = cc % 256; ustr = ustr + char(a); ustr = ustr + char(b); } return ustr; } After message conversion by one of these functions I gave result to Indy component TIdSnmp as usually and it will be send without problem. UnicodeString ustr = Windows1251ForSnmp("Русский"); UTF8String param = _D("Русский"); UnicodeString ustr2 = Utf8ForSnmp(param); UnicodeString ustr3 = Utf16ForSnmp("Русский"); values->AddObject(ustr, (TObject*)ASN1_OCTSTR); values->AddObject(ustr2, (TObject*)ASN1_OCTSTR); values->AddObject(ustr3, (TObject*)ASN1_OCTSTR); So, on the "other side" I recieved russian messages in Windows1251, Utf8 and Utf16 encoding.