Solved

terminate a string in RPG Data Structure

Posted on 2004-09-21
16
462 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now