terminate a string in RPG Data Structure

The C++ Struct is like this

Struct xxx {
char *inprec;
char *outrec;
char inpfn[FILENAMELEN + 1];
char outfn[FILENAMELEN + 1];
};

where FILENAMELEN = 128;

My RPG Data Structure is

Dxxx               DS
D inprec                       *
D outrec                       *
D inpfn                        128A  Inz('aaaaa')
D  nullt1                          1A Inz(X'00')
D outfn                        128A Inz('bbb')
D  nullt2                          1A Inz(X'00')

I am passing RPG to C++. The value of inpfn is "aaaaa                                     upto 128 Bytes".
It doesn't null terminate.
If I define the length of inpfn to be 5A. It display fine but then the outfn string gets concatenated just after inpfn.
 I don't know where I am doing wrong.

Any body with data structure experience ,please help

Thanks

Dhumal    
dhumalAsked:
Who is Participating?
 
moduloCommented:
Closed, 150 points refunded.

modulo
Community Support Moderator
Experts Exchange
0
 
daveslaterCommented:
You need to specify the
VALUE
and
OPTIONS(*STRING)

in the prototype definition

dave
0
 
daveslaterCommented:
quick example

 D stat            pr            10i 0 extproc('stat')                                          
 D  filename                       *   value options(*string)               null terminated str  
 D  statStruct                     *   value                                                    
                                                                                                 
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dhumalAuthor Commented:
Hi Dave,

I used your example , but getting following error

Keyword "Inz" is not allowed. This means I cannot initialize the members in my data structure.

Please help with any working example, if you have.

Appreciate your help!

Dhumal
0
 
daveslaterCommented:
Hi
the example define the parmaters that you are passing to the C++ program. It is not the actual data structure.
You then use the CALLP to evoke the C++ functions

ie


CALLP              stat(%trim(mystring) : %addr(mydatastructure))

dave
0
 
daveslaterCommented:
Ps
I can not give a working example as I do not know your C++ procedure name, I do not know C++ only how to use the IBM supplied C++ routines in the QC2LE directory.

Dave
0
 
tliottaCommented:
Dhumal:

First, since you're defining pointers as part of your DS, make sure the DS has the ALIGN keyword. Second, you can replace the four fields inpfn, nullt1, outfn and nullt2 with two definitions of 129A. That will allow the maximum 128 chars for both inpfn and outfn plus null terminators (128+1).

In order to put values in that memory, please explain what you need to do. Are you initializing to 'aaaaa' and 'bbb' because those values will always be passed? If so, then code something like this in your initialization routine:

 C                   eval      inpfn = 'aaaaa' + x'00'
 C                   eval      outfn = 'bbb' + x'00'

I don't know any way of initializing a value to include a null terminator except to code an EVAL.

If you are only using 'aaaaa' and 'bbb' as example values and you are really using values from variables, code something like this:

  C                   eval      %str( %addr( inpfn ) : %size( inpfn )) =
  c                                       %trim( someinpvar )
  C                   eval      %str( %addr( outfn ) : %size( outfn )) =
  c                                       %trim( someoutvar )

Tom
0
 
dhumalAuthor Commented:
Hi Tom,

Thanks for your response.

I have already defined the keyword ALIGN and. And I need to initialize inpfn and outfn
with some values. I tried your 1st suggestion
C                   eval      inpfn = 'aaaaa' + x'00'
C                   eval      outfn = 'bbb' + x'00'

but still not getting it null terminated.

Do you have any other idea?

Thanks,

Dhumal
0
 
tliottaCommented:
Dhumal:

If that's what you have, then it is being null-terminated. Only other thing I can even imagine is using *allx'00' in place of x'00'. Since I have no idea what the C++ procedure does, I don't know what it's expecting in the allocated memory. Filling the memory with a known value might tell something even if it's all hex zeros.

Tom
0
 
HelixirCommented:
I would personnaly do like tliotta says, define my DS with 2 string of 129.
And you could manage to put your null terminated string with %substr()

ex:
eval      inpfn = 'aaaaa'
eval      %substr(inpfn:129:1) = x'00'
0
 
tliottaCommented:
Helixir:

Note that placing the x'00' into position 129 will create a string 128 chars long because all trailing blanks will be preserved. If the C++ needs/wants only the five significant characters in 'aaaaa', then the null-terminator would need to be in position 6.

Tom
0
 
dhumalAuthor Commented:
Hi Dave,

Thanks for your response, but unfortunately I have not received any satisfactory solution. So I kindly request you to refund the points.

Regards,

-Tej
0
 
tliottaCommented:
One item hasn't been covered -- how the pointers inprec                       and outrec are being set. If the correct addresses, aren't placed in those pointers, null-termination won't be reliable. Further, because these are pointer values, the method used to pass the DS to C is important. The address of the DS needs to be passed; the DS can't be passed by VALUE for example. Doing so wil probably corrupt the pointer values.

Tom
0
 
daveslaterCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ - Refund points

Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
daveslater
Page Editor
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.