Question

  Asked: Jul 2 2008   6:08 PM GMT
  Asked by: GLinds01


Using system() function in RPG IV


AS/400, RPG IV, AS/400 errors

Could someone please tell why this doesn't work? Path = '\SOMENAME. I get a CPF006 ('Errors occurred in command.') The message in the joblog is 'String '\XMLDATA\A' contains a character that is not valid.'


D path S 63A Varying
D cpfmsg S 7A Import('_EXCP_MSGID')
D command S 1024A Varying
D system PR 10I 0 extProc('system')
D cmdstring * Value Options(*String)

path = %trimR(PfhWS);
command = 'CRTDIR \XMLDATA' + path;
if system(command) <> 0;

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



I can see that the system() command requires a *string type variable (that is, a null-terminated string - one that ends with hex '00').

You are passing it an RPG varying string - one whose length is given by a length attribute. RPG will pass the data part of the string, without the two-byte length part, which system() would not have understood anyway.

So, what you need to do is add the X'00' to the end of your string:

command = 'CRTDIR \XMLDATA' + path + X'00';

Et voila! As Del Boy would say, you should have liftoff.

Sloopy, after a long lunch.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on AS/400.

Looking for relevant AS/400 Whitepapers? Visit the Search400.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

BigKat  |   Jul 3 2008  2:04PM GMT

Have you tried it like this. The VARYING adds a 2(?) byte size to the front of the string.

D path S 63A Varying
D cpfmsg S 7A Import('_EXCP_MSGID')
D command S 1024A
D system PR 10I 0 extProc('system')
D cmdstring * Value Options(*String)

path = %trimR(PfhWS);
command = 'CRTDIR \XMLDATA' + path;

if system(%trim(command)) <> 0;

 

BigKat  |   Jul 7 2008  12:35PM GMT

hi sloopy,

I thought that the Value Options(*String) would generate the pointer to the VARYING field, and that it was “scooping up” the length bytes as he was getting an invalid character error and not a missing terminator error,

 

Sloopy  |   Jul 8 2008  2:52PM GMT

It may well be doing that too, BigKat. But the *String option does require that a terminating X’00′ must be present, and in RPG we have to do that ourselves - it won’t be done by the RPG EVAL operation.

And the error message doesn’t say that string ‘CRTDIR…’ contains an invalid character, which it would (though probably expressing the string fragment in hex) if the variable cmdstring contained the ‘varying’ length bytes.

In any event, the first byte of the length bytes would be hex 00, and that would say ‘null termination’ to the system() command.

(Varying, varsize and *string options become irritating when we start using them all together….)

GLinds01 - please give us feedback on this, and let us know what solves your problem!

Sloopy, after a sedate and responsible lunch.