25 pts.
 Using system() function in RPG IV
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 'XMLDATAA' 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;

Software/Hardware used:
ASKED: July 2, 2008  6:08 PM
UPDATED: May 3, 2010  6:02 AM

Answer Wiki:
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. ============================================================== The CRTDIR command requires a quoted string if the value contains special characters such as a back-slash. Send in the correct string value and the error should change. Since you define <i>Options(*String) </i>, the prototype should handle the null-termination fine for you. That's one of the reasons for specifying it. Tom
Last Wiki Answer Submitted:  May 3, 2010  6:02 am  by  Sloopy   2,195 pts.
All Answer Wiki Contributors:  Sloopy   2,195 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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; 
 7,185 pts.

 

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,

 7,185 pts.

 

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.

 2,195 pts.