Using system() function in RPG IV

25 pts.
Tags:
AS/400
AS/400 errors
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;

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BigKat
    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; 
    
    8,350 pointsBadges:
    report
  • BigKat
    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,
    8,350 pointsBadges:
    report
  • Sloopy
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following