[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

terminate a string in RPG Data Structure

Posted on 2004-09-21
16
Medium Priority
?
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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