I've written a custom COBOL batch program (named P1006) that I want to use to call a SQL-Server package from the operating system command line. The command string I'm generating within the P1006 uses two parameters entered into the program by the user. The COBOL program compiles correctly and executes. However, the command string being executed is not the command string that the program is generating.
I put in a display so that it echoes the command to an output file and I've verified the command syntax is correct. I've gone as far as copying the command to my Windows clipboard, pasting it into a DOS prompt, and executing it without error.
The problem is that when the command is actually executed by COBOL, it's putting my two parameters plus a "N" character in front of the command string. The command string then fails.
I'd be more than happy to provide the program files here for review if someone thinks they can help. I sure could use some.
Attached is the output file from my P1006 program. You'll be able to see the command string I'm trying to execute (following the "USING COMMAND STRING OF" entry) and the actual command that is executed (beginning with the word "Option").
Since the "Option" entry is occurring below the Microsoft copyright notice, I'm wondering if it's actually SQL-Server throwing the error and not my COBOL program. But this doesn't make sense since the displayed command above the Microsoft notice will execute correctly.
Thanks for any help you can provide. I'm driving myself crazy trying to figure this out. Funny thing is, this program worked fine in my Lawson 8.x environment. It's only since migrating it to LSF9 that it blows up.
Here's the text of the PD file:
000100****************************************************************** 000200 050-EDIT-PARAMETERS SECTION 10. 000300****************************************************************** 000400 050-START. 000500 000600 IF (PRM-COMPANY-IN = ZEROES) 001400 MOVE 050 TO CRT-ERROR-NBR 001500 MOVE WS-TRUE TO WS-PARAMETER-ERROR 001600 PERFORM 780-PRINT-ERROR-MSG 001700 GO TO 050-END.
000600 IF (PRM-MTH-END-DATE = ZEROES) 001400 MOVE 052 TO CRT-ERROR-NBR 001500 MOVE WS-TRUE TO WS-PARAMETER-ERROR 001600 PERFORM 780-PRINT-ERROR-MSG 001700 GO TO 050-END. 001800 001900 050-END. 002000 002100****************************************************************** 002200 100-PROGRAM-CONTROL SECTION 10. 002300****************************************************************** 002400 100-START. 002500 002600 MOVE 051 TO CRT-MSG-NBR. 002700 PERFORM 780-DISPLAY-MSG. 002800 003100 PERFORM 1000-FIRE-OFF-DTS. 003400 003500 100-END. 003600 003700****************************************************************** 003800 1000-FIRE-OFF-DTS SECTION 50. 003900****************************************************************** 004000 1000-START. MOVE PRM-COMPANY-IN TO WS-COMPANY-IN. 004100 MOVE PRM-MTH-END-DATE TO WS-MTH-END-DATE. DISPLAY " ". STRING "dtexec /FILE " WS-QUOTE "\\wchlawapp01\f$\DTSX_packages\" "Test_SSIS_package.dtsx" WS-QUOTE " /SET " WS-QUOTE "\Package.Variables[User::COMPANY]" ".Properties[Value]" WS-QUOTE ";" WS-COMPANY-IN " /SET " WS-QUOTE "\Package.Variables[User::MONTH_END_DATE]" ".Properties[Value]" WS-QUOTE ";" WS-MTH-END-DATE WS-CARRIAGE-RETURN DELIMITED BY SIZE INTO WS-DTS-COMMAND. MOVE WS-DTS-COMMAND TO WS-DTS-COMMAND-DISP. DISPLAY "USING COMMAND STRING OF:". DISPLAY " ". DISPLAY WS-DTS-COMMAND-DISP. DISPLAY " ". 006100 CALL "SYSTEM" USING WS-DTS-COMMAND. 020000 020100****************************************************************** 020200 1000-END. 020300****************************************************************** 020400
And here is the text of the WS file:
000100****************************************************************** 000200* P1006WS * 000300****************************************************************** 000400 01 P1006WS. 002800 02 WS-DTS-COMMAND PIC X(300) VALUE SPACES. 02 WS-COMPANY-IN PIC X(2) VALUE SPACES. 02 WS-MTH-END-DATE PIC X(8) VALUE SPACES. 02 WS-QUOTE PIC X VALUE X"22". 02 WS-CARRIAGE-RETURN PIC X VALUE X"0D". 02 WS-PROG-RNGPRM-SETTO-HV PIC X VALUE "N". 02 WS-DTS-COMMAND-DISP PIC X(300) VALUE SPACES.
Sam - I did see references to adding a null character to a command, but I couldn't find any examples of how to do that.
When you pass a command string to the SYSTEM function, it needs to a null-terminated string wrapped in quotes, so here are a couple of suggestions: 1. Change your command string terminator to a null, not a carriage return. 2. You may need to experiment a little with the quotes, and you may find that it's easier to pass the variables to a script, and have the script call dtexec. You can see an example of calling the SYSTEM function here: