Using Offsets in a User Space

An offset indicates where in a structure that specific information s offsets are correctly used, programs can extract specific pieces structure and perform actions on that data.

Incorrectly working with offsets can produce errors by API users wh base 1 language such as RPG and COBOL. One way to determine the b language is how a programmer specifies the first element of an arra language, the first element is number 0. In base 1 languages, the f number 1.

The example programs in the following topics are coded using RPG. RPG base 1 language while the APIs produce information using a base of pensate for APIs producing information at base 0, the API user must

decimal and hexadecimal offsets to formats that areSystemcontainedAPI in th Referencebook.

Using Offsets in a

User

Space—Example

of

Incorrect

Coding

 

 

The

point

for

beginning

to

read

a user

.space18/ on ispageshown9-30at. The

data is read and placed into a user space. However, the data in

incorrect

because

the

starting

position

to

start was off by 1. Thi

to retrieve

the data

one

character (or

position) too soon. The corr

shown

at.19/

on

page

9-34.

 

 

 

 

I\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I\

 

 

I\Program Name: APIUG1

 

I\

 

 

I\Programming Language:

RPG

I\

 

 

I\Description: This sample program illustrates the incor￿rect

I\

way of using the offset in a user space.

I\

 

 

I\Header Files Included: QUSGEN - Generic Header of a User S￿pace

I\

 

QUSEC - Error Code Parameter

I\

 

(Copied into Program)

I\

 

QUSLOBJ - List Objects API

I\

 

 

I\APIs Used:

QUSCRTUS -

Create User Space

I\

QUSLOBJ -

List Objects

I\

QUSRTVUS -

Retrieve User Space

I\

QUSDLTUS -

Delete User Space

I\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I\

I\ Generic Header of a User Space Include

I\

I/COPY QSYSINC/QRPGSRC,QUSGEN

I\

I\ Error Code Parameter Include for the APIs

I\

I\ The following QUSEC include is copied into this program￿

I\ so that the variable length field can be defined as a

I\ fixed length.

Chapter 9. Common API Programming Errors 9-27

Page 233
Image 233
IBM Version 4 manual Using Offsets in a User Space, Incorrect, Point For Beginning Read User, Quslobj