Entire Connection Script Read with spaces

In Entire Connection,

Is there any way to read an optional parameter from a file that maybe separated by a space ?

If a file contains ‘Hello Sir’ then after,

READ 1 #PARM1 #PARAM2

#PARAM1 = Hello
#PARAM2 = Sir

But, If a file contains ‘Hello There Sir’ , then

READ 1 #PARM1 #PARAM2

#PARAM1 = Hello
#PARAM2 = There

How can I achieve,

#PARAM1 = Hello There
#PARAM2 = Sir

?

Hallo and thank you for your question.

Unfortunately, when using the ‘READ’ command the record is always split into fields that are separated by blanks. This behavior cannot be changed by the user. For more information about the ‘READ’ command see the documentation (Commands => READ).

As a workaround I would suggest using the ‘READ’ command with three parameters. Afterword’s you can use the ‘SET’ command to merge the first and the second parameter (see Commands => SET).

In your example it would look like this:

A File contains ‘Hello There Sir’.

READ 1 #PARM1 #PARAM2 #PARAM3

Then the content would be:

#PARAM1 = Hello
#PARAM2 = There
#PARAM3 = Sir

Now merge #PARM1 #PARAM2 to #MPARAM:

SET #MPARAM #PARAM1 ‘ ’ #PARAM2

Then the content would be:

#PARAM1 = Hello
#PARAM2 = There
#PARAM3 = Sir
#MPARAM = Hello There

Afterword’s you can overwrite the #PARAM1 and #PARAM2 to get the desired result:

SET #PARAM1 #MPARAM
SET #PARAM2 #PARAM3

Result should be:

#PARAM1 = Hello There
#PARAM2 = Sir

I hope this answer helps you.
Please feel free to ask for any clarification.

Kind Regards
Marcel

Thank you very much for your help! I have a follow-up question.

I would like to do this conditionally.
Could you please tell me if there are any errors with the following code?

READ 1 #parm1 #parm2 #parm3 #parm4

If #parm4 NE ‘’
SET #parm2 #parm2 ’ ’ #parm3
SET #parm3 #parm4

I wanted to create block of code for the if statement if possible.
Also, is checking for blank the same as checking for null.
I read in the documentation that the remaining unused variables in an if statement are null

Good Evening,

I’m always happy to help!

To your follow-up question:

The syntax for the if statement is as follows.

IF [variable] [operator] variable command

So, you are only able to perform a single command after the query. The command should be also in the same line as the query itself.

To perform two statements (like setting #parm2 & #parm3) in a condition it would be necessary to use the ‘PERFORM’ command to branch in another location of the procedure. For more information about perform please see Commands => PERFORM.

For better understanding I will try to give you an example:

First call the if statement with the perform command.

If #parm4 NE ‘’ PERFORM newparm

Perform will now jump to the routine (by tag)‘newparm’. Normally tags as routines are defined at the end of the procedure.
Routines start with the tag ‘:routineName’ and normally ends with the RETURN statement (see Commands => RETURN).

In your example:

:newparm
SET #parm2 #parm2 ’ ’ #parm3
SET #parm3 #parm4
RETURN

Another point is that if you define tags at the end of the file you have to make sure that you use the EXIT command correctly (see Commands => EXIT).

In you example this would look like this:

… some stuff you want to do before …
If #parm4 NE ‘’ PERFORM newparm
… some stuff you want to do afterword’s …
EXIT

:newparm
SET #parm2 #parm2 ’ ’ #parm3
SET #parm3 #parm4
RETURN

If you forget to run ‘EXIT’ the newparm tag would be run through again at the end

I am looking forward to receiving your feedback!

Kind Regards
Marcel

Thanks so much!
I think this should work for the most part.

The only thing I am concerned about would be if Null is different from ‘’.
The documentation didn’t have anything for checking Null,
so ill have to assume that for strings, it is the same as ‘’

Good Morning,

You are probably referring to the following section from the documentation in ‘Commands => READ’:

If you specify more variables than fields, the unused variables are reset to null. If there are more fields than variables, the last variable contains the rest of the record.

I’m pretty sure that with ‘reset to null’ setting the string to the length zero is meant. Which is equivalent to ‘’.

In the documentation at ‘Terminal Emulation => Variables => Local Variables => Local Variables with Value Type String” strings are defined as the following.

Variables with value type String may contain any character or a group of characters. The maximum length is 254 characters.

Zero is not mentioned here.

I will discuss with colleagues if the documentation must be adjusted here to be more user friendly.

I would be happy to hear if your code works as expected.

Kind Regards
Marcel