Solved

terminate a string in RPG Data Structure

Posted on 2004-09-21
16
473 Views
Last Modified: 2012-06-27
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    
0
Comment
Question by:dhumal
  • 5
  • 4
  • 3
  • +2
16 Comments
 
LVL 14

Expert Comment

by:daveslater
ID: 12121308
You need to specify the
VALUE
and
OPTIONS(*STRING)

in the prototype definition

dave
0
 
LVL 14

Expert Comment

by:daveslater
ID: 12122141
quick example

 D stat            pr            10i 0 extproc('stat')                                          
 D  filename                       *   value options(*string)               null terminated str  
 D  statStruct                     *   value                                                    
                                                                                                 
0
 

Author Comment

by:dhumal
ID: 12122940
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 14

Expert Comment

by:daveslater
ID: 12123349
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
 
LVL 14

Expert Comment

by:daveslater
ID: 12123371
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
 
LVL 27

Expert Comment

by:tliotta
ID: 12129334
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
 

Author Comment

by:dhumal
ID: 12132137
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
 
LVL 27

Expert Comment

by:tliotta
ID: 12136404
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
 
LVL 1

Expert Comment

by:Helixir
ID: 12144685
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
 
LVL 27

Expert Comment

by:tliotta
ID: 12148415
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
 

Author Comment

by:dhumal
ID: 13044933
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
 
LVL 27

Expert Comment

by:tliotta
ID: 13047456
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
 
LVL 14

Expert Comment

by:daveslater
ID: 13175367
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13361787
Closed, 150 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries change printer IP in Navigator 6 137
best way to update esxi hosts 6 151
AS400 QAOSDIAJRN / APYJRNCHG Processing 5 45
Using the QLIRLIBD 2 21
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question